├── .gitignore ├── AutoFormer ├── .figure │ ├── ofa.png │ ├── overview.png │ └── performance.png ├── README.md ├── evolution.py ├── experiments │ ├── subnet │ │ ├── AutoFormer-B.yaml │ │ ├── AutoFormer-S.yaml │ │ └── AutoFormer-T.yaml │ └── supernet │ │ ├── supernet-B.yaml │ │ ├── supernet-S.yaml │ │ └── supernet-T.yaml ├── lib │ ├── config.py │ ├── datasets.py │ ├── imagenet_withhold.py │ ├── samplers.py │ ├── subImageNet.py │ └── utils.py ├── model │ ├── module │ │ ├── Linear_super.py │ │ ├── __init__.py │ │ ├── embedding_super.py │ │ ├── layernorm_super.py │ │ ├── multihead_super.py │ │ └── qkv_super.py │ ├── supernet_transformer.py │ └── utils.py ├── requirements.txt ├── supernet_engine.py └── supernet_train.py ├── AutoFormerV2 ├── .figure │ ├── overview.jpg │ └── performance.jpg ├── README.md ├── configs │ ├── S3-B.yaml │ ├── S3-S.yaml │ └── S3-T.yaml ├── engine.py ├── evaluation.py ├── lib │ ├── config.py │ ├── datasets.py │ ├── samplers.py │ └── utils.py ├── model │ └── SSS.py └── requirements.txt ├── CDARTS ├── CDARTS │ ├── _init_paths.py │ ├── cells │ │ ├── cifar_genotype.json │ │ ├── dartsv1_genotype.json │ │ ├── dartsv2_genotype.json │ │ ├── imagenet_genotype.json │ │ ├── pcdarts_cifar_genotype.json │ │ ├── pcdarts_imagenet_genotype.json │ │ └── pdarts_genotype.json │ ├── retrain.py │ ├── search.py │ └── test.py ├── CDARTS_detection │ ├── README.md │ ├── configs │ │ └── CyDAS_retinanet_1x.py │ ├── mmcv │ │ ├── __init__.py │ │ ├── _ext.cpython-36m-x86_64-linux-gnu.so │ │ ├── arraymisc │ │ │ ├── __init__.py │ │ │ └── quantization.py │ │ ├── cnn │ │ │ ├── __init__.py │ │ │ ├── alexnet.py │ │ │ ├── resnet.py │ │ │ ├── vgg.py │ │ │ └── weight_init.py │ │ ├── fileio │ │ │ ├── __init__.py │ │ │ ├── handlers │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── json_handler.py │ │ │ │ ├── pickle_handler.py │ │ │ │ └── yaml_handler.py │ │ │ ├── io.py │ │ │ └── parse.py │ │ ├── image │ │ │ ├── __init__.py │ │ │ ├── io.py │ │ │ └── transforms │ │ │ │ ├── __init__.py │ │ │ │ ├── colorspace.py │ │ │ │ ├── geometry.py │ │ │ │ ├── normalize.py │ │ │ │ └── resize.py │ │ ├── opencv_info.py │ │ ├── parallel │ │ │ ├── __init__.py │ │ │ ├── _functions.py │ │ │ ├── collate.py │ │ │ ├── data_container.py │ │ │ ├── data_parallel.py │ │ │ ├── distributed.py │ │ │ └── scatter_gather.py │ │ ├── runner │ │ │ ├── __init__.py │ │ │ ├── checkpoint.py │ │ │ ├── dist_utils.py │ │ │ ├── hooks │ │ │ │ ├── __init__.py │ │ │ │ ├── checkpoint.py │ │ │ │ ├── closure.py │ │ │ │ ├── hook.py │ │ │ │ ├── iter_timer.py │ │ │ │ ├── logger │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── base.py │ │ │ │ │ ├── pavi.py │ │ │ │ │ ├── tensorboard.py │ │ │ │ │ └── text.py │ │ │ │ ├── lr_updater.py │ │ │ │ ├── memory.py │ │ │ │ ├── optimizer.py │ │ │ │ └── sampler_seed.py │ │ │ ├── log_buffer.py │ │ │ ├── parallel_test.py │ │ │ ├── priority.py │ │ │ ├── runner.py │ │ │ └── utils.py │ │ ├── utils │ │ │ ├── __init__.py │ │ │ ├── config.py │ │ │ ├── misc.py │ │ │ ├── path.py │ │ │ ├── progressbar.py │ │ │ └── timer.py │ │ ├── version.py │ │ ├── video │ │ │ ├── __init__.py │ │ │ ├── io.py │ │ │ ├── optflow.py │ │ │ ├── optflow_warp │ │ │ │ ├── __init__.py │ │ │ │ ├── flow_warp.cpp │ │ │ │ ├── flow_warp.hpp │ │ │ │ ├── flow_warp_module.cpp │ │ │ │ └── flow_warp_module.pyx │ │ │ └── processing.py │ │ └── visualization │ │ │ ├── __init__.py │ │ │ ├── color.py │ │ │ ├── image.py │ │ │ └── optflow.py │ ├── mmdet.egg-info │ │ ├── PKG-INFO │ │ ├── SOURCES.txt │ │ ├── dependency_links.txt │ │ ├── not-zip-safe │ │ ├── requires.txt │ │ └── top_level.txt │ ├── mmdet │ │ ├── __init__.py │ │ ├── apis │ │ │ ├── __init__.py │ │ │ ├── env.py │ │ │ ├── inference.py │ │ │ └── train.py │ │ ├── core │ │ │ ├── __init__.py │ │ │ ├── anchor │ │ │ │ ├── __init__.py │ │ │ │ ├── anchor_generator.py │ │ │ │ ├── anchor_target.py │ │ │ │ └── guided_anchor_target.py │ │ │ ├── bbox │ │ │ │ ├── __init__.py │ │ │ │ ├── assign_sampling.py │ │ │ │ ├── assigners │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── approx_max_iou_assigner.py │ │ │ │ │ ├── assign_result.py │ │ │ │ │ ├── base_assigner.py │ │ │ │ │ └── max_iou_assigner.py │ │ │ │ ├── bbox_target.py │ │ │ │ ├── geometry.py │ │ │ │ ├── samplers │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── base_sampler.py │ │ │ │ │ ├── combined_sampler.py │ │ │ │ │ ├── instance_balanced_pos_sampler.py │ │ │ │ │ ├── iou_balanced_neg_sampler.py │ │ │ │ │ ├── ohem_sampler.py │ │ │ │ │ ├── pseudo_sampler.py │ │ │ │ │ ├── random_sampler.py │ │ │ │ │ └── sampling_result.py │ │ │ │ └── transforms.py │ │ │ ├── evaluation │ │ │ │ ├── __init__.py │ │ │ │ ├── bbox_overlaps.py │ │ │ │ ├── class_names.py │ │ │ │ ├── coco_utils.py │ │ │ │ ├── eval_hooks.py │ │ │ │ ├── mean_ap.py │ │ │ │ └── recall.py │ │ │ ├── fp16 │ │ │ │ ├── __init__.py │ │ │ │ ├── decorators.py │ │ │ │ ├── hooks.py │ │ │ │ └── utils.py │ │ │ ├── mask │ │ │ │ ├── __init__.py │ │ │ │ ├── mask_target.py │ │ │ │ └── utils.py │ │ │ ├── post_processing │ │ │ │ ├── __init__.py │ │ │ │ ├── bbox_nms.py │ │ │ │ └── merge_augs.py │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── dist_utils.py │ │ │ │ └── misc.py │ │ ├── datasets │ │ │ ├── __init__.py │ │ │ ├── builder.py │ │ │ ├── cityscapes.py │ │ │ ├── coco.py │ │ │ ├── custom.py │ │ │ ├── dataset_wrappers.py │ │ │ ├── loader │ │ │ │ ├── __init__.py │ │ │ │ ├── build_loader.py │ │ │ │ └── sampler.py │ │ │ ├── pipelines │ │ │ │ ├── __init__.py │ │ │ │ ├── compose.py │ │ │ │ ├── formating.py │ │ │ │ ├── loading.py │ │ │ │ ├── test_aug.py │ │ │ │ └── transforms.py │ │ │ ├── registry.py │ │ │ ├── transforms.py │ │ │ ├── utils.py │ │ │ ├── voc.py │ │ │ ├── wider_face.py │ │ │ └── xml_style.py │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── anchor_heads │ │ │ │ ├── __init__.py │ │ │ │ ├── anchor_head.py │ │ │ │ ├── fcos_head.py │ │ │ │ ├── ga_retina_head.py │ │ │ │ ├── ga_rpn_head.py │ │ │ │ ├── guided_anchor_head.py │ │ │ │ ├── retina_head.py │ │ │ │ ├── rpn_head.py │ │ │ │ └── ssd_head.py │ │ │ ├── backbones │ │ │ │ ├── __init__.py │ │ │ │ ├── builder.py │ │ │ │ ├── detnas.py │ │ │ │ ├── dropblock.py │ │ │ │ ├── efficientnet.py │ │ │ │ ├── efficientnet_builder.py │ │ │ │ ├── fbnet.py │ │ │ │ ├── fbnet_arch.py │ │ │ │ ├── fbnet_blocks.py │ │ │ │ ├── feature_hooks.py │ │ │ │ ├── hrnet.py │ │ │ │ ├── mnasnet.py │ │ │ │ ├── mobilenetv2.py │ │ │ │ ├── mobilenetv3.py │ │ │ │ ├── resnet.py │ │ │ │ ├── resnext.py │ │ │ │ ├── ssd_vgg.py │ │ │ │ └── utils.py │ │ │ ├── bbox_heads │ │ │ │ ├── __init__.py │ │ │ │ ├── auto_head │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── build_head.py │ │ │ │ │ ├── mbblock_head_search.py │ │ │ │ │ └── mbblock_ops.py │ │ │ │ ├── bbox_head.py │ │ │ │ ├── convfc_bbox_head.py │ │ │ │ └── double_bbox_head.py │ │ │ ├── builder.py │ │ │ ├── detectors │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── cascade_rcnn.py │ │ │ │ ├── double_head_rcnn.py │ │ │ │ ├── fast_rcnn.py │ │ │ │ ├── faster_rcnn.py │ │ │ │ ├── fcos.py │ │ │ │ ├── grid_rcnn.py │ │ │ │ ├── htc.py │ │ │ │ ├── mask_rcnn.py │ │ │ │ ├── mask_scoring_rcnn.py │ │ │ │ ├── retinanet.py │ │ │ │ ├── rpn.py │ │ │ │ ├── single_stage.py │ │ │ │ ├── test_mixins.py │ │ │ │ └── two_stage.py │ │ │ ├── losses │ │ │ │ ├── __init__.py │ │ │ │ ├── accuracy.py │ │ │ │ ├── balanced_l1_loss.py │ │ │ │ ├── cross_entropy_loss.py │ │ │ │ ├── focal_loss.py │ │ │ │ ├── ghm_loss.py │ │ │ │ ├── iou_loss.py │ │ │ │ ├── mse_loss.py │ │ │ │ ├── smooth_l1_loss.py │ │ │ │ └── utils.py │ │ │ ├── mask_heads │ │ │ │ ├── __init__.py │ │ │ │ ├── fcn_mask_head.py │ │ │ │ ├── fused_semantic_head.py │ │ │ │ ├── grid_head.py │ │ │ │ ├── htc_mask_head.py │ │ │ │ └── maskiou_head.py │ │ │ ├── necks │ │ │ │ ├── __init__.py │ │ │ │ ├── auto_neck │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── build_neck.py │ │ │ │ │ ├── hit_neck_search.py │ │ │ │ │ └── hit_ops.py │ │ │ │ ├── bfp.py │ │ │ │ ├── fpn.py │ │ │ │ ├── fpn_panet.py │ │ │ │ ├── hrfpn.py │ │ │ │ ├── nas_fpn.py │ │ │ │ └── search_pafpn.py │ │ │ ├── plugins │ │ │ │ ├── __init__.py │ │ │ │ ├── generalized_attention.py │ │ │ │ └── non_local.py │ │ │ ├── registry.py │ │ │ ├── roi_extractors │ │ │ │ ├── __init__.py │ │ │ │ └── single_level.py │ │ │ ├── shared_heads │ │ │ │ ├── __init__.py │ │ │ │ └── res_layer.py │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── conv_module.py │ │ │ │ ├── conv_ws.py │ │ │ │ ├── norm.py │ │ │ │ ├── quant_conv.py │ │ │ │ ├── scale.py │ │ │ │ └── weight_init.py │ │ ├── ops │ │ │ ├── __init__.py │ │ │ ├── dcn │ │ │ │ ├── __init__.py │ │ │ │ ├── functions │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── deform_conv.py │ │ │ │ │ └── deform_pool.py │ │ │ │ ├── modules │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── deform_conv.py │ │ │ │ │ └── deform_pool.py │ │ │ │ ├── setup.py │ │ │ │ └── src │ │ │ │ │ ├── deform_conv_cuda.cpp │ │ │ │ │ ├── deform_conv_cuda_kernel.cu │ │ │ │ │ ├── deform_pool_cuda.cpp │ │ │ │ │ └── deform_pool_cuda_kernel.cu │ │ │ ├── gcb │ │ │ │ ├── __init__.py │ │ │ │ └── context_block.py │ │ │ ├── masked_conv │ │ │ │ ├── __init__.py │ │ │ │ ├── functions │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── masked_conv.py │ │ │ │ ├── modules │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── masked_conv.py │ │ │ │ ├── setup.py │ │ │ │ └── src │ │ │ │ │ ├── masked_conv2d_cuda.cpp │ │ │ │ │ └── masked_conv2d_kernel.cu │ │ │ ├── nms │ │ │ │ ├── __init__.py │ │ │ │ ├── nms_wrapper.py │ │ │ │ ├── setup.py │ │ │ │ └── src │ │ │ │ │ ├── nms_cpu.cpp │ │ │ │ │ ├── nms_cuda.cpp │ │ │ │ │ ├── nms_kernel.cu │ │ │ │ │ ├── soft_nms_cpu.cpp │ │ │ │ │ └── soft_nms_cpu.pyx │ │ │ ├── roi_align │ │ │ │ ├── __init__.py │ │ │ │ ├── functions │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── roi_align.py │ │ │ │ ├── gradcheck.py │ │ │ │ ├── modules │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── roi_align.py │ │ │ │ ├── roi_align.py │ │ │ │ ├── setup.py │ │ │ │ └── src │ │ │ │ │ ├── roi_align_cuda.cpp │ │ │ │ │ └── roi_align_kernel.cu │ │ │ ├── roi_pool │ │ │ │ ├── __init__.py │ │ │ │ ├── functions │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── roi_pool.py │ │ │ │ ├── gradcheck.py │ │ │ │ ├── modules │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── roi_pool.py │ │ │ │ ├── setup.py │ │ │ │ └── src │ │ │ │ │ ├── roi_pool_cuda.cpp │ │ │ │ │ └── roi_pool_kernel.cu │ │ │ └── sigmoid_focal_loss │ │ │ │ ├── __init__.py │ │ │ │ ├── functions │ │ │ │ ├── __init__.py │ │ │ │ └── sigmoid_focal_loss.py │ │ │ │ ├── modules │ │ │ │ ├── __init__.py │ │ │ │ └── sigmoid_focal_loss.py │ │ │ │ ├── setup.py │ │ │ │ └── src │ │ │ │ ├── sigmoid_focal_loss.cpp │ │ │ │ └── sigmoid_focal_loss_cuda.cu │ │ ├── utils │ │ │ ├── __init__.py │ │ │ ├── collect_env.py │ │ │ ├── contextmanagers.py │ │ │ ├── flops_counter.py │ │ │ ├── logger.py │ │ │ ├── profiling.py │ │ │ ├── registry.py │ │ │ └── util_mixins.py │ │ └── version.py │ ├── setup.py │ ├── test.py │ ├── tools │ │ ├── analyze_logs.py │ │ ├── coco_eval.py │ │ ├── convert_datasets │ │ │ └── pascal_voc.py │ │ ├── detectron2pytorch.py │ │ ├── get_flops.py │ │ ├── publish_model.py │ │ ├── test.py │ │ ├── upgrade_model_version.py │ │ └── voc_eval.py │ └── train.py ├── CDARTS_segmentation │ ├── LICENSE │ ├── README.md │ ├── configs │ │ ├── ade │ │ │ └── cydas.yaml │ │ └── cityscapes │ │ │ └── cydas.yaml │ ├── dataloaders │ │ ├── __init__.py │ │ ├── custom_transforms.py │ │ ├── dataloader_utils.py │ │ ├── datasets │ │ │ ├── __init__.py │ │ │ ├── cityscapes.py │ │ │ ├── coco.py │ │ │ ├── combine_dbs.py │ │ │ ├── kd.py │ │ │ ├── pascal.py │ │ │ └── sbd.py │ │ ├── segdatasets │ │ │ ├── __init__.py │ │ │ ├── base_dataset.py │ │ │ ├── cityscapes.py │ │ │ ├── cityscapes_panoptic.py │ │ │ ├── coco_panoptic.py │ │ │ └── utils.py │ │ └── transforms │ │ │ ├── __init__.py │ │ │ ├── build.py │ │ │ ├── pre_augmentation_transforms.py │ │ │ ├── target_transforms.py │ │ │ └── transforms.py │ ├── segmentation │ │ ├── __init__.py │ │ ├── config │ │ │ ├── __init__.py │ │ │ ├── default.py │ │ │ └── hrnet_config.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ ├── build.py │ │ │ ├── datasets │ │ │ │ ├── __init__.py │ │ │ │ ├── base_dataset.py │ │ │ │ ├── cityscapes.py │ │ │ │ ├── cityscapes_panoptic.py │ │ │ │ ├── coco_panoptic.py │ │ │ │ └── utils.py │ │ │ ├── samplers │ │ │ │ ├── __init__.py │ │ │ │ └── distributed_sampler.py │ │ │ └── transforms │ │ │ │ ├── __init__.py │ │ │ │ ├── build.py │ │ │ │ ├── pre_augmentation_transforms.py │ │ │ │ ├── target_transforms.py │ │ │ │ └── transforms.py │ │ ├── evaluation │ │ │ ├── __init__.py │ │ │ ├── coco_instance.py │ │ │ ├── coco_panoptic.py │ │ │ ├── instance.py │ │ │ ├── panoptic.py │ │ │ └── semantic.py │ │ ├── model │ │ │ ├── __init__.py │ │ │ ├── backbone │ │ │ │ ├── __init__.py │ │ │ │ ├── hrnet.py │ │ │ │ ├── mnasnet.py │ │ │ │ ├── mobilenet.py │ │ │ │ ├── resnet.py │ │ │ │ └── xception.py │ │ │ ├── build.py │ │ │ ├── decoder │ │ │ │ ├── __init__.py │ │ │ │ ├── aspp.py │ │ │ │ ├── conv_module.py │ │ │ │ ├── deeplabv3.py │ │ │ │ ├── deeplabv3plus.py │ │ │ │ └── panoptic_deeplab.py │ │ │ ├── loss │ │ │ │ ├── __init__.py │ │ │ │ └── criterion.py │ │ │ ├── meta_arch │ │ │ │ ├── __init__.py │ │ │ │ ├── base.py │ │ │ │ ├── deeplabv3.py │ │ │ │ ├── deeplabv3plus.py │ │ │ │ └── panoptic_deeplab.py │ │ │ └── post_processing │ │ │ │ ├── __init__.py │ │ │ │ ├── evaluation_format.py │ │ │ │ ├── instance_post_processing.py │ │ │ │ └── semantic_post_processing.py │ │ ├── solver │ │ │ ├── __init__.py │ │ │ ├── build.py │ │ │ ├── lr_scheduler.py │ │ │ └── utils.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── comm.py │ │ │ ├── debug.py │ │ │ ├── env.py │ │ │ ├── flow_vis.py │ │ │ ├── logger.py │ │ │ ├── save_annotation.py │ │ │ ├── test_utils.py │ │ │ └── utils.py │ ├── tools │ │ ├── __init__.py │ │ ├── datasets │ │ │ ├── BaseDataset.py │ │ │ ├── __init__.py │ │ │ ├── bdd │ │ │ │ ├── __init__.py │ │ │ │ └── bdd.py │ │ │ ├── camvid │ │ │ │ ├── __init__.py │ │ │ │ └── camvid.py │ │ │ ├── cityscapes │ │ │ │ ├── __init__.py │ │ │ │ ├── cityscapes.py │ │ │ │ ├── cityscapes_test.txt │ │ │ │ ├── cityscapes_train_fine.txt │ │ │ │ └── cityscapes_val_fine.txt │ │ │ └── coco │ │ │ │ ├── __init__.py │ │ │ │ └── coco.py │ │ ├── engine │ │ │ ├── __init__.py │ │ │ ├── evaluator.py │ │ │ ├── logger.py │ │ │ └── tester.py │ │ ├── seg_opr │ │ │ ├── __init__.py │ │ │ ├── loss_opr.py │ │ │ └── metric.py │ │ ├── utils │ │ │ ├── __init__.py │ │ │ ├── cal_model.py │ │ │ ├── darts_utils.py │ │ │ ├── dist_utils.py │ │ │ ├── genotypes.py │ │ │ ├── img_utils.py │ │ │ ├── init_func.py │ │ │ ├── lr_scheduler.py │ │ │ ├── metrics.py │ │ │ ├── pyt_utils.py │ │ │ └── visualize.py │ │ └── vis │ │ │ ├── panoptic_coco_categories.json │ │ │ ├── vis_cityscapes.py │ │ │ └── vis_coco.py │ └── train │ │ ├── _init_paths.py │ │ ├── att_sa.py │ │ ├── builder.py │ │ ├── cal_model.py │ │ ├── config_test.py │ │ ├── config_train.py │ │ ├── configs │ │ ├── ADE20K │ │ │ ├── 512.yaml │ │ │ └── base.yaml │ │ └── Cityscapes-PanopticSegmentation │ │ │ ├── Base-PanopticDeepLab-OS16.yaml │ │ │ ├── base.yaml │ │ │ ├── panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024.yaml │ │ │ └── panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024_dsconv.yaml │ │ ├── cydas.py │ │ ├── dataloader.py │ │ ├── eval.py │ │ ├── genotypes.py │ │ ├── latency_lookup_table.npy │ │ ├── launch.py │ │ ├── layers.py │ │ ├── loss.py │ │ ├── operations.py │ │ ├── seg_metrics.py │ │ ├── seg_oprs.py │ │ ├── slimmable_ops.py │ │ ├── test.py │ │ ├── test_seg.py │ │ ├── train_ade20k_cydas.py │ │ ├── train_cydas.py │ │ └── vis_arch.py ├── LICENSE ├── README.md ├── SETUP.md ├── benchmark201 │ ├── README.md │ ├── configs │ │ └── config.py │ ├── core │ │ ├── augment_function.py │ │ ├── pretrain_function.py │ │ └── search_function.py │ ├── datasets │ │ ├── cifar.py │ │ ├── data_utils.py │ │ └── imagenet.py │ ├── models │ │ ├── augment_cells.py │ │ ├── aux_head.py │ │ ├── cdarts_controller.py │ │ ├── loss.py │ │ ├── model_augment.py │ │ ├── model_test.py │ │ ├── ops.py │ │ └── search_cells.py │ ├── search.py │ ├── search │ │ ├── cifar10-search │ │ │ ├── cifar10-search.log │ │ │ └── tb │ │ │ │ └── readme.md │ │ └── imagenet-search │ │ │ ├── imagenet-search.log │ │ │ └── tb │ │ │ └── readme.md │ └── utils │ │ ├── genotypes.py │ │ ├── get_info.py │ │ ├── utils.py │ │ └── visualize.py ├── demo │ ├── NATS_bench.png │ ├── ade.png │ ├── cell.png │ ├── cell_cifar.png │ ├── cell_imagenet.png │ ├── chain.png │ ├── chain_arch.png │ ├── city.png │ ├── coco.png │ ├── framework1.png │ └── framework2.png ├── experiments │ ├── retrain │ │ ├── cifar10-retrain │ │ │ ├── cifar10-retrain.log │ │ │ └── tb │ │ │ │ └── readme.md │ │ └── imagenet-retrain │ │ │ ├── imagenet-retrain.log │ │ │ └── tb │ │ │ └── readme.md │ └── search │ │ ├── cifar10-search │ │ ├── cifar10-search.log │ │ └── tb │ │ │ └── readme.md │ │ └── imagenet-search │ │ ├── imagenet-search.log │ │ └── tb │ │ └── readme.md ├── lib │ ├── config.py │ ├── core │ │ ├── augment_function.py │ │ ├── pretrain_function.py │ │ └── search_function.py │ ├── datasets │ │ ├── cifar.py │ │ ├── data_utils.py │ │ └── imagenet.py │ ├── models │ │ ├── augment_cells.py │ │ ├── aux_head.py │ │ ├── cdarts_controller.py │ │ ├── loss.py │ │ ├── model_augment.py │ │ ├── model_test.py │ │ ├── ops.py │ │ └── search_cells.py │ └── utils │ │ ├── count_flops.py │ │ ├── genotypes.py │ │ ├── utils.py │ │ └── visualize.py └── requirements ├── CODE_OF_CONDUCT.md ├── Cream ├── README.md ├── data │ ├── subclass_list.txt │ └── subimages_list.txt ├── demo │ ├── intro.jpg │ ├── results_100.jpg │ └── results_600.jpg ├── experiments │ ├── configs │ │ ├── retrain │ │ │ ├── 114.yaml │ │ │ ├── 14.yaml │ │ │ ├── 23.yaml │ │ │ ├── 287.yaml │ │ │ ├── 43.yaml │ │ │ ├── 481.yaml │ │ │ ├── 604.yaml │ │ │ ├── 72.yaml │ │ │ └── retrain.yaml │ │ ├── test │ │ │ └── test.yaml │ │ └── train │ │ │ └── train.yaml │ └── workspace │ │ ├── retrain │ │ └── README.md │ │ ├── test │ │ └── README.md │ │ └── train │ │ └── README.md ├── lib │ ├── config.py │ ├── core │ │ ├── retrain.py │ │ ├── test.py │ │ └── train.py │ ├── models │ │ ├── MetaMatchingNetwork.py │ │ ├── PrioritizedBoard.py │ │ ├── blocks │ │ │ ├── __init__.py │ │ │ ├── inverted_residual_block.py │ │ │ └── residual_block.py │ │ ├── builders │ │ │ ├── build_childnet.py │ │ │ └── build_supernet.py │ │ └── structures │ │ │ ├── childnet.py │ │ │ └── supernet.py │ └── utils │ │ ├── builder_util.py │ │ ├── flops_table.py │ │ ├── op_by_layer_dict.py │ │ ├── search_structure_supernet.py │ │ └── util.py ├── requirements └── tools │ ├── _init_paths.py │ ├── generate_subImageNet.py │ ├── main.py │ ├── retrain.py │ ├── test.py │ └── train.py ├── EfficientViT ├── .gitignore ├── LICENSE ├── README.md ├── classification │ ├── .figures │ │ ├── efficientvit_main.gif │ │ ├── efficientvit_main_static.png │ │ └── modelACC_gpu.png │ ├── README.md │ ├── data │ │ ├── __init__.py │ │ ├── datasets.py │ │ ├── samplers.py │ │ └── threeaugment.py │ ├── engine.py │ ├── losses.py │ ├── main.py │ ├── model │ │ ├── __init__.py │ │ ├── build.py │ │ └── efficientvit.py │ ├── requirements.txt │ ├── speed_test.py │ └── utils.py └── downstream │ ├── README.md │ ├── configs │ ├── _base_ │ │ ├── datasets │ │ │ ├── cityscapes_detection.py │ │ │ ├── cityscapes_instance.py │ │ │ ├── coco_detection.py │ │ │ ├── coco_instance.py │ │ │ ├── coco_instance_semantic.py │ │ │ ├── deepfashion.py │ │ │ ├── lvis_v0.5_instance.py │ │ │ ├── lvis_v1_instance.py │ │ │ ├── voc0712.py │ │ │ └── wider_face.py │ │ ├── default_runtime.py │ │ ├── models │ │ │ ├── cascade_mask_rcnn_r50_fpn.py │ │ │ ├── cascade_mask_rcnn_swin_fpn.py │ │ │ ├── cascade_rcnn_r50_fpn.py │ │ │ ├── fast_rcnn_r50_fpn.py │ │ │ ├── faster_rcnn_r50_caffe_c4.py │ │ │ ├── faster_rcnn_r50_caffe_dc5.py │ │ │ ├── faster_rcnn_r50_fpn.py │ │ │ ├── mask_rcnn_efficientvit_fpn.py │ │ │ ├── mask_rcnn_r50_caffe_c4.py │ │ │ ├── mask_rcnn_r50_fpn.py │ │ │ ├── mask_rcnn_swin_fpn.py │ │ │ ├── mask_reppointsv2_swin_bifpn.py │ │ │ ├── reppointsv2_swin_bifpn.py │ │ │ ├── retinanet_efficientvit_fpn.py │ │ │ ├── retinanet_r50_fpn.py │ │ │ ├── rpn_r50_caffe_c4.py │ │ │ ├── rpn_r50_fpn.py │ │ │ └── ssd300.py │ │ └── schedules │ │ │ ├── schedule_1x.py │ │ │ ├── schedule_20e.py │ │ │ └── schedule_2x.py │ ├── mask_rcnn_efficientvit_m4_fpn_1x_coco.py │ └── retinanet_efficientvit_m4_fpn_1x_coco.py │ ├── dist_test.sh │ ├── dist_train.sh │ ├── efficientvit.py │ ├── efficientvit_fpn.py │ ├── mmcv_custom │ ├── __init__.py │ ├── checkpoint.py │ └── runner │ │ ├── __init__.py │ │ ├── checkpoint.py │ │ ├── epoch_based_runner.py │ │ └── optimizer.py │ ├── mmdet_custom │ └── apis │ │ └── train.py │ ├── test.py │ └── train.py ├── LICENSE ├── MiniViT ├── .figure │ └── framework.png ├── .gitignore ├── Mini-DeiT │ ├── LICENSE │ ├── README.md │ ├── datasets.py │ ├── engine.py │ ├── irpe.py │ ├── losses.py │ ├── main.py │ ├── mini_deit_models.py │ ├── mini_vision_transformer.py │ ├── models.py │ ├── requirements.txt │ ├── rpe_ops │ │ ├── README.md │ │ ├── rpe_index.cpp │ │ ├── rpe_index.py │ │ ├── rpe_index_cuda.cu │ │ └── setup.py │ ├── samplers.py │ └── utils.py ├── Mini-Swin │ ├── LICENSE │ ├── README.md │ ├── config.py │ ├── configs │ │ ├── swin_base_patch4_window12_384.yaml │ │ ├── swin_base_patch4_window7_224.yaml │ │ ├── swin_base_patch4_window7_224_minivit_sharenum2.yaml │ │ ├── swin_base_patch4_window7_224to384_minivit_sharenum2_adamw.yaml │ │ ├── swin_large_patch4_window12_384.yaml │ │ ├── swin_large_patch4_window7_224.yaml │ │ ├── swin_small_patch4_window7_224.yaml │ │ ├── swin_small_patch4_window7_224_minivit_sharenum2.yaml │ │ ├── swin_tiny_patch4_window7_224.yaml │ │ └── swin_tiny_patch4_window7_224_minivit_sharenum6.yaml │ ├── data │ │ ├── __init__.py │ │ ├── build.py │ │ ├── cached_image_folder.py │ │ ├── samplers.py │ │ └── zipreader.py │ ├── logger.py │ ├── lr_scheduler.py │ ├── main.py │ ├── models │ │ ├── __init__.py │ │ ├── build.py │ │ ├── swin_mlp.py │ │ ├── swin_transformer.py │ │ ├── swin_transformer_distill.py │ │ ├── swin_transformer_minivit.py │ │ └── swin_transformer_minivit_distill.py │ ├── my_meter.py │ ├── optimizer.py │ ├── requirements.txt │ └── utils.py └── README.md ├── README.md ├── SECURITY.md ├── TinyCLIP ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── docs │ ├── EVALUATION.md │ ├── PREPARATION.md │ └── PRETRAINING.md ├── figure │ ├── TinyCLIP.jpg │ └── fig1.jpg ├── inference.py ├── requirements-test.txt ├── requirements-training.txt ├── requirements.txt ├── script │ ├── auto_weight_inherit_100to75.sh │ ├── auto_weight_inherit_50to25.sh │ ├── auto_weight_inherit_75to50.sh │ ├── manual_weight_inherit_100to75.sh │ └── manual_weight_inherit_75to50.sh ├── setup.py └── src │ ├── data │ └── gather_cc.py │ ├── open_clip │ ├── __init__.py │ ├── bpe_simple_vocab_16e6.txt.gz │ ├── clip_soft_loss.py │ ├── constants.py │ ├── factory.py │ ├── imagenet_zeroshot_data.py │ ├── l0module.py │ ├── loss.py │ ├── model.py │ ├── model_configs │ │ ├── RN50.json │ │ ├── TinyCLIP-ResNet-19M-Text-19M.json │ │ ├── TinyCLIP-ResNet-30M-Text-29M.json │ │ ├── TinyCLIP-ViT-39M-16-Text-19M.json │ │ ├── TinyCLIP-ViT-40M-32-Text-19M.json │ │ ├── TinyCLIP-ViT-61M-32-Text-29M.json │ │ ├── TinyCLIP-ViT-8M-16-Text-3M.json │ │ ├── ViT-B-16.json │ │ └── ViT-B-32.json │ ├── openai.py │ ├── pretrained.py │ ├── resnet.py │ ├── timm_model.py │ ├── tokenizer.py │ ├── transform.py │ ├── utils.py │ ├── version.py │ └── weight_inherit.py │ └── training │ ├── .gitignore │ ├── __init__.py │ ├── data.py │ ├── distributed.py │ ├── logger.py │ ├── loss_scaler.py │ ├── main.py │ ├── main_for_test.py │ ├── my_meter.py │ ├── optimizer.py │ ├── params.py │ ├── precision.py │ ├── scheduler.py │ ├── train.py │ ├── viz.py │ └── zero_shot.py ├── TinyViT ├── .figure │ ├── cat.jpg │ ├── distill.png │ ├── framework.png │ └── performance.png ├── LICENSE ├── README.md ├── config.py ├── configs │ ├── 1k │ │ ├── tiny_vit_11m.yaml │ │ ├── tiny_vit_21m.yaml │ │ └── tiny_vit_5m.yaml │ ├── 22k_distill │ │ ├── tiny_vit_11m_22k_distill.yaml │ │ ├── tiny_vit_21m_22k_distill.yaml │ │ └── tiny_vit_5m_22k_distill.yaml │ ├── 22kto1k │ │ ├── tiny_vit_11m_22kto1k.yaml │ │ ├── tiny_vit_21m_22kto1k.yaml │ │ └── tiny_vit_5m_22kto1k.yaml │ ├── higher_resolution │ │ ├── tiny_vit_21m_224to384.yaml │ │ └── tiny_vit_21m_384to512.yaml │ └── teacher │ │ └── clip_vit_large_patch14_22k.yaml ├── data │ ├── __init__.py │ ├── augmentation │ │ ├── README.md │ │ ├── __init__.py │ │ ├── aug_random.py │ │ ├── aug_tv_transforms.py │ │ ├── auto_augment.py │ │ ├── config.py │ │ ├── constants.py │ │ ├── dataset.py │ │ ├── dataset_factory.py │ │ ├── dataset_wrapper.py │ │ ├── distributed_sampler.py │ │ ├── loader.py │ │ ├── manager.py │ │ ├── mixup.py │ │ ├── parsers │ │ │ ├── __init__.py │ │ │ ├── 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 │ ├── build.py │ ├── imagenet22k_dataset.py │ ├── imagenet_classnames.py │ └── sampler.py ├── docs │ ├── EVALUATION.md │ ├── PREPARATION.md │ ├── SAVE_TEACHER_LOGITS.md │ └── TRAINING.md ├── imagenet_1kto22k.txt ├── inference.py ├── logger.py ├── lr_scheduler.py ├── main.py ├── models │ ├── __init__.py │ ├── build.py │ ├── clip.py │ ├── remap_layer.py │ └── tiny_vit.py ├── my_meter.py ├── optimizer.py ├── requirements.txt ├── save_logits.py ├── tests │ └── test_models.py ├── tinyvit_utils.py └── utils.py └── iRPE ├── DETR-with-iRPE ├── .gitignore ├── LICENSE ├── README.md ├── datasets │ ├── __init__.py │ ├── coco.py │ ├── coco_eval.py │ ├── coco_panoptic.py │ ├── panoptic_eval.py │ └── transforms.py ├── engine.py ├── main.py ├── models │ ├── __init__.py │ ├── backbone.py │ ├── detr.py │ ├── matcher.py │ ├── position_encoding.py │ ├── rpe_attention │ │ ├── __init__.py │ │ ├── irpe.py │ │ ├── multi_head_attention.py │ │ └── rpe_attention_function.py │ ├── segmentation.py │ └── transformer.py ├── requirements.txt ├── rpe_ops │ ├── README.md │ ├── rpe_index.cpp │ ├── rpe_index.py │ ├── rpe_index_cuda.cu │ └── setup.py ├── run_with_submitit.py └── util │ ├── __init__.py │ ├── box_ops.py │ ├── misc.py │ └── plot_utils.py ├── DeiT-with-iRPE ├── .gitignore ├── LICENSE ├── README.md ├── datasets.py ├── engine.py ├── hubconf.py ├── irpe.py ├── losses.py ├── main.py ├── models.py ├── requirements.txt ├── rpe_models.py ├── rpe_ops │ ├── README.md │ ├── rpe_index.cpp │ ├── rpe_index.py │ ├── rpe_index_cuda.cu │ └── setup.py ├── rpe_vision_transformer.py ├── run_with_submitit.py ├── samplers.py ├── tox.ini └── utils.py ├── HOW_TO_EQUIP_iRPE.md ├── README.md └── iRPE.png /.gitignore: -------------------------------------------------------------------------------- 1 | checkpoint/ 2 | *.pyc 3 | /*.log 4 | *ptm 5 | .vscode 6 | *visualize_images*/ 7 | *_tsne_* 8 | *hard_triplet_* 9 | *_feature.pkl 10 | Visualize_Network_* 11 | hard_mining/ 12 | backup.py 13 | *pdf 14 | *.bak* 15 | *.sh -------------------------------------------------------------------------------- /AutoFormer/.figure/ofa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/AutoFormer/.figure/ofa.png -------------------------------------------------------------------------------- /AutoFormer/.figure/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/AutoFormer/.figure/overview.png -------------------------------------------------------------------------------- /AutoFormer/.figure/performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/AutoFormer/.figure/performance.png -------------------------------------------------------------------------------- /AutoFormer/experiments/subnet/AutoFormer-B.yaml: -------------------------------------------------------------------------------- 1 | SUPERNET: 2 | MLP_RATIO: 4.0 3 | NUM_HEADS: 10 4 | EMBED_DIM: 640 5 | DEPTH: 16 6 | SEARCH_SPACE: 7 | MLP_RATIO: 8 | - 3.0 9 | - 3.5 10 | - 4.0 11 | NUM_HEADS: 12 | - 8 13 | - 9 14 | - 10 15 | DEPTH: 16 | - 14 17 | - 15 18 | - 16 19 | EMBED_DIM: 20 | - 528 21 | - 576 22 | - 624 23 | RETRAIN: 24 | MLP_RATIO: 25 | - 3.5 26 | - 3.5 27 | - 4.0 28 | - 3.5 29 | - 4.0 30 | - 3.5 31 | - 3.5 32 | - 3.0 33 | - 4.0 34 | - 4.0 35 | - 3.0 36 | - 4.0 37 | - 3.0 38 | - 3.5 39 | NUM_HEADS: 40 | - 9 41 | - 9 42 | - 9 43 | - 9 44 | - 9 45 | - 10 46 | - 9 47 | - 9 48 | - 10 49 | - 9 50 | - 10 51 | - 9 52 | - 9 53 | - 10 54 | DEPTH: 14 55 | EMBED_DIM: 576 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /AutoFormer/experiments/subnet/AutoFormer-S.yaml: -------------------------------------------------------------------------------- 1 | SUPERNET: 2 | MLP_RATIO: 4.0 3 | NUM_HEADS: 7 4 | EMBED_DIM: 448 5 | DEPTH: 14 6 | SEARCH_SPACE: 7 | MLP_RATIO: 8 | - 3.0 9 | - 3.5 10 | - 4.0 11 | NUM_HEADS: 12 | - 5 13 | - 6 14 | - 7 15 | DEPTH: 16 | - 12 17 | - 13 18 | - 14 19 | EMBED_DIM: 20 | - 320 21 | - 384 22 | - 448 23 | RETRAIN: 24 | MLP_RATIO: 25 | - 3.0 26 | - 3.5 27 | - 3.0 28 | - 3.5 29 | - 4.0 30 | - 4.0 31 | - 4.0 32 | - 4.0 33 | - 4.0 34 | - 4.0 35 | - 4.0 36 | - 3.5 37 | - 4.0 38 | NUM_HEADS: 39 | - 6 40 | - 6 41 | - 5 42 | - 7 43 | - 5 44 | - 5 45 | - 5 46 | - 6 47 | - 6 48 | - 7 49 | - 7 50 | - 6 51 | - 7 52 | DEPTH: 13 53 | EMBED_DIM: 384 54 | 55 | -------------------------------------------------------------------------------- /AutoFormer/experiments/subnet/AutoFormer-T.yaml: -------------------------------------------------------------------------------- 1 | SUPERNET: 2 | MLP_RATIO: 4.0 3 | NUM_HEADS: 4 4 | EMBED_DIM: 256 5 | DEPTH: 14 6 | SEARCH_SPACE: 7 | MLP_RATIO: 8 | - 3.5 9 | - 4 10 | NUM_HEADS: 11 | - 3 12 | - 4 13 | DEPTH: 14 | - 12 15 | - 13 16 | - 14 17 | EMBED_DIM: 18 | - 192 19 | - 216 20 | - 240 21 | RETRAIN: 22 | MLP_RATIO: 23 | - 3.5 24 | - 3.5 25 | - 3.0 26 | - 3.5 27 | - 3.0 28 | - 3.0 29 | - 4.0 30 | - 4.0 31 | - 3.5 32 | - 4.0 33 | - 3.5 34 | - 4.0 35 | - 3.5 36 | NUM_HEADS: 37 | - 3 38 | - 3 39 | - 3 40 | - 3 41 | - 3 42 | - 3 43 | - 3 44 | - 3 45 | - 3 46 | - 3 47 | - 4 48 | - 3 49 | - 3 50 | DEPTH: 13 51 | EMBED_DIM: 192 -------------------------------------------------------------------------------- /AutoFormer/experiments/supernet/supernet-B.yaml: -------------------------------------------------------------------------------- 1 | SUPERNET: 2 | MLP_RATIO: 4.0 3 | NUM_HEADS: 10 4 | EMBED_DIM: 640 5 | DEPTH: 16 6 | SEARCH_SPACE: 7 | MLP_RATIO: 8 | - 3.0 9 | - 3.5 10 | - 4.0 11 | NUM_HEADS: 12 | - 9 13 | - 10 14 | DEPTH: 15 | - 14 16 | - 15 17 | - 16 18 | EMBED_DIM: 19 | - 528 20 | - 576 21 | - 624 22 | -------------------------------------------------------------------------------- /AutoFormer/experiments/supernet/supernet-S.yaml: -------------------------------------------------------------------------------- 1 | SUPERNET: 2 | MLP_RATIO: 4.0 3 | NUM_HEADS: 7 4 | EMBED_DIM: 448 5 | DEPTH: 14 6 | SEARCH_SPACE: 7 | MLP_RATIO: 8 | - 3.0 9 | - 3.5 10 | - 4.0 11 | NUM_HEADS: 12 | - 5 13 | - 6 14 | - 7 15 | DEPTH: 16 | - 12 17 | - 13 18 | - 14 19 | EMBED_DIM: 20 | - 320 21 | - 384 22 | - 448 23 | -------------------------------------------------------------------------------- /AutoFormer/experiments/supernet/supernet-T.yaml: -------------------------------------------------------------------------------- 1 | SUPERNET: 2 | MLP_RATIO: 4.0 3 | NUM_HEADS: 4 4 | EMBED_DIM: 256 5 | DEPTH: 14 6 | SEARCH_SPACE: 7 | MLP_RATIO: 8 | - 3.5 9 | - 4 10 | NUM_HEADS: 11 | - 3 12 | - 4 13 | DEPTH: 14 | - 12 15 | - 13 16 | - 14 17 | EMBED_DIM: 18 | - 192 19 | - 216 20 | - 240 21 | -------------------------------------------------------------------------------- /AutoFormer/lib/config.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | import yaml 3 | 4 | cfg = edict() 5 | 6 | 7 | def _edict2dict(dest_dict, src_edict): 8 | if isinstance(dest_dict, dict) and isinstance(src_edict, dict): 9 | for k, v in src_edict.items(): 10 | if not isinstance(v, edict): 11 | dest_dict[k] = v 12 | else: 13 | dest_dict[k] = {} 14 | _edict2dict(dest_dict[k], v) 15 | else: 16 | return 17 | 18 | def gen_config(config_file): 19 | cfg_dict = {} 20 | _edict2dict(cfg_dict, cfg) 21 | with open(config_file, 'w') as f: 22 | yaml.dump(cfg_dict, f, default_flow_style=False) 23 | 24 | 25 | def _update_config(base_cfg, exp_cfg): 26 | if isinstance(base_cfg, edict) and isinstance(exp_cfg, edict): 27 | for k, v in exp_cfg.items(): 28 | base_cfg[k] = v 29 | else: 30 | return 31 | 32 | 33 | def update_config_from_file(filename): 34 | exp_config = None 35 | with open(filename) as f: 36 | exp_config = edict(yaml.safe_load(f)) 37 | _update_config(cfg, exp_config) 38 | 39 | 40 | -------------------------------------------------------------------------------- /AutoFormer/model/module/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/AutoFormer/model/module/__init__.py -------------------------------------------------------------------------------- /AutoFormer/requirements.txt: -------------------------------------------------------------------------------- 1 | torch==1.7.0 2 | timm==0.3.2 3 | scikit-image 4 | ptflops 5 | easydict 6 | PyYAML 7 | pillow 8 | torchvision==0.2.1 9 | opencv-python 10 | -------------------------------------------------------------------------------- /AutoFormerV2/.figure/overview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/AutoFormerV2/.figure/overview.jpg -------------------------------------------------------------------------------- /AutoFormerV2/.figure/performance.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/AutoFormerV2/.figure/performance.jpg -------------------------------------------------------------------------------- /AutoFormerV2/configs/S3-B.yaml: -------------------------------------------------------------------------------- 1 | MLP_RATIO: [[4.0, 4.0], [4.0, 4.0], [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], [4.0, 4.0]] 2 | NUM_HEADS: [[3,3], [6,6], [12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12], [24,24]] 3 | EMBED_DIM: [96,192,384,768] 4 | DEPTHS: [ 2, 2, 30, 2 ] 5 | WINDOW_SIZE: [[7,7], [7,7], [14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14], [7,7]] -------------------------------------------------------------------------------- /AutoFormerV2/configs/S3-S.yaml: -------------------------------------------------------------------------------- 1 | MLP_RATIO: [[4.0, 4.0], [4.0, 4.0], [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0,4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], [4.0, 4.0]] 2 | NUM_HEADS: [[3,3], [6,6], [12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12], [24,24]] 3 | EMBED_DIM: [96,192,384,768] 4 | DEPTHS: [ 2, 2, 18, 2 ] 5 | WINDOW_SIZE: [[14,14], [14,14], [14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14], [14,14]] -------------------------------------------------------------------------------- /AutoFormerV2/configs/S3-T.yaml: -------------------------------------------------------------------------------- 1 | MLP_RATIO: [[4.0, 4.0], [4.0, 4.0], [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0], [4.0, 4.0]] 2 | NUM_HEADS: [[3,3], [6,6], [12,12,12,12,12,12,12,12], [24,24]] 3 | EMBED_DIM: [96,192,384,768] 4 | DEPTHS: [ 2, 2, 6, 2 ] 5 | WINDOW_SIZE: [[7,7], [7,7], [14,14,14,14,14,14,14,14], [7,7]] 6 | -------------------------------------------------------------------------------- /AutoFormerV2/lib/config.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | import yaml 3 | 4 | cfg = edict() 5 | 6 | 7 | def _edict2dict(dest_dict, src_edict): 8 | if isinstance(dest_dict, dict) and isinstance(src_edict, dict): 9 | for k, v in src_edict.items(): 10 | if not isinstance(v, edict): 11 | dest_dict[k] = v 12 | else: 13 | dest_dict[k] = {} 14 | _edict2dict(dest_dict[k], v) 15 | else: 16 | return 17 | 18 | def gen_config(config_file): 19 | cfg_dict = {} 20 | _edict2dict(cfg_dict, cfg) 21 | with open(config_file, 'w') as f: 22 | yaml.dump(cfg_dict, f, default_flow_style=False) 23 | 24 | 25 | def _update_config(base_cfg, exp_cfg): 26 | if isinstance(base_cfg, edict) and isinstance(exp_cfg, edict): 27 | for k, v in exp_cfg.items(): 28 | base_cfg[k] = v 29 | else: 30 | return 31 | 32 | 33 | def update_config_from_file(filename): 34 | exp_config = None 35 | with open(filename) as f: 36 | exp_config = edict(yaml.safe_load(f)) 37 | _update_config(cfg, exp_config) 38 | 39 | 40 | -------------------------------------------------------------------------------- /AutoFormerV2/requirements.txt: -------------------------------------------------------------------------------- 1 | torch==1.7.1 2 | timm==0.3.2 3 | scikit-image 4 | ptflops 5 | easydict 6 | PyYAML 7 | pillow 8 | torchvision==0.8.2 9 | opencv-python 10 | yacs==0.1.8 -------------------------------------------------------------------------------- /CDARTS/CDARTS/_init_paths.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from __future__ import division 3 | from __future__ import print_function 4 | 5 | import os.path as osp 6 | import sys 7 | 8 | 9 | def add_path(path): 10 | if path not in sys.path: 11 | sys.path.insert(0, path) 12 | 13 | 14 | this_dir = osp.dirname(__file__) 15 | lib_path = osp.join(this_dir, '..', 'lib') 16 | add_path(lib_path) 17 | 18 | lib_path = osp.join(this_dir, '..') 19 | add_path(lib_path) 20 | -------------------------------------------------------------------------------- /CDARTS/CDARTS/cells/cifar_genotype.json: -------------------------------------------------------------------------------- 1 | {"0": "Genotype(normal=[[('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 2)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('skip_connect', 0), ('skip_connect', 2)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('max_pool_3x3', 0)], [('dil_conv_5x5', 2), ('skip_connect', 0)], [('sep_conv_3x3', 0), ('sep_conv_5x5', 1)], [('sep_conv_3x3', 0), ('dil_conv_5x5', 2)]], reduce_concat=range(2, 6))", "1": "Genotype(normal=[[('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 2)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('skip_connect', 0), ('skip_connect', 2)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('max_pool_3x3', 0)], [('dil_conv_5x5', 2), ('skip_connect', 0)], [('sep_conv_3x3', 0), ('sep_conv_5x5', 1)], [('sep_conv_3x3', 0), ('dil_conv_5x5', 2)]], reduce_concat=range(2, 6))", "2": "Genotype(normal=[[('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 2)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('skip_connect', 0), ('skip_connect', 2)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('max_pool_3x3', 0)], [('dil_conv_5x5', 2), ('skip_connect', 0)], [('sep_conv_3x3', 0), ('sep_conv_5x5', 1)], [('sep_conv_3x3', 0), ('dil_conv_5x5', 2)]], reduce_concat=range(2, 6))"} -------------------------------------------------------------------------------- /CDARTS/CDARTS/cells/dartsv1_genotype.json: -------------------------------------------------------------------------------- 1 | {"0": "Genotype(normal=[[('sep_conv_3x3', 1), ('sep_conv_3x3', 0)], [('skip_connect', 0), ('sep_conv_3x3', 1)], [('skip_connect', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 0), ('skip_connect', 2)]], normal_concat=[2, 3, 4, 5], reduce=[[('max_pool_3x3', 0), ('max_pool_3x3', 1)], [('skip_connect', 2), ('max_pool_3x3', 0)], [('max_pool_3x3', 0), ('skip_connect', 2)], [('skip_connect', 2), ('avg_pool_3x3', 0)]], reduce_concat=[2, 3, 4, 5])", "1": "Genotype(normal=[[('sep_conv_3x3', 1), ('sep_conv_3x3', 0)], [('skip_connect', 0), ('sep_conv_3x3', 1)], [('skip_connect', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 0), ('skip_connect', 2)]], normal_concat=[2, 3, 4, 5], reduce=[[('max_pool_3x3', 0), ('max_pool_3x3', 1)], [('skip_connect', 2), ('max_pool_3x3', 0)], [('max_pool_3x3', 0), ('skip_connect', 2)], [('skip_connect', 2), ('avg_pool_3x3', 0)]], reduce_concat=[2, 3, 4, 5])", "2": "Genotype(normal=[[('sep_conv_3x3', 1), ('sep_conv_3x3', 0)], [('skip_connect', 0), ('sep_conv_3x3', 1)], [('skip_connect', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 0), ('skip_connect', 2)]], normal_concat=[2, 3, 4, 5], reduce=[[('max_pool_3x3', 0), ('max_pool_3x3', 1)], [('skip_connect', 2), ('max_pool_3x3', 0)], [('max_pool_3x3', 0), ('skip_connect', 2)], [('skip_connect', 2), ('avg_pool_3x3', 0)]], reduce_concat=[2, 3, 4, 5])"} -------------------------------------------------------------------------------- /CDARTS/CDARTS/cells/dartsv2_genotype.json: -------------------------------------------------------------------------------- 1 | {"0": "Genotype(normal=[[('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('skip_connect', 0)], [('skip_connect', 0), ('dil_conv_3x3', 2)]], normal_concat=[2, 3, 4, 5], reduce=[[('max_pool_3x3', 0), ('max_pool_3x3', 1)], [('skip_connect', 2), ('max_pool_3x3', 1)], [('max_pool_3x3', 0), ('skip_connect', 2)], [('skip_connect', 2), ('max_pool_3x3', 1)]], reduce_concat=[2, 3, 4, 5])", "1": "Genotype(normal=[[('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('skip_connect', 0)], [('skip_connect', 0), ('dil_conv_3x3', 2)]], normal_concat=[2, 3, 4, 5], reduce=[[('max_pool_3x3', 0), ('max_pool_3x3', 1)], [('skip_connect', 2), ('max_pool_3x3', 1)], [('max_pool_3x3', 0), ('skip_connect', 2)], [('skip_connect', 2), ('max_pool_3x3', 1)]], reduce_concat=[2, 3, 4, 5])", "2": "Genotype(normal=[[('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('skip_connect', 0)], [('skip_connect', 0), ('dil_conv_3x3', 2)]], normal_concat=[2, 3, 4, 5], reduce=[[('max_pool_3x3', 0), ('max_pool_3x3', 1)], [('skip_connect', 2), ('max_pool_3x3', 1)], [('max_pool_3x3', 0), ('skip_connect', 2)], [('skip_connect', 2), ('max_pool_3x3', 1)]], reduce_concat=[2, 3, 4, 5])"} -------------------------------------------------------------------------------- /CDARTS/CDARTS/cells/imagenet_genotype.json: -------------------------------------------------------------------------------- 1 | {"0": "Genotype(normal=[[('sep_conv_3x3', 1), ('sep_conv_3x3', 0)], [('sep_conv_3x3', 0), ('sep_conv_5x5', 2)], [('sep_conv_5x5', 2), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('avg_pool_3x3', 0)], [('max_pool_3x3', 1), ('dil_conv_5x5', 2)], [('sep_conv_5x5', 1), ('dil_conv_5x5', 2)], [('sep_conv_3x3', 3), ('dil_conv_3x3', 4)]], reduce_concat=range(2, 6))", "1": "Genotype(normal=[[('sep_conv_3x3', 1), ('sep_conv_3x3', 0)], [('sep_conv_3x3', 0), ('sep_conv_5x5', 2)], [('sep_conv_5x5', 2), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('avg_pool_3x3', 0)], [('max_pool_3x3', 1), ('dil_conv_5x5', 2)], [('sep_conv_5x5', 1), ('dil_conv_5x5', 2)], [('sep_conv_3x3', 3), ('dil_conv_3x3', 4)]], reduce_concat=range(2, 6))", "2": "Genotype(normal=[[('sep_conv_3x3', 1), ('sep_conv_3x3', 0)], [('sep_conv_3x3', 0), ('sep_conv_5x5', 2)], [('sep_conv_5x5', 2), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('avg_pool_3x3', 0)], [('max_pool_3x3', 1), ('dil_conv_5x5', 2)], [('sep_conv_5x5', 1), ('dil_conv_5x5', 2)], [('sep_conv_3x3', 3), ('dil_conv_3x3', 4)]], reduce_concat=range(2, 6))"} -------------------------------------------------------------------------------- /CDARTS/CDARTS/cells/pcdarts_cifar_genotype.json: -------------------------------------------------------------------------------- 1 | {"0": "Genotype(normal=[[('sep_conv_3x3', 1), ('skip_connect', 0)], [('sep_conv_3x3', 0), ('dil_conv_3x3', 1)], [('sep_conv_5x5', 0), ('sep_conv_3x3', 1)], [('avg_pool_3x3', 0), ('dil_conv_3x3', 1)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('max_pool_3x3', 0)], [('sep_conv_5x5', 1), ('sep_conv_5x5', 2)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 3)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 2)]], reduce_concat=range(2, 6))", "1": "Genotype(normal=[[('sep_conv_3x3', 1), ('skip_connect', 0)], [('sep_conv_3x3', 0), ('dil_conv_3x3', 1)], [('sep_conv_5x5', 0), ('sep_conv_3x3', 1)], [('avg_pool_3x3', 0), ('dil_conv_3x3', 1)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('max_pool_3x3', 0)], [('sep_conv_5x5', 1), ('sep_conv_5x5', 2)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 3)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 2)]], reduce_concat=range(2, 6))", "2": "Genotype(normal=[[('sep_conv_3x3', 1), ('skip_connect', 0)], [('sep_conv_3x3', 0), ('dil_conv_3x3', 1)], [('sep_conv_5x5', 0), ('sep_conv_3x3', 1)], [('avg_pool_3x3', 0), ('dil_conv_3x3', 1)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('max_pool_3x3', 0)], [('sep_conv_5x5', 1), ('sep_conv_5x5', 2)], [('sep_conv_3x3', 0), ('sep_conv_3x3', 3)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 2)]], reduce_concat=range(2, 6))"} -------------------------------------------------------------------------------- /CDARTS/CDARTS/cells/pcdarts_imagenet_genotype.json: -------------------------------------------------------------------------------- 1 | {"0": "Genotype(normal=[[('skip_connect', 1), ('sep_conv_3x3', 0)], [('sep_conv_3x3', 0), ('skip_connect', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 3)], [('sep_conv_3x3', 1), ('dil_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('sep_conv_3x3', 0), ('skip_connect', 1)], [('dil_conv_5x5', 2), ('max_pool_3x3', 1)], [('sep_conv_3x3', 2), ('sep_conv_3x3', 1)], [('sep_conv_5x5', 0), ('sep_conv_3x3', 3)]], reduce_concat=range(2, 6))", "1": "Genotype(normal=[[('skip_connect', 1), ('sep_conv_3x3', 0)], [('sep_conv_3x3', 0), ('skip_connect', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 3)], [('sep_conv_3x3', 1), ('dil_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('sep_conv_3x3', 0), ('skip_connect', 1)], [('dil_conv_5x5', 2), ('max_pool_3x3', 1)], [('sep_conv_3x3', 2), ('sep_conv_3x3', 1)], [('sep_conv_5x5', 0), ('sep_conv_3x3', 3)]], reduce_concat=range(2, 6))", "2": "Genotype(normal=[[('skip_connect', 1), ('sep_conv_3x3', 0)], [('sep_conv_3x3', 0), ('skip_connect', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 3)], [('sep_conv_3x3', 1), ('dil_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('sep_conv_3x3', 0), ('skip_connect', 1)], [('dil_conv_5x5', 2), ('max_pool_3x3', 1)], [('sep_conv_3x3', 2), ('sep_conv_3x3', 1)], [('sep_conv_5x5', 0), ('sep_conv_3x3', 3)]], reduce_concat=range(2, 6))"} -------------------------------------------------------------------------------- /CDARTS/CDARTS/cells/pdarts_genotype.json: -------------------------------------------------------------------------------- 1 | {"0": "Genotype(normal=[[('skip_connect', 0), ('dil_conv_3x3', 1)], [('skip_connect', 0),('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 3)], [('sep_conv_3x3',0), ('dil_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('avg_pool_3x3', 0), ('sep_conv_5x5', 1)], [('sep_conv_3x3', 0), ('dil_conv_5x5', 2)], [('max_pool_3x3', 0), ('dil_conv_3x3', 1)], [('dil_conv_3x3', 1), ('dil_conv_5x5', 3)]], reduce_concat=range(2, 6))", "1": "Genotype(normal=[[('skip_connect', 0), ('dil_conv_3x3', 1)], [('skip_connect', 0),('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 3)], [('sep_conv_3x3',0), ('dil_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('avg_pool_3x3', 0), ('sep_conv_5x5', 1)], [('sep_conv_3x3', 0), ('dil_conv_5x5', 2)], [('max_pool_3x3', 0), ('dil_conv_3x3', 1)], [('dil_conv_3x3', 1), ('dil_conv_5x5', 3)]], reduce_concat=range(2, 6))", "2": "Genotype(normal=[[('skip_connect', 0), ('dil_conv_3x3', 1)], [('skip_connect', 0),('sep_conv_3x3', 1)], [('sep_conv_3x3', 1), ('sep_conv_3x3', 3)], [('sep_conv_3x3',0), ('dil_conv_5x5', 4)]], normal_concat=range(2, 6), reduce=[[('avg_pool_3x3', 0), ('sep_conv_5x5', 1)], [('sep_conv_3x3', 0), ('dil_conv_5x5', 2)], [('max_pool_3x3', 0), ('dil_conv_3x3', 1)], [('dil_conv_3x3', 1), ('dil_conv_5x5', 3)]], reduce_concat=range(2, 6))"} -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .arraymisc import * 3 | from .utils import * 4 | from .fileio import * 5 | from .opencv_info import * 6 | from .image import * 7 | from .video import * 8 | from .visualization import * 9 | from .version import __version__ 10 | # The following modules are not imported to this level, so mmcv may be used 11 | # without PyTorch. 12 | # - runner 13 | # - parallel 14 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/_ext.cpython-36m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmcv/_ext.cpython-36m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/arraymisc/__init__.py: -------------------------------------------------------------------------------- 1 | from .quantization import quantize, dequantize 2 | 3 | __all__ = ['quantize', 'dequantize'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/cnn/__init__.py: -------------------------------------------------------------------------------- 1 | from .alexnet import AlexNet 2 | from .vgg import VGG, make_vgg_layer 3 | from .resnet import ResNet, make_res_layer 4 | from .weight_init import (constant_init, xavier_init, normal_init, 5 | uniform_init, kaiming_init, caffe2_xavier_init) 6 | 7 | __all__ = [ 8 | 'AlexNet', 'VGG', 'make_vgg_layer', 'ResNet', 'make_res_layer', 9 | 'constant_init', 'xavier_init', 'normal_init', 'uniform_init', 10 | 'kaiming_init', 'caffe2_xavier_init' 11 | ] 12 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/fileio/__init__.py: -------------------------------------------------------------------------------- 1 | from .io import load, dump, register_handler 2 | from .handlers import BaseFileHandler, JsonHandler, PickleHandler, YamlHandler 3 | from .parse import list_from_file, dict_from_file 4 | 5 | __all__ = [ 6 | 'load', 'dump', 'register_handler', 'BaseFileHandler', 'JsonHandler', 7 | 'PickleHandler', 'YamlHandler', 'list_from_file', 'dict_from_file' 8 | ] 9 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/fileio/handlers/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import BaseFileHandler 2 | from .json_handler import JsonHandler 3 | from .pickle_handler import PickleHandler 4 | from .yaml_handler import YamlHandler 5 | 6 | __all__ = ['BaseFileHandler', 'JsonHandler', 'PickleHandler', 'YamlHandler'] 7 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/fileio/handlers/base.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | 4 | class BaseFileHandler(object): 5 | 6 | __metaclass__ = ABCMeta # python 2 compatibility 7 | 8 | @abstractmethod 9 | def load_from_fileobj(self, file, **kwargs): 10 | pass 11 | 12 | @abstractmethod 13 | def dump_to_fileobj(self, obj, file, **kwargs): 14 | pass 15 | 16 | @abstractmethod 17 | def dump_to_str(self, obj, **kwargs): 18 | pass 19 | 20 | def load_from_path(self, filepath, mode='r', **kwargs): 21 | with open(filepath, mode) as f: 22 | return self.load_from_fileobj(f, **kwargs) 23 | 24 | def dump_to_path(self, obj, filepath, mode='w', **kwargs): 25 | with open(filepath, mode) as f: 26 | self.dump_to_fileobj(obj, f, **kwargs) 27 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/fileio/handlers/json_handler.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from .base import BaseFileHandler 4 | 5 | 6 | class JsonHandler(BaseFileHandler): 7 | 8 | def load_from_fileobj(self, file): 9 | return json.load(file) 10 | 11 | def dump_to_fileobj(self, obj, file, **kwargs): 12 | json.dump(obj, file, **kwargs) 13 | 14 | def dump_to_str(self, obj, **kwargs): 15 | return json.dumps(obj, **kwargs) 16 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/fileio/handlers/pickle_handler.py: -------------------------------------------------------------------------------- 1 | from six.moves import cPickle as pickle 2 | 3 | from .base import BaseFileHandler 4 | 5 | 6 | class PickleHandler(BaseFileHandler): 7 | 8 | def load_from_fileobj(self, file, **kwargs): 9 | return pickle.load(file, **kwargs) 10 | 11 | def load_from_path(self, filepath, **kwargs): 12 | return super(PickleHandler, self).load_from_path( 13 | filepath, mode='rb', **kwargs) 14 | 15 | def dump_to_str(self, obj, **kwargs): 16 | kwargs.setdefault('protocol', 2) 17 | return pickle.dumps(obj, **kwargs) 18 | 19 | def dump_to_fileobj(self, obj, file, **kwargs): 20 | kwargs.setdefault('protocol', 2) 21 | pickle.dump(obj, file, **kwargs) 22 | 23 | def dump_to_path(self, obj, filepath, **kwargs): 24 | super(PickleHandler, self).dump_to_path( 25 | obj, filepath, mode='wb', **kwargs) 26 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/fileio/handlers/yaml_handler.py: -------------------------------------------------------------------------------- 1 | import yaml 2 | 3 | try: 4 | from yaml import CLoader as Loader, CDumper as Dumper 5 | except ImportError: 6 | from yaml import Loader, Dumper 7 | 8 | from .base import BaseFileHandler # isort:skip 9 | 10 | 11 | class YamlHandler(BaseFileHandler): 12 | 13 | def load_from_fileobj(self, file, **kwargs): 14 | kwargs.setdefault('Loader', Loader) 15 | return yaml.load(file, **kwargs) 16 | 17 | def dump_to_fileobj(self, obj, file, **kwargs): 18 | kwargs.setdefault('Dumper', Dumper) 19 | yaml.dump(obj, file, **kwargs) 20 | 21 | def dump_to_str(self, obj, **kwargs): 22 | kwargs.setdefault('Dumper', Dumper) 23 | return yaml.dump(obj, **kwargs) 24 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/image/__init__.py: -------------------------------------------------------------------------------- 1 | from .io import imread, imwrite, imfrombytes 2 | from .transforms import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv, 3 | hsv2bgr, bgr2hls, hls2bgr, iminvert, imflip, imrotate, 4 | imcrop, impad, impad_to_multiple, imnormalize, 5 | imdenormalize, imresize, imresize_like, imrescale) 6 | 7 | __all__ = [ 8 | 'imread', 'imwrite', 'imfrombytes', 'bgr2gray', 'gray2bgr', 'bgr2rgb', 9 | 'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 'bgr2hls', 'hls2bgr', 'iminvert', 10 | 'imflip', 'imrotate', 'imcrop', 'impad', 'impad_to_multiple', 11 | 'imnormalize', 'imdenormalize', 'imresize', 'imresize_like', 'imrescale' 12 | ] 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/image/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | from .colorspace import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv, 2 | hsv2bgr, bgr2hls, hls2bgr, iminvert) 3 | from .geometry import imflip, imrotate, imcrop, impad, impad_to_multiple 4 | from .normalize import imnormalize, imdenormalize 5 | from .resize import imresize, imresize_like, imrescale 6 | 7 | __all__ = [ 8 | 'bgr2gray', 'gray2bgr', 'bgr2rgb', 'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 9 | 'bgr2hls', 'hls2bgr', 'iminvert', 'imflip', 'imrotate', 'imcrop', 'impad', 10 | 'impad_to_multiple', 'imnormalize', 'imdenormalize', 'imresize', 11 | 'imresize_like', 'imrescale' 12 | ] 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/image/transforms/normalize.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from .colorspace import bgr2rgb, rgb2bgr 4 | 5 | 6 | def imnormalize(img, mean, std, to_rgb=True): 7 | img = img.astype(np.float32) 8 | if to_rgb: 9 | img = bgr2rgb(img) 10 | return (img - mean) / std 11 | 12 | 13 | def imdenormalize(img, mean, std, to_bgr=True): 14 | img = (img * std) + mean 15 | if to_bgr: 16 | img = rgb2bgr(img) 17 | return img 18 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/opencv_info.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | 4 | def use_opencv2(): 5 | try: 6 | major_version = cv2.__version__.split('.')[0] 7 | except TypeError: # solves doc generation issue 8 | major_version = 4 9 | return major_version == '2' 10 | 11 | 12 | USE_OPENCV2 = use_opencv2() 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/parallel/__init__.py: -------------------------------------------------------------------------------- 1 | from .collate import collate 2 | from .data_container import DataContainer 3 | from .data_parallel import MMDataParallel 4 | from .distributed import MMDistributedDataParallel 5 | from .scatter_gather import scatter, scatter_kwargs 6 | 7 | __all__ = [ 8 | 'collate', 'DataContainer', 'MMDataParallel', 'MMDistributedDataParallel', 9 | 'scatter', 'scatter_kwargs' 10 | ] 11 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/parallel/data_parallel.py: -------------------------------------------------------------------------------- 1 | from torch.nn.parallel import DataParallel 2 | 3 | from .scatter_gather import scatter_kwargs 4 | 5 | 6 | class MMDataParallel(DataParallel): 7 | 8 | def scatter(self, inputs, kwargs, device_ids): 9 | return scatter_kwargs(inputs, kwargs, device_ids, dim=self.dim) 10 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/__init__.py: -------------------------------------------------------------------------------- 1 | from .runner import Runner 2 | from .log_buffer import LogBuffer 3 | from .dist_utils import get_dist_info, init_dist, master_only 4 | from .hooks import (Hook, CheckpointHook, ClosureHook, LrUpdaterHook, 5 | OptimizerHook, OptimizerArchHook, IterTimerHook, DistSamplerSeedHook, 6 | LoggerHook, TextLoggerHook, PaviLoggerHook, 7 | TensorboardLoggerHook) 8 | from .checkpoint import (load_state_dict, load_checkpoint, weights_to_cpu, 9 | save_checkpoint) 10 | from .parallel_test import parallel_test 11 | from .priority import Priority, get_priority 12 | from .utils import (get_host_info, get_dist_info, master_only, get_time_str, 13 | obj_from_dict) 14 | 15 | __all__ = [ 16 | 'Runner', 'LogBuffer', 'Hook', 'CheckpointHook', 'ClosureHook', 17 | 'LrUpdaterHook', 'OptimizerHook', 'OptimizerArchHook', 'IterTimerHook', 'DistSamplerSeedHook', 18 | 'LoggerHook', 'TextLoggerHook', 'PaviLoggerHook', 'TensorboardLoggerHook', 19 | 'load_state_dict', 'load_checkpoint', 'weights_to_cpu', 'save_checkpoint', 20 | 'parallel_test', 'Priority', 'get_priority', 'get_host_info', 21 | 'get_dist_info', 'master_only', 'get_time_str', 'obj_from_dict', 22 | 'init_dist', 'get_dist_info', 'master_only' 23 | ] 24 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/hooks/__init__.py: -------------------------------------------------------------------------------- 1 | from .hook import Hook 2 | from .checkpoint import CheckpointHook 3 | from .closure import ClosureHook 4 | from .lr_updater import LrUpdaterHook 5 | from .optimizer import OptimizerHook, OptimizerArchHook 6 | from .iter_timer import IterTimerHook 7 | from .sampler_seed import DistSamplerSeedHook 8 | from .memory import EmptyCacheHook 9 | from .logger import (LoggerHook, TextLoggerHook, PaviLoggerHook, 10 | TensorboardLoggerHook) 11 | 12 | __all__ = [ 13 | 'Hook', 'CheckpointHook', 'ClosureHook', 'LrUpdaterHook', 'OptimizerHook', 'OptimizerArchHook', 14 | 'IterTimerHook', 'DistSamplerSeedHook', 'EmptyCacheHook', 'LoggerHook', 15 | 'TextLoggerHook', 'PaviLoggerHook', 'TensorboardLoggerHook' 16 | ] 17 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/hooks/checkpoint.py: -------------------------------------------------------------------------------- 1 | from ..utils import master_only 2 | from .hook import Hook 3 | 4 | 5 | class CheckpointHook(Hook): 6 | 7 | def __init__(self, 8 | interval=-1, 9 | save_optimizer=True, 10 | out_dir=None, 11 | **kwargs): 12 | self.interval = interval 13 | self.save_optimizer = save_optimizer 14 | self.out_dir = out_dir 15 | self.args = kwargs 16 | 17 | @master_only 18 | def after_train_epoch(self, runner): 19 | if not self.every_n_epochs(runner, self.interval): 20 | return 21 | 22 | if not self.out_dir: 23 | self.out_dir = runner.work_dir 24 | runner.save_checkpoint( 25 | self.out_dir, save_optimizer=self.save_optimizer, **self.args) 26 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/hooks/closure.py: -------------------------------------------------------------------------------- 1 | from .hook import Hook 2 | 3 | 4 | class ClosureHook(Hook): 5 | 6 | def __init__(self, fn_name, fn): 7 | assert hasattr(self, fn_name) 8 | assert callable(fn) 9 | setattr(self, fn_name, fn) 10 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/hooks/iter_timer.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from .hook import Hook 4 | 5 | 6 | class IterTimerHook(Hook): 7 | 8 | def before_epoch(self, runner): 9 | self.t = time.time() 10 | 11 | def before_iter(self, runner): 12 | runner.log_buffer.update({'data_time': time.time() - self.t}) 13 | 14 | def after_iter(self, runner): 15 | runner.log_buffer.update({'time': time.time() - self.t}) 16 | self.t = time.time() 17 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/hooks/logger/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import LoggerHook 2 | from .pavi import PaviLoggerHook 3 | from .tensorboard import TensorboardLoggerHook 4 | from .text import TextLoggerHook 5 | 6 | __all__ = [ 7 | 'LoggerHook', 'TextLoggerHook', 'PaviLoggerHook', 'TensorboardLoggerHook' 8 | ] 9 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/hooks/memory.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from .hook import Hook 4 | 5 | 6 | class EmptyCacheHook(Hook): 7 | 8 | def __init__(self, before_epoch=False, after_epoch=True, after_iter=False): 9 | self._before_epoch = before_epoch 10 | self._after_epoch = after_epoch 11 | self._after_iter = after_iter 12 | 13 | def after_iter(self, runner): 14 | if self._after_iter: 15 | torch.cuda.empty_cache() 16 | 17 | def before_epoch(self, runner): 18 | if self._before_epoch: 19 | torch.cuda.empty_cache() 20 | 21 | def after_epoch(self, runner): 22 | if self._after_epoch: 23 | torch.cuda.empty_cache() 24 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/hooks/optimizer.py: -------------------------------------------------------------------------------- 1 | from torch.nn.utils import clip_grad 2 | 3 | from .hook import Hook 4 | 5 | 6 | class OptimizerHook(Hook): 7 | def __init__(self, grad_clip=None): 8 | self.grad_clip = grad_clip 9 | 10 | def clip_grads(self, params): 11 | clip_grad.clip_grad_norm_( 12 | filter(lambda p: p.requires_grad, params), **self.grad_clip) 13 | 14 | def after_train_iter(self, runner): 15 | runner.optimizer.zero_grad() 16 | runner.outputs['loss'].backward() 17 | if self.grad_clip is not None: 18 | self.clip_grads(runner.model.parameters()) 19 | runner.optimizer.step() 20 | 21 | 22 | class OptimizerArchHook(Hook): 23 | def __init__(self, grad_clip=None): 24 | self.grad_clip = grad_clip 25 | 26 | def clip_grads(self, params): 27 | clip_grad.clip_grad_norm_( 28 | filter(lambda p: p.requires_grad, params), **self.grad_clip) 29 | 30 | def arch_after_train_iter(self, runner): 31 | if runner.optimizer_arch is not None: 32 | runner.optimizer_arch.zero_grad() 33 | runner.outputs_arch['loss'].backward() 34 | if runner.optimizer_arch is not None: 35 | runner.optimizer_arch.step() -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/runner/hooks/sampler_seed.py: -------------------------------------------------------------------------------- 1 | from .hook import Hook 2 | 3 | 4 | class DistSamplerSeedHook(Hook): 5 | 6 | def before_epoch(self, runner): 7 | runner.data_loader.sampler.set_epoch(runner.epoch) 8 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .config import ConfigDict, Config 2 | from .misc import (is_str, iter_cast, list_cast, tuple_cast, is_seq_of, 3 | is_list_of, is_tuple_of, slice_list, concat_list, 4 | check_prerequisites, requires_package, requires_executable) 5 | from .path import (is_filepath, fopen, check_file_exist, mkdir_or_exist, 6 | symlink, scandir, FileNotFoundError) 7 | from .progressbar import ProgressBar, track_progress, track_parallel_progress 8 | from .timer import Timer, TimerError, check_time 9 | 10 | __all__ = [ 11 | 'ConfigDict', 'Config', 'is_str', 'iter_cast', 'list_cast', 'tuple_cast', 12 | 'is_seq_of', 'is_list_of', 'is_tuple_of', 'slice_list', 'concat_list', 13 | 'check_prerequisites', 'requires_package', 'requires_executable', 14 | 'is_filepath', 'fopen', 'check_file_exist', 'mkdir_or_exist', 'symlink', 15 | 'scandir', 'FileNotFoundError', 'ProgressBar', 'track_progress', 16 | 'track_parallel_progress', 'Timer', 'TimerError', 'check_time' 17 | ] 18 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.2.12' 2 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/video/__init__.py: -------------------------------------------------------------------------------- 1 | from .io import Cache, VideoReader, frames2video 2 | from .processing import convert_video, resize_video, cut_video, concat_video 3 | from .optflow import (flowread, flowwrite, quantize_flow, dequantize_flow, 4 | flow_warp) 5 | 6 | __all__ = [ 7 | 'Cache', 'VideoReader', 'frames2video', 'convert_video', 'resize_video', 8 | 'cut_video', 'concat_video', 'flowread', 'flowwrite', 'quantize_flow', 9 | 'dequantize_flow', 'flow_warp' 10 | ] 11 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/video/optflow_warp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmcv/video/optflow_warp/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/video/optflow_warp/flow_warp.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void FlowWarp(double* img, double* flow1, double* out, const int height, 7 | const int width, const int channels, const int filling_value, 8 | const int interpolateMode); 9 | 10 | void BilinearInterpolate(const double* img, int width, int height, int channels, 11 | double x, double y, double* out); 12 | 13 | void NNInterpolate(const double* img, int width, int height, int channels, 14 | double x, double y, double* out); 15 | 16 | template 17 | inline T __min__(T a, T b) { 18 | return a > b ? b : a; 19 | } 20 | 21 | template 22 | inline T __max__(T a, T b) { 23 | return (a < b) ? b : a; 24 | } 25 | 26 | template 27 | inline T EnforceRange(const T x, const int MaxValue) { 28 | return __min__(__max__(x, 0), MaxValue); 29 | } 30 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/video/optflow_warp/flow_warp_module.pyx: -------------------------------------------------------------------------------- 1 | STUFF = "Hi" 2 | 3 | import numpy as np 4 | cimport numpy as np 5 | 6 | np.import_array() 7 | 8 | cdef extern from "flow_warp.hpp": 9 | void FlowWarp(double* img, double* flow1, double* out, const int height, const int width, const int channels, const int filling_value, const int interpolateMode) 10 | 11 | def flow_warp_c(np.ndarray[double, ndim=3, mode="c"] img_array not None, 12 | np.ndarray[double, ndim=3, mode="c"] flow_array not None, 13 | int filling_value=0, 14 | int interpolate_mode=1): 15 | 16 | out_array = np.zeros_like(img_array) 17 | 18 | FlowWarp( np.PyArray_DATA(img_array), 19 | np.PyArray_DATA(flow_array), 20 | np.PyArray_DATA(out_array), 21 | out_array.shape[0], 22 | out_array.shape[1], 23 | out_array.shape[2], 24 | filling_value, 25 | interpolate_mode) 26 | 27 | return out_array 28 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmcv/visualization/__init__.py: -------------------------------------------------------------------------------- 1 | from .color import Color, color_val 2 | from .image import imshow, imshow_bboxes, imshow_det_bboxes 3 | from .optflow import flowshow, flow2rgb, make_color_wheel 4 | 5 | __all__ = [ 6 | 'Color', 'color_val', 'imshow', 'imshow_bboxes', 'imshow_det_bboxes', 7 | 'flowshow', 'flow2rgb', 'make_color_wheel' 8 | ] 9 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | mmcv>=0.2.6 2 | numpy 3 | matplotlib 4 | six 5 | terminaltables 6 | pycocotools 7 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | mmcv 2 | mmdet 3 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/__init__.py: -------------------------------------------------------------------------------- 1 | from .version import __version__, short_version 2 | 3 | __all__ = ['__version__', 'short_version'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/apis/__init__.py: -------------------------------------------------------------------------------- 1 | from .env import get_root_logger, init_dist, set_random_seed 2 | from .inference import (inference_detector, init_detector, show_result, 3 | show_result_pyplot) 4 | from .train import train_detector 5 | 6 | __all__ = [ 7 | 'init_dist', 'get_root_logger', 'set_random_seed', 'train_detector', 8 | 'init_detector', 'inference_detector', 'show_result', 'show_result_pyplot' 9 | ] 10 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/__init__.py: -------------------------------------------------------------------------------- 1 | from .anchor import * # noqa: F401, F403 2 | from .bbox import * # noqa: F401, F403 3 | from .evaluation import * # noqa: F401, F403 4 | from .fp16 import * # noqa: F401, F403 5 | from .mask import * # noqa: F401, F403 6 | from .post_processing import * # noqa: F401, F403 7 | from .utils import * # noqa: F401, F403 8 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/anchor/__init__.py: -------------------------------------------------------------------------------- 1 | from .anchor_generator import AnchorGenerator 2 | from .anchor_target import anchor_target, anchor_inside_flags 3 | from .guided_anchor_target import ga_loc_target, ga_shape_target 4 | 5 | __all__ = [ 6 | 'AnchorGenerator', 'anchor_target', 'anchor_inside_flags', 'ga_loc_target', 7 | 'ga_shape_target' 8 | ] 9 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/__init__.py: -------------------------------------------------------------------------------- 1 | from .geometry import bbox_overlaps 2 | from .assigners import BaseAssigner, MaxIoUAssigner, AssignResult 3 | from .samplers import (BaseSampler, PseudoSampler, RandomSampler, 4 | InstanceBalancedPosSampler, IoUBalancedNegSampler, 5 | CombinedSampler, SamplingResult) 6 | from .assign_sampling import build_assigner, build_sampler, assign_and_sample 7 | from .transforms import (bbox2delta, delta2bbox, bbox_flip, bbox_mapping, 8 | bbox_mapping_back, bbox2roi, roi2bbox, bbox2result, 9 | distance2bbox) 10 | from .bbox_target import bbox_target 11 | 12 | __all__ = [ 13 | 'bbox_overlaps', 'BaseAssigner', 'MaxIoUAssigner', 'AssignResult', 14 | 'BaseSampler', 'PseudoSampler', 'RandomSampler', 15 | 'InstanceBalancedPosSampler', 'IoUBalancedNegSampler', 'CombinedSampler', 16 | 'SamplingResult', 'build_assigner', 'build_sampler', 'assign_and_sample', 17 | 'bbox2delta', 'delta2bbox', 'bbox_flip', 'bbox_mapping', 18 | 'bbox_mapping_back', 'bbox2roi', 'roi2bbox', 'bbox2result', 19 | 'distance2bbox', 'bbox_target' 20 | ] 21 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/assign_sampling.py: -------------------------------------------------------------------------------- 1 | import mmcv 2 | 3 | from . import assigners, samplers 4 | 5 | 6 | def build_assigner(cfg, **kwargs): 7 | if isinstance(cfg, assigners.BaseAssigner): 8 | return cfg 9 | elif isinstance(cfg, dict): 10 | return mmcv.runner.obj_from_dict(cfg, assigners, default_args=kwargs) 11 | else: 12 | raise TypeError('Invalid type {} for building a sampler'.format( 13 | type(cfg))) 14 | 15 | 16 | def build_sampler(cfg, **kwargs): 17 | if isinstance(cfg, samplers.BaseSampler): 18 | return cfg 19 | elif isinstance(cfg, dict): 20 | return mmcv.runner.obj_from_dict(cfg, samplers, default_args=kwargs) 21 | else: 22 | raise TypeError('Invalid type {} for building a sampler'.format( 23 | type(cfg))) 24 | 25 | 26 | def assign_and_sample(bboxes, gt_bboxes, gt_bboxes_ignore, gt_labels, cfg): 27 | bbox_assigner = build_assigner(cfg.assigner) 28 | bbox_sampler = build_sampler(cfg.sampler) 29 | assign_result = bbox_assigner.assign(bboxes, gt_bboxes, gt_bboxes_ignore, 30 | gt_labels) 31 | sampling_result = bbox_sampler.sample(assign_result, bboxes, gt_bboxes, 32 | gt_labels) 33 | return assign_result, sampling_result 34 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/assigners/__init__.py: -------------------------------------------------------------------------------- 1 | from .base_assigner import BaseAssigner 2 | from .max_iou_assigner import MaxIoUAssigner 3 | from .approx_max_iou_assigner import ApproxMaxIoUAssigner 4 | from .assign_result import AssignResult 5 | 6 | __all__ = [ 7 | 'BaseAssigner', 'MaxIoUAssigner', 'ApproxMaxIoUAssigner', 'AssignResult' 8 | ] 9 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/assigners/assign_result.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | class AssignResult(object): 5 | 6 | def __init__(self, num_gts, gt_inds, max_overlaps, labels=None): 7 | self.num_gts = num_gts 8 | self.gt_inds = gt_inds 9 | self.max_overlaps = max_overlaps 10 | self.labels = labels 11 | 12 | def add_gt_(self, gt_labels): 13 | self_inds = torch.arange( 14 | 1, len(gt_labels) + 1, dtype=torch.long, device=gt_labels.device) 15 | self.gt_inds = torch.cat([self_inds, self.gt_inds]) 16 | self.max_overlaps = torch.cat( 17 | [self.max_overlaps.new_ones(self.num_gts), self.max_overlaps]) 18 | if self.labels is not None: 19 | self.labels = torch.cat([gt_labels, self.labels]) 20 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/assigners/base_assigner.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | 4 | class BaseAssigner(metaclass=ABCMeta): 5 | 6 | @abstractmethod 7 | def assign(self, bboxes, gt_bboxes, gt_bboxes_ignore=None, gt_labels=None): 8 | pass 9 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/samplers/__init__.py: -------------------------------------------------------------------------------- 1 | from .base_sampler import BaseSampler 2 | from .pseudo_sampler import PseudoSampler 3 | from .random_sampler import RandomSampler 4 | from .instance_balanced_pos_sampler import InstanceBalancedPosSampler 5 | from .iou_balanced_neg_sampler import IoUBalancedNegSampler 6 | from .combined_sampler import CombinedSampler 7 | from .ohem_sampler import OHEMSampler 8 | from .sampling_result import SamplingResult 9 | 10 | __all__ = [ 11 | 'BaseSampler', 'PseudoSampler', 'RandomSampler', 12 | 'InstanceBalancedPosSampler', 'IoUBalancedNegSampler', 'CombinedSampler', 13 | 'OHEMSampler', 'SamplingResult' 14 | ] 15 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/samplers/combined_sampler.py: -------------------------------------------------------------------------------- 1 | from .base_sampler import BaseSampler 2 | from ..assign_sampling import build_sampler 3 | 4 | 5 | class CombinedSampler(BaseSampler): 6 | 7 | def __init__(self, pos_sampler, neg_sampler, **kwargs): 8 | super(CombinedSampler, self).__init__(**kwargs) 9 | self.pos_sampler = build_sampler(pos_sampler, **kwargs) 10 | self.neg_sampler = build_sampler(neg_sampler, **kwargs) 11 | 12 | def _sample_pos(self, **kwargs): 13 | raise NotImplementedError 14 | 15 | def _sample_neg(self, **kwargs): 16 | raise NotImplementedError 17 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/samplers/pseudo_sampler.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from .base_sampler import BaseSampler 4 | from .sampling_result import SamplingResult 5 | 6 | 7 | class PseudoSampler(BaseSampler): 8 | 9 | def __init__(self, **kwargs): 10 | pass 11 | 12 | def _sample_pos(self, **kwargs): 13 | raise NotImplementedError 14 | 15 | def _sample_neg(self, **kwargs): 16 | raise NotImplementedError 17 | 18 | def sample(self, assign_result, bboxes, gt_bboxes, **kwargs): 19 | pos_inds = torch.nonzero( 20 | assign_result.gt_inds > 0).squeeze(-1).unique() 21 | neg_inds = torch.nonzero( 22 | assign_result.gt_inds == 0).squeeze(-1).unique() 23 | gt_flags = bboxes.new_zeros(bboxes.shape[0], dtype=torch.uint8) 24 | sampling_result = SamplingResult(pos_inds, neg_inds, bboxes, gt_bboxes, 25 | assign_result, gt_flags) 26 | return sampling_result 27 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/bbox/samplers/sampling_result.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | class SamplingResult(object): 5 | 6 | def __init__(self, pos_inds, neg_inds, bboxes, gt_bboxes, assign_result, 7 | gt_flags): 8 | self.pos_inds = pos_inds 9 | self.neg_inds = neg_inds 10 | self.pos_bboxes = bboxes[pos_inds] 11 | self.neg_bboxes = bboxes[neg_inds] 12 | self.pos_is_gt = gt_flags[pos_inds] 13 | 14 | self.num_gts = gt_bboxes.shape[0] 15 | self.pos_assigned_gt_inds = assign_result.gt_inds[pos_inds] - 1 16 | self.pos_gt_bboxes = gt_bboxes[self.pos_assigned_gt_inds, :] 17 | if assign_result.labels is not None: 18 | self.pos_gt_labels = assign_result.labels[pos_inds] 19 | else: 20 | self.pos_gt_labels = None 21 | 22 | @property 23 | def bboxes(self): 24 | return torch.cat([self.pos_bboxes, self.neg_bboxes]) 25 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | from .class_names import (coco_classes, dataset_aliases, get_classes, 2 | imagenet_det_classes, imagenet_vid_classes, 3 | voc_classes) 4 | from .eval_hooks import DistEvalHook 5 | from .mean_ap import average_precision, eval_map, print_map_summary 6 | from .recall import (eval_recalls, plot_iou_recall, plot_num_recall, 7 | print_recall_summary) 8 | 9 | __all__ = [ 10 | 'voc_classes', 'imagenet_det_classes', 'imagenet_vid_classes', 11 | 'coco_classes', 'dataset_aliases', 'get_classes', 'DistEvalHook', 12 | 'average_precision', 'eval_map', 'print_map_summary', 'eval_recalls', 13 | 'print_recall_summary', 'plot_num_recall', 'plot_iou_recall' 14 | ] 15 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/fp16/__init__.py: -------------------------------------------------------------------------------- 1 | from .decorators import auto_fp16, force_fp32 2 | from .hooks import Fp16OptimizerHook, wrap_fp16_model 3 | 4 | __all__ = ['auto_fp16', 'force_fp32', 'Fp16OptimizerHook', 'wrap_fp16_model'] 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/fp16/utils.py: -------------------------------------------------------------------------------- 1 | from collections import abc 2 | 3 | import numpy as np 4 | import torch 5 | 6 | 7 | def cast_tensor_type(inputs, src_type, dst_type): 8 | if isinstance(inputs, torch.Tensor): 9 | return inputs.to(dst_type) 10 | elif isinstance(inputs, str): 11 | return inputs 12 | elif isinstance(inputs, np.ndarray): 13 | return inputs 14 | elif isinstance(inputs, abc.Mapping): 15 | return type(inputs)({ 16 | k: cast_tensor_type(v, src_type, dst_type) 17 | for k, v in inputs.items() 18 | }) 19 | elif isinstance(inputs, abc.Iterable): 20 | return type(inputs)( 21 | cast_tensor_type(item, src_type, dst_type) for item in inputs) 22 | else: 23 | return inputs 24 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/mask/__init__.py: -------------------------------------------------------------------------------- 1 | from .utils import split_combined_polys 2 | from .mask_target import mask_target 3 | 4 | __all__ = ['split_combined_polys', 'mask_target'] 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/mask/utils.py: -------------------------------------------------------------------------------- 1 | import mmcv 2 | 3 | 4 | def split_combined_polys(polys, poly_lens, polys_per_mask): 5 | """Split the combined 1-D polys into masks. 6 | 7 | A mask is represented as a list of polys, and a poly is represented as 8 | a 1-D array. In dataset, all masks are concatenated into a single 1-D 9 | tensor. Here we need to split the tensor into original representations. 10 | 11 | Args: 12 | polys (list): a list (length = image num) of 1-D tensors 13 | poly_lens (list): a list (length = image num) of poly length 14 | polys_per_mask (list): a list (length = image num) of poly number 15 | of each mask 16 | 17 | Returns: 18 | list: a list (length = image num) of list (length = mask num) of 19 | list (length = poly num) of numpy array 20 | """ 21 | mask_polys_list = [] 22 | for img_id in range(len(polys)): 23 | polys_single = polys[img_id] 24 | polys_lens_single = poly_lens[img_id].tolist() 25 | polys_per_mask_single = polys_per_mask[img_id].tolist() 26 | 27 | split_polys = mmcv.slice_list(polys_single, polys_lens_single) 28 | mask_polys = mmcv.slice_list(split_polys, polys_per_mask_single) 29 | mask_polys_list.append(mask_polys) 30 | return mask_polys_list 31 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/post_processing/__init__.py: -------------------------------------------------------------------------------- 1 | from .bbox_nms import multiclass_nms 2 | from .merge_augs import (merge_aug_proposals, merge_aug_bboxes, 3 | merge_aug_scores, merge_aug_masks) 4 | 5 | __all__ = [ 6 | 'multiclass_nms', 'merge_aug_proposals', 'merge_aug_bboxes', 7 | 'merge_aug_scores', 'merge_aug_masks' 8 | ] 9 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .dist_utils import allreduce_grads, DistOptimizerHook, DistOptimizerArchHook 2 | from .misc import tensor2imgs, unmap, multi_apply 3 | 4 | __all__ = [ 5 | 'allreduce_grads', 'DistOptimizerHook', 'tensor2imgs', 'unmap', 6 | 'multi_apply', 'DistOptimizerArchHook' 7 | ] 8 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/core/utils/misc.py: -------------------------------------------------------------------------------- 1 | from functools import partial 2 | 3 | import mmcv 4 | import numpy as np 5 | from six.moves import map, zip 6 | 7 | 8 | def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True): 9 | num_imgs = tensor.size(0) 10 | mean = np.array(mean, dtype=np.float32) 11 | std = np.array(std, dtype=np.float32) 12 | imgs = [] 13 | for img_id in range(num_imgs): 14 | img = tensor[img_id, ...].cpu().numpy().transpose(1, 2, 0) 15 | img = mmcv.imdenormalize( 16 | img, mean, std, to_bgr=to_rgb).astype(np.uint8) 17 | imgs.append(np.ascontiguousarray(img)) 18 | return imgs 19 | 20 | 21 | def multi_apply(func, *args, **kwargs): 22 | pfunc = partial(func, **kwargs) if kwargs else func 23 | map_results = map(pfunc, *args) 24 | return tuple(map(list, zip(*map_results))) 25 | 26 | 27 | def unmap(data, count, inds, fill=0): 28 | """ Unmap a subset of item (data) back to the original set of items (of 29 | size count) """ 30 | if data.dim() == 1: 31 | ret = data.new_full((count, ), fill) 32 | ret[inds] = data 33 | else: 34 | new_size = (count, ) + data.size()[1:] 35 | ret = data.new_full(new_size, fill) 36 | ret[inds, :] = data 37 | return ret 38 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | from .custom import CustomDataset 2 | from .cityscapes import CityscapesDataset 3 | from .xml_style import XMLDataset 4 | from .coco import CocoDataset 5 | from .voc import VOCDataset 6 | from .wider_face import WIDERFaceDataset 7 | from .loader import GroupSampler, DistributedGroupSampler, build_dataloader, build_dataloader_arch 8 | from .dataset_wrappers import ConcatDataset, RepeatDataset 9 | from .registry import DATASETS 10 | from .builder import build_dataset 11 | 12 | __all__ = [ 13 | 'CustomDataset', 'XMLDataset', 'CocoDataset', 'VOCDataset', 14 | 'CityscapesDataset', 'GroupSampler', 'DistributedGroupSampler', 15 | 'build_dataloader', 'ConcatDataset', 'RepeatDataset', 'WIDERFaceDataset', 16 | 'DATASETS', 'build_dataset', 'build_dataloader_arch' 17 | ] -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/datasets/cityscapes.py: -------------------------------------------------------------------------------- 1 | from .coco import CocoDataset 2 | from .registry import DATASETS 3 | 4 | 5 | @DATASETS.register_module 6 | class CityscapesDataset(CocoDataset): 7 | 8 | CLASSES = ('person', 'rider', 'car', 'truck', 'bus', 'train', 'motorcycle', 9 | 'bicycle') 10 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/datasets/loader/__init__.py: -------------------------------------------------------------------------------- 1 | from .build_loader import build_dataloader, build_dataloader_arch 2 | from .sampler import DistributedGroupSampler, GroupSampler 3 | 4 | __all__ = ['GroupSampler', 'DistributedGroupSampler', 'build_dataloader', 'build_dataloader_arch'] 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/datasets/pipelines/__init__.py: -------------------------------------------------------------------------------- 1 | from .compose import Compose 2 | from .formating import (Collect, ImageToTensor, ToDataContainer, ToTensor, 3 | Transpose, to_tensor) 4 | from .loading import LoadAnnotations, LoadImageFromFile, LoadProposals 5 | from .test_aug import MultiScaleFlipAug 6 | from .transforms import (Albu, Expand, MinIoURandomCrop, Normalize, Pad, 7 | PhotoMetricDistortion, RandomCrop, RandomFlip, Resize, 8 | SegResizeFlipPadRescale) 9 | 10 | __all__ = [ 11 | 'Compose', 'to_tensor', 'ToTensor', 'ImageToTensor', 'ToDataContainer', 12 | 'Transpose', 'Collect', 'LoadAnnotations', 'LoadImageFromFile', 13 | 'LoadProposals', 'MultiScaleFlipAug', 'Resize', 'RandomFlip', 'Pad', 14 | 'RandomCrop', 'Normalize', 'SegResizeFlipPadRescale', 'MinIoURandomCrop', 15 | 'Expand', 'PhotoMetricDistortion', 'Albu' 16 | ] 17 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/datasets/pipelines/compose.py: -------------------------------------------------------------------------------- 1 | import collections 2 | 3 | from mmdet.utils import build_from_cfg 4 | from ..registry import PIPELINES 5 | 6 | 7 | @PIPELINES.register_module 8 | class Compose(object): 9 | 10 | def __init__(self, transforms): 11 | assert isinstance(transforms, collections.abc.Sequence) 12 | self.transforms = [] 13 | for transform in transforms: 14 | if isinstance(transform, dict): 15 | transform = build_from_cfg(transform, PIPELINES) 16 | self.transforms.append(transform) 17 | elif callable(transform): 18 | self.transforms.append(transform) 19 | else: 20 | raise TypeError('transform must be callable or a dict') 21 | 22 | def __call__(self, data): 23 | for t in self.transforms: 24 | data = t(data) 25 | if data is None: 26 | return None 27 | return data 28 | 29 | def __repr__(self): 30 | format_string = self.__class__.__name__ + '(' 31 | for t in self.transforms: 32 | format_string += '\n' 33 | format_string += ' {0}'.format(t) 34 | format_string += '\n)' 35 | return format_string 36 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/datasets/registry.py: -------------------------------------------------------------------------------- 1 | from mmdet.utils import Registry 2 | 3 | DATASETS = Registry('dataset') 4 | PIPELINES = Registry('pipeline') 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .backbones import * # noqa: F401,F403 2 | from .necks import * # noqa: F401,F403 3 | from .roi_extractors import * # noqa: F401,F403 4 | from .anchor_heads import * # noqa: F401,F403 5 | from .shared_heads import * # noqa: F401,F403 6 | from .bbox_heads import * # noqa: F401,F403 7 | from .mask_heads import * # noqa: F401,F403 8 | from .losses import * # noqa: F401,F403 9 | from .detectors import * # noqa: F401,F403 10 | from .registry import (BACKBONES, NECKS, ROI_EXTRACTORS, SHARED_HEADS, HEADS, 11 | LOSSES, DETECTORS) 12 | from .builder import (build_backbone, build_neck, build_roi_extractor, 13 | build_shared_head, build_head, build_loss, 14 | build_detector) 15 | 16 | __all__ = [ 17 | 'BACKBONES', 'NECKS', 'ROI_EXTRACTORS', 'SHARED_HEADS', 'HEADS', 'LOSSES', 18 | 'DETECTORS', 'build_backbone', 'build_neck', 'build_roi_extractor', 19 | 'build_shared_head', 'build_head', 'build_loss', 'build_detector' 20 | ] 21 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/anchor_heads/__init__.py: -------------------------------------------------------------------------------- 1 | from .anchor_head import AnchorHead 2 | from .guided_anchor_head import GuidedAnchorHead, FeatureAdaption 3 | from .fcos_head import FCOSHead 4 | from .rpn_head import RPNHead 5 | from .ga_rpn_head import GARPNHead 6 | from .retina_head import RetinaHead 7 | from .ga_retina_head import GARetinaHead 8 | from .ssd_head import SSDHead 9 | 10 | __all__ = [ 11 | 'AnchorHead', 'GuidedAnchorHead', 'FeatureAdaption', 'RPNHead', 12 | 'GARPNHead', 'RetinaHead', 'GARetinaHead', 'SSDHead', 'FCOSHead' 13 | ] 14 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/backbones/__init__.py: -------------------------------------------------------------------------------- 1 | from .resnet import ResNet, make_res_layer 2 | from .resnext import ResNeXt 3 | from .ssd_vgg import SSDVGG 4 | from .hrnet import HRNet 5 | from .mobilenetv2 import MobileNetV2 6 | from .detnas import DetNas 7 | from .fbnet import FBNet 8 | from .mnasnet import MnasNet 9 | from .mobilenetv3 import SSDMobilenetV3 10 | from .efficientnet import SSDEFFB0 11 | 12 | __all__ = ['ResNet', 'make_res_layer', 'ResNeXt', 'SSDVGG', 'HRNet', 'MobileNetV2', 'DetNas', 'FBNet', 'MnasNet', 'SSDMobilenetV3', 'SSDEFFB0'] 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/backbones/feature_hooks.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict, OrderedDict 2 | from functools import partial 3 | 4 | 5 | class FeatureHooks: 6 | 7 | def __init__(self, hooks, named_modules): 8 | # setup feature hooks 9 | modules = {k: v for k, v in named_modules} 10 | for h in hooks: 11 | hook_name = h['name'] 12 | m = modules[hook_name] 13 | hook_fn = partial(self._collect_output_hook, hook_name) 14 | if h['type'] == 'forward_pre': 15 | m.register_forward_pre_hook(hook_fn) 16 | elif h['type'] == 'forward': 17 | m.register_forward_hook(hook_fn) 18 | else: 19 | assert False, "Unsupported hook type" 20 | self._feature_outputs = defaultdict(OrderedDict) 21 | 22 | def _collect_output_hook(self, name, *args): 23 | x = args[-1] # tensor we want is last argument, output for fwd, input for fwd_pre 24 | if isinstance(x, tuple): 25 | x = x[0] # unwrap input tuple 26 | self._feature_outputs[x.device][name] = x 27 | 28 | def get_output(self, device): 29 | output = tuple(self._feature_outputs[device].values())[::-1] 30 | self._feature_outputs[device] = OrderedDict() # clear after reading 31 | return output 32 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/bbox_heads/__init__.py: -------------------------------------------------------------------------------- 1 | from .bbox_head import BBoxHead 2 | from .convfc_bbox_head import ConvFCBBoxHead, SharedFCBBoxHead 3 | from .double_bbox_head import DoubleConvFCBBoxHead 4 | 5 | __all__ = [ 6 | 'BBoxHead', 'ConvFCBBoxHead', 'SharedFCBBoxHead', 'DoubleConvFCBBoxHead' 7 | ] 8 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/bbox_heads/auto_head/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/models/bbox_heads/auto_head/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/bbox_heads/auto_head/build_head.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Copyright (c) 2019 Jianyuan Guo (guojianyuan1@huawei.com) 3 | # -------------------------------------------------------- 4 | 5 | # from .darts_head_search import DartsHead 6 | from .mbblock_head_search import MbblockHead 7 | 8 | 9 | def build_search_head(cfg): 10 | """Build head model from config dict. 11 | """ 12 | if cfg is not None: 13 | cfg_ = cfg.copy() 14 | head_type = cfg_.pop('type') 15 | if head_type == 'DARTS': 16 | raise NotImplementedError 17 | elif head_type == 'MBBlock': 18 | return MbblockHead(**cfg_) 19 | else: 20 | raise KeyError('Invalid head type {}'.fromat(head_type)) 21 | else: 22 | return None -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/builder.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | 3 | from mmdet.utils import build_from_cfg 4 | from .registry import (BACKBONES, NECKS, ROI_EXTRACTORS, SHARED_HEADS, HEADS, 5 | LOSSES, DETECTORS) 6 | 7 | 8 | def build(cfg, registry, default_args=None): 9 | if isinstance(cfg, list): 10 | modules = [ 11 | build_from_cfg(cfg_, registry, default_args) for cfg_ in cfg 12 | ] 13 | return nn.Sequential(*modules) 14 | else: 15 | return build_from_cfg(cfg, registry, default_args) 16 | 17 | 18 | def build_backbone(cfg): 19 | return build(cfg, BACKBONES) 20 | 21 | 22 | def build_neck(cfg): 23 | return build(cfg, NECKS) 24 | 25 | 26 | def build_roi_extractor(cfg): 27 | return build(cfg, ROI_EXTRACTORS) 28 | 29 | 30 | def build_shared_head(cfg): 31 | return build(cfg, SHARED_HEADS) 32 | 33 | 34 | def build_head(cfg): 35 | return build(cfg, HEADS) 36 | 37 | 38 | def build_loss(cfg): 39 | return build(cfg, LOSSES) 40 | 41 | 42 | def build_detector(cfg, train_cfg=None, test_cfg=None): 43 | return build(cfg, DETECTORS, dict(train_cfg=train_cfg, test_cfg=test_cfg)) 44 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/detectors/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import BaseDetector 2 | from .double_head_rcnn import DoubleHeadRCNN 3 | from .single_stage import SingleStageDetector 4 | from .two_stage import TwoStageDetector 5 | from .rpn import RPN 6 | from .fast_rcnn import FastRCNN 7 | from .faster_rcnn import FasterRCNN 8 | from .mask_rcnn import MaskRCNN 9 | from .cascade_rcnn import CascadeRCNN 10 | from .htc import HybridTaskCascade 11 | from .retinanet import RetinaNet 12 | from .fcos import FCOS 13 | from .grid_rcnn import GridRCNN 14 | from .mask_scoring_rcnn import MaskScoringRCNN 15 | 16 | __all__ = [ 17 | 'BaseDetector', 'SingleStageDetector', 'TwoStageDetector', 'RPN', 18 | 'FastRCNN', 'FasterRCNN', 'MaskRCNN', 'CascadeRCNN', 'HybridTaskCascade', 19 | 'RetinaNet', 'FCOS', 'GridRCNN', 'MaskScoringRCNN', 'DoubleHeadRCNN' 20 | ] 21 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/detectors/faster_rcnn.py: -------------------------------------------------------------------------------- 1 | from .two_stage import TwoStageDetector 2 | from ..registry import DETECTORS 3 | 4 | 5 | @DETECTORS.register_module 6 | class FasterRCNN(TwoStageDetector): 7 | 8 | def __init__(self, 9 | backbone, 10 | rpn_head, 11 | bbox_roi_extractor, 12 | bbox_head, 13 | train_cfg, 14 | test_cfg, 15 | neck=None, 16 | shared_head=None, 17 | cls_roi_scale_factor=None, 18 | reg_roi_scale_factor=None, 19 | pretrained=None): 20 | super(FasterRCNN, self).__init__( 21 | backbone=backbone, 22 | neck=neck, 23 | shared_head=shared_head, 24 | rpn_head=rpn_head, 25 | bbox_roi_extractor=bbox_roi_extractor, 26 | bbox_head=bbox_head, 27 | train_cfg=train_cfg, 28 | test_cfg=test_cfg, 29 | cls_roi_scale_factor = cls_roi_scale_factor, 30 | reg_roi_scale_factor = reg_roi_scale_factor, 31 | pretrained=pretrained) 32 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/detectors/fcos.py: -------------------------------------------------------------------------------- 1 | from .single_stage import SingleStageDetector 2 | from ..registry import DETECTORS 3 | 4 | 5 | @DETECTORS.register_module 6 | class FCOS(SingleStageDetector): 7 | 8 | def __init__(self, 9 | backbone, 10 | neck, 11 | bbox_head, 12 | train_cfg=None, 13 | test_cfg=None, 14 | pretrained=None): 15 | super(FCOS, self).__init__(backbone, neck, bbox_head, train_cfg, 16 | test_cfg, pretrained) 17 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/detectors/mask_rcnn.py: -------------------------------------------------------------------------------- 1 | from .two_stage import TwoStageDetector 2 | from ..registry import DETECTORS 3 | 4 | 5 | @DETECTORS.register_module 6 | class MaskRCNN(TwoStageDetector): 7 | 8 | def __init__(self, 9 | backbone, 10 | rpn_head, 11 | bbox_roi_extractor, 12 | bbox_head, 13 | mask_roi_extractor, 14 | mask_head, 15 | train_cfg, 16 | test_cfg, 17 | neck=None, 18 | shared_head=None, 19 | pretrained=None): 20 | super(MaskRCNN, self).__init__( 21 | backbone=backbone, 22 | neck=neck, 23 | shared_head=shared_head, 24 | rpn_head=rpn_head, 25 | bbox_roi_extractor=bbox_roi_extractor, 26 | bbox_head=bbox_head, 27 | mask_roi_extractor=mask_roi_extractor, 28 | mask_head=mask_head, 29 | train_cfg=train_cfg, 30 | test_cfg=test_cfg, 31 | pretrained=pretrained) 32 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/detectors/retinanet.py: -------------------------------------------------------------------------------- 1 | from .single_stage import SingleStageDetector 2 | from ..registry import DETECTORS 3 | 4 | 5 | @DETECTORS.register_module 6 | class RetinaNet(SingleStageDetector): 7 | 8 | def __init__(self, 9 | backbone, 10 | neck, 11 | bbox_head, 12 | train_cfg=None, 13 | test_cfg=None, 14 | pretrained=None): 15 | super(RetinaNet, self).__init__(backbone, neck, bbox_head, train_cfg, 16 | test_cfg, pretrained) 17 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/losses/__init__.py: -------------------------------------------------------------------------------- 1 | from .accuracy import accuracy, Accuracy 2 | from .cross_entropy_loss import (cross_entropy, binary_cross_entropy, 3 | mask_cross_entropy, CrossEntropyLoss) 4 | from .focal_loss import sigmoid_focal_loss, FocalLoss 5 | from .smooth_l1_loss import smooth_l1_loss, SmoothL1Loss 6 | from .ghm_loss import GHMC, GHMR 7 | from .balanced_l1_loss import balanced_l1_loss, BalancedL1Loss 8 | from .mse_loss import mse_loss, MSELoss 9 | from .iou_loss import iou_loss, bounded_iou_loss, IoULoss, BoundedIoULoss 10 | from .utils import reduce_loss, weight_reduce_loss, weighted_loss 11 | 12 | __all__ = [ 13 | 'accuracy', 'Accuracy', 'cross_entropy', 'binary_cross_entropy', 14 | 'mask_cross_entropy', 'CrossEntropyLoss', 'sigmoid_focal_loss', 15 | 'FocalLoss', 'smooth_l1_loss', 'SmoothL1Loss', 'balanced_l1_loss', 16 | 'BalancedL1Loss', 'mse_loss', 'MSELoss', 'iou_loss', 'bounded_iou_loss', 17 | 'IoULoss', 'BoundedIoULoss', 'GHMC', 'GHMR', 'reduce_loss', 18 | 'weight_reduce_loss', 'weighted_loss' 19 | ] 20 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/losses/accuracy.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | 3 | 4 | def accuracy(pred, target, topk=1): 5 | assert isinstance(topk, (int, tuple)) 6 | if isinstance(topk, int): 7 | topk = (topk, ) 8 | return_single = True 9 | else: 10 | return_single = False 11 | 12 | maxk = max(topk) 13 | _, pred_label = pred.topk(maxk, dim=1) 14 | pred_label = pred_label.t() 15 | correct = pred_label.eq(target.view(1, -1).expand_as(pred_label)) 16 | 17 | res = [] 18 | for k in topk: 19 | correct_k = correct[:k].view(-1).float().sum(0, keepdim=True) 20 | res.append(correct_k.mul_(100.0 / pred.size(0))) 21 | return res[0] if return_single else res 22 | 23 | 24 | class Accuracy(nn.Module): 25 | 26 | def __init__(self, topk=(1, )): 27 | super().__init__() 28 | self.topk = topk 29 | 30 | def forward(self, pred, target): 31 | return accuracy(pred, target, self.topk) 32 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/losses/mse_loss.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch.nn.functional as F 3 | 4 | from .utils import weighted_loss 5 | from ..registry import LOSSES 6 | 7 | mse_loss = weighted_loss(F.mse_loss) 8 | 9 | 10 | @LOSSES.register_module 11 | class MSELoss(nn.Module): 12 | 13 | def __init__(self, reduction='mean', loss_weight=1.0): 14 | super().__init__() 15 | self.reduction = reduction 16 | self.loss_weight = loss_weight 17 | 18 | def forward(self, pred, target, weight=None, avg_factor=None): 19 | loss = self.loss_weight * mse_loss( 20 | pred, 21 | target, 22 | weight, 23 | reduction=self.reduction, 24 | avg_factor=avg_factor) 25 | return loss 26 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/mask_heads/__init__.py: -------------------------------------------------------------------------------- 1 | from .fcn_mask_head import FCNMaskHead 2 | from .fused_semantic_head import FusedSemanticHead 3 | from .grid_head import GridHead 4 | from .htc_mask_head import HTCMaskHead 5 | from .maskiou_head import MaskIoUHead 6 | 7 | __all__ = [ 8 | 'FCNMaskHead', 'HTCMaskHead', 'FusedSemanticHead', 'GridHead', 9 | 'MaskIoUHead' 10 | ] 11 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/necks/__init__.py: -------------------------------------------------------------------------------- 1 | from .fpn import FPN 2 | from .fpn_panet import PAFPN 3 | from .bfp import BFP 4 | from .hrfpn import HRFPN 5 | from .nas_fpn import NASFPN 6 | from .search_pafpn import SearchPAFPN 7 | 8 | __all__ = ['FPN', 'BFP', 'HRFPN', 'NASFPN', 9 | 'PAFPN', 'SearchPAFPN'] 10 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/necks/auto_neck/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/models/necks/auto_neck/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/necks/auto_neck/build_neck.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # Copyright (c) 2019 Jianyuan Guo (guojianyuan1@huawei.com) 3 | # -------------------------------------------------------- 4 | 5 | # from .darts_neck_search import DartsNeck 6 | from .hit_neck_search import HitNeck 7 | 8 | 9 | def build_search_neck(cfg): 10 | """Build neck model from config dict. 11 | """ 12 | if cfg is not None: 13 | cfg_ = cfg.copy() 14 | neck_type = cfg_.pop('type') 15 | if neck_type == 'DARTS': 16 | raise NotImplementedError 17 | # return DartsNeck(**cfg_) 18 | elif neck_type == 'HitDet': 19 | return HitNeck(**cfg_) 20 | else: 21 | raise KeyError('Invalid neck type {}'.fromat(neck_type)) 22 | else: 23 | return None -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/plugins/__init__.py: -------------------------------------------------------------------------------- 1 | from .non_local import NonLocal2D 2 | from .generalized_attention import GeneralizedAttention 3 | 4 | __all__ = ['NonLocal2D', 'GeneralizedAttention'] 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/registry.py: -------------------------------------------------------------------------------- 1 | from mmdet.utils import Registry 2 | 3 | BACKBONES = Registry('backbone') 4 | NECKS = Registry('neck') 5 | ROI_EXTRACTORS = Registry('roi_extractor') 6 | SHARED_HEADS = Registry('shared_head') 7 | HEADS = Registry('head') 8 | LOSSES = Registry('loss') 9 | DETECTORS = Registry('detector') -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/roi_extractors/__init__.py: -------------------------------------------------------------------------------- 1 | from .single_level import SingleRoIExtractor 2 | 3 | __all__ = ['SingleRoIExtractor'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/shared_heads/__init__.py: -------------------------------------------------------------------------------- 1 | from .res_layer import ResLayer 2 | 3 | __all__ = ['ResLayer'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .conv_ws import conv_ws_2d, ConvWS2d 2 | from .conv_module import build_conv_layer, ConvModule 3 | from .norm import build_norm_layer 4 | from .scale import Scale 5 | from .weight_init import (xavier_init, normal_init, uniform_init, kaiming_init, 6 | bias_init_with_prob) 7 | 8 | __all__ = [ 9 | 'conv_ws_2d', 'ConvWS2d', 'build_conv_layer', 'ConvModule', 10 | 'build_norm_layer', 'xavier_init', 'normal_init', 'uniform_init', 11 | 'kaiming_init', 'bias_init_with_prob', 'Scale' 12 | ] 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/models/utils/scale.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class Scale(nn.Module): 6 | 7 | def __init__(self, scale=1.0): 8 | super(Scale, self).__init__() 9 | self.scale = nn.Parameter(torch.tensor(scale, dtype=torch.float)) 10 | 11 | def forward(self, x): 12 | return x * self.scale 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/__init__.py: -------------------------------------------------------------------------------- 1 | from .dcn import (DeformConv, DeformConvPack, ModulatedDeformConv, 2 | ModulatedDeformConvPack, DeformRoIPooling, 3 | DeformRoIPoolingPack, ModulatedDeformRoIPoolingPack, 4 | deform_conv, modulated_deform_conv, deform_roi_pooling) 5 | from .gcb import ContextBlock 6 | from .nms import nms, soft_nms 7 | from .roi_align import RoIAlign, roi_align 8 | from .roi_pool import RoIPool, roi_pool 9 | from .sigmoid_focal_loss import SigmoidFocalLoss, sigmoid_focal_loss 10 | from .masked_conv import MaskedConv2d 11 | 12 | __all__ = [ 13 | 'nms', 'soft_nms', 'RoIAlign', 'roi_align', 'RoIPool', 'roi_pool', 14 | 'DeformConv', 'DeformConvPack', 'DeformRoIPooling', 'DeformRoIPoolingPack', 15 | 'ModulatedDeformRoIPoolingPack', 'ModulatedDeformConv', 16 | 'ModulatedDeformConvPack', 'deform_conv', 'modulated_deform_conv', 17 | 'deform_roi_pooling', 'SigmoidFocalLoss', 'sigmoid_focal_loss', 18 | 'MaskedConv2d', 'ContextBlock' 19 | ] 20 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/dcn/__init__.py: -------------------------------------------------------------------------------- 1 | from .functions.deform_conv import deform_conv, modulated_deform_conv 2 | from .functions.deform_pool import deform_roi_pooling 3 | from .modules.deform_conv import (DeformConv, ModulatedDeformConv, 4 | DeformConvPack, ModulatedDeformConvPack) 5 | from .modules.deform_pool import (DeformRoIPooling, DeformRoIPoolingPack, 6 | ModulatedDeformRoIPoolingPack) 7 | 8 | __all__ = [ 9 | 'DeformConv', 'DeformConvPack', 'ModulatedDeformConv', 10 | 'ModulatedDeformConvPack', 'DeformRoIPooling', 'DeformRoIPoolingPack', 11 | 'ModulatedDeformRoIPoolingPack', 'deform_conv', 'modulated_deform_conv', 12 | 'deform_roi_pooling' 13 | ] 14 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/dcn/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/dcn/functions/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/dcn/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/dcn/modules/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/dcn/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from torch.utils.cpp_extension import BuildExtension, CUDAExtension 3 | 4 | setup( 5 | name='deform_conv', 6 | ext_modules=[ 7 | CUDAExtension('deform_conv_cuda', [ 8 | 'src/deform_conv_cuda.cpp', 9 | 'src/deform_conv_cuda_kernel.cu', 10 | ]), 11 | CUDAExtension( 12 | 'deform_pool_cuda', 13 | ['src/deform_pool_cuda.cpp', 'src/deform_pool_cuda_kernel.cu']), 14 | ], 15 | cmdclass={'build_ext': BuildExtension}) 16 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/gcb/__init__.py: -------------------------------------------------------------------------------- 1 | from .context_block import ContextBlock 2 | 3 | __all__ = [ 4 | 'ContextBlock', 5 | ] 6 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/masked_conv/__init__.py: -------------------------------------------------------------------------------- 1 | from .functions.masked_conv import masked_conv2d 2 | from .modules.masked_conv import MaskedConv2d 3 | 4 | __all__ = ['masked_conv2d', 'MaskedConv2d'] 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/masked_conv/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/masked_conv/functions/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/masked_conv/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/masked_conv/modules/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/masked_conv/modules/masked_conv.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | from ..functions.masked_conv import masked_conv2d 3 | 4 | 5 | class MaskedConv2d(nn.Conv2d): 6 | """A MaskedConv2d which inherits the official Conv2d. 7 | 8 | The masked forward doesn't implement the backward function and only 9 | supports the stride parameter to be 1 currently. 10 | """ 11 | 12 | def __init__(self, 13 | in_channels, 14 | out_channels, 15 | kernel_size, 16 | stride=1, 17 | padding=0, 18 | dilation=1, 19 | groups=1, 20 | bias=True): 21 | super(MaskedConv2d, 22 | self).__init__(in_channels, out_channels, kernel_size, stride, 23 | padding, dilation, groups, bias) 24 | 25 | def forward(self, input, mask=None): 26 | if mask is None: # fallback to the normal Conv2d 27 | return super(MaskedConv2d, self).forward(input) 28 | else: 29 | return masked_conv2d(input, mask, self.weight, self.bias, 30 | self.padding) 31 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/masked_conv/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from torch.utils.cpp_extension import BuildExtension, CUDAExtension 3 | 4 | setup( 5 | name='masked_conv2d_cuda', 6 | ext_modules=[ 7 | CUDAExtension('masked_conv2d_cuda', [ 8 | 'src/masked_conv2d_cuda.cpp', 9 | 'src/masked_conv2d_kernel.cu', 10 | ]), 11 | ], 12 | cmdclass={'build_ext': BuildExtension}) 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/nms/__init__.py: -------------------------------------------------------------------------------- 1 | from .nms_wrapper import nms, soft_nms 2 | 3 | __all__ = ['nms', 'soft_nms'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/nms/src/nms_cuda.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #include 3 | 4 | #define CHECK_CUDA(x) TORCH_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ") 5 | 6 | at::Tensor nms_cuda(const at::Tensor boxes, float nms_overlap_thresh); 7 | 8 | at::Tensor nms(const at::Tensor& dets, const float threshold) { 9 | CHECK_CUDA(dets); 10 | if (dets.numel() == 0) 11 | return at::empty({0}, dets.options().dtype(at::kLong).device(at::kCPU)); 12 | return nms_cuda(dets, threshold); 13 | } 14 | 15 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 16 | m.def("nms", &nms, "non-maximum suppression"); 17 | } 18 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_align/__init__.py: -------------------------------------------------------------------------------- 1 | from .roi_align import RoIAlign, roi_align 2 | 3 | __all__ = ['roi_align', 'RoIAlign'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_align/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/roi_align/functions/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_align/gradcheck.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import sys 3 | 4 | import numpy as np 5 | import torch 6 | from torch.autograd import gradcheck 7 | 8 | sys.path.append(osp.abspath(osp.join(__file__, '../../'))) 9 | from roi_align import RoIAlign # noqa: E402, isort:skip 10 | 11 | feat_size = 15 12 | spatial_scale = 1.0 / 8 13 | img_size = feat_size / spatial_scale 14 | num_imgs = 2 15 | num_rois = 20 16 | 17 | batch_ind = np.random.randint(num_imgs, size=(num_rois, 1)) 18 | rois = np.random.rand(num_rois, 4) * img_size * 0.5 19 | rois[:, 2:] += img_size * 0.5 20 | rois = np.hstack((batch_ind, rois)) 21 | 22 | feat = torch.randn( 23 | num_imgs, 16, feat_size, feat_size, requires_grad=True, device='cuda:0') 24 | rois = torch.from_numpy(rois).float().cuda() 25 | inputs = (feat, rois) 26 | print('Gradcheck for roi align...') 27 | test = gradcheck(RoIAlign(3, spatial_scale), inputs, atol=1e-3, eps=1e-3) 28 | print(test) 29 | test = gradcheck(RoIAlign(3, spatial_scale, 2), inputs, atol=1e-3, eps=1e-3) 30 | print(test) 31 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_align/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/roi_align/modules/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_align/modules/roi_align.py: -------------------------------------------------------------------------------- 1 | from torch.nn.modules.module import Module 2 | from ..functions.roi_align import RoIAlignFunction 3 | 4 | 5 | class RoIAlign(Module): 6 | 7 | def __init__(self, out_size, spatial_scale, sample_num=0): 8 | super(RoIAlign, self).__init__() 9 | 10 | self.out_size = out_size 11 | self.spatial_scale = float(spatial_scale) 12 | self.sample_num = int(sample_num) 13 | 14 | def forward(self, features, rois): 15 | return RoIAlignFunction.apply(features, rois, self.out_size, 16 | self.spatial_scale, self.sample_num) 17 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_align/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from torch.utils.cpp_extension import BuildExtension, CUDAExtension 3 | 4 | setup( 5 | name='roi_align_cuda', 6 | ext_modules=[ 7 | CUDAExtension('roi_align_cuda', [ 8 | 'src/roi_align_cuda.cpp', 9 | 'src/roi_align_kernel.cu', 10 | ]), 11 | ], 12 | cmdclass={'build_ext': BuildExtension}) 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_pool/__init__.py: -------------------------------------------------------------------------------- 1 | from .functions.roi_pool import roi_pool 2 | from .modules.roi_pool import RoIPool 3 | 4 | __all__ = ['roi_pool', 'RoIPool'] 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_pool/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/roi_pool/functions/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_pool/gradcheck.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.autograd import gradcheck 3 | 4 | import os.path as osp 5 | import sys 6 | sys.path.append(osp.abspath(osp.join(__file__, '../../'))) 7 | from roi_pool import RoIPool # noqa: E402 8 | 9 | feat = torch.randn(4, 16, 15, 15, requires_grad=True).cuda() 10 | rois = torch.Tensor([[0, 0, 0, 50, 50], [0, 10, 30, 43, 55], 11 | [1, 67, 40, 110, 120]]).cuda() 12 | inputs = (feat, rois) 13 | print('Gradcheck for roi pooling...') 14 | test = gradcheck(RoIPool(4, 1.0 / 8), inputs, eps=1e-5, atol=1e-3) 15 | print(test) 16 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_pool/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/roi_pool/modules/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_pool/modules/roi_pool.py: -------------------------------------------------------------------------------- 1 | from torch.nn.modules.module import Module 2 | from ..functions.roi_pool import roi_pool 3 | 4 | 5 | class RoIPool(Module): 6 | 7 | def __init__(self, out_size, spatial_scale): 8 | super(RoIPool, self).__init__() 9 | 10 | self.out_size = out_size 11 | self.spatial_scale = float(spatial_scale) 12 | 13 | def forward(self, features, rois): 14 | return roi_pool(features, rois, self.out_size, self.spatial_scale) 15 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/roi_pool/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from torch.utils.cpp_extension import BuildExtension, CUDAExtension 3 | 4 | setup( 5 | name='roi_pool', 6 | ext_modules=[ 7 | CUDAExtension('roi_pool_cuda', [ 8 | 'src/roi_pool_cuda.cpp', 9 | 'src/roi_pool_kernel.cu', 10 | ]) 11 | ], 12 | cmdclass={'build_ext': BuildExtension}) 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/sigmoid_focal_loss/__init__.py: -------------------------------------------------------------------------------- 1 | from .modules.sigmoid_focal_loss import SigmoidFocalLoss, sigmoid_focal_loss 2 | 3 | __all__ = ['SigmoidFocalLoss', 'sigmoid_focal_loss'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/sigmoid_focal_loss/functions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/sigmoid_focal_loss/functions/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/sigmoid_focal_loss/functions/sigmoid_focal_loss.py: -------------------------------------------------------------------------------- 1 | from torch.autograd import Function 2 | from torch.autograd.function import once_differentiable 3 | 4 | from .. import sigmoid_focal_loss_cuda 5 | 6 | 7 | class SigmoidFocalLossFunction(Function): 8 | 9 | @staticmethod 10 | def forward(ctx, input, target, gamma=2.0, alpha=0.25): 11 | ctx.save_for_backward(input, target) 12 | num_classes = input.shape[1] 13 | ctx.num_classes = num_classes 14 | ctx.gamma = gamma 15 | ctx.alpha = alpha 16 | 17 | loss = sigmoid_focal_loss_cuda.forward(input, target, num_classes, 18 | gamma, alpha) 19 | return loss 20 | 21 | @staticmethod 22 | @once_differentiable 23 | def backward(ctx, d_loss): 24 | input, target = ctx.saved_tensors 25 | num_classes = ctx.num_classes 26 | gamma = ctx.gamma 27 | alpha = ctx.alpha 28 | d_loss = d_loss.contiguous() 29 | d_input = sigmoid_focal_loss_cuda.backward(input, target, d_loss, 30 | num_classes, gamma, alpha) 31 | return d_input, None, None, None, None 32 | 33 | 34 | sigmoid_focal_loss = SigmoidFocalLossFunction.apply 35 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/sigmoid_focal_loss/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_detection/mmdet/ops/sigmoid_focal_loss/modules/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/sigmoid_focal_loss/modules/sigmoid_focal_loss.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | 3 | from ..functions.sigmoid_focal_loss import sigmoid_focal_loss 4 | 5 | 6 | # TODO: remove this module 7 | class SigmoidFocalLoss(nn.Module): 8 | 9 | def __init__(self, gamma, alpha): 10 | super(SigmoidFocalLoss, self).__init__() 11 | self.gamma = gamma 12 | self.alpha = alpha 13 | 14 | def forward(self, logits, targets): 15 | assert logits.is_cuda 16 | loss = sigmoid_focal_loss(logits, targets, self.gamma, self.alpha) 17 | return loss.sum() 18 | 19 | def __repr__(self): 20 | tmpstr = self.__class__.__name__ + "(" 21 | tmpstr += "gamma=" + str(self.gamma) 22 | tmpstr += ", alpha=" + str(self.alpha) 23 | tmpstr += ")" 24 | return tmpstr 25 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/ops/sigmoid_focal_loss/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from torch.utils.cpp_extension import BuildExtension, CUDAExtension 3 | 4 | setup( 5 | name='SigmoidFocalLoss', 6 | ext_modules=[ 7 | CUDAExtension('sigmoid_focal_loss_cuda', [ 8 | 'src/sigmoid_focal_loss.cpp', 9 | 'src/sigmoid_focal_loss_cuda.cu', 10 | ]), 11 | ], 12 | cmdclass={'build_ext': BuildExtension}) 13 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .collect_env import collect_env 2 | from .flops_counter import get_model_complexity_info 3 | from .logger import get_root_logger, print_log 4 | from .registry import Registry, build_from_cfg 5 | 6 | 7 | __all__ = [ 8 | 'Registry', 'build_from_cfg', 'get_model_complexity_info', 9 | 'get_root_logger', 'print_log', 'collect_env' 10 | ] -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/mmdet/version.py: -------------------------------------------------------------------------------- 1 | # GENERATED VERSION FILE 2 | # TIME: Fri Oct 15 17:01:16 2021 3 | 4 | __version__ = '0.6.0+0889383' 5 | short_version = '0.6.0' 6 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/tools/coco_eval.py: -------------------------------------------------------------------------------- 1 | from argparse import ArgumentParser 2 | 3 | from mmdet.core import coco_eval 4 | 5 | 6 | def main(): 7 | parser = ArgumentParser(description='COCO Evaluation') 8 | parser.add_argument('result', help='result file path') 9 | parser.add_argument('--ann', help='annotation file path') 10 | parser.add_argument( 11 | '--types', 12 | type=str, 13 | nargs='+', 14 | choices=['proposal_fast', 'proposal', 'bbox', 'segm', 'keypoint'], 15 | default=['bbox'], 16 | help='result types') 17 | parser.add_argument( 18 | '--max-dets', 19 | type=int, 20 | nargs='+', 21 | default=[100, 300, 1000], 22 | help='proposal numbers, only used for recall evaluation') 23 | args = parser.parse_args() 24 | coco_eval(args.result, args.types, args.ann, args.max_dets) 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_detection/tools/publish_model.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import subprocess 3 | import torch 4 | 5 | 6 | def parse_args(): 7 | parser = argparse.ArgumentParser( 8 | description='Process a checkpoint to be published') 9 | parser.add_argument('in_file', help='input checkpoint filename') 10 | parser.add_argument('out_file', help='output checkpoint filename') 11 | args = parser.parse_args() 12 | return args 13 | 14 | 15 | def process_checkpoint(in_file, out_file): 16 | checkpoint = torch.load(in_file, map_location='cpu') 17 | # remove optimizer for smaller file size 18 | if 'optimizer' in checkpoint: 19 | del checkpoint['optimizer'] 20 | # if it is necessary to remove some sensitive data in checkpoint['meta'], 21 | # add the code here. 22 | torch.save(checkpoint, out_file) 23 | sha = subprocess.check_output(['sha256sum', out_file]).decode() 24 | final_file = out_file.rstrip('.pth') + '-{}.pth'.format(sha[:8]) 25 | subprocess.Popen(['mv', out_file, final_file]) 26 | 27 | 28 | def main(): 29 | args = parse_args() 30 | process_checkpoint(args.in_file, args.out_file) 31 | 32 | 33 | if __name__ == '__main__': 34 | main() 35 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Wuyang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/configs/ade/cydas.yaml: -------------------------------------------------------------------------------- 1 | json_file: "jsons/big4.json" 2 | data_path: "../DATASET/ADEChallengeData2016/" 3 | dataset: "coco" 4 | det2_cfg: "configs/ADE20K/base.yaml" 5 | num_classes: 150 6 | max_iteration: 160000 7 | seed: 12345 8 | random_sample: False 9 | eval_flag: True 10 | opt: "sgd" 11 | opt_eps: 0.001 12 | sched: "new" #"raw for original" 13 | epochs: 1000 14 | drop_path_prob: 0.2 15 | image_height: 640 16 | image_width: 640 17 | eval_height: 640 18 | eval_width: 640 19 | crop_size: 640 20 | batch_size: 4 21 | mode: "poly" 22 | base_lr: 0.05 23 | Fch: 16 24 | bn_momentum: 0.01 25 | warmup_start_lr: 5e-6 26 | warmup_iters: 1000 27 | weight_decay: 1e-4 28 | model_ema: True 29 | model_ema_decay: 0.9998 30 | clip_grad: 1.0 31 | lamb: 0.2 32 | ignore: 255 33 | topk_percent: 0.2 34 | semantic_loss_weight: 1.0 35 | center_loss_weight: 200 36 | offset_loss_weight: 0.01 37 | eval_flip: False 38 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/configs/cityscapes/cydas.yaml: -------------------------------------------------------------------------------- 1 | data_path: "../DATASET/cityscapes/" 2 | det2_cfg: "configs/Cityscapes-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024.yaml" 3 | seed: 12345 4 | random_sample: False 5 | opt: "sgd" 6 | opt_eps: 0.001 7 | sched: "new" #"raw for original" 8 | epochs: 4000 9 | drop_path_prob: 0.2 10 | image_height: 512 11 | image_width: 1024 12 | eval_height: 1024 13 | eval_width: 2048 14 | batch_size: 4 15 | mode: "poly" 16 | base_lr: 0.05 17 | workers: 4 18 | Fch: 6 19 | warmup_start_lr: 5e-6 20 | warmup_iters: 1000 21 | weight_decay: 1e-4 22 | model_ema: True 23 | model_ema_decay: 0.9998 24 | stem_head_width: 1.0 25 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/dataloaders/datasets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_segmentation/dataloaders/datasets/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/dataloaders/segdatasets/__init__.py: -------------------------------------------------------------------------------- 1 | from .base_dataset import BaseDataset 2 | from .cityscapes import Cityscapes 3 | from .cityscapes_panoptic import CityscapesPanoptic 4 | from .coco_panoptic import COCOPanoptic 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/dataloaders/segdatasets/utils.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Reference: https://github.com/tensorflow/models/blob/master/research/deeplab/datasets/data_generator.py 3 | # ------------------------------------------------------------------------------ 4 | 5 | import collections 6 | 7 | # Named tuple to describe the dataset properties. 8 | DatasetDescriptor = collections.namedtuple( 9 | 'DatasetDescriptor', 10 | [ 11 | 'splits_to_sizes', # Splits of the dataset into training, val and test. 12 | 'num_classes', # Number of semantic classes, including the 13 | # background class (if exists). For example, there 14 | # are 20 foreground classes + 1 background class in 15 | # the PASCAL VOC 2012 dataset. Thus, we set 16 | # num_classes=21. 17 | 'ignore_label', # Ignore label value. 18 | ]) 19 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/dataloaders/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_transforms 2 | from .pre_augmentation_transforms import Resize 3 | from .target_transforms import PanopticTargetGenerator, SemanticTargetGenerator 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_segmentation/segmentation/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/config/__init__.py: -------------------------------------------------------------------------------- 1 | from .default import _C as config 2 | from .default import update_config 3 | seg_config = config 4 | update_seg_config = update_config -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import ( 2 | build_dataset_from_cfg, build_train_loader_from_cfg, build_test_loader_from_cfg) 3 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | from .base_dataset import BaseDataset 2 | from .cityscapes import Cityscapes 3 | from .cityscapes_panoptic import CityscapesPanoptic 4 | from .coco_panoptic import COCOPanoptic 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/data/datasets/utils.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Reference: https://github.com/tensorflow/models/blob/master/research/deeplab/datasets/data_generator.py 3 | # ------------------------------------------------------------------------------ 4 | 5 | import collections 6 | 7 | # Named tuple to describe the dataset properties. 8 | DatasetDescriptor = collections.namedtuple( 9 | 'DatasetDescriptor', 10 | [ 11 | 'splits_to_sizes', # Splits of the dataset into training, val and test. 12 | 'num_classes', # Number of semantic classes, including the 13 | # background class (if exists). For example, there 14 | # are 20 foreground classes + 1 background class in 15 | # the PASCAL VOC 2012 dataset. Thus, we set 16 | # num_classes=21. 17 | 'ignore_label', # Ignore label value. 18 | ]) 19 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/data/samplers/__init__.py: -------------------------------------------------------------------------------- 1 | from .distributed_sampler import TrainingSampler, InferenceSampler 2 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/data/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_transforms 2 | from .pre_augmentation_transforms import Resize 3 | from .target_transforms import PanopticTargetGenerator, SemanticTargetGenerator 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | from .semantic import SemanticEvaluator 2 | from .instance import CityscapesInstanceEvaluator 3 | from .panoptic import CityscapesPanopticEvaluator 4 | from .coco_instance import COCOInstanceEvaluator 5 | from .coco_panoptic import COCOPanopticEvaluator 6 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/model/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_segmentation_model_from_cfg 2 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/model/backbone/__init__.py: -------------------------------------------------------------------------------- 1 | from .resnet import * 2 | from .mobilenet import * 3 | from .mnasnet import * 4 | from .hrnet import * 5 | from .xception import * 6 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/model/decoder/__init__.py: -------------------------------------------------------------------------------- 1 | from .aspp import ASPP 2 | from .deeplabv3 import DeepLabV3Decoder 3 | from .deeplabv3plus import DeepLabV3PlusDecoder 4 | from .panoptic_deeplab import PanopticDeepLabDecoder 5 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/model/loss/__init__.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | 3 | from .criterion import RegularCE, OhemCE, DeepLabCE 4 | 5 | L1Loss = nn.L1Loss 6 | MSELoss = nn.MSELoss 7 | CrossEntropyLoss = nn.CrossEntropyLoss 8 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/model/meta_arch/__init__.py: -------------------------------------------------------------------------------- 1 | from .deeplabv3 import DeepLabV3 2 | from .deeplabv3plus import DeepLabV3Plus 3 | from .panoptic_deeplab import PanopticDeepLab 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/model/post_processing/__init__.py: -------------------------------------------------------------------------------- 1 | from .semantic_post_processing import get_semantic_segmentation 2 | from .instance_post_processing import get_panoptic_segmentation 3 | from .evaluation_format import get_cityscapes_instance_format 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/model/post_processing/semantic_post_processing.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Post-processing to get semantic segmentation results. 3 | # Written by Bowen Cheng (bcheng9@illinois.edu) 4 | # ------------------------------------------------------------------------------ 5 | 6 | import torch 7 | 8 | __all__ = ['get_semantic_segmentation'] 9 | 10 | 11 | def get_semantic_segmentation(sem): 12 | """ 13 | Post-processing for semantic segmentation branch. 14 | Arguments: 15 | sem: A Tensor of shape [N, C, H, W], where N is the batch size, for consistent, we only 16 | support N=1. 17 | Returns: 18 | A Tensor of shape [1, H, W] (to be gathered by distributed data parallel). 19 | Raises: 20 | ValueError, if batch size is not 1. 21 | """ 22 | if sem.size(0) != 1: 23 | raise ValueError('Only supports inference for batch size = 1') 24 | sem = sem.squeeze(0) 25 | return torch.argmax(sem, dim=0, keepdim=True) 26 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/solver/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_optimizer, build_lr_scheduler 2 | from .lr_scheduler import WarmupMultiStepLR, WarmupCosineLR, WarmupPolyLR 3 | from .utils import get_lr_group_id 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/solver/utils.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Reference: https://github.com/facebookresearch/detectron2/blob/master/detectron2/engine/hooks.py#L195 3 | # Modified by Bowen Cheng (bcheng9@illinois.edu) 4 | # ------------------------------------------------------------------------------ 5 | 6 | from collections import Counter 7 | 8 | 9 | def get_lr_group_id(optimizer): 10 | """ 11 | Returns the group id with majority of lr. 12 | """ 13 | # Get the correct parameter group id to access to lr info. 14 | largest_group = max(len(g["params"]) for g in optimizer.param_groups) 15 | if largest_group == 1: 16 | # If all groups have one parameter, 17 | # then find the most common initial LR, and use it for summary 18 | lr_count = Counter([g["lr"] for g in optimizer.param_groups]) 19 | lr = lr_count.most_common()[0][0] 20 | for i, g in enumerate(optimizer.param_groups): 21 | if g["lr"] == lr: 22 | best_param_group_id = i 23 | break 24 | else: 25 | for i, g in enumerate(optimizer.param_groups): 26 | if len(g["params"]) == largest_group: 27 | best_param_group_id = i 28 | break 29 | return best_param_group_id 30 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .save_annotation import ( 2 | save_annotation, save_instance_annotation, save_panoptic_annotation, save_center_image, save_heatmap_image, 3 | save_heatmap_and_center_image, save_offset_image) 4 | from .flow_vis import flow_compute_color 5 | from .utils import AverageMeter 6 | from .debug import save_debug_images 7 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/segmentation/utils/env.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Reference: https://github.com/facebookresearch/detectron2/blob/master/detectron2/utils/env.py#L15 3 | # Modified by Bowen Cheng (bcheng9@illinois.edu) 4 | # ------------------------------------------------------------------------------ 5 | 6 | import importlib 7 | import importlib.util 8 | import logging 9 | import numpy as np 10 | import os 11 | import random 12 | import sys 13 | from datetime import datetime 14 | import torch 15 | 16 | __all__ = ["seed_all_rng"] 17 | 18 | 19 | def seed_all_rng(seed=None): 20 | """ 21 | Set the random seed for the RNG in torch, numpy and python. 22 | Args: 23 | seed (int): if None, will use a strong random seed. 24 | """ 25 | if seed is None: 26 | seed = ( 27 | os.getpid() 28 | + int(datetime.now().strftime("%S%f")) 29 | + int.from_bytes(os.urandom(2), "big") 30 | ) 31 | logger = logging.getLogger(__name__) 32 | logger.info("Using a generated random seed {}".format(seed)) 33 | np.random.seed(seed) 34 | torch.set_rng_state(torch.manual_seed(seed).get_state()) 35 | random.seed(seed) 36 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_segmentation/tools/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | from .cityscapes import Cityscapes 2 | from .bdd import BDD 3 | from .coco import COCO 4 | from .camvid import CamVid 5 | 6 | __all__ = ['Cityscapes', 'BDD', 'CamVid', 'COCO'] 7 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/datasets/bdd/__init__.py: -------------------------------------------------------------------------------- 1 | from .bdd import BDD 2 | 3 | __all__ = ['BDD'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/datasets/camvid/__init__.py: -------------------------------------------------------------------------------- 1 | from .camvid import CamVid 2 | 3 | __all__ = ['CamVid'] -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/datasets/camvid/camvid.py: -------------------------------------------------------------------------------- 1 | from datasets.BaseDataset import BaseDataset 2 | 3 | 4 | class CamVid(BaseDataset): 5 | @classmethod 6 | def get_class_colors(*args): 7 | return [[128, 0, 0], [128, 128, 0], [128, 128, 128], [64, 0, 128], 8 | [192, 128, 128], [128, 64, 128], [64, 64, 0], [64, 64, 128], 9 | [192, 192, 128], [0, 0, 192], [0, 128, 192]] 10 | 11 | @classmethod 12 | def get_class_names(*args): 13 | # class counting(gtFine) 14 | # 2953 2811 2934 970 1296 2949 1658 2808 2891 1654 2686 2343 1023 2832 15 | # 359 274 142 513 1646 16 | return ['Building', 'Tree', 'Sky', 'Car', 'Sign-Symbol', 'Road', 17 | 'Pedestrian', 'Fence', 'Column-Pole', 'Side-Walk', 'Bicyclist', 'Void'] 18 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/datasets/cityscapes/__init__.py: -------------------------------------------------------------------------------- 1 | from .cityscapes import Cityscapes 2 | 3 | __all__ = ['Cityscapes'] -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/datasets/coco/__init__.py: -------------------------------------------------------------------------------- 1 | from .coco import COCO 2 | 3 | __all__ = ['COCO'] 4 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/engine/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_segmentation/tools/engine/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/seg_opr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_segmentation/tools/seg_opr/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/tools/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_segmentation/tools/utils/__init__.py -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/train/_init_paths.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # Adds `segmentation` package into Python path. 3 | # Written by Bowen Cheng (bcheng9@illinois.edu) 4 | # ------------------------------------------------------------------------------ 5 | 6 | import os.path as osp 7 | import sys 8 | 9 | 10 | def add_path(path): 11 | if path not in sys.path: 12 | sys.path.insert(0, path) 13 | 14 | 15 | this_dir = osp.dirname(__file__) 16 | lib_path = osp.join(this_dir, '..') 17 | add_path(lib_path) 18 | add_path(this_dir) 19 | add_path(osp.join(lib_path, 'tools')) 20 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/train/configs/ADE20K/512.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: ../Cityscapes-PanopticSegmentation/Base-PanopticDeepLab-OS16.yaml 2 | MODEL: 3 | WEIGHTS: "detectron2://DeepLab/R-52.pkl" 4 | PIXEL_MEAN: [123.675, 116.280, 103.530] 5 | PIXEL_STD: [58.395, 57.120, 57.375] 6 | BACKBONE: 7 | NAME: "build_resnet_deeplab_backbone" 8 | RESNETS: 9 | DEPTH: 50 10 | NORM: "SyncBN" 11 | RES5_MULTI_GRID: [1, 2, 4] 12 | STEM_TYPE: "deeplab" 13 | STEM_OUT_CHANNELS: 128 14 | STRIDE_IN_1X1: False 15 | SEM_SEG_HEAD: 16 | NUM_CLASSES: 133 17 | LOSS_TOP_K: 1.0 18 | USE_DEPTHWISE_SEPARABLE_CONV: True 19 | PANOPTIC_DEEPLAB: 20 | STUFF_AREA: 4096 21 | NMS_KERNEL: 41 22 | SIZE_DIVISIBILITY: 640 23 | USE_DEPTHWISE_SEPARABLE_CONV: True 24 | DATASETS: 25 | TRAIN: ("ade20k_sem_seg_train",) 26 | TEST: ("ade20k_sem_seg_val",) 27 | SOLVER: 28 | BASE_LR: 0.0005 29 | MAX_ITER: 200000000 30 | IMS_PER_BATCH: 32 31 | INPUT: 32 | FORMAT: "RGB" 33 | GAUSSIAN_SIGMA: 8 34 | MIN_SIZE_TRAIN: (256, 320, 352, 416, 448, 512, 576, 608, 672, 704, 768, 832, 864, 928, 960, 1024) 35 | MIN_SIZE_TRAIN_SAMPLING: "choice" 36 | MIN_SIZE_TEST: 512 37 | MAX_SIZE_TRAIN: 1024 38 | MAX_SIZE_TEST: 512 39 | CROP: 40 | ENABLED: True 41 | TYPE: "absolute" 42 | SIZE: (512, 512) 43 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/train/configs/ADE20K/base.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: ../Cityscapes-PanopticSegmentation/Base-PanopticDeepLab-OS16.yaml 2 | MODEL: 3 | WEIGHTS: "detectron2://DeepLab/R-52.pkl" 4 | PIXEL_MEAN: [123.675, 116.280, 103.530] 5 | PIXEL_STD: [58.395, 57.120, 57.375] 6 | BACKBONE: 7 | NAME: "build_resnet_deeplab_backbone" 8 | RESNETS: 9 | DEPTH: 50 10 | NORM: "SyncBN" 11 | RES5_MULTI_GRID: [1, 2, 4] 12 | STEM_TYPE: "deeplab" 13 | STEM_OUT_CHANNELS: 128 14 | STRIDE_IN_1X1: False 15 | SEM_SEG_HEAD: 16 | NUM_CLASSES: 133 17 | LOSS_TOP_K: 1.0 18 | USE_DEPTHWISE_SEPARABLE_CONV: True 19 | PANOPTIC_DEEPLAB: 20 | STUFF_AREA: 4096 21 | NMS_KERNEL: 41 22 | SIZE_DIVISIBILITY: 640 23 | USE_DEPTHWISE_SEPARABLE_CONV: True 24 | DATASETS: 25 | TRAIN: ("ade20k_sem_seg_train",) 26 | TEST: ("ade20k_sem_seg_val",) 27 | SOLVER: 28 | BASE_LR: 0.0005 29 | MAX_ITER: 200000000 30 | IMS_PER_BATCH: 32 31 | INPUT: 32 | FORMAT: "RGB" 33 | GAUSSIAN_SIGMA: 8 34 | MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 640) for x in range(5, 16)]"] 35 | MIN_SIZE_TRAIN_SAMPLING: "choice" 36 | MIN_SIZE_TEST: 640 37 | MAX_SIZE_TRAIN: 960 38 | MAX_SIZE_TEST: 640 39 | CROP: 40 | ENABLED: True 41 | TYPE: "absolute" 42 | SIZE: (640, 640) 43 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/train/configs/Cityscapes-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: Base-PanopticDeepLab-OS16.yaml 2 | MODEL: 3 | WEIGHTS: "detectron2://DeepLab/R-52.pkl" 4 | PIXEL_MEAN: [123.675, 116.280, 103.530] 5 | PIXEL_STD: [58.395, 57.120, 57.375] 6 | BACKBONE: 7 | NAME: "build_resnet_deeplab_backbone" 8 | RESNETS: 9 | DEPTH: 50 10 | NORM: "SyncBN" 11 | RES5_MULTI_GRID: [1, 2, 4] 12 | STEM_TYPE: "deeplab" 13 | STEM_OUT_CHANNELS: 128 14 | STRIDE_IN_1X1: False 15 | SOLVER: 16 | MAX_ITER: 90000 17 | INPUT: 18 | FORMAT: "RGB" 19 | CROP: 20 | SIZE: (512, 1024) 21 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/train/configs/Cityscapes-PanopticSegmentation/panoptic_deeplab_R_52_os16_mg124_poly_90k_bs32_crop_512_1024_dsconv.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: Base-PanopticDeepLab-OS16.yaml 2 | MODEL: 3 | WEIGHTS: "detectron2://DeepLab/R-52.pkl" 4 | PIXEL_MEAN: [123.675, 116.280, 103.530] 5 | PIXEL_STD: [58.395, 57.120, 57.375] 6 | BACKBONE: 7 | NAME: "build_resnet_deeplab_backbone" 8 | RESNETS: 9 | DEPTH: 50 10 | NORM: "SyncBN" 11 | RES5_MULTI_GRID: [1, 2, 4] 12 | STEM_TYPE: "deeplab" 13 | STEM_OUT_CHANNELS: 128 14 | STRIDE_IN_1X1: False 15 | PANOPTIC_DEEPLAB: 16 | USE_DEPTHWISE_SEPARABLE_CONV: True 17 | SEM_SEG_HEAD: 18 | USE_DEPTHWISE_SEPARABLE_CONV: True 19 | SOLVER: 20 | MAX_ITER: 90000 21 | INPUT: 22 | FORMAT: "RGB" 23 | CROP: 24 | SIZE: (512, 1024) 25 | -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/train/genotypes.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | Genotype = namedtuple('Genotype', 'normal normal_concat reduce reduce_concat') 4 | 5 | PRIMITIVES = [ 6 | 'skip', 7 | 'conv', 8 | 'conv_downup', 9 | 'conv_2x_downup', 10 | 'sa', 11 | ] 12 | 13 | # 'conv_2x', -------------------------------------------------------------------------------- /CDARTS/CDARTS_segmentation/train/latency_lookup_table.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/CDARTS_segmentation/train/latency_lookup_table.npy -------------------------------------------------------------------------------- /CDARTS/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | 23 | 24 | -------------------------------------------------------------------------------- /CDARTS/benchmark201/README.md: -------------------------------------------------------------------------------- 1 | ## NAS-Bench-201 2 | * Main python file is 3 | ```buildoutcfg 4 | ${ROOT}/benchmark201/search.py 5 | ``` 6 | * Here we present our search script on NAS-Bench-201. 7 | ```buildoutcfg 8 | cd benchmark201 9 | bash run_search_cifar_1gpu.sh 10 | ``` 11 | -------------------------------------------------------------------------------- /CDARTS/benchmark201/search/cifar10-search/tb/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/benchmark201/search/cifar10-search/tb/readme.md -------------------------------------------------------------------------------- /CDARTS/benchmark201/search/imagenet-search/imagenet-search.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/benchmark201/search/imagenet-search/imagenet-search.log -------------------------------------------------------------------------------- /CDARTS/benchmark201/search/imagenet-search/tb/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/benchmark201/search/imagenet-search/tb/readme.md -------------------------------------------------------------------------------- /CDARTS/demo/NATS_bench.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/NATS_bench.png -------------------------------------------------------------------------------- /CDARTS/demo/ade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/ade.png -------------------------------------------------------------------------------- /CDARTS/demo/cell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/cell.png -------------------------------------------------------------------------------- /CDARTS/demo/cell_cifar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/cell_cifar.png -------------------------------------------------------------------------------- /CDARTS/demo/cell_imagenet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/cell_imagenet.png -------------------------------------------------------------------------------- /CDARTS/demo/chain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/chain.png -------------------------------------------------------------------------------- /CDARTS/demo/chain_arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/chain_arch.png -------------------------------------------------------------------------------- /CDARTS/demo/city.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/city.png -------------------------------------------------------------------------------- /CDARTS/demo/coco.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/coco.png -------------------------------------------------------------------------------- /CDARTS/demo/framework1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/framework1.png -------------------------------------------------------------------------------- /CDARTS/demo/framework2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/demo/framework2.png -------------------------------------------------------------------------------- /CDARTS/experiments/retrain/cifar10-retrain/cifar10-retrain.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/experiments/retrain/cifar10-retrain/cifar10-retrain.log -------------------------------------------------------------------------------- /CDARTS/experiments/retrain/cifar10-retrain/tb/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/experiments/retrain/cifar10-retrain/tb/readme.md -------------------------------------------------------------------------------- /CDARTS/experiments/retrain/imagenet-retrain/imagenet-retrain.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/experiments/retrain/imagenet-retrain/imagenet-retrain.log -------------------------------------------------------------------------------- /CDARTS/experiments/retrain/imagenet-retrain/tb/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/experiments/retrain/imagenet-retrain/tb/readme.md -------------------------------------------------------------------------------- /CDARTS/experiments/search/cifar10-search/cifar10-search.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/experiments/search/cifar10-search/cifar10-search.log -------------------------------------------------------------------------------- /CDARTS/experiments/search/cifar10-search/tb/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/experiments/search/cifar10-search/tb/readme.md -------------------------------------------------------------------------------- /CDARTS/experiments/search/imagenet-search/imagenet-search.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/experiments/search/imagenet-search/imagenet-search.log -------------------------------------------------------------------------------- /CDARTS/experiments/search/imagenet-search/tb/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/CDARTS/experiments/search/imagenet-search/tb/readme.md -------------------------------------------------------------------------------- /CDARTS/lib/utils/count_flops.py: -------------------------------------------------------------------------------- 1 | """ Search cell """ 2 | import json 3 | import lib.utils.genotypes as gt 4 | 5 | from torchscope import scope 6 | from lib.models.model_test import ModelTest 7 | 8 | # config 9 | stem_multiplier = 1 10 | n_classes = 1000 11 | init_channels = 48 12 | model_type = 'imagenet' 13 | cell_file = './genotypes.json' 14 | 15 | 16 | #stem_multiplier = 3 17 | #n_classes = 10 18 | #init_channels = 36 19 | #model_type = 'cifar' 20 | #cell_file = './genotypes.json' 21 | 22 | def main(): 23 | file = open(cell_file, 'r') 24 | js = file.read() 25 | r_dict = json.loads(js) 26 | 27 | file.close() 28 | genotypes_dict = {} 29 | for layer_idx, genotype in r_dict.items(): 30 | genotypes_dict[int(layer_idx)] = gt.from_str(genotype) 31 | 32 | model_main = ModelTest(genotypes_dict, model_type, res_stem=False, init_channel=init_channels, \ 33 | stem_multiplier=stem_multiplier, n_nodes=4, num_classes=n_classes) 34 | 35 | if 'cifar' in model_type: 36 | input_x = (3, 32, 32) 37 | elif 'imagenet' in model_type: 38 | input_x = (3, 224, 224) 39 | else: 40 | raise Exception("Not support dataset!") 41 | 42 | scope(model_main, input_size=input_x) 43 | 44 | 45 | if __name__ == "__main__": 46 | main() 47 | -------------------------------------------------------------------------------- /CDARTS/requirements: -------------------------------------------------------------------------------- 1 | graphviz 2 | torch==1.2 3 | torchvision==0.2 4 | tensorboard 5 | tensorboardX -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct] (https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /Cream/demo/intro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/Cream/demo/intro.jpg -------------------------------------------------------------------------------- /Cream/demo/results_100.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/Cream/demo/results_100.jpg -------------------------------------------------------------------------------- /Cream/demo/results_600.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/Cream/demo/results_600.jpg -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/114.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '112m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.2 28 | SELECTION: 470 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9999 34 | 35 | 36 | LR: 0.064 37 | EPOCHS: 500 38 | OPT_EPS: 1e-3 39 | SCHED: 'cosine' 40 | OPT: 'rmsproptf' 41 | WARMUP_LR: 1e-6 42 | DECAY_EPOCHS: 2.4 43 | DECAY_RATE: 0.973 44 | WARMUP_EPOCHS: 3 45 | WEIGHT_DECAY: 1e-5 46 | 47 | AUGMENTATION: 48 | AA: 'rand-m9-mstd0.5' 49 | RE_PROB: 0.2 # random erase prob 50 | RE_MODE: 'pixel' # random erase mode 51 | 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/14.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '14m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.2 28 | SELECTION: 14 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9999 34 | 35 | 36 | LR: 0.064 37 | EPOCHS: 500 38 | OPT_EPS: 1e-3 39 | SCHED: 'step' 40 | OPT: 'rmsproptf' 41 | WARMUP_LR: 1e-6 42 | DECAY_EPOCHS: 2.4 43 | DECAY_RATE: 0.973 44 | WARMUP_EPOCHS: 3 45 | WEIGHT_DECAY: 1e-5 46 | 47 | AUGMENTATION: 48 | AA: 'rand-m9-mstd0.5' 49 | RE_PROB: 0.2 # random erase prob 50 | RE_MODE: 'pixel' # random erase mode 51 | 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/23.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '23m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.2 28 | SELECTION: 470 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9999 34 | 35 | 36 | LR: 0.064 37 | EPOCHS: 500 38 | OPT_EPS: 1e-3 39 | SCHED: 'step' 40 | OPT: 'rmsproptf' 41 | WARMUP_LR: 1e-6 42 | DECAY_EPOCHS: 2.4 43 | DECAY_RATE: 0.973 44 | WARMUP_EPOCHS: 3 45 | WEIGHT_DECAY: 1e-5 46 | 47 | AUGMENTATION: 48 | AA: 'rand-m9-mstd0.5' 49 | RE_PROB: 0.2 # random erase prob 50 | RE_MODE: 'pixel' # random erase mode 51 | 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/287.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '287m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.2 28 | SELECTION: 470 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9999 34 | 35 | 36 | LR: 0.064 37 | EPOCHS: 500 38 | OPT_EPS: 1e-3 39 | SCHED: 'cosine' 40 | OPT: 'rmsproptf' 41 | WARMUP_LR: 1e-6 42 | DECAY_EPOCHS: 2.4 43 | DECAY_RATE: 0.973 44 | WARMUP_EPOCHS: 3 45 | WEIGHT_DECAY: 1e-5 46 | 47 | AUGMENTATION: 48 | AA: 'rand-m9-mstd0.5' 49 | RE_PROB: 0.2 # random erase prob 50 | RE_MODE: 'pixel' # random erase mode 51 | 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/43.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '43m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.2 28 | SELECTION: 43 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9999 34 | 35 | 36 | LR: 0.064 37 | EPOCHS: 500 38 | OPT_EPS: 1e-3 39 | SCHED: 'step' 40 | OPT: 'rmsproptf' 41 | WARMUP_LR: 1e-6 42 | DECAY_EPOCHS: 2.4 43 | DECAY_RATE: 0.973 44 | WARMUP_EPOCHS: 3 45 | WEIGHT_DECAY: 1e-5 46 | 47 | AUGMENTATION: 48 | AA: 'rand-m9-mstd0.5' 49 | RE_PROB: 0.2 # random erase prob 50 | RE_MODE: 'pixel' # random erase mode 51 | 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/481.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '481m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.2 28 | SELECTION: 481 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9999 34 | 35 | 36 | LR: 0.064 37 | EPOCHS: 500 38 | OPT_EPS: 1e-3 39 | SCHED: 'cosine' 40 | OPT: 'rmsproptf' 41 | WARMUP_LR: 1e-6 42 | DECAY_EPOCHS: 2.4 43 | DECAY_RATE: 0.973 44 | WARMUP_EPOCHS: 3 45 | WEIGHT_DECAY: 1e-5 46 | 47 | AUGMENTATION: 48 | AA: 'rand-m9-mstd0.5' 49 | RE_PROB: 0.2 # random erase prob 50 | RE_MODE: 'pixel' # random erase mode 51 | 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/604.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '604m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.2 28 | SELECTION: 604 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9999 34 | 35 | 36 | LR: 0.064 37 | EPOCHS: 500 38 | OPT_EPS: 1e-3 39 | SCHED: 'cosine' 40 | OPT: 'rmsproptf' 41 | WARMUP_LR: 1e-6 42 | DECAY_EPOCHS: 2.4 43 | DECAY_RATE: 0.973 44 | WARMUP_EPOCHS: 3 45 | WEIGHT_DECAY: 1e-5 46 | 47 | AUGMENTATION: 48 | AA: 'rand-m9-mstd0.5' 49 | RE_PROB: 0.2 # random erase prob 50 | RE_MODE: 'pixel' # random erase mode 51 | 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/72.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '72m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.2 28 | SELECTION: 470 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9999 34 | 35 | 36 | LR: 0.064 37 | EPOCHS: 500 38 | OPT_EPS: 1e-3 39 | SCHED: 'step' 40 | OPT: 'rmsproptf' 41 | WARMUP_LR: 1e-6 42 | DECAY_EPOCHS: 2.4 43 | DECAY_RATE: 0.973 44 | WARMUP_EPOCHS: 3 45 | WEIGHT_DECAY: 1e-5 46 | 47 | AUGMENTATION: 48 | AA: 'rand-m9-mstd0.5' 49 | RE_PROB: 0.2 # random erase prob 50 | RE_MODE: 'pixel' # random erase mode 51 | 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/retrain/retrain.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: '600m_retrain' 4 | RESUME_PATH: './experiments/workspace/retrain/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/retrain' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 4 10 | NUM_GPU: 2 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'random' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.0 28 | SELECTION: 42 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9998 34 | 35 | OPT: 'rmsproptf' 36 | OPT_EPS: 1e-2 37 | MOMENTUM: 0.9 38 | DECAY_RATE: 0.1 39 | 40 | SCHED: 'sgd' 41 | LR_NOISE_PCT: 0.67 42 | LR_NOISE_STD: 1.0 43 | WARMUP_LR: 1e-4 44 | MIN_LR: 1e-5 45 | EPOCHS: 200 46 | START_EPOCH: None 47 | DECAY_EPOCHS: 30.0 48 | WARMUP_EPOCHS: 3 49 | COOLDOWN_EPOCHS: 10 50 | PATIENCE_EPOCHS: 10 51 | LR: 1e-2 52 | -------------------------------------------------------------------------------- /Cream/experiments/configs/test/test.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: True 2 | DATA_DIR: './data/imagenet' 3 | MODEL: 'Childnet_Testing' 4 | RESUME_PATH: './experiments/workspace/ckps/42.pth.tar' 5 | SAVE_PATH: './experiments/workspace/test' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 4 10 | NUM_GPU: 2 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'bilinear' # Image resize interpolation type 22 | BATCH_SIZE: 32 # batch size 23 | NO_PREFECHTER: False 24 | 25 | NET: 26 | GP: 'avg' 27 | DROPOUT_RATE: 0.0 28 | SELECTION: 42 29 | 30 | EMA: 31 | USE: True 32 | FORCE_CPU: False # force model ema to be tracked on CPU 33 | DECAY: 0.9998 34 | 35 | OPTIMIZER: 36 | MOMENTUM: 0.9 37 | WEIGHT_DECAY: 1e-3 -------------------------------------------------------------------------------- /Cream/experiments/configs/train/train.yaml: -------------------------------------------------------------------------------- 1 | AUTO_RESUME: False 2 | DATA_DIR: './data/imagenet' 3 | MODEL: 'Supernet_Training' 4 | RESUME_PATH: './experiments/workspace/train/resume.pth.tar' 5 | SAVE_PATH: './experiments/workspace/train' 6 | SEED: 42 7 | LOG_INTERVAL: 50 8 | RECOVERY_INTERVAL: 0 9 | WORKERS: 8 10 | NUM_GPU: 8 11 | SAVE_IMAGES: False 12 | AMP: False 13 | OUTPUT: 'None' 14 | EVAL_METRICS: 'prec1' 15 | TTA: 0 16 | LOCAL_RANK: 0 17 | 18 | DATASET: 19 | NUM_CLASSES: 1000 20 | IMAGE_SIZE: 224 # image patch size 21 | INTERPOLATION: 'bilinear' # Image resize interpolation type 22 | BATCH_SIZE: 128 # batch size 23 | 24 | NET: 25 | GP: 'avg' 26 | DROPOUT_RATE: 0.0 27 | 28 | EMA: 29 | USE: True 30 | FORCE_CPU: False # force model ema to be tracked on CPU 31 | DECAY: 0.9998 32 | 33 | OPT: 'sgd' 34 | LR: 1.0 35 | EPOCHS: 120 36 | META_LR: 1e-4 37 | 38 | BATCHNORM: 39 | SYNC_BN: False 40 | 41 | SUPERNET: 42 | UPDATE_ITER: 200 43 | SLICE: 4 44 | POOL_SIZE: 10 45 | RESUNIT: False 46 | DIL_CONV: False 47 | UPDATE_2ND: True 48 | FLOPS_MINIMUM: 0 49 | FLOPS_MAXIMUM: 600 50 | PICK_METHOD: 'meta' 51 | META_STA_EPOCH: 20 52 | HOW_TO_PROB: 'pre_prob' 53 | PRE_PROB: (0.05,0.2,0.05,0.5,0.05,0.15) 54 | -------------------------------------------------------------------------------- /Cream/experiments/workspace/retrain/README.md: -------------------------------------------------------------------------------- 1 | # Retrain Workspace -------------------------------------------------------------------------------- /Cream/experiments/workspace/test/README.md: -------------------------------------------------------------------------------- 1 | # Test Workspace -------------------------------------------------------------------------------- /Cream/experiments/workspace/train/README.md: -------------------------------------------------------------------------------- 1 | # Train Workspace -------------------------------------------------------------------------------- /Cream/lib/models/blocks/__init__.py: -------------------------------------------------------------------------------- 1 | from lib.models.blocks.residual_block import get_Bottleneck, get_BasicBlock 2 | from lib.models.blocks.inverted_residual_block import InvertedResidual -------------------------------------------------------------------------------- /Cream/requirements: -------------------------------------------------------------------------------- 1 | yacs 2 | numpy==1.17 3 | opencv-python==4.0.1.24 4 | torchvision==0.2.1 5 | thop 6 | git+https://github.com/sovrasov/flops-counter.pytorch.git 7 | pillow==6.1.0 8 | torch==1.2 9 | timm==0.1.20 10 | tensorboardx==1.2 11 | tensorboard 12 | future -------------------------------------------------------------------------------- /Cream/tools/_init_paths.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | # Written by Hao Du and Houwen Peng 4 | # email: haodu8-c@my.cityu.edu.hk and houwen.peng@microsoft.com 5 | 6 | # This file is to add current path into python library. 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 | lib_path = osp.join(this_dir, '..', 'lib') 23 | add_path(lib_path) 24 | 25 | lib_path = osp.join(this_dir, '..') 26 | add_path(lib_path) 27 | -------------------------------------------------------------------------------- /EfficientViT/classification/.figures/efficientvit_main.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/EfficientViT/classification/.figures/efficientvit_main.gif -------------------------------------------------------------------------------- /EfficientViT/classification/.figures/efficientvit_main_static.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/EfficientViT/classification/.figures/efficientvit_main_static.png -------------------------------------------------------------------------------- /EfficientViT/classification/.figures/modelACC_gpu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/EfficientViT/classification/.figures/modelACC_gpu.png -------------------------------------------------------------------------------- /EfficientViT/classification/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/EfficientViT/classification/data/__init__.py -------------------------------------------------------------------------------- /EfficientViT/classification/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/EfficientViT/classification/model/__init__.py -------------------------------------------------------------------------------- /EfficientViT/classification/requirements.txt: -------------------------------------------------------------------------------- 1 | torch==1.11.0 2 | torchvision 3 | timm==0.5.4 4 | einops==0.4.1 5 | fvcore 6 | easydict 7 | matplotlib 8 | numpy==1.21.0 9 | yacs 10 | scikit-image==0.19.3 11 | pillow 12 | -------------------------------------------------------------------------------- /EfficientViT/downstream/configs/_base_/datasets/lvis_v0.5_instance.py: -------------------------------------------------------------------------------- 1 | _base_ = 'coco_instance.py' 2 | dataset_type = 'LVISV05Dataset' 3 | data_root = 'data/lvis_v0.5/' 4 | data = dict( 5 | samples_per_gpu=2, 6 | workers_per_gpu=2, 7 | train=dict( 8 | _delete_=True, 9 | type='ClassBalancedDataset', 10 | oversample_thr=1e-3, 11 | dataset=dict( 12 | type=dataset_type, 13 | ann_file=data_root + 'annotations/lvis_v0.5_train.json', 14 | img_prefix=data_root + 'train2017/')), 15 | val=dict( 16 | type=dataset_type, 17 | ann_file=data_root + 'annotations/lvis_v0.5_val.json', 18 | img_prefix=data_root + 'val2017/'), 19 | test=dict( 20 | type=dataset_type, 21 | ann_file=data_root + 'annotations/lvis_v0.5_val.json', 22 | img_prefix=data_root + 'val2017/')) 23 | evaluation = dict(metric=['bbox', 'segm']) 24 | -------------------------------------------------------------------------------- /EfficientViT/downstream/configs/_base_/datasets/lvis_v1_instance.py: -------------------------------------------------------------------------------- 1 | _base_ = 'coco_instance.py' 2 | dataset_type = 'LVISV1Dataset' 3 | data_root = 'data/lvis_v1/' 4 | data = dict( 5 | samples_per_gpu=2, 6 | workers_per_gpu=2, 7 | train=dict( 8 | _delete_=True, 9 | type='ClassBalancedDataset', 10 | oversample_thr=1e-3, 11 | dataset=dict( 12 | type=dataset_type, 13 | ann_file=data_root + 'annotations/lvis_v1_train.json', 14 | img_prefix=data_root)), 15 | val=dict( 16 | type=dataset_type, 17 | ann_file=data_root + 'annotations/lvis_v1_val.json', 18 | img_prefix=data_root), 19 | test=dict( 20 | type=dataset_type, 21 | ann_file=data_root + 'annotations/lvis_v1_val.json', 22 | img_prefix=data_root)) 23 | evaluation = dict(metric=['bbox', 'segm']) 24 | -------------------------------------------------------------------------------- /EfficientViT/downstream/configs/_base_/default_runtime.py: -------------------------------------------------------------------------------- 1 | checkpoint_config = dict(interval=1) 2 | # yapf:disable 3 | log_config = dict( 4 | interval=50, 5 | hooks=[ 6 | dict(type='TextLoggerHook'), 7 | # dict(type='TensorboardLoggerHook') 8 | ]) 9 | # yapf:enable 10 | custom_hooks = [dict(type='NumClassCheckHook')] 11 | 12 | dist_params = dict(backend='nccl') 13 | log_level = 'INFO' 14 | load_from = None 15 | resume_from = None 16 | workflow = [('train', 1)] 17 | -------------------------------------------------------------------------------- /EfficientViT/downstream/configs/_base_/schedules/schedule_1x.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy='step', 7 | warmup='linear', 8 | warmup_iters=500, 9 | warmup_ratio=0.001, 10 | step=[8, 11]) 11 | runner = dict(type='EpochBasedRunner', max_epochs=12) 12 | -------------------------------------------------------------------------------- /EfficientViT/downstream/configs/_base_/schedules/schedule_20e.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy='step', 7 | warmup='linear', 8 | warmup_iters=500, 9 | warmup_ratio=0.001, 10 | step=[16, 19]) 11 | runner = dict(type='EpochBasedRunner', max_epochs=20) 12 | -------------------------------------------------------------------------------- /EfficientViT/downstream/configs/_base_/schedules/schedule_2x.py: -------------------------------------------------------------------------------- 1 | # optimizer 2 | optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001) 3 | optimizer_config = dict(grad_clip=None) 4 | # learning policy 5 | lr_config = dict( 6 | policy='step', 7 | warmup='linear', 8 | warmup_iters=500, 9 | warmup_ratio=0.001, 10 | step=[16, 22]) 11 | runner = dict(type='EpochBasedRunner', max_epochs=24) 12 | -------------------------------------------------------------------------------- /EfficientViT/downstream/dist_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CONFIG=$1 4 | CHECKPOINT=$2 5 | GPUS=$3 6 | PORT=${PORT:-29500} 7 | 8 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \ 9 | python -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=$PORT \ 10 | $(dirname "$0")/test.py $CONFIG $CHECKPOINT --launcher pytorch ${@:4} 11 | -------------------------------------------------------------------------------- /EfficientViT/downstream/dist_train.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CONFIG=$1 4 | GPUS=$2 5 | PORT=${PORT:-29500} 6 | 7 | PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \ 8 | python -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=$PORT \ 9 | $(dirname "$0")/train.py $CONFIG --launcher pytorch ${@:3} 10 | -------------------------------------------------------------------------------- /EfficientViT/downstream/mmcv_custom/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from .checkpoint import load_checkpoint, load_state_dict, _load_checkpoint 4 | 5 | __all__ = ['load_checkpoint', 'load_state_dict', '_load_checkpoint'] 6 | -------------------------------------------------------------------------------- /EfficientViT/downstream/mmcv_custom/runner/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Open-MMLab. All rights reserved. 2 | from .checkpoint import save_checkpoint 3 | from .epoch_based_runner import EpochBasedRunnerAmp 4 | 5 | 6 | __all__ = [ 7 | 'EpochBasedRunnerAmp', 'save_checkpoint' 8 | ] 9 | -------------------------------------------------------------------------------- /EfficientViT/downstream/mmcv_custom/runner/optimizer.py: -------------------------------------------------------------------------------- 1 | from mmcv.runner import OptimizerHook, HOOKS 2 | try: 3 | import apex 4 | except: 5 | print('apex is not installed') 6 | 7 | 8 | @HOOKS.register_module() 9 | class DistOptimizerHook(OptimizerHook): 10 | """Optimizer hook for distributed training.""" 11 | 12 | def __init__(self, update_interval=1, grad_clip=None, coalesce=True, bucket_size_mb=-1, use_fp16=False): 13 | self.grad_clip = grad_clip 14 | self.coalesce = coalesce 15 | self.bucket_size_mb = bucket_size_mb 16 | self.update_interval = update_interval 17 | self.use_fp16 = use_fp16 18 | 19 | def before_run(self, runner): 20 | runner.optimizer.zero_grad() 21 | 22 | def after_train_iter(self, runner): 23 | runner.outputs['loss'] /= self.update_interval 24 | if self.use_fp16: 25 | with apex.amp.scale_loss(runner.outputs['loss'], runner.optimizer) as scaled_loss: 26 | scaled_loss.backward() 27 | else: 28 | runner.outputs['loss'].backward() 29 | if self.every_n_iters(runner, self.update_interval): 30 | if self.grad_clip is not None: 31 | self.clip_grads(runner.model.parameters()) 32 | runner.optimizer.step() 33 | runner.optimizer.zero_grad() -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) Microsoft Corporation. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | 23 | 24 | -------------------------------------------------------------------------------- /MiniViT/.figure/framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/MiniViT/.figure/framework.png -------------------------------------------------------------------------------- /MiniViT/Mini-DeiT/requirements.txt: -------------------------------------------------------------------------------- 1 | torch 2 | torchvision 3 | timm==0.4.12 4 | easydict 5 | -------------------------------------------------------------------------------- /MiniViT/Mini-DeiT/rpe_ops/README.md: -------------------------------------------------------------------------------- 1 | # 2D RPE Operators 2 | 3 | ## Build iRPE operators implemented by CUDA. 4 | Although iRPE can be implemented by PyTorch native functions, the backward speed of PyTorch index function is very slow. We implement CUDA operators for more efficient training and recommend to build it. `nvcc` is necessary to build CUDA operators. 5 | ```bash 6 | cd rpe_ops/ 7 | python setup.py install --user 8 | ``` 9 | 10 | ## rpe\_index 11 | The function [`rpe_index`](./rpe_index.py#L5) is equal to 12 | ```python 13 | def rpe_index(input, index): 14 | '''Y[b, h, i, j] = input[b, h, i, index[i, j]] 15 | 16 | Parameters 17 | ---------- 18 | input: torch.Tensor, float32 19 | The shape is (B, H, L_query, num_buckets) 20 | index: torch.Tensor, int32 21 | The shape is (L_query, L_key) 22 | 23 | where B is the batch size, and H is the number of attention heads. 24 | 25 | Returns 26 | ------- 27 | Y: torch.Tensor, float32 28 | The shape is (B, H, L_query, L_key) 29 | ''' 30 | L_query, L_key = index.shape 31 | num_buckets = input.size(-1) 32 | B = len(input) 33 | offset = torch.arange(0, L_query * num_buckets, num_buckets).view(-1, 1) 34 | return input.flatten(2)[:, :, (index + offset).flatten()].view(B, -1, L_query, L_key) 35 | ``` 36 | -------------------------------------------------------------------------------- /MiniViT/Mini-DeiT/rpe_ops/setup.py: -------------------------------------------------------------------------------- 1 | """Build iRPE (image RPE) Functions""" 2 | from setuptools import setup, Extension 3 | import torch 4 | from torch.utils import cpp_extension 5 | 6 | ext_t = cpp_extension.CppExtension 7 | ext_fnames = ['rpe_index.cpp'] 8 | define_macros = [] 9 | extra_compile_args = dict(cxx=['-fopenmp', '-O3'], 10 | nvcc=['-O3']) 11 | 12 | if torch.cuda.is_available(): 13 | ext_t = cpp_extension.CUDAExtension 14 | ext_fnames.append('rpe_index_cuda.cu') 15 | define_macros.append(('WITH_CUDA', None)) 16 | 17 | setup(name='rpe_index', 18 | version="1.2.0", 19 | ext_modules=[ext_t( 20 | 'rpe_index_cpp', 21 | ext_fnames, 22 | define_macros=define_macros, 23 | extra_compile_args=extra_compile_args, 24 | )], 25 | cmdclass={'build_ext': cpp_extension.BuildExtension}) 26 | -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_base_patch4_window12_384.yaml: -------------------------------------------------------------------------------- 1 | # only for evaluation 2 | DATA: 3 | IMG_SIZE: 384 4 | MODEL: 5 | TYPE: swin 6 | NAME: swin_base_patch4_window12_384 7 | SWIN: 8 | EMBED_DIM: 128 9 | DEPTHS: [ 2, 2, 18, 2 ] 10 | NUM_HEADS: [ 4, 8, 16, 32 ] 11 | WINDOW_SIZE: 12 12 | TEST: 13 | CROP: False -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_base_patch4_window7_224.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | TYPE: swin 3 | NAME: swin_base_patch4_window7_224 4 | DROP_PATH_RATE: 0.5 5 | SWIN: 6 | EMBED_DIM: 128 7 | DEPTHS: [ 2, 2, 18, 2 ] 8 | NUM_HEADS: [ 4, 8, 16, 32 ] 9 | WINDOW_SIZE: 7 -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_base_patch4_window7_224_minivit_sharenum2.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | TYPE: swin_minivit_distill 3 | NAME: swin_base_patch4_window7_224_minivit 4 | DROP_PATH_RATE: 0.2 5 | SWIN: 6 | EMBED_DIM: 128 7 | DEPTHS: [ 2, 2, 18, 2 ] 8 | NUM_HEADS: [ 4, 8, 16, 32 ] 9 | WINDOW_SIZE: 7 10 | MINIVIT: 11 | SEPARATE_LAYERNUM_LIST: [1, 1, 9, 1] -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_base_patch4_window7_224to384_minivit_sharenum2_adamw.yaml: -------------------------------------------------------------------------------- 1 | DATA: 2 | IMG_SIZE: 384 3 | MODEL: 4 | TYPE: swin_minivit_distill 5 | NAME: swin_base_patch4_window7_224to384_minivit 6 | DROP_PATH_RATE: 0.2 7 | SWIN: 8 | EMBED_DIM: 128 9 | DEPTHS: [ 2, 2, 18, 2 ] 10 | NUM_HEADS: [ 4, 8, 16, 32 ] 11 | WINDOW_SIZE: 12 12 | MINIVIT: 13 | SEPARATE_LAYERNUM_LIST: [1, 1, 9, 1] 14 | TRAIN: 15 | EPOCHS: 30 16 | WARMUP_EPOCHS: 5 17 | WEIGHT_DECAY: 1e-8 18 | BASE_LR: 2e-5 19 | CLIP_GRAD: 5.0 -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_large_patch4_window12_384.yaml: -------------------------------------------------------------------------------- 1 | # only for evaluation 2 | DATA: 3 | IMG_SIZE: 384 4 | MODEL: 5 | TYPE: swin 6 | NAME: swin_large_patch4_window12_384 7 | SWIN: 8 | EMBED_DIM: 192 9 | DEPTHS: [ 2, 2, 18, 2 ] 10 | NUM_HEADS: [ 6, 12, 24, 48 ] 11 | WINDOW_SIZE: 12 12 | TEST: 13 | CROP: False -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_large_patch4_window7_224.yaml: -------------------------------------------------------------------------------- 1 | # only for evaluation 2 | MODEL: 3 | TYPE: swin 4 | NAME: swin_large_patch4_window7_224 5 | SWIN: 6 | EMBED_DIM: 192 7 | DEPTHS: [ 2, 2, 18, 2 ] 8 | NUM_HEADS: [ 6, 12, 24, 48 ] 9 | WINDOW_SIZE: 7 -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_small_patch4_window7_224.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | TYPE: swin 3 | NAME: swin_small_patch4_window7_224 4 | DROP_PATH_RATE: 0.3 5 | SWIN: 6 | EMBED_DIM: 96 7 | DEPTHS: [ 2, 2, 18, 2 ] 8 | NUM_HEADS: [ 3, 6, 12, 24 ] 9 | WINDOW_SIZE: 7 -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_small_patch4_window7_224_minivit_sharenum2.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | TYPE: swin_minivit_distill 3 | NAME: swin_small_patch4_window7_224_minivit 4 | DROP_PATH_RATE: 0.1 5 | SWIN: 6 | EMBED_DIM: 96 7 | DEPTHS: [ 2, 2, 18, 2 ] 8 | NUM_HEADS: [ 3, 6, 12, 24 ] 9 | WINDOW_SIZE: 7 10 | MINIVIT: 11 | SEPARATE_LAYERNUM_LIST: [1, 1, 9, 1] -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_tiny_patch4_window7_224.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | TYPE: swin 3 | NAME: swin_tiny_patch4_window7_224 4 | DROP_PATH_RATE: 0.2 5 | SWIN: 6 | EMBED_DIM: 96 7 | DEPTHS: [ 2, 2, 6, 2 ] 8 | NUM_HEADS: [ 3, 6, 12, 24 ] 9 | WINDOW_SIZE: 7 -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/configs/swin_tiny_patch4_window7_224_minivit_sharenum6.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | TYPE: swin_minivit_distill 3 | NAME: swin_tiny_patch4_window7_224_minivit 4 | DROP_PATH_RATE: 0.0 5 | SWIN: 6 | EMBED_DIM: 96 7 | DEPTHS: [ 2, 2, 6, 2 ] 8 | NUM_HEADS: [ 3, 6, 12, 24 ] 9 | WINDOW_SIZE: 7 10 | MINIVIT: 11 | SEPARATE_LAYERNUM_LIST: [1, 1, 1, 1] -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_loader -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/data/samplers.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | class SubsetRandomSampler(torch.utils.data.Sampler): 5 | r"""Samples elements randomly from a given list of indices, without replacement. 6 | 7 | Arguments: 8 | indices (sequence): a sequence of indices 9 | """ 10 | 11 | def __init__(self, indices): 12 | self.epoch = 0 13 | self.indices = indices 14 | 15 | def __iter__(self): 16 | return (self.indices[i] for i in torch.randperm(len(self.indices))) 17 | 18 | def __len__(self): 19 | return len(self.indices) 20 | 21 | def set_epoch(self, epoch): 22 | self.epoch = epoch 23 | -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_model -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/my_meter.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.distributed as dist 3 | from utils import reduce_tensor 4 | 5 | class AverageMeter: 6 | """Computes and stores the average and current value""" 7 | def __init__(self): 8 | self.reset() 9 | 10 | def reset(self): 11 | self.val = 0 12 | self.avg = 0 13 | self.sum = 0 14 | self.count = 0 15 | 16 | def update(self, val, n=1): 17 | self.val = val 18 | self.sum += val * n 19 | self.count += n 20 | self.avg = self.sum / self.count 21 | 22 | 23 | def sync(self): 24 | rank = dist.get_rank() 25 | world_size = dist.get_world_size() 26 | val = torch.tensor(self.val).cuda() 27 | sum_v = torch.tensor(self.sum).cuda() 28 | count = torch.tensor(self.count).cuda() 29 | self.val = reduce_tensor(val, world_size).item() 30 | self.sum = reduce_tensor(sum_v, 1).item() 31 | self.count = reduce_tensor(count, 1).item() 32 | self.avg = self.sum / max(1, self.count) 33 | -------------------------------------------------------------------------------- /MiniViT/Mini-Swin/requirements.txt: -------------------------------------------------------------------------------- 1 | torch 2 | torchvision 3 | timm==0.4.12 4 | yacs 5 | termcolor 6 | -------------------------------------------------------------------------------- /TinyCLIP/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include src/open_clip/bpe_simple_vocab_16e6.txt.gz 2 | include src/open_clip/model_configs/*.json 3 | 4 | -------------------------------------------------------------------------------- /TinyCLIP/Makefile: -------------------------------------------------------------------------------- 1 | install: ## [Local development] Upgrade pip, install requirements, install package. 2 | python -m pip install -U pip 3 | python -m pip install -e . 4 | 5 | install-dev: ## [Local development] Install test requirements 6 | python -m pip install -r requirements-test.txt 7 | 8 | test: ## [Local development] Run unit tests 9 | python -m pytest -x -s -v tests 10 | -------------------------------------------------------------------------------- /TinyCLIP/docs/PREPARATION.md: -------------------------------------------------------------------------------- 1 | # Preparation 2 | 3 | ### Install the dependencies 4 | ```bash 5 | pip install -r requirements-training.txt 6 | pip install -v -e . 7 | ``` 8 | 9 | ### Data Preparation 10 | 11 | We need to prepare [ImageNet-1k](http://www.image-net.org/) datasets to do zero-shot classification task. 12 | 13 | - ImageNet-1k 14 | 15 | ImageNet-1k contains 1.28 M images for training and 50 K images for validation. 16 | The train set and validation set should be saved as the `*.tar` archives: 17 | 18 | ``` 19 | ImageNet/ 20 | ├── train.tar 21 | └── val.tar 22 | ``` 23 | 24 | Our code also supports storing images as individual files as follow: 25 | ``` 26 | ImageNet/ 27 | ├── train 28 | │ ├── n01440764 29 | │ │ ├── n01440764_10026.JPEG 30 | │ │ ├── n01440764_10027.JPEG 31 | ... 32 | ├── val 33 | │ ├── n01440764 34 | │ │ ├── ILSVRC2012_val_00000293.JPEG 35 | ``` 36 | -------------------------------------------------------------------------------- /TinyCLIP/figure/TinyCLIP.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/TinyCLIP/figure/TinyCLIP.jpg -------------------------------------------------------------------------------- /TinyCLIP/figure/fig1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/TinyCLIP/figure/fig1.jpg -------------------------------------------------------------------------------- /TinyCLIP/requirements-test.txt: -------------------------------------------------------------------------------- 1 | pytest-xdist==2.5.0 2 | pytest==7.0.1 -------------------------------------------------------------------------------- /TinyCLIP/requirements-training.txt: -------------------------------------------------------------------------------- 1 | torch>=1.9.0 2 | torchvision 3 | webdataset>=0.2.5 4 | regex 5 | ftfy 6 | tqdm 7 | pandas 8 | braceexpand 9 | huggingface_hub 10 | psutil 11 | timm==0.4.12 12 | -------------------------------------------------------------------------------- /TinyCLIP/requirements.txt: -------------------------------------------------------------------------------- 1 | torch>=1.9.0 2 | torchvision 3 | regex 4 | ftfy 5 | tqdm 6 | huggingface_hub 7 | psutil 8 | -------------------------------------------------------------------------------- /TinyCLIP/script/auto_weight_inherit_100to75.sh: -------------------------------------------------------------------------------- 1 | export NNODES=1 2 | export GPUS_PER_NODE=8 3 | 4 | DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES" 5 | torchrun $DISTRIBUTED_ARGS src/training/main.py \ 6 | --save-frequency 1 \ 7 | --report-to wandb \ 8 | --train-data synthetic \ 9 | --dataset-type synthetic \ 10 | --imagenet-val ./ImageNet \ 11 | --warmup 3000 \ 12 | --batch-size 1024 \ 13 | --epochs 6 \ 14 | --workers 8 \ 15 | --model ViT-B-32 \ 16 | --name exp_name \ 17 | --seed 0 \ 18 | --local-loss \ 19 | --grad-checkpointing \ 20 | --logs ./outputs/ViT-B-32 \ 21 | --lr 0.0001 \ 22 | --gather-with-grad \ 23 | --pretrained-image-file ViT-B-32@laion2b_e16 \ 24 | --pretrained-text-file ViT-B-32@laion2b_e16 \ 25 | --distillation-teacher ViT-B-32@laion2b_e16 \ 26 | --norm_gradient_clip 5 \ 27 | --train-num-samples 400000000 \ 28 | --prune-step 3000 \ 29 | --prune-image \ 30 | --prune-text \ 31 | --total-loss-flag \ 32 | --target-sparsity 0.25 \ 33 | --start-sparsity 0.0 \ 34 | --sparsity-warmup 1000 \ 35 | --logit-scale 50 36 | -------------------------------------------------------------------------------- /TinyCLIP/script/auto_weight_inherit_50to25.sh: -------------------------------------------------------------------------------- 1 | export NNODES=1 2 | export GPUS_PER_NODE=8 3 | 4 | DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES" 5 | torchrun $DISTRIBUTED_ARGS src/training/main.py \ 6 | --save-frequency 1 \ 7 | --report-to wandb \ 8 | --train-data synthetic \ 9 | --dataset-type synthetic \ 10 | --imagenet-val ./ImageNet \ 11 | --warmup 8000 \ 12 | --batch-size 1024 \ 13 | --epochs 6 \ 14 | --workers 8 \ 15 | --model ViT-B-32 \ 16 | --name exp_name \ 17 | --seed 0 \ 18 | --local-loss \ 19 | --grad-checkpointing \ 20 | --logs ./outputs/ViT-B-32 \ 21 | --lr 0.0001 \ 22 | --gather-with-grad \ 23 | --pretrained-image-file ViT-B-32@laion2b_e16 \ 24 | --pretrained-text-file ViT-B-32@laion2b_e16 \ 25 | --distillation-teacher ViT-B-32@laion2b_e16 \ 26 | --logit-scale 50 \ 27 | --norm_gradient_clip 5 \ 28 | --train-num-samples 400000000 \ 29 | --prune-step 8000 \ 30 | --prune-image \ 31 | --prune-text \ 32 | --total-loss-flag \ 33 | --target-sparsity 0.75 \ 34 | --start-sparsity 0.5 \ 35 | --sparsity-warmup 1000 \ 36 | --resume ./checkpoints/TinyCLIP-auto-ViT-45M-32-Text-18M-LAION400M.pt \ 37 | --load-last-stage 38 | -------------------------------------------------------------------------------- /TinyCLIP/script/auto_weight_inherit_75to50.sh: -------------------------------------------------------------------------------- 1 | export NNODES=1 2 | export GPUS_PER_NODE=8 3 | 4 | DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES" 5 | torchrun $DISTRIBUTED_ARGS src/training/main.py \ 6 | --save-frequency 1 \ 7 | --report-to wandb \ 8 | --train-data synthetic \ 9 | --dataset-type synthetic \ 10 | --imagenet-val ./ImageNet \ 11 | --warmup 5000 \ 12 | --batch-size 1024 \ 13 | --epochs 6 \ 14 | --workers 8 \ 15 | --model ViT-B-32 \ 16 | --name exp_name \ 17 | --seed 0 \ 18 | --local-loss \ 19 | --grad-checkpointing \ 20 | --logs ./outputs/ViT-B-32 \ 21 | --lr 0.0001 \ 22 | --gather-with-grad \ 23 | --pretrained-image-file ViT-B-32@laion2b_e16 \ 24 | --pretrained-text-file ViT-B-32@laion2b_e16 \ 25 | --distillation-teacher ViT-B-32@laion2b_e16 \ 26 | --logit-scale 50 \ 27 | --norm_gradient_clip 5 \ 28 | --train-num-samples 400000000 \ 29 | --prune-step 5000 \ 30 | --prune-image \ 31 | --prune-text \ 32 | --total-loss-flag \ 33 | --target-sparsity 0.5 \ 34 | --start-sparsity 0.25 \ 35 | --sparsity-warmup 1000 \ 36 | --resume ./checkpoints/TinyCLIP-auto-ViT-63M-32-Text-31M-LAION400M.pt \ 37 | --load-last-stage 38 | -------------------------------------------------------------------------------- /TinyCLIP/script/manual_weight_inherit_100to75.sh: -------------------------------------------------------------------------------- 1 | export NNODES=1 2 | export GPUS_PER_NODE=8 3 | 4 | DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES" 5 | torchrun $DISTRIBUTED_ARGS src/training/main.py \ 6 | --save-frequency 1 \ 7 | --report-to wandb \ 8 | --train-data synthetic \ 9 | --dataset-type synthetic \ 10 | --imagenet-val ./ImageNet \ 11 | --warmup 2000 \ 12 | --batch-size 1024 \ 13 | --epochs 6 \ 14 | --workers 8 \ 15 | --model TinyCLIP-ViT-61M-32-Text-29M \ 16 | --name exp_name \ 17 | --seed 0 \ 18 | --local-loss \ 19 | --grad-checkpointing \ 20 | --logs ./outputs/ViT-B-32 \ 21 | --lr 0.0001 \ 22 | --gather-with-grad \ 23 | --pretrained-image-file ViT-B-32@laion2b_e16 \ 24 | --pretrained-text-file ViT-B-32@laion2b_e16 \ 25 | --distillation-teacher ViT-B-32@laion2b_e16 \ 26 | --logit-scale 50 \ 27 | --norm_gradient_clip 5 \ 28 | --train-num-samples 400000000 29 | -------------------------------------------------------------------------------- /TinyCLIP/script/manual_weight_inherit_75to50.sh: -------------------------------------------------------------------------------- 1 | export NNODES=1 2 | export GPUS_PER_NODE=8 3 | 4 | DISTRIBUTED_ARGS="--nproc_per_node $GPUS_PER_NODE --nnodes $NNODES" 5 | torchrun $DISTRIBUTED_ARGS src/training/main.py \ 6 | --save-frequency 1 \ 7 | --report-to wandb \ 8 | --train-data synthetic \ 9 | --dataset-type synthetic \ 10 | --imagenet-val ./ImageNet \ 11 | --warmup 2000 \ 12 | --batch-size 1024 \ 13 | --epochs 6 \ 14 | --workers 8 \ 15 | --model TinyCLIP-ViT-40M-32-Text-19M \ 16 | --name exp_name \ 17 | --seed 0 \ 18 | --local-loss \ 19 | --grad-checkpointing \ 20 | --logs ./outputs/ViT-B-32 \ 21 | --lr 0.0001 \ 22 | --gather-with-grad \ 23 | --pretrained-image-file checkpoints/TinyCLIP-ViT-61M-32-Text-29M-LAION400M.pt \ 24 | --pretrained-text-file checkpoints/TinyCLIP-ViT-61M-32-Text-29M-LAION400M.pt \ 25 | --distillation-teacher ViT-B-32@laion2b_e16 \ 26 | --logit-scale 50 \ 27 | --norm_gradient_clip 5 \ 28 | --train-num-samples 400000000 29 | -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/__init__.py: -------------------------------------------------------------------------------- 1 | from .constants import OPENAI_DATASET_MEAN, OPENAI_DATASET_STD 2 | from .factory import list_models, create_model, create_model_and_transforms, get_tokenizer, add_model_config, \ 3 | load_model, load_exp 4 | from .loss import ClipLoss 5 | from .model import CLIP, CLIPTextCfg, CLIPVisionCfg, convert_weights_to_fp16, trace_model 6 | from .openai import load_openai_model, list_openai_models 7 | from .pretrained import list_pretrained, list_pretrained_tag_models, list_pretrained_model_tags,\ 8 | get_pretrained_url, download_pretrained_from_url, is_pretrained_cfg, get_pretrained_cfg, download_pretrained 9 | from .tokenizer import SimpleTokenizer, tokenize 10 | from .transform import image_transform 11 | from .l0module import L0Module 12 | -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/bpe_simple_vocab_16e6.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/TinyCLIP/src/open_clip/bpe_simple_vocab_16e6.txt.gz -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/constants.py: -------------------------------------------------------------------------------- 1 | OPENAI_DATASET_MEAN = (0.48145466, 0.4578275, 0.40821073) 2 | OPENAI_DATASET_STD = (0.26862954, 0.26130258, 0.27577711) 3 | -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/RN50.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 1024, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": [ 6 | 3, 7 | 4, 8 | 6, 9 | 3 10 | ], 11 | "width": 64, 12 | "patch_size": null 13 | }, 14 | "text_cfg": { 15 | "context_length": 77, 16 | "vocab_size": 49408, 17 | "width": 512, 18 | "heads": 8, 19 | "layers": 12 20 | } 21 | } -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/TinyCLIP-ResNet-19M-Text-19M.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 1024, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": [ 6 | 3, 7 | 4, 8 | 6, 9 | 3 10 | ], 11 | "width": 44, 12 | "patch_size": null 13 | }, 14 | "text_cfg": { 15 | "context_length": 77, 16 | "vocab_size": 49408, 17 | "width": 512, 18 | "heads": 8, 19 | "layers": 6 20 | } 21 | } -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/TinyCLIP-ResNet-30M-Text-29M.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 1024, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": [ 6 | 3, 7 | 4, 8 | 6, 9 | 3 10 | ], 11 | "width": 56, 12 | "patch_size": null 13 | }, 14 | "text_cfg": { 15 | "context_length": 77, 16 | "vocab_size": 49408, 17 | "width": 512, 18 | "heads": 8, 19 | "layers": 9 20 | } 21 | } -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/TinyCLIP-ViT-39M-16-Text-19M.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 512, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": 12, 6 | "width": 512, 7 | "patch_size": 16 8 | }, 9 | "text_cfg": { 10 | "context_length": 77, 11 | "vocab_size": 49408, 12 | "width": 512, 13 | "heads": 8, 14 | "layers": 6 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/TinyCLIP-ViT-40M-32-Text-19M.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 512, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": 12, 6 | "width": 512, 7 | "patch_size": 32 8 | }, 9 | "text_cfg": { 10 | "context_length": 77, 11 | "vocab_size": 49408, 12 | "width": 512, 13 | "heads": 8, 14 | "layers": 6 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/TinyCLIP-ViT-61M-32-Text-29M.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 512, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": 12, 6 | "width": 640, 7 | "patch_size": 32 8 | }, 9 | "text_cfg": { 10 | "context_length": 77, 11 | "vocab_size": 49408, 12 | "width": 512, 13 | "heads": 8, 14 | "layers": 9 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/TinyCLIP-ViT-8M-16-Text-3M.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 512, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": 10, 6 | "width": 256, 7 | "patch_size": 16 8 | }, 9 | "text_cfg": { 10 | "context_length": 77, 11 | "vocab_size": 49408, 12 | "width": 256, 13 | "heads": 4, 14 | "layers": 3 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/ViT-B-16.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 512, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": 12, 6 | "width": 768, 7 | "patch_size": 16 8 | }, 9 | "text_cfg": { 10 | "context_length": 77, 11 | "vocab_size": 49408, 12 | "width": 512, 13 | "heads": 8, 14 | "layers": 12 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/model_configs/ViT-B-32.json: -------------------------------------------------------------------------------- 1 | { 2 | "embed_dim": 512, 3 | "vision_cfg": { 4 | "image_size": 224, 5 | "layers": 12, 6 | "width": 768, 7 | "patch_size": 32 8 | }, 9 | "text_cfg": { 10 | "context_length": 77, 11 | "vocab_size": 49408, 12 | "width": 512, 13 | "heads": 8, 14 | "layers": 12 15 | } 16 | } -------------------------------------------------------------------------------- /TinyCLIP/src/open_clip/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '2.0.2' 2 | -------------------------------------------------------------------------------- /TinyCLIP/src/training/.gitignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | -------------------------------------------------------------------------------- /TinyCLIP/src/training/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/TinyCLIP/src/training/__init__.py -------------------------------------------------------------------------------- /TinyCLIP/src/training/logger.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | 4 | def setup_logging(log_file, level, include_host=False): 5 | if include_host: 6 | import socket 7 | hostname = socket.gethostname() 8 | formatter = logging.Formatter( 9 | f'%(asctime)s | {hostname} | %(levelname)s | %(message)s', datefmt='%Y-%m-%d,%H:%M:%S') 10 | else: 11 | formatter = logging.Formatter( 12 | '%(asctime)s | %(levelname)s | %(message)s', datefmt='%Y-%m-%d,%H:%M:%S') 13 | 14 | logging.root.setLevel(level) 15 | loggers = [logging.getLogger(name) 16 | for name in logging.root.manager.loggerDict] 17 | for logger in loggers: 18 | logger.setLevel(level) 19 | 20 | stream_handler = logging.StreamHandler() 21 | stream_handler.setFormatter(formatter) 22 | logging.root.addHandler(stream_handler) 23 | 24 | if log_file: 25 | file_handler = logging.FileHandler(filename=log_file) 26 | file_handler.setFormatter(formatter) 27 | logging.root.addHandler(file_handler) 28 | -------------------------------------------------------------------------------- /TinyCLIP/src/training/precision.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from contextlib import suppress 3 | 4 | # amp_bfloat16 is more stable than amp float16 for clip training 5 | 6 | 7 | def get_autocast(precision): 8 | if precision == 'amp': 9 | return torch.cuda.amp.autocast 10 | elif precision == 'amp_bfloat16': 11 | return lambda: torch.cuda.amp.autocast(dtype=torch.bfloat16) 12 | elif precision == 'fp32': 13 | return lambda: torch.cuda.amp.autocast(enabled=False) 14 | else: 15 | return suppress 16 | -------------------------------------------------------------------------------- /TinyViT/.figure/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/TinyViT/.figure/cat.jpg -------------------------------------------------------------------------------- /TinyViT/.figure/distill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/TinyViT/.figure/distill.png -------------------------------------------------------------------------------- /TinyViT/.figure/framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/TinyViT/.figure/framework.png -------------------------------------------------------------------------------- /TinyViT/.figure/performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/TinyViT/.figure/performance.png -------------------------------------------------------------------------------- /TinyViT/configs/1k/tiny_vit_11m.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-11M-1k 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.1 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 2, 4, 8, 14 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [64, 128, 256, 448] 12 | -------------------------------------------------------------------------------- /TinyViT/configs/1k/tiny_vit_21m.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-21M-1k 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.2 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 3, 6, 12, 18 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [96, 192, 384, 576] 12 | -------------------------------------------------------------------------------- /TinyViT/configs/1k/tiny_vit_5m.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-5M-1k 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.0 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 2, 4, 5, 10 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [64, 128, 160, 320] 12 | -------------------------------------------------------------------------------- /TinyViT/configs/22k_distill/tiny_vit_11m_22k_distill.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-11M-22k-distill 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.0 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 2, 4, 8, 14 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [64, 128, 256, 448] 12 | 13 | TRAIN: 14 | EPOCHS: 90 15 | BASE_LR: 2.5e-4 16 | WARMUP_EPOCHS: 5 17 | WEIGHT_DECAY: 0.01 18 | 19 | DATA: 20 | DATASET: imagenet22k 21 | 22 | AUG: 23 | MIXUP: 0.0 24 | CUTMIX: 0.0 25 | -------------------------------------------------------------------------------- /TinyViT/configs/22k_distill/tiny_vit_21m_22k_distill.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-21M-22k-distill 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.1 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 3, 6, 12, 18 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [96, 192, 384, 576] 12 | 13 | TRAIN: 14 | EPOCHS: 90 15 | BASE_LR: 2.5e-4 16 | WARMUP_EPOCHS: 5 17 | WEIGHT_DECAY: 0.01 18 | 19 | DATA: 20 | DATASET: imagenet22k 21 | 22 | AUG: 23 | MIXUP: 0.0 24 | CUTMIX: 0.0 25 | -------------------------------------------------------------------------------- /TinyViT/configs/22k_distill/tiny_vit_5m_22k_distill.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-5M-22k-distill 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.0 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 2, 4, 5, 10 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [64, 128, 160, 320] 12 | 13 | TRAIN: 14 | EPOCHS: 90 15 | BASE_LR: 2.5e-4 16 | WARMUP_EPOCHS: 5 17 | WEIGHT_DECAY: 0.01 18 | 19 | DATA: 20 | DATASET: imagenet22k 21 | 22 | AUG: 23 | MIXUP: 0.0 24 | CUTMIX: 0.0 25 | -------------------------------------------------------------------------------- /TinyViT/configs/22kto1k/tiny_vit_11m_22kto1k.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-11M-22kto1k 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.0 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 2, 4, 8, 14 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [64, 128, 256, 448] 12 | 13 | TRAIN: 14 | EPOCHS: 30 15 | WARMUP_EPOCHS: 5 16 | BASE_LR: 2.5e-4 17 | WEIGHT_DECAY: 1e-8 18 | MIN_LR: 1e-5 19 | LAYER_LR_DECAY: 0.8 20 | EVAL_BN_WHEN_TRAINING: True 21 | 22 | AUG: 23 | MIXUP: 0.0 24 | CUTMIX: 0.0 25 | -------------------------------------------------------------------------------- /TinyViT/configs/22kto1k/tiny_vit_21m_22kto1k.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-21M-22kto1k 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.1 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 3, 6, 12, 18 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [96, 192, 384, 576] 12 | 13 | TRAIN: 14 | EPOCHS: 30 15 | WARMUP_EPOCHS: 5 16 | BASE_LR: 2.5e-4 17 | WEIGHT_DECAY: 1e-8 18 | MIN_LR: 1e-5 19 | LAYER_LR_DECAY: 0.8 20 | EVAL_BN_WHEN_TRAINING: True 21 | 22 | AUG: 23 | MIXUP: 0.0 24 | CUTMIX: 0.0 25 | -------------------------------------------------------------------------------- /TinyViT/configs/22kto1k/tiny_vit_5m_22kto1k.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-5M-22kto1k 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.0 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 2, 4, 5, 10 ] 10 | WINDOW_SIZES: [ 7, 7, 14, 7 ] 11 | EMBED_DIMS: [64, 128, 160, 320] 12 | 13 | TRAIN: 14 | EPOCHS: 30 15 | WARMUP_EPOCHS: 5 16 | BASE_LR: 2.5e-4 17 | WEIGHT_DECAY: 1e-8 18 | MIN_LR: 1e-5 19 | LAYER_LR_DECAY: 0.8 20 | EVAL_BN_WHEN_TRAINING: True 21 | 22 | AUG: 23 | MIXUP: 0.0 24 | CUTMIX: 0.0 25 | -------------------------------------------------------------------------------- /TinyViT/configs/higher_resolution/tiny_vit_21m_224to384.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-21M-224to384 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.1 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 3, 6, 12, 18 ] 10 | WINDOW_SIZES: [ 12, 12, 24, 12 ] 11 | EMBED_DIMS: [96, 192, 384, 576] 12 | 13 | DATA: 14 | IMG_SIZE: 384 15 | 16 | TRAIN: 17 | EPOCHS: 30 18 | WARMUP_EPOCHS: 5 19 | WEIGHT_DECAY: 1e-8 20 | BASE_LR: 2e-05 21 | WARMUP_LR: 2e-08 22 | MIN_LR: 2e-07 23 | EVAL_BN_WHEN_TRAINING: True 24 | TEST: 25 | CROP: False 26 | AUG: 27 | MIXUP: 0.0 28 | CUTMIX: 0.0 29 | -------------------------------------------------------------------------------- /TinyViT/configs/higher_resolution/tiny_vit_21m_384to512.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | NAME: TinyViT-21M-384to512 3 | TYPE: tiny_vit 4 | 5 | DROP_PATH_RATE: 0.1 6 | 7 | TINY_VIT: 8 | DEPTHS: [ 2, 2, 6, 2 ] 9 | NUM_HEADS: [ 3, 6, 12, 18 ] 10 | WINDOW_SIZES: [ 16, 16, 32, 16 ] 11 | EMBED_DIMS: [96, 192, 384, 576] 12 | DATA: 13 | IMG_SIZE: 512 14 | TRAIN: 15 | EPOCHS: 30 16 | WARMUP_EPOCHS: 5 17 | WEIGHT_DECAY: 1e-8 18 | BASE_LR: 2e-05 19 | WARMUP_LR: 2e-08 20 | MIN_LR: 2e-07 21 | EVAL_BN_WHEN_TRAINING: True 22 | TEST: 23 | CROP: False 24 | 25 | AUG: 26 | MIXUP: 0.0 27 | CUTMIX: 0.0 28 | -------------------------------------------------------------------------------- /TinyViT/configs/teacher/clip_vit_large_patch14_22k.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | TYPE: clip_vit_large14_224 3 | 4 | TRAIN: 5 | EPOCHS: 90 6 | 7 | DATA: 8 | MEAN_AND_STD_TYPE: clip 9 | DATASET: imagenet22k 10 | 11 | AUG: 12 | MIXUP: 0.0 13 | CUTMIX: 0.0 14 | -------------------------------------------------------------------------------- /TinyViT/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_loader, build_transform 2 | from .imagenet_classnames import imagenet_classnames 3 | -------------------------------------------------------------------------------- /TinyViT/data/augmentation/README.md: -------------------------------------------------------------------------------- 1 | # Image Augmentation for TinyViT 2 | 3 | The code is based on [timm.data](https://github.com/rwightman/pytorch-image-models/tree/master/timm/data) of [pytorch-image-models](https://github.com/rwightman/pytorch-image-models) written by [Ross Wightman](https://github.com/rwightman) and the contributors. Thanks a lot! 4 | 5 | We adapt it for TinyViT. 6 | 7 | Apache License 8 | 9 | ## Code Structure 10 | 11 | File | Description 12 | ---------------------------------------------|-------------------------- 13 | [`aug_random.py`](./aug_random.py) | unify all random values of augmentation with a random generator 14 | [`dataset_wrapper.py`](./dataset_wrapper.py) | a dataset wrapper for saving logits 15 | [`manager.py`](./manager.py) | The writter and reader for logits files 16 | -------------------------------------------------------------------------------- /TinyViT/data/augmentation/__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 -------------------------------------------------------------------------------- /TinyViT/data/augmentation/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 | -------------------------------------------------------------------------------- /TinyViT/data/augmentation/parsers/__init__.py: -------------------------------------------------------------------------------- 1 | from .parser_factory import create_parser 2 | -------------------------------------------------------------------------------- /TinyViT/data/augmentation/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 | -------------------------------------------------------------------------------- /TinyViT/data/augmentation/parsers/constants.py: -------------------------------------------------------------------------------- 1 | IMG_EXTENSIONS = ('.png', '.jpg', '.jpeg') 2 | -------------------------------------------------------------------------------- /TinyViT/data/augmentation/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 | -------------------------------------------------------------------------------- /TinyViT/data/augmentation/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 | -------------------------------------------------------------------------------- /TinyViT/inference.py: -------------------------------------------------------------------------------- 1 | """Model Inference.""" 2 | import torch 3 | import numpy as np 4 | from PIL import Image 5 | 6 | from models.tiny_vit import tiny_vit_21m_224 7 | from data import build_transform, imagenet_classnames 8 | from config import get_config 9 | 10 | config = get_config() 11 | 12 | 13 | # Build model 14 | model = tiny_vit_21m_224(pretrained=True) 15 | model.eval() 16 | 17 | # Load Image 18 | fname = './.figure/cat.jpg' 19 | image = Image.open(fname) 20 | transform = build_transform(is_train=False, config=config) 21 | 22 | # (1, 3, img_size, img_size) 23 | batch = transform(image)[None] 24 | 25 | with torch.no_grad(): 26 | logits = model(batch) 27 | 28 | # print top-5 classification names 29 | probs = torch.softmax(logits, -1) 30 | scores, inds = probs.topk(5, largest=True, sorted=True) 31 | print('=' * 30) 32 | print(fname) 33 | for score, ind in zip(scores[0].numpy(), inds[0].numpy()): 34 | print(f'{imagenet_classnames[ind]}: {score:.2f}') 35 | -------------------------------------------------------------------------------- /TinyViT/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_model 2 | -------------------------------------------------------------------------------- /TinyViT/models/remap_layer.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # TinyViT Utils 3 | # Copyright (c) 2022 Microsoft 4 | # -------------------------------------------------------- 5 | 6 | import torch 7 | from torch import nn 8 | 9 | 10 | class RemapLayer(nn.Module): 11 | def __init__(self, fname): 12 | super().__init__() 13 | with open(fname) as fin: 14 | self.mapping = torch.Tensor( 15 | list(map(int, fin.readlines()))).to(torch.long) 16 | 17 | def forward(self, x): 18 | ''' 19 | x: [batch_size, class] 20 | ''' 21 | B = len(x) 22 | dummy_cls = x.new_zeros((B, 1)) 23 | expand_x = torch.cat([x, dummy_cls], dim=1) 24 | return expand_x[:, self.mapping] 25 | -------------------------------------------------------------------------------- /TinyViT/requirements.txt: -------------------------------------------------------------------------------- 1 | timm==0.4.12 2 | yacs 3 | termcolor 4 | wandb 5 | -------------------------------------------------------------------------------- /iRPE/DETR-with-iRPE/.gitignore: -------------------------------------------------------------------------------- 1 | .nfs* 2 | *.ipynb 3 | *.pyc 4 | .dumbo.json 5 | .DS_Store 6 | .*.swp 7 | *.pth 8 | **/__pycache__/** 9 | .ipynb_checkpoints/ 10 | datasets/data/ 11 | experiment-* 12 | *.tmp 13 | *.pkl 14 | **/.mypy_cache/* 15 | .mypy_cache/* 16 | not_tracked_dir/ 17 | .vscode 18 | -------------------------------------------------------------------------------- /iRPE/DETR-with-iRPE/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | import torch.utils.data 3 | import torchvision 4 | 5 | from .coco import build as build_coco 6 | 7 | 8 | def get_coco_api_from_dataset(dataset): 9 | for _ in range(10): 10 | # if isinstance(dataset, torchvision.datasets.CocoDetection): 11 | # break 12 | if isinstance(dataset, torch.utils.data.Subset): 13 | dataset = dataset.dataset 14 | if isinstance(dataset, torchvision.datasets.CocoDetection): 15 | return dataset.coco 16 | 17 | 18 | def build_dataset(image_set, args): 19 | if args.dataset_file == 'coco': 20 | return build_coco(image_set, args) 21 | if args.dataset_file == 'coco_panoptic': 22 | # to avoid making panopticapi required for coco 23 | from .coco_panoptic import build as build_coco_panoptic 24 | return build_coco_panoptic(image_set, args) 25 | raise ValueError(f'dataset {args.dataset_file} not supported') 26 | -------------------------------------------------------------------------------- /iRPE/DETR-with-iRPE/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .detr import build 3 | 4 | 5 | def build_model(args): 6 | return build(args) 7 | -------------------------------------------------------------------------------- /iRPE/DETR-with-iRPE/models/rpe_attention/__init__.py: -------------------------------------------------------------------------------- 1 | from .multi_head_attention import RPEMultiheadAttention 2 | from . import irpe 3 | -------------------------------------------------------------------------------- /iRPE/DETR-with-iRPE/requirements.txt: -------------------------------------------------------------------------------- 1 | cython 2 | git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools 3 | submitit 4 | torch>=1.5.0 5 | torchvision>=0.6.0 6 | git+https://github.com/cocodataset/panopticapi.git#egg=panopticapi 7 | scipy 8 | onnx 9 | onnxruntime 10 | -------------------------------------------------------------------------------- /iRPE/DETR-with-iRPE/rpe_ops/README.md: -------------------------------------------------------------------------------- 1 | # 2D RPE Operators 2 | 3 | ## Build iRPE operators implemented by CUDA. 4 | Although iRPE can be implemented by PyTorch native functions, the backward speed of PyTorch index function is very slow. We implement CUDA operators for more efficient training and recommend to build it. `nvcc` is necessary to build CUDA operators. 5 | ```bash 6 | cd rpe_ops/ 7 | python setup.py install --user 8 | ``` 9 | 10 | ## rpe\_index 11 | The function [`rpe_index`](./rpe_index.py#L5) is equal to 12 | ```python 13 | def rpe_index(input, index): 14 | '''Y[b, h, i, j] = input[b, h, i, index[i, j]] 15 | 16 | Parameters 17 | ---------- 18 | input: torch.Tensor, float32 19 | The shape is (B, H, L_query, num_buckets) 20 | index: torch.Tensor, int32 21 | The shape is (L_query, L_key) 22 | 23 | where B is the batch size, and H is the number of attention heads. 24 | 25 | Returns 26 | ------- 27 | Y: torch.Tensor, float32 28 | The shape is (B, H, L_query, L_key) 29 | ''' 30 | L_query, L_key = index.shape 31 | num_buckets = input.size(-1) 32 | B = len(input) 33 | offset = torch.arange(0, L_query * num_buckets, num_buckets).view(-1, 1) 34 | return input.flatten(2)[:, :, (index + offset).flatten()].view(B, -1, L_query, L_key) 35 | ``` 36 | -------------------------------------------------------------------------------- /iRPE/DETR-with-iRPE/rpe_ops/setup.py: -------------------------------------------------------------------------------- 1 | """Build iRPE (image RPE) Functions""" 2 | from setuptools import setup, Extension 3 | import torch 4 | from torch.utils import cpp_extension 5 | 6 | ext_t = cpp_extension.CppExtension 7 | ext_fnames = ['rpe_index.cpp'] 8 | define_macros = [] 9 | extra_compile_args = dict(cxx=['-fopenmp', '-O3'], 10 | nvcc=['-O3']) 11 | 12 | if torch.cuda.is_available(): 13 | ext_t = cpp_extension.CUDAExtension 14 | ext_fnames.append('rpe_index_cuda.cu') 15 | define_macros.append(('WITH_CUDA', None)) 16 | 17 | setup(name='rpe_index', 18 | version="1.2.0", 19 | ext_modules=[ext_t( 20 | 'rpe_index_cpp', 21 | ext_fnames, 22 | define_macros=define_macros, 23 | extra_compile_args=extra_compile_args, 24 | )], 25 | cmdclass={'build_ext': cpp_extension.BuildExtension}) 26 | -------------------------------------------------------------------------------- /iRPE/DETR-with-iRPE/util/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | -------------------------------------------------------------------------------- /iRPE/DeiT-with-iRPE/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | **/__pycache__/** 3 | imnet_resnet50_scratch/timm_temp/ 4 | .dumbo.json 5 | checkpoints/ 6 | -------------------------------------------------------------------------------- /iRPE/DeiT-with-iRPE/hubconf.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-present, Facebook, Inc. 2 | # All rights reserved. 3 | from models import * 4 | 5 | dependencies = ["torch", "torchvision", "timm"] 6 | -------------------------------------------------------------------------------- /iRPE/DeiT-with-iRPE/requirements.txt: -------------------------------------------------------------------------------- 1 | torch>=1.7.0 2 | torchvision>=0.8.1 3 | timm>=0.3.2 4 | easydict 5 | -------------------------------------------------------------------------------- /iRPE/DeiT-with-iRPE/rpe_ops/README.md: -------------------------------------------------------------------------------- 1 | # 2D RPE Operators 2 | 3 | ## Build iRPE operators implemented by CUDA. 4 | Although iRPE can be implemented by PyTorch native functions, the backward speed of PyTorch index function is very slow. We implement CUDA operators for more efficient training and recommend to build it. `nvcc` is necessary to build CUDA operators. 5 | ```bash 6 | cd rpe_ops/ 7 | python setup.py install --user 8 | ``` 9 | 10 | ## rpe\_index 11 | The function [`rpe_index`](./rpe_index.py#L5) is equal to 12 | ```python 13 | def rpe_index(input, index): 14 | '''Y[b, h, i, j] = input[b, h, i, index[i, j]] 15 | 16 | Parameters 17 | ---------- 18 | input: torch.Tensor, float32 19 | The shape is (B, H, L_query, num_buckets) 20 | index: torch.Tensor, int32 21 | The shape is (L_query, L_key) 22 | 23 | where B is the batch size, and H is the number of attention heads. 24 | 25 | Returns 26 | ------- 27 | Y: torch.Tensor, float32 28 | The shape is (B, H, L_query, L_key) 29 | ''' 30 | L_query, L_key = index.shape 31 | num_buckets = input.size(-1) 32 | B = len(input) 33 | offset = torch.arange(0, L_query * num_buckets, num_buckets).view(-1, 1) 34 | return input.flatten(2)[:, :, (index + offset).flatten()].view(B, -1, L_query, L_key) 35 | ``` 36 | -------------------------------------------------------------------------------- /iRPE/DeiT-with-iRPE/rpe_ops/setup.py: -------------------------------------------------------------------------------- 1 | """Build iRPE (image RPE) Functions""" 2 | from setuptools import setup, Extension 3 | import torch 4 | from torch.utils import cpp_extension 5 | 6 | ext_t = cpp_extension.CppExtension 7 | ext_fnames = ['rpe_index.cpp'] 8 | define_macros = [] 9 | extra_compile_args = dict(cxx=['-fopenmp', '-O3'], 10 | nvcc=['-O3']) 11 | 12 | if torch.cuda.is_available(): 13 | ext_t = cpp_extension.CUDAExtension 14 | ext_fnames.append('rpe_index_cuda.cu') 15 | define_macros.append(('WITH_CUDA', None)) 16 | 17 | setup(name='rpe_index', 18 | version="1.2.0", 19 | ext_modules=[ext_t( 20 | 'rpe_index_cpp', 21 | ext_fnames, 22 | define_macros=define_macros, 23 | extra_compile_args=extra_compile_args, 24 | )], 25 | cmdclass={'build_ext': cpp_extension.BuildExtension}) 26 | -------------------------------------------------------------------------------- /iRPE/DeiT-with-iRPE/tox.ini: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | ignore = F401,E402,F403,W503,W504 4 | -------------------------------------------------------------------------------- /iRPE/iRPE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cream/4a13c4091e78f9abd2160e7e01c02e48c1cf8fb9/iRPE/iRPE.png --------------------------------------------------------------------------------