├── CHINESE_README.md ├── LICENSE ├── README.md ├── docs ├── IJCAI2022_Poster.pdf ├── README.md ├── _config.yml ├── index.html └── static │ ├── css │ ├── bulma-carousel.min.css │ ├── bulma-slider.min.css │ ├── bulma.css.map.txt │ ├── bulma.min.css │ ├── fontawesome.all.min.css │ └── index.css │ ├── images │ ├── diag.jpg │ ├── favicon.svg │ ├── label.jpg │ ├── other_data_set.jpg │ ├── pred.jpg │ ├── pred_video.jpg │ ├── sample_agg.jpg │ └── steve.webm │ └── js │ ├── bulma-carousel.js │ ├── bulma-carousel.min.js │ ├── bulma-slider.js │ ├── bulma-slider.min.js │ ├── fontawesome.all.min.js │ └── index.js ├── experiments ├── coco │ ├── aggpose │ │ ├── aggpose_L_256x192_adamw_lr1e-3.yaml │ │ └── aggpose_L_384x288_adamw_lr1e-3.yaml │ ├── hrnet │ │ ├── w32_256x192_adam_lr1e-3.yaml │ │ ├── w32_384x288_adam_lr1e-3.yaml │ │ ├── w48_256x192_adam_lr1e-3.yaml │ │ └── w48_384x288_adam_lr1e-3.yaml │ └── resnet │ │ ├── res101_256x192_d256x3_adam_lr1e-3.yaml │ │ ├── res101_384x288_d256x3_adam_lr1e-3.yaml │ │ ├── res152_256x192_d256x3_adam_lr1e-3.yaml │ │ ├── res152_384x288_d256x3_adam_lr1e-3.yaml │ │ ├── res50_256x192_d256x3_adam_lr1e-3.yaml │ │ └── res50_384x288_d256x3_adam_lr1e-3.yaml └── infantpose │ ├── aggpose │ └── aggpose_L_256x192.yaml │ ├── hrnet │ └── hrnet_w32_256x192.yaml │ └── resnet │ └── resnet152_256x192.yaml ├── lib ├── Makefile ├── config │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ ├── default.cpython-38.pyc │ │ └── models.cpython-38.pyc │ ├── default.py │ └── models.py ├── core │ ├── __pycache__ │ │ ├── evaluate.cpython-38.pyc │ │ ├── function.cpython-38.pyc │ │ ├── inference.cpython-38.pyc │ │ └── loss.cpython-38.pyc │ ├── evaluate.py │ ├── function.py │ ├── inference.py │ └── loss.py ├── dataset │ ├── JointsDataset.py │ ├── __init__.py │ ├── coco.py │ ├── infantpose.py │ └── mpii.py ├── models │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ ├── pose_aggpose.cpython-38.pyc │ │ ├── pose_hrnet.cpython-38.pyc │ │ ├── pose_resnet.cpython-38.pyc │ │ └── pose_segformer.cpython-38.pyc │ ├── pose_aggpose.py │ ├── pose_hrnet.py │ ├── pose_resnet.py │ └── pose_segformer.py ├── nms │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ └── nms.cpython-38.pyc │ ├── cpu_nms.c │ ├── cpu_nms.cpython-38-x86_64-linux-gnu.so │ ├── cpu_nms.pyx │ ├── gpu_nms.cpp │ ├── gpu_nms.cpython-38-x86_64-linux-gnu.so │ ├── gpu_nms.cu │ ├── gpu_nms.hpp │ ├── gpu_nms.pyx │ ├── nms.py │ ├── nms_kernel.cu │ └── setup_linux.py ├── test_model.py ├── timm │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-38.pyc │ │ └── version.cpython-38.pyc │ ├── data │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-38.pyc │ │ │ ├── auto_augment.cpython-38.pyc │ │ │ ├── config.cpython-38.pyc │ │ │ ├── constants.cpython-38.pyc │ │ │ ├── dataset.cpython-38.pyc │ │ │ ├── dataset_factory.cpython-38.pyc │ │ │ ├── distributed_sampler.cpython-38.pyc │ │ │ ├── loader.cpython-38.pyc │ │ │ ├── mixup.cpython-38.pyc │ │ │ ├── random_erasing.cpython-38.pyc │ │ │ ├── real_labels.cpython-38.pyc │ │ │ ├── transforms.cpython-38.pyc │ │ │ └── transforms_factory.cpython-38.pyc │ │ ├── auto_augment.py │ │ ├── config.py │ │ ├── constants.py │ │ ├── dataset.py │ │ ├── dataset_factory.py │ │ ├── distributed_sampler.py │ │ ├── loader.py │ │ ├── mixup.py │ │ ├── parsers │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── class_map.cpython-38.pyc │ │ │ │ ├── constants.cpython-38.pyc │ │ │ │ ├── parser.cpython-38.pyc │ │ │ │ ├── parser_factory.cpython-38.pyc │ │ │ │ ├── parser_image_folder.cpython-38.pyc │ │ │ │ ├── parser_image_in_tar.cpython-38.pyc │ │ │ │ └── parser_image_tar.cpython-38.pyc │ │ │ ├── class_map.py │ │ │ ├── constants.py │ │ │ ├── parser.py │ │ │ ├── parser_factory.py │ │ │ ├── parser_image_folder.py │ │ │ ├── parser_image_in_tar.py │ │ │ ├── parser_image_tar.py │ │ │ └── parser_tfds.py │ │ ├── random_erasing.py │ │ ├── real_labels.py │ │ ├── tf_preprocessing.py │ │ ├── transforms.py │ │ └── transforms_factory.py │ ├── loss │ │ ├── __init__.py │ │ ├── asymmetric_loss.py │ │ ├── binary_cross_entropy.py │ │ ├── cross_entropy.py │ │ └── jsd.py │ ├── models │ │ ├── MAE.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── MAE.cpython-38.pyc │ │ │ ├── __init__.cpython-38.pyc │ │ │ ├── beit.cpython-38.pyc │ │ │ ├── byoanet.cpython-38.pyc │ │ │ ├── byobnet.cpython-38.pyc │ │ │ ├── cait.cpython-38.pyc │ │ │ ├── coat.cpython-38.pyc │ │ │ ├── convit.cpython-38.pyc │ │ │ ├── convmixer.cpython-38.pyc │ │ │ ├── crossvit.cpython-38.pyc │ │ │ ├── cspnet.cpython-38.pyc │ │ │ ├── densenet.cpython-38.pyc │ │ │ ├── dla.cpython-38.pyc │ │ │ ├── dpn.cpython-38.pyc │ │ │ ├── efficientnet.cpython-38.pyc │ │ │ ├── efficientnet_blocks.cpython-38.pyc │ │ │ ├── efficientnet_builder.cpython-38.pyc │ │ │ ├── factory.cpython-38.pyc │ │ │ ├── features.cpython-38.pyc │ │ │ ├── fx_features.cpython-38.pyc │ │ │ ├── ghostnet.cpython-38.pyc │ │ │ ├── gluon_resnet.cpython-38.pyc │ │ │ ├── gluon_xception.cpython-38.pyc │ │ │ ├── hardcorenas.cpython-38.pyc │ │ │ ├── helpers.cpython-38.pyc │ │ │ ├── hrnet.cpython-38.pyc │ │ │ ├── hub.cpython-38.pyc │ │ │ ├── inception_resnet_v2.cpython-38.pyc │ │ │ ├── inception_v3.cpython-38.pyc │ │ │ ├── inception_v4.cpython-38.pyc │ │ │ ├── levit.cpython-38.pyc │ │ │ ├── mlp_mixer.cpython-38.pyc │ │ │ ├── mobilenetv3.cpython-38.pyc │ │ │ ├── nasnet.cpython-38.pyc │ │ │ ├── nest.cpython-38.pyc │ │ │ ├── nfnet.cpython-38.pyc │ │ │ ├── pit.cpython-38.pyc │ │ │ ├── pnasnet.cpython-38.pyc │ │ │ ├── registry.cpython-38.pyc │ │ │ ├── regnet.cpython-38.pyc │ │ │ ├── res2net.cpython-38.pyc │ │ │ ├── resnest.cpython-38.pyc │ │ │ ├── resnet.cpython-38.pyc │ │ │ ├── resnetv2.cpython-38.pyc │ │ │ ├── rexnet.cpython-38.pyc │ │ │ ├── selecsls.cpython-38.pyc │ │ │ ├── senet.cpython-38.pyc │ │ │ ├── sknet.cpython-38.pyc │ │ │ ├── swin_transformer.cpython-38.pyc │ │ │ ├── tnt.cpython-38.pyc │ │ │ ├── tresnet.cpython-38.pyc │ │ │ ├── twins.cpython-38.pyc │ │ │ ├── vgg.cpython-38.pyc │ │ │ ├── visformer.cpython-38.pyc │ │ │ ├── vision_transformer.cpython-38.pyc │ │ │ ├── vision_transformer_hybrid.cpython-38.pyc │ │ │ ├── vovnet.cpython-38.pyc │ │ │ ├── xception.cpython-38.pyc │ │ │ ├── xception_aligned.cpython-38.pyc │ │ │ └── xcit.cpython-38.pyc │ │ ├── beit.py │ │ ├── byoanet.py │ │ ├── byobnet.py │ │ ├── cait.py │ │ ├── coat.py │ │ ├── convit.py │ │ ├── convmixer.py │ │ ├── crossvit.py │ │ ├── cspnet.py │ │ ├── densenet.py │ │ ├── dla.py │ │ ├── dpn.py │ │ ├── efficientnet.py │ │ ├── efficientnet_blocks.py │ │ ├── efficientnet_builder.py │ │ ├── factory.py │ │ ├── features.py │ │ ├── fx_features.py │ │ ├── ghostnet.py │ │ ├── gluon_resnet.py │ │ ├── gluon_xception.py │ │ ├── hardcorenas.py │ │ ├── helpers.py │ │ ├── hrnet.py │ │ ├── hub.py │ │ ├── inception_resnet_v2.py │ │ ├── inception_v3.py │ │ ├── inception_v4.py │ │ ├── layers │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── activations.cpython-38.pyc │ │ │ │ ├── activations_jit.cpython-38.pyc │ │ │ │ ├── activations_me.cpython-38.pyc │ │ │ │ ├── adaptive_avgmax_pool.cpython-38.pyc │ │ │ │ ├── blur_pool.cpython-38.pyc │ │ │ │ ├── bottleneck_attn.cpython-38.pyc │ │ │ │ ├── cbam.cpython-38.pyc │ │ │ │ ├── classifier.cpython-38.pyc │ │ │ │ ├── cond_conv2d.cpython-38.pyc │ │ │ │ ├── config.cpython-38.pyc │ │ │ │ ├── conv2d_same.cpython-38.pyc │ │ │ │ ├── conv_bn_act.cpython-38.pyc │ │ │ │ ├── create_act.cpython-38.pyc │ │ │ │ ├── create_attn.cpython-38.pyc │ │ │ │ ├── create_conv2d.cpython-38.pyc │ │ │ │ ├── create_norm_act.cpython-38.pyc │ │ │ │ ├── drop.cpython-38.pyc │ │ │ │ ├── eca.cpython-38.pyc │ │ │ │ ├── evo_norm.cpython-38.pyc │ │ │ │ ├── gather_excite.cpython-38.pyc │ │ │ │ ├── global_context.cpython-38.pyc │ │ │ │ ├── halo_attn.cpython-38.pyc │ │ │ │ ├── helpers.cpython-38.pyc │ │ │ │ ├── inplace_abn.cpython-38.pyc │ │ │ │ ├── lambda_layer.cpython-38.pyc │ │ │ │ ├── linear.cpython-38.pyc │ │ │ │ ├── mixed_conv2d.cpython-38.pyc │ │ │ │ ├── mlp.cpython-38.pyc │ │ │ │ ├── non_local_attn.cpython-38.pyc │ │ │ │ ├── norm.cpython-38.pyc │ │ │ │ ├── norm_act.cpython-38.pyc │ │ │ │ ├── padding.cpython-38.pyc │ │ │ │ ├── patch_embed.cpython-38.pyc │ │ │ │ ├── pool2d_same.cpython-38.pyc │ │ │ │ ├── selective_kernel.cpython-38.pyc │ │ │ │ ├── separable_conv.cpython-38.pyc │ │ │ │ ├── space_to_depth.cpython-38.pyc │ │ │ │ ├── split_attn.cpython-38.pyc │ │ │ │ ├── split_batchnorm.cpython-38.pyc │ │ │ │ ├── squeeze_excite.cpython-38.pyc │ │ │ │ ├── std_conv.cpython-38.pyc │ │ │ │ ├── test_time_pool.cpython-38.pyc │ │ │ │ ├── trace_utils.cpython-38.pyc │ │ │ │ └── weight_init.cpython-38.pyc │ │ │ ├── activations.py │ │ │ ├── activations_jit.py │ │ │ ├── activations_me.py │ │ │ ├── adaptive_avgmax_pool.py │ │ │ ├── attention_pool2d.py │ │ │ ├── blur_pool.py │ │ │ ├── bottleneck_attn.py │ │ │ ├── cbam.py │ │ │ ├── classifier.py │ │ │ ├── cond_conv2d.py │ │ │ ├── config.py │ │ │ ├── conv2d_same.py │ │ │ ├── conv_bn_act.py │ │ │ ├── create_act.py │ │ │ ├── create_attn.py │ │ │ ├── create_conv2d.py │ │ │ ├── create_norm_act.py │ │ │ ├── drop.py │ │ │ ├── eca.py │ │ │ ├── evo_norm.py │ │ │ ├── gather_excite.py │ │ │ ├── global_context.py │ │ │ ├── halo_attn.py │ │ │ ├── helpers.py │ │ │ ├── inplace_abn.py │ │ │ ├── lambda_layer.py │ │ │ ├── linear.py │ │ │ ├── median_pool.py │ │ │ ├── mixed_conv2d.py │ │ │ ├── mlp.py │ │ │ ├── non_local_attn.py │ │ │ ├── norm.py │ │ │ ├── norm_act.py │ │ │ ├── padding.py │ │ │ ├── patch_embed.py │ │ │ ├── pool2d_same.py │ │ │ ├── selective_kernel.py │ │ │ ├── separable_conv.py │ │ │ ├── space_to_depth.py │ │ │ ├── split_attn.py │ │ │ ├── split_batchnorm.py │ │ │ ├── squeeze_excite.py │ │ │ ├── std_conv.py │ │ │ ├── test_time_pool.py │ │ │ ├── trace_utils.py │ │ │ └── weight_init.py │ │ ├── levit.py │ │ ├── mlp_mixer.py │ │ ├── mobilenetv3.py │ │ ├── nasnet.py │ │ ├── nest.py │ │ ├── nfnet.py │ │ ├── pit.py │ │ ├── pnasnet.py │ │ ├── pruned │ │ │ ├── ecaresnet101d_pruned.txt │ │ │ ├── ecaresnet50d_pruned.txt │ │ │ ├── efficientnet_b1_pruned.txt │ │ │ ├── efficientnet_b2_pruned.txt │ │ │ └── efficientnet_b3_pruned.txt │ │ ├── registry.py │ │ ├── regnet.py │ │ ├── res2net.py │ │ ├── resnest.py │ │ ├── resnet.py │ │ ├── resnetv2.py │ │ ├── rexnet.py │ │ ├── selecsls.py │ │ ├── senet.py │ │ ├── sknet.py │ │ ├── swin_transformer.py │ │ ├── tnt.py │ │ ├── tresnet.py │ │ ├── twins.py │ │ ├── vgg.py │ │ ├── visformer.py │ │ ├── vision_transformer.py │ │ ├── vision_transformer_hybrid.py │ │ ├── vovnet.py │ │ ├── xception.py │ │ ├── xception_aligned.py │ │ └── xcit.py │ ├── optim │ │ ├── __init__.py │ │ ├── adabelief.py │ │ ├── adafactor.py │ │ ├── adahessian.py │ │ ├── adamp.py │ │ ├── adamw.py │ │ ├── lamb.py │ │ ├── lars.py │ │ ├── lookahead.py │ │ ├── madgrad.py │ │ ├── nadam.py │ │ ├── nvnovograd.py │ │ ├── optim_factory.py │ │ ├── radam.py │ │ ├── rmsprop_tf.py │ │ └── sgdp.py │ ├── scheduler │ │ ├── __init__.py │ │ ├── cosine_lr.py │ │ ├── multistep_lr.py │ │ ├── plateau_lr.py │ │ ├── poly_lr.py │ │ ├── scheduler.py │ │ ├── scheduler_factory.py │ │ ├── step_lr.py │ │ └── tanh_lr.py │ ├── utils │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-38.pyc │ │ │ ├── agc.cpython-38.pyc │ │ │ ├── checkpoint_saver.cpython-38.pyc │ │ │ ├── clip_grad.cpython-38.pyc │ │ │ ├── cuda.cpython-38.pyc │ │ │ ├── distributed.cpython-38.pyc │ │ │ ├── jit.cpython-38.pyc │ │ │ ├── log.cpython-38.pyc │ │ │ ├── metrics.cpython-38.pyc │ │ │ ├── misc.cpython-38.pyc │ │ │ ├── model.cpython-38.pyc │ │ │ ├── model_ema.cpython-38.pyc │ │ │ ├── random.cpython-38.pyc │ │ │ └── summary.cpython-38.pyc │ │ ├── agc.py │ │ ├── checkpoint_saver.py │ │ ├── clip_grad.py │ │ ├── cuda.py │ │ ├── distributed.py │ │ ├── jit.py │ │ ├── log.py │ │ ├── metrics.py │ │ ├── misc.py │ │ ├── model.py │ │ ├── model_ema.py │ │ ├── random.py │ │ └── summary.py │ └── version.py └── utils │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── opencv_functional.cpython-38.pyc │ ├── opencv_transforms.cpython-38.pyc │ ├── transforms.cpython-38.pyc │ ├── utils.cpython-38.pyc │ └── vis.cpython-38.pyc │ ├── opencv_functional.py │ ├── opencv_transforms.py │ ├── transforms.py │ ├── utils.py │ ├── vis.py │ └── zipreader.py ├── logs └── COCO2017 │ └── coco_val_POSE_CILVR.out ├── tools ├── __pycache__ │ └── _init_paths.cpython-38.pyc ├── _init_paths.py ├── test.py └── train.py └── visualization └── plot_coco.py /CHINESE_README.md: -------------------------------------------------------------------------------- 1 | # AggPose - Deep Aggregation Vision Transformer for Infant Pose Estimation (Pytorch官方实现版本) 2 | 3 | [English Version](https://github.com/SZAR-LAB/AggPose/blob/main/README.md) 4 | 5 | ## 介绍 6 | 7 | 新生儿的姿势评估可以用于辅助儿科医生预测神经发育障碍,进而早期干预相关疾病。然而,绝大多数的人体姿态估计方法都以成年人为基准,缺乏大规模的婴儿姿态估计数据集和深度学习框架。在本文中,我们通过提出用于人类(重点是婴幼儿)姿势估计的AggPose来填补这一空白,效仿HRNet,AggPose引入了一个多分辨率的Transformer框架,但是和HRNet系列模型不同,AggPose在模型早期阶段用Transformer取代卷积运算来提取特征。该算法将 Transformer + MLP 推广到特征图中的多尺度深层聚合,从而实现不同分辨率下视觉标记之间的信息融合。本文中的Transformer结构使用了和SegFormer一致的Mix-Transformer / Mix-FFN结构,代码部分容易理解。我们在 COCO 姿势估计上对 AggPose 进行了预训练,并预训练模型在我们新发布的大规模婴儿姿势估计数据集上finetune。结果表明,AggPose 可以有效地学习不同分辨率之间的多尺度特征,并显着提高性能。虽然模型相较HRFormer, TokenPose等2021年的baseline提升仅有1%,但是这一结构初步证实了全Transformer结构也可以用于人体姿态评估。作者希望未来能在应用侧将这一算法和自监督学习相结合,扩展人体姿态评估在临床研究和产品开发中的可能性。 8 | 9 | 本文的数据来源于深圳宝安妇幼保健院、深圳儿童医院。在数据集整理完备后将通过infantpose@gmail.com这一邮箱来接受临床数据访问申请。 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AggPose - Deep Aggregation Vision Transformer for Infant Pose Estimation 2 | 3 | [中文版](https://github.com/SZAR-LAB/AggPose/blob/main/CHINESE_README.md) 4 | 5 | ## Introduction 6 | 7 | Movement and pose assessment of newborns lets trained pediatricians predict neurodevelopmental disorders, allowing early intervention for related diseases. However, most of newest approaches for human pose estimation method focus on adults, lacking publicly large-scale dataset and powerful deep learning framework for infant pose estimation. In this paper, we fill this gap by proposing Deep Aggregation Vision Transformer for human (infant) posture estimation (AggPose), which introduces a high-resolution transformer framework without using convolution operations to extract features in the early stages. It generalizes Transformer + MLP to multi-scale deep layer aggregation within feature maps, thus enabling information fusion between different levels of vision tokens. We pre-train AggPose on COCO pose estimation and apply it on our newly released large-scale infant pose estimation dataset. The results show that AggPose could effectively learn the multi-scale features among different resolutions and significantly improve the performance. 8 | 9 | This work was accepted by IJCAI-ECAI 2022 AI for Good Track 10 | 11 | ## Requirements 12 | 13 | 14 | ## COCO Dataset 15 | 16 | Download the dataset: [COCO 2017](https://cocodataset.org/#download) 17 | 18 | The dataset folder should like this: 19 | 20 | ``` 21 | ── coco 22 | │-- annotations 23 | │ │-- person_keypoints_train2017.json 24 | │ |-- person_keypoints_val2017.json 25 | │ |-- person_keypoints_test-dev-2017.json 26 | |-- person_detection_results 27 | | |-- COCO_val2017_detections_AP_H_56_person.json 28 | | |-- COCO_test-dev2017_detections_AP_H_609_person.json 29 | │-- train2017 30 | │ │-- 000000000009.jpg 31 | │ │-- 000000000025.jpg 32 | │ │-- 000000000030.jpg 33 | │ │-- ... 34 | `-- val2017 35 | │-- 000000000139.jpg 36 | │-- 000000000285.jpg 37 | │-- 000000000632.jpg 38 | │-- ... 39 | ``` 40 | 41 | 42 | AggPose Model Parameter: 43 | [COCO 2017 AggPose-L 256x192](https://drive.google.com/file/d/1h9mu7EDwwWLmYcWh0z1ToknCbR08pFZU/view?usp=sharing) 44 | [infantpose 2022 AggPose-L 256x192](https://drive.google.com/file/d/1wvQo5tqVr39fopm3gf9likUU1xk_sUPf/view?usp=sharing) 45 | 46 | More modified code will release soon. I will update this repo continually. I am trying to re-train the model with 384x288 input size. For 256x192 input size, please use the parm in above link. Thanks! 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /docs/IJCAI2022_Poster.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/IJCAI2022_Poster.pdf -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # infant-aggpose 2 | 3 | The webpage is cloned from [Nerfies website](https://nerfies.github.io). 4 | 5 | Cite: 6 | 7 | ``` 8 | @article{park2021nerfies 9 | author = {Park, Keunhong and Sinha, Utkarsh and Barron, Jonathan T. and Bouaziz, Sofien and Goldman, Dan B and Seitz, Steven M. and Martin-Brualla, Ricardo}, 10 | title = {Nerfies: Deformable Neural Radiance Fields}, 11 | journal = {ICCV}, 12 | year = {2021}, 13 | } 14 | ``` -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/_config.yml -------------------------------------------------------------------------------- /docs/static/css/bulma-carousel.min.css: -------------------------------------------------------------------------------- 1 | @-webkit-keyframes spinAround{from{-webkit-transform:rotate(0);transform:rotate(0)}to{-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@keyframes spinAround{from{-webkit-transform:rotate(0);transform:rotate(0)}to{-webkit-transform:rotate(359deg);transform:rotate(359deg)}}.slider{position:relative;width:100%}.slider-container{display:flex;flex-wrap:nowrap;flex-direction:row;overflow:hidden;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);min-height:100%}.slider-container.is-vertical{flex-direction:column}.slider-container .slider-item{flex:none}.slider-container .slider-item .image.is-covered img{-o-object-fit:cover;object-fit:cover;-o-object-position:center center;object-position:center center;height:100%;width:100%}.slider-container .slider-item .video-container{height:0;padding-bottom:0;padding-top:56.25%;margin:0;position:relative}.slider-container .slider-item .video-container.is-1by1,.slider-container .slider-item .video-container.is-square{padding-top:100%}.slider-container .slider-item .video-container.is-4by3{padding-top:75%}.slider-container .slider-item .video-container.is-21by9{padding-top:42.857143%}.slider-container .slider-item .video-container embed,.slider-container .slider-item .video-container iframe,.slider-container .slider-item .video-container object{position:absolute;top:0;left:0;width:100%!important;height:100%!important}.slider-navigation-next,.slider-navigation-previous{display:flex;justify-content:center;align-items:center;position:absolute;width:42px;height:42px;background:#fff center center no-repeat;background-size:20px 20px;border:1px solid #fff;border-radius:25091983px;box-shadow:0 2px 5px #3232321a;top:50%;margin-top:-20px;left:0;cursor:pointer;transition:opacity .3s,-webkit-transform .3s;transition:transform .3s,opacity .3s;transition:transform .3s,opacity .3s,-webkit-transform .3s}.slider-navigation-next:hover,.slider-navigation-previous:hover{-webkit-transform:scale(1.2);transform:scale(1.2)}.slider-navigation-next.is-hidden,.slider-navigation-previous.is-hidden{display:none;opacity:0}.slider-navigation-next svg,.slider-navigation-previous svg{width:25%}.slider-navigation-next{left:auto;right:0;background:#fff center center no-repeat;background-size:20px 20px}.slider-pagination{display:none;justify-content:center;align-items:center;position:absolute;bottom:0;left:0;right:0;padding:.5rem 1rem;text-align:center}.slider-pagination .slider-page{background:#fff;width:10px;height:10px;border-radius:25091983px;display:inline-block;margin:0 3px;box-shadow:0 2px 5px #3232321a;transition:-webkit-transform .3s;transition:transform .3s;transition:transform .3s,-webkit-transform .3s;cursor:pointer}.slider-pagination .slider-page.is-active,.slider-pagination .slider-page:hover{-webkit-transform:scale(1.4);transform:scale(1.4)}@media screen and (min-width:800px){.slider-pagination{display:flex}}.hero.has-carousel{position:relative}.hero.has-carousel+.hero-body,.hero.has-carousel+.hero-footer,.hero.has-carousel+.hero-head{z-index:10;overflow:hidden}.hero.has-carousel .hero-carousel{position:absolute;top:0;left:0;bottom:0;right:0;height:auto;border:none;margin:auto;padding:0;z-index:0}.hero.has-carousel .hero-carousel .slider{width:100%;max-width:100%;overflow:hidden;height:100%!important;max-height:100%;z-index:0}.hero.has-carousel .hero-carousel .slider .has-background{max-height:100%}.hero.has-carousel .hero-carousel .slider .has-background .is-background{-o-object-fit:cover;object-fit:cover;-o-object-position:center center;object-position:center center;height:100%;width:100%}.hero.has-carousel .hero-body{margin:0 3rem;z-index:10} -------------------------------------------------------------------------------- /docs/static/css/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Noto Sans', sans-serif; 3 | } 4 | 5 | 6 | .footer .icon-link { 7 | font-size: 25px; 8 | color: #000; 9 | } 10 | 11 | .link-block a { 12 | margin-top: 5px; 13 | margin-bottom: 5px; 14 | } 15 | 16 | .dnerf { 17 | font-variant: small-caps; 18 | } 19 | 20 | 21 | .teaser .hero-body { 22 | padding-top: 0; 23 | padding-bottom: 3rem; 24 | } 25 | 26 | .teaser { 27 | font-family: 'Google Sans', sans-serif; 28 | } 29 | 30 | 31 | .publication-title { 32 | } 33 | 34 | .publication-banner { 35 | max-height: parent; 36 | 37 | } 38 | 39 | .publication-banner video { 40 | position: relative; 41 | left: auto; 42 | top: auto; 43 | transform: none; 44 | object-fit: fit; 45 | } 46 | 47 | .publication-header .hero-body { 48 | } 49 | 50 | .publication-title { 51 | font-family: 'Google Sans', sans-serif; 52 | } 53 | 54 | .publication-authors { 55 | font-family: 'Google Sans', sans-serif; 56 | } 57 | 58 | .publication-venue { 59 | color: #555; 60 | width: fit-content; 61 | font-weight: bold; 62 | } 63 | 64 | .publication-awards { 65 | color: #ff3860; 66 | width: fit-content; 67 | font-weight: bolder; 68 | } 69 | 70 | .publication-authors { 71 | } 72 | 73 | .publication-authors a { 74 | color: hsl(204, 86%, 53%) !important; 75 | } 76 | 77 | .publication-authors a:hover { 78 | text-decoration: underline; 79 | } 80 | 81 | .author-block { 82 | display: inline-block; 83 | } 84 | 85 | .publication-banner img { 86 | } 87 | 88 | .publication-authors { 89 | /*color: #4286f4;*/ 90 | } 91 | 92 | .publication-video { 93 | position: relative; 94 | width: 100%; 95 | height: 0; 96 | padding-bottom: 56.25%; 97 | 98 | overflow: hidden; 99 | border-radius: 10px !important; 100 | } 101 | 102 | .publication-video iframe { 103 | position: absolute; 104 | top: 0; 105 | left: 0; 106 | width: 100%; 107 | height: 100%; 108 | } 109 | 110 | .publication-body img { 111 | } 112 | 113 | .results-carousel { 114 | overflow: hidden; 115 | } 116 | 117 | .results-carousel .item { 118 | margin: 5px; 119 | overflow: hidden; 120 | border: 1px solid #bbb; 121 | border-radius: 10px; 122 | padding: 0; 123 | font-size: 0; 124 | } 125 | 126 | .results-carousel video { 127 | margin: 0; 128 | } 129 | 130 | 131 | .interpolation-panel { 132 | background: #f5f5f5; 133 | border-radius: 10px; 134 | } 135 | 136 | .interpolation-panel .interpolation-image { 137 | width: 100%; 138 | border-radius: 5px; 139 | } 140 | 141 | .interpolation-video-column { 142 | } 143 | 144 | .interpolation-panel .slider { 145 | margin: 0 !important; 146 | } 147 | 148 | .interpolation-panel .slider { 149 | margin: 0 !important; 150 | } 151 | 152 | #interpolation-image-wrapper { 153 | width: 100%; 154 | } 155 | #interpolation-image-wrapper img { 156 | border-radius: 5px; 157 | } 158 | -------------------------------------------------------------------------------- /docs/static/images/diag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/static/images/diag.jpg -------------------------------------------------------------------------------- /docs/static/images/favicon.svg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/static/images/favicon.svg -------------------------------------------------------------------------------- /docs/static/images/label.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/static/images/label.jpg -------------------------------------------------------------------------------- /docs/static/images/other_data_set.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/static/images/other_data_set.jpg -------------------------------------------------------------------------------- /docs/static/images/pred.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/static/images/pred.jpg -------------------------------------------------------------------------------- /docs/static/images/pred_video.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/static/images/pred_video.jpg -------------------------------------------------------------------------------- /docs/static/images/sample_agg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/static/images/sample_agg.jpg -------------------------------------------------------------------------------- /docs/static/images/steve.webm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/docs/static/images/steve.webm -------------------------------------------------------------------------------- /docs/static/js/index.js: -------------------------------------------------------------------------------- 1 | window.HELP_IMPROVE_VIDEOJS = false; 2 | 3 | var INTERP_BASE = "https://homes.cs.washington.edu/~kpar/nerfies/interpolation/stacked"; 4 | var NUM_INTERP_FRAMES = 240; 5 | 6 | var interp_images = []; 7 | function preloadInterpolationImages() { 8 | for (var i = 0; i < NUM_INTERP_FRAMES; i++) { 9 | var path = INTERP_BASE + '/' + String(i).padStart(6, '0') + '.jpg'; 10 | interp_images[i] = new Image(); 11 | interp_images[i].src = path; 12 | } 13 | } 14 | 15 | function setInterpolationImage(i) { 16 | var image = interp_images[i]; 17 | image.ondragstart = function() { return false; }; 18 | image.oncontextmenu = function() { return false; }; 19 | $('#interpolation-image-wrapper').empty().append(image); 20 | } 21 | 22 | 23 | $(document).ready(function() { 24 | // Check for click events on the navbar burger icon 25 | $(".navbar-burger").click(function() { 26 | // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu" 27 | $(".navbar-burger").toggleClass("is-active"); 28 | $(".navbar-menu").toggleClass("is-active"); 29 | 30 | }); 31 | 32 | var options = { 33 | slidesToScroll: 1, 34 | slidesToShow: 3, 35 | loop: true, 36 | infinite: true, 37 | autoplay: false, 38 | autoplaySpeed: 3000, 39 | } 40 | 41 | // Initialize all div with carousel class 42 | var carousels = bulmaCarousel.attach('.carousel', options); 43 | 44 | // Loop on each carousel initialized 45 | for(var i = 0; i < carousels.length; i++) { 46 | // Add listener to event 47 | carousels[i].on('before:show', state => { 48 | console.log(state); 49 | }); 50 | } 51 | 52 | // Access to bulmaCarousel instance of an element 53 | var element = document.querySelector('#my-element'); 54 | if (element && element.bulmaCarousel) { 55 | // bulmaCarousel instance is available as element.bulmaCarousel 56 | element.bulmaCarousel.on('before-show', function(state) { 57 | console.log(state); 58 | }); 59 | } 60 | 61 | /*var player = document.getElementById('interpolation-video'); 62 | player.addEventListener('loadedmetadata', function() { 63 | $('#interpolation-slider').on('input', function(event) { 64 | console.log(this.value, player.duration); 65 | player.currentTime = player.duration / 100 * this.value; 66 | }) 67 | }, false);*/ 68 | preloadInterpolationImages(); 69 | 70 | $('#interpolation-slider').on('input', function(event) { 71 | setInterpolationImage(this.value); 72 | }); 73 | setInterpolationImage(0); 74 | $('#interpolation-slider').prop('max', NUM_INTERP_FRAMES - 1); 75 | 76 | bulmaSlider.attach(); 77 | 78 | }) 79 | -------------------------------------------------------------------------------- /experiments/coco/aggpose/aggpose_L_256x192_adamw_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 1 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'coco' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 8 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/coco/' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_aggpose 28 | NUM_JOINTS: 17 29 | PRETRAINED: '' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 192 33 | - 256 34 | HEATMAP_SIZE: 35 | - 48 36 | - 64 37 | SIGMA: 2 38 | 39 | LOSS: 40 | USE_TARGET_WEIGHT: true 41 | TRAIN: 42 | BATCH_SIZE_PER_GPU: 32 43 | SHUFFLE: true 44 | BEGIN_EPOCH: 0 45 | END_EPOCH: 500 46 | OPTIMIZER: adamw 47 | LR: 0.001 48 | LR_FACTOR: 0.1 49 | LR_STEP: 50 | - 170 51 | - 200 52 | - 240 53 | WD: 0.0001 54 | GAMMA1: 0.99 55 | GAMMA2: 0.0 56 | MOMENTUM: 0.9 57 | NESTEROV: false 58 | TEST: 59 | BATCH_SIZE_PER_GPU: 32 60 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 61 | BBOX_THRE: 1.0 62 | IMAGE_THRE: 0.0 63 | IN_VIS_THRE: 0.2 64 | MODEL_FILE: '' 65 | NMS_THRE: 1.0 66 | OKS_THRE: 0.9 67 | USE_GT_BBOX: true 68 | FLIP_TEST: true 69 | POST_PROCESS: true 70 | SHIFT_HEATMAP: true 71 | DEBUG: 72 | DEBUG: true 73 | SAVE_BATCH_IMAGES_GT: true 74 | SAVE_BATCH_IMAGES_PRED: true 75 | SAVE_HEATMAPS_GT: true 76 | SAVE_HEATMAPS_PRED: true 77 | -------------------------------------------------------------------------------- /experiments/coco/aggpose/aggpose_L_384x288_adamw_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 1 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'coco' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 8 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/coco/' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_aggpose 28 | NUM_JOINTS: 17 29 | PRETRAINED: '' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 288 33 | - 384 34 | HEATMAP_SIZE: 35 | - 72 36 | - 96 37 | SIGMA: 3 38 | 39 | LOSS: 40 | USE_TARGET_WEIGHT: true 41 | TRAIN: 42 | BATCH_SIZE_PER_GPU: 16 43 | SHUFFLE: true 44 | BEGIN_EPOCH: 0 45 | END_EPOCH: 400 46 | OPTIMIZER: adamw 47 | LR: 0.001 48 | LR_FACTOR: 0.1 49 | LR_STEP: 50 | - 210 51 | - 280 52 | - 350 53 | WD: 0.0001 54 | GAMMA1: 0.99 55 | GAMMA2: 0.0 56 | MOMENTUM: 0.9 57 | NESTEROV: false 58 | TEST: 59 | BATCH_SIZE_PER_GPU: 16 60 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 61 | BBOX_THRE: 1.0 62 | IMAGE_THRE: 0.0 63 | IN_VIS_THRE: 0.2 64 | MODEL_FILE: '' 65 | NMS_THRE: 1.0 66 | OKS_THRE: 0.9 67 | USE_GT_BBOX: true 68 | FLIP_TEST: true 69 | POST_PROCESS: true 70 | SHIFT_HEATMAP: true 71 | DEBUG: 72 | DEBUG: true 73 | SAVE_BATCH_IMAGES_GT: true 74 | SAVE_BATCH_IMAGES_PRED: true 75 | SAVE_HEATMAPS_GT: true 76 | SAVE_HEATMAPS_PRED: true 77 | -------------------------------------------------------------------------------- /experiments/coco/hrnet/w32_256x192_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'coco' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 8 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/coco/' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_hrnet 28 | NUM_JOINTS: 17 29 | PRETRAINED: 'models/pytorch/imagenet/hrnet_w32-36af842e.pth' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 192 33 | - 256 34 | HEATMAP_SIZE: 35 | - 48 36 | - 64 37 | SIGMA: 2 38 | EXTRA: 39 | PRETRAINED_LAYERS: 40 | - 'conv1' 41 | - 'bn1' 42 | - 'conv2' 43 | - 'bn2' 44 | - 'layer1' 45 | - 'transition1' 46 | - 'stage2' 47 | - 'transition2' 48 | - 'stage3' 49 | - 'transition3' 50 | - 'stage4' 51 | FINAL_CONV_KERNEL: 1 52 | STAGE2: 53 | NUM_MODULES: 1 54 | NUM_BRANCHES: 2 55 | BLOCK: BASIC 56 | NUM_BLOCKS: 57 | - 4 58 | - 4 59 | NUM_CHANNELS: 60 | - 32 61 | - 64 62 | FUSE_METHOD: SUM 63 | STAGE3: 64 | NUM_MODULES: 4 65 | NUM_BRANCHES: 3 66 | BLOCK: BASIC 67 | NUM_BLOCKS: 68 | - 4 69 | - 4 70 | - 4 71 | NUM_CHANNELS: 72 | - 32 73 | - 64 74 | - 128 75 | FUSE_METHOD: SUM 76 | STAGE4: 77 | NUM_MODULES: 3 78 | NUM_BRANCHES: 4 79 | BLOCK: BASIC 80 | NUM_BLOCKS: 81 | - 4 82 | - 4 83 | - 4 84 | - 4 85 | NUM_CHANNELS: 86 | - 32 87 | - 64 88 | - 128 89 | - 256 90 | FUSE_METHOD: SUM 91 | LOSS: 92 | USE_TARGET_WEIGHT: true 93 | TRAIN: 94 | BATCH_SIZE_PER_GPU: 32 95 | SHUFFLE: true 96 | BEGIN_EPOCH: 0 97 | END_EPOCH: 210 98 | OPTIMIZER: adam 99 | LR: 0.001 100 | LR_FACTOR: 0.1 101 | LR_STEP: 102 | - 170 103 | - 200 104 | WD: 0.0001 105 | GAMMA1: 0.99 106 | GAMMA2: 0.0 107 | MOMENTUM: 0.9 108 | NESTEROV: false 109 | TEST: 110 | BATCH_SIZE_PER_GPU: 32 111 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 112 | BBOX_THRE: 1.0 113 | IMAGE_THRE: 0.0 114 | IN_VIS_THRE: 0.2 115 | MODEL_FILE: '' 116 | NMS_THRE: 1.0 117 | OKS_THRE: 0.9 118 | USE_GT_BBOX: true 119 | FLIP_TEST: true 120 | POST_PROCESS: true 121 | SHIFT_HEATMAP: true 122 | DEBUG: 123 | DEBUG: true 124 | SAVE_BATCH_IMAGES_GT: true 125 | SAVE_BATCH_IMAGES_PRED: true 126 | SAVE_HEATMAPS_GT: true 127 | SAVE_HEATMAPS_PRED: true 128 | -------------------------------------------------------------------------------- /experiments/coco/hrnet/w32_384x288_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'coco' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 8 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/coco/' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_hrnet 28 | NUM_JOINTS: 17 29 | PRETRAINED: 'models/pytorch/imagenet/hrnet_w32-36af842e.pth' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 288 33 | - 384 34 | HEATMAP_SIZE: 35 | - 72 36 | - 96 37 | SIGMA: 3 38 | EXTRA: 39 | PRETRAINED_LAYERS: 40 | - 'conv1' 41 | - 'bn1' 42 | - 'conv2' 43 | - 'bn2' 44 | - 'layer1' 45 | - 'transition1' 46 | - 'stage2' 47 | - 'transition2' 48 | - 'stage3' 49 | - 'transition3' 50 | - 'stage4' 51 | FINAL_CONV_KERNEL: 1 52 | STAGE2: 53 | NUM_MODULES: 1 54 | NUM_BRANCHES: 2 55 | BLOCK: BASIC 56 | NUM_BLOCKS: 57 | - 4 58 | - 4 59 | NUM_CHANNELS: 60 | - 32 61 | - 64 62 | FUSE_METHOD: SUM 63 | STAGE3: 64 | NUM_MODULES: 4 65 | NUM_BRANCHES: 3 66 | BLOCK: BASIC 67 | NUM_BLOCKS: 68 | - 4 69 | - 4 70 | - 4 71 | NUM_CHANNELS: 72 | - 32 73 | - 64 74 | - 128 75 | FUSE_METHOD: SUM 76 | STAGE4: 77 | NUM_MODULES: 3 78 | NUM_BRANCHES: 4 79 | BLOCK: BASIC 80 | NUM_BLOCKS: 81 | - 4 82 | - 4 83 | - 4 84 | - 4 85 | NUM_CHANNELS: 86 | - 32 87 | - 64 88 | - 128 89 | - 256 90 | FUSE_METHOD: SUM 91 | LOSS: 92 | USE_TARGET_WEIGHT: true 93 | TRAIN: 94 | BATCH_SIZE_PER_GPU: 32 95 | SHUFFLE: true 96 | BEGIN_EPOCH: 0 97 | END_EPOCH: 210 98 | OPTIMIZER: adam 99 | LR: 0.001 100 | LR_FACTOR: 0.1 101 | LR_STEP: 102 | - 170 103 | - 200 104 | WD: 0.0001 105 | GAMMA1: 0.99 106 | GAMMA2: 0.0 107 | MOMENTUM: 0.9 108 | NESTEROV: false 109 | TEST: 110 | BATCH_SIZE_PER_GPU: 32 111 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 112 | BBOX_THRE: 1.0 113 | IMAGE_THRE: 0.0 114 | IN_VIS_THRE: 0.2 115 | MODEL_FILE: '' 116 | NMS_THRE: 1.0 117 | OKS_THRE: 0.9 118 | USE_GT_BBOX: true 119 | FLIP_TEST: true 120 | POST_PROCESS: true 121 | SHIFT_HEATMAP: true 122 | DEBUG: 123 | DEBUG: true 124 | SAVE_BATCH_IMAGES_GT: true 125 | SAVE_BATCH_IMAGES_PRED: true 126 | SAVE_HEATMAPS_GT: true 127 | SAVE_HEATMAPS_PRED: true 128 | -------------------------------------------------------------------------------- /experiments/coco/hrnet/w48_256x192_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'coco' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 8 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/coco/' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_hrnet 28 | NUM_JOINTS: 17 29 | PRETRAINED: 'models/pytorch/imagenet/hrnet_w48-8ef0771d.pth' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 192 33 | - 256 34 | HEATMAP_SIZE: 35 | - 48 36 | - 64 37 | SIGMA: 2 38 | EXTRA: 39 | PRETRAINED_LAYERS: 40 | - 'conv1' 41 | - 'bn1' 42 | - 'conv2' 43 | - 'bn2' 44 | - 'layer1' 45 | - 'transition1' 46 | - 'stage2' 47 | - 'transition2' 48 | - 'stage3' 49 | - 'transition3' 50 | - 'stage4' 51 | FINAL_CONV_KERNEL: 1 52 | STAGE2: 53 | NUM_MODULES: 1 54 | NUM_BRANCHES: 2 55 | BLOCK: BASIC 56 | NUM_BLOCKS: 57 | - 4 58 | - 4 59 | NUM_CHANNELS: 60 | - 48 61 | - 96 62 | FUSE_METHOD: SUM 63 | STAGE3: 64 | NUM_MODULES: 4 65 | NUM_BRANCHES: 3 66 | BLOCK: BASIC 67 | NUM_BLOCKS: 68 | - 4 69 | - 4 70 | - 4 71 | NUM_CHANNELS: 72 | - 48 73 | - 96 74 | - 192 75 | FUSE_METHOD: SUM 76 | STAGE4: 77 | NUM_MODULES: 3 78 | NUM_BRANCHES: 4 79 | BLOCK: BASIC 80 | NUM_BLOCKS: 81 | - 4 82 | - 4 83 | - 4 84 | - 4 85 | NUM_CHANNELS: 86 | - 48 87 | - 96 88 | - 192 89 | - 384 90 | FUSE_METHOD: SUM 91 | LOSS: 92 | USE_TARGET_WEIGHT: true 93 | TRAIN: 94 | BATCH_SIZE_PER_GPU: 32 95 | SHUFFLE: true 96 | BEGIN_EPOCH: 0 97 | END_EPOCH: 210 98 | OPTIMIZER: adam 99 | LR: 0.001 100 | LR_FACTOR: 0.1 101 | LR_STEP: 102 | - 170 103 | - 200 104 | WD: 0.0001 105 | GAMMA1: 0.99 106 | GAMMA2: 0.0 107 | MOMENTUM: 0.9 108 | NESTEROV: false 109 | TEST: 110 | BATCH_SIZE_PER_GPU: 32 111 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 112 | BBOX_THRE: 1.0 113 | IMAGE_THRE: 0.0 114 | IN_VIS_THRE: 0.2 115 | MODEL_FILE: '' 116 | NMS_THRE: 1.0 117 | OKS_THRE: 0.9 118 | USE_GT_BBOX: true 119 | FLIP_TEST: true 120 | POST_PROCESS: true 121 | SHIFT_HEATMAP: true 122 | DEBUG: 123 | DEBUG: true 124 | SAVE_BATCH_IMAGES_GT: true 125 | SAVE_BATCH_IMAGES_PRED: true 126 | SAVE_HEATMAPS_GT: true 127 | SAVE_HEATMAPS_PRED: true 128 | -------------------------------------------------------------------------------- /experiments/coco/hrnet/w48_384x288_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'coco' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 8 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/coco/' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_hrnet 28 | NUM_JOINTS: 17 29 | PRETRAINED: 'models/pytorch/imagenet/hrnet_w48-8ef0771d.pth' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 288 33 | - 384 34 | HEATMAP_SIZE: 35 | - 72 36 | - 96 37 | SIGMA: 3 38 | EXTRA: 39 | PRETRAINED_LAYERS: 40 | - 'conv1' 41 | - 'bn1' 42 | - 'conv2' 43 | - 'bn2' 44 | - 'layer1' 45 | - 'transition1' 46 | - 'stage2' 47 | - 'transition2' 48 | - 'stage3' 49 | - 'transition3' 50 | - 'stage4' 51 | FINAL_CONV_KERNEL: 1 52 | STAGE2: 53 | NUM_MODULES: 1 54 | NUM_BRANCHES: 2 55 | BLOCK: BASIC 56 | NUM_BLOCKS: 57 | - 4 58 | - 4 59 | NUM_CHANNELS: 60 | - 48 61 | - 96 62 | FUSE_METHOD: SUM 63 | STAGE3: 64 | NUM_MODULES: 4 65 | NUM_BRANCHES: 3 66 | BLOCK: BASIC 67 | NUM_BLOCKS: 68 | - 4 69 | - 4 70 | - 4 71 | NUM_CHANNELS: 72 | - 48 73 | - 96 74 | - 192 75 | FUSE_METHOD: SUM 76 | STAGE4: 77 | NUM_MODULES: 3 78 | NUM_BRANCHES: 4 79 | BLOCK: BASIC 80 | NUM_BLOCKS: 81 | - 4 82 | - 4 83 | - 4 84 | - 4 85 | NUM_CHANNELS: 86 | - 48 87 | - 96 88 | - 192 89 | - 384 90 | FUSE_METHOD: SUM 91 | LOSS: 92 | USE_TARGET_WEIGHT: true 93 | TRAIN: 94 | BATCH_SIZE_PER_GPU: 24 95 | SHUFFLE: true 96 | BEGIN_EPOCH: 0 97 | END_EPOCH: 210 98 | OPTIMIZER: adam 99 | LR: 0.001 100 | LR_FACTOR: 0.1 101 | LR_STEP: 102 | - 170 103 | - 200 104 | WD: 0.0001 105 | GAMMA1: 0.99 106 | GAMMA2: 0.0 107 | MOMENTUM: 0.9 108 | NESTEROV: false 109 | TEST: 110 | BATCH_SIZE_PER_GPU: 24 111 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 112 | BBOX_THRE: 1.0 113 | IMAGE_THRE: 0.0 114 | IN_VIS_THRE: 0.2 115 | MODEL_FILE: '' 116 | NMS_THRE: 1.0 117 | OKS_THRE: 0.9 118 | USE_GT_BBOX: true 119 | FLIP_TEST: true 120 | POST_PROCESS: true 121 | SHIFT_HEATMAP: true 122 | DEBUG: 123 | DEBUG: true 124 | SAVE_BATCH_IMAGES_GT: true 125 | SAVE_BATCH_IMAGES_PRED: true 126 | SAVE_HEATMAPS_GT: true 127 | SAVE_HEATMAPS_PRED: true 128 | -------------------------------------------------------------------------------- /experiments/coco/resnet/res101_256x192_d256x3_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: false 15 | DATASET: 'coco' 16 | ROOT: 'data/coco/' 17 | TEST_SET: 'val2017' 18 | TRAIN_SET: 'train2017' 19 | FLIP: true 20 | ROT_FACTOR: 40 21 | SCALE_FACTOR: 0.3 22 | MODEL: 23 | NAME: 'pose_resnet' 24 | PRETRAINED: 'models/pytorch/imagenet/resnet101-5d3b4d8f.pth' 25 | IMAGE_SIZE: 26 | - 192 27 | - 256 28 | HEATMAP_SIZE: 29 | - 48 30 | - 64 31 | SIGMA: 2 32 | NUM_JOINTS: 17 33 | TARGET_TYPE: 'gaussian' 34 | EXTRA: 35 | FINAL_CONV_KERNEL: 1 36 | DECONV_WITH_BIAS: false 37 | NUM_DECONV_LAYERS: 3 38 | NUM_DECONV_FILTERS: 39 | - 256 40 | - 256 41 | - 256 42 | NUM_DECONV_KERNELS: 43 | - 4 44 | - 4 45 | - 4 46 | NUM_LAYERS: 101 47 | LOSS: 48 | USE_TARGET_WEIGHT: true 49 | TRAIN: 50 | BATCH_SIZE_PER_GPU: 32 51 | SHUFFLE: true 52 | BEGIN_EPOCH: 0 53 | END_EPOCH: 140 54 | OPTIMIZER: 'adam' 55 | LR: 0.001 56 | LR_FACTOR: 0.1 57 | LR_STEP: 58 | - 90 59 | - 120 60 | WD: 0.0001 61 | GAMMA1: 0.99 62 | GAMMA2: 0.0 63 | MOMENTUM: 0.9 64 | NESTEROV: false 65 | TEST: 66 | BATCH_SIZE_PER_GPU: 32 67 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 68 | BBOX_THRE: 1.0 69 | IMAGE_THRE: 0.0 70 | IN_VIS_THRE: 0.2 71 | MODEL_FILE: '' 72 | NMS_THRE: 1.0 73 | OKS_THRE: 0.9 74 | FLIP_TEST: true 75 | POST_PROCESS: true 76 | SHIFT_HEATMAP: true 77 | USE_GT_BBOX: true 78 | DEBUG: 79 | DEBUG: true 80 | SAVE_BATCH_IMAGES_GT: true 81 | SAVE_BATCH_IMAGES_PRED: true 82 | SAVE_HEATMAPS_GT: true 83 | SAVE_HEATMAPS_PRED: true 84 | -------------------------------------------------------------------------------- /experiments/coco/resnet/res101_384x288_d256x3_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: false 15 | DATASET: 'coco' 16 | ROOT: 'data/coco/' 17 | TEST_SET: 'val2017' 18 | TRAIN_SET: 'train2017' 19 | FLIP: true 20 | ROT_FACTOR: 40 21 | SCALE_FACTOR: 0.3 22 | MODEL: 23 | NAME: 'pose_resnet' 24 | PRETRAINED: 'models/pytorch/imagenet/resnet101-5d3b4d8f.pth' 25 | IMAGE_SIZE: 26 | - 288 27 | - 384 28 | HEATMAP_SIZE: 29 | - 72 30 | - 96 31 | SIGMA: 3 32 | NUM_JOINTS: 17 33 | TARGET_TYPE: 'gaussian' 34 | EXTRA: 35 | FINAL_CONV_KERNEL: 1 36 | DECONV_WITH_BIAS: false 37 | NUM_DECONV_LAYERS: 3 38 | NUM_DECONV_FILTERS: 39 | - 256 40 | - 256 41 | - 256 42 | NUM_DECONV_KERNELS: 43 | - 4 44 | - 4 45 | - 4 46 | NUM_LAYERS: 101 47 | LOSS: 48 | USE_TARGET_WEIGHT: true 49 | TRAIN: 50 | BATCH_SIZE_PER_GPU: 32 51 | SHUFFLE: true 52 | BEGIN_EPOCH: 0 53 | END_EPOCH: 140 54 | OPTIMIZER: 'adam' 55 | LR: 0.001 56 | LR_FACTOR: 0.1 57 | LR_STEP: 58 | - 90 59 | - 120 60 | WD: 0.0001 61 | GAMMA1: 0.99 62 | GAMMA2: 0.0 63 | MOMENTUM: 0.9 64 | NESTEROV: false 65 | TEST: 66 | BATCH_SIZE_PER_GPU: 32 67 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 68 | BBOX_THRE: 1.0 69 | IMAGE_THRE: 0.0 70 | IN_VIS_THRE: 0.2 71 | MODEL_FILE: '' 72 | NMS_THRE: 1.0 73 | OKS_THRE: 0.9 74 | FLIP_TEST: true 75 | POST_PROCESS: true 76 | SHIFT_HEATMAP: true 77 | USE_GT_BBOX: true 78 | DEBUG: 79 | DEBUG: true 80 | SAVE_BATCH_IMAGES_GT: true 81 | SAVE_BATCH_IMAGES_PRED: true 82 | SAVE_HEATMAPS_GT: true 83 | SAVE_HEATMAPS_PRED: true 84 | -------------------------------------------------------------------------------- /experiments/coco/resnet/res152_256x192_d256x3_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: false 15 | DATASET: 'coco' 16 | ROOT: 'data/coco/' 17 | TEST_SET: 'val2017' 18 | TRAIN_SET: 'train2017' 19 | FLIP: true 20 | ROT_FACTOR: 40 21 | SCALE_FACTOR: 0.3 22 | MODEL: 23 | NAME: 'pose_resnet' 24 | PRETRAINED: 'models/pytorch/imagenet/resnet152-b121ed2d.pth' 25 | IMAGE_SIZE: 26 | - 192 27 | - 256 28 | HEATMAP_SIZE: 29 | - 48 30 | - 64 31 | SIGMA: 2 32 | NUM_JOINTS: 17 33 | TARGET_TYPE: 'gaussian' 34 | EXTRA: 35 | FINAL_CONV_KERNEL: 1 36 | DECONV_WITH_BIAS: false 37 | NUM_DECONV_LAYERS: 3 38 | NUM_DECONV_FILTERS: 39 | - 256 40 | - 256 41 | - 256 42 | NUM_DECONV_KERNELS: 43 | - 4 44 | - 4 45 | - 4 46 | NUM_LAYERS: 152 47 | LOSS: 48 | USE_TARGET_WEIGHT: true 49 | TRAIN: 50 | BATCH_SIZE_PER_GPU: 32 51 | SHUFFLE: true 52 | BEGIN_EPOCH: 0 53 | END_EPOCH: 140 54 | OPTIMIZER: 'adam' 55 | LR: 0.001 56 | LR_FACTOR: 0.1 57 | LR_STEP: 58 | - 90 59 | - 120 60 | WD: 0.0001 61 | GAMMA1: 0.99 62 | GAMMA2: 0.0 63 | MOMENTUM: 0.9 64 | NESTEROV: false 65 | TEST: 66 | BATCH_SIZE_PER_GPU: 32 67 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 68 | BBOX_THRE: 1.0 69 | IMAGE_THRE: 0.0 70 | IN_VIS_THRE: 0.2 71 | MODEL_FILE: '' 72 | NMS_THRE: 1.0 73 | OKS_THRE: 0.9 74 | FLIP_TEST: true 75 | POST_PROCESS: true 76 | SHIFT_HEATMAP: true 77 | USE_GT_BBOX: true 78 | DEBUG: 79 | DEBUG: true 80 | SAVE_BATCH_IMAGES_GT: true 81 | SAVE_BATCH_IMAGES_PRED: true 82 | SAVE_HEATMAPS_GT: true 83 | SAVE_HEATMAPS_PRED: true 84 | -------------------------------------------------------------------------------- /experiments/coco/resnet/res152_384x288_d256x3_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: false 15 | DATASET: 'coco' 16 | ROOT: 'data/coco/' 17 | TEST_SET: 'val2017' 18 | TRAIN_SET: 'train2017' 19 | FLIP: true 20 | ROT_FACTOR: 40 21 | SCALE_FACTOR: 0.3 22 | MODEL: 23 | NAME: 'pose_resnet' 24 | PRETRAINED: 'models/pytorch/imagenet/resnet152-b121ed2d.pth' 25 | IMAGE_SIZE: 26 | - 288 27 | - 384 28 | HEATMAP_SIZE: 29 | - 72 30 | - 96 31 | SIGMA: 3 32 | NUM_JOINTS: 17 33 | TARGET_TYPE: 'gaussian' 34 | EXTRA: 35 | FINAL_CONV_KERNEL: 1 36 | DECONV_WITH_BIAS: false 37 | NUM_DECONV_LAYERS: 3 38 | NUM_DECONV_FILTERS: 39 | - 256 40 | - 256 41 | - 256 42 | NUM_DECONV_KERNELS: 43 | - 4 44 | - 4 45 | - 4 46 | NUM_LAYERS: 152 47 | LOSS: 48 | USE_TARGET_WEIGHT: true 49 | TRAIN: 50 | BATCH_SIZE_PER_GPU: 32 51 | SHUFFLE: true 52 | BEGIN_EPOCH: 0 53 | END_EPOCH: 140 54 | OPTIMIZER: 'adam' 55 | LR: 0.001 56 | LR_FACTOR: 0.1 57 | LR_STEP: 58 | - 90 59 | - 120 60 | WD: 0.0001 61 | GAMMA1: 0.99 62 | GAMMA2: 0.0 63 | MOMENTUM: 0.9 64 | NESTEROV: false 65 | TEST: 66 | BATCH_SIZE_PER_GPU: 32 67 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 68 | BBOX_THRE: 1.0 69 | IMAGE_THRE: 0.0 70 | IN_VIS_THRE: 0.2 71 | MODEL_FILE: '' 72 | NMS_THRE: 1.0 73 | OKS_THRE: 0.9 74 | FLIP_TEST: true 75 | POST_PROCESS: true 76 | SHIFT_HEATMAP: true 77 | USE_GT_BBOX: true 78 | DEBUG: 79 | DEBUG: true 80 | SAVE_BATCH_IMAGES_GT: true 81 | SAVE_BATCH_IMAGES_PRED: true 82 | SAVE_HEATMAPS_GT: true 83 | SAVE_HEATMAPS_PRED: true 84 | -------------------------------------------------------------------------------- /experiments/coco/resnet/res50_256x192_d256x3_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: false 15 | DATASET: 'coco' 16 | ROOT: 'data/coco/' 17 | TEST_SET: 'val2017' 18 | TRAIN_SET: 'train2017' 19 | FLIP: true 20 | ROT_FACTOR: 40 21 | SCALE_FACTOR: 0.3 22 | MODEL: 23 | NAME: 'pose_resnet' 24 | PRETRAINED: 'models/pytorch/imagenet/resnet50-19c8e357.pth' 25 | IMAGE_SIZE: 26 | - 192 27 | - 256 28 | HEATMAP_SIZE: 29 | - 48 30 | - 64 31 | SIGMA: 2 32 | NUM_JOINTS: 17 33 | TARGET_TYPE: 'gaussian' 34 | EXTRA: 35 | FINAL_CONV_KERNEL: 1 36 | DECONV_WITH_BIAS: false 37 | NUM_DECONV_LAYERS: 3 38 | NUM_DECONV_FILTERS: 39 | - 256 40 | - 256 41 | - 256 42 | NUM_DECONV_KERNELS: 43 | - 4 44 | - 4 45 | - 4 46 | NUM_LAYERS: 50 47 | LOSS: 48 | USE_TARGET_WEIGHT: true 49 | TRAIN: 50 | BATCH_SIZE_PER_GPU: 32 51 | SHUFFLE: true 52 | BEGIN_EPOCH: 0 53 | END_EPOCH: 140 54 | OPTIMIZER: 'adam' 55 | LR: 0.001 56 | LR_FACTOR: 0.1 57 | LR_STEP: 58 | - 90 59 | - 120 60 | WD: 0.0001 61 | GAMMA1: 0.99 62 | GAMMA2: 0.0 63 | MOMENTUM: 0.9 64 | NESTEROV: false 65 | TEST: 66 | BATCH_SIZE_PER_GPU: 32 67 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 68 | BBOX_THRE: 1.0 69 | IMAGE_THRE: 0.0 70 | IN_VIS_THRE: 0.2 71 | MODEL_FILE: '' 72 | NMS_THRE: 1.0 73 | OKS_THRE: 0.9 74 | FLIP_TEST: true 75 | POST_PROCESS: true 76 | SHIFT_HEATMAP: true 77 | USE_GT_BBOX: true 78 | DEBUG: 79 | DEBUG: true 80 | SAVE_BATCH_IMAGES_GT: true 81 | SAVE_BATCH_IMAGES_PRED: true 82 | SAVE_HEATMAPS_GT: true 83 | SAVE_HEATMAPS_PRED: true 84 | -------------------------------------------------------------------------------- /experiments/coco/resnet/res50_384x288_d256x3_adam_lr1e-3.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1,2,3) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 24 11 | PRINT_FREQ: 100 12 | 13 | DATASET: 14 | COLOR_RGB: false 15 | DATASET: 'coco' 16 | ROOT: 'data/coco/' 17 | TEST_SET: 'val2017' 18 | TRAIN_SET: 'train2017' 19 | FLIP: true 20 | ROT_FACTOR: 40 21 | SCALE_FACTOR: 0.3 22 | MODEL: 23 | NAME: 'pose_resnet' 24 | PRETRAINED: 'models/pytorch/imagenet/resnet50-19c8e357.pth' 25 | IMAGE_SIZE: 26 | - 288 27 | - 384 28 | HEATMAP_SIZE: 29 | - 72 30 | - 96 31 | SIGMA: 3 32 | NUM_JOINTS: 17 33 | TARGET_TYPE: 'gaussian' 34 | EXTRA: 35 | FINAL_CONV_KERNEL: 1 36 | DECONV_WITH_BIAS: false 37 | NUM_DECONV_LAYERS: 3 38 | NUM_DECONV_FILTERS: 39 | - 256 40 | - 256 41 | - 256 42 | NUM_DECONV_KERNELS: 43 | - 4 44 | - 4 45 | - 4 46 | NUM_LAYERS: 50 47 | LOSS: 48 | USE_TARGET_WEIGHT: true 49 | TRAIN: 50 | BATCH_SIZE_PER_GPU: 32 51 | SHUFFLE: true 52 | BEGIN_EPOCH: 0 53 | END_EPOCH: 140 54 | OPTIMIZER: 'adam' 55 | LR: 0.001 56 | LR_FACTOR: 0.1 57 | LR_STEP: 58 | - 90 59 | - 120 60 | WD: 0.0001 61 | GAMMA1: 0.99 62 | GAMMA2: 0.0 63 | MOMENTUM: 0.9 64 | NESTEROV: false 65 | TEST: 66 | BATCH_SIZE_PER_GPU: 32 67 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 68 | BBOX_THRE: 1.0 69 | IMAGE_THRE: 0.0 70 | IN_VIS_THRE: 0.2 71 | MODEL_FILE: '' 72 | NMS_THRE: 1.0 73 | OKS_THRE: 0.9 74 | FLIP_TEST: true 75 | POST_PROCESS: true 76 | SHIFT_HEATMAP: true 77 | USE_GT_BBOX: true 78 | DEBUG: 79 | DEBUG: true 80 | SAVE_BATCH_IMAGES_GT: true 81 | SAVE_BATCH_IMAGES_PRED: true 82 | SAVE_HEATMAPS_GT: true 83 | SAVE_HEATMAPS_PRED: true 84 | -------------------------------------------------------------------------------- /experiments/infantpose/aggpose/aggpose_L_256x192.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 1 11 | PRINT_FREQ: 50 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'infantpose' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 9 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/InfantPose' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_aggpose 28 | NUM_JOINTS: 21 29 | PRETRAINED: '' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 192 33 | - 256 34 | HEATMAP_SIZE: 35 | - 48 36 | - 64 37 | SIGMA: 2 38 | 39 | LOSS: 40 | USE_TARGET_WEIGHT: true 41 | TRAIN: 42 | BATCH_SIZE_PER_GPU: 32 43 | SHUFFLE: true 44 | BEGIN_EPOCH: 0 45 | END_EPOCH: 100 46 | OPTIMIZER: adamw 47 | LR: 0.0001 48 | LR_FACTOR: 0.1 49 | LR_STEP: 50 | - 50 51 | - 80 52 | WD: 0.0001 53 | GAMMA1: 0.99 54 | GAMMA2: 0.0 55 | MOMENTUM: 0.9 56 | NESTEROV: false 57 | TEST: 58 | BATCH_SIZE_PER_GPU: 32 59 | COCO_BBOX_FILE: '' 60 | BBOX_THRE: 1.0 61 | IMAGE_THRE: 0.0 62 | IN_VIS_THRE: 0.2 63 | MODEL_FILE: '' 64 | NMS_THRE: 1.0 65 | OKS_THRE: 0.9 66 | USE_GT_BBOX: true 67 | FLIP_TEST: true 68 | POST_PROCESS: true 69 | SHIFT_HEATMAP: true 70 | DEBUG: 71 | DEBUG: true 72 | SAVE_BATCH_IMAGES_GT: true 73 | SAVE_BATCH_IMAGES_PRED: true 74 | SAVE_HEATMAPS_GT: true 75 | SAVE_HEATMAPS_PRED: true 76 | -------------------------------------------------------------------------------- /experiments/infantpose/hrnet/hrnet_w32_256x192.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 1 11 | PRINT_FREQ: 50 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'infantpose' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 9 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/InfantPose' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_hrnet 28 | NUM_JOINTS: 21 29 | PRETRAINED: 'models/hrnet/hrnet_w32-36af842e.pth' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 192 33 | - 256 34 | HEATMAP_SIZE: 35 | - 48 36 | - 64 37 | SIGMA: 2 38 | EXTRA: 39 | PRETRAINED_LAYERS: 40 | - 'conv1' 41 | - 'bn1' 42 | - 'conv2' 43 | - 'bn2' 44 | - 'layer1' 45 | - 'transition1' 46 | - 'stage2' 47 | - 'transition2' 48 | - 'stage3' 49 | - 'transition3' 50 | - 'stage4' 51 | FINAL_CONV_KERNEL: 1 52 | STAGE2: 53 | NUM_MODULES: 1 54 | NUM_BRANCHES: 2 55 | BLOCK: BASIC 56 | NUM_BLOCKS: 57 | - 4 58 | - 4 59 | NUM_CHANNELS: 60 | - 32 61 | - 64 62 | FUSE_METHOD: SUM 63 | STAGE3: 64 | NUM_MODULES: 4 65 | NUM_BRANCHES: 3 66 | BLOCK: BASIC 67 | NUM_BLOCKS: 68 | - 4 69 | - 4 70 | - 4 71 | NUM_CHANNELS: 72 | - 32 73 | - 64 74 | - 128 75 | FUSE_METHOD: SUM 76 | STAGE4: 77 | NUM_MODULES: 3 78 | NUM_BRANCHES: 4 79 | BLOCK: BASIC 80 | NUM_BLOCKS: 81 | - 4 82 | - 4 83 | - 4 84 | - 4 85 | NUM_CHANNELS: 86 | - 32 87 | - 64 88 | - 128 89 | - 256 90 | FUSE_METHOD: SUM 91 | LOSS: 92 | USE_TARGET_WEIGHT: true 93 | TRAIN: 94 | BATCH_SIZE_PER_GPU: 32 95 | SHUFFLE: true 96 | BEGIN_EPOCH: 0 97 | END_EPOCH: 100 98 | OPTIMIZER: adamw 99 | LR: 0.0001 100 | LR_FACTOR: 0.1 101 | LR_STEP: 102 | - 50 103 | - 80 104 | WD: 0.0001 105 | GAMMA1: 0.99 106 | GAMMA2: 0.0 107 | MOMENTUM: 0.9 108 | NESTEROV: false 109 | TEST: 110 | BATCH_SIZE_PER_GPU: 32 111 | COCO_BBOX_FILE: '' 112 | BBOX_THRE: 1.0 113 | IMAGE_THRE: 0.0 114 | IN_VIS_THRE: 0.2 115 | MODEL_FILE: '' 116 | NMS_THRE: 1.0 117 | OKS_THRE: 0.9 118 | USE_GT_BBOX: true 119 | FLIP_TEST: true 120 | POST_PROCESS: true 121 | SHIFT_HEATMAP: true 122 | DEBUG: 123 | DEBUG: true 124 | SAVE_BATCH_IMAGES_GT: true 125 | SAVE_BATCH_IMAGES_PRED: true 126 | SAVE_HEATMAPS_GT: true 127 | SAVE_HEATMAPS_PRED: true 128 | -------------------------------------------------------------------------------- /experiments/infantpose/resnet/resnet152_256x192.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: true 2 | CUDNN: 3 | BENCHMARK: true 4 | DETERMINISTIC: false 5 | ENABLED: true 6 | DATA_DIR: '' 7 | GPUS: (0,1) 8 | OUTPUT_DIR: 'output' 9 | LOG_DIR: 'log' 10 | WORKERS: 1 11 | PRINT_FREQ: 50 12 | 13 | DATASET: 14 | COLOR_RGB: true 15 | DATASET: 'infantpose' 16 | DATA_FORMAT: jpg 17 | FLIP: true 18 | NUM_JOINTS_HALF_BODY: 9 19 | PROB_HALF_BODY: 0.3 20 | ROOT: 'data/InfantPose' 21 | ROT_FACTOR: 45 22 | SCALE_FACTOR: 0.35 23 | TEST_SET: 'val2017' 24 | TRAIN_SET: 'train2017' 25 | MODEL: 26 | INIT_WEIGHTS: true 27 | NAME: pose_resnet 28 | NUM_JOINTS: 21 29 | PRETRAINED: '' 30 | TARGET_TYPE: gaussian 31 | IMAGE_SIZE: 32 | - 192 33 | - 256 34 | HEATMAP_SIZE: 35 | - 48 36 | - 64 37 | SIGMA: 2 38 | EXTRA: 39 | FINAL_CONV_KERNEL: 1 40 | DECONV_WITH_BIAS: false 41 | NUM_DECONV_LAYERS: 3 42 | NUM_DECONV_FILTERS: 43 | - 256 44 | - 256 45 | - 256 46 | NUM_DECONV_KERNELS: 47 | - 4 48 | - 4 49 | - 4 50 | NUM_LAYERS: 50 51 | LOSS: 52 | USE_TARGET_WEIGHT: true 53 | TRAIN: 54 | BATCH_SIZE_PER_GPU: 4 55 | SHUFFLE: true 56 | BEGIN_EPOCH: 0 57 | END_EPOCH: 100 58 | OPTIMIZER: adamw 59 | LR: 0.0001 60 | LR_FACTOR: 0.1 61 | LR_STEP: 62 | - 50 63 | - 80 64 | WD: 0.0001 65 | GAMMA1: 0.99 66 | GAMMA2: 0.0 67 | MOMENTUM: 0.9 68 | NESTEROV: false 69 | TEST: 70 | BATCH_SIZE_PER_GPU: 4 71 | COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json' 72 | BBOX_THRE: 1.0 73 | IMAGE_THRE: 0.0 74 | IN_VIS_THRE: 0.2 75 | MODEL_FILE: '' 76 | NMS_THRE: 1.0 77 | OKS_THRE: 0.9 78 | USE_GT_BBOX: true 79 | FLIP_TEST: true 80 | POST_PROCESS: true 81 | SHIFT_HEATMAP: true 82 | DEBUG: 83 | DEBUG: true 84 | SAVE_BATCH_IMAGES_GT: true 85 | SAVE_BATCH_IMAGES_PRED: true 86 | SAVE_HEATMAPS_GT: true 87 | SAVE_HEATMAPS_PRED: true -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd nms; python setup_linux.py build_ext --inplace; rm -rf build; cd ../../ 3 | clean: 4 | cd nms; rm *.so; cd ../../ 5 | -------------------------------------------------------------------------------- /lib/config/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) Microsoft 3 | # Licensed under the MIT License. 4 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from .default import _C as cfg 8 | from .default import update_config 9 | from .models import MODEL_EXTRAS 10 | -------------------------------------------------------------------------------- /lib/config/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/config/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/config/__pycache__/default.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/config/__pycache__/default.cpython-38.pyc -------------------------------------------------------------------------------- /lib/config/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/config/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /lib/config/models.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) Microsoft 3 | # Licensed under the MIT License. 4 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from __future__ import absolute_import 8 | from __future__ import division 9 | from __future__ import print_function 10 | 11 | from yacs.config import CfgNode as CN 12 | 13 | 14 | # pose_resnet related params 15 | POSE_RESNET = CN() 16 | POSE_RESNET.NUM_LAYERS = 50 17 | POSE_RESNET.DECONV_WITH_BIAS = False 18 | POSE_RESNET.NUM_DECONV_LAYERS = 3 19 | POSE_RESNET.NUM_DECONV_FILTERS = [256, 256, 256] 20 | POSE_RESNET.NUM_DECONV_KERNELS = [4, 4, 4] 21 | POSE_RESNET.FINAL_CONV_KERNEL = 1 22 | POSE_RESNET.PRETRAINED_LAYERS = ['*'] 23 | 24 | # pose_multi_resoluton_net related params 25 | POSE_HIGH_RESOLUTION_NET = CN() 26 | POSE_HIGH_RESOLUTION_NET.PRETRAINED_LAYERS = ['*'] 27 | POSE_HIGH_RESOLUTION_NET.STEM_INPLANES = 64 28 | POSE_HIGH_RESOLUTION_NET.FINAL_CONV_KERNEL = 1 29 | 30 | POSE_HIGH_RESOLUTION_NET.STAGE2 = CN() 31 | POSE_HIGH_RESOLUTION_NET.STAGE2.NUM_MODULES = 1 32 | POSE_HIGH_RESOLUTION_NET.STAGE2.NUM_BRANCHES = 2 33 | POSE_HIGH_RESOLUTION_NET.STAGE2.NUM_BLOCKS = [4, 4] 34 | POSE_HIGH_RESOLUTION_NET.STAGE2.NUM_CHANNELS = [32, 64] 35 | POSE_HIGH_RESOLUTION_NET.STAGE2.BLOCK = 'BASIC' 36 | POSE_HIGH_RESOLUTION_NET.STAGE2.FUSE_METHOD = 'SUM' 37 | 38 | POSE_HIGH_RESOLUTION_NET.STAGE3 = CN() 39 | POSE_HIGH_RESOLUTION_NET.STAGE3.NUM_MODULES = 1 40 | POSE_HIGH_RESOLUTION_NET.STAGE3.NUM_BRANCHES = 3 41 | POSE_HIGH_RESOLUTION_NET.STAGE3.NUM_BLOCKS = [4, 4, 4] 42 | POSE_HIGH_RESOLUTION_NET.STAGE3.NUM_CHANNELS = [32, 64, 128] 43 | POSE_HIGH_RESOLUTION_NET.STAGE3.BLOCK = 'BASIC' 44 | POSE_HIGH_RESOLUTION_NET.STAGE3.FUSE_METHOD = 'SUM' 45 | 46 | POSE_HIGH_RESOLUTION_NET.STAGE4 = CN() 47 | POSE_HIGH_RESOLUTION_NET.STAGE4.NUM_MODULES = 1 48 | POSE_HIGH_RESOLUTION_NET.STAGE4.NUM_BRANCHES = 4 49 | POSE_HIGH_RESOLUTION_NET.STAGE4.NUM_BLOCKS = [4, 4, 4, 4] 50 | POSE_HIGH_RESOLUTION_NET.STAGE4.NUM_CHANNELS = [32, 64, 128, 256] 51 | POSE_HIGH_RESOLUTION_NET.STAGE4.BLOCK = 'BASIC' 52 | POSE_HIGH_RESOLUTION_NET.STAGE4.FUSE_METHOD = 'SUM' 53 | 54 | 55 | MODEL_EXTRAS = { 56 | 'pose_resnet': POSE_RESNET, 57 | 'pose_high_resolution_net': POSE_HIGH_RESOLUTION_NET, 58 | } 59 | -------------------------------------------------------------------------------- /lib/core/__pycache__/evaluate.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/core/__pycache__/evaluate.cpython-38.pyc -------------------------------------------------------------------------------- /lib/core/__pycache__/function.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/core/__pycache__/function.cpython-38.pyc -------------------------------------------------------------------------------- /lib/core/__pycache__/inference.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/core/__pycache__/inference.cpython-38.pyc -------------------------------------------------------------------------------- /lib/core/__pycache__/loss.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/core/__pycache__/loss.cpython-38.pyc -------------------------------------------------------------------------------- /lib/core/evaluate.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) Microsoft 3 | # Licensed under the MIT License. 4 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from __future__ import absolute_import 8 | from __future__ import division 9 | from __future__ import print_function 10 | 11 | import numpy as np 12 | 13 | from core.inference import get_max_preds 14 | 15 | 16 | def calc_dists(preds, target, normalize): 17 | preds = preds.astype(np.float32) 18 | target = target.astype(np.float32) 19 | dists = np.zeros((preds.shape[1], preds.shape[0])) 20 | for n in range(preds.shape[0]): 21 | for c in range(preds.shape[1]): 22 | if target[n, c, 0] > 1 and target[n, c, 1] > 1: 23 | normed_preds = preds[n, c, :] / normalize[n] 24 | normed_targets = target[n, c, :] / normalize[n] 25 | dists[c, n] = np.linalg.norm(normed_preds - normed_targets) 26 | else: 27 | dists[c, n] = -1 28 | return dists 29 | 30 | 31 | def dist_acc(dists, thr=0.5): 32 | ''' Return percentage below threshold while ignoring values with a -1 ''' 33 | dist_cal = np.not_equal(dists, -1) 34 | num_dist_cal = dist_cal.sum() 35 | if num_dist_cal > 0: 36 | return np.less(dists[dist_cal], thr).sum() * 1.0 / num_dist_cal 37 | else: 38 | return -1 39 | 40 | 41 | def accuracy(output, target, hm_type='gaussian', thr=0.5): 42 | ''' 43 | Calculate accuracy according to PCK, 44 | but uses ground truth heatmap rather than x,y locations 45 | First value to be returned is average accuracy across 'idxs', 46 | followed by individual accuracies 47 | ''' 48 | idx = list(range(output.shape[1])) 49 | norm = 1.0 50 | if hm_type == 'gaussian': 51 | pred, _ = get_max_preds(output) 52 | target, _ = get_max_preds(target) 53 | h = output.shape[2] 54 | w = output.shape[3] 55 | norm = np.ones((pred.shape[0], 2)) * np.array([h, w]) / 10 56 | dists = calc_dists(pred, target, norm) 57 | 58 | acc = np.zeros((len(idx) + 1)) 59 | avg_acc = 0 60 | cnt = 0 61 | 62 | for i in range(len(idx)): 63 | acc[i + 1] = dist_acc(dists[idx[i]]) 64 | if acc[i + 1] >= 0: 65 | avg_acc = avg_acc + acc[i + 1] 66 | cnt += 1 67 | 68 | avg_acc = avg_acc / cnt if cnt != 0 else 0 69 | if cnt != 0: 70 | acc[0] = avg_acc 71 | return acc, avg_acc, cnt, pred 72 | 73 | 74 | -------------------------------------------------------------------------------- /lib/core/loss.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) Microsoft 3 | # Licensed under the MIT License. 4 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from __future__ import absolute_import 8 | from __future__ import division 9 | from __future__ import print_function 10 | 11 | import torch 12 | import torch.nn as nn 13 | 14 | 15 | class JointsMSELoss(nn.Module): 16 | def __init__(self, use_target_weight): 17 | super(JointsMSELoss, self).__init__() 18 | self.criterion = nn.MSELoss(reduction='mean') 19 | self.use_target_weight = use_target_weight 20 | 21 | def forward(self, output, target, target_weight): 22 | batch_size = output.size(0) 23 | num_joints = output.size(1) 24 | heatmaps_pred = output.reshape((batch_size, num_joints, -1)).split(1, 1) 25 | heatmaps_gt = target.reshape((batch_size, num_joints, -1)).split(1, 1) 26 | loss = 0 27 | 28 | for idx in range(num_joints): 29 | heatmap_pred = heatmaps_pred[idx].squeeze() 30 | heatmap_gt = heatmaps_gt[idx].squeeze() 31 | if self.use_target_weight: 32 | loss += 0.5 * self.criterion( 33 | heatmap_pred.mul(target_weight[:, idx]), 34 | heatmap_gt.mul(target_weight[:, idx]) 35 | ) 36 | else: 37 | loss += 0.5 * self.criterion(heatmap_pred, heatmap_gt) 38 | 39 | return loss / num_joints 40 | 41 | 42 | class JointsOHKMMSELoss(nn.Module): 43 | def __init__(self, use_target_weight, topk=8): 44 | super(JointsOHKMMSELoss, self).__init__() 45 | self.criterion = nn.MSELoss(reduction='none') 46 | self.use_target_weight = use_target_weight 47 | self.topk = topk 48 | 49 | def ohkm(self, loss): 50 | ohkm_loss = 0. 51 | for i in range(loss.size()[0]): 52 | sub_loss = loss[i] 53 | topk_val, topk_idx = torch.topk( 54 | sub_loss, k=self.topk, dim=0, sorted=False 55 | ) 56 | tmp_loss = torch.gather(sub_loss, 0, topk_idx) 57 | ohkm_loss += torch.sum(tmp_loss) / self.topk 58 | ohkm_loss /= loss.size()[0] 59 | return ohkm_loss 60 | 61 | def forward(self, output, target, target_weight): 62 | batch_size = output.size(0) 63 | num_joints = output.size(1) 64 | heatmaps_pred = output.reshape((batch_size, num_joints, -1)).split(1, 1) 65 | heatmaps_gt = target.reshape((batch_size, num_joints, -1)).split(1, 1) 66 | 67 | loss = [] 68 | for idx in range(num_joints): 69 | heatmap_pred = heatmaps_pred[idx].squeeze() 70 | heatmap_gt = heatmaps_gt[idx].squeeze() 71 | if self.use_target_weight: 72 | loss.append(0.5 * self.criterion( 73 | heatmap_pred.mul(target_weight[:, idx]), 74 | heatmap_gt.mul(target_weight[:, idx]) 75 | )) 76 | else: 77 | loss.append( 78 | 0.5 * self.criterion(heatmap_pred, heatmap_gt) 79 | ) 80 | 81 | loss = [l.mean(dim=1).unsqueeze(dim=1) for l in loss] 82 | loss = torch.cat(loss, dim=1) 83 | 84 | return self.ohkm(loss) 85 | -------------------------------------------------------------------------------- /lib/dataset/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) Microsoft 3 | # Licensed under the MIT License. 4 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from __future__ import absolute_import 8 | from __future__ import division 9 | from __future__ import print_function 10 | 11 | from .mpii import MPIIDataset as mpii 12 | from .coco import COCODataset as coco 13 | from .infantpose import InfantPoseDataset as infantpose 14 | -------------------------------------------------------------------------------- /lib/models/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) SZAR-Lab 3 | # Licensed under the MIT License. 4 | # Modified by Iroh Cao (irohcao@gmail.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from __future__ import absolute_import 8 | from __future__ import division 9 | from __future__ import print_function 10 | 11 | from __future__ import absolute_import 12 | from __future__ import division 13 | from __future__ import print_function 14 | 15 | import models.pose_resnet 16 | import models.pose_hrnet 17 | import models.pose_segformer 18 | import models.pose_aggpose 19 | -------------------------------------------------------------------------------- /lib/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/models/__pycache__/pose_aggpose.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/models/__pycache__/pose_aggpose.cpython-38.pyc -------------------------------------------------------------------------------- /lib/models/__pycache__/pose_hrnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/models/__pycache__/pose_hrnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/models/__pycache__/pose_resnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/models/__pycache__/pose_resnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/models/__pycache__/pose_segformer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/models/__pycache__/pose_segformer.cpython-38.pyc -------------------------------------------------------------------------------- /lib/nms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/nms/__init__.py -------------------------------------------------------------------------------- /lib/nms/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/nms/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/nms/__pycache__/nms.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/nms/__pycache__/nms.cpython-38.pyc -------------------------------------------------------------------------------- /lib/nms/cpu_nms.cpython-38-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/nms/cpu_nms.cpython-38-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /lib/nms/cpu_nms.pyx: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) Microsoft 3 | # Licensed under the MIT License. 4 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from __future__ import absolute_import 8 | from __future__ import division 9 | from __future__ import print_function 10 | 11 | import numpy as np 12 | cimport numpy as np 13 | 14 | cdef inline np.float32_t max(np.float32_t a, np.float32_t b): 15 | return a if a >= b else b 16 | 17 | cdef inline np.float32_t min(np.float32_t a, np.float32_t b): 18 | return a if a <= b else b 19 | 20 | def cpu_nms(np.ndarray[np.float32_t, ndim=2] dets, np.float thresh): 21 | cdef np.ndarray[np.float32_t, ndim=1] x1 = dets[:, 0] 22 | cdef np.ndarray[np.float32_t, ndim=1] y1 = dets[:, 1] 23 | cdef np.ndarray[np.float32_t, ndim=1] x2 = dets[:, 2] 24 | cdef np.ndarray[np.float32_t, ndim=1] y2 = dets[:, 3] 25 | cdef np.ndarray[np.float32_t, ndim=1] scores = dets[:, 4] 26 | 27 | cdef np.ndarray[np.float32_t, ndim=1] areas = (x2 - x1 + 1) * (y2 - y1 + 1) 28 | cdef np.ndarray[np.int_t, ndim=1] order = scores.argsort()[::-1].astype('i') 29 | 30 | cdef int ndets = dets.shape[0] 31 | cdef np.ndarray[np.int_t, ndim=1] suppressed = \ 32 | np.zeros((ndets), dtype=np.int) 33 | 34 | # nominal indices 35 | cdef int _i, _j 36 | # sorted indices 37 | cdef int i, j 38 | # temp variables for box i's (the box currently under consideration) 39 | cdef np.float32_t ix1, iy1, ix2, iy2, iarea 40 | # variables for computing overlap with box j (lower scoring box) 41 | cdef np.float32_t xx1, yy1, xx2, yy2 42 | cdef np.float32_t w, h 43 | cdef np.float32_t inter, ovr 44 | 45 | keep = [] 46 | for _i in range(ndets): 47 | i = order[_i] 48 | if suppressed[i] == 1: 49 | continue 50 | keep.append(i) 51 | ix1 = x1[i] 52 | iy1 = y1[i] 53 | ix2 = x2[i] 54 | iy2 = y2[i] 55 | iarea = areas[i] 56 | for _j in range(_i + 1, ndets): 57 | j = order[_j] 58 | if suppressed[j] == 1: 59 | continue 60 | xx1 = max(ix1, x1[j]) 61 | yy1 = max(iy1, y1[j]) 62 | xx2 = min(ix2, x2[j]) 63 | yy2 = min(iy2, y2[j]) 64 | w = max(0.0, xx2 - xx1 + 1) 65 | h = max(0.0, yy2 - yy1 + 1) 66 | inter = w * h 67 | ovr = inter / (iarea + areas[j] - inter) 68 | if ovr >= thresh: 69 | suppressed[j] = 1 70 | 71 | return keep 72 | -------------------------------------------------------------------------------- /lib/nms/gpu_nms.cpython-38-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/nms/gpu_nms.cpython-38-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /lib/nms/gpu_nms.hpp: -------------------------------------------------------------------------------- 1 | void _nms(int* keep_out, int* num_out, const float* boxes_host, int boxes_num, 2 | int boxes_dim, float nms_overlap_thresh, int device_id); 3 | -------------------------------------------------------------------------------- /lib/nms/gpu_nms.pyx: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) Microsoft 3 | # Licensed under the MIT License. 4 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from __future__ import absolute_import 8 | from __future__ import division 9 | from __future__ import print_function 10 | 11 | import numpy as np 12 | cimport numpy as np 13 | 14 | assert sizeof(int) == sizeof(np.int32_t) 15 | 16 | cdef extern from "gpu_nms.hpp": 17 | void _nms(np.int32_t*, int*, np.float32_t*, int, int, float, int) 18 | 19 | def gpu_nms(np.ndarray[np.float32_t, ndim=2] dets, np.float thresh, 20 | np.int32_t device_id=0): 21 | cdef int boxes_num = dets.shape[0] 22 | cdef int boxes_dim = dets.shape[1] 23 | cdef int num_out 24 | cdef np.ndarray[np.int32_t, ndim=1] \ 25 | keep = np.zeros(boxes_num, dtype=np.int32) 26 | cdef np.ndarray[np.float32_t, ndim=1] \ 27 | scores = dets[:, 4] 28 | cdef np.ndarray[np.int32_t, ndim=1] \ 29 | order = scores.argsort()[::-1].astype(np.int32) 30 | cdef np.ndarray[np.float32_t, ndim=2] \ 31 | sorted_dets = dets[order, :] 32 | _nms(&keep[0], &num_out, &sorted_dets[0, 0], boxes_num, boxes_dim, thresh, device_id) 33 | keep = keep[:num_out] 34 | return list(order[keep]) 35 | -------------------------------------------------------------------------------- /lib/test_model.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) SZAR-Lab 3 | # Licensed under the MIT License. 4 | # Modified by Iroh Cao (irohcao@gmail.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | import argparse 8 | import os 9 | import pprint 10 | import shutil 11 | 12 | import torch 13 | import torch.nn.parallel 14 | import torch.backends.cudnn as cudnn 15 | import torch.optim 16 | import torch.utils.data 17 | import torch.utils.data.distributed 18 | import torchvision.transforms as transforms 19 | from tensorboardX import SummaryWriter 20 | 21 | from models.pose_aggpose import get_pose_net 22 | from config import cfg 23 | from config import update_config 24 | 25 | def parse_args(): 26 | parser = argparse.ArgumentParser(description='Train keypoints network') 27 | # general 28 | parser.add_argument('--cfg', 29 | help='experiment configure file name', 30 | required=True, 31 | type=str) 32 | 33 | parser.add_argument('opts', 34 | help="Modify config options using the command-line", 35 | default=None, 36 | nargs=argparse.REMAINDER) 37 | 38 | # philly 39 | parser.add_argument('--modelDir', 40 | help='model directory', 41 | type=str, 42 | default='') 43 | parser.add_argument('--logDir', 44 | help='log directory', 45 | type=str, 46 | default='') 47 | parser.add_argument('--dataDir', 48 | help='data directory', 49 | type=str, 50 | default='') 51 | parser.add_argument('--prevModelDir', 52 | help='prev Model directory', 53 | type=str, 54 | default='') 55 | 56 | args = parser.parse_args() 57 | 58 | return args 59 | 60 | 61 | args = parse_args() 62 | update_config(cfg, args) 63 | 64 | model = get_pose_net(cfg, True) 65 | 66 | dummy_input = torch.randn((2, 3 ,256, 192)) 67 | output = model(dummy_input) 68 | 69 | print(output.shape) -------------------------------------------------------------------------------- /lib/timm/__init__.py: -------------------------------------------------------------------------------- 1 | from .version import __version__ 2 | from .models import create_model, list_models, is_model, list_modules, model_entrypoint, \ 3 | is_scriptable, is_exportable, set_scriptable, set_exportable, has_model_default_key, is_model_default_key, \ 4 | get_model_default_value, is_model_pretrained 5 | -------------------------------------------------------------------------------- /lib/timm/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/__pycache__/version.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/__pycache__/version.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .auto_augment import RandAugment, AutoAugment, rand_augment_ops, auto_augment_policy,\ 2 | rand_augment_transform, auto_augment_transform 3 | from .config import resolve_data_config 4 | from .constants import * 5 | from .dataset import ImageDataset, IterableImageDataset, AugMixDataset 6 | from .dataset_factory import create_dataset 7 | from .loader import create_loader 8 | from .mixup import Mixup, FastCollateMixup 9 | from .parsers import create_parser 10 | from .real_labels import RealLabelsImagenet 11 | from .transforms import * 12 | from .transforms_factory import create_transform -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/auto_augment.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/auto_augment.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/config.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/config.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/constants.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/constants.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/dataset.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/dataset.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/dataset_factory.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/dataset_factory.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/distributed_sampler.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/distributed_sampler.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/loader.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/loader.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/mixup.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/mixup.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/random_erasing.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/random_erasing.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/real_labels.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/real_labels.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/transforms.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/transforms.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/__pycache__/transforms_factory.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/__pycache__/transforms_factory.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/config.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from .constants import * 3 | 4 | 5 | _logger = logging.getLogger(__name__) 6 | 7 | 8 | def resolve_data_config(args, default_cfg={}, model=None, use_test_size=False, verbose=False): 9 | new_config = {} 10 | default_cfg = default_cfg 11 | if not default_cfg and model is not None and hasattr(model, 'default_cfg'): 12 | default_cfg = model.default_cfg 13 | 14 | # Resolve input/image size 15 | in_chans = 3 16 | if 'chans' in args and args['chans'] is not None: 17 | in_chans = args['chans'] 18 | 19 | input_size = (in_chans, 224, 224) 20 | if 'input_size' in args and args['input_size'] is not None: 21 | assert isinstance(args['input_size'], (tuple, list)) 22 | assert len(args['input_size']) == 3 23 | input_size = tuple(args['input_size']) 24 | in_chans = input_size[0] # input_size overrides in_chans 25 | elif 'img_size' in args and args['img_size'] is not None: 26 | assert isinstance(args['img_size'], int) 27 | input_size = (in_chans, args['img_size'], args['img_size']) 28 | else: 29 | if use_test_size and 'test_input_size' in default_cfg: 30 | input_size = default_cfg['test_input_size'] 31 | elif 'input_size' in default_cfg: 32 | input_size = default_cfg['input_size'] 33 | new_config['input_size'] = input_size 34 | 35 | # resolve interpolation method 36 | new_config['interpolation'] = 'bicubic' 37 | if 'interpolation' in args and args['interpolation']: 38 | new_config['interpolation'] = args['interpolation'] 39 | elif 'interpolation' in default_cfg: 40 | new_config['interpolation'] = default_cfg['interpolation'] 41 | 42 | # resolve dataset + model mean for normalization 43 | new_config['mean'] = IMAGENET_DEFAULT_MEAN 44 | if 'mean' in args and args['mean'] is not None: 45 | mean = tuple(args['mean']) 46 | if len(mean) == 1: 47 | mean = tuple(list(mean) * in_chans) 48 | else: 49 | assert len(mean) == in_chans 50 | new_config['mean'] = mean 51 | elif 'mean' in default_cfg: 52 | new_config['mean'] = default_cfg['mean'] 53 | 54 | # resolve dataset + model std deviation for normalization 55 | new_config['std'] = IMAGENET_DEFAULT_STD 56 | if 'std' in args and args['std'] is not None: 57 | std = tuple(args['std']) 58 | if len(std) == 1: 59 | std = tuple(list(std) * in_chans) 60 | else: 61 | assert len(std) == in_chans 62 | new_config['std'] = std 63 | elif 'std' in default_cfg: 64 | new_config['std'] = default_cfg['std'] 65 | 66 | # resolve default crop percentage 67 | new_config['crop_pct'] = DEFAULT_CROP_PCT 68 | if 'crop_pct' in args and args['crop_pct'] is not None: 69 | new_config['crop_pct'] = args['crop_pct'] 70 | elif 'crop_pct' in default_cfg: 71 | new_config['crop_pct'] = default_cfg['crop_pct'] 72 | 73 | if verbose: 74 | _logger.info('Data processing configuration for current model + dataset:') 75 | for n, v in new_config.items(): 76 | _logger.info('\t%s: %s' % (n, str(v))) 77 | 78 | return new_config 79 | -------------------------------------------------------------------------------- /lib/timm/data/constants.py: -------------------------------------------------------------------------------- 1 | DEFAULT_CROP_PCT = 0.875 2 | IMAGENET_DEFAULT_MEAN = (0.485, 0.456, 0.406) 3 | IMAGENET_DEFAULT_STD = (0.229, 0.224, 0.225) 4 | IMAGENET_INCEPTION_MEAN = (0.5, 0.5, 0.5) 5 | IMAGENET_INCEPTION_STD = (0.5, 0.5, 0.5) 6 | IMAGENET_DPN_MEAN = (124 / 255, 117 / 255, 104 / 255) 7 | IMAGENET_DPN_STD = tuple([1 / (.0167 * 255)] * 3) 8 | -------------------------------------------------------------------------------- /lib/timm/data/parsers/__init__.py: -------------------------------------------------------------------------------- 1 | from .parser_factory import create_parser 2 | -------------------------------------------------------------------------------- /lib/timm/data/parsers/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/parsers/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/parsers/__pycache__/class_map.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/parsers/__pycache__/class_map.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/parsers/__pycache__/constants.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/parsers/__pycache__/constants.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/parsers/__pycache__/parser.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/parsers/__pycache__/parser.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/parsers/__pycache__/parser_factory.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/parsers/__pycache__/parser_factory.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/parsers/__pycache__/parser_image_folder.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/parsers/__pycache__/parser_image_folder.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/parsers/__pycache__/parser_image_in_tar.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/parsers/__pycache__/parser_image_in_tar.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/parsers/__pycache__/parser_image_tar.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/data/parsers/__pycache__/parser_image_tar.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/data/parsers/class_map.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def load_class_map(map_or_filename, root=''): 5 | if isinstance(map_or_filename, dict): 6 | assert dict, 'class_map dict must be non-empty' 7 | return map_or_filename 8 | class_map_path = map_or_filename 9 | if not os.path.exists(class_map_path): 10 | class_map_path = os.path.join(root, class_map_path) 11 | assert os.path.exists(class_map_path), 'Cannot locate specified class map file (%s)' % map_or_filename 12 | class_map_ext = os.path.splitext(map_or_filename)[-1].lower() 13 | if class_map_ext == '.txt': 14 | with open(class_map_path) as f: 15 | class_to_idx = {v.strip(): k for k, v in enumerate(f)} 16 | else: 17 | assert False, f'Unsupported class map file extension ({class_map_ext}).' 18 | return class_to_idx 19 | 20 | -------------------------------------------------------------------------------- /lib/timm/data/parsers/constants.py: -------------------------------------------------------------------------------- 1 | IMG_EXTENSIONS = ('.png', '.jpg', '.jpeg') 2 | -------------------------------------------------------------------------------- /lib/timm/data/parsers/parser.py: -------------------------------------------------------------------------------- 1 | from abc import abstractmethod 2 | 3 | 4 | class Parser: 5 | def __init__(self): 6 | pass 7 | 8 | @abstractmethod 9 | def _filename(self, index, basename=False, absolute=False): 10 | pass 11 | 12 | def filename(self, index, basename=False, absolute=False): 13 | return self._filename(index, basename=basename, absolute=absolute) 14 | 15 | def filenames(self, basename=False, absolute=False): 16 | return [self._filename(index, basename=basename, absolute=absolute) for index in range(len(self))] 17 | 18 | -------------------------------------------------------------------------------- /lib/timm/data/parsers/parser_factory.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from .parser_image_folder import ParserImageFolder 4 | from .parser_image_tar import ParserImageTar 5 | from .parser_image_in_tar import ParserImageInTar 6 | 7 | 8 | def create_parser(name, root, split='train', **kwargs): 9 | name = name.lower() 10 | name = name.split('/', 2) 11 | prefix = '' 12 | if len(name) > 1: 13 | prefix = name[0] 14 | name = name[-1] 15 | 16 | # FIXME improve the selection right now just tfds prefix or fallback path, will need options to 17 | # explicitly select other options shortly 18 | if prefix == 'tfds': 19 | from .parser_tfds import ParserTfds # defer tensorflow import 20 | parser = ParserTfds(root, name, split=split, **kwargs) 21 | else: 22 | assert os.path.exists(root) 23 | # default fallback path (backwards compat), use image tar if root is a .tar file, otherwise image folder 24 | # FIXME support split here, in parser? 25 | if os.path.isfile(root) and os.path.splitext(root)[1] == '.tar': 26 | parser = ParserImageInTar(root, **kwargs) 27 | else: 28 | parser = ParserImageFolder(root, **kwargs) 29 | return parser 30 | -------------------------------------------------------------------------------- /lib/timm/data/parsers/parser_image_folder.py: -------------------------------------------------------------------------------- 1 | """ A dataset parser that reads images from folders 2 | 3 | Folders are scannerd recursively to find image files. Labels are based 4 | on the folder hierarchy, just leaf folders by default. 5 | 6 | Hacked together by / Copyright 2020 Ross Wightman 7 | """ 8 | import os 9 | 10 | from timm.utils.misc import natural_key 11 | 12 | from .parser import Parser 13 | from .class_map import load_class_map 14 | from .constants import IMG_EXTENSIONS 15 | 16 | 17 | def find_images_and_targets(folder, types=IMG_EXTENSIONS, class_to_idx=None, leaf_name_only=True, sort=True): 18 | labels = [] 19 | filenames = [] 20 | for root, subdirs, files in os.walk(folder, topdown=False, followlinks=True): 21 | rel_path = os.path.relpath(root, folder) if (root != folder) else '' 22 | label = os.path.basename(rel_path) if leaf_name_only else rel_path.replace(os.path.sep, '_') 23 | for f in files: 24 | base, ext = os.path.splitext(f) 25 | if ext.lower() in types: 26 | filenames.append(os.path.join(root, f)) 27 | labels.append(label) 28 | if class_to_idx is None: 29 | # building class index 30 | unique_labels = set(labels) 31 | sorted_labels = list(sorted(unique_labels, key=natural_key)) 32 | class_to_idx = {c: idx for idx, c in enumerate(sorted_labels)} 33 | images_and_targets = [(f, class_to_idx[l]) for f, l in zip(filenames, labels) if l in class_to_idx] 34 | if sort: 35 | images_and_targets = sorted(images_and_targets, key=lambda k: natural_key(k[0])) 36 | return images_and_targets, class_to_idx 37 | 38 | 39 | class ParserImageFolder(Parser): 40 | 41 | def __init__( 42 | self, 43 | root, 44 | class_map=''): 45 | super().__init__() 46 | 47 | self.root = root 48 | class_to_idx = None 49 | if class_map: 50 | class_to_idx = load_class_map(class_map, root) 51 | self.samples, self.class_to_idx = find_images_and_targets(root, class_to_idx=class_to_idx) 52 | if len(self.samples) == 0: 53 | raise RuntimeError( 54 | f'Found 0 images in subfolders of {root}. Supported image extensions are {", ".join(IMG_EXTENSIONS)}') 55 | 56 | def __getitem__(self, index): 57 | path, target = self.samples[index] 58 | return open(path, 'rb'), target 59 | 60 | def __len__(self): 61 | return len(self.samples) 62 | 63 | def _filename(self, index, basename=False, absolute=False): 64 | filename = self.samples[index][0] 65 | if basename: 66 | filename = os.path.basename(filename) 67 | elif not absolute: 68 | filename = os.path.relpath(filename, self.root) 69 | return filename 70 | -------------------------------------------------------------------------------- /lib/timm/data/parsers/parser_image_tar.py: -------------------------------------------------------------------------------- 1 | """ A dataset parser that reads single tarfile based datasets 2 | 3 | This parser can read datasets consisting if a single tarfile containing images. 4 | I am planning to deprecated it in favour of ParerImageInTar. 5 | 6 | Hacked together by / Copyright 2020 Ross Wightman 7 | """ 8 | import os 9 | import tarfile 10 | 11 | from .parser import Parser 12 | from .class_map import load_class_map 13 | from .constants import IMG_EXTENSIONS 14 | from timm.utils.misc import natural_key 15 | 16 | 17 | def extract_tarinfo(tarfile, class_to_idx=None, sort=True): 18 | files = [] 19 | labels = [] 20 | for ti in tarfile.getmembers(): 21 | if not ti.isfile(): 22 | continue 23 | dirname, basename = os.path.split(ti.path) 24 | label = os.path.basename(dirname) 25 | ext = os.path.splitext(basename)[1] 26 | if ext.lower() in IMG_EXTENSIONS: 27 | files.append(ti) 28 | labels.append(label) 29 | if class_to_idx is None: 30 | unique_labels = set(labels) 31 | sorted_labels = list(sorted(unique_labels, key=natural_key)) 32 | class_to_idx = {c: idx for idx, c in enumerate(sorted_labels)} 33 | tarinfo_and_targets = [(f, class_to_idx[l]) for f, l in zip(files, labels) if l in class_to_idx] 34 | if sort: 35 | tarinfo_and_targets = sorted(tarinfo_and_targets, key=lambda k: natural_key(k[0].path)) 36 | return tarinfo_and_targets, class_to_idx 37 | 38 | 39 | class ParserImageTar(Parser): 40 | """ Single tarfile dataset where classes are mapped to folders within tar 41 | NOTE: This class is being deprecated in favour of the more capable ParserImageInTar that can 42 | operate on folders of tars or tars in tars. 43 | """ 44 | def __init__(self, root, class_map=''): 45 | super().__init__() 46 | 47 | class_to_idx = None 48 | if class_map: 49 | class_to_idx = load_class_map(class_map, root) 50 | assert os.path.isfile(root) 51 | self.root = root 52 | 53 | with tarfile.open(root) as tf: # cannot keep this open across processes, reopen later 54 | self.samples, self.class_to_idx = extract_tarinfo(tf, class_to_idx) 55 | self.imgs = self.samples 56 | self.tarfile = None # lazy init in __getitem__ 57 | 58 | def __getitem__(self, index): 59 | if self.tarfile is None: 60 | self.tarfile = tarfile.open(self.root) 61 | tarinfo, target = self.samples[index] 62 | fileobj = self.tarfile.extractfile(tarinfo) 63 | return fileobj, target 64 | 65 | def __len__(self): 66 | return len(self.samples) 67 | 68 | def _filename(self, index, basename=False, absolute=False): 69 | filename = self.samples[index][0].name 70 | if basename: 71 | filename = os.path.basename(filename) 72 | return filename 73 | -------------------------------------------------------------------------------- /lib/timm/data/real_labels.py: -------------------------------------------------------------------------------- 1 | """ Real labels evaluator for ImageNet 2 | Paper: `Are we done with ImageNet?` - https://arxiv.org/abs/2006.07159 3 | Based on Numpy example at https://github.com/google-research/reassessed-imagenet 4 | 5 | Hacked together by / Copyright 2020 Ross Wightman 6 | """ 7 | import os 8 | import json 9 | import numpy as np 10 | 11 | 12 | class RealLabelsImagenet: 13 | 14 | def __init__(self, filenames, real_json='real.json', topk=(1, 5)): 15 | with open(real_json) as real_labels: 16 | real_labels = json.load(real_labels) 17 | real_labels = {f'ILSVRC2012_val_{i + 1:08d}.JPEG': labels for i, labels in enumerate(real_labels)} 18 | self.real_labels = real_labels 19 | self.filenames = filenames 20 | assert len(self.filenames) == len(self.real_labels) 21 | self.topk = topk 22 | self.is_correct = {k: [] for k in topk} 23 | self.sample_idx = 0 24 | 25 | def add_result(self, output): 26 | maxk = max(self.topk) 27 | _, pred_batch = output.topk(maxk, 1, True, True) 28 | pred_batch = pred_batch.cpu().numpy() 29 | for pred in pred_batch: 30 | filename = self.filenames[self.sample_idx] 31 | filename = os.path.basename(filename) 32 | if self.real_labels[filename]: 33 | for k in self.topk: 34 | self.is_correct[k].append( 35 | any([p in self.real_labels[filename] for p in pred[:k]])) 36 | self.sample_idx += 1 37 | 38 | def get_accuracy(self, k=None): 39 | if k is None: 40 | return {k: float(np.mean(self.is_correct[k])) * 100 for k in self.topk} 41 | else: 42 | return float(np.mean(self.is_correct[k])) * 100 43 | -------------------------------------------------------------------------------- /lib/timm/loss/__init__.py: -------------------------------------------------------------------------------- 1 | from .asymmetric_loss import AsymmetricLossMultiLabel, AsymmetricLossSingleLabel 2 | from .binary_cross_entropy import BinaryCrossEntropy 3 | from .cross_entropy import LabelSmoothingCrossEntropy, SoftTargetCrossEntropy 4 | from .jsd import JsdCrossEntropy 5 | -------------------------------------------------------------------------------- /lib/timm/loss/binary_cross_entropy.py: -------------------------------------------------------------------------------- 1 | """ Binary Cross Entropy w/ a few extras 2 | 3 | Hacked together by / Copyright 2021 Ross Wightman 4 | """ 5 | from typing import Optional 6 | 7 | import torch 8 | import torch.nn as nn 9 | import torch.nn.functional as F 10 | 11 | 12 | class BinaryCrossEntropy(nn.Module): 13 | """ BCE with optional one-hot from dense targets, label smoothing, thresholding 14 | NOTE for experiments comparing CE to BCE /w label smoothing, may remove 15 | """ 16 | def __init__( 17 | self, smoothing=0.1, target_threshold: Optional[float] = None, weight: Optional[torch.Tensor] = None, 18 | reduction: str = 'mean', pos_weight: Optional[torch.Tensor] = None): 19 | super(BinaryCrossEntropy, self).__init__() 20 | assert 0. <= smoothing < 1.0 21 | self.smoothing = smoothing 22 | self.target_threshold = target_threshold 23 | self.reduction = reduction 24 | self.register_buffer('weight', weight) 25 | self.register_buffer('pos_weight', pos_weight) 26 | 27 | def forward(self, x: torch.Tensor, target: torch.Tensor) -> torch.Tensor: 28 | assert x.shape[0] == target.shape[0] 29 | if target.shape != x.shape: 30 | # NOTE currently assume smoothing or other label softening is applied upstream if targets are already sparse 31 | num_classes = x.shape[-1] 32 | # FIXME should off/on be different for smoothing w/ BCE? Other impl out there differ 33 | off_value = self.smoothing / num_classes 34 | on_value = 1. - self.smoothing + off_value 35 | target = target.long().view(-1, 1) 36 | target = torch.full( 37 | (target.size()[0], num_classes), 38 | off_value, 39 | device=x.device, dtype=x.dtype).scatter_(1, target, on_value) 40 | if self.target_threshold is not None: 41 | # Make target 0, or 1 if threshold set 42 | target = target.gt(self.target_threshold).to(dtype=target.dtype) 43 | return F.binary_cross_entropy_with_logits( 44 | x, target, 45 | self.weight, 46 | pos_weight=self.pos_weight, 47 | reduction=self.reduction) 48 | -------------------------------------------------------------------------------- /lib/timm/loss/cross_entropy.py: -------------------------------------------------------------------------------- 1 | """ Cross Entropy w/ smoothing or soft targets 2 | 3 | Hacked together by / Copyright 2021 Ross Wightman 4 | """ 5 | 6 | import torch 7 | import torch.nn as nn 8 | import torch.nn.functional as F 9 | 10 | 11 | class LabelSmoothingCrossEntropy(nn.Module): 12 | """ NLL loss with label smoothing. 13 | """ 14 | def __init__(self, smoothing=0.1): 15 | super(LabelSmoothingCrossEntropy, self).__init__() 16 | assert smoothing < 1.0 17 | self.smoothing = smoothing 18 | self.confidence = 1. - smoothing 19 | 20 | def forward(self, x: torch.Tensor, target: torch.Tensor) -> torch.Tensor: 21 | logprobs = F.log_softmax(x, dim=-1) 22 | nll_loss = -logprobs.gather(dim=-1, index=target.unsqueeze(1)) 23 | nll_loss = nll_loss.squeeze(1) 24 | smooth_loss = -logprobs.mean(dim=-1) 25 | loss = self.confidence * nll_loss + self.smoothing * smooth_loss 26 | return loss.mean() 27 | 28 | 29 | class SoftTargetCrossEntropy(nn.Module): 30 | 31 | def __init__(self): 32 | super(SoftTargetCrossEntropy, self).__init__() 33 | 34 | def forward(self, x: torch.Tensor, target: torch.Tensor) -> torch.Tensor: 35 | loss = torch.sum(-target * F.log_softmax(x, dim=-1), dim=-1) 36 | return loss.mean() 37 | -------------------------------------------------------------------------------- /lib/timm/loss/jsd.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | 5 | from .cross_entropy import LabelSmoothingCrossEntropy 6 | 7 | 8 | class JsdCrossEntropy(nn.Module): 9 | """ Jensen-Shannon Divergence + Cross-Entropy Loss 10 | 11 | Based on impl here: https://github.com/google-research/augmix/blob/master/imagenet.py 12 | From paper: 'AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty - 13 | https://arxiv.org/abs/1912.02781 14 | 15 | Hacked together by / Copyright 2020 Ross Wightman 16 | """ 17 | def __init__(self, num_splits=3, alpha=12, smoothing=0.1): 18 | super().__init__() 19 | self.num_splits = num_splits 20 | self.alpha = alpha 21 | if smoothing is not None and smoothing > 0: 22 | self.cross_entropy_loss = LabelSmoothingCrossEntropy(smoothing) 23 | else: 24 | self.cross_entropy_loss = torch.nn.CrossEntropyLoss() 25 | 26 | def __call__(self, output, target): 27 | split_size = output.shape[0] // self.num_splits 28 | assert split_size * self.num_splits == output.shape[0] 29 | logits_split = torch.split(output, split_size) 30 | 31 | # Cross-entropy is only computed on clean images 32 | loss = self.cross_entropy_loss(logits_split[0], target[:split_size]) 33 | probs = [F.softmax(logits, dim=1) for logits in logits_split] 34 | 35 | # Clamp mixture distribution to avoid exploding KL divergence 36 | logp_mixture = torch.clamp(torch.stack(probs).mean(axis=0), 1e-7, 1).log() 37 | loss += self.alpha * sum([F.kl_div( 38 | logp_mixture, p_split, reduction='batchmean') for p_split in probs]) / len(probs) 39 | return loss 40 | -------------------------------------------------------------------------------- /lib/timm/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .beit import * 2 | from .byoanet import * 3 | from .byobnet import * 4 | from .cait import * 5 | from .coat import * 6 | from .convit import * 7 | from .convmixer import * 8 | from .crossvit import * 9 | from .cspnet import * 10 | from .densenet import * 11 | from .dla import * 12 | from .dpn import * 13 | from .efficientnet import * 14 | from .ghostnet import * 15 | from .gluon_resnet import * 16 | from .gluon_xception import * 17 | from .hardcorenas import * 18 | from .hrnet import * 19 | from .inception_resnet_v2 import * 20 | from .inception_v3 import * 21 | from .inception_v4 import * 22 | from .levit import * 23 | from .mlp_mixer import * 24 | from .mobilenetv3 import * 25 | from .nasnet import * 26 | from .nest import * 27 | from .nfnet import * 28 | from .pit import * 29 | from .pnasnet import * 30 | from .regnet import * 31 | from .res2net import * 32 | from .resnest import * 33 | from .resnet import * 34 | from .resnetv2 import * 35 | from .rexnet import * 36 | from .selecsls import * 37 | from .senet import * 38 | from .sknet import * 39 | from .swin_transformer import * 40 | from .tnt import * 41 | from .tresnet import * 42 | from .twins import * 43 | from .vgg import * 44 | from .visformer import * 45 | from .vision_transformer import * 46 | from .vision_transformer_hybrid import * 47 | from .vovnet import * 48 | from .xception import * 49 | from .xception_aligned import * 50 | from .xcit import * 51 | 52 | from .factory import create_model, split_model_name, safe_model_name 53 | from .helpers import load_checkpoint, resume_checkpoint, model_parameters 54 | from .layers import TestTimePoolHead, apply_test_time_pool 55 | from .layers import convert_splitbn_model 56 | from .layers import is_scriptable, is_exportable, set_scriptable, set_exportable, is_no_jit, set_no_jit 57 | from .registry import register_model, model_entrypoint, list_models, is_model, list_modules, is_model_in_modules,\ 58 | has_model_default_key, is_model_default_key, get_model_default_value, is_model_pretrained 59 | -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/MAE.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/MAE.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/beit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/beit.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/byoanet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/byoanet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/byobnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/byobnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/cait.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/cait.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/coat.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/coat.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/convit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/convit.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/convmixer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/convmixer.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/crossvit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/crossvit.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/cspnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/cspnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/densenet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/densenet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/dla.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/dla.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/dpn.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/dpn.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/efficientnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/efficientnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/efficientnet_blocks.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/efficientnet_blocks.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/efficientnet_builder.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/efficientnet_builder.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/factory.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/factory.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/features.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/features.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/fx_features.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/fx_features.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/ghostnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/ghostnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/gluon_resnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/gluon_resnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/gluon_xception.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/gluon_xception.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/hardcorenas.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/hardcorenas.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/helpers.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/helpers.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/hrnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/hrnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/hub.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/hub.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/inception_resnet_v2.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/inception_resnet_v2.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/inception_v3.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/inception_v3.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/inception_v4.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/inception_v4.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/levit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/levit.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/mlp_mixer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/mlp_mixer.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/mobilenetv3.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/mobilenetv3.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/nasnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/nasnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/nest.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/nest.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/nfnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/nfnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/pit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/pit.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/pnasnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/pnasnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/registry.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/registry.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/regnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/regnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/res2net.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/res2net.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/resnest.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/resnest.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/resnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/resnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/resnetv2.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/resnetv2.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/rexnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/rexnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/selecsls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/selecsls.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/senet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/senet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/sknet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/sknet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/swin_transformer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/swin_transformer.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/tnt.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/tnt.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/tresnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/tresnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/twins.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/twins.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/vgg.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/vgg.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/visformer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/visformer.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/vision_transformer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/vision_transformer.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/vision_transformer_hybrid.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/vision_transformer_hybrid.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/vovnet.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/vovnet.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/xception.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/xception.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/xception_aligned.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/xception_aligned.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/__pycache__/xcit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/__pycache__/xcit.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/fx_features.py: -------------------------------------------------------------------------------- 1 | """ PyTorch FX Based Feature Extraction Helpers 2 | Using https://pytorch.org/vision/stable/feature_extraction.html 3 | """ 4 | from typing import Callable 5 | from torch import nn 6 | 7 | from .features import _get_feature_info 8 | 9 | try: 10 | from torchvision.models.feature_extraction import create_feature_extractor 11 | has_fx_feature_extraction = True 12 | except ImportError: 13 | has_fx_feature_extraction = False 14 | 15 | # Layers we went to treat as leaf modules 16 | from .layers import Conv2dSame, ScaledStdConv2dSame, BatchNormAct2d, BlurPool2d, CondConv2d, StdConv2dSame, DropPath 17 | from .layers.non_local_attn import BilinearAttnTransform 18 | from .layers.pool2d_same import MaxPool2dSame, AvgPool2dSame 19 | 20 | # NOTE: By default, any modules from timm.models.layers that we want to treat as leaf modules go here 21 | # BUT modules from timm.models should use the registration mechanism below 22 | _leaf_modules = { 23 | BatchNormAct2d, # reason: flow control for jit scripting 24 | BilinearAttnTransform, # reason: flow control t <= 1 25 | BlurPool2d, # reason: TypeError: F.conv2d received Proxy in groups=x.shape[1] 26 | # Reason: get_same_padding has a max which raises a control flow error 27 | Conv2dSame, MaxPool2dSame, ScaledStdConv2dSame, StdConv2dSame, AvgPool2dSame, 28 | CondConv2d, # reason: TypeError: F.conv2d received Proxy in groups=self.groups * B (because B = x.shape[0]) 29 | DropPath, # reason: TypeError: rand recieved Proxy in `size` argument 30 | } 31 | 32 | try: 33 | from .layers import InplaceAbn 34 | _leaf_modules.add(InplaceAbn) 35 | except ImportError: 36 | pass 37 | 38 | 39 | def register_notrace_module(module: nn.Module): 40 | """ 41 | Any module not under timm.models.layers should get this decorator if we don't want to trace through it. 42 | """ 43 | _leaf_modules.add(module) 44 | return module 45 | 46 | 47 | # Functions we want to autowrap (treat them as leaves) 48 | _autowrap_functions = set() 49 | 50 | 51 | def register_notrace_function(func: Callable): 52 | """ 53 | Decorator for functions which ought not to be traced through 54 | """ 55 | _autowrap_functions.add(func) 56 | return func 57 | 58 | 59 | class FeatureGraphNet(nn.Module): 60 | def __init__(self, model, out_indices, out_map=None): 61 | super().__init__() 62 | assert has_fx_feature_extraction, 'Please update to PyTorch 1.10+, torchvision 0.11+ for FX feature extraction' 63 | self.feature_info = _get_feature_info(model, out_indices) 64 | if out_map is not None: 65 | assert len(out_map) == len(out_indices) 66 | return_nodes = {info['module']: out_map[i] if out_map is not None else info['module'] 67 | for i, info in enumerate(self.feature_info) if i in out_indices} 68 | self.graph_module = create_feature_extractor( 69 | model, return_nodes, 70 | tracer_kwargs={'leaf_modules': list(_leaf_modules), 'autowrap_functions': list(_autowrap_functions)}) 71 | 72 | def forward(self, x): 73 | return list(self.graph_module(x).values()) 74 | -------------------------------------------------------------------------------- /lib/timm/models/layers/__init__.py: -------------------------------------------------------------------------------- 1 | from .activations import * 2 | from .adaptive_avgmax_pool import \ 3 | adaptive_avgmax_pool2d, select_adaptive_pool2d, AdaptiveAvgMaxPool2d, SelectAdaptivePool2d 4 | from .blur_pool import BlurPool2d 5 | from .classifier import ClassifierHead, create_classifier 6 | from .cond_conv2d import CondConv2d, get_condconv_initializer 7 | from .config import is_exportable, is_scriptable, is_no_jit, set_exportable, set_scriptable, set_no_jit,\ 8 | set_layer_config 9 | from .conv2d_same import Conv2dSame, conv2d_same 10 | from .conv_bn_act import ConvBnAct 11 | from .create_act import create_act_layer, get_act_layer, get_act_fn 12 | from .create_attn import get_attn, create_attn 13 | from .create_conv2d import create_conv2d 14 | from .create_norm_act import get_norm_act_layer, create_norm_act, convert_norm_act 15 | from .drop import DropBlock2d, DropPath, drop_block_2d, drop_path 16 | from .eca import EcaModule, CecaModule, EfficientChannelAttn, CircularEfficientChannelAttn 17 | from .evo_norm import EvoNormBatch2d, EvoNormSample2d 18 | from .gather_excite import GatherExcite 19 | from .global_context import GlobalContext 20 | from .helpers import to_ntuple, to_2tuple, to_3tuple, to_4tuple, make_divisible 21 | from .inplace_abn import InplaceAbn 22 | from .linear import Linear 23 | from .mixed_conv2d import MixedConv2d 24 | from .mlp import Mlp, GluMlp, GatedMlp 25 | from .non_local_attn import NonLocalAttn, BatNonLocalAttn 26 | from .norm import GroupNorm, LayerNorm2d 27 | from .norm_act import BatchNormAct2d, GroupNormAct 28 | from .padding import get_padding, get_same_padding, pad_same 29 | from .patch_embed import PatchEmbed 30 | from .pool2d_same import AvgPool2dSame, create_pool2d 31 | from .squeeze_excite import SEModule, SqueezeExcite, EffectiveSEModule, EffectiveSqueezeExcite 32 | from .selective_kernel import SelectiveKernel 33 | from .separable_conv import SeparableConv2d, SeparableConvBnAct 34 | from .space_to_depth import SpaceToDepthModule 35 | from .split_attn import SplitAttn 36 | from .split_batchnorm import SplitBatchNorm2d, convert_splitbn_model 37 | from .std_conv import StdConv2d, StdConv2dSame, ScaledStdConv2d, ScaledStdConv2dSame 38 | from .test_time_pool import TestTimePoolHead, apply_test_time_pool 39 | from .trace_utils import _assert, _float_to_int 40 | from .weight_init import trunc_normal_, variance_scaling_, lecun_normal_ 41 | -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/activations.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/activations.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/activations_jit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/activations_jit.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/activations_me.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/activations_me.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/adaptive_avgmax_pool.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/adaptive_avgmax_pool.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/blur_pool.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/blur_pool.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/bottleneck_attn.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/bottleneck_attn.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/cbam.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/cbam.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/classifier.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/classifier.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/cond_conv2d.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/cond_conv2d.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/config.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/config.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/conv2d_same.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/conv2d_same.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/conv_bn_act.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/conv_bn_act.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/create_act.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/create_act.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/create_attn.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/create_attn.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/create_conv2d.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/create_conv2d.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/create_norm_act.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/create_norm_act.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/drop.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/drop.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/eca.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/eca.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/evo_norm.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/evo_norm.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/gather_excite.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/gather_excite.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/global_context.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/global_context.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/halo_attn.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/halo_attn.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/helpers.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/helpers.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/inplace_abn.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/inplace_abn.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/lambda_layer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/lambda_layer.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/linear.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/linear.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/mixed_conv2d.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/mixed_conv2d.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/mlp.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/mlp.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/non_local_attn.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/non_local_attn.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/norm.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/norm.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/norm_act.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/norm_act.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/padding.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/padding.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/patch_embed.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/patch_embed.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/pool2d_same.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/pool2d_same.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/selective_kernel.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/selective_kernel.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/separable_conv.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/separable_conv.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/space_to_depth.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/space_to_depth.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/split_attn.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/split_attn.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/split_batchnorm.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/split_batchnorm.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/squeeze_excite.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/squeeze_excite.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/std_conv.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/std_conv.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/test_time_pool.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/test_time_pool.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/trace_utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/trace_utils.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/__pycache__/weight_init.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/models/layers/__pycache__/weight_init.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/models/layers/activations_jit.py: -------------------------------------------------------------------------------- 1 | """ Activations 2 | 3 | A collection of jit-scripted activations fn and modules with a common interface so that they can 4 | easily be swapped. All have an `inplace` arg even if not used. 5 | 6 | All jit scripted activations are lacking in-place variations on purpose, scripted kernel fusion does not 7 | currently work across in-place op boundaries, thus performance is equal to or less than the non-scripted 8 | versions if they contain in-place ops. 9 | 10 | Hacked together by / Copyright 2020 Ross Wightman 11 | """ 12 | 13 | import torch 14 | from torch import nn as nn 15 | from torch.nn import functional as F 16 | 17 | 18 | @torch.jit.script 19 | def swish_jit(x, inplace: bool = False): 20 | """Swish - Described in: https://arxiv.org/abs/1710.05941 21 | """ 22 | return x.mul(x.sigmoid()) 23 | 24 | 25 | @torch.jit.script 26 | def mish_jit(x, _inplace: bool = False): 27 | """Mish: A Self Regularized Non-Monotonic Neural Activation Function - https://arxiv.org/abs/1908.08681 28 | """ 29 | return x.mul(F.softplus(x).tanh()) 30 | 31 | 32 | class SwishJit(nn.Module): 33 | def __init__(self, inplace: bool = False): 34 | super(SwishJit, self).__init__() 35 | 36 | def forward(self, x): 37 | return swish_jit(x) 38 | 39 | 40 | class MishJit(nn.Module): 41 | def __init__(self, inplace: bool = False): 42 | super(MishJit, self).__init__() 43 | 44 | def forward(self, x): 45 | return mish_jit(x) 46 | 47 | 48 | @torch.jit.script 49 | def hard_sigmoid_jit(x, inplace: bool = False): 50 | # return F.relu6(x + 3.) / 6. 51 | return (x + 3).clamp(min=0, max=6).div(6.) # clamp seems ever so slightly faster? 52 | 53 | 54 | class HardSigmoidJit(nn.Module): 55 | def __init__(self, inplace: bool = False): 56 | super(HardSigmoidJit, self).__init__() 57 | 58 | def forward(self, x): 59 | return hard_sigmoid_jit(x) 60 | 61 | 62 | @torch.jit.script 63 | def hard_swish_jit(x, inplace: bool = False): 64 | # return x * (F.relu6(x + 3.) / 6) 65 | return x * (x + 3).clamp(min=0, max=6).div(6.) # clamp seems ever so slightly faster? 66 | 67 | 68 | class HardSwishJit(nn.Module): 69 | def __init__(self, inplace: bool = False): 70 | super(HardSwishJit, self).__init__() 71 | 72 | def forward(self, x): 73 | return hard_swish_jit(x) 74 | 75 | 76 | @torch.jit.script 77 | def hard_mish_jit(x, inplace: bool = False): 78 | """ Hard Mish 79 | Experimental, based on notes by Mish author Diganta Misra at 80 | https://github.com/digantamisra98/H-Mish/blob/0da20d4bc58e696b6803f2523c58d3c8a82782d0/README.md 81 | """ 82 | return 0.5 * x * (x + 2).clamp(min=0, max=2) 83 | 84 | 85 | class HardMishJit(nn.Module): 86 | def __init__(self, inplace: bool = False): 87 | super(HardMishJit, self).__init__() 88 | 89 | def forward(self, x): 90 | return hard_mish_jit(x) 91 | -------------------------------------------------------------------------------- /lib/timm/models/layers/blur_pool.py: -------------------------------------------------------------------------------- 1 | """ 2 | BlurPool layer inspired by 3 | - Kornia's Max_BlurPool2d 4 | - Making Convolutional Networks Shift-Invariant Again :cite:`zhang2019shiftinvar` 5 | 6 | Hacked together by Chris Ha and Ross Wightman 7 | """ 8 | 9 | import torch 10 | import torch.nn as nn 11 | import torch.nn.functional as F 12 | import numpy as np 13 | from .padding import get_padding 14 | 15 | 16 | class BlurPool2d(nn.Module): 17 | r"""Creates a module that computes blurs and downsample a given feature map. 18 | See :cite:`zhang2019shiftinvar` for more details. 19 | Corresponds to the Downsample class, which does blurring and subsampling 20 | 21 | Args: 22 | channels = Number of input channels 23 | filt_size (int): binomial filter size for blurring. currently supports 3 (default) and 5. 24 | stride (int): downsampling filter stride 25 | 26 | Returns: 27 | torch.Tensor: the transformed tensor. 28 | """ 29 | def __init__(self, channels, filt_size=3, stride=2) -> None: 30 | super(BlurPool2d, self).__init__() 31 | assert filt_size > 1 32 | self.channels = channels 33 | self.filt_size = filt_size 34 | self.stride = stride 35 | self.padding = [get_padding(filt_size, stride, dilation=1)] * 4 36 | coeffs = torch.tensor((np.poly1d((0.5, 0.5)) ** (self.filt_size - 1)).coeffs.astype(np.float32)) 37 | blur_filter = (coeffs[:, None] * coeffs[None, :])[None, None, :, :].repeat(self.channels, 1, 1, 1) 38 | self.register_buffer('filt', blur_filter, persistent=False) 39 | 40 | def forward(self, x: torch.Tensor) -> torch.Tensor: 41 | x = F.pad(x, self.padding, 'reflect') 42 | return F.conv2d(x, self.filt, stride=self.stride, groups=x.shape[1]) 43 | -------------------------------------------------------------------------------- /lib/timm/models/layers/classifier.py: -------------------------------------------------------------------------------- 1 | """ Classifier head and layer factory 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | from torch import nn as nn 6 | from torch.nn import functional as F 7 | 8 | from .adaptive_avgmax_pool import SelectAdaptivePool2d 9 | from .linear import Linear 10 | 11 | 12 | def _create_pool(num_features, num_classes, pool_type='avg', use_conv=False): 13 | flatten_in_pool = not use_conv # flatten when we use a Linear layer after pooling 14 | if not pool_type: 15 | assert num_classes == 0 or use_conv,\ 16 | 'Pooling can only be disabled if classifier is also removed or conv classifier is used' 17 | flatten_in_pool = False # disable flattening if pooling is pass-through (no pooling) 18 | global_pool = SelectAdaptivePool2d(pool_type=pool_type, flatten=flatten_in_pool) 19 | num_pooled_features = num_features * global_pool.feat_mult() 20 | return global_pool, num_pooled_features 21 | 22 | 23 | def _create_fc(num_features, num_classes, use_conv=False): 24 | if num_classes <= 0: 25 | fc = nn.Identity() # pass-through (no classifier) 26 | elif use_conv: 27 | fc = nn.Conv2d(num_features, num_classes, 1, bias=True) 28 | else: 29 | # NOTE: using my Linear wrapper that fixes AMP + torchscript casting issue 30 | fc = Linear(num_features, num_classes, bias=True) 31 | return fc 32 | 33 | 34 | def create_classifier(num_features, num_classes, pool_type='avg', use_conv=False): 35 | global_pool, num_pooled_features = _create_pool(num_features, num_classes, pool_type, use_conv=use_conv) 36 | fc = _create_fc(num_pooled_features, num_classes, use_conv=use_conv) 37 | return global_pool, fc 38 | 39 | 40 | class ClassifierHead(nn.Module): 41 | """Classifier head w/ configurable global pooling and dropout.""" 42 | 43 | def __init__(self, in_chs, num_classes, pool_type='avg', drop_rate=0., use_conv=False): 44 | super(ClassifierHead, self).__init__() 45 | self.drop_rate = drop_rate 46 | self.global_pool, num_pooled_features = _create_pool(in_chs, num_classes, pool_type, use_conv=use_conv) 47 | self.fc = _create_fc(num_pooled_features, num_classes, use_conv=use_conv) 48 | self.flatten = nn.Flatten(1) if use_conv and pool_type else nn.Identity() 49 | 50 | def forward(self, x): 51 | x = self.global_pool(x) 52 | if self.drop_rate: 53 | x = F.dropout(x, p=float(self.drop_rate), training=self.training) 54 | x = self.fc(x) 55 | x = self.flatten(x) 56 | return x 57 | -------------------------------------------------------------------------------- /lib/timm/models/layers/conv2d_same.py: -------------------------------------------------------------------------------- 1 | """ Conv2d w/ Same Padding 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import torch 6 | import torch.nn as nn 7 | import torch.nn.functional as F 8 | from typing import Tuple, Optional 9 | 10 | from .padding import pad_same, get_padding_value 11 | 12 | 13 | def conv2d_same( 14 | x, weight: torch.Tensor, bias: Optional[torch.Tensor] = None, stride: Tuple[int, int] = (1, 1), 15 | padding: Tuple[int, int] = (0, 0), dilation: Tuple[int, int] = (1, 1), groups: int = 1): 16 | x = pad_same(x, weight.shape[-2:], stride, dilation) 17 | return F.conv2d(x, weight, bias, stride, (0, 0), dilation, groups) 18 | 19 | 20 | class Conv2dSame(nn.Conv2d): 21 | """ Tensorflow like 'SAME' convolution wrapper for 2D convolutions 22 | """ 23 | 24 | def __init__(self, in_channels, out_channels, kernel_size, stride=1, 25 | padding=0, dilation=1, groups=1, bias=True): 26 | super(Conv2dSame, self).__init__( 27 | in_channels, out_channels, kernel_size, stride, 0, dilation, groups, bias) 28 | 29 | def forward(self, x): 30 | return conv2d_same(x, self.weight, self.bias, self.stride, self.padding, self.dilation, self.groups) 31 | 32 | 33 | def create_conv2d_pad(in_chs, out_chs, kernel_size, **kwargs): 34 | padding = kwargs.pop('padding', '') 35 | kwargs.setdefault('bias', False) 36 | padding, is_dynamic = get_padding_value(padding, kernel_size, **kwargs) 37 | if is_dynamic: 38 | return Conv2dSame(in_chs, out_chs, kernel_size, **kwargs) 39 | else: 40 | return nn.Conv2d(in_chs, out_chs, kernel_size, padding=padding, **kwargs) 41 | 42 | 43 | -------------------------------------------------------------------------------- /lib/timm/models/layers/conv_bn_act.py: -------------------------------------------------------------------------------- 1 | """ Conv2d + BN + Act 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | from torch import nn as nn 6 | 7 | from .create_conv2d import create_conv2d 8 | from .create_norm_act import convert_norm_act 9 | 10 | 11 | class ConvBnAct(nn.Module): 12 | def __init__(self, in_channels, out_channels, kernel_size=1, stride=1, padding='', dilation=1, groups=1, 13 | bias=False, apply_act=True, norm_layer=nn.BatchNorm2d, act_layer=nn.ReLU, aa_layer=None, 14 | drop_block=None): 15 | super(ConvBnAct, self).__init__() 16 | use_aa = aa_layer is not None 17 | 18 | self.conv = create_conv2d( 19 | in_channels, out_channels, kernel_size, stride=1 if use_aa else stride, 20 | padding=padding, dilation=dilation, groups=groups, bias=bias) 21 | 22 | # NOTE for backwards compatibility with models that use separate norm and act layer definitions 23 | norm_act_layer = convert_norm_act(norm_layer, act_layer) 24 | self.bn = norm_act_layer(out_channels, apply_act=apply_act, drop_block=drop_block) 25 | self.aa = aa_layer(channels=out_channels) if stride == 2 and use_aa else None 26 | 27 | @property 28 | def in_channels(self): 29 | return self.conv.in_channels 30 | 31 | @property 32 | def out_channels(self): 33 | return self.conv.out_channels 34 | 35 | def forward(self, x): 36 | x = self.conv(x) 37 | x = self.bn(x) 38 | if self.aa is not None: 39 | x = self.aa(x) 40 | return x 41 | -------------------------------------------------------------------------------- /lib/timm/models/layers/create_conv2d.py: -------------------------------------------------------------------------------- 1 | """ Create Conv2d Factory Method 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | 6 | from .mixed_conv2d import MixedConv2d 7 | from .cond_conv2d import CondConv2d 8 | from .conv2d_same import create_conv2d_pad 9 | 10 | 11 | def create_conv2d(in_channels, out_channels, kernel_size, **kwargs): 12 | """ Select a 2d convolution implementation based on arguments 13 | Creates and returns one of torch.nn.Conv2d, Conv2dSame, MixedConv2d, or CondConv2d. 14 | 15 | Used extensively by EfficientNet, MobileNetv3 and related networks. 16 | """ 17 | if isinstance(kernel_size, list): 18 | assert 'num_experts' not in kwargs # MixNet + CondConv combo not supported currently 19 | assert 'groups' not in kwargs # MixedConv groups are defined by kernel list 20 | # We're going to use only lists for defining the MixedConv2d kernel groups, 21 | # ints, tuples, other iterables will continue to pass to normal conv and specify h, w. 22 | m = MixedConv2d(in_channels, out_channels, kernel_size, **kwargs) 23 | else: 24 | depthwise = kwargs.pop('depthwise', False) 25 | # for DW out_channels must be multiple of in_channels as must have out_channels % groups == 0 26 | groups = in_channels if depthwise else kwargs.pop('groups', 1) 27 | if 'num_experts' in kwargs and kwargs['num_experts'] > 0: 28 | m = CondConv2d(in_channels, out_channels, kernel_size, groups=groups, **kwargs) 29 | else: 30 | m = create_conv2d_pad(in_channels, out_channels, kernel_size, groups=groups, **kwargs) 31 | return m 32 | -------------------------------------------------------------------------------- /lib/timm/models/layers/global_context.py: -------------------------------------------------------------------------------- 1 | """ Global Context Attention Block 2 | 3 | Paper: `GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond` 4 | - https://arxiv.org/abs/1904.11492 5 | 6 | Official code consulted as reference: https://github.com/xvjiarui/GCNet 7 | 8 | Hacked together by / Copyright 2021 Ross Wightman 9 | """ 10 | from torch import nn as nn 11 | import torch.nn.functional as F 12 | 13 | from .create_act import create_act_layer, get_act_layer 14 | from .helpers import make_divisible 15 | from .mlp import ConvMlp 16 | from .norm import LayerNorm2d 17 | 18 | 19 | class GlobalContext(nn.Module): 20 | 21 | def __init__(self, channels, use_attn=True, fuse_add=False, fuse_scale=True, init_last_zero=False, 22 | rd_ratio=1./8, rd_channels=None, rd_divisor=1, act_layer=nn.ReLU, gate_layer='sigmoid'): 23 | super(GlobalContext, self).__init__() 24 | act_layer = get_act_layer(act_layer) 25 | 26 | self.conv_attn = nn.Conv2d(channels, 1, kernel_size=1, bias=True) if use_attn else None 27 | 28 | if rd_channels is None: 29 | rd_channels = make_divisible(channels * rd_ratio, rd_divisor, round_limit=0.) 30 | if fuse_add: 31 | self.mlp_add = ConvMlp(channels, rd_channels, act_layer=act_layer, norm_layer=LayerNorm2d) 32 | else: 33 | self.mlp_add = None 34 | if fuse_scale: 35 | self.mlp_scale = ConvMlp(channels, rd_channels, act_layer=act_layer, norm_layer=LayerNorm2d) 36 | else: 37 | self.mlp_scale = None 38 | 39 | self.gate = create_act_layer(gate_layer) 40 | self.init_last_zero = init_last_zero 41 | self.reset_parameters() 42 | 43 | def reset_parameters(self): 44 | if self.conv_attn is not None: 45 | nn.init.kaiming_normal_(self.conv_attn.weight, mode='fan_in', nonlinearity='relu') 46 | if self.mlp_add is not None: 47 | nn.init.zeros_(self.mlp_add.fc2.weight) 48 | 49 | def forward(self, x): 50 | B, C, H, W = x.shape 51 | 52 | if self.conv_attn is not None: 53 | attn = self.conv_attn(x).reshape(B, 1, H * W) # (B, 1, H * W) 54 | attn = F.softmax(attn, dim=-1).unsqueeze(3) # (B, 1, H * W, 1) 55 | context = x.reshape(B, C, H * W).unsqueeze(1) @ attn 56 | context = context.view(B, C, 1, 1) 57 | else: 58 | context = x.mean(dim=(2, 3), keepdim=True) 59 | 60 | if self.mlp_scale is not None: 61 | mlp_x = self.mlp_scale(context) 62 | x = x * self.gate(mlp_x) 63 | if self.mlp_add is not None: 64 | mlp_x = self.mlp_add(context) 65 | x = x + mlp_x 66 | 67 | return x 68 | -------------------------------------------------------------------------------- /lib/timm/models/layers/helpers.py: -------------------------------------------------------------------------------- 1 | """ Layer/Module Helpers 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | from itertools import repeat 6 | import collections.abc 7 | 8 | 9 | # From PyTorch internals 10 | def _ntuple(n): 11 | def parse(x): 12 | if isinstance(x, collections.abc.Iterable): 13 | return x 14 | return tuple(repeat(x, n)) 15 | return parse 16 | 17 | 18 | to_1tuple = _ntuple(1) 19 | to_2tuple = _ntuple(2) 20 | to_3tuple = _ntuple(3) 21 | to_4tuple = _ntuple(4) 22 | to_ntuple = _ntuple 23 | 24 | 25 | def make_divisible(v, divisor=8, min_value=None, round_limit=.9): 26 | min_value = min_value or divisor 27 | new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) 28 | # Make sure that round down does not go down by more than 10%. 29 | if new_v < round_limit * v: 30 | new_v += divisor 31 | return new_v 32 | -------------------------------------------------------------------------------- /lib/timm/models/layers/linear.py: -------------------------------------------------------------------------------- 1 | """ Linear layer (alternate definition) 2 | """ 3 | import torch 4 | import torch.nn.functional as F 5 | from torch import nn as nn 6 | 7 | 8 | class Linear(nn.Linear): 9 | r"""Applies a linear transformation to the incoming data: :math:`y = xA^T + b` 10 | 11 | Wraps torch.nn.Linear to support AMP + torchscript usage by manually casting 12 | weight & bias to input.dtype to work around an issue w/ torch.addmm in this use case. 13 | """ 14 | def forward(self, input: torch.Tensor) -> torch.Tensor: 15 | if torch.jit.is_scripting(): 16 | bias = self.bias.to(dtype=input.dtype) if self.bias is not None else None 17 | return F.linear(input, self.weight.to(dtype=input.dtype), bias=bias) 18 | else: 19 | return F.linear(input, self.weight, self.bias) 20 | -------------------------------------------------------------------------------- /lib/timm/models/layers/median_pool.py: -------------------------------------------------------------------------------- 1 | """ Median Pool 2 | Hacked together by / Copyright 2020 Ross Wightman 3 | """ 4 | import torch.nn as nn 5 | import torch.nn.functional as F 6 | from .helpers import to_2tuple, to_4tuple 7 | 8 | 9 | class MedianPool2d(nn.Module): 10 | """ Median pool (usable as median filter when stride=1) module. 11 | 12 | Args: 13 | kernel_size: size of pooling kernel, int or 2-tuple 14 | stride: pool stride, int or 2-tuple 15 | padding: pool padding, int or 4-tuple (l, r, t, b) as in pytorch F.pad 16 | same: override padding and enforce same padding, boolean 17 | """ 18 | def __init__(self, kernel_size=3, stride=1, padding=0, same=False): 19 | super(MedianPool2d, self).__init__() 20 | self.k = to_2tuple(kernel_size) 21 | self.stride = to_2tuple(stride) 22 | self.padding = to_4tuple(padding) # convert to l, r, t, b 23 | self.same = same 24 | 25 | def _padding(self, x): 26 | if self.same: 27 | ih, iw = x.size()[2:] 28 | if ih % self.stride[0] == 0: 29 | ph = max(self.k[0] - self.stride[0], 0) 30 | else: 31 | ph = max(self.k[0] - (ih % self.stride[0]), 0) 32 | if iw % self.stride[1] == 0: 33 | pw = max(self.k[1] - self.stride[1], 0) 34 | else: 35 | pw = max(self.k[1] - (iw % self.stride[1]), 0) 36 | pl = pw // 2 37 | pr = pw - pl 38 | pt = ph // 2 39 | pb = ph - pt 40 | padding = (pl, pr, pt, pb) 41 | else: 42 | padding = self.padding 43 | return padding 44 | 45 | def forward(self, x): 46 | x = F.pad(x, self._padding(x), mode='reflect') 47 | x = x.unfold(2, self.k[0], self.stride[0]).unfold(3, self.k[1], self.stride[1]) 48 | x = x.contiguous().view(x.size()[:4] + (-1,)).median(dim=-1)[0] 49 | return x 50 | -------------------------------------------------------------------------------- /lib/timm/models/layers/mixed_conv2d.py: -------------------------------------------------------------------------------- 1 | """ PyTorch Mixed Convolution 2 | 3 | Paper: MixConv: Mixed Depthwise Convolutional Kernels (https://arxiv.org/abs/1907.09595) 4 | 5 | Hacked together by / Copyright 2020 Ross Wightman 6 | """ 7 | 8 | import torch 9 | from torch import nn as nn 10 | 11 | from .conv2d_same import create_conv2d_pad 12 | 13 | 14 | def _split_channels(num_chan, num_groups): 15 | split = [num_chan // num_groups for _ in range(num_groups)] 16 | split[0] += num_chan - sum(split) 17 | return split 18 | 19 | 20 | class MixedConv2d(nn.ModuleDict): 21 | """ Mixed Grouped Convolution 22 | 23 | Based on MDConv and GroupedConv in MixNet impl: 24 | https://github.com/tensorflow/tpu/blob/master/models/official/mnasnet/mixnet/custom_layers.py 25 | """ 26 | def __init__(self, in_channels, out_channels, kernel_size=3, 27 | stride=1, padding='', dilation=1, depthwise=False, **kwargs): 28 | super(MixedConv2d, self).__init__() 29 | 30 | kernel_size = kernel_size if isinstance(kernel_size, list) else [kernel_size] 31 | num_groups = len(kernel_size) 32 | in_splits = _split_channels(in_channels, num_groups) 33 | out_splits = _split_channels(out_channels, num_groups) 34 | self.in_channels = sum(in_splits) 35 | self.out_channels = sum(out_splits) 36 | for idx, (k, in_ch, out_ch) in enumerate(zip(kernel_size, in_splits, out_splits)): 37 | conv_groups = in_ch if depthwise else 1 38 | # use add_module to keep key space clean 39 | self.add_module( 40 | str(idx), 41 | create_conv2d_pad( 42 | in_ch, out_ch, k, stride=stride, 43 | padding=padding, dilation=dilation, groups=conv_groups, **kwargs) 44 | ) 45 | self.splits = in_splits 46 | 47 | def forward(self, x): 48 | x_split = torch.split(x, self.splits, 1) 49 | x_out = [c(x_split[i]) for i, c in enumerate(self.values())] 50 | x = torch.cat(x_out, 1) 51 | return x 52 | -------------------------------------------------------------------------------- /lib/timm/models/layers/norm.py: -------------------------------------------------------------------------------- 1 | """ Normalization layers and wrappers 2 | """ 3 | import torch 4 | import torch.nn as nn 5 | import torch.nn.functional as F 6 | 7 | 8 | class GroupNorm(nn.GroupNorm): 9 | def __init__(self, num_channels, num_groups=32, eps=1e-5, affine=True): 10 | # NOTE num_channels is swapped to first arg for consistency in swapping norm layers with BN 11 | super().__init__(num_groups, num_channels, eps=eps, affine=affine) 12 | 13 | def forward(self, x): 14 | return F.group_norm(x, self.num_groups, self.weight, self.bias, self.eps) 15 | 16 | 17 | class LayerNorm2d(nn.LayerNorm): 18 | """ LayerNorm for channels of '2D' spatial BCHW tensors """ 19 | def __init__(self, num_channels): 20 | super().__init__(num_channels) 21 | 22 | def forward(self, x: torch.Tensor) -> torch.Tensor: 23 | return F.layer_norm( 24 | x.permute(0, 2, 3, 1), self.normalized_shape, self.weight, self.bias, self.eps).permute(0, 3, 1, 2) 25 | -------------------------------------------------------------------------------- /lib/timm/models/layers/padding.py: -------------------------------------------------------------------------------- 1 | """ Padding Helpers 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import math 6 | from typing import List, Tuple 7 | 8 | import torch.nn.functional as F 9 | 10 | 11 | # Calculate symmetric padding for a convolution 12 | def get_padding(kernel_size: int, stride: int = 1, dilation: int = 1, **_) -> int: 13 | padding = ((stride - 1) + dilation * (kernel_size - 1)) // 2 14 | return padding 15 | 16 | 17 | # Calculate asymmetric TensorFlow-like 'SAME' padding for a convolution 18 | def get_same_padding(x: int, k: int, s: int, d: int): 19 | return max((math.ceil(x / s) - 1) * s + (k - 1) * d + 1 - x, 0) 20 | 21 | 22 | # Can SAME padding for given args be done statically? 23 | def is_static_pad(kernel_size: int, stride: int = 1, dilation: int = 1, **_): 24 | return stride == 1 and (dilation * (kernel_size - 1)) % 2 == 0 25 | 26 | 27 | # Dynamically pad input x with 'SAME' padding for conv with specified args 28 | def pad_same(x, k: List[int], s: List[int], d: List[int] = (1, 1), value: float = 0): 29 | ih, iw = x.size()[-2:] 30 | pad_h, pad_w = get_same_padding(ih, k[0], s[0], d[0]), get_same_padding(iw, k[1], s[1], d[1]) 31 | if pad_h > 0 or pad_w > 0: 32 | x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2], value=value) 33 | return x 34 | 35 | 36 | def get_padding_value(padding, kernel_size, **kwargs) -> Tuple[Tuple, bool]: 37 | dynamic = False 38 | if isinstance(padding, str): 39 | # for any string padding, the padding will be calculated for you, one of three ways 40 | padding = padding.lower() 41 | if padding == 'same': 42 | # TF compatible 'SAME' padding, has a performance and GPU memory allocation impact 43 | if is_static_pad(kernel_size, **kwargs): 44 | # static case, no extra overhead 45 | padding = get_padding(kernel_size, **kwargs) 46 | else: 47 | # dynamic 'SAME' padding, has runtime/GPU memory overhead 48 | padding = 0 49 | dynamic = True 50 | elif padding == 'valid': 51 | # 'VALID' padding, same as padding=0 52 | padding = 0 53 | else: 54 | # Default to PyTorch style 'same'-ish symmetric padding 55 | padding = get_padding(kernel_size, **kwargs) 56 | return padding, dynamic 57 | -------------------------------------------------------------------------------- /lib/timm/models/layers/patch_embed.py: -------------------------------------------------------------------------------- 1 | """ Image to Patch Embedding using Conv2d 2 | 3 | A convolution based approach to patchifying a 2D image w/ embedding projection. 4 | 5 | Based on the impl in https://github.com/google-research/vision_transformer 6 | 7 | Hacked together by / Copyright 2020 Ross Wightman 8 | """ 9 | from torch import nn as nn 10 | 11 | from .helpers import to_2tuple 12 | from .trace_utils import _assert 13 | 14 | 15 | class PatchEmbed(nn.Module): 16 | """ 2D Image to Patch Embedding 17 | """ 18 | def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768, norm_layer=None, flatten=True): 19 | super().__init__() 20 | img_size = to_2tuple(img_size) 21 | patch_size = to_2tuple(patch_size) 22 | self.img_size = img_size 23 | self.patch_size = patch_size 24 | self.grid_size = (img_size[0] // patch_size[0], img_size[1] // patch_size[1]) 25 | self.num_patches = self.grid_size[0] * self.grid_size[1] 26 | self.flatten = flatten 27 | 28 | self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size) 29 | self.norm = norm_layer(embed_dim) if norm_layer else nn.Identity() 30 | 31 | def forward(self, x): 32 | B, C, H, W = x.shape 33 | _assert(H == self.img_size[0], f"Input image height ({H}) doesn't match model ({self.img_size[0]}).") 34 | _assert(W == self.img_size[1], f"Input image width ({W}) doesn't match model ({self.img_size[1]}).") 35 | x = self.proj(x) 36 | if self.flatten: 37 | x = x.flatten(2).transpose(1, 2) # BCHW -> BNC 38 | x = self.norm(x) 39 | return x 40 | -------------------------------------------------------------------------------- /lib/timm/models/layers/pool2d_same.py: -------------------------------------------------------------------------------- 1 | """ AvgPool2d w/ Same Padding 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import torch 6 | import torch.nn as nn 7 | import torch.nn.functional as F 8 | from typing import List, Tuple, Optional 9 | 10 | from .helpers import to_2tuple 11 | from .padding import pad_same, get_padding_value 12 | 13 | 14 | def avg_pool2d_same(x, kernel_size: List[int], stride: List[int], padding: List[int] = (0, 0), 15 | ceil_mode: bool = False, count_include_pad: bool = True): 16 | # FIXME how to deal with count_include_pad vs not for external padding? 17 | x = pad_same(x, kernel_size, stride) 18 | return F.avg_pool2d(x, kernel_size, stride, (0, 0), ceil_mode, count_include_pad) 19 | 20 | 21 | class AvgPool2dSame(nn.AvgPool2d): 22 | """ Tensorflow like 'SAME' wrapper for 2D average pooling 23 | """ 24 | def __init__(self, kernel_size: int, stride=None, padding=0, ceil_mode=False, count_include_pad=True): 25 | kernel_size = to_2tuple(kernel_size) 26 | stride = to_2tuple(stride) 27 | super(AvgPool2dSame, self).__init__(kernel_size, stride, (0, 0), ceil_mode, count_include_pad) 28 | 29 | def forward(self, x): 30 | x = pad_same(x, self.kernel_size, self.stride) 31 | return F.avg_pool2d( 32 | x, self.kernel_size, self.stride, self.padding, self.ceil_mode, self.count_include_pad) 33 | 34 | 35 | def max_pool2d_same( 36 | x, kernel_size: List[int], stride: List[int], padding: List[int] = (0, 0), 37 | dilation: List[int] = (1, 1), ceil_mode: bool = False): 38 | x = pad_same(x, kernel_size, stride, value=-float('inf')) 39 | return F.max_pool2d(x, kernel_size, stride, (0, 0), dilation, ceil_mode) 40 | 41 | 42 | class MaxPool2dSame(nn.MaxPool2d): 43 | """ Tensorflow like 'SAME' wrapper for 2D max pooling 44 | """ 45 | def __init__(self, kernel_size: int, stride=None, padding=0, dilation=1, ceil_mode=False): 46 | kernel_size = to_2tuple(kernel_size) 47 | stride = to_2tuple(stride) 48 | dilation = to_2tuple(dilation) 49 | super(MaxPool2dSame, self).__init__(kernel_size, stride, (0, 0), dilation, ceil_mode) 50 | 51 | def forward(self, x): 52 | x = pad_same(x, self.kernel_size, self.stride, value=-float('inf')) 53 | return F.max_pool2d(x, self.kernel_size, self.stride, (0, 0), self.dilation, self.ceil_mode) 54 | 55 | 56 | def create_pool2d(pool_type, kernel_size, stride=None, **kwargs): 57 | stride = stride or kernel_size 58 | padding = kwargs.pop('padding', '') 59 | padding, is_dynamic = get_padding_value(padding, kernel_size, stride=stride, **kwargs) 60 | if is_dynamic: 61 | if pool_type == 'avg': 62 | return AvgPool2dSame(kernel_size, stride=stride, **kwargs) 63 | elif pool_type == 'max': 64 | return MaxPool2dSame(kernel_size, stride=stride, **kwargs) 65 | else: 66 | assert False, f'Unsupported pool type {pool_type}' 67 | else: 68 | if pool_type == 'avg': 69 | return nn.AvgPool2d(kernel_size, stride=stride, padding=padding, **kwargs) 70 | elif pool_type == 'max': 71 | return nn.MaxPool2d(kernel_size, stride=stride, padding=padding, **kwargs) 72 | else: 73 | assert False, f'Unsupported pool type {pool_type}' 74 | -------------------------------------------------------------------------------- /lib/timm/models/layers/separable_conv.py: -------------------------------------------------------------------------------- 1 | """ Depthwise Separable Conv Modules 2 | 3 | Basic DWS convs. Other variations of DWS exist with batch norm or activations between the 4 | DW and PW convs such as the Depthwise modules in MobileNetV2 / EfficientNet and Xception. 5 | 6 | Hacked together by / Copyright 2020 Ross Wightman 7 | """ 8 | from torch import nn as nn 9 | 10 | from .create_conv2d import create_conv2d 11 | from .create_norm_act import convert_norm_act 12 | 13 | 14 | class SeparableConvBnAct(nn.Module): 15 | """ Separable Conv w/ trailing Norm and Activation 16 | """ 17 | def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, dilation=1, padding='', bias=False, 18 | channel_multiplier=1.0, pw_kernel_size=1, norm_layer=nn.BatchNorm2d, act_layer=nn.ReLU, 19 | apply_act=True, drop_block=None): 20 | super(SeparableConvBnAct, self).__init__() 21 | 22 | self.conv_dw = create_conv2d( 23 | in_channels, int(in_channels * channel_multiplier), kernel_size, 24 | stride=stride, dilation=dilation, padding=padding, depthwise=True) 25 | 26 | self.conv_pw = create_conv2d( 27 | int(in_channels * channel_multiplier), out_channels, pw_kernel_size, padding=padding, bias=bias) 28 | 29 | norm_act_layer = convert_norm_act(norm_layer, act_layer) 30 | self.bn = norm_act_layer(out_channels, apply_act=apply_act, drop_block=drop_block) 31 | 32 | @property 33 | def in_channels(self): 34 | return self.conv_dw.in_channels 35 | 36 | @property 37 | def out_channels(self): 38 | return self.conv_pw.out_channels 39 | 40 | def forward(self, x): 41 | x = self.conv_dw(x) 42 | x = self.conv_pw(x) 43 | if self.bn is not None: 44 | x = self.bn(x) 45 | return x 46 | 47 | 48 | class SeparableConv2d(nn.Module): 49 | """ Separable Conv 50 | """ 51 | def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, dilation=1, padding='', bias=False, 52 | channel_multiplier=1.0, pw_kernel_size=1): 53 | super(SeparableConv2d, self).__init__() 54 | 55 | self.conv_dw = create_conv2d( 56 | in_channels, int(in_channels * channel_multiplier), kernel_size, 57 | stride=stride, dilation=dilation, padding=padding, depthwise=True) 58 | 59 | self.conv_pw = create_conv2d( 60 | int(in_channels * channel_multiplier), out_channels, pw_kernel_size, padding=padding, bias=bias) 61 | 62 | @property 63 | def in_channels(self): 64 | return self.conv_dw.in_channels 65 | 66 | @property 67 | def out_channels(self): 68 | return self.conv_pw.out_channels 69 | 70 | def forward(self, x): 71 | x = self.conv_dw(x) 72 | x = self.conv_pw(x) 73 | return x 74 | -------------------------------------------------------------------------------- /lib/timm/models/layers/space_to_depth.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class SpaceToDepth(nn.Module): 6 | def __init__(self, block_size=4): 7 | super().__init__() 8 | assert block_size == 4 9 | self.bs = block_size 10 | 11 | def forward(self, x): 12 | N, C, H, W = x.size() 13 | x = x.view(N, C, H // self.bs, self.bs, W // self.bs, self.bs) # (N, C, H//bs, bs, W//bs, bs) 14 | x = x.permute(0, 3, 5, 1, 2, 4).contiguous() # (N, bs, bs, C, H//bs, W//bs) 15 | x = x.view(N, C * (self.bs ** 2), H // self.bs, W // self.bs) # (N, C*bs^2, H//bs, W//bs) 16 | return x 17 | 18 | 19 | @torch.jit.script 20 | class SpaceToDepthJit(object): 21 | def __call__(self, x: torch.Tensor): 22 | # assuming hard-coded that block_size==4 for acceleration 23 | N, C, H, W = x.size() 24 | x = x.view(N, C, H // 4, 4, W // 4, 4) # (N, C, H//bs, bs, W//bs, bs) 25 | x = x.permute(0, 3, 5, 1, 2, 4).contiguous() # (N, bs, bs, C, H//bs, W//bs) 26 | x = x.view(N, C * 16, H // 4, W // 4) # (N, C*bs^2, H//bs, W//bs) 27 | return x 28 | 29 | 30 | class SpaceToDepthModule(nn.Module): 31 | def __init__(self, no_jit=False): 32 | super().__init__() 33 | if not no_jit: 34 | self.op = SpaceToDepthJit() 35 | else: 36 | self.op = SpaceToDepth() 37 | 38 | def forward(self, x): 39 | return self.op(x) 40 | 41 | 42 | class DepthToSpace(nn.Module): 43 | 44 | def __init__(self, block_size): 45 | super().__init__() 46 | self.bs = block_size 47 | 48 | def forward(self, x): 49 | N, C, H, W = x.size() 50 | x = x.view(N, self.bs, self.bs, C // (self.bs ** 2), H, W) # (N, bs, bs, C//bs^2, H, W) 51 | x = x.permute(0, 3, 4, 1, 5, 2).contiguous() # (N, C//bs^2, H, bs, W, bs) 52 | x = x.view(N, C // (self.bs ** 2), H * self.bs, W * self.bs) # (N, C//bs^2, H * bs, W * bs) 53 | return x 54 | -------------------------------------------------------------------------------- /lib/timm/models/layers/split_attn.py: -------------------------------------------------------------------------------- 1 | """ Split Attention Conv2d (for ResNeSt Models) 2 | 3 | Paper: `ResNeSt: Split-Attention Networks` - /https://arxiv.org/abs/2004.08955 4 | 5 | Adapted from original PyTorch impl at https://github.com/zhanghang1989/ResNeSt 6 | 7 | Modified for torchscript compat, performance, and consistency with timm by Ross Wightman 8 | """ 9 | import torch 10 | import torch.nn.functional as F 11 | from torch import nn 12 | 13 | from .helpers import make_divisible 14 | 15 | 16 | class RadixSoftmax(nn.Module): 17 | def __init__(self, radix, cardinality): 18 | super(RadixSoftmax, self).__init__() 19 | self.radix = radix 20 | self.cardinality = cardinality 21 | 22 | def forward(self, x): 23 | batch = x.size(0) 24 | if self.radix > 1: 25 | x = x.view(batch, self.cardinality, self.radix, -1).transpose(1, 2) 26 | x = F.softmax(x, dim=1) 27 | x = x.reshape(batch, -1) 28 | else: 29 | x = torch.sigmoid(x) 30 | return x 31 | 32 | 33 | class SplitAttn(nn.Module): 34 | """Split-Attention (aka Splat) 35 | """ 36 | def __init__(self, in_channels, out_channels=None, kernel_size=3, stride=1, padding=None, 37 | dilation=1, groups=1, bias=False, radix=2, rd_ratio=0.25, rd_channels=None, rd_divisor=8, 38 | act_layer=nn.ReLU, norm_layer=None, drop_block=None, **kwargs): 39 | super(SplitAttn, self).__init__() 40 | out_channels = out_channels or in_channels 41 | self.radix = radix 42 | self.drop_block = drop_block 43 | mid_chs = out_channels * radix 44 | if rd_channels is None: 45 | attn_chs = make_divisible(in_channels * radix * rd_ratio, min_value=32, divisor=rd_divisor) 46 | else: 47 | attn_chs = rd_channels * radix 48 | 49 | padding = kernel_size // 2 if padding is None else padding 50 | self.conv = nn.Conv2d( 51 | in_channels, mid_chs, kernel_size, stride, padding, dilation, 52 | groups=groups * radix, bias=bias, **kwargs) 53 | self.bn0 = norm_layer(mid_chs) if norm_layer else nn.Identity() 54 | self.act0 = act_layer(inplace=True) 55 | self.fc1 = nn.Conv2d(out_channels, attn_chs, 1, groups=groups) 56 | self.bn1 = norm_layer(attn_chs) if norm_layer else nn.Identity() 57 | self.act1 = act_layer(inplace=True) 58 | self.fc2 = nn.Conv2d(attn_chs, mid_chs, 1, groups=groups) 59 | self.rsoftmax = RadixSoftmax(radix, groups) 60 | 61 | def forward(self, x): 62 | x = self.conv(x) 63 | x = self.bn0(x) 64 | if self.drop_block is not None: 65 | x = self.drop_block(x) 66 | x = self.act0(x) 67 | 68 | B, RC, H, W = x.shape 69 | if self.radix > 1: 70 | x = x.reshape((B, self.radix, RC // self.radix, H, W)) 71 | x_gap = x.sum(dim=1) 72 | else: 73 | x_gap = x 74 | x_gap = x_gap.mean((2, 3), keepdim=True) 75 | x_gap = self.fc1(x_gap) 76 | x_gap = self.bn1(x_gap) 77 | x_gap = self.act1(x_gap) 78 | x_attn = self.fc2(x_gap) 79 | 80 | x_attn = self.rsoftmax(x_attn).view(B, -1, 1, 1) 81 | if self.radix > 1: 82 | out = (x * x_attn.reshape((B, self.radix, RC // self.radix, 1, 1))).sum(dim=1) 83 | else: 84 | out = x * x_attn 85 | return out.contiguous() 86 | -------------------------------------------------------------------------------- /lib/timm/models/layers/squeeze_excite.py: -------------------------------------------------------------------------------- 1 | """ Squeeze-and-Excitation Channel Attention 2 | 3 | An SE implementation originally based on PyTorch SE-Net impl. 4 | Has since evolved with additional functionality / configuration. 5 | 6 | Paper: `Squeeze-and-Excitation Networks` - https://arxiv.org/abs/1709.01507 7 | 8 | Also included is Effective Squeeze-Excitation (ESE). 9 | Paper: `CenterMask : Real-Time Anchor-Free Instance Segmentation` - https://arxiv.org/abs/1911.06667 10 | 11 | Hacked together by / Copyright 2021 Ross Wightman 12 | """ 13 | from torch import nn as nn 14 | 15 | from .create_act import create_act_layer 16 | from .helpers import make_divisible 17 | 18 | 19 | class SEModule(nn.Module): 20 | """ SE Module as defined in original SE-Nets with a few additions 21 | Additions include: 22 | * divisor can be specified to keep channels % div == 0 (default: 8) 23 | * reduction channels can be specified directly by arg (if rd_channels is set) 24 | * reduction channels can be specified by float rd_ratio (default: 1/16) 25 | * global max pooling can be added to the squeeze aggregation 26 | * customizable activation, normalization, and gate layer 27 | """ 28 | def __init__( 29 | self, channels, rd_ratio=1. / 16, rd_channels=None, rd_divisor=8, add_maxpool=False, 30 | act_layer=nn.ReLU, norm_layer=None, gate_layer='sigmoid'): 31 | super(SEModule, self).__init__() 32 | self.add_maxpool = add_maxpool 33 | if not rd_channels: 34 | rd_channels = make_divisible(channels * rd_ratio, rd_divisor, round_limit=0.) 35 | self.fc1 = nn.Conv2d(channels, rd_channels, kernel_size=1, bias=True) 36 | self.bn = norm_layer(rd_channels) if norm_layer else nn.Identity() 37 | self.act = create_act_layer(act_layer, inplace=True) 38 | self.fc2 = nn.Conv2d(rd_channels, channels, kernel_size=1, bias=True) 39 | self.gate = create_act_layer(gate_layer) 40 | 41 | def forward(self, x): 42 | x_se = x.mean((2, 3), keepdim=True) 43 | if self.add_maxpool: 44 | # experimental codepath, may remove or change 45 | x_se = 0.5 * x_se + 0.5 * x.amax((2, 3), keepdim=True) 46 | x_se = self.fc1(x_se) 47 | x_se = self.act(self.bn(x_se)) 48 | x_se = self.fc2(x_se) 49 | return x * self.gate(x_se) 50 | 51 | 52 | SqueezeExcite = SEModule # alias 53 | 54 | 55 | class EffectiveSEModule(nn.Module): 56 | """ 'Effective Squeeze-Excitation 57 | From `CenterMask : Real-Time Anchor-Free Instance Segmentation` - https://arxiv.org/abs/1911.06667 58 | """ 59 | def __init__(self, channels, add_maxpool=False, gate_layer='hard_sigmoid', **_): 60 | super(EffectiveSEModule, self).__init__() 61 | self.add_maxpool = add_maxpool 62 | self.fc = nn.Conv2d(channels, channels, kernel_size=1, padding=0) 63 | self.gate = create_act_layer(gate_layer) 64 | 65 | def forward(self, x): 66 | x_se = x.mean((2, 3), keepdim=True) 67 | if self.add_maxpool: 68 | # experimental codepath, may remove or change 69 | x_se = 0.5 * x_se + 0.5 * x.amax((2, 3), keepdim=True) 70 | x_se = self.fc(x_se) 71 | return x * self.gate(x_se) 72 | 73 | 74 | EffectiveSqueezeExcite = EffectiveSEModule # alias 75 | -------------------------------------------------------------------------------- /lib/timm/models/layers/test_time_pool.py: -------------------------------------------------------------------------------- 1 | """ Test Time Pooling (Average-Max Pool) 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | 6 | import logging 7 | from torch import nn 8 | import torch.nn.functional as F 9 | 10 | from .adaptive_avgmax_pool import adaptive_avgmax_pool2d 11 | 12 | 13 | _logger = logging.getLogger(__name__) 14 | 15 | 16 | class TestTimePoolHead(nn.Module): 17 | def __init__(self, base, original_pool=7): 18 | super(TestTimePoolHead, self).__init__() 19 | self.base = base 20 | self.original_pool = original_pool 21 | base_fc = self.base.get_classifier() 22 | if isinstance(base_fc, nn.Conv2d): 23 | self.fc = base_fc 24 | else: 25 | self.fc = nn.Conv2d( 26 | self.base.num_features, self.base.num_classes, kernel_size=1, bias=True) 27 | self.fc.weight.data.copy_(base_fc.weight.data.view(self.fc.weight.size())) 28 | self.fc.bias.data.copy_(base_fc.bias.data.view(self.fc.bias.size())) 29 | self.base.reset_classifier(0) # delete original fc layer 30 | 31 | def forward(self, x): 32 | x = self.base.forward_features(x) 33 | x = F.avg_pool2d(x, kernel_size=self.original_pool, stride=1) 34 | x = self.fc(x) 35 | x = adaptive_avgmax_pool2d(x, 1) 36 | return x.view(x.size(0), -1) 37 | 38 | 39 | def apply_test_time_pool(model, config, use_test_size=True): 40 | test_time_pool = False 41 | if not hasattr(model, 'default_cfg') or not model.default_cfg: 42 | return model, False 43 | if use_test_size and 'test_input_size' in model.default_cfg: 44 | df_input_size = model.default_cfg['test_input_size'] 45 | else: 46 | df_input_size = model.default_cfg['input_size'] 47 | if config['input_size'][-1] > df_input_size[-1] and config['input_size'][-2] > df_input_size[-2]: 48 | _logger.info('Target input size %s > pretrained default %s, using test time pooling' % 49 | (str(config['input_size'][-2:]), str(df_input_size[-2:]))) 50 | model = TestTimePoolHead(model, original_pool=model.default_cfg['pool_size']) 51 | test_time_pool = True 52 | return model, test_time_pool 53 | -------------------------------------------------------------------------------- /lib/timm/models/layers/trace_utils.py: -------------------------------------------------------------------------------- 1 | try: 2 | from torch import _assert 3 | except ImportError: 4 | def _assert(condition: bool, message: str): 5 | assert condition, message 6 | 7 | 8 | def _float_to_int(x: float) -> int: 9 | """ 10 | Symbolic tracing helper to substitute for inbuilt `int`. 11 | Hint: Inbuilt `int` can't accept an argument of type `Proxy` 12 | """ 13 | return int(x) 14 | -------------------------------------------------------------------------------- /lib/timm/optim/__init__.py: -------------------------------------------------------------------------------- 1 | from .adabelief import AdaBelief 2 | from .adafactor import Adafactor 3 | from .adahessian import Adahessian 4 | from .adamp import AdamP 5 | from .adamw import AdamW 6 | from .lamb import Lamb 7 | from .lars import Lars 8 | from .lookahead import Lookahead 9 | from .madgrad import MADGRAD 10 | from .nadam import Nadam 11 | from .nvnovograd import NvNovoGrad 12 | from .radam import RAdam 13 | from .rmsprop_tf import RMSpropTF 14 | from .sgdp import SGDP 15 | from .optim_factory import create_optimizer, create_optimizer_v2, optimizer_kwargs 16 | -------------------------------------------------------------------------------- /lib/timm/optim/lookahead.py: -------------------------------------------------------------------------------- 1 | """ Lookahead Optimizer Wrapper. 2 | Implementation modified from: https://github.com/alphadl/lookahead.pytorch 3 | Paper: `Lookahead Optimizer: k steps forward, 1 step back` - https://arxiv.org/abs/1907.08610 4 | 5 | Hacked together by / Copyright 2020 Ross Wightman 6 | """ 7 | import torch 8 | from torch.optim.optimizer import Optimizer 9 | from collections import defaultdict 10 | 11 | 12 | class Lookahead(Optimizer): 13 | def __init__(self, base_optimizer, alpha=0.5, k=6): 14 | # NOTE super().__init__() not called on purpose 15 | if not 0.0 <= alpha <= 1.0: 16 | raise ValueError(f'Invalid slow update rate: {alpha}') 17 | if not 1 <= k: 18 | raise ValueError(f'Invalid lookahead steps: {k}') 19 | defaults = dict(lookahead_alpha=alpha, lookahead_k=k, lookahead_step=0) 20 | self._base_optimizer = base_optimizer 21 | self.param_groups = base_optimizer.param_groups 22 | self.defaults = base_optimizer.defaults 23 | self.defaults.update(defaults) 24 | self.state = defaultdict(dict) 25 | # manually add our defaults to the param groups 26 | for name, default in defaults.items(): 27 | for group in self._base_optimizer.param_groups: 28 | group.setdefault(name, default) 29 | 30 | @torch.no_grad() 31 | def update_slow(self, group): 32 | for fast_p in group["params"]: 33 | if fast_p.grad is None: 34 | continue 35 | param_state = self._base_optimizer.state[fast_p] 36 | if 'lookahead_slow_buff' not in param_state: 37 | param_state['lookahead_slow_buff'] = torch.empty_like(fast_p) 38 | param_state['lookahead_slow_buff'].copy_(fast_p) 39 | slow = param_state['lookahead_slow_buff'] 40 | slow.add_(fast_p - slow, alpha=group['lookahead_alpha']) 41 | fast_p.copy_(slow) 42 | 43 | def sync_lookahead(self): 44 | for group in self._base_optimizer.param_groups: 45 | self.update_slow(group) 46 | 47 | @torch.no_grad() 48 | def step(self, closure=None): 49 | loss = self._base_optimizer.step(closure) 50 | for group in self._base_optimizer.param_groups: 51 | group['lookahead_step'] += 1 52 | if group['lookahead_step'] % group['lookahead_k'] == 0: 53 | self.update_slow(group) 54 | return loss 55 | 56 | def state_dict(self): 57 | return self._base_optimizer.state_dict() 58 | 59 | def load_state_dict(self, state_dict): 60 | self._base_optimizer.load_state_dict(state_dict) 61 | self.param_groups = self._base_optimizer.param_groups 62 | -------------------------------------------------------------------------------- /lib/timm/optim/sgdp.py: -------------------------------------------------------------------------------- 1 | """ 2 | SGDP Optimizer Implementation copied from https://github.com/clovaai/AdamP/blob/master/adamp/sgdp.py 3 | 4 | Paper: `Slowing Down the Weight Norm Increase in Momentum-based Optimizers` - https://arxiv.org/abs/2006.08217 5 | Code: https://github.com/clovaai/AdamP 6 | 7 | Copyright (c) 2020-present NAVER Corp. 8 | MIT license 9 | """ 10 | 11 | import torch 12 | import torch.nn.functional as F 13 | from torch.optim.optimizer import Optimizer, required 14 | import math 15 | 16 | from .adamp import projection 17 | 18 | 19 | class SGDP(Optimizer): 20 | def __init__(self, params, lr=required, momentum=0, dampening=0, 21 | weight_decay=0, nesterov=False, eps=1e-8, delta=0.1, wd_ratio=0.1): 22 | defaults = dict( 23 | lr=lr, momentum=momentum, dampening=dampening, weight_decay=weight_decay, 24 | nesterov=nesterov, eps=eps, delta=delta, wd_ratio=wd_ratio) 25 | super(SGDP, self).__init__(params, defaults) 26 | 27 | @torch.no_grad() 28 | def step(self, closure=None): 29 | loss = None 30 | if closure is not None: 31 | with torch.enable_grad(): 32 | loss = closure() 33 | 34 | for group in self.param_groups: 35 | weight_decay = group['weight_decay'] 36 | momentum = group['momentum'] 37 | dampening = group['dampening'] 38 | nesterov = group['nesterov'] 39 | 40 | for p in group['params']: 41 | if p.grad is None: 42 | continue 43 | grad = p.grad 44 | state = self.state[p] 45 | 46 | # State initialization 47 | if len(state) == 0: 48 | state['momentum'] = torch.zeros_like(p) 49 | 50 | # SGD 51 | buf = state['momentum'] 52 | buf.mul_(momentum).add_(grad, alpha=1. - dampening) 53 | if nesterov: 54 | d_p = grad + momentum * buf 55 | else: 56 | d_p = buf 57 | 58 | # Projection 59 | wd_ratio = 1. 60 | if len(p.shape) > 1: 61 | d_p, wd_ratio = projection(p, grad, d_p, group['delta'], group['wd_ratio'], group['eps']) 62 | 63 | # Weight decay 64 | if weight_decay != 0: 65 | p.mul_(1. - group['lr'] * group['weight_decay'] * wd_ratio / (1-momentum)) 66 | 67 | # Step 68 | p.add_(d_p, alpha=-group['lr']) 69 | 70 | return loss 71 | -------------------------------------------------------------------------------- /lib/timm/scheduler/__init__.py: -------------------------------------------------------------------------------- 1 | from .cosine_lr import CosineLRScheduler 2 | from .multistep_lr import MultiStepLRScheduler 3 | from .plateau_lr import PlateauLRScheduler 4 | from .poly_lr import PolyLRScheduler 5 | from .step_lr import StepLRScheduler 6 | from .tanh_lr import TanhLRScheduler 7 | 8 | from .scheduler_factory import create_scheduler 9 | -------------------------------------------------------------------------------- /lib/timm/scheduler/multistep_lr.py: -------------------------------------------------------------------------------- 1 | """ MultiStep LR Scheduler 2 | 3 | Basic multi step LR schedule with warmup, noise. 4 | """ 5 | import torch 6 | import bisect 7 | from timm.scheduler.scheduler import Scheduler 8 | from typing import List 9 | 10 | class MultiStepLRScheduler(Scheduler): 11 | """ 12 | """ 13 | 14 | def __init__(self, 15 | optimizer: torch.optim.Optimizer, 16 | decay_t: List[int], 17 | decay_rate: float = 1., 18 | warmup_t=0, 19 | warmup_lr_init=0, 20 | t_in_epochs=True, 21 | noise_range_t=None, 22 | noise_pct=0.67, 23 | noise_std=1.0, 24 | noise_seed=42, 25 | initialize=True, 26 | ) -> None: 27 | super().__init__( 28 | optimizer, param_group_field="lr", 29 | noise_range_t=noise_range_t, noise_pct=noise_pct, noise_std=noise_std, noise_seed=noise_seed, 30 | initialize=initialize) 31 | 32 | self.decay_t = decay_t 33 | self.decay_rate = decay_rate 34 | self.warmup_t = warmup_t 35 | self.warmup_lr_init = warmup_lr_init 36 | self.t_in_epochs = t_in_epochs 37 | if self.warmup_t: 38 | self.warmup_steps = [(v - warmup_lr_init) / self.warmup_t for v in self.base_values] 39 | super().update_groups(self.warmup_lr_init) 40 | else: 41 | self.warmup_steps = [1 for _ in self.base_values] 42 | 43 | def get_curr_decay_steps(self, t): 44 | # find where in the array t goes, 45 | # assumes self.decay_t is sorted 46 | return bisect.bisect_right(self.decay_t, t+1) 47 | 48 | def _get_lr(self, t): 49 | if t < self.warmup_t: 50 | lrs = [self.warmup_lr_init + t * s for s in self.warmup_steps] 51 | else: 52 | lrs = [v * (self.decay_rate ** self.get_curr_decay_steps(t)) for v in self.base_values] 53 | return lrs 54 | 55 | def get_epoch_values(self, epoch: int): 56 | if self.t_in_epochs: 57 | return self._get_lr(epoch) 58 | else: 59 | return None 60 | 61 | def get_update_values(self, num_updates: int): 62 | if not self.t_in_epochs: 63 | return self._get_lr(num_updates) 64 | else: 65 | return None 66 | -------------------------------------------------------------------------------- /lib/timm/scheduler/step_lr.py: -------------------------------------------------------------------------------- 1 | """ Step Scheduler 2 | 3 | Basic step LR schedule with warmup, noise. 4 | 5 | Hacked together by / Copyright 2020 Ross Wightman 6 | """ 7 | import math 8 | import torch 9 | 10 | from .scheduler import Scheduler 11 | 12 | 13 | class StepLRScheduler(Scheduler): 14 | """ 15 | """ 16 | 17 | def __init__(self, 18 | optimizer: torch.optim.Optimizer, 19 | decay_t: float, 20 | decay_rate: float = 1., 21 | warmup_t=0, 22 | warmup_lr_init=0, 23 | t_in_epochs=True, 24 | noise_range_t=None, 25 | noise_pct=0.67, 26 | noise_std=1.0, 27 | noise_seed=42, 28 | initialize=True, 29 | ) -> None: 30 | super().__init__( 31 | optimizer, param_group_field="lr", 32 | noise_range_t=noise_range_t, noise_pct=noise_pct, noise_std=noise_std, noise_seed=noise_seed, 33 | initialize=initialize) 34 | 35 | self.decay_t = decay_t 36 | self.decay_rate = decay_rate 37 | self.warmup_t = warmup_t 38 | self.warmup_lr_init = warmup_lr_init 39 | self.t_in_epochs = t_in_epochs 40 | if self.warmup_t: 41 | self.warmup_steps = [(v - warmup_lr_init) / self.warmup_t for v in self.base_values] 42 | super().update_groups(self.warmup_lr_init) 43 | else: 44 | self.warmup_steps = [1 for _ in self.base_values] 45 | 46 | def _get_lr(self, t): 47 | if t < self.warmup_t: 48 | lrs = [self.warmup_lr_init + t * s for s in self.warmup_steps] 49 | else: 50 | lrs = [v * (self.decay_rate ** (t // self.decay_t)) for v in self.base_values] 51 | return lrs 52 | 53 | def get_epoch_values(self, epoch: int): 54 | if self.t_in_epochs: 55 | return self._get_lr(epoch) 56 | else: 57 | return None 58 | 59 | def get_update_values(self, num_updates: int): 60 | if not self.t_in_epochs: 61 | return self._get_lr(num_updates) 62 | else: 63 | return None 64 | -------------------------------------------------------------------------------- /lib/timm/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .agc import adaptive_clip_grad 2 | from .checkpoint_saver import CheckpointSaver 3 | from .clip_grad import dispatch_clip_grad 4 | from .cuda import ApexScaler, NativeScaler 5 | from .distributed import distribute_bn, reduce_tensor 6 | from .jit import set_jit_legacy 7 | from .log import setup_default_logging, FormatterNoInfo 8 | from .metrics import AverageMeter, accuracy 9 | from .misc import natural_key, add_bool_arg 10 | from .model import unwrap_model, get_state_dict, freeze, unfreeze 11 | from .model_ema import ModelEma, ModelEmaV2 12 | from .random import random_seed 13 | from .summary import update_summary, get_outdir 14 | -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/agc.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/agc.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/checkpoint_saver.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/checkpoint_saver.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/clip_grad.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/clip_grad.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/cuda.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/cuda.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/distributed.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/distributed.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/jit.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/jit.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/log.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/log.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/metrics.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/metrics.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/misc.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/misc.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/model.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/model.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/model_ema.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/model_ema.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/random.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/random.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/__pycache__/summary.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/timm/utils/__pycache__/summary.cpython-38.pyc -------------------------------------------------------------------------------- /lib/timm/utils/agc.py: -------------------------------------------------------------------------------- 1 | """ Adaptive Gradient Clipping 2 | 3 | An impl of AGC, as per (https://arxiv.org/abs/2102.06171): 4 | 5 | @article{brock2021high, 6 | author={Andrew Brock and Soham De and Samuel L. Smith and Karen Simonyan}, 7 | title={High-Performance Large-Scale Image Recognition Without Normalization}, 8 | journal={arXiv preprint arXiv:}, 9 | year={2021} 10 | } 11 | 12 | Code references: 13 | * Official JAX impl (paper authors): https://github.com/deepmind/deepmind-research/tree/master/nfnets 14 | * Phil Wang's PyTorch gist: https://gist.github.com/lucidrains/0d6560077edac419ab5d3aa29e674d5c 15 | 16 | Hacked together by / Copyright 2021 Ross Wightman 17 | """ 18 | import torch 19 | 20 | 21 | def unitwise_norm(x, norm_type=2.0): 22 | if x.ndim <= 1: 23 | return x.norm(norm_type) 24 | else: 25 | # works for nn.ConvNd and nn,Linear where output dim is first in the kernel/weight tensor 26 | # might need special cases for other weights (possibly MHA) where this may not be true 27 | return x.norm(norm_type, dim=tuple(range(1, x.ndim)), keepdim=True) 28 | 29 | 30 | def adaptive_clip_grad(parameters, clip_factor=0.01, eps=1e-3, norm_type=2.0): 31 | if isinstance(parameters, torch.Tensor): 32 | parameters = [parameters] 33 | for p in parameters: 34 | if p.grad is None: 35 | continue 36 | p_data = p.detach() 37 | g_data = p.grad.detach() 38 | max_norm = unitwise_norm(p_data, norm_type=norm_type).clamp_(min=eps).mul_(clip_factor) 39 | grad_norm = unitwise_norm(g_data, norm_type=norm_type) 40 | clipped_grad = g_data * (max_norm / grad_norm.clamp(min=1e-6)) 41 | new_grads = torch.where(grad_norm < max_norm, g_data, clipped_grad) 42 | p.grad.detach().copy_(new_grads) 43 | -------------------------------------------------------------------------------- /lib/timm/utils/clip_grad.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from timm.utils.agc import adaptive_clip_grad 4 | 5 | 6 | def dispatch_clip_grad(parameters, value: float, mode: str = 'norm', norm_type: float = 2.0): 7 | """ Dispatch to gradient clipping method 8 | 9 | Args: 10 | parameters (Iterable): model parameters to clip 11 | value (float): clipping value/factor/norm, mode dependant 12 | mode (str): clipping mode, one of 'norm', 'value', 'agc' 13 | norm_type (float): p-norm, default 2.0 14 | """ 15 | if mode == 'norm': 16 | torch.nn.utils.clip_grad_norm_(parameters, value, norm_type=norm_type) 17 | elif mode == 'value': 18 | torch.nn.utils.clip_grad_value_(parameters, value) 19 | elif mode == 'agc': 20 | adaptive_clip_grad(parameters, value, norm_type=norm_type) 21 | else: 22 | assert False, f"Unknown clip mode ({mode})." 23 | 24 | -------------------------------------------------------------------------------- /lib/timm/utils/cuda.py: -------------------------------------------------------------------------------- 1 | """ CUDA / AMP utils 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import torch 6 | 7 | try: 8 | from apex import amp 9 | has_apex = True 10 | except ImportError: 11 | amp = None 12 | has_apex = False 13 | 14 | from .clip_grad import dispatch_clip_grad 15 | 16 | 17 | class ApexScaler: 18 | state_dict_key = "amp" 19 | 20 | def __call__(self, loss, optimizer, clip_grad=None, clip_mode='norm', parameters=None, create_graph=False): 21 | with amp.scale_loss(loss, optimizer) as scaled_loss: 22 | scaled_loss.backward(create_graph=create_graph) 23 | if clip_grad is not None: 24 | dispatch_clip_grad(amp.master_params(optimizer), clip_grad, mode=clip_mode) 25 | optimizer.step() 26 | 27 | def state_dict(self): 28 | if 'state_dict' in amp.__dict__: 29 | return amp.state_dict() 30 | 31 | def load_state_dict(self, state_dict): 32 | if 'load_state_dict' in amp.__dict__: 33 | amp.load_state_dict(state_dict) 34 | 35 | 36 | class NativeScaler: 37 | state_dict_key = "amp_scaler" 38 | 39 | def __init__(self): 40 | self._scaler = torch.cuda.amp.GradScaler() 41 | 42 | def __call__(self, loss, optimizer, clip_grad=None, clip_mode='norm', parameters=None, create_graph=False): 43 | self._scaler.scale(loss).backward(create_graph=create_graph) 44 | if clip_grad is not None: 45 | assert parameters is not None 46 | self._scaler.unscale_(optimizer) # unscale the gradients of optimizer's assigned params in-place 47 | dispatch_clip_grad(parameters, clip_grad, mode=clip_mode) 48 | self._scaler.step(optimizer) 49 | self._scaler.update() 50 | 51 | def state_dict(self): 52 | return self._scaler.state_dict() 53 | 54 | def load_state_dict(self, state_dict): 55 | self._scaler.load_state_dict(state_dict) 56 | -------------------------------------------------------------------------------- /lib/timm/utils/distributed.py: -------------------------------------------------------------------------------- 1 | """ Distributed training/validation utils 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import torch 6 | from torch import distributed as dist 7 | 8 | from .model import unwrap_model 9 | 10 | 11 | def reduce_tensor(tensor, n): 12 | rt = tensor.clone() 13 | dist.all_reduce(rt, op=dist.ReduceOp.SUM) 14 | rt /= n 15 | return rt 16 | 17 | 18 | def distribute_bn(model, world_size, reduce=False): 19 | # ensure every node has the same running bn stats 20 | for bn_name, bn_buf in unwrap_model(model).named_buffers(recurse=True): 21 | if ('running_mean' in bn_name) or ('running_var' in bn_name): 22 | if reduce: 23 | # average bn stats across whole group 24 | torch.distributed.all_reduce(bn_buf, op=dist.ReduceOp.SUM) 25 | bn_buf /= float(world_size) 26 | else: 27 | # broadcast bn stats from rank 0 to whole group 28 | torch.distributed.broadcast(bn_buf, 0) 29 | -------------------------------------------------------------------------------- /lib/timm/utils/jit.py: -------------------------------------------------------------------------------- 1 | """ JIT scripting/tracing utils 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import torch 6 | 7 | 8 | def set_jit_legacy(): 9 | """ Set JIT executor to legacy w/ support for op fusion 10 | This is hopefully a temporary need in 1.5/1.5.1/1.6 to restore performance due to changes 11 | in the JIT exectutor. These API are not supported so could change. 12 | """ 13 | # 14 | assert hasattr(torch._C, '_jit_set_profiling_executor'), "Old JIT behavior doesn't exist!" 15 | torch._C._jit_set_profiling_executor(False) 16 | torch._C._jit_set_profiling_mode(False) 17 | torch._C._jit_override_can_fuse_on_gpu(True) 18 | #torch._C._jit_set_texpr_fuser_enabled(True) 19 | -------------------------------------------------------------------------------- /lib/timm/utils/log.py: -------------------------------------------------------------------------------- 1 | """ Logging helpers 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import logging 6 | import logging.handlers 7 | 8 | 9 | class FormatterNoInfo(logging.Formatter): 10 | def __init__(self, fmt='%(levelname)s: %(message)s'): 11 | logging.Formatter.__init__(self, fmt) 12 | 13 | def format(self, record): 14 | if record.levelno == logging.INFO: 15 | return str(record.getMessage()) 16 | return logging.Formatter.format(self, record) 17 | 18 | 19 | def setup_default_logging(default_level=logging.INFO, log_path=''): 20 | console_handler = logging.StreamHandler() 21 | console_handler.setFormatter(FormatterNoInfo()) 22 | logging.root.addHandler(console_handler) 23 | logging.root.setLevel(default_level) 24 | if log_path: 25 | file_handler = logging.handlers.RotatingFileHandler(log_path, maxBytes=(1024 ** 2 * 2), backupCount=3) 26 | file_formatter = logging.Formatter("%(asctime)s - %(name)20s: [%(levelname)8s] - %(message)s") 27 | file_handler.setFormatter(file_formatter) 28 | logging.root.addHandler(file_handler) 29 | -------------------------------------------------------------------------------- /lib/timm/utils/metrics.py: -------------------------------------------------------------------------------- 1 | """ Eval metrics and related 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | 6 | 7 | class AverageMeter: 8 | """Computes and stores the average and current value""" 9 | def __init__(self): 10 | self.reset() 11 | 12 | def reset(self): 13 | self.val = 0 14 | self.avg = 0 15 | self.sum = 0 16 | self.count = 0 17 | 18 | def update(self, val, n=1): 19 | self.val = val 20 | self.sum += val * n 21 | self.count += n 22 | self.avg = self.sum / self.count 23 | 24 | 25 | def accuracy(output, target, topk=(1,)): 26 | """Computes the accuracy over the k top predictions for the specified values of k""" 27 | maxk = min(max(topk), output.size()[1]) 28 | batch_size = target.size(0) 29 | _, pred = output.topk(maxk, 1, True, True) 30 | pred = pred.t() 31 | correct = pred.eq(target.reshape(1, -1).expand_as(pred)) 32 | return [correct[:min(k, maxk)].reshape(-1).float().sum(0) * 100. / batch_size for k in topk] 33 | -------------------------------------------------------------------------------- /lib/timm/utils/misc.py: -------------------------------------------------------------------------------- 1 | """ Misc utils 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import re 6 | 7 | 8 | def natural_key(string_): 9 | """See http://www.codinghorror.com/blog/archives/001018.html""" 10 | return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_.lower())] 11 | 12 | 13 | def add_bool_arg(parser, name, default=False, help=''): 14 | dest_name = name.replace('-', '_') 15 | group = parser.add_mutually_exclusive_group(required=False) 16 | group.add_argument('--' + name, dest=dest_name, action='store_true', help=help) 17 | group.add_argument('--no-' + name, dest=dest_name, action='store_false', help=help) 18 | parser.set_defaults(**{dest_name: default}) 19 | -------------------------------------------------------------------------------- /lib/timm/utils/random.py: -------------------------------------------------------------------------------- 1 | import random 2 | import numpy as np 3 | import torch 4 | 5 | 6 | def random_seed(seed=42, rank=0): 7 | torch.manual_seed(seed + rank) 8 | np.random.seed(seed + rank) 9 | random.seed(seed + rank) 10 | -------------------------------------------------------------------------------- /lib/timm/utils/summary.py: -------------------------------------------------------------------------------- 1 | """ Summary utilities 2 | 3 | Hacked together by / Copyright 2020 Ross Wightman 4 | """ 5 | import csv 6 | import os 7 | from collections import OrderedDict 8 | try: 9 | import wandb 10 | except ImportError: 11 | pass 12 | 13 | def get_outdir(path, *paths, inc=False): 14 | outdir = os.path.join(path, *paths) 15 | if not os.path.exists(outdir): 16 | os.makedirs(outdir) 17 | elif inc: 18 | count = 1 19 | outdir_inc = outdir + '-' + str(count) 20 | while os.path.exists(outdir_inc): 21 | count = count + 1 22 | outdir_inc = outdir + '-' + str(count) 23 | assert count < 100 24 | outdir = outdir_inc 25 | os.makedirs(outdir) 26 | return outdir 27 | 28 | 29 | def update_summary(epoch, train_metrics, eval_metrics, filename, write_header=False, log_wandb=False): 30 | rowd = OrderedDict(epoch=epoch) 31 | rowd.update([('train_' + k, v) for k, v in train_metrics.items()]) 32 | rowd.update([('eval_' + k, v) for k, v in eval_metrics.items()]) 33 | if log_wandb: 34 | wandb.log(rowd) 35 | with open(filename, mode='a') as cf: 36 | dw = csv.DictWriter(cf, fieldnames=rowd.keys()) 37 | if write_header: # first iteration (epoch == 1 can't be used) 38 | dw.writeheader() 39 | dw.writerow(rowd) 40 | -------------------------------------------------------------------------------- /lib/timm/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.5.0' 2 | -------------------------------------------------------------------------------- /lib/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/utils/__init__.py -------------------------------------------------------------------------------- /lib/utils/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/utils/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/opencv_functional.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/utils/__pycache__/opencv_functional.cpython-38.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/opencv_transforms.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/utils/__pycache__/opencv_transforms.cpython-38.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/transforms.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/utils/__pycache__/transforms.cpython-38.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/utils/__pycache__/utils.cpython-38.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/vis.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/lib/utils/__pycache__/vis.cpython-38.pyc -------------------------------------------------------------------------------- /lib/utils/zipreader.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Copyright (c) Microsoft 3 | # Licensed under the MIT License. 4 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 5 | # ------------------------------------------------------------------------------ 6 | 7 | from __future__ import absolute_import 8 | from __future__ import division 9 | from __future__ import print_function 10 | 11 | import os 12 | import zipfile 13 | import xml.etree.ElementTree as ET 14 | 15 | import cv2 16 | import numpy as np 17 | 18 | _im_zfile = [] 19 | _xml_path_zip = [] 20 | _xml_zfile = [] 21 | 22 | 23 | def imread(filename, flags=cv2.IMREAD_COLOR): 24 | global _im_zfile 25 | path = filename 26 | pos_at = path.index('@') 27 | if pos_at == -1: 28 | print("character '@' is not found from the given path '%s'"%(path)) 29 | assert 0 30 | path_zip = path[0: pos_at] 31 | path_img = path[pos_at + 2:] 32 | if not os.path.isfile(path_zip): 33 | print("zip file '%s' is not found"%(path_zip)) 34 | assert 0 35 | for i in range(len(_im_zfile)): 36 | if _im_zfile[i]['path'] == path_zip: 37 | data = _im_zfile[i]['zipfile'].read(path_img) 38 | return cv2.imdecode(np.frombuffer(data, np.uint8), flags) 39 | 40 | _im_zfile.append({ 41 | 'path': path_zip, 42 | 'zipfile': zipfile.ZipFile(path_zip, 'r') 43 | }) 44 | data = _im_zfile[-1]['zipfile'].read(path_img) 45 | 46 | return cv2.imdecode(np.frombuffer(data, np.uint8), flags) 47 | 48 | 49 | def xmlread(filename): 50 | global _xml_path_zip 51 | global _xml_zfile 52 | path = filename 53 | pos_at = path.index('@') 54 | if pos_at == -1: 55 | print("character '@' is not found from the given path '%s'"%(path)) 56 | assert 0 57 | path_zip = path[0: pos_at] 58 | path_xml = path[pos_at + 2:] 59 | if not os.path.isfile(path_zip): 60 | print("zip file '%s' is not found"%(path_zip)) 61 | assert 0 62 | for i in xrange(len(_xml_path_zip)): 63 | if _xml_path_zip[i] == path_zip: 64 | data = _xml_zfile[i].open(path_xml) 65 | return ET.fromstring(data.read()) 66 | _xml_path_zip.append(path_zip) 67 | print("read new xml file '%s'"%(path_zip)) 68 | _xml_zfile.append(zipfile.ZipFile(path_zip, 'r')) 69 | data = _xml_zfile[-1].open(path_xml) 70 | return ET.fromstring(data.read()) 71 | -------------------------------------------------------------------------------- /logs/COCO2017/coco_val_POSE_CILVR.out: -------------------------------------------------------------------------------- 1 | Sun May 15 00:25:03 2022 2 | +-----------------------------------------------------------------------------+ 3 | | NVIDIA-SMI 470.57.02 Driver Version: 470.57.02 CUDA Version: 11.4 | 4 | |-------------------------------+----------------------+----------------------+ 5 | | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | 6 | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | 7 | | | | MIG M. | 8 | |===============================+======================+======================| 9 | | 0 Tesla V100-SXM2... On | 00000000:85:00.0 Off | 0 | 10 | | N/A 39C P0 44W / 163W | 0MiB / 32510MiB | 0% Default | 11 | | | | N/A | 12 | +-------------------------------+----------------------+----------------------+ 13 | | 1 Tesla V100-SXM2... On | 00000000:86:00.0 Off | 0 | 14 | | N/A 41C P0 42W / 163W | 0MiB / 32510MiB | 0% Default | 15 | | | | N/A | 16 | +-------------------------------+----------------------+----------------------+ 17 | 18 | +-----------------------------------------------------------------------------+ 19 | | Processes: | 20 | | GPU GI CI PID Type Process name GPU Memory | 21 | | ID ID Usage | 22 | |=============================================================================| 23 | | No running processes found | 24 | +-----------------------------------------------------------------------------+ 25 | => creating output/coco/pose_aggpose/aggpose_L_256x192_val 26 | => creating log/coco/pose_aggpose/aggpose_L_256x192_val_2022-05-15-00-25 27 | loading annotations into memory... 28 | Done (t=0.38s) 29 | creating index... 30 | index created! 31 | Loading and preparing results... 32 | DONE (t=5.55s) 33 | creating index... 34 | index created! 35 | Running per image evaluation... 36 | Evaluate annotation type *keypoints* 37 | DONE (t=16.68s). 38 | Accumulating evaluation results... 39 | DONE (t=0.38s). 40 | Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets= 20 ] = 0.764 41 | Average Precision (AP) @[ IoU=0.50 | area= all | maxDets= 20 ] = 0.906 42 | Average Precision (AP) @[ IoU=0.75 | area= all | maxDets= 20 ] = 0.829 43 | Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets= 20 ] = 0.727 44 | Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets= 20 ] = 0.834 45 | Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 20 ] = 0.813 46 | Average Recall (AR) @[ IoU=0.50 | area= all | maxDets= 20 ] = 0.944 47 | Average Recall (AR) @[ IoU=0.75 | area= all | maxDets= 20 ] = 0.872 48 | Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets= 20 ] = 0.772 49 | Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets= 20 ] = 0.873 50 | -------------------------------------------------------------------------------- /tools/__pycache__/_init_paths.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PediaMedAI/AggPose/754066e9844cf52ee7727c47a4eb7107ab18a6ac/tools/__pycache__/_init_paths.cpython-38.pyc -------------------------------------------------------------------------------- /tools/_init_paths.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # pose.pytorch 3 | # Copyright (c) 2018-present Microsoft 4 | # Licensed under The Apache-2.0 License [see LICENSE for details] 5 | # Written by Bin Xiao (Bin.Xiao@microsoft.com) 6 | # ------------------------------------------------------------------------------ 7 | 8 | from __future__ import absolute_import 9 | from __future__ import division 10 | from __future__ import print_function 11 | 12 | import os.path as osp 13 | import sys 14 | 15 | 16 | def add_path(path): 17 | if path not in sys.path: 18 | sys.path.insert(0, path) 19 | 20 | 21 | this_dir = osp.dirname(__file__) 22 | 23 | lib_path = osp.join(this_dir, '..', 'lib') 24 | add_path(lib_path) 25 | 26 | mm_path = osp.join(this_dir, '..', 'lib/poseeval/py-motmetrics') 27 | add_path(mm_path) 28 | --------------------------------------------------------------------------------