├── .gitignore ├── README.md ├── assets ├── DATA.md ├── INSTALL.md ├── MODEL_ZOO.md ├── TEST.md ├── TRAIN.md └── images │ ├── Cross-Category-Performance.png │ ├── Cross-Dataset-Performance.png │ ├── Generalization_Visualization.jpg │ ├── Hierarchical_SA_1B_v3.jpg │ ├── SAM-Comparison.png │ ├── data_vis.jpg │ ├── eye-fill.svg │ ├── hierarchical_data_vis.jpg │ ├── object-part-tasks.png │ ├── pipeline.png │ └── traditional-image-tasks.png ├── configs ├── Base-RCNN-C4.yaml ├── Base-RCNN-DilatedC5.yaml ├── Base-RCNN-FPN.yaml ├── Base-RetinaNet.yaml ├── COCO-Detection │ ├── fast_rcnn_R_50_FPN_1x.yaml │ ├── faster_rcnn_R_101_C4_3x.yaml │ ├── faster_rcnn_R_101_DC5_3x.yaml │ ├── faster_rcnn_R_101_FPN_3x.yaml │ ├── faster_rcnn_R_50_C4_1x.yaml │ ├── faster_rcnn_R_50_C4_3x.yaml │ ├── faster_rcnn_R_50_DC5_1x.yaml │ ├── faster_rcnn_R_50_DC5_3x.yaml │ ├── faster_rcnn_R_50_FPN_1x.yaml │ ├── faster_rcnn_R_50_FPN_3x.yaml │ ├── faster_rcnn_X_101_32x8d_FPN_3x.yaml │ ├── fcos_R_50_FPN_1x.py │ ├── retinanet_R_101_FPN_3x.yaml │ ├── retinanet_R_50_FPN_1x.py │ ├── retinanet_R_50_FPN_1x.yaml │ ├── retinanet_R_50_FPN_3x.yaml │ ├── rpn_R_50_C4_1x.yaml │ └── rpn_R_50_FPN_1x.yaml ├── COCO-InstanceSegmentation │ ├── mask_rcnn_R_101_C4_3x.yaml │ ├── mask_rcnn_R_101_DC5_3x.yaml │ ├── mask_rcnn_R_101_FPN_3x.yaml │ ├── mask_rcnn_R_50_C4_1x.py │ ├── mask_rcnn_R_50_C4_1x.yaml │ ├── mask_rcnn_R_50_C4_3x.yaml │ ├── mask_rcnn_R_50_DC5_1x.yaml │ ├── mask_rcnn_R_50_DC5_3x.yaml │ ├── mask_rcnn_R_50_FPN_1x.py │ ├── mask_rcnn_R_50_FPN_1x.yaml │ ├── mask_rcnn_R_50_FPN_1x_giou.yaml │ ├── mask_rcnn_R_50_FPN_3x.yaml │ ├── mask_rcnn_X_101_32x8d_FPN_3x.yaml │ ├── mask_rcnn_regnetx_4gf_dds_fpn_1x.py │ └── mask_rcnn_regnety_4gf_dds_fpn_1x.py ├── COCO-Keypoints │ ├── Base-Keypoint-RCNN-FPN.yaml │ ├── keypoint_rcnn_R_101_FPN_3x.yaml │ ├── keypoint_rcnn_R_50_FPN_1x.py │ ├── keypoint_rcnn_R_50_FPN_1x.yaml │ ├── keypoint_rcnn_R_50_FPN_3x.yaml │ └── keypoint_rcnn_X_101_32x8d_FPN_3x.yaml ├── COCO-PanopticSegmentation │ ├── Base-Panoptic-FPN.yaml │ ├── panoptic_fpn_R_101_3x.yaml │ ├── panoptic_fpn_R_50_1x.py │ ├── panoptic_fpn_R_50_1x.yaml │ └── panoptic_fpn_R_50_3x.yaml ├── Cityscapes │ └── mask_rcnn_R_50_FPN.yaml ├── Detectron1-Comparisons │ ├── README.md │ ├── faster_rcnn_R_50_FPN_noaug_1x.yaml │ ├── keypoint_rcnn_R_50_FPN_1x.yaml │ └── mask_rcnn_R_50_FPN_noaug_1x.yaml ├── LVISv0.5-InstanceSegmentation │ ├── mask_rcnn_R_101_FPN_1x.yaml │ ├── mask_rcnn_R_50_FPN_1x.yaml │ └── mask_rcnn_X_101_32x8d_FPN_1x.yaml ├── LVISv1-InstanceSegmentation │ ├── mask_rcnn_R_101_FPN_1x.yaml │ ├── mask_rcnn_R_50_FPN_1x.yaml │ └── mask_rcnn_X_101_32x8d_FPN_1x.yaml ├── Misc │ ├── cascade_mask_rcnn_R_50_FPN_1x.yaml │ ├── cascade_mask_rcnn_R_50_FPN_3x.yaml │ ├── cascade_mask_rcnn_X_152_32x8d_FPN_IN5k_gn_dconv.yaml │ ├── mask_rcnn_R_50_FPN_1x_cls_agnostic.yaml │ ├── mask_rcnn_R_50_FPN_1x_dconv_c3-c5.yaml │ ├── mask_rcnn_R_50_FPN_3x_dconv_c3-c5.yaml │ ├── mask_rcnn_R_50_FPN_3x_gn.yaml │ ├── mask_rcnn_R_50_FPN_3x_syncbn.yaml │ ├── mmdet_mask_rcnn_R_50_FPN_1x.py │ ├── panoptic_fpn_R_101_dconv_cascade_gn_3x.yaml │ ├── scratch_mask_rcnn_R_50_FPN_3x_gn.yaml │ ├── scratch_mask_rcnn_R_50_FPN_9x_gn.yaml │ ├── scratch_mask_rcnn_R_50_FPN_9x_syncbn.yaml │ ├── semantic_R_50_FPN_1x.yaml │ └── torchvision_imagenet_R_50.py ├── PascalVOC-Detection │ ├── faster_rcnn_R_50_C4.yaml │ └── faster_rcnn_R_50_FPN.yaml ├── common │ ├── README.md │ ├── coco_schedule.py │ ├── data │ │ ├── coco.py │ │ ├── coco_keypoint.py │ │ └── coco_panoptic_separated.py │ ├── models │ │ ├── cascade_rcnn.py │ │ ├── fcos.py │ │ ├── keypoint_rcnn_fpn.py │ │ ├── mask_rcnn_c4.py │ │ ├── mask_rcnn_fpn.py │ │ ├── panoptic_fpn.py │ │ └── retinanet.py │ ├── optim.py │ └── train.py ├── new_baselines │ ├── mask_rcnn_R_101_FPN_100ep_LSJ.py │ ├── mask_rcnn_R_101_FPN_200ep_LSJ.py │ ├── mask_rcnn_R_101_FPN_400ep_LSJ.py │ ├── mask_rcnn_R_50_FPN_100ep_LSJ.py │ ├── mask_rcnn_R_50_FPN_200ep_LSJ.py │ ├── mask_rcnn_R_50_FPN_400ep_LSJ.py │ ├── mask_rcnn_R_50_FPN_50ep_LSJ.py │ ├── mask_rcnn_regnetx_4gf_dds_FPN_100ep_LSJ.py │ ├── mask_rcnn_regnetx_4gf_dds_FPN_200ep_LSJ.py │ ├── mask_rcnn_regnetx_4gf_dds_FPN_400ep_LSJ.py │ ├── mask_rcnn_regnety_4gf_dds_FPN_100ep_LSJ.py │ ├── mask_rcnn_regnety_4gf_dds_FPN_200ep_LSJ.py │ └── mask_rcnn_regnety_4gf_dds_FPN_400ep_LSJ.py └── quick_schedules │ ├── README.md │ ├── cascade_mask_rcnn_R_50_FPN_inference_acc_test.yaml │ ├── cascade_mask_rcnn_R_50_FPN_instant_test.yaml │ ├── fast_rcnn_R_50_FPN_inference_acc_test.yaml │ ├── fast_rcnn_R_50_FPN_instant_test.yaml │ ├── keypoint_rcnn_R_50_FPN_inference_acc_test.yaml │ ├── keypoint_rcnn_R_50_FPN_instant_test.yaml │ ├── keypoint_rcnn_R_50_FPN_normalized_training_acc_test.yaml │ ├── keypoint_rcnn_R_50_FPN_training_acc_test.yaml │ ├── mask_rcnn_R_50_C4_GCV_instant_test.yaml │ ├── mask_rcnn_R_50_C4_inference_acc_test.yaml │ ├── mask_rcnn_R_50_C4_instant_test.yaml │ ├── mask_rcnn_R_50_C4_training_acc_test.yaml │ ├── mask_rcnn_R_50_DC5_inference_acc_test.yaml │ ├── mask_rcnn_R_50_FPN_inference_acc_test.yaml │ ├── mask_rcnn_R_50_FPN_instant_test.yaml │ ├── mask_rcnn_R_50_FPN_pred_boxes_training_acc_test.yaml │ ├── mask_rcnn_R_50_FPN_training_acc_test.yaml │ ├── panoptic_fpn_R_50_inference_acc_test.yaml │ ├── panoptic_fpn_R_50_instant_test.yaml │ ├── panoptic_fpn_R_50_training_acc_test.yaml │ ├── retinanet_R_50_FPN_inference_acc_test.yaml │ ├── retinanet_R_50_FPN_instant_test.yaml │ ├── rpn_R_50_FPN_inference_acc_test.yaml │ ├── rpn_R_50_FPN_instant_test.yaml │ ├── semantic_R_50_FPN_inference_acc_test.yaml │ ├── semantic_R_50_FPN_instant_test.yaml │ └── semantic_R_50_FPN_training_acc_test.yaml ├── datasets └── visual_genome │ ├── vg_all_categories.txt │ ├── vg_object_category.txt │ └── vg_part_category.txt ├── demo ├── README.md ├── demo.py └── predictor.py ├── detectron2 ├── _C.cpython-310-x86_64-linux-gnu.so ├── _C.cpython-37m-x86_64-linux-gnu.so ├── _C.cpython-38-x86_64-linux-gnu.so ├── _C.cpython-39-x86_64-linux-gnu.so ├── __init__.py ├── checkpoint │ ├── __init__.py │ ├── c2_model_loading.py │ ├── catalog.py │ ├── detection_checkpoint.py │ └── hdfs_checkpoint.py ├── config │ ├── __init__.py │ ├── compat.py │ ├── config.py │ ├── defaults.py │ ├── instantiate.py │ └── lazy.py ├── data │ ├── __init__.py │ ├── benchmark.py │ ├── build.py │ ├── catalog.py │ ├── common.py │ ├── dataset_mapper.py │ ├── datasets │ │ ├── README.md │ │ ├── __init__.py │ │ ├── builtin.py │ │ ├── builtin_meta.py │ │ ├── cityscapes.py │ │ ├── cityscapes_panoptic.py │ │ ├── coco.py │ │ ├── coco_panoptic.py │ │ ├── lvis.py │ │ ├── lvis_v0_5_categories.py │ │ ├── lvis_v1_categories.py │ │ ├── pascal_voc.py │ │ └── register_coco.py │ ├── detection_utils.py │ ├── samplers │ │ ├── __init__.py │ │ ├── distributed_sampler.py │ │ └── grouped_batch_sampler.py │ └── transforms │ │ ├── __init__.py │ │ ├── augmentation.py │ │ ├── augmentation_impl.py │ │ └── transform.py ├── engine │ ├── __init__.py │ ├── defaults.py │ ├── hooks.py │ ├── launch.py │ └── train_loop.py ├── evaluation │ ├── __init__.py │ ├── cityscapes_evaluation.py │ ├── coco_evaluation.py │ ├── evaluator.py │ ├── fast_eval_api.py │ ├── lvis_eval.py │ ├── lvis_evaluation.py │ ├── panoptic_evaluation.py │ ├── pascal_voc_evaluation.py │ ├── refcocoeval.py │ ├── rotated_coco_evaluation.py │ ├── sem_seg_evaluation.py │ └── testing.py ├── export │ ├── README.md │ ├── __init__.py │ ├── api.py │ ├── c10.py │ ├── caffe2_export.py │ ├── caffe2_inference.py │ ├── caffe2_modeling.py │ ├── caffe2_patch.py │ ├── flatten.py │ ├── shared.py │ ├── torchscript.py │ └── torchscript_patch.py ├── layers │ ├── __init__.py │ ├── aspp.py │ ├── batch_norm.py │ ├── blocks.py │ ├── csrc │ │ ├── README.md │ │ ├── ROIAlignRotated │ │ │ ├── ROIAlignRotated.h │ │ │ ├── ROIAlignRotated_cpu.cpp │ │ │ └── ROIAlignRotated_cuda.cu │ │ ├── box_iou_rotated │ │ │ ├── box_iou_rotated.h │ │ │ ├── box_iou_rotated_cpu.cpp │ │ │ ├── box_iou_rotated_cuda.cu │ │ │ └── box_iou_rotated_utils.h │ │ ├── cocoeval │ │ │ ├── cocoeval.cpp │ │ │ └── cocoeval.h │ │ ├── cuda_version.cu │ │ ├── deformable │ │ │ ├── deform_conv.h │ │ │ ├── deform_conv_cuda.cu │ │ │ └── deform_conv_cuda_kernel.cu │ │ ├── nms_rotated │ │ │ ├── nms_rotated.h │ │ │ ├── nms_rotated_cpu.cpp │ │ │ └── nms_rotated_cuda.cu │ │ └── vision.cpp │ ├── deform_conv.py │ ├── losses.py │ ├── mask_ops.py │ ├── nms.py │ ├── roi_align.py │ ├── roi_align_rotated.py │ ├── rotated_boxes.py │ ├── shape_spec.py │ └── wrappers.py ├── model_zoo │ ├── __init__.py │ ├── configs │ └── model_zoo.py ├── modeling │ ├── __init__.py │ ├── anchor_generator.py │ ├── backbone │ │ ├── __init__.py │ │ ├── backbone.py │ │ ├── build.py │ │ ├── fpn.py │ │ ├── regnet.py │ │ └── resnet.py │ ├── box_regression.py │ ├── matcher.py │ ├── meta_arch │ │ ├── __init__.py │ │ ├── build.py │ │ ├── dense_detector.py │ │ ├── fcos.py │ │ ├── panoptic_fpn.py │ │ ├── rcnn.py │ │ ├── retinanet.py │ │ └── semantic_seg.py │ ├── mmdet_wrapper.py │ ├── poolers.py │ ├── postprocessing.py │ ├── proposal_generator │ │ ├── __init__.py │ │ ├── build.py │ │ ├── proposal_utils.py │ │ ├── rpn.py │ │ └── rrpn.py │ ├── roi_heads │ │ ├── __init__.py │ │ ├── box_head.py │ │ ├── cascade_rcnn.py │ │ ├── fast_rcnn.py │ │ ├── keypoint_head.py │ │ ├── mask_head.py │ │ ├── roi_heads.py │ │ └── rotated_fast_rcnn.py │ ├── sampling.py │ └── test_time_augmentation.py ├── projects │ ├── README.md │ └── __init__.py ├── solver │ ├── __init__.py │ ├── build.py │ └── lr_scheduler.py ├── structures │ ├── __init__.py │ ├── boxes.py │ ├── image_list.py │ ├── instances.py │ ├── keypoints.py │ ├── masks.py │ └── rotated_boxes.py ├── tracking │ ├── __init__.py │ ├── base_tracker.py │ ├── bbox_iou_tracker.py │ ├── hungarian_tracker.py │ ├── iou_weighted_hungarian_bbox_iou_tracker.py │ ├── utils.py │ └── vanilla_hungarian_bbox_iou_tracker.py └── utils │ ├── README.md │ ├── __init__.py │ ├── analysis.py │ ├── collect_env.py │ ├── colormap.py │ ├── comm.py │ ├── develop.py │ ├── env.py │ ├── events.py │ ├── file_io.py │ ├── logger.py │ ├── memory.py │ ├── registry.py │ ├── serialize.py │ ├── testing.py │ ├── video_visualizer.py │ └── visualizer.py ├── dev ├── README.md ├── linter.sh ├── packaging │ ├── README.md │ ├── build_all_wheels.sh │ ├── build_wheel.sh │ ├── gen_install_table.py │ ├── gen_wheel_index.sh │ └── pkg_helpers.bash ├── parse_results.sh ├── run_inference_tests.sh └── run_instant_tests.sh ├── docker ├── Dockerfile ├── README.md ├── deploy.Dockerfile └── docker-compose.yml ├── docs ├── .gitignore ├── Makefile ├── README.md ├── _static │ └── css │ │ └── custom.css ├── conf.py ├── index.rst ├── modules │ ├── checkpoint.rst │ ├── config.rst │ ├── data.rst │ ├── data_transforms.rst │ ├── engine.rst │ ├── evaluation.rst │ ├── export.rst │ ├── fvcore.rst │ ├── index.rst │ ├── layers.rst │ ├── model_zoo.rst │ ├── modeling.rst │ ├── solver.rst │ ├── structures.rst │ └── utils.rst ├── notes │ ├── benchmarks.md │ ├── changelog.md │ ├── compatibility.md │ ├── contributing.md │ └── index.rst ├── requirements.txt └── tutorials │ ├── README.md │ ├── augmentation.md │ ├── builtin_datasets.md │ ├── configs.md │ ├── data_loading.md │ ├── datasets.md │ ├── deployment.md │ ├── evaluation.md │ ├── extend.md │ ├── getting_started.md │ ├── index.rst │ ├── install.md │ ├── lazyconfigs.md │ ├── models.md │ ├── training.md │ └── write-models.md ├── launch.py ├── projects └── PartGLEE │ ├── clip_vit_base_patch32 │ ├── config.json │ ├── merges.txt │ ├── preprocessor_config.json │ ├── special_tokens_map.json │ ├── tokenizer.json │ ├── tokenizer_config.json │ └── vocab.json │ ├── configs │ ├── Inference │ │ ├── RN50 │ │ │ ├── SeginW.yaml │ │ │ ├── ade20k-part-234.yaml │ │ │ ├── coco.yaml │ │ │ ├── paco.yaml │ │ │ ├── partimagenet.yaml │ │ │ ├── pascal-part-116.yaml │ │ │ └── pascal_part.yaml │ │ └── Swin-L │ │ │ ├── coco.yaml │ │ │ └── paco.yaml │ ├── Training │ │ ├── Joint-Training-RN50.yaml │ │ └── Joint-Training-Swin-L.yaml │ └── base_clip_frozen_image_r50.yaml │ ├── partglee │ ├── PartGLEE.py │ ├── __init__.py │ ├── backbone │ │ ├── __init__.py │ │ ├── backbone.py │ │ ├── build.py │ │ ├── davit.py │ │ ├── eva01 copy.py │ │ ├── eva01.py │ │ ├── eva02 copy 2.py │ │ ├── eva02 copy.py │ │ ├── eva02-dino.py │ │ ├── eva02.py │ │ ├── eva_01_utils.py │ │ ├── eva_02_utils copy.py │ │ ├── eva_02_utils.py │ │ ├── focal.py │ │ ├── focal_dw.py │ │ ├── internimage.py │ │ ├── ops_dcnv3 │ │ │ ├── functions │ │ │ │ ├── __init__.py │ │ │ │ └── dcnv3_func.py │ │ │ ├── make.sh │ │ │ ├── modules │ │ │ │ ├── __init__.py │ │ │ │ └── dcnv3.py │ │ │ ├── setup.py │ │ │ ├── src │ │ │ │ ├── cpu │ │ │ │ │ ├── dcnv3_cpu.cpp │ │ │ │ │ └── dcnv3_cpu.h │ │ │ │ ├── cuda │ │ │ │ │ ├── dcnv3_cuda.cu │ │ │ │ │ ├── dcnv3_cuda.h │ │ │ │ │ └── dcnv3_im2col_cuda.cuh │ │ │ │ ├── dcnv3.h │ │ │ │ └── vision.cpp │ │ │ └── test.py │ │ ├── registry.py │ │ ├── resnet.py │ │ ├── swin.py │ │ ├── vit.py │ │ └── vit_utils.py │ ├── body │ │ ├── __init__.py │ │ ├── build.py │ │ ├── decoder │ │ │ ├── __init__.py │ │ │ ├── build.py │ │ │ ├── registry.py │ │ │ ├── seem.py │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── attention_data_struct.py │ │ │ │ ├── attn.py │ │ │ │ └── utils.py │ │ ├── encoder │ │ │ ├── __init__.py │ │ │ ├── build.py │ │ │ ├── ops │ │ │ │ ├── functions │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── ms_deform_attn_func.py │ │ │ │ ├── make.sh │ │ │ │ ├── modules │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── ms_deform_attn.py │ │ │ │ ├── setup.py │ │ │ │ ├── src │ │ │ │ │ ├── cpu │ │ │ │ │ │ ├── ms_deform_attn_cpu.cpp │ │ │ │ │ │ └── ms_deform_attn_cpu.h │ │ │ │ │ ├── cuda │ │ │ │ │ │ ├── ms_deform_attn_cuda.cu │ │ │ │ │ │ ├── ms_deform_attn_cuda.h │ │ │ │ │ │ └── ms_deform_im2col_cuda.cuh │ │ │ │ │ ├── ms_deform_attn.h │ │ │ │ │ └── vision.cpp │ │ │ │ └── test.py │ │ │ ├── registry.py │ │ │ ├── transformer_encoder_deform.py │ │ │ └── transformer_encoder_fpn.py │ │ ├── registry.py │ │ ├── transformer_blocks.py │ │ └── xdecoder_head.py │ ├── config.py │ ├── data │ │ ├── __init__.py │ │ ├── ade20k_evaluation │ │ │ ├── __init__.py │ │ │ ├── generalized_sem_seg_evaluation.py │ │ │ └── utils │ │ │ │ └── post_process_utils.py │ │ ├── augmentation.py │ │ ├── augmentation_vis.py │ │ ├── build.py │ │ ├── coco_dataset_mapper.py │ │ ├── coco_dataset_mapper_uni.py │ │ ├── coco_instance_new_baseline_dataset_mapper.py │ │ ├── coco_panoptic_new_baseline_dataset_mapper.py │ │ ├── custom_dataset_dataloader.py │ │ ├── datasets │ │ │ ├── VisualGenome.py │ │ │ ├── __init__.py │ │ │ ├── ade_part_utils.py │ │ │ ├── bdd100k.py │ │ │ ├── builtin.py │ │ │ ├── burst_video.py │ │ │ ├── coco.py │ │ │ ├── objects365.py │ │ │ ├── objects365_v2.py │ │ │ ├── odinw.py │ │ │ ├── omnilabel.py │ │ │ ├── open_image.py │ │ │ ├── paco.py │ │ │ ├── paco_categories.py │ │ │ ├── partimagenet.py │ │ │ ├── pascal_joint.py │ │ │ ├── pascal_part.py │ │ │ ├── pascal_voc_2010.py │ │ │ ├── refcoco.py │ │ │ ├── register_ade20k_base.py │ │ │ ├── register_ade20k_joint.py │ │ │ ├── register_ade_part_234.py │ │ │ ├── register_coco_panoptic_annos_semseg.py │ │ │ ├── register_partimagenet_joint.py │ │ │ ├── register_partimagenet_semseg.py │ │ │ ├── register_pascal_part_116.py │ │ │ ├── register_pascal_part_open_vocabulary.py │ │ │ ├── register_pascalvoc_base.py │ │ │ ├── register_pascalvoc_joint.py │ │ │ ├── register_seginw_instance.py │ │ │ ├── rvos.py │ │ │ ├── sa1b.py │ │ │ ├── tao.py │ │ │ ├── uvo_image.py │ │ │ ├── uvo_video.py │ │ │ ├── vis.py │ │ │ └── visual_genome_joint.py │ │ ├── instance_evaluation.py │ │ ├── joint_image_dataset_LSJ_mapper.py │ │ ├── joint_new_baseline_dataset_mapper.py │ │ ├── lvis_eval.py │ │ ├── object_part_mapper.py │ │ ├── object_part_mapper_backup.py │ │ ├── omnilabel_eval.py │ │ ├── paco_eval_api │ │ │ ├── __init__.py │ │ │ ├── eval.py │ │ │ ├── paco.py │ │ │ └── results.py │ │ ├── paco_evaluation.py │ │ ├── pascal_part_new_baseline_dataset_mapper.py │ │ ├── pascal_part_openvocabulary_evaluation.py │ │ ├── refcoco_dataset_mapper.py │ │ ├── seginw │ │ │ ├── seginw_categories.py │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── config.py │ │ │ │ ├── misc.py │ │ │ │ └── utils │ │ │ │ ├── Config.py │ │ │ │ ├── __init__.py │ │ │ │ ├── arguments.py │ │ │ │ ├── constants.py │ │ │ │ ├── distributed.py │ │ │ │ ├── misc.py │ │ │ │ ├── model.py │ │ │ │ ├── prompt_engineering.py │ │ │ │ ├── seginw_categories.py │ │ │ │ └── visualizer.py │ │ ├── seginw_dataset_mapper.py │ │ ├── transforms │ │ │ ├── __init__.py │ │ │ ├── augmentation.py │ │ │ ├── augmentation_impl.py │ │ │ └── transform.py │ │ ├── two_crop_mapper.py │ │ ├── uni_video_image_mapper.py │ │ ├── uni_video_pseudo_mapper.py │ │ ├── utils │ │ │ ├── __init__.py │ │ │ ├── paco_query_utils.py │ │ │ └── paco_utils.py │ │ ├── vis_dataset_mapper.py │ │ ├── ytvis_eval copy.py │ │ └── ytvis_eval.py │ ├── language │ │ ├── LangEncoder │ │ │ ├── __init__.py │ │ │ ├── build.py │ │ │ ├── distributed.py │ │ │ ├── model.py │ │ │ ├── registry.py │ │ │ └── transformer.py │ │ ├── __init__.py │ │ ├── build.py │ │ ├── fixvlpencoder.py │ │ ├── loss.py │ │ ├── misc.py │ │ ├── registry.py │ │ └── vlpencoder.py │ ├── models │ │ ├── PartGLEE_Model.py │ │ ├── _CONSTANTS.py │ │ ├── _INFERENCE_CONSTANTS.py │ │ ├── bert_model.py │ │ ├── criterion.py │ │ ├── matcher.py │ │ ├── pixel_decoder │ │ │ ├── __init__.py │ │ │ ├── early_fusion.py │ │ │ ├── maskdino_encoder copy.py │ │ │ ├── maskdino_encoder.py │ │ │ ├── ops │ │ │ │ ├── functions │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── ms_deform_attn_func.py │ │ │ │ ├── make.sh │ │ │ │ ├── modules │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── ms_deform_attn.py │ │ │ │ ├── setup.py │ │ │ │ ├── src │ │ │ │ │ ├── cpu │ │ │ │ │ │ ├── ms_deform_attn_cpu.cpp │ │ │ │ │ │ └── ms_deform_attn_cpu.h │ │ │ │ │ ├── cuda │ │ │ │ │ │ ├── ms_deform_attn_cuda.cu │ │ │ │ │ │ ├── ms_deform_attn_cuda.h │ │ │ │ │ │ └── ms_deform_im2col_cuda.cuh │ │ │ │ │ ├── ms_deform_attn.h │ │ │ │ │ └── vision.cpp │ │ │ │ └── test.py │ │ │ └── position_encoding.py │ │ ├── tracker.py │ │ ├── transformer_decoder │ │ │ ├── __init__.py │ │ │ ├── dino_decoder.py │ │ │ ├── maskdino_decoder.py │ │ │ ├── maskdino_part_decoder.py │ │ │ └── transformer.py │ │ └── vos_utils.py │ ├── modules │ │ ├── __init__.py │ │ ├── attention.py │ │ ├── point_features.py │ │ ├── position_encoding.py │ │ └── postprocessing.py │ └── utils │ │ ├── __init__.py │ │ ├── box_ops.py │ │ ├── config.py │ │ ├── it_contrastive.py │ │ ├── misc.py │ │ ├── point_features.py │ │ └── utils.py │ ├── tools │ ├── convert_sam2coco_rewritresa1b.py │ ├── converter.py │ ├── merge_sa1b.py │ ├── partimagenet_format_json.py │ ├── pascal_part_mat2json.py │ └── pascal_part_one_json.py │ └── train_net.py ├── setup.cfg ├── setup.py ├── tests ├── README.md ├── __init__.py ├── config │ ├── dir1 │ │ ├── dir1_a.py │ │ └── dir1_b.py │ ├── root_cfg.py │ ├── test_instantiate_config.py │ ├── test_lazy_config.py │ └── test_yacs_config.py ├── data │ ├── __init__.py │ ├── test_coco.py │ ├── test_coco_evaluation.py │ ├── test_dataset.py │ ├── test_detection_utils.py │ ├── test_rotation_transform.py │ ├── test_sampler.py │ └── test_transforms.py ├── layers │ ├── __init__.py │ ├── test_blocks.py │ ├── test_deformable.py │ ├── test_losses.py │ ├── test_mask_ops.py │ ├── test_nms.py │ ├── test_nms_rotated.py │ ├── test_roi_align.py │ └── test_roi_align_rotated.py ├── modeling │ ├── __init__.py │ ├── test_anchor_generator.py │ ├── test_backbone.py │ ├── test_box2box_transform.py │ ├── test_fast_rcnn.py │ ├── test_matcher.py │ ├── test_mmdet.py │ ├── test_model_e2e.py │ ├── test_roi_heads.py │ ├── test_roi_pooler.py │ └── test_rpn.py ├── structures │ ├── __init__.py │ ├── test_boxes.py │ ├── test_imagelist.py │ ├── test_instances.py │ ├── test_keypoints.py │ ├── test_masks.py │ └── test_rotated_boxes.py ├── test_checkpoint.py ├── test_engine.py ├── test_events.py ├── test_export_caffe2.py ├── test_export_torchscript.py ├── test_model_analysis.py ├── test_model_zoo.py ├── test_packaging.py ├── test_registry.py ├── test_scheduler.py ├── test_solver.py ├── test_visualizer.py └── tracking │ ├── __init__.py │ ├── test_bbox_iou_tracker.py │ ├── test_hungarian_tracker.py │ ├── test_iou_weighted_hungarian_bbox_iou_tracker.py │ └── test_vanilla_hungarian_bbox_iou_tracker.py └── tools ├── README.md ├── __init__.py ├── analyze_model.py ├── benchmark.py ├── convert-pretrained-swin-model-to-d2.py ├── convert-torchvision-to-d2.py ├── deploy ├── CMakeLists.txt ├── README.md ├── export_model.py └── torchscript_mask_rcnn.cpp ├── lazyconfig_train_net.py ├── lightning_train_net.py ├── plain_train_net.py ├── train_net.py ├── visualize_data.py └── visualize_json_results.py /assets/INSTALL.md: -------------------------------------------------------------------------------- 1 | # INSTALL 2 | 3 | ## Requirements 4 | 5 | We test the codes in the following environments, other versions may also be compatible but Pytorch vision should be >= 1.7 6 | 7 | - CUDA 12.1 8 | - Python 3.9.2 9 | - Pytorch 2.1.0 10 | - Torchvison 0.16.0 11 | 12 | ## Install environment for PartGLEE 13 | 14 | ``` 15 | pip3 install shapely==1.7.1 16 | pip3 install numpy==1.26.4 17 | pip3 install Pillow==8.4.0 18 | pip3 install lvis 19 | pip3 install scipy 20 | pip3 install fairscale 21 | pip3 install einops 22 | pip3 install xformers 23 | pip3 install tensorboard 24 | pip3 install opencv-python-headless 25 | pip3 install timm 26 | pip3 install ftfy 27 | pip3 install transformers==4.36.0 28 | 29 | pip3 install -e . 30 | pip3 install git+https://github.com/wjf5203/cocoapi.git#"egg=pycocotools&subdirectory=PythonAPI" --user 31 | 32 | # Download pretrained Language Model (CLIP text encoder from transformers) 33 | wget -P projects/PartGLEE/clip_vit_base_patch32/ https://huggingface.co/spaces/Junfeng5/GLEE_demo/resolve/main/GLEE/clip_vit_base_patch32/pytorch_model.bin 34 | 35 | # compile Deformable DETR 36 | cd projects/PartGLEE/partglee/models/pixel_decoder/ops/ 37 | python3 setup.py build install --user 38 | ``` 39 | -------------------------------------------------------------------------------- /assets/MODEL_ZOO.md: -------------------------------------------------------------------------------- 1 | # PartGLEE MODEL ZOO 2 | 3 | Here we provide the model weights for PartGLEE joint-trained across multiple hierarchical datasets. Please download our weights through the link below. 4 | 5 | | Name | Backbone | Weight | 6 | | :----------------: | :------------------: | :----------------------------------------------------------: | 7 | | PartGLEE-RN50 | ResNet-50 | [PartGLEE-RN50](https://drive.google.com/file/d/1SK0HsYXBcTvprFAxqxH-lgpkgV67B4UZ/view?usp=drive_link) | 8 | | PartGLEE-SwinL | SwinTransformer-Large | [PartGLEE-SwinL](https://drive.google.com/file/d/1D4my_0SA1f0YR7JOpC-Op92rsiaPtgST/view?usp=drive_link) | -------------------------------------------------------------------------------- /assets/images/Cross-Category-Performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/Cross-Category-Performance.png -------------------------------------------------------------------------------- /assets/images/Cross-Dataset-Performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/Cross-Dataset-Performance.png -------------------------------------------------------------------------------- /assets/images/Generalization_Visualization.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/Generalization_Visualization.jpg -------------------------------------------------------------------------------- /assets/images/Hierarchical_SA_1B_v3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/Hierarchical_SA_1B_v3.jpg -------------------------------------------------------------------------------- /assets/images/SAM-Comparison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/SAM-Comparison.png -------------------------------------------------------------------------------- /assets/images/data_vis.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/data_vis.jpg -------------------------------------------------------------------------------- /assets/images/eye-fill.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /assets/images/hierarchical_data_vis.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/hierarchical_data_vis.jpg -------------------------------------------------------------------------------- /assets/images/object-part-tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/object-part-tasks.png -------------------------------------------------------------------------------- /assets/images/pipeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/pipeline.png -------------------------------------------------------------------------------- /assets/images/traditional-image-tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/assets/images/traditional-image-tasks.png -------------------------------------------------------------------------------- /configs/Base-RCNN-C4.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "GeneralizedRCNN" 3 | RPN: 4 | PRE_NMS_TOPK_TEST: 6000 5 | POST_NMS_TOPK_TEST: 1000 6 | ROI_HEADS: 7 | NAME: "Res5ROIHeads" 8 | DATASETS: 9 | TRAIN: ("coco_2017_train",) 10 | TEST: ("coco_2017_val",) 11 | SOLVER: 12 | IMS_PER_BATCH: 16 13 | BASE_LR: 0.02 14 | STEPS: (60000, 80000) 15 | MAX_ITER: 90000 16 | INPUT: 17 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 18 | VERSION: 2 19 | -------------------------------------------------------------------------------- /configs/Base-RCNN-DilatedC5.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "GeneralizedRCNN" 3 | RESNETS: 4 | OUT_FEATURES: ["res5"] 5 | RES5_DILATION: 2 6 | RPN: 7 | IN_FEATURES: ["res5"] 8 | PRE_NMS_TOPK_TEST: 6000 9 | POST_NMS_TOPK_TEST: 1000 10 | ROI_HEADS: 11 | NAME: "StandardROIHeads" 12 | IN_FEATURES: ["res5"] 13 | ROI_BOX_HEAD: 14 | NAME: "FastRCNNConvFCHead" 15 | NUM_FC: 2 16 | POOLER_RESOLUTION: 7 17 | ROI_MASK_HEAD: 18 | NAME: "MaskRCNNConvUpsampleHead" 19 | NUM_CONV: 4 20 | POOLER_RESOLUTION: 14 21 | DATASETS: 22 | TRAIN: ("coco_2017_train",) 23 | TEST: ("coco_2017_val",) 24 | SOLVER: 25 | IMS_PER_BATCH: 16 26 | BASE_LR: 0.02 27 | STEPS: (60000, 80000) 28 | MAX_ITER: 90000 29 | INPUT: 30 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 31 | VERSION: 2 32 | -------------------------------------------------------------------------------- /configs/Base-RCNN-FPN.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "GeneralizedRCNN" 3 | BACKBONE: 4 | NAME: "build_resnet_fpn_backbone" 5 | RESNETS: 6 | OUT_FEATURES: ["res2", "res3", "res4", "res5"] 7 | FPN: 8 | IN_FEATURES: ["res2", "res3", "res4", "res5"] 9 | ANCHOR_GENERATOR: 10 | SIZES: [[32], [64], [128], [256], [512]] # One size for each in feature map 11 | ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps) 12 | RPN: 13 | IN_FEATURES: ["p2", "p3", "p4", "p5", "p6"] 14 | PRE_NMS_TOPK_TRAIN: 2000 # Per FPN level 15 | PRE_NMS_TOPK_TEST: 1000 # Per FPN level 16 | # Detectron1 uses 2000 proposals per-batch, 17 | # (See "modeling/rpn/rpn_outputs.py" for details of this legacy issue) 18 | # which is approximately 1000 proposals per-image since the default batch size for FPN is 2. 19 | POST_NMS_TOPK_TRAIN: 1000 20 | POST_NMS_TOPK_TEST: 1000 21 | ROI_HEADS: 22 | NAME: "StandardROIHeads" 23 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 24 | ROI_BOX_HEAD: 25 | NAME: "FastRCNNConvFCHead" 26 | NUM_FC: 2 27 | POOLER_RESOLUTION: 7 28 | ROI_MASK_HEAD: 29 | NAME: "MaskRCNNConvUpsampleHead" 30 | NUM_CONV: 4 31 | POOLER_RESOLUTION: 14 32 | DATASETS: 33 | TRAIN: ("coco_2017_train",) 34 | TEST: ("coco_2017_val",) 35 | SOLVER: 36 | IMS_PER_BATCH: 16 37 | BASE_LR: 0.02 38 | STEPS: (60000, 80000) 39 | MAX_ITER: 90000 40 | INPUT: 41 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 42 | VERSION: 2 43 | -------------------------------------------------------------------------------- /configs/Base-RetinaNet.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "RetinaNet" 3 | BACKBONE: 4 | NAME: "build_retinanet_resnet_fpn_backbone" 5 | RESNETS: 6 | OUT_FEATURES: ["res3", "res4", "res5"] 7 | ANCHOR_GENERATOR: 8 | SIZES: !!python/object/apply:eval ["[[x, x * 2**(1.0/3), x * 2**(2.0/3) ] for x in [32, 64, 128, 256, 512 ]]"] 9 | FPN: 10 | IN_FEATURES: ["res3", "res4", "res5"] 11 | RETINANET: 12 | IOU_THRESHOLDS: [0.4, 0.5] 13 | IOU_LABELS: [0, -1, 1] 14 | SMOOTH_L1_LOSS_BETA: 0.0 15 | DATASETS: 16 | TRAIN: ("coco_2017_train",) 17 | TEST: ("coco_2017_val",) 18 | SOLVER: 19 | IMS_PER_BATCH: 16 20 | BASE_LR: 0.01 # Note that RetinaNet uses a different default learning rate 21 | STEPS: (60000, 80000) 22 | MAX_ITER: 90000 23 | INPUT: 24 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 25 | VERSION: 2 26 | -------------------------------------------------------------------------------- /configs/COCO-Detection/fast_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | LOAD_PROPOSALS: True 6 | RESNETS: 7 | DEPTH: 50 8 | PROPOSAL_GENERATOR: 9 | NAME: "PrecomputedProposals" 10 | DATASETS: 11 | TRAIN: ("coco_2017_train",) 12 | PROPOSAL_FILES_TRAIN: ("detectron2://COCO-Detection/rpn_R_50_FPN_1x/137258492/coco_2017_train_box_proposals_21bc3a.pkl", ) 13 | TEST: ("coco_2017_val",) 14 | PROPOSAL_FILES_TEST: ("detectron2://COCO-Detection/rpn_R_50_FPN_1x/137258492/coco_2017_val_box_proposals_ee0dad.pkl", ) 15 | DATALOADER: 16 | # proposals are part of the dataset_dicts, and take a lot of RAM 17 | NUM_WORKERS: 2 18 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_101_C4_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 101 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_101_DC5_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-DilatedC5.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 101 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 101 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_50_C4_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_50_C4_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_50_DC5_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-DilatedC5.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_50_DC5_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-DilatedC5.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | MASK_ON: False 4 | WEIGHTS: "detectron2://ImageNetPretrained/FAIR/X-101-32x8d.pkl" 5 | PIXEL_STD: [57.375, 57.120, 58.395] 6 | RESNETS: 7 | STRIDE_IN_1X1: False # this is a C2 model 8 | NUM_GROUPS: 32 9 | WIDTH_PER_GROUP: 8 10 | DEPTH: 101 11 | SOLVER: 12 | STEPS: (210000, 250000) 13 | MAX_ITER: 270000 14 | -------------------------------------------------------------------------------- /configs/COCO-Detection/fcos_R_50_FPN_1x.py: -------------------------------------------------------------------------------- 1 | from ..common.optim import SGD as optimizer 2 | from ..common.coco_schedule import lr_multiplier_1x as lr_multiplier 3 | from ..common.data.coco import dataloader 4 | from ..common.models.fcos import model 5 | from ..common.train import train 6 | 7 | dataloader.train.mapper.use_instance_mask = False 8 | optimizer.lr = 0.01 9 | 10 | model.backbone.bottom_up.freeze_at = 2 11 | train.init_checkpoint = "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 12 | -------------------------------------------------------------------------------- /configs/COCO-Detection/retinanet_R_101_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RetinaNet.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | SOLVER: 7 | STEPS: (210000, 250000) 8 | MAX_ITER: 270000 9 | -------------------------------------------------------------------------------- /configs/COCO-Detection/retinanet_R_50_FPN_1x.py: -------------------------------------------------------------------------------- 1 | from ..common.optim import SGD as optimizer 2 | from ..common.coco_schedule import lr_multiplier_1x as lr_multiplier 3 | from ..common.data.coco import dataloader 4 | from ..common.models.retinanet import model 5 | from ..common.train import train 6 | 7 | dataloader.train.mapper.use_instance_mask = False 8 | model.backbone.bottom_up.freeze_at = 2 9 | optimizer.lr = 0.01 10 | 11 | train.init_checkpoint = "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 12 | -------------------------------------------------------------------------------- /configs/COCO-Detection/retinanet_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RetinaNet.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | -------------------------------------------------------------------------------- /configs/COCO-Detection/retinanet_R_50_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RetinaNet.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | SOLVER: 7 | STEPS: (210000, 250000) 8 | MAX_ITER: 270000 9 | -------------------------------------------------------------------------------- /configs/COCO-Detection/rpn_R_50_C4_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "ProposalNetwork" 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | MASK_ON: False 6 | RESNETS: 7 | DEPTH: 50 8 | RPN: 9 | PRE_NMS_TOPK_TEST: 12000 10 | POST_NMS_TOPK_TEST: 2000 11 | -------------------------------------------------------------------------------- /configs/COCO-Detection/rpn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "ProposalNetwork" 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | MASK_ON: False 6 | RESNETS: 7 | DEPTH: 50 8 | RPN: 9 | POST_NMS_TOPK_TEST: 2000 10 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_101_C4_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 101 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_101_DC5_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-DilatedC5.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 101 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 101 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x.py: -------------------------------------------------------------------------------- 1 | from ..common.train import train 2 | from ..common.optim import SGD as optimizer 3 | from ..common.coco_schedule import lr_multiplier_1x as lr_multiplier 4 | from ..common.data.coco import dataloader 5 | from ..common.models.mask_rcnn_c4 import model 6 | 7 | model.backbone.freeze_at = 2 8 | train.init_checkpoint = "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 9 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_C4_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-DilatedC5.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-DilatedC5.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.py: -------------------------------------------------------------------------------- 1 | from ..common.optim import SGD as optimizer 2 | from ..common.coco_schedule import lr_multiplier_1x as lr_multiplier 3 | from ..common.data.coco import dataloader 4 | from ..common.models.mask_rcnn_fpn import model 5 | from ..common.train import train 6 | 7 | model.backbone.bottom_up.freeze_at = 2 8 | train.init_checkpoint = "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 9 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x_giou.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | RPN: 8 | BBOX_REG_LOSS_TYPE: "giou" 9 | BBOX_REG_LOSS_WEIGHT: 2.0 10 | ROI_BOX_HEAD: 11 | BBOX_REG_LOSS_TYPE: "giou" 12 | BBOX_REG_LOSS_WEIGHT: 10.0 13 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | SOLVER: 8 | STEPS: (210000, 250000) 9 | MAX_ITER: 270000 10 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | MASK_ON: True 4 | WEIGHTS: "detectron2://ImageNetPretrained/FAIR/X-101-32x8d.pkl" 5 | PIXEL_STD: [57.375, 57.120, 58.395] 6 | RESNETS: 7 | STRIDE_IN_1X1: False # this is a C2 model 8 | NUM_GROUPS: 32 9 | WIDTH_PER_GROUP: 8 10 | DEPTH: 101 11 | SOLVER: 12 | STEPS: (210000, 250000) 13 | MAX_ITER: 270000 14 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_regnetx_4gf_dds_fpn_1x.py: -------------------------------------------------------------------------------- 1 | from ..common.optim import SGD as optimizer 2 | from ..common.coco_schedule import lr_multiplier_1x as lr_multiplier 3 | from ..common.data.coco import dataloader 4 | from ..common.models.mask_rcnn_fpn import model 5 | from ..common.train import train 6 | 7 | from detectron2.config import LazyCall as L 8 | from detectron2.modeling.backbone import RegNet 9 | from detectron2.modeling.backbone.regnet import SimpleStem, ResBottleneckBlock 10 | 11 | 12 | # Replace default ResNet with RegNetX-4GF from the DDS paper. Config source: 13 | # https://github.com/facebookresearch/pycls/blob/2c152a6e5d913e898cca4f0a758f41e6b976714d/configs/dds_baselines/regnetx/RegNetX-4.0GF_dds_8gpu.yaml#L4-L9 # noqa 14 | model.backbone.bottom_up = L(RegNet)( 15 | stem_class=SimpleStem, 16 | stem_width=32, 17 | block_class=ResBottleneckBlock, 18 | depth=23, 19 | w_a=38.65, 20 | w_0=96, 21 | w_m=2.43, 22 | group_width=40, 23 | freeze_at=2, 24 | norm="FrozenBN", 25 | out_features=["s1", "s2", "s3", "s4"], 26 | ) 27 | model.pixel_std = [57.375, 57.120, 58.395] 28 | 29 | optimizer.weight_decay = 5e-5 30 | train.init_checkpoint = ( 31 | "https://dl.fbaipublicfiles.com/pycls/dds_baselines/160906383/RegNetX-4.0GF_dds_8gpu.pyth" 32 | ) 33 | # RegNets benefit from enabling cudnn benchmark mode 34 | train.cudnn_benchmark = True 35 | -------------------------------------------------------------------------------- /configs/COCO-InstanceSegmentation/mask_rcnn_regnety_4gf_dds_fpn_1x.py: -------------------------------------------------------------------------------- 1 | from ..common.optim import SGD as optimizer 2 | from ..common.coco_schedule import lr_multiplier_1x as lr_multiplier 3 | from ..common.data.coco import dataloader 4 | from ..common.models.mask_rcnn_fpn import model 5 | from ..common.train import train 6 | 7 | from detectron2.config import LazyCall as L 8 | from detectron2.modeling.backbone import RegNet 9 | from detectron2.modeling.backbone.regnet import SimpleStem, ResBottleneckBlock 10 | 11 | 12 | # Replace default ResNet with RegNetY-4GF from the DDS paper. Config source: 13 | # https://github.com/facebookresearch/pycls/blob/2c152a6e5d913e898cca4f0a758f41e6b976714d/configs/dds_baselines/regnety/RegNetY-4.0GF_dds_8gpu.yaml#L4-L10 # noqa 14 | model.backbone.bottom_up = L(RegNet)( 15 | stem_class=SimpleStem, 16 | stem_width=32, 17 | block_class=ResBottleneckBlock, 18 | depth=22, 19 | w_a=31.41, 20 | w_0=96, 21 | w_m=2.24, 22 | group_width=64, 23 | se_ratio=0.25, 24 | freeze_at=2, 25 | norm="FrozenBN", 26 | out_features=["s1", "s2", "s3", "s4"], 27 | ) 28 | model.pixel_std = [57.375, 57.120, 58.395] 29 | 30 | optimizer.weight_decay = 5e-5 31 | train.init_checkpoint = ( 32 | "https://dl.fbaipublicfiles.com/pycls/dds_baselines/160906838/RegNetY-4.0GF_dds_8gpu.pyth" 33 | ) 34 | # RegNets benefit from enabling cudnn benchmark mode 35 | train.cudnn_benchmark = True 36 | -------------------------------------------------------------------------------- /configs/COCO-Keypoints/Base-Keypoint-RCNN-FPN.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | KEYPOINT_ON: True 4 | ROI_HEADS: 5 | NUM_CLASSES: 1 6 | ROI_BOX_HEAD: 7 | SMOOTH_L1_BETA: 0.5 # Keypoint AP degrades (though box AP improves) when using plain L1 loss 8 | RPN: 9 | # Detectron1 uses 2000 proposals per-batch, but this option is per-image in detectron2. 10 | # 1000 proposals per-image is found to hurt box AP. 11 | # Therefore we increase it to 1500 per-image. 12 | POST_NMS_TOPK_TRAIN: 1500 13 | DATASETS: 14 | TRAIN: ("keypoints_coco_2017_train",) 15 | TEST: ("keypoints_coco_2017_val",) 16 | -------------------------------------------------------------------------------- /configs/COCO-Keypoints/keypoint_rcnn_R_101_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-Keypoint-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | SOLVER: 7 | STEPS: (210000, 250000) 8 | MAX_ITER: 270000 9 | -------------------------------------------------------------------------------- /configs/COCO-Keypoints/keypoint_rcnn_R_50_FPN_1x.py: -------------------------------------------------------------------------------- 1 | from ..common.optim import SGD as optimizer 2 | from ..common.coco_schedule import lr_multiplier_1x as lr_multiplier 3 | from ..common.data.coco_keypoint import dataloader 4 | from ..common.models.keypoint_rcnn_fpn import model 5 | from ..common.train import train 6 | 7 | model.backbone.bottom_up.freeze_at = 2 8 | train.init_checkpoint = "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 9 | -------------------------------------------------------------------------------- /configs/COCO-Keypoints/keypoint_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-Keypoint-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | -------------------------------------------------------------------------------- /configs/COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-Keypoint-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | SOLVER: 7 | STEPS: (210000, 250000) 8 | MAX_ITER: 270000 9 | -------------------------------------------------------------------------------- /configs/COCO-Keypoints/keypoint_rcnn_X_101_32x8d_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-Keypoint-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/FAIR/X-101-32x8d.pkl" 4 | PIXEL_STD: [57.375, 57.120, 58.395] 5 | RESNETS: 6 | STRIDE_IN_1X1: False # this is a C2 model 7 | NUM_GROUPS: 32 8 | WIDTH_PER_GROUP: 8 9 | DEPTH: 101 10 | SOLVER: 11 | STEPS: (210000, 250000) 12 | MAX_ITER: 270000 13 | -------------------------------------------------------------------------------- /configs/COCO-PanopticSegmentation/Base-Panoptic-FPN.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PanopticFPN" 4 | MASK_ON: True 5 | SEM_SEG_HEAD: 6 | LOSS_WEIGHT: 0.5 7 | DATASETS: 8 | TRAIN: ("coco_2017_train_panoptic_separated",) 9 | TEST: ("coco_2017_val_panoptic_separated",) 10 | DATALOADER: 11 | FILTER_EMPTY_ANNOTATIONS: False 12 | -------------------------------------------------------------------------------- /configs/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-Panoptic-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | SOLVER: 7 | STEPS: (210000, 250000) 8 | MAX_ITER: 270000 9 | -------------------------------------------------------------------------------- /configs/COCO-PanopticSegmentation/panoptic_fpn_R_50_1x.py: -------------------------------------------------------------------------------- 1 | from ..common.optim import SGD as optimizer 2 | from ..common.coco_schedule import lr_multiplier_1x as lr_multiplier 3 | from ..common.data.coco_panoptic_separated import dataloader 4 | from ..common.models.panoptic_fpn import model 5 | from ..common.train import train 6 | 7 | model.backbone.bottom_up.freeze_at = 2 8 | train.init_checkpoint = "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 9 | -------------------------------------------------------------------------------- /configs/COCO-PanopticSegmentation/panoptic_fpn_R_50_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-Panoptic-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | -------------------------------------------------------------------------------- /configs/COCO-PanopticSegmentation/panoptic_fpn_R_50_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-Panoptic-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | SOLVER: 7 | STEPS: (210000, 250000) 8 | MAX_ITER: 270000 9 | -------------------------------------------------------------------------------- /configs/Cityscapes/mask_rcnn_R_50_FPN.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | # WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | # For better, more stable performance initialize from COCO 5 | WEIGHTS: "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl" 6 | MASK_ON: True 7 | ROI_HEADS: 8 | NUM_CLASSES: 8 9 | # This is similar to the setting used in Mask R-CNN paper, Appendix A 10 | # But there are some differences, e.g., we did not initialize the output 11 | # layer using the corresponding classes from COCO 12 | INPUT: 13 | MIN_SIZE_TRAIN: (800, 832, 864, 896, 928, 960, 992, 1024) 14 | MIN_SIZE_TRAIN_SAMPLING: "choice" 15 | MIN_SIZE_TEST: 1024 16 | MAX_SIZE_TRAIN: 2048 17 | MAX_SIZE_TEST: 2048 18 | DATASETS: 19 | TRAIN: ("cityscapes_fine_instance_seg_train",) 20 | TEST: ("cityscapes_fine_instance_seg_val",) 21 | SOLVER: 22 | BASE_LR: 0.01 23 | STEPS: (18000,) 24 | MAX_ITER: 24000 25 | IMS_PER_BATCH: 8 26 | TEST: 27 | EVAL_PERIOD: 8000 28 | -------------------------------------------------------------------------------- /configs/Detectron1-Comparisons/faster_rcnn_R_50_FPN_noaug_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | # Detectron1 uses smooth L1 loss with some magic beta values. 8 | # The defaults are changed to L1 loss in Detectron2. 9 | RPN: 10 | SMOOTH_L1_BETA: 0.1111 11 | ROI_BOX_HEAD: 12 | SMOOTH_L1_BETA: 1.0 13 | POOLER_SAMPLING_RATIO: 2 14 | POOLER_TYPE: "ROIAlign" 15 | INPUT: 16 | # no scale augmentation 17 | MIN_SIZE_TRAIN: (800, ) 18 | -------------------------------------------------------------------------------- /configs/Detectron1-Comparisons/keypoint_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | KEYPOINT_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | NUM_CLASSES: 1 9 | ROI_KEYPOINT_HEAD: 10 | POOLER_RESOLUTION: 14 11 | POOLER_SAMPLING_RATIO: 2 12 | POOLER_TYPE: "ROIAlign" 13 | # Detectron1 uses smooth L1 loss with some magic beta values. 14 | # The defaults are changed to L1 loss in Detectron2. 15 | ROI_BOX_HEAD: 16 | SMOOTH_L1_BETA: 1.0 17 | POOLER_SAMPLING_RATIO: 2 18 | POOLER_TYPE: "ROIAlign" 19 | RPN: 20 | SMOOTH_L1_BETA: 0.1111 21 | # Detectron1 uses 2000 proposals per-batch, but this option is per-image in detectron2 22 | # 1000 proposals per-image is found to hurt box AP. 23 | # Therefore we increase it to 1500 per-image. 24 | POST_NMS_TOPK_TRAIN: 1500 25 | DATASETS: 26 | TRAIN: ("keypoints_coco_2017_train",) 27 | TEST: ("keypoints_coco_2017_val",) 28 | -------------------------------------------------------------------------------- /configs/Detectron1-Comparisons/mask_rcnn_R_50_FPN_noaug_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | # Detectron1 uses smooth L1 loss with some magic beta values. 8 | # The defaults are changed to L1 loss in Detectron2. 9 | RPN: 10 | SMOOTH_L1_BETA: 0.1111 11 | ROI_BOX_HEAD: 12 | SMOOTH_L1_BETA: 1.0 13 | POOLER_SAMPLING_RATIO: 2 14 | POOLER_TYPE: "ROIAlign" 15 | ROI_MASK_HEAD: 16 | POOLER_SAMPLING_RATIO: 2 17 | POOLER_TYPE: "ROIAlign" 18 | INPUT: 19 | # no scale augmentation 20 | MIN_SIZE_TRAIN: (800, ) 21 | -------------------------------------------------------------------------------- /configs/LVISv0.5-InstanceSegmentation/mask_rcnn_R_101_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 101 7 | ROI_HEADS: 8 | NUM_CLASSES: 1230 9 | SCORE_THRESH_TEST: 0.0001 10 | INPUT: 11 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 12 | DATASETS: 13 | TRAIN: ("lvis_v0.5_train",) 14 | TEST: ("lvis_v0.5_val",) 15 | TEST: 16 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 17 | DATALOADER: 18 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 19 | REPEAT_THRESHOLD: 0.001 20 | -------------------------------------------------------------------------------- /configs/LVISv0.5-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | NUM_CLASSES: 1230 9 | SCORE_THRESH_TEST: 0.0001 10 | INPUT: 11 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 12 | DATASETS: 13 | TRAIN: ("lvis_v0.5_train",) 14 | TEST: ("lvis_v0.5_val",) 15 | TEST: 16 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 17 | DATALOADER: 18 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 19 | REPEAT_THRESHOLD: 0.001 20 | -------------------------------------------------------------------------------- /configs/LVISv0.5-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/FAIR/X-101-32x8d.pkl" 4 | PIXEL_STD: [57.375, 57.120, 58.395] 5 | MASK_ON: True 6 | RESNETS: 7 | STRIDE_IN_1X1: False # this is a C2 model 8 | NUM_GROUPS: 32 9 | WIDTH_PER_GROUP: 8 10 | DEPTH: 101 11 | ROI_HEADS: 12 | NUM_CLASSES: 1230 13 | SCORE_THRESH_TEST: 0.0001 14 | INPUT: 15 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 16 | DATASETS: 17 | TRAIN: ("lvis_v0.5_train",) 18 | TEST: ("lvis_v0.5_val",) 19 | TEST: 20 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 21 | DATALOADER: 22 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 23 | REPEAT_THRESHOLD: 0.001 24 | -------------------------------------------------------------------------------- /configs/LVISv1-InstanceSegmentation/mask_rcnn_R_101_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 101 7 | ROI_HEADS: 8 | NUM_CLASSES: 1203 9 | SCORE_THRESH_TEST: 0.0001 10 | INPUT: 11 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 12 | DATASETS: 13 | TRAIN: ("lvis_v1_train",) 14 | TEST: ("lvis_v1_val",) 15 | TEST: 16 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 17 | SOLVER: 18 | STEPS: (120000, 160000) 19 | MAX_ITER: 180000 # 180000 * 16 / 100000 ~ 28.8 epochs 20 | DATALOADER: 21 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 22 | REPEAT_THRESHOLD: 0.001 23 | -------------------------------------------------------------------------------- /configs/LVISv1-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | NUM_CLASSES: 1203 9 | SCORE_THRESH_TEST: 0.0001 10 | INPUT: 11 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 12 | DATASETS: 13 | TRAIN: ("lvis_v1_train",) 14 | TEST: ("lvis_v1_val",) 15 | TEST: 16 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 17 | SOLVER: 18 | STEPS: (120000, 160000) 19 | MAX_ITER: 180000 # 180000 * 16 / 100000 ~ 28.8 epochs 20 | DATALOADER: 21 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 22 | REPEAT_THRESHOLD: 0.001 23 | -------------------------------------------------------------------------------- /configs/LVISv1-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/FAIR/X-101-32x8d.pkl" 4 | PIXEL_STD: [57.375, 57.120, 58.395] 5 | MASK_ON: True 6 | RESNETS: 7 | STRIDE_IN_1X1: False # this is a C2 model 8 | NUM_GROUPS: 32 9 | WIDTH_PER_GROUP: 8 10 | DEPTH: 101 11 | ROI_HEADS: 12 | NUM_CLASSES: 1203 13 | SCORE_THRESH_TEST: 0.0001 14 | INPUT: 15 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 16 | DATASETS: 17 | TRAIN: ("lvis_v1_train",) 18 | TEST: ("lvis_v1_val",) 19 | SOLVER: 20 | STEPS: (120000, 160000) 21 | MAX_ITER: 180000 # 180000 * 16 / 100000 ~ 28.8 epochs 22 | TEST: 23 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 24 | DATALOADER: 25 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 26 | REPEAT_THRESHOLD: 0.001 27 | -------------------------------------------------------------------------------- /configs/Misc/cascade_mask_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | NAME: CascadeROIHeads 9 | ROI_BOX_HEAD: 10 | CLS_AGNOSTIC_BBOX_REG: True 11 | RPN: 12 | POST_NMS_TOPK_TRAIN: 2000 13 | -------------------------------------------------------------------------------- /configs/Misc/cascade_mask_rcnn_R_50_FPN_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | NAME: CascadeROIHeads 9 | ROI_BOX_HEAD: 10 | CLS_AGNOSTIC_BBOX_REG: True 11 | RPN: 12 | POST_NMS_TOPK_TRAIN: 2000 13 | SOLVER: 14 | STEPS: (210000, 250000) 15 | MAX_ITER: 270000 16 | -------------------------------------------------------------------------------- /configs/Misc/cascade_mask_rcnn_X_152_32x8d_FPN_IN5k_gn_dconv.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | MASK_ON: True 4 | WEIGHTS: "catalog://ImageNetPretrained/FAIR/X-152-32x8d-IN5k" 5 | RESNETS: 6 | STRIDE_IN_1X1: False # this is a C2 model 7 | NUM_GROUPS: 32 8 | WIDTH_PER_GROUP: 8 9 | DEPTH: 152 10 | DEFORM_ON_PER_STAGE: [False, True, True, True] 11 | ROI_HEADS: 12 | NAME: "CascadeROIHeads" 13 | ROI_BOX_HEAD: 14 | NAME: "FastRCNNConvFCHead" 15 | NUM_CONV: 4 16 | NUM_FC: 1 17 | NORM: "GN" 18 | CLS_AGNOSTIC_BBOX_REG: True 19 | ROI_MASK_HEAD: 20 | NUM_CONV: 8 21 | NORM: "GN" 22 | RPN: 23 | POST_NMS_TOPK_TRAIN: 2000 24 | SOLVER: 25 | IMS_PER_BATCH: 128 26 | STEPS: (35000, 45000) 27 | MAX_ITER: 50000 28 | BASE_LR: 0.16 29 | INPUT: 30 | MIN_SIZE_TRAIN: (640, 864) 31 | MIN_SIZE_TRAIN_SAMPLING: "range" 32 | MAX_SIZE_TRAIN: 1440 33 | CROP: 34 | ENABLED: True 35 | TEST: 36 | EVAL_PERIOD: 2500 37 | -------------------------------------------------------------------------------- /configs/Misc/mask_rcnn_R_50_FPN_1x_cls_agnostic.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_BOX_HEAD: 8 | CLS_AGNOSTIC_BBOX_REG: True 9 | ROI_MASK_HEAD: 10 | CLS_AGNOSTIC_MASK: True 11 | -------------------------------------------------------------------------------- /configs/Misc/mask_rcnn_R_50_FPN_1x_dconv_c3-c5.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | DEFORM_ON_PER_STAGE: [False, True, True, True] # on Res3,Res4,Res5 8 | DEFORM_MODULATED: False 9 | -------------------------------------------------------------------------------- /configs/Misc/mask_rcnn_R_50_FPN_3x_dconv_c3-c5.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | DEFORM_ON_PER_STAGE: [False, True, True, True] # on Res3,Res4,Res5 8 | DEFORM_MODULATED: False 9 | SOLVER: 10 | STEPS: (210000, 250000) 11 | MAX_ITER: 270000 12 | -------------------------------------------------------------------------------- /configs/Misc/mask_rcnn_R_50_FPN_3x_gn.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "catalog://ImageNetPretrained/FAIR/R-50-GN" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | NORM: "GN" 8 | STRIDE_IN_1X1: False 9 | FPN: 10 | NORM: "GN" 11 | ROI_BOX_HEAD: 12 | NAME: "FastRCNNConvFCHead" 13 | NUM_CONV: 4 14 | NUM_FC: 1 15 | NORM: "GN" 16 | ROI_MASK_HEAD: 17 | NORM: "GN" 18 | SOLVER: 19 | # 3x schedule 20 | STEPS: (210000, 250000) 21 | MAX_ITER: 270000 22 | -------------------------------------------------------------------------------- /configs/Misc/mask_rcnn_R_50_FPN_3x_syncbn.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | NORM: "SyncBN" 8 | STRIDE_IN_1X1: True 9 | FPN: 10 | NORM: "SyncBN" 11 | ROI_BOX_HEAD: 12 | NAME: "FastRCNNConvFCHead" 13 | NUM_CONV: 4 14 | NUM_FC: 1 15 | NORM: "SyncBN" 16 | ROI_MASK_HEAD: 17 | NORM: "SyncBN" 18 | SOLVER: 19 | # 3x schedule 20 | STEPS: (210000, 250000) 21 | MAX_ITER: 270000 22 | TEST: 23 | PRECISE_BN: 24 | ENABLED: True 25 | -------------------------------------------------------------------------------- /configs/Misc/panoptic_fpn_R_101_dconv_cascade_gn_3x.yaml: -------------------------------------------------------------------------------- 1 | # A large PanopticFPN for demo purposes. 2 | # Use GN on backbone to support semantic seg. 3 | # Use Cascade + Deform Conv to improve localization. 4 | _BASE_: "../COCO-PanopticSegmentation/Base-Panoptic-FPN.yaml" 5 | MODEL: 6 | WEIGHTS: "catalog://ImageNetPretrained/FAIR/R-101-GN" 7 | RESNETS: 8 | DEPTH: 101 9 | NORM: "GN" 10 | DEFORM_ON_PER_STAGE: [False, True, True, True] 11 | STRIDE_IN_1X1: False 12 | FPN: 13 | NORM: "GN" 14 | ROI_HEADS: 15 | NAME: CascadeROIHeads 16 | ROI_BOX_HEAD: 17 | CLS_AGNOSTIC_BBOX_REG: True 18 | ROI_MASK_HEAD: 19 | NORM: "GN" 20 | RPN: 21 | POST_NMS_TOPK_TRAIN: 2000 22 | SOLVER: 23 | STEPS: (105000, 125000) 24 | MAX_ITER: 135000 25 | IMS_PER_BATCH: 32 26 | BASE_LR: 0.04 27 | -------------------------------------------------------------------------------- /configs/Misc/scratch_mask_rcnn_R_50_FPN_3x_gn.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "mask_rcnn_R_50_FPN_3x_gn.yaml" 2 | MODEL: 3 | # Train from random initialization. 4 | WEIGHTS: "" 5 | # It makes sense to divide by STD when training from scratch 6 | # But it seems to make no difference on the results and C2's models didn't do this. 7 | # So we keep things consistent with C2. 8 | # PIXEL_STD: [57.375, 57.12, 58.395] 9 | MASK_ON: True 10 | BACKBONE: 11 | FREEZE_AT: 0 12 | # NOTE: Please refer to Rethinking ImageNet Pre-training https://arxiv.org/abs/1811.08883 13 | # to learn what you need for training from scratch. 14 | -------------------------------------------------------------------------------- /configs/Misc/scratch_mask_rcnn_R_50_FPN_9x_gn.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "mask_rcnn_R_50_FPN_3x_gn.yaml" 2 | MODEL: 3 | PIXEL_STD: [57.375, 57.12, 58.395] 4 | WEIGHTS: "" 5 | MASK_ON: True 6 | RESNETS: 7 | STRIDE_IN_1X1: False 8 | BACKBONE: 9 | FREEZE_AT: 0 10 | SOLVER: 11 | # 9x schedule 12 | IMS_PER_BATCH: 64 # 4x the standard 13 | STEPS: (187500, 197500) # last 60/4==15k and last 20/4==5k 14 | MAX_ITER: 202500 # 90k * 9 / 4 15 | BASE_LR: 0.08 16 | TEST: 17 | EVAL_PERIOD: 2500 18 | # NOTE: Please refer to Rethinking ImageNet Pre-training https://arxiv.org/abs/1811.08883 19 | # to learn what you need for training from scratch. 20 | -------------------------------------------------------------------------------- /configs/Misc/scratch_mask_rcnn_R_50_FPN_9x_syncbn.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "mask_rcnn_R_50_FPN_3x_syncbn.yaml" 2 | MODEL: 3 | PIXEL_STD: [57.375, 57.12, 58.395] 4 | WEIGHTS: "" 5 | MASK_ON: True 6 | RESNETS: 7 | STRIDE_IN_1X1: False 8 | BACKBONE: 9 | FREEZE_AT: 0 10 | SOLVER: 11 | # 9x schedule 12 | IMS_PER_BATCH: 64 # 4x the standard 13 | STEPS: (187500, 197500) # last 60/4==15k and last 20/4==5k 14 | MAX_ITER: 202500 # 90k * 9 / 4 15 | BASE_LR: 0.08 16 | TEST: 17 | EVAL_PERIOD: 2500 18 | # NOTE: Please refer to Rethinking ImageNet Pre-training https://arxiv.org/abs/1811.08883 19 | # to learn what you need for training from scratch. 20 | -------------------------------------------------------------------------------- /configs/Misc/semantic_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "SemanticSegmentor" 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | RESNETS: 6 | DEPTH: 50 7 | DATASETS: 8 | TRAIN: ("coco_2017_train_panoptic_stuffonly",) 9 | TEST: ("coco_2017_val_panoptic_stuffonly",) 10 | INPUT: 11 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 12 | -------------------------------------------------------------------------------- /configs/PascalVOC-Detection/faster_rcnn_R_50_C4.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | NUM_CLASSES: 20 9 | INPUT: 10 | MIN_SIZE_TRAIN: (480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800) 11 | MIN_SIZE_TEST: 800 12 | DATASETS: 13 | TRAIN: ('voc_2007_trainval', 'voc_2012_trainval') 14 | TEST: ('voc_2007_test',) 15 | SOLVER: 16 | STEPS: (12000, 16000) 17 | MAX_ITER: 18000 # 17.4 epochs 18 | WARMUP_ITERS: 100 19 | -------------------------------------------------------------------------------- /configs/PascalVOC-Detection/faster_rcnn_R_50_FPN.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | NUM_CLASSES: 20 9 | INPUT: 10 | MIN_SIZE_TRAIN: (480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800) 11 | MIN_SIZE_TEST: 800 12 | DATASETS: 13 | TRAIN: ('voc_2007_trainval', 'voc_2012_trainval') 14 | TEST: ('voc_2007_test',) 15 | SOLVER: 16 | STEPS: (12000, 16000) 17 | MAX_ITER: 18000 # 17.4 epochs 18 | WARMUP_ITERS: 100 19 | -------------------------------------------------------------------------------- /configs/common/README.md: -------------------------------------------------------------------------------- 1 | This directory provides definitions for a few common models, dataloaders, scheduler, 2 | and optimizers that are often used in training. 3 | The definition of these objects are provided in the form of lazy instantiation: 4 | their arguments can be edited by users before constructing the objects. 5 | 6 | They can be imported, or loaded by `model_zoo.get_config` API in users' own configs. 7 | -------------------------------------------------------------------------------- /configs/common/data/coco.py: -------------------------------------------------------------------------------- 1 | from omegaconf import OmegaConf 2 | 3 | import detectron2.data.transforms as T 4 | from detectron2.config import LazyCall as L 5 | from detectron2.data import ( 6 | DatasetMapper, 7 | build_detection_test_loader, 8 | build_detection_train_loader, 9 | get_detection_dataset_dicts, 10 | ) 11 | from detectron2.evaluation import COCOEvaluator 12 | 13 | dataloader = OmegaConf.create() 14 | 15 | dataloader.train = L(build_detection_train_loader)( 16 | dataset=L(get_detection_dataset_dicts)(names="coco_2017_train"), 17 | mapper=L(DatasetMapper)( 18 | is_train=True, 19 | augmentations=[ 20 | L(T.ResizeShortestEdge)( 21 | short_edge_length=(640, 672, 704, 736, 768, 800), 22 | sample_style="choice", 23 | max_size=1333, 24 | ), 25 | L(T.RandomFlip)(horizontal=True), 26 | ], 27 | image_format="BGR", 28 | use_instance_mask=True, 29 | ), 30 | total_batch_size=16, 31 | num_workers=4, 32 | ) 33 | 34 | dataloader.test = L(build_detection_test_loader)( 35 | dataset=L(get_detection_dataset_dicts)(names="coco_2017_val", filter_empty=False), 36 | mapper=L(DatasetMapper)( 37 | is_train=False, 38 | augmentations=[ 39 | L(T.ResizeShortestEdge)(short_edge_length=800, max_size=1333), 40 | ], 41 | image_format="${...train.mapper.image_format}", 42 | ), 43 | num_workers=4, 44 | ) 45 | 46 | dataloader.evaluator = L(COCOEvaluator)( 47 | dataset_name="${..test.dataset.names}", 48 | ) 49 | -------------------------------------------------------------------------------- /configs/common/data/coco_keypoint.py: -------------------------------------------------------------------------------- 1 | from detectron2.data.detection_utils import create_keypoint_hflip_indices 2 | 3 | from .coco import dataloader 4 | 5 | dataloader.train.dataset.min_keypoints = 1 6 | dataloader.train.dataset.names = "keypoints_coco_2017_train" 7 | dataloader.test.dataset.names = "keypoints_coco_2017_val" 8 | 9 | dataloader.train.mapper.update( 10 | use_instance_mask=False, 11 | use_keypoint=True, 12 | keypoint_hflip_indices=create_keypoint_hflip_indices(dataloader.train.dataset.names), 13 | ) 14 | -------------------------------------------------------------------------------- /configs/common/data/coco_panoptic_separated.py: -------------------------------------------------------------------------------- 1 | from detectron2.config import LazyCall as L 2 | from detectron2.evaluation import ( 3 | COCOEvaluator, 4 | COCOPanopticEvaluator, 5 | DatasetEvaluators, 6 | SemSegEvaluator, 7 | ) 8 | 9 | from .coco import dataloader 10 | 11 | dataloader.train.dataset.names = "coco_2017_train_panoptic_separated" 12 | dataloader.train.dataset.filter_empty = False 13 | dataloader.test.dataset.names = "coco_2017_val_panoptic_separated" 14 | 15 | 16 | dataloader.evaluator = [ 17 | L(COCOEvaluator)( 18 | dataset_name="${...test.dataset.names}", 19 | ), 20 | L(SemSegEvaluator)( 21 | dataset_name="${...test.dataset.names}", 22 | ), 23 | L(COCOPanopticEvaluator)( 24 | dataset_name="${...test.dataset.names}", 25 | ), 26 | ] 27 | -------------------------------------------------------------------------------- /configs/common/models/cascade_rcnn.py: -------------------------------------------------------------------------------- 1 | from detectron2.config import LazyCall as L 2 | from detectron2.layers import ShapeSpec 3 | from detectron2.modeling.box_regression import Box2BoxTransform 4 | from detectron2.modeling.matcher import Matcher 5 | from detectron2.modeling.roi_heads import FastRCNNOutputLayers, FastRCNNConvFCHead, CascadeROIHeads 6 | 7 | from .mask_rcnn_fpn import model 8 | 9 | # arguments that don't exist for Cascade R-CNN 10 | [model.roi_heads.pop(k) for k in ["box_head", "box_predictor", "proposal_matcher"]] 11 | 12 | model.roi_heads.update( 13 | _target_=CascadeROIHeads, 14 | box_heads=[ 15 | L(FastRCNNConvFCHead)( 16 | input_shape=ShapeSpec(channels=256, height=7, width=7), 17 | conv_dims=[], 18 | fc_dims=[1024, 1024], 19 | ) 20 | for k in range(3) 21 | ], 22 | box_predictors=[ 23 | L(FastRCNNOutputLayers)( 24 | input_shape=ShapeSpec(channels=1024), 25 | test_score_thresh=0.05, 26 | box2box_transform=L(Box2BoxTransform)(weights=(w1, w1, w2, w2)), 27 | cls_agnostic_bbox_reg=True, 28 | num_classes="${...num_classes}", 29 | ) 30 | for (w1, w2) in [(10, 5), (20, 10), (30, 15)] 31 | ], 32 | proposal_matchers=[ 33 | L(Matcher)(thresholds=[th], labels=[0, 1], allow_low_quality_matches=False) 34 | for th in [0.5, 0.6, 0.7] 35 | ], 36 | ) 37 | -------------------------------------------------------------------------------- /configs/common/models/fcos.py: -------------------------------------------------------------------------------- 1 | from detectron2.modeling.meta_arch.fcos import FCOS, FCOSHead 2 | 3 | from .retinanet import model 4 | 5 | model._target_ = FCOS 6 | 7 | del model.anchor_generator 8 | del model.box2box_transform 9 | del model.anchor_matcher 10 | del model.input_format 11 | 12 | # Use P5 instead of C5 to compute P6/P7 13 | # (Sec 2.2 of https://arxiv.org/abs/2006.09214) 14 | model.backbone.top_block.in_feature = "p5" 15 | model.backbone.top_block.in_channels = 256 16 | 17 | # New score threshold determined based on sqrt(cls_score * centerness) 18 | model.test_score_thresh = 0.2 19 | model.test_nms_thresh = 0.6 20 | 21 | model.head._target_ = FCOSHead 22 | del model.head.num_anchors 23 | model.head.norm = "GN" 24 | -------------------------------------------------------------------------------- /configs/common/models/keypoint_rcnn_fpn.py: -------------------------------------------------------------------------------- 1 | from detectron2.config import LazyCall as L 2 | from detectron2.layers import ShapeSpec 3 | from detectron2.modeling.poolers import ROIPooler 4 | from detectron2.modeling.roi_heads import KRCNNConvDeconvUpsampleHead 5 | 6 | from .mask_rcnn_fpn import model 7 | 8 | [model.roi_heads.pop(x) for x in ["mask_in_features", "mask_pooler", "mask_head"]] 9 | 10 | model.roi_heads.update( 11 | num_classes=1, 12 | keypoint_in_features=["p2", "p3", "p4", "p5"], 13 | keypoint_pooler=L(ROIPooler)( 14 | output_size=14, 15 | scales=(1.0 / 4, 1.0 / 8, 1.0 / 16, 1.0 / 32), 16 | sampling_ratio=0, 17 | pooler_type="ROIAlignV2", 18 | ), 19 | keypoint_head=L(KRCNNConvDeconvUpsampleHead)( 20 | input_shape=ShapeSpec(channels=256, width=14, height=14), 21 | num_keypoints=17, 22 | conv_dims=[512] * 8, 23 | loss_normalizer="visible", 24 | ), 25 | ) 26 | 27 | # Detectron1 uses 2000 proposals per-batch, but this option is per-image in detectron2. 28 | # 1000 proposals per-image is found to hurt box AP. 29 | # Therefore we increase it to 1500 per-image. 30 | model.proposal_generator.post_nms_topk = (1500, 1000) 31 | 32 | # Keypoint AP degrades (though box AP improves) when using plain L1 loss 33 | model.roi_heads.box_predictor.smooth_l1_beta = 0.5 34 | -------------------------------------------------------------------------------- /configs/common/models/panoptic_fpn.py: -------------------------------------------------------------------------------- 1 | from detectron2.config import LazyCall as L 2 | from detectron2.layers import ShapeSpec 3 | from detectron2.modeling import PanopticFPN 4 | from detectron2.modeling.meta_arch.semantic_seg import SemSegFPNHead 5 | 6 | from .mask_rcnn_fpn import model 7 | 8 | model._target_ = PanopticFPN 9 | model.sem_seg_head = L(SemSegFPNHead)( 10 | input_shape={ 11 | f: L(ShapeSpec)(stride=s, channels="${....backbone.out_channels}") 12 | for f, s in zip(["p2", "p3", "p4", "p5"], [4, 8, 16, 32]) 13 | }, 14 | ignore_value=255, 15 | num_classes=54, # COCO stuff + 1 16 | conv_dims=128, 17 | common_stride=4, 18 | loss_weight=0.5, 19 | norm="GN", 20 | ) 21 | -------------------------------------------------------------------------------- /configs/common/optim.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from detectron2.config import LazyCall as L 4 | from detectron2.solver.build import get_default_optimizer_params 5 | 6 | SGD = L(torch.optim.SGD)( 7 | params=L(get_default_optimizer_params)( 8 | # params.model is meant to be set to the model object, before instantiating 9 | # the optimizer. 10 | weight_decay_norm=0.0 11 | ), 12 | lr=0.02, 13 | momentum=0.9, 14 | weight_decay=1e-4, 15 | ) 16 | -------------------------------------------------------------------------------- /configs/common/train.py: -------------------------------------------------------------------------------- 1 | # Common training-related configs that are designed for "tools/lazyconfig_train_net.py" 2 | # You can use your own instead, together with your own train_net.py 3 | train = dict( 4 | output_dir="./output", 5 | init_checkpoint="", 6 | max_iter=90000, 7 | amp=dict(enabled=False), # options for Automatic Mixed Precision 8 | ddp=dict( # options for DistributedDataParallel 9 | broadcast_buffers=False, 10 | find_unused_parameters=False, 11 | fp16_compression=False, 12 | ), 13 | checkpointer=dict(period=5000, max_to_keep=100), # options for PeriodicCheckpointer 14 | eval_period=5000, 15 | log_period=20, 16 | device="cuda" 17 | # ... 18 | ) 19 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_R_101_FPN_100ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_R_50_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | model.backbone.bottom_up.stages.depth = 101 10 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_R_101_FPN_200ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_R_101_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter *= 2 # 100ep -> 200ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone * 2 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_R_101_FPN_400ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_R_101_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter *= 4 # 100ep -> 400ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone * 4 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_R_50_FPN_200ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_R_50_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter *= 2 # 100ep -> 200ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone * 2 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_R_50_FPN_400ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_R_50_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter *= 4 # 100ep -> 400ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone * 4 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_R_50_FPN_50ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_R_50_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter //= 2 # 100ep -> 50ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone // 2 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_regnetx_4gf_dds_FPN_100ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_R_50_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | from detectron2.config import LazyCall as L 9 | from detectron2.modeling.backbone import RegNet 10 | from detectron2.modeling.backbone.regnet import SimpleStem, ResBottleneckBlock 11 | 12 | # Config source: 13 | # https://github.com/facebookresearch/detectron2/blob/main/configs/COCO-InstanceSegmentation/mask_rcnn_regnetx_4gf_dds_fpn_1x.py # noqa 14 | model.backbone.bottom_up = L(RegNet)( 15 | stem_class=SimpleStem, 16 | stem_width=32, 17 | block_class=ResBottleneckBlock, 18 | depth=23, 19 | w_a=38.65, 20 | w_0=96, 21 | w_m=2.43, 22 | group_width=40, 23 | norm="SyncBN", 24 | out_features=["s1", "s2", "s3", "s4"], 25 | ) 26 | model.pixel_std = [57.375, 57.120, 58.395] 27 | 28 | # RegNets benefit from enabling cudnn benchmark mode 29 | train.cudnn_benchmark = True 30 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_regnetx_4gf_dds_FPN_200ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_regnetx_4gf_dds_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter *= 2 # 100ep -> 200ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone * 2 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_regnetx_4gf_dds_FPN_400ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_regnetx_4gf_dds_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter *= 4 # 100ep -> 400ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone * 4 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_regnety_4gf_dds_FPN_100ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_R_50_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | from detectron2.config import LazyCall as L 9 | from detectron2.modeling.backbone import RegNet 10 | from detectron2.modeling.backbone.regnet import SimpleStem, ResBottleneckBlock 11 | 12 | # Config source: 13 | # https://github.com/facebookresearch/detectron2/blob/main/configs/COCO-InstanceSegmentation/mask_rcnn_regnety_4gf_dds_fpn_1x.py # noqa 14 | model.backbone.bottom_up = L(RegNet)( 15 | stem_class=SimpleStem, 16 | stem_width=32, 17 | block_class=ResBottleneckBlock, 18 | depth=22, 19 | w_a=31.41, 20 | w_0=96, 21 | w_m=2.24, 22 | group_width=64, 23 | se_ratio=0.25, 24 | norm="SyncBN", 25 | out_features=["s1", "s2", "s3", "s4"], 26 | ) 27 | model.pixel_std = [57.375, 57.120, 58.395] 28 | 29 | # RegNets benefit from enabling cudnn benchmark mode 30 | train.cudnn_benchmark = True 31 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_regnety_4gf_dds_FPN_200ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_regnety_4gf_dds_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter *= 2 # 100ep -> 200ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone * 2 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/new_baselines/mask_rcnn_regnety_4gf_dds_FPN_400ep_LSJ.py: -------------------------------------------------------------------------------- 1 | from .mask_rcnn_regnety_4gf_dds_FPN_100ep_LSJ import ( 2 | dataloader, 3 | lr_multiplier, 4 | model, 5 | optimizer, 6 | train, 7 | ) 8 | 9 | train.max_iter *= 4 # 100ep -> 400ep 10 | 11 | lr_multiplier.scheduler.milestones = [ 12 | milestone * 4 for milestone in lr_multiplier.scheduler.milestones 13 | ] 14 | lr_multiplier.scheduler.num_updates = train.max_iter 15 | -------------------------------------------------------------------------------- /configs/quick_schedules/README.md: -------------------------------------------------------------------------------- 1 | These are quick configs for performance or accuracy regression tracking purposes. 2 | 3 | * `*instance_test.yaml`: can train on 2 GPUs. They are used to test whether the training can 4 | successfully finish. They are not expected to produce reasonable training results. 5 | * `*inference_acc_test.yaml`: They should be run using `--eval-only`. They run inference using pre-trained models and verify 6 | the results are as expected. 7 | * `*training_acc_test.yaml`: They should be trained on 8 GPUs. They finish in about an hour and verify the training accuracy 8 | is within the normal range. 9 | -------------------------------------------------------------------------------- /configs/quick_schedules/cascade_mask_rcnn_R_50_FPN_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Misc/cascade_mask_rcnn_R_50_FPN_3x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://Misc/cascade_mask_rcnn_R_50_FPN_3x/144998488/model_final_480dd8.pkl" 4 | DATASETS: 5 | TEST: ("coco_2017_val_100",) 6 | TEST: 7 | EXPECTED_RESULTS: [["bbox", "AP", 50.18, 0.02], ["segm", "AP", 43.87, 0.02]] 8 | -------------------------------------------------------------------------------- /configs/quick_schedules/cascade_mask_rcnn_R_50_FPN_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Misc/cascade_mask_rcnn_R_50_FPN_3x.yaml" 2 | DATASETS: 3 | TRAIN: ("coco_2017_val_100",) 4 | TEST: ("coco_2017_val_100",) 5 | SOLVER: 6 | BASE_LR: 0.005 7 | STEPS: (30,) 8 | MAX_ITER: 40 9 | IMS_PER_BATCH: 4 10 | DATALOADER: 11 | NUM_WORKERS: 2 12 | -------------------------------------------------------------------------------- /configs/quick_schedules/fast_rcnn_R_50_FPN_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-Detection/fast_rcnn_R_50_FPN_1x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://COCO-Detection/fast_rcnn_R_50_FPN_1x/137635226/model_final_e5f7ce.pkl" 4 | DATASETS: 5 | TEST: ("coco_2017_val_100",) 6 | TEST: 7 | EXPECTED_RESULTS: [["bbox", "AP", 45.70, 0.02]] 8 | -------------------------------------------------------------------------------- /configs/quick_schedules/fast_rcnn_R_50_FPN_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-Detection/fast_rcnn_R_50_FPN_1x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | DATASETS: 5 | TRAIN: ("coco_2017_val_100",) 6 | PROPOSAL_FILES_TRAIN: ("detectron2://COCO-Detection/rpn_R_50_FPN_1x/137258492/coco_2017_val_box_proposals_ee0dad.pkl", ) 7 | TEST: ("coco_2017_val_100",) 8 | PROPOSAL_FILES_TEST: ("detectron2://COCO-Detection/rpn_R_50_FPN_1x/137258492/coco_2017_val_box_proposals_ee0dad.pkl", ) 9 | SOLVER: 10 | BASE_LR: 0.005 11 | STEPS: (30,) 12 | MAX_ITER: 40 13 | IMS_PER_BATCH: 4 14 | DATALOADER: 15 | NUM_WORKERS: 2 16 | -------------------------------------------------------------------------------- /configs/quick_schedules/keypoint_rcnn_R_50_FPN_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x/137849621/model_final_a6e10b.pkl" 4 | DATASETS: 5 | TEST: ("keypoints_coco_2017_val_100",) 6 | TEST: 7 | EXPECTED_RESULTS: [["bbox", "AP", 52.47, 0.02], ["keypoints", "AP", 67.36, 0.02]] 8 | -------------------------------------------------------------------------------- /configs/quick_schedules/keypoint_rcnn_R_50_FPN_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | KEYPOINT_ON: True 5 | ROI_HEADS: 6 | NUM_CLASSES: 1 7 | DATASETS: 8 | TRAIN: ("keypoints_coco_2017_val_100",) 9 | TEST: ("keypoints_coco_2017_val_100",) 10 | SOLVER: 11 | BASE_LR: 0.005 12 | STEPS: (30,) 13 | MAX_ITER: 40 14 | IMS_PER_BATCH: 4 15 | DATALOADER: 16 | NUM_WORKERS: 2 17 | -------------------------------------------------------------------------------- /configs/quick_schedules/keypoint_rcnn_R_50_FPN_normalized_training_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | KEYPOINT_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | BATCH_SIZE_PER_IMAGE: 256 9 | NUM_CLASSES: 1 10 | ROI_KEYPOINT_HEAD: 11 | POOLER_RESOLUTION: 14 12 | POOLER_SAMPLING_RATIO: 2 13 | NORMALIZE_LOSS_BY_VISIBLE_KEYPOINTS: False 14 | LOSS_WEIGHT: 4.0 15 | ROI_BOX_HEAD: 16 | SMOOTH_L1_BETA: 1.0 # Keypoint AP degrades when using plain L1 loss 17 | RPN: 18 | SMOOTH_L1_BETA: 0.2 # Keypoint AP degrades when using plain L1 loss 19 | DATASETS: 20 | TRAIN: ("keypoints_coco_2017_val",) 21 | TEST: ("keypoints_coco_2017_val",) 22 | INPUT: 23 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 24 | SOLVER: 25 | WARMUP_FACTOR: 0.33333333 26 | WARMUP_ITERS: 100 27 | STEPS: (5500, 5800) 28 | MAX_ITER: 6000 29 | TEST: 30 | EXPECTED_RESULTS: [["bbox", "AP", 55.35, 1.0], ["keypoints", "AP", 76.91, 1.0]] 31 | -------------------------------------------------------------------------------- /configs/quick_schedules/keypoint_rcnn_R_50_FPN_training_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | KEYPOINT_ON: True 5 | RESNETS: 6 | DEPTH: 50 7 | ROI_HEADS: 8 | BATCH_SIZE_PER_IMAGE: 256 9 | NUM_CLASSES: 1 10 | ROI_KEYPOINT_HEAD: 11 | POOLER_RESOLUTION: 14 12 | POOLER_SAMPLING_RATIO: 2 13 | ROI_BOX_HEAD: 14 | SMOOTH_L1_BETA: 1.0 # Keypoint AP degrades when using plain L1 loss 15 | RPN: 16 | SMOOTH_L1_BETA: 0.2 # Keypoint AP degrades when using plain L1 loss 17 | DATASETS: 18 | TRAIN: ("keypoints_coco_2017_val",) 19 | TEST: ("keypoints_coco_2017_val",) 20 | INPUT: 21 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 22 | SOLVER: 23 | WARMUP_FACTOR: 0.33333333 24 | WARMUP_ITERS: 100 25 | STEPS: (5500, 5800) 26 | MAX_ITER: 6000 27 | TEST: 28 | EXPECTED_RESULTS: [["bbox", "AP", 53.5, 1.0], ["keypoints", "AP", 72.4, 1.0]] 29 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_C4_GCV_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | DATASETS: 6 | TRAIN: ("coco_2017_val_100",) 7 | TEST: ("coco_2017_val_100",) 8 | SOLVER: 9 | BASE_LR: 0.001 10 | STEPS: (30,) 11 | MAX_ITER: 40 12 | IMS_PER_BATCH: 4 13 | CLIP_GRADIENTS: 14 | ENABLED: True 15 | CLIP_TYPE: "value" 16 | CLIP_VALUE: 1.0 17 | DATALOADER: 18 | NUM_WORKERS: 2 19 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_C4_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-InstanceSegmentation/mask_rcnn_R_50_C4_3x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_C4_3x/137849525/model_final_4ce675.pkl" 4 | DATASETS: 5 | TEST: ("coco_2017_val_100",) 6 | TEST: 7 | EXPECTED_RESULTS: [["bbox", "AP", 47.37, 0.02], ["segm", "AP", 40.99, 0.02]] 8 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_C4_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | DATASETS: 6 | TRAIN: ("coco_2017_val_100",) 7 | TEST: ("coco_2017_val_100",) 8 | SOLVER: 9 | BASE_LR: 0.001 10 | STEPS: (30,) 11 | MAX_ITER: 40 12 | IMS_PER_BATCH: 4 13 | DATALOADER: 14 | NUM_WORKERS: 2 15 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_C4_training_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | ROI_HEADS: 5 | BATCH_SIZE_PER_IMAGE: 256 6 | MASK_ON: True 7 | DATASETS: 8 | TRAIN: ("coco_2017_val",) 9 | TEST: ("coco_2017_val",) 10 | INPUT: 11 | MIN_SIZE_TRAIN: (600,) 12 | MAX_SIZE_TRAIN: 1000 13 | MIN_SIZE_TEST: 800 14 | MAX_SIZE_TEST: 1000 15 | SOLVER: 16 | IMS_PER_BATCH: 8 # base uses 16 17 | WARMUP_FACTOR: 0.33333 18 | WARMUP_ITERS: 100 19 | STEPS: (11000, 11600) 20 | MAX_ITER: 12000 21 | TEST: 22 | EXPECTED_RESULTS: [["bbox", "AP", 41.88, 0.7], ["segm", "AP", 33.79, 0.5]] 23 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_DC5_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_3x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_DC5_3x/137849551/model_final_84107b.pkl" 4 | DATASETS: 5 | TEST: ("coco_2017_val_100",) 6 | TEST: 7 | EXPECTED_RESULTS: [["bbox", "AP", 47.44, 0.02], ["segm", "AP", 42.94, 0.02]] 8 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_FPN_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl" 4 | DATASETS: 5 | TEST: ("coco_2017_val_100",) 6 | TEST: 7 | EXPECTED_RESULTS: [["bbox", "AP", 47.34, 0.02], ["segm", "AP", 42.67, 0.02], ["bbox_TTA", "AP", 49.11, 0.02], ["segm_TTA", "AP", 45.04, 0.02]] 8 | AUG: 9 | ENABLED: True 10 | MIN_SIZES: (700, 800) # to save some time 11 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_FPN_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: True 5 | DATASETS: 6 | TRAIN: ("coco_2017_val_100",) 7 | TEST: ("coco_2017_val_100",) 8 | SOLVER: 9 | BASE_LR: 0.005 10 | STEPS: (30,) 11 | MAX_ITER: 40 12 | IMS_PER_BATCH: 4 13 | DATALOADER: 14 | NUM_WORKERS: 2 15 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_FPN_pred_boxes_training_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "./mask_rcnn_R_50_FPN_training_acc_test.yaml" 2 | MODEL: 3 | ROI_BOX_HEAD: 4 | TRAIN_ON_PRED_BOXES: True 5 | TEST: 6 | EXPECTED_RESULTS: [["bbox", "AP", 42.6, 1.0], ["segm", "AP", 35.8, 0.8]] 7 | -------------------------------------------------------------------------------- /configs/quick_schedules/mask_rcnn_R_50_FPN_training_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | ROI_HEADS: 5 | BATCH_SIZE_PER_IMAGE: 256 6 | MASK_ON: True 7 | DATASETS: 8 | TRAIN: ("coco_2017_val",) 9 | TEST: ("coco_2017_val",) 10 | INPUT: 11 | MIN_SIZE_TRAIN: (600,) 12 | MAX_SIZE_TRAIN: 1000 13 | MIN_SIZE_TEST: 800 14 | MAX_SIZE_TEST: 1000 15 | SOLVER: 16 | WARMUP_FACTOR: 0.3333333 17 | WARMUP_ITERS: 100 18 | STEPS: (5500, 5800) 19 | MAX_ITER: 6000 20 | TEST: 21 | EXPECTED_RESULTS: [["bbox", "AP", 42.5, 1.0], ["segm", "AP", 35.8, 0.8]] 22 | -------------------------------------------------------------------------------- /configs/quick_schedules/panoptic_fpn_R_50_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-PanopticSegmentation/panoptic_fpn_R_50_3x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://COCO-PanopticSegmentation/panoptic_fpn_R_50_3x/139514569/model_final_c10459.pkl" 4 | DATASETS: 5 | TEST: ("coco_2017_val_100_panoptic_separated",) 6 | TEST: 7 | EXPECTED_RESULTS: [["bbox", "AP", 46.47, 0.02], ["segm", "AP", 43.39, 0.02], ["sem_seg", "mIoU", 42.55, 0.02], ["panoptic_seg", "PQ", 38.99, 0.02]] 8 | -------------------------------------------------------------------------------- /configs/quick_schedules/panoptic_fpn_R_50_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PanopticFPN" 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | MASK_ON: True 6 | RESNETS: 7 | DEPTH: 50 8 | SEM_SEG_HEAD: 9 | LOSS_WEIGHT: 0.5 10 | DATASETS: 11 | TRAIN: ("coco_2017_val_100_panoptic_separated",) 12 | TEST: ("coco_2017_val_100_panoptic_separated",) 13 | SOLVER: 14 | BASE_LR: 0.005 15 | STEPS: (30,) 16 | MAX_ITER: 40 17 | IMS_PER_BATCH: 4 18 | DATALOADER: 19 | NUM_WORKERS: 1 20 | -------------------------------------------------------------------------------- /configs/quick_schedules/panoptic_fpn_R_50_training_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PanopticFPN" 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | MASK_ON: True 6 | RESNETS: 7 | DEPTH: 50 8 | SEM_SEG_HEAD: 9 | LOSS_WEIGHT: 0.5 10 | DATASETS: 11 | TRAIN: ("coco_2017_val_panoptic_separated",) 12 | TEST: ("coco_2017_val_panoptic_separated",) 13 | SOLVER: 14 | BASE_LR: 0.01 15 | WARMUP_FACTOR: 0.001 16 | WARMUP_ITERS: 500 17 | STEPS: (5500,) 18 | MAX_ITER: 7000 19 | TEST: 20 | EXPECTED_RESULTS: [["bbox", "AP", 46.70, 1.1], ["segm", "AP", 39.0, 0.7], ["sem_seg", "mIoU", 64.73, 1.3], ["panoptic_seg", "PQ", 48.13, 0.8]] 21 | -------------------------------------------------------------------------------- /configs/quick_schedules/retinanet_R_50_FPN_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-Detection/retinanet_R_50_FPN_3x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://COCO-Detection/retinanet_R_50_FPN_3x/190397829/model_final_5bd44e.pkl" 4 | DATASETS: 5 | TEST: ("coco_2017_val_100",) 6 | TEST: 7 | EXPECTED_RESULTS: [["bbox", "AP", 44.45, 0.02]] 8 | -------------------------------------------------------------------------------- /configs/quick_schedules/retinanet_R_50_FPN_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-Detection/retinanet_R_50_FPN_1x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | DATASETS: 5 | TRAIN: ("coco_2017_val_100",) 6 | TEST: ("coco_2017_val_100",) 7 | SOLVER: 8 | BASE_LR: 0.005 9 | STEPS: (30,) 10 | MAX_ITER: 40 11 | IMS_PER_BATCH: 4 12 | DATALOADER: 13 | NUM_WORKERS: 2 14 | -------------------------------------------------------------------------------- /configs/quick_schedules/rpn_R_50_FPN_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-Detection/rpn_R_50_FPN_1x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://COCO-Detection/rpn_R_50_FPN_1x/137258492/model_final_02ce48.pkl" 4 | DATASETS: 5 | TEST: ("coco_2017_val_100",) 6 | TEST: 7 | EXPECTED_RESULTS: [["box_proposals", "AR@1000", 58.16, 0.02]] 8 | -------------------------------------------------------------------------------- /configs/quick_schedules/rpn_R_50_FPN_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../COCO-Detection/rpn_R_50_FPN_1x.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | DATASETS: 5 | TRAIN: ("coco_2017_val_100",) 6 | TEST: ("coco_2017_val_100",) 7 | SOLVER: 8 | STEPS: (30,) 9 | MAX_ITER: 40 10 | BASE_LR: 0.005 11 | IMS_PER_BATCH: 4 12 | DATALOADER: 13 | NUM_WORKERS: 2 14 | -------------------------------------------------------------------------------- /configs/quick_schedules/semantic_R_50_FPN_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "SemanticSegmentor" 4 | WEIGHTS: "detectron2://semantic_R_50_FPN_1x/111802073/model_final_c18079783c55a94968edc28b7101c5f0.pkl" 5 | RESNETS: 6 | DEPTH: 50 7 | DATASETS: 8 | TEST: ("coco_2017_val_100_panoptic_stuffonly",) 9 | TEST: 10 | EXPECTED_RESULTS: [["sem_seg", "mIoU", 39.53, 0.02], ["sem_seg", "mACC", 51.50, 0.02]] 11 | -------------------------------------------------------------------------------- /configs/quick_schedules/semantic_R_50_FPN_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "SemanticSegmentor" 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | RESNETS: 6 | DEPTH: 50 7 | DATASETS: 8 | TRAIN: ("coco_2017_val_100_panoptic_stuffonly",) 9 | TEST: ("coco_2017_val_100_panoptic_stuffonly",) 10 | INPUT: 11 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 12 | SOLVER: 13 | BASE_LR: 0.005 14 | STEPS: (30,) 15 | MAX_ITER: 40 16 | IMS_PER_BATCH: 4 17 | DATALOADER: 18 | NUM_WORKERS: 2 19 | -------------------------------------------------------------------------------- /configs/quick_schedules/semantic_R_50_FPN_training_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "SemanticSegmentor" 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | RESNETS: 6 | DEPTH: 50 7 | DATASETS: 8 | TRAIN: ("coco_2017_val_panoptic_stuffonly",) 9 | TEST: ("coco_2017_val_panoptic_stuffonly",) 10 | SOLVER: 11 | BASE_LR: 0.01 12 | WARMUP_FACTOR: 0.001 13 | WARMUP_ITERS: 300 14 | STEPS: (5500,) 15 | MAX_ITER: 7000 16 | TEST: 17 | EXPECTED_RESULTS: [["sem_seg", "mIoU", 76.51, 1.0], ["sem_seg", "mACC", 83.25, 1.0]] 18 | INPUT: 19 | # no scale augmentation 20 | MIN_SIZE_TRAIN: (800, ) 21 | -------------------------------------------------------------------------------- /demo/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Detectron2 Demo 3 | 4 | We provide a command line tool to run a simple demo of builtin configs. 5 | The usage is explained in [GETTING_STARTED.md](../GETTING_STARTED.md). 6 | 7 | See our [blog post](https://ai.facebook.com/blog/-detectron2-a-pytorch-based-modular-object-detection-library-) 8 | for a high-quality demo generated with this tool. 9 | -------------------------------------------------------------------------------- /detectron2/_C.cpython-310-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/detectron2/_C.cpython-310-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /detectron2/_C.cpython-37m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/detectron2/_C.cpython-37m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /detectron2/_C.cpython-38-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/detectron2/_C.cpython-38-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /detectron2/_C.cpython-39-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/detectron2/_C.cpython-39-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /detectron2/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | 3 | from .utils.env import setup_environment 4 | 5 | setup_environment() 6 | 7 | 8 | # This line will be programatically read/write by setup.py. 9 | # Leave them at the bottom of this file and don't touch them. 10 | __version__ = "0.6" 11 | -------------------------------------------------------------------------------- /detectron2/checkpoint/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | # File: 4 | 5 | from . import catalog as _UNUSED # register the handler 6 | from .detection_checkpoint import DetectionCheckpointer 7 | from fvcore.common.checkpoint import Checkpointer, PeriodicCheckpointer 8 | 9 | __all__ = ["Checkpointer", "PeriodicCheckpointer", "DetectionCheckpointer"] -------------------------------------------------------------------------------- /detectron2/config/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .compat import downgrade_config, upgrade_config 3 | from .config import CfgNode, get_cfg, global_cfg, set_global_cfg, configurable 4 | from .instantiate import instantiate 5 | from .lazy import LazyCall, LazyConfig 6 | 7 | __all__ = [ 8 | "CfgNode", 9 | "get_cfg", 10 | "global_cfg", 11 | "set_global_cfg", 12 | "downgrade_config", 13 | "upgrade_config", 14 | "configurable", 15 | "instantiate", 16 | "LazyCall", 17 | "LazyConfig", 18 | ] 19 | 20 | 21 | from detectron2.utils.env import fixup_module_metadata 22 | 23 | fixup_module_metadata(__name__, globals(), __all__) 24 | del fixup_module_metadata 25 | -------------------------------------------------------------------------------- /detectron2/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from . import transforms # isort:skip 3 | 4 | from .build import ( 5 | build_batch_data_loader, 6 | build_detection_test_loader, 7 | build_detection_train_loader, 8 | get_detection_dataset_dicts, 9 | load_proposals_into_dataset, 10 | print_instances_class_histogram, 11 | ) 12 | from .catalog import DatasetCatalog, MetadataCatalog, Metadata 13 | from .common import DatasetFromList, MapDataset, ToIterableDataset 14 | from .dataset_mapper import DatasetMapper 15 | 16 | # ensure the builtin datasets are registered 17 | from . import datasets, samplers # isort:skip 18 | 19 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 20 | -------------------------------------------------------------------------------- /detectron2/data/datasets/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Common Datasets 4 | 5 | The dataset implemented here do not need to load the data into the final format. 6 | It should provide the minimal data structure needed to use the dataset, so it can be very efficient. 7 | 8 | For example, for an image dataset, just provide the file names and labels, but don't read the images. 9 | Let the downstream decide how to read. 10 | -------------------------------------------------------------------------------- /detectron2/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .coco import load_coco_json, load_sem_seg, register_coco_instances, convert_to_coco_json 3 | from .coco_panoptic import register_coco_panoptic, register_coco_panoptic_separated 4 | from .lvis import load_lvis_json, register_lvis_instances, get_lvis_instances_meta 5 | from .pascal_voc import load_voc_instances, register_pascal_voc 6 | from . import builtin as _builtin # ensure the builtin datasets are registered 7 | 8 | 9 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 10 | -------------------------------------------------------------------------------- /detectron2/data/datasets/register_coco.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .coco import register_coco_instances # noqa 3 | from .coco_panoptic import register_coco_panoptic_separated # noqa 4 | -------------------------------------------------------------------------------- /detectron2/data/samplers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .distributed_sampler import ( 3 | InferenceSampler, 4 | RandomSubsetTrainingSampler, 5 | RepeatFactorTrainingSampler, 6 | TrainingSampler, 7 | ) 8 | 9 | from .grouped_batch_sampler import GroupedBatchSampler 10 | 11 | __all__ = [ 12 | "GroupedBatchSampler", 13 | "TrainingSampler", 14 | "RandomSubsetTrainingSampler", 15 | "InferenceSampler", 16 | "RepeatFactorTrainingSampler", 17 | ] 18 | -------------------------------------------------------------------------------- /detectron2/data/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from fvcore.transforms.transform import Transform, TransformList # order them first 3 | from fvcore.transforms.transform import * 4 | from .transform import * 5 | from .augmentation import * 6 | from .augmentation_impl import * 7 | 8 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 9 | 10 | 11 | from detectron2.utils.env import fixup_module_metadata 12 | 13 | fixup_module_metadata(__name__, globals(), __all__) 14 | del fixup_module_metadata 15 | -------------------------------------------------------------------------------- /detectron2/engine/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | 3 | from .launch import * 4 | from .train_loop import * 5 | 6 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 7 | 8 | 9 | # prefer to let hooks and defaults live in separate namespaces (therefore not in __all__) 10 | # but still make them available here 11 | from .hooks import * 12 | from .defaults import * 13 | -------------------------------------------------------------------------------- /detectron2/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .cityscapes_evaluation import CityscapesInstanceEvaluator, CityscapesSemSegEvaluator 3 | from .coco_evaluation import COCOEvaluator 4 | from .rotated_coco_evaluation import RotatedCOCOEvaluator 5 | from .evaluator import DatasetEvaluator, DatasetEvaluators, inference_context, inference_on_dataset 6 | from .lvis_evaluation import LVISEvaluator 7 | from .panoptic_evaluation import COCOPanopticEvaluator 8 | from .pascal_voc_evaluation import PascalVOCDetectionEvaluator 9 | from .sem_seg_evaluation import SemSegEvaluator 10 | from .testing import print_csv_format, verify_results 11 | from .lvis_eval import LVISEval 12 | 13 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 14 | -------------------------------------------------------------------------------- /detectron2/export/README.md: -------------------------------------------------------------------------------- 1 | 2 | This directory contains code to prepare a detectron2 model for deployment. 3 | Currently it supports exporting a detectron2 model to Caffe2 format through ONNX. 4 | 5 | Please see [documentation](https://detectron2.readthedocs.io/tutorials/deployment.html) for its usage. 6 | 7 | 8 | ### Acknowledgements 9 | 10 | Thanks to Mobile Vision team at Facebook for developing the Caffe2 conversion tools. 11 | 12 | Thanks to Computing Platform Department - PAI team at Alibaba Group (@bddpqq, @chenbohua3) who 13 | help export Detectron2 models to TorchScript. 14 | -------------------------------------------------------------------------------- /detectron2/export/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | try: 4 | from caffe2.proto import caffe2_pb2 as _tmp 5 | 6 | # caffe2 is optional 7 | except ImportError: 8 | pass 9 | else: 10 | from .api import * 11 | 12 | from .flatten import TracingAdapter 13 | from .torchscript import scripting_with_instances, dump_torchscript_IR 14 | 15 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 16 | -------------------------------------------------------------------------------- /detectron2/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .batch_norm import FrozenBatchNorm2d, get_norm, NaiveSyncBatchNorm, CycleBatchNormList 3 | from .deform_conv import DeformConv, ModulatedDeformConv 4 | from .mask_ops import paste_masks_in_image 5 | from .nms import batched_nms, batched_nms_rotated, nms, nms_rotated 6 | from .roi_align import ROIAlign, roi_align 7 | from .roi_align_rotated import ROIAlignRotated, roi_align_rotated 8 | from .shape_spec import ShapeSpec 9 | from .wrappers import ( 10 | BatchNorm2d, 11 | Conv2d, 12 | ConvTranspose2d, 13 | cat, 14 | interpolate, 15 | Linear, 16 | nonzero_tuple, 17 | cross_entropy, 18 | shapes_to_tensor, 19 | ) 20 | from .blocks import CNNBlockBase, DepthwiseSeparableConv2d 21 | from .aspp import ASPP 22 | from .losses import ciou_loss, diou_loss 23 | 24 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 25 | -------------------------------------------------------------------------------- /detectron2/layers/csrc/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | To add a new Op: 4 | 5 | 1. Create a new directory 6 | 2. Implement new ops there 7 | 3. Delcare its Python interface in `vision.cpp`. 8 | -------------------------------------------------------------------------------- /detectron2/layers/csrc/box_iou_rotated/box_iou_rotated.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. 2 | #pragma once 3 | #include 4 | 5 | namespace detectron2 { 6 | 7 | at::Tensor box_iou_rotated_cpu( 8 | const at::Tensor& boxes1, 9 | const at::Tensor& boxes2); 10 | 11 | #if defined(WITH_CUDA) || defined(WITH_HIP) 12 | at::Tensor box_iou_rotated_cuda( 13 | const at::Tensor& boxes1, 14 | const at::Tensor& boxes2); 15 | #endif 16 | 17 | // Interface for Python 18 | // inline is needed to prevent multiple function definitions when this header is 19 | // included by different cpps 20 | inline at::Tensor box_iou_rotated( 21 | const at::Tensor& boxes1, 22 | const at::Tensor& boxes2) { 23 | assert(boxes1.device().is_cuda() == boxes2.device().is_cuda()); 24 | if (boxes1.device().is_cuda()) { 25 | #if defined(WITH_CUDA) || defined(WITH_HIP) 26 | return box_iou_rotated_cuda(boxes1.contiguous(), boxes2.contiguous()); 27 | #else 28 | AT_ERROR("Detectron2 is not compiled with GPU support!"); 29 | #endif 30 | } 31 | 32 | return box_iou_rotated_cpu(boxes1.contiguous(), boxes2.contiguous()); 33 | } 34 | 35 | } // namespace detectron2 36 | -------------------------------------------------------------------------------- /detectron2/layers/csrc/box_iou_rotated/box_iou_rotated_cpu.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. 2 | #include "box_iou_rotated.h" 3 | #include "box_iou_rotated_utils.h" 4 | 5 | namespace detectron2 { 6 | 7 | template 8 | void box_iou_rotated_cpu_kernel( 9 | const at::Tensor& boxes1, 10 | const at::Tensor& boxes2, 11 | at::Tensor& ious) { 12 | auto num_boxes1 = boxes1.size(0); 13 | auto num_boxes2 = boxes2.size(0); 14 | 15 | for (int i = 0; i < num_boxes1; i++) { 16 | for (int j = 0; j < num_boxes2; j++) { 17 | ious[i * num_boxes2 + j] = single_box_iou_rotated( 18 | boxes1[i].data_ptr(), boxes2[j].data_ptr()); 19 | } 20 | } 21 | } 22 | 23 | at::Tensor box_iou_rotated_cpu( 24 | // input must be contiguous: 25 | const at::Tensor& boxes1, 26 | const at::Tensor& boxes2) { 27 | auto num_boxes1 = boxes1.size(0); 28 | auto num_boxes2 = boxes2.size(0); 29 | at::Tensor ious = 30 | at::empty({num_boxes1 * num_boxes2}, boxes1.options().dtype(at::kFloat)); 31 | 32 | box_iou_rotated_cpu_kernel(boxes1, boxes2, ious); 33 | 34 | // reshape from 1d array to 2d array 35 | auto shape = std::vector{num_boxes1, num_boxes2}; 36 | return ious.reshape(shape); 37 | } 38 | 39 | } // namespace detectron2 40 | -------------------------------------------------------------------------------- /detectron2/layers/csrc/cuda_version.cu: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. 2 | 3 | #include 4 | 5 | namespace detectron2 { 6 | int get_cudart_version() { 7 | // Not a ROCM platform: Either HIP is not used, or 8 | // it is used, but platform is not ROCM (i.e. it is CUDA) 9 | #if !defined(__HIP_PLATFORM_HCC__) 10 | return CUDART_VERSION; 11 | #else 12 | int version = 0; 13 | 14 | #if HIP_VERSION_MAJOR != 0 15 | // Create a convention similar to that of CUDA, as assumed by other 16 | // parts of the code. 17 | 18 | version = HIP_VERSION_MINOR; 19 | version += (HIP_VERSION_MAJOR * 100); 20 | #else 21 | hipRuntimeGetVersion(&version); 22 | #endif 23 | return version; 24 | #endif 25 | } 26 | } // namespace detectron2 27 | -------------------------------------------------------------------------------- /detectron2/layers/csrc/nms_rotated/nms_rotated.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. 2 | #pragma once 3 | #include 4 | 5 | namespace detectron2 { 6 | 7 | at::Tensor nms_rotated_cpu( 8 | const at::Tensor& dets, 9 | const at::Tensor& scores, 10 | const double iou_threshold); 11 | 12 | #if defined(WITH_CUDA) || defined(WITH_HIP) 13 | at::Tensor nms_rotated_cuda( 14 | const at::Tensor& dets, 15 | const at::Tensor& scores, 16 | const double iou_threshold); 17 | #endif 18 | 19 | // Interface for Python 20 | // inline is needed to prevent multiple function definitions when this header is 21 | // included by different cpps 22 | inline at::Tensor nms_rotated( 23 | const at::Tensor& dets, 24 | const at::Tensor& scores, 25 | const double iou_threshold) { 26 | assert(dets.device().is_cuda() == scores.device().is_cuda()); 27 | if (dets.device().is_cuda()) { 28 | #if defined(WITH_CUDA) || defined(WITH_HIP) 29 | return nms_rotated_cuda( 30 | dets.contiguous(), scores.contiguous(), iou_threshold); 31 | #else 32 | AT_ERROR("Detectron2 is not compiled with GPU support!"); 33 | #endif 34 | } 35 | 36 | return nms_rotated_cpu(dets.contiguous(), scores.contiguous(), iou_threshold); 37 | } 38 | 39 | } // namespace detectron2 40 | -------------------------------------------------------------------------------- /detectron2/layers/rotated_boxes.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from __future__ import absolute_import, division, print_function, unicode_literals 3 | import torch 4 | 5 | 6 | def pairwise_iou_rotated(boxes1, boxes2): 7 | """ 8 | Return intersection-over-union (Jaccard index) of boxes. 9 | 10 | Both sets of boxes are expected to be in 11 | (x_center, y_center, width, height, angle) format. 12 | 13 | Arguments: 14 | boxes1 (Tensor[N, 5]) 15 | boxes2 (Tensor[M, 5]) 16 | 17 | Returns: 18 | iou (Tensor[N, M]): the NxM matrix containing the pairwise 19 | IoU values for every element in boxes1 and boxes2 20 | """ 21 | return torch.ops.detectron2.box_iou_rotated(boxes1, boxes2) 22 | -------------------------------------------------------------------------------- /detectron2/layers/shape_spec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | from collections import namedtuple 4 | 5 | 6 | class ShapeSpec(namedtuple("_ShapeSpec", ["channels", "height", "width", "stride"])): 7 | """ 8 | A simple structure that contains basic shape specification about a tensor. 9 | It is often used as the auxiliary inputs/outputs of models, 10 | to complement the lack of shape inference ability among pytorch modules. 11 | 12 | Attributes: 13 | channels: 14 | height: 15 | width: 16 | stride: 17 | """ 18 | 19 | def __new__(cls, channels=None, height=None, width=None, stride=None): 20 | return super().__new__(cls, channels, height, width, stride) 21 | -------------------------------------------------------------------------------- /detectron2/model_zoo/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | """ 3 | Model Zoo API for Detectron2: a collection of functions to create common model architectures 4 | listed in `MODEL_ZOO.md `_, 5 | and optionally load their pre-trained weights. 6 | """ 7 | 8 | from .model_zoo import get, get_config_file, get_checkpoint_url, get_config 9 | 10 | __all__ = ["get_checkpoint_url", "get", "get_config_file", "get_config"] 11 | -------------------------------------------------------------------------------- /detectron2/model_zoo/configs: -------------------------------------------------------------------------------- 1 | /home/ljy/PartGLEE/configs -------------------------------------------------------------------------------- /detectron2/modeling/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from detectron2.layers import ShapeSpec 3 | 4 | from .anchor_generator import build_anchor_generator, ANCHOR_GENERATOR_REGISTRY 5 | from .backbone import ( 6 | BACKBONE_REGISTRY, 7 | FPN, 8 | Backbone, 9 | ResNet, 10 | ResNetBlockBase, 11 | build_backbone, 12 | build_resnet_backbone, 13 | make_stage, 14 | ) 15 | from .meta_arch import ( 16 | META_ARCH_REGISTRY, 17 | SEM_SEG_HEADS_REGISTRY, 18 | GeneralizedRCNN, 19 | PanopticFPN, 20 | ProposalNetwork, 21 | RetinaNet, 22 | SemanticSegmentor, 23 | build_model, 24 | build_sem_seg_head, 25 | FCOS, 26 | ) 27 | from .postprocessing import detector_postprocess 28 | from .proposal_generator import ( 29 | PROPOSAL_GENERATOR_REGISTRY, 30 | build_proposal_generator, 31 | RPN_HEAD_REGISTRY, 32 | build_rpn_head, 33 | ) 34 | from .roi_heads import ( 35 | ROI_BOX_HEAD_REGISTRY, 36 | ROI_HEADS_REGISTRY, 37 | ROI_KEYPOINT_HEAD_REGISTRY, 38 | ROI_MASK_HEAD_REGISTRY, 39 | ROIHeads, 40 | StandardROIHeads, 41 | BaseMaskRCNNHead, 42 | BaseKeypointRCNNHead, 43 | FastRCNNOutputLayers, 44 | build_box_head, 45 | build_keypoint_head, 46 | build_mask_head, 47 | build_roi_heads, 48 | ) 49 | from .test_time_augmentation import DatasetMapperTTA, GeneralizedRCNNWithTTA 50 | from .mmdet_wrapper import MMDetBackbone, MMDetDetector 51 | 52 | _EXCLUDE = {"ShapeSpec"} 53 | __all__ = [k for k in globals().keys() if k not in _EXCLUDE and not k.startswith("_")] 54 | 55 | 56 | from detectron2.utils.env import fixup_module_metadata 57 | 58 | fixup_module_metadata(__name__, globals(), __all__) 59 | del fixup_module_metadata 60 | -------------------------------------------------------------------------------- /detectron2/modeling/backbone/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .build import build_backbone, BACKBONE_REGISTRY # noqa F401 isort:skip 3 | 4 | from .backbone import Backbone 5 | from .fpn import FPN 6 | from .regnet import RegNet 7 | from .resnet import ( 8 | BasicStem, 9 | ResNet, 10 | ResNetBlockBase, 11 | build_resnet_backbone, 12 | make_stage, 13 | BottleneckBlock, 14 | ) 15 | 16 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 17 | # TODO can expose more resnet blocks after careful consideration 18 | -------------------------------------------------------------------------------- /detectron2/modeling/backbone/backbone.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from abc import ABCMeta, abstractmethod 3 | import torch.nn as nn 4 | 5 | from detectron2.layers import ShapeSpec 6 | 7 | __all__ = ["Backbone"] 8 | 9 | 10 | class Backbone(nn.Module, metaclass=ABCMeta): 11 | """ 12 | Abstract base class for network backbones. 13 | """ 14 | 15 | def __init__(self): 16 | """ 17 | The `__init__` method of any subclass can specify its own set of arguments. 18 | """ 19 | super().__init__() 20 | 21 | @abstractmethod 22 | def forward(self): 23 | """ 24 | Subclasses must override this method, but adhere to the same return type. 25 | 26 | Returns: 27 | dict[str->Tensor]: mapping from feature name (e.g., "res2") to tensor 28 | """ 29 | pass 30 | 31 | @property 32 | def size_divisibility(self) -> int: 33 | """ 34 | Some backbones require the input height and width to be divisible by a 35 | specific integer. This is typically true for encoder / decoder type networks 36 | with lateral connection (e.g., FPN) for which feature maps need to match 37 | dimension in the "bottom up" and "top down" paths. Set to 0 if no specific 38 | input size divisibility is required. 39 | """ 40 | return 0 41 | 42 | def output_shape(self): 43 | """ 44 | Returns: 45 | dict[str->ShapeSpec] 46 | """ 47 | # this is a backward-compatible default 48 | return { 49 | name: ShapeSpec( 50 | channels=self._out_feature_channels[name], stride=self._out_feature_strides[name] 51 | ) 52 | for name in self._out_features 53 | } 54 | -------------------------------------------------------------------------------- /detectron2/modeling/backbone/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from detectron2.layers import ShapeSpec 3 | from detectron2.utils.registry import Registry 4 | 5 | from .backbone import Backbone 6 | 7 | BACKBONE_REGISTRY = Registry("BACKBONE") 8 | BACKBONE_REGISTRY.__doc__ = """ 9 | Registry for backbones, which extract feature maps from images 10 | 11 | The registered object must be a callable that accepts two arguments: 12 | 13 | 1. A :class:`detectron2.config.CfgNode` 14 | 2. A :class:`detectron2.layers.ShapeSpec`, which contains the input shape specification. 15 | 16 | Registered object must return instance of :class:`Backbone`. 17 | """ 18 | 19 | 20 | def build_backbone(cfg, input_shape=None): 21 | """ 22 | Build a backbone from `cfg.MODEL.BACKBONE.NAME`. 23 | 24 | Returns: 25 | an instance of :class:`Backbone` 26 | """ 27 | if input_shape is None: 28 | input_shape = ShapeSpec(channels=len(cfg.MODEL.PIXEL_MEAN)) 29 | 30 | backbone_name = cfg.MODEL.BACKBONE.NAME 31 | backbone = BACKBONE_REGISTRY.get(backbone_name)(cfg, input_shape) 32 | assert isinstance(backbone, Backbone) 33 | return backbone 34 | -------------------------------------------------------------------------------- /detectron2/modeling/meta_arch/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | from .build import META_ARCH_REGISTRY, build_model # isort:skip 5 | 6 | from .panoptic_fpn import PanopticFPN 7 | 8 | # import all the meta_arch, so they will be registered 9 | from .rcnn import GeneralizedRCNN, ProposalNetwork 10 | from .dense_detector import DenseDetector 11 | from .retinanet import RetinaNet 12 | from .fcos import FCOS 13 | from .semantic_seg import SEM_SEG_HEADS_REGISTRY, SemanticSegmentor, build_sem_seg_head 14 | 15 | 16 | __all__ = list(globals().keys()) 17 | -------------------------------------------------------------------------------- /detectron2/modeling/meta_arch/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import torch 3 | 4 | from detectron2.utils.logger import _log_api_usage 5 | from detectron2.utils.registry import Registry 6 | 7 | META_ARCH_REGISTRY = Registry("META_ARCH") # noqa F401 isort:skip 8 | META_ARCH_REGISTRY.__doc__ = """ 9 | Registry for meta-architectures, i.e. the whole model. 10 | 11 | The registered object will be called with `obj(cfg)` 12 | and expected to return a `nn.Module` object. 13 | """ 14 | 15 | 16 | def build_model(cfg): 17 | """ 18 | Build the whole model architecture, defined by ``cfg.MODEL.META_ARCHITECTURE``. 19 | Note that it does not load any weights from ``cfg``. 20 | """ 21 | meta_arch = cfg.MODEL.META_ARCHITECTURE 22 | model = META_ARCH_REGISTRY.get(meta_arch)(cfg) 23 | model.to(torch.device(cfg.MODEL.DEVICE)) 24 | _log_api_usage("modeling.meta_arch." + meta_arch) 25 | return model 26 | -------------------------------------------------------------------------------- /detectron2/modeling/proposal_generator/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .build import PROPOSAL_GENERATOR_REGISTRY, build_proposal_generator 3 | from .rpn import RPN_HEAD_REGISTRY, build_rpn_head, RPN, StandardRPNHead 4 | 5 | __all__ = list(globals().keys()) 6 | -------------------------------------------------------------------------------- /detectron2/modeling/proposal_generator/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from detectron2.utils.registry import Registry 3 | 4 | PROPOSAL_GENERATOR_REGISTRY = Registry("PROPOSAL_GENERATOR") 5 | PROPOSAL_GENERATOR_REGISTRY.__doc__ = """ 6 | Registry for proposal generator, which produces object proposals from feature maps. 7 | 8 | The registered object will be called with `obj(cfg, input_shape)`. 9 | The call should return a `nn.Module` object. 10 | """ 11 | 12 | from . import rpn, rrpn # noqa F401 isort:skip 13 | 14 | 15 | def build_proposal_generator(cfg, input_shape): 16 | """ 17 | Build a proposal generator from `cfg.MODEL.PROPOSAL_GENERATOR.NAME`. 18 | The name can be "PrecomputedProposals" to use no proposal generator. 19 | """ 20 | name = cfg.MODEL.PROPOSAL_GENERATOR.NAME 21 | if name == "PrecomputedProposals": 22 | return None 23 | 24 | return PROPOSAL_GENERATOR_REGISTRY.get(name)(cfg, input_shape) 25 | -------------------------------------------------------------------------------- /detectron2/modeling/roi_heads/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .box_head import ROI_BOX_HEAD_REGISTRY, build_box_head, FastRCNNConvFCHead 3 | from .keypoint_head import ( 4 | ROI_KEYPOINT_HEAD_REGISTRY, 5 | build_keypoint_head, 6 | BaseKeypointRCNNHead, 7 | KRCNNConvDeconvUpsampleHead, 8 | ) 9 | from .mask_head import ( 10 | ROI_MASK_HEAD_REGISTRY, 11 | build_mask_head, 12 | BaseMaskRCNNHead, 13 | MaskRCNNConvUpsampleHead, 14 | ) 15 | from .roi_heads import ( 16 | ROI_HEADS_REGISTRY, 17 | ROIHeads, 18 | Res5ROIHeads, 19 | StandardROIHeads, 20 | build_roi_heads, 21 | select_foreground_proposals, 22 | ) 23 | from .cascade_rcnn import CascadeROIHeads 24 | from .rotated_fast_rcnn import RROIHeads 25 | from .fast_rcnn import FastRCNNOutputLayers 26 | 27 | from . import cascade_rcnn # isort:skip 28 | 29 | __all__ = list(globals().keys()) 30 | -------------------------------------------------------------------------------- /detectron2/projects/README.md: -------------------------------------------------------------------------------- 1 | 2 | Projects live in the [`projects` directory](../../projects) under the root of this repository, but not here. 3 | -------------------------------------------------------------------------------- /detectron2/projects/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import importlib 3 | from pathlib import Path 4 | 5 | _PROJECTS = { 6 | "partglee":"PartGLEE" 7 | } 8 | _PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent / "projects" 9 | 10 | if _PROJECT_ROOT.is_dir(): 11 | # This is true only for in-place installation (pip install -e, setup.py develop), 12 | # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230 13 | 14 | class _D2ProjectsFinder(importlib.abc.MetaPathFinder): 15 | def find_spec(self, name, path, target=None): 16 | if not name.startswith("detectron2.projects."): 17 | return 18 | project_name = name.split(".")[-1] 19 | project_dir = _PROJECTS.get(project_name) 20 | if not project_dir: 21 | return 22 | target_file = _PROJECT_ROOT / f"{project_dir}/{project_name}/__init__.py" 23 | if not target_file.is_file(): 24 | return 25 | return importlib.util.spec_from_file_location(name, target_file) 26 | 27 | import sys 28 | 29 | sys.meta_path.append(_D2ProjectsFinder()) 30 | -------------------------------------------------------------------------------- /detectron2/solver/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .build import build_lr_scheduler, build_optimizer, get_default_optimizer_params 3 | from .lr_scheduler import WarmupCosineLR, WarmupMultiStepLR, LRMultiplier, WarmupParamScheduler 4 | 5 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 6 | -------------------------------------------------------------------------------- /detectron2/structures/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .boxes import Boxes, BoxMode, pairwise_iou, pairwise_ioa, pairwise_point_box_distance 3 | from .image_list import ImageList 4 | 5 | from .instances import Instances 6 | from .keypoints import Keypoints, heatmaps_to_keypoints 7 | from .masks import BitMasks, PolygonMasks, polygons_to_bitmask, ROIMasks 8 | from .rotated_boxes import RotatedBoxes 9 | from .rotated_boxes import pairwise_iou as pairwise_iou_rotated 10 | 11 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 12 | 13 | 14 | from detectron2.utils.env import fixup_module_metadata 15 | 16 | fixup_module_metadata(__name__, globals(), __all__) 17 | del fixup_module_metadata 18 | -------------------------------------------------------------------------------- /detectron2/tracking/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from .base_tracker import ( # noqa 3 | BaseTracker, 4 | build_tracker_head, 5 | TRACKER_HEADS_REGISTRY, 6 | ) 7 | from .bbox_iou_tracker import BBoxIOUTracker # noqa 8 | from .hungarian_tracker import BaseHungarianTracker # noqa 9 | from .iou_weighted_hungarian_bbox_iou_tracker import ( # noqa 10 | IOUWeightedHungarianBBoxIOUTracker, 11 | ) 12 | from .utils import create_prediction_pairs # noqa 13 | from .vanilla_hungarian_bbox_iou_tracker import VanillaHungarianBBoxIOUTracker # noqa 14 | 15 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 16 | -------------------------------------------------------------------------------- /detectron2/tracking/utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from detectron2.structures import Instances 3 | import numpy as np 4 | from typing import List 5 | 6 | 7 | def create_prediction_pairs( 8 | instances: Instances, 9 | prev_instances: Instances, 10 | iou_all: np.ndarray, 11 | threshold: float = 0.5, 12 | ) -> List: 13 | """ 14 | Args: 15 | instances: predictions from current frame 16 | prev_instances: predictions from previous frame 17 | iou_all: 2D numpy array containing iou for each bbox pair 18 | threshold: below the threshold, doesn't consider the pair of bbox is valid 19 | Return: 20 | List of bbox pairs 21 | """ 22 | bbox_pairs = [] 23 | for i in range(len(instances)): 24 | for j in range(len(prev_instances)): 25 | if iou_all[i, j] < threshold: 26 | continue 27 | bbox_pairs.append( 28 | { 29 | "idx": i, 30 | "prev_idx": j, 31 | "prev_id": prev_instances.ID[j], 32 | "IoU": iou_all[i, j], 33 | "prev_period": prev_instances.ID_period[j], 34 | } 35 | ) 36 | return bbox_pairs 37 | 38 | 39 | LARGE_COST_VALUE = 100000 40 | -------------------------------------------------------------------------------- /detectron2/utils/README.md: -------------------------------------------------------------------------------- 1 | # Utility functions 2 | 3 | This folder contain utility functions that are not used in the 4 | core library, but are useful for building models or training 5 | code using the config system. 6 | -------------------------------------------------------------------------------- /detectron2/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | -------------------------------------------------------------------------------- /detectron2/utils/file_io.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from iopath.common.file_io import HTTPURLHandler, OneDrivePathHandler, PathHandler 3 | from iopath.common.file_io import PathManager as PathManagerBase 4 | 5 | __all__ = ["PathManager", "PathHandler"] 6 | 7 | 8 | PathManager = PathManagerBase() 9 | """ 10 | This is a detectron2 project-specific PathManager. 11 | We try to stay away from global PathManager in fvcore as it 12 | introduces potential conflicts among other libraries. 13 | """ 14 | 15 | 16 | class Detectron2Handler(PathHandler): 17 | """ 18 | Resolve anything that's hosted under detectron2's namespace. 19 | """ 20 | 21 | PREFIX = "detectron2://" 22 | S3_DETECTRON2_PREFIX = "https://dl.fbaipublicfiles.com/detectron2/" 23 | 24 | def _get_supported_prefixes(self): 25 | return [self.PREFIX] 26 | 27 | def _get_local_path(self, path, **kwargs): 28 | name = path[len(self.PREFIX) :] 29 | return PathManager.get_local_path(self.S3_DETECTRON2_PREFIX + name, **kwargs) 30 | 31 | def _open(self, path, mode="r", **kwargs): 32 | return PathManager.open(self._get_local_path(path), mode, **kwargs) 33 | 34 | 35 | PathManager.register_handler(HTTPURLHandler()) 36 | PathManager.register_handler(OneDrivePathHandler()) 37 | PathManager.register_handler(Detectron2Handler()) 38 | -------------------------------------------------------------------------------- /detectron2/utils/serialize.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import cloudpickle 3 | 4 | 5 | class PicklableWrapper(object): 6 | """ 7 | Wrap an object to make it more picklable, note that it uses 8 | heavy weight serialization libraries that are slower than pickle. 9 | It's best to use it only on closures (which are usually not picklable). 10 | 11 | This is a simplified version of 12 | https://github.com/joblib/joblib/blob/master/joblib/externals/loky/cloudpickle_wrapper.py 13 | """ 14 | 15 | def __init__(self, obj): 16 | while isinstance(obj, PicklableWrapper): 17 | # Wrapping an object twice is no-op 18 | obj = obj._obj 19 | self._obj = obj 20 | 21 | def __reduce__(self): 22 | s = cloudpickle.dumps(self._obj) 23 | return cloudpickle.loads, (s,) 24 | 25 | def __call__(self, *args, **kwargs): 26 | return self._obj(*args, **kwargs) 27 | 28 | def __getattr__(self, attr): 29 | # Ensure that the wrapped object can be used seamlessly as the previous object. 30 | if attr not in ["_obj"]: 31 | return getattr(self._obj, attr) 32 | return getattr(self, attr) 33 | -------------------------------------------------------------------------------- /dev/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Some scripts for developers to use, include: 3 | 4 | - `linter.sh`: lint the codebase before commit. 5 | - `run_{inference,instant}_tests.sh`: run inference/training for a few iterations. 6 | Note that these tests require 2 GPUs. 7 | - `parse_results.sh`: parse results from a log file. 8 | -------------------------------------------------------------------------------- /dev/linter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | # cd to detectron2 project root 5 | cd "$(dirname "${BASH_SOURCE[0]}")/.." 6 | 7 | { 8 | black --version | grep -E "21\." > /dev/null 9 | } || { 10 | echo "Linter requires 'black==21.*' !" 11 | exit 1 12 | } 13 | 14 | ISORT_VERSION=$(isort --version-number) 15 | if [[ "$ISORT_VERSION" != 4.3* ]]; then 16 | echo "Linter requires isort==4.3.21 !" 17 | exit 1 18 | fi 19 | 20 | set -v 21 | 22 | echo "Running isort ..." 23 | isort -y -sp . --atomic 24 | 25 | echo "Running black ..." 26 | black -l 100 . 27 | 28 | echo "Running flake8 ..." 29 | if [ -x "$(command -v flake8-3)" ]; then 30 | flake8-3 . 31 | else 32 | python3 -m flake8 . 33 | fi 34 | 35 | # echo "Running mypy ..." 36 | # Pytorch does not have enough type annotations 37 | # mypy detectron2/solver detectron2/structures detectron2/config 38 | 39 | echo "Running clang-format ..." 40 | find . -regex ".*\.\(cpp\|c\|cc\|cu\|cxx\|h\|hh\|hpp\|hxx\|tcc\|mm\|m\)" -print0 | xargs -0 clang-format -i 41 | 42 | command -v arc > /dev/null && arc lint 43 | -------------------------------------------------------------------------------- /dev/packaging/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## To build a cu101 wheel for release: 3 | 4 | ``` 5 | $ nvidia-docker run -it --storage-opt "size=20GB" --name pt pytorch/manylinux-cuda101 6 | # inside the container: 7 | # git clone https://github.com/facebookresearch/detectron2/ 8 | # cd detectron2 9 | # export CU_VERSION=cu101 D2_VERSION_SUFFIX= PYTHON_VERSION=3.7 PYTORCH_VERSION=1.8 10 | # ./dev/packaging/build_wheel.sh 11 | ``` 12 | 13 | ## To build all wheels for combinations of CUDA and Python 14 | ``` 15 | ./dev/packaging/build_all_wheels.sh 16 | ./dev/packaging/gen_wheel_index.sh /path/to/wheels 17 | ``` 18 | -------------------------------------------------------------------------------- /dev/packaging/build_all_wheels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | [[ -d "dev/packaging" ]] || { 5 | echo "Please run this script at detectron2 root!" 6 | exit 1 7 | } 8 | 9 | build_one() { 10 | cu=$1 11 | pytorch_ver=$2 12 | 13 | case "$cu" in 14 | cu*) 15 | container_name=manylinux-cuda${cu/cu/} 16 | ;; 17 | cpu) 18 | container_name=manylinux-cuda101 19 | ;; 20 | *) 21 | echo "Unrecognized cu=$cu" 22 | exit 1 23 | ;; 24 | esac 25 | 26 | echo "Launching container $container_name ..." 27 | container_id="$container_name"_"$cu"_"$pytorch_ver" 28 | 29 | py_versions=(3.6 3.7 3.8 3.9) 30 | 31 | for py in "${py_versions[@]}"; do 32 | docker run -itd \ 33 | --name "$container_id" \ 34 | --mount type=bind,source="$(pwd)",target=/detectron2 \ 35 | pytorch/$container_name 36 | 37 | cat </dev/null 2>&1 && pwd )" 8 | . "$script_dir/pkg_helpers.bash" 9 | 10 | echo "Build Settings:" 11 | echo "CU_VERSION: $CU_VERSION" # e.g. cu101 12 | echo "D2_VERSION_SUFFIX: $D2_VERSION_SUFFIX" # e.g. +cu101 or "" 13 | echo "PYTHON_VERSION: $PYTHON_VERSION" # e.g. 3.6 14 | echo "PYTORCH_VERSION: $PYTORCH_VERSION" # e.g. 1.4 15 | 16 | setup_cuda 17 | setup_wheel_python 18 | 19 | yum install ninja-build -y 20 | ln -sv /usr/bin/ninja-build /usr/bin/ninja || true 21 | 22 | pip_install pip numpy -U 23 | pip_install "torch==$PYTORCH_VERSION" \ 24 | -f https://download.pytorch.org/whl/"$CU_VERSION"/torch_stable.html 25 | 26 | # use separate directories to allow parallel build 27 | BASE_BUILD_DIR=build/$CU_VERSION-py$PYTHON_VERSION-pt$PYTORCH_VERSION 28 | python setup.py \ 29 | build -b "$BASE_BUILD_DIR" \ 30 | bdist_wheel -b "$BASE_BUILD_DIR/build_dist" -d "wheels/$CU_VERSION/torch$PYTORCH_VERSION" 31 | rm -rf "$BASE_BUILD_DIR" 32 | -------------------------------------------------------------------------------- /dev/packaging/gen_wheel_index.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | 5 | root=$(readlink -f $1) 6 | if [[ -z "$root" ]]; then 7 | echo "Usage: ./gen_wheel_index.sh /absolute/path/to/wheels" 8 | exit 9 | fi 10 | 11 | export LC_ALL=C # reproducible sort 12 | # NOTE: all sort in this script might not work when xx.10 is released 13 | 14 | index=$root/index.html 15 | 16 | cd "$root" 17 | for cu in cpu cu92 cu100 cu101 cu102 cu110 cu111 cu113; do 18 | mkdir -p "$root/$cu" 19 | cd "$root/$cu" 20 | echo "Creating $PWD/index.html ..." 21 | # First sort by torch version, then stable sort by d2 version with unique. 22 | # As a result, the latest torch version for each d2 version is kept. 23 | for whl in $(find -type f -name '*.whl' -printf '%P\n' \ 24 | | sort -k 1 -r | sort -t '/' -k 2 --stable -r --unique); do 25 | echo "$whl
" 26 | done > index.html 27 | 28 | 29 | for torch in torch*; do 30 | cd "$root/$cu/$torch" 31 | 32 | # list all whl for each cuda,torch version 33 | echo "Creating $PWD/index.html ..." 34 | for whl in $(find . -type f -name '*.whl' -printf '%P\n' | sort -r); do 35 | echo "$whl
" 36 | done > index.html 37 | done 38 | done 39 | 40 | cd "$root" 41 | # Just list everything: 42 | echo "Creating $index ..." 43 | for whl in $(find . -type f -name '*.whl' -printf '%P\n' | sort -r); do 44 | echo "$whl
" 45 | done > "$index" 46 | 47 | -------------------------------------------------------------------------------- /dev/run_inference_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | BIN="python tools/train_net.py" 5 | OUTPUT="inference_test_output" 6 | NUM_GPUS=2 7 | 8 | CFG_LIST=( "${@:1}" ) 9 | 10 | if [ ${#CFG_LIST[@]} -eq 0 ]; then 11 | CFG_LIST=( ./configs/quick_schedules/*inference_acc_test.yaml ) 12 | fi 13 | 14 | echo "========================================================================" 15 | echo "Configs to run:" 16 | echo "${CFG_LIST[@]}" 17 | echo "========================================================================" 18 | 19 | 20 | for cfg in "${CFG_LIST[@]}"; do 21 | echo "========================================================================" 22 | echo "Running $cfg ..." 23 | echo "========================================================================" 24 | $BIN \ 25 | --eval-only \ 26 | --num-gpus $NUM_GPUS \ 27 | --config-file "$cfg" \ 28 | OUTPUT_DIR $OUTPUT 29 | rm -rf $OUTPUT 30 | done 31 | 32 | 33 | echo "========================================================================" 34 | echo "Running demo.py ..." 35 | echo "========================================================================" 36 | DEMO_BIN="python demo/demo.py" 37 | COCO_DIR=datasets/coco/val2014 38 | mkdir -pv $OUTPUT 39 | 40 | set -v 41 | 42 | $DEMO_BIN --config-file ./configs/quick_schedules/panoptic_fpn_R_50_inference_acc_test.yaml \ 43 | --input $COCO_DIR/COCO_val2014_0000001933* --output $OUTPUT 44 | rm -rf $OUTPUT 45 | -------------------------------------------------------------------------------- /dev/run_instant_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | BIN="python tools/train_net.py" 5 | OUTPUT="instant_test_output" 6 | NUM_GPUS=2 7 | 8 | CFG_LIST=( "${@:1}" ) 9 | if [ ${#CFG_LIST[@]} -eq 0 ]; then 10 | CFG_LIST=( ./configs/quick_schedules/*instant_test.yaml ) 11 | fi 12 | 13 | echo "========================================================================" 14 | echo "Configs to run:" 15 | echo "${CFG_LIST[@]}" 16 | echo "========================================================================" 17 | 18 | for cfg in "${CFG_LIST[@]}"; do 19 | echo "========================================================================" 20 | echo "Running $cfg ..." 21 | echo "========================================================================" 22 | $BIN --num-gpus $NUM_GPUS --config-file "$cfg" \ 23 | SOLVER.IMS_PER_BATCH $(($NUM_GPUS * 2)) \ 24 | OUTPUT_DIR "$OUTPUT" 25 | rm -rf "$OUTPUT" 26 | done 27 | 28 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Use the container (with docker ≥ 19.03) 3 | 4 | ``` 5 | cd docker/ 6 | # Build: 7 | docker build --build-arg USER_ID=$UID -t detectron2:v0 . 8 | # Launch (require GPUs): 9 | docker run --gpus all -it \ 10 | --shm-size=8gb --env="DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \ 11 | --name=detectron2 detectron2:v0 12 | 13 | # Grant docker access to host X server to show images 14 | xhost +local:`docker inspect --format='{{ .Config.Hostname }}' detectron2` 15 | ``` 16 | 17 | ## Use the container (with docker-compose ≥ 1.28.0) 18 | 19 | Install docker-compose and nvidia-docker-toolkit, then run: 20 | ``` 21 | cd docker && USER_ID=$UID docker-compose run detectron2 22 | ``` 23 | 24 | ## Use the deployment container (to test C++ examples) 25 | After building the base detectron2 container as above, do: 26 | ``` 27 | # Build: 28 | docker build -t detectron2-deploy:v0 -f deploy.Dockerfile . 29 | # Launch: 30 | docker run --gpus all -it detectron2-deploy:v0 31 | ``` 32 | 33 | #### Using a persistent cache directory 34 | 35 | You can prevent models from being re-downloaded on every run, 36 | by storing them in a cache directory. 37 | 38 | To do this, add `--volume=$HOME/.torch/fvcore_cache:/tmp:rw` in the run command. 39 | 40 | ## Install new dependencies 41 | Add the following to `Dockerfile` to make persistent changes. 42 | ``` 43 | RUN sudo apt-get update && sudo apt-get install -y vim 44 | ``` 45 | Or run them in the container to make temporary changes. 46 | -------------------------------------------------------------------------------- /docker/deploy.Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # This file defines a container that compiles the C++ examples of detectron2. 3 | # See docker/README.md for usage. 4 | 5 | # Depends on the image produced by "./Dockerfile" 6 | FROM detectron2:v0 7 | 8 | USER appuser 9 | ENV HOME=/home/appuser 10 | WORKDIR $HOME 11 | 12 | # Let torchvision find libtorch 13 | ENV CMAKE_PREFIX_PATH=$HOME/.local/lib/python3.6/site-packages/torch/ 14 | 15 | RUN sudo apt-get update && sudo apt-get install libopencv-dev --yes 16 | 17 | # install libtorchvision 18 | RUN git clone --branch v0.11.1 https://github.com/pytorch/vision/ 19 | RUN mkdir vision/build && cd vision/build && \ 20 | cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/.local -DCMAKE_BUILD_TYPE=Release -DWITH_CUDA=on -DTORCH_CUDA_ARCH_LIST=$TORCH_CUDA_ARCH_LIST && \ 21 | make -j && make install 22 | 23 | # make our installation take effect 24 | ENV CPATH=$HOME/.local/include \ 25 | LIBRARY_PATH=$HOME/.local/lib \ 26 | LD_LIBRARY_PATH=$HOME/.local/lib 27 | 28 | 29 | # build C++ examples of detectron2 30 | RUN cd detectron2_repo/tools/deploy && mkdir build && cd build && \ 31 | cmake -DTORCH_CUDA_ARCH_LIST=$TORCH_CUDA_ARCH_LIST .. && make 32 | # binaries will be available under tools/deploy/build 33 | -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2.3" 2 | services: 3 | detectron2: 4 | build: 5 | context: . 6 | dockerfile: Dockerfile 7 | args: 8 | USER_ID: ${USER_ID:-1000} 9 | deploy: 10 | resources: 11 | reservations: 12 | devices: 13 | - capabilities: 14 | - gpu 15 | shm_size: "8gb" 16 | ulimits: 17 | memlock: -1 18 | stack: 67108864 19 | volumes: 20 | - /tmp/.X11-unix:/tmp/.X11-unix:ro 21 | environment: 22 | - DISPLAY=$DISPLAY 23 | - NVIDIA_VISIBLE_DEVICES=all 24 | # Uncomment with proper source to access webcam from docker 25 | # devices: 26 | # - /dev/video0:/dev/video0 27 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = . 8 | BUILDDIR = _build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 20 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Read the docs: 2 | 3 | The latest documentation built from this directory is available at [detectron2.readthedocs.io](https://detectron2.readthedocs.io/). 4 | Documents in this directory are not meant to be read on github. 5 | 6 | # Build the docs: 7 | 8 | 1. Install detectron2 according to [INSTALL.md](../INSTALL.md). 9 | 2. Install additional libraries required to build docs: 10 | - docutils==0.16 11 | - Sphinx==3.2.0 12 | - recommonmark==0.6.0 13 | - sphinx_rtd_theme 14 | 15 | 3. Run `make html` from this directory. 16 | -------------------------------------------------------------------------------- /docs/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * some extra css to make markdown look similar between github/sphinx 4 | */ 5 | 6 | /* 7 | * Below is for install.md: 8 | */ 9 | .rst-content code { 10 | white-space: pre; 11 | border: 0px; 12 | } 13 | 14 | .rst-content th { 15 | border: 1px solid #e1e4e5; 16 | } 17 | 18 | .rst-content th p { 19 | /* otherwise will be default 24px for regular paragraph */ 20 | margin-bottom: 0px; 21 | } 22 | 23 | .rst-content .line-block { 24 | /* otherwise will be 24px */ 25 | margin-bottom: 0px; 26 | } 27 | 28 | div.section > details { 29 | padding-bottom: 1em; 30 | } 31 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. detectron2 documentation master file, created by 2 | sphinx-quickstart on Sat Sep 21 13:46:45 2019. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to detectron2's documentation! 7 | ====================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | tutorials/index 13 | notes/index 14 | modules/index 15 | -------------------------------------------------------------------------------- /docs/modules/checkpoint.rst: -------------------------------------------------------------------------------- 1 | detectron2.checkpoint 2 | ============================= 3 | 4 | .. automodule:: detectron2.checkpoint 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/config.rst: -------------------------------------------------------------------------------- 1 | detectron2.config 2 | ========================= 3 | 4 | Related tutorials: :doc:`../tutorials/configs`, :doc:`../tutorials/extend`. 5 | 6 | .. automodule:: detectron2.config 7 | :members: 8 | :undoc-members: 9 | :show-inheritance: 10 | 11 | 12 | Yaml Config References 13 | ----------------- 14 | 15 | .. literalinclude:: ../../detectron2/config/defaults.py 16 | :language: python 17 | :linenos: 18 | :lines: 7- 19 | -------------------------------------------------------------------------------- /docs/modules/data.rst: -------------------------------------------------------------------------------- 1 | detectron2.data 2 | ======================= 3 | 4 | .. autodata:: detectron2.data.DatasetCatalog(dict) 5 | :annotation: 6 | 7 | .. autodata:: detectron2.data.MetadataCatalog(dict) 8 | :annotation: 9 | 10 | .. automodule:: detectron2.data 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | detectron2.data.detection\_utils module 16 | --------------------------------------- 17 | 18 | .. automodule:: detectron2.data.detection_utils 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | detectron2.data.datasets module 24 | --------------------------------------- 25 | 26 | .. automodule:: detectron2.data.datasets 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | detectron2.data.samplers module 32 | --------------------------------------- 33 | 34 | .. automodule:: detectron2.data.samplers 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/modules/data_transforms.rst: -------------------------------------------------------------------------------- 1 | detectron2.data.transforms 2 | ==================================== 3 | 4 | Related tutorial: :doc:`../tutorials/augmentation`. 5 | 6 | .. automodule:: detectron2.data.transforms 7 | :members: 8 | :undoc-members: 9 | :show-inheritance: 10 | :imported-members: 11 | -------------------------------------------------------------------------------- /docs/modules/engine.rst: -------------------------------------------------------------------------------- 1 | detectron2.engine 2 | ========================= 3 | 4 | Related tutorial: :doc:`../tutorials/training`. 5 | 6 | .. automodule:: detectron2.engine 7 | :members: 8 | :undoc-members: 9 | :show-inheritance: 10 | 11 | 12 | detectron2.engine.defaults module 13 | --------------------------------- 14 | 15 | .. automodule:: detectron2.engine.defaults 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | detectron2.engine.hooks module 21 | --------------------------------- 22 | 23 | .. automodule:: detectron2.engine.hooks 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /docs/modules/evaluation.rst: -------------------------------------------------------------------------------- 1 | detectron2.evaluation 2 | ============================= 3 | 4 | .. automodule:: detectron2.evaluation 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/export.rst: -------------------------------------------------------------------------------- 1 | detectron2.export 2 | ========================= 3 | 4 | Related tutorial: :doc:`../tutorials/deployment`. 5 | 6 | .. automodule:: detectron2.export 7 | :members: 8 | :undoc-members: 9 | :show-inheritance: 10 | -------------------------------------------------------------------------------- /docs/modules/fvcore.rst: -------------------------------------------------------------------------------- 1 | fvcore documentation 2 | ==================== 3 | 4 | Detectron2 depends on utilities in 5 | `fvcore `_. 6 | We include part of fvcore documentation here for easier reference. 7 | 8 | fvcore.nn 9 | ----------------- 10 | 11 | .. automodule:: fvcore.nn 12 | :members: 13 | :inherited-members: 14 | :undoc-members: 15 | :show-inheritance: 16 | 17 | fvcore.common 18 | --------------------- 19 | 20 | .. automodule:: fvcore.common.checkpoint 21 | :members: 22 | :undoc-members: 23 | :show-inheritance: 24 | 25 | .. automodule:: fvcore.common.config 26 | :members: 27 | :undoc-members: 28 | :show-inheritance: 29 | 30 | .. automodule:: fvcore.common.history_buffer 31 | :members: 32 | :undoc-members: 33 | :show-inheritance: 34 | 35 | .. automodule:: fvcore.common.param_scheduler 36 | :members: 37 | :inherited-members: 38 | :undoc-members: 39 | :show-inheritance: 40 | 41 | .. automodule:: fvcore.common.registry 42 | :members: 43 | :undoc-members: 44 | :show-inheritance: 45 | 46 | .. automodule:: fvcore.common.timer 47 | :members: 48 | :undoc-members: 49 | :show-inheritance: 50 | -------------------------------------------------------------------------------- /docs/modules/index.rst: -------------------------------------------------------------------------------- 1 | API Documentation 2 | ================== 3 | 4 | .. toctree:: 5 | 6 | checkpoint 7 | config 8 | data 9 | data_transforms 10 | engine 11 | evaluation 12 | layers 13 | model_zoo 14 | modeling 15 | solver 16 | structures 17 | utils 18 | export 19 | fvcore 20 | -------------------------------------------------------------------------------- /docs/modules/layers.rst: -------------------------------------------------------------------------------- 1 | detectron2.layers 2 | ========================= 3 | 4 | .. automodule:: detectron2.layers 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/model_zoo.rst: -------------------------------------------------------------------------------- 1 | detectron2.model_zoo 2 | ============================ 3 | 4 | .. automodule:: detectron2.model_zoo 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/solver.rst: -------------------------------------------------------------------------------- 1 | detectron2.solver 2 | ========================= 3 | 4 | .. automodule:: detectron2.solver 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/structures.rst: -------------------------------------------------------------------------------- 1 | detectron2.structures 2 | ============================= 3 | 4 | .. automodule:: detectron2.structures 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/notes/contributing.md: -------------------------------------------------------------------------------- 1 | ../../.github/CONTRIBUTING.md -------------------------------------------------------------------------------- /docs/notes/index.rst: -------------------------------------------------------------------------------- 1 | Notes 2 | ====================================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | benchmarks 8 | compatibility 9 | contributing 10 | changelog 11 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | docutils==0.16 2 | # https://github.com/sphinx-doc/sphinx/commit/7acd3ada3f38076af7b2b5c9f3b60bb9c2587a3d 3 | sphinx==3.2.0 4 | recommonmark==0.6.0 5 | sphinx_rtd_theme 6 | # Dependencies here are only those required by import 7 | termcolor 8 | numpy 9 | tqdm 10 | matplotlib 11 | termcolor 12 | yacs 13 | tabulate 14 | cloudpickle 15 | Pillow 16 | future 17 | git+git://github.com/facebookresearch/fvcore.git 18 | https://download.pytorch.org/whl/cpu/torch-1.8.1%2Bcpu-cp37-cp37m-linux_x86_64.whl 19 | https://download.pytorch.org/whl/cpu/torchvision-0.9.1%2Bcpu-cp37-cp37m-linux_x86_64.whl 20 | omegaconf>=2.1.0.dev24 21 | hydra-core>=1.1.0.dev5 22 | scipy 23 | -------------------------------------------------------------------------------- /docs/tutorials/README.md: -------------------------------------------------------------------------------- 1 | # Read the docs: 2 | 3 | The latest documentation built from this directory is available at [detectron2.readthedocs.io](https://detectron2.readthedocs.io/). 4 | Documents in this directory are not meant to be read on github. 5 | -------------------------------------------------------------------------------- /docs/tutorials/builtin_datasets.md: -------------------------------------------------------------------------------- 1 | ../../datasets/README.md -------------------------------------------------------------------------------- /docs/tutorials/getting_started.md: -------------------------------------------------------------------------------- 1 | ../../GETTING_STARTED.md -------------------------------------------------------------------------------- /docs/tutorials/index.rst: -------------------------------------------------------------------------------- 1 | Tutorials 2 | ====================================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | install 8 | getting_started 9 | builtin_datasets 10 | extend 11 | datasets 12 | data_loading 13 | augmentation 14 | models 15 | write-models 16 | training 17 | evaluation 18 | configs 19 | lazyconfigs 20 | deployment 21 | -------------------------------------------------------------------------------- /docs/tutorials/install.md: -------------------------------------------------------------------------------- 1 | ../../INSTALL.md -------------------------------------------------------------------------------- /projects/PartGLEE/clip_vit_base_patch32/preprocessor_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "crop_size": 224, 3 | "do_center_crop": true, 4 | "do_normalize": true, 5 | "do_resize": true, 6 | "feature_extractor_type": "CLIPFeatureExtractor", 7 | "image_mean": [ 8 | 0.48145466, 9 | 0.4578275, 10 | 0.40821073 11 | ], 12 | "image_std": [ 13 | 0.26862954, 14 | 0.26130258, 15 | 0.27577711 16 | ], 17 | "resample": 3, 18 | "size": 224 19 | } 20 | -------------------------------------------------------------------------------- /projects/PartGLEE/clip_vit_base_patch32/special_tokens_map.json: -------------------------------------------------------------------------------- 1 | {"bos_token": {"content": "<|startoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "pad_token": "<|endoftext|>"} -------------------------------------------------------------------------------- /projects/PartGLEE/clip_vit_base_patch32/tokenizer_config.json: -------------------------------------------------------------------------------- 1 | {"unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "<|startoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "pad_token": "<|endoftext|>", "add_prefix_space": false, "errors": "replace", "do_lower_case": true, "name_or_path": "./clip_ViT_B_32/"} -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/RN50/SeginW.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_RN50.pth" 4 | SEM_SEG_HEAD: 5 | NAME: "MaskDINOHead" 6 | IGNORE_VALUE: 255 7 | NUM_CLASSES: 531 8 | MaskDINO: 9 | NUM_OBJECT_QUERIES: 300 10 | NUM_PART_QUERIES: 10 11 | UNIFY_OBJECT_PART: True 12 | Q_FORMER: True 13 | OBJECT_PART_DECODER_LAYERS: 6 14 | DATASETS: 15 | TEST: ('seginw_Airplane-Parts_val', 'seginw_Bottles_val', 'seginw_Brain-Tumor_val', 'seginw_Chicken_val', 'seginw_Cows_val', 'seginw_Electric-Shaver_val', 'seginw_Elephants_val', 'seginw_Fruits_val', 'seginw_Garbage_val', 'seginw_Ginger-Garlic_val', 'seginw_Hand_val', 'seginw_Hand-Metal_val', 'seginw_House-Parts_val', 'seginw_HouseHold-Items_val', 'seginw_Nutterfly-Squireel_val', 'seginw_Phones_val', 'seginw_Poles_val', 'seginw_Puppies_val', 'seginw_Rail_val', 'seginw_Salmon-Fillet_val', 'seginw_Strawberry_val', 'seginw_Tablets_val', 'seginw_Toolkits_val', 'seginw_Trash_val', 'seginw_Watermelon_val') 16 | SOLVER: 17 | IMS_PER_BATCH: 8 18 | BASE_LR: 0.00005 19 | STEPS: (60000, ) 20 | MAX_ITER: 90000 21 | CHECKPOINT_PERIOD: 5000 22 | TEST: 23 | EVAL_PERIOD: 5000 24 | INPUT: 25 | IMAGE_SIZE: 1024 26 | MIN_SCALE: 0.1 27 | MAX_SCALE: 2.0 28 | FORMAT: "RGB" 29 | DATASET_MAPPER_NAME: "joint_image_lsj" 30 | DATALOADER: 31 | FILTER_EMPTY_ANNOTATIONS: True 32 | NUM_WORKERS: 4 33 | OUTPUT_DIR: projects/PartGLEE/output/Inference/SeginW-RN50/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/RN50/ade20k-part-234.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PartGLEE" 4 | USE_EARLYFUSION: True 5 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_RN50.pth" 6 | SEM_SEG_HEAD: 7 | NAME: "MaskDINOHead" 8 | IGNORE_VALUE: 255 9 | NUM_CLASSES: 531 10 | MaskDINO: 11 | NUM_OBJECT_QUERIES: 300 12 | NUM_PART_QUERIES: 10 13 | UNIFY_OBJECT_PART: True 14 | Q_FORMER: True 15 | OBJECT_PART_DECODER_LAYERS: 6 16 | TEST: 17 | SEMANTIC_ON: True 18 | OBJECT_PART_TEST_AUGMENTATIONS: True 19 | ORACLE: True 20 | DATASETS: 21 | TRAIN: ("ade20k_base_train",) 22 | TEST: ("ade_obj_part_val_obj_condition",) 23 | SOLVER: 24 | IMS_PER_BATCH: 8 25 | BASE_LR: 0.00005 26 | STEPS: (12000, 16000) 27 | MAX_ITER: 20000 28 | CHECKPOINT_PERIOD: 5000 29 | TEST: 30 | EVAL_PERIOD: 5000 31 | DETECTIONS_PER_IMAGE: 100 32 | INPUT: 33 | IMAGE_SIZE: 1024 34 | MIN_SCALE: 0.1 35 | MAX_SCALE: 2.0 36 | FORMAT: "RGB" 37 | DATASET_MAPPER_NAME: "joint_image_lsj" 38 | DATALOADER: 39 | FILTER_EMPTY_ANNOTATIONS: True 40 | NUM_WORKERS: 4 41 | OUTPUT_DIR: projects/PartGLEE/output/Inference/ADE20K-Part-234/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/RN50/coco.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PartGLEE" 4 | USE_EARLYFUSION: True 5 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_RN50.pth" 6 | SEM_SEG_HEAD: 7 | NAME: "MaskDINOHead" 8 | IGNORE_VALUE: 255 9 | NUM_CLASSES: 531 10 | MaskDINO: 11 | NUM_OBJECT_QUERIES: 300 12 | NUM_PART_QUERIES: 10 13 | UNIFY_OBJECT_PART: True 14 | Q_FORMER: True 15 | OBJECT_PART_DECODER_LAYERS: 6 16 | DATASETS: 17 | TRAIN: ("coco_2017_train",) 18 | TEST: ("coco_2017_val",) 19 | INPUT: 20 | IMAGE_SIZE: 1024 21 | MIN_SCALE: 0.1 22 | MAX_SCALE: 2.0 23 | FORMAT: "RGB" 24 | DATASET_MAPPER_NAME: "joint_image_lsj" 25 | DATALOADER: 26 | FILTER_EMPTY_ANNOTATIONS: True 27 | NUM_WORKERS: 8 28 | OUTPUT_DIR: projects/PartGLEE/output/Inference/coco_RN50/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/RN50/paco.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PartGLEE" 4 | USE_EARLYFUSION: True 5 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_RN50.pth" 6 | SEM_SEG_HEAD: 7 | NAME: "MaskDINOHead" 8 | IGNORE_VALUE: 255 9 | NUM_CLASSES: 531 10 | MaskDINO: 11 | NUM_OBJECT_QUERIES: 300 12 | NUM_PART_QUERIES: 10 13 | UNIFY_OBJECT_PART: True 14 | Q_FORMER: True 15 | OBJECT_PART_DECODER_LAYERS: 6 16 | DATASETS: 17 | TRAIN: ("paco_lvis_v1_train",) 18 | TEST: ("paco_lvis_v1_val",) 19 | INPUT: 20 | IMAGE_SIZE: 1024 21 | MIN_SCALE: 0.1 22 | MAX_SCALE: 2.0 23 | FORMAT: "RGB" 24 | DATASET_MAPPER_NAME: "joint_image_lsj" 25 | DATALOADER: 26 | FILTER_EMPTY_ANNOTATIONS: True 27 | NUM_WORKERS: 8 28 | OUTPUT_DIR: projects/PartGLEE/output/Inference/paco_RN50/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/RN50/partimagenet.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_RN50.pth" 4 | SEM_SEG_HEAD: 5 | NAME: "MaskDINOHead" 6 | IGNORE_VALUE: 255 7 | NUM_CLASSES: 531 8 | MaskDINO: 9 | NUM_OBJECT_QUERIES: 300 10 | NUM_PART_QUERIES: 10 11 | UNIFY_OBJECT_PART: True 12 | Q_FORMER: True 13 | OBJECT_PART_DECODER_LAYERS: 6 14 | DATASETS: 15 | TRAIN: ("partimagenet_train",) 16 | TEST: ("partimagenet_val",) 17 | SOLVER: 18 | IMS_PER_BATCH: 16 19 | BASE_LR: 0.00005 20 | STEPS: (6000, ) 21 | MAX_ITER: 10000 22 | CHECKPOINT_PERIOD: 2000 23 | TEST: 24 | EVAL_PERIOD: 2000 25 | INPUT: 26 | IMAGE_SIZE: 1024 27 | MIN_SCALE: 0.1 28 | MAX_SCALE: 2.0 29 | FORMAT: "RGB" 30 | DATASET_MAPPER_NAME: "joint_image_lsj" 31 | DATALOADER: 32 | FILTER_EMPTY_ANNOTATIONS: True 33 | NUM_WORKERS: 4 34 | OUTPUT_DIR: projects/PartGLEE/output/Inference/partimagenet_RN50/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/RN50/pascal-part-116.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PartGLEE" 4 | USE_EARLYFUSION: True 5 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_RN50.pth" 6 | SEM_SEG_HEAD: 7 | NAME: "MaskDINOHead" 8 | IGNORE_VALUE: 255 9 | NUM_CLASSES: 531 10 | MaskDINO: 11 | NUM_OBJECT_QUERIES: 300 12 | NUM_PART_QUERIES: 10 13 | UNIFY_OBJECT_PART: True 14 | Q_FORMER: True 15 | OBJECT_PART_DECODER_LAYERS: 6 16 | TEST: 17 | SEMANTIC_ON: True 18 | OBJECT_PART_TEST_AUGMENTATIONS: True 19 | ORACLE: True 20 | DATASETS: 21 | TRAIN: ("pascalvoc_base_train",) 22 | TEST: ("voc_obj_part_sem_seg_val_obj_condition",) 23 | SOLVER: 24 | IMS_PER_BATCH: 8 25 | BASE_LR: 0.00005 26 | STEPS: (12000, ) 27 | MAX_ITER: 20000 28 | CHECKPOINT_PERIOD: 5000 29 | TEST: 30 | EVAL_PERIOD: 5000 31 | DETECTIONS_PER_IMAGE: 100 32 | INPUT: 33 | IMAGE_SIZE: 1024 34 | MIN_SCALE: 0.1 35 | MAX_SCALE: 2.0 36 | FORMAT: "RGB" 37 | DATASET_MAPPER_NAME: "joint_image_lsj" 38 | DATALOADER: 39 | FILTER_EMPTY_ANNOTATIONS: True 40 | NUM_WORKERS: 4 41 | OUTPUT_DIR: projects/PartGLEE/output/Inference/Pascal-Part-116/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/RN50/pascal_part.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PartGLEE" 4 | USE_EARLYFUSION: True 5 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_RN50.pth" 6 | SEM_SEG_HEAD: 7 | NAME: "MaskDINOHead" 8 | IGNORE_VALUE: 255 9 | NUM_CLASSES: 531 10 | MaskDINO: 11 | NUM_OBJECT_QUERIES: 300 12 | NUM_PART_QUERIES: 10 13 | UNIFY_OBJECT_PART: True 14 | Q_FORMER: True 15 | OBJECT_PART_DECODER_LAYERS: 6 16 | DATASETS: 17 | TRAIN: ("pascal_voc_train_segm", "pascal_part_base_train", ) 18 | TEST: ("pascal_part_open_vocabulary_val", ) 19 | SOLVER: 20 | IMS_PER_BATCH: 16 21 | BASE_LR: 0.00005 22 | STEPS: (12000, 16000,) 23 | MAX_ITER: 20000 24 | CHECKPOINT_PERIOD: 5000 25 | TEST: 26 | EVAL_PERIOD: 5000 27 | INPUT: 28 | IMAGE_SIZE: 1024 29 | MIN_SCALE: 0.1 30 | MAX_SCALE: 2.0 31 | FORMAT: "RGB" 32 | DATASET_MAPPER_NAME: "joint_image_lsj" 33 | DATALOADER: 34 | SAMPLER_TRAIN: "MultiDatasetSampler" 35 | DATASET_RATIO: [1, 2] 36 | USE_DIFF_BS_SIZE: True 37 | DATASET_BS: [1, 1] 38 | USE_RFS: [False, False] 39 | FILTER_EMPTY_ANNOTATIONS: True 40 | NUM_WORKERS: 8 41 | OUTPUT_DIR: projects/PartGLEE/output/Inference/pascal_part_RN50/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/Swin-L/coco.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PartGLEE" 4 | USE_EARLYFUSION: True 5 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_SwinL.pth" 6 | BACKBONE: 7 | NAME: "D2SwinTransformer" 8 | SWIN: 9 | EMBED_DIM: 192 10 | DEPTHS: [2, 2, 18, 2] 11 | NUM_HEADS: [6, 12, 24, 48] 12 | WINDOW_SIZE: 12 13 | APE: False 14 | DROP_PATH_RATE: 0.3 15 | PATCH_NORM: True 16 | PRETRAIN_IMG_SIZE: 384 17 | SEM_SEG_HEAD: 18 | NAME: "MaskDINOHead" 19 | IGNORE_VALUE: 255 20 | NUM_CLASSES: 531 21 | MaskDINO: 22 | NUM_OBJECT_QUERIES: 300 23 | NUM_PART_QUERIES: 10 24 | UNIFY_OBJECT_PART: True 25 | Q_FORMER: True 26 | OBJECT_PART_DECODER_LAYERS: 6 27 | DATASETS: 28 | TRAIN: ("coco_2017_train",) 29 | TEST: ("coco_2017_val",) 30 | INPUT: 31 | IMAGE_SIZE: 1024 32 | MIN_SCALE: 0.1 33 | MAX_SCALE: 2.0 34 | FORMAT: "RGB" 35 | DATASET_MAPPER_NAME: "joint_image_lsj" 36 | DATALOADER: 37 | FILTER_EMPTY_ANNOTATIONS: True 38 | NUM_WORKERS: 8 39 | OUTPUT_DIR: projects/PartGLEE/output/Inference/coco_SwinL/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Inference/Swin-L/paco.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "PartGLEE" 4 | USE_EARLYFUSION: True 5 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_SwinL.pth" 6 | BACKBONE: 7 | NAME: "D2SwinTransformer" 8 | SWIN: 9 | EMBED_DIM: 192 10 | DEPTHS: [2, 2, 18, 2] 11 | NUM_HEADS: [6, 12, 24, 48] 12 | WINDOW_SIZE: 12 13 | APE: False 14 | DROP_PATH_RATE: 0.3 15 | PATCH_NORM: True 16 | PRETRAIN_IMG_SIZE: 384 17 | SEM_SEG_HEAD: 18 | NAME: "MaskDINOHead" 19 | IGNORE_VALUE: 255 20 | NUM_CLASSES: 531 21 | MaskDINO: 22 | NUM_OBJECT_QUERIES: 300 23 | NUM_PART_QUERIES: 10 24 | UNIFY_OBJECT_PART: True 25 | Q_FORMER: True 26 | OBJECT_PART_DECODER_LAYERS: 6 27 | DATASETS: 28 | TRAIN: ("paco_lvis_v1_train",) 29 | TEST: ("paco_lvis_v1_val",) 30 | INPUT: 31 | IMAGE_SIZE: 1024 32 | MIN_SCALE: 0.1 33 | MAX_SCALE: 2.0 34 | FORMAT: "RGB" 35 | DATASET_MAPPER_NAME: "joint_image_lsj" 36 | DATALOADER: 37 | FILTER_EMPTY_ANNOTATIONS: True 38 | NUM_WORKERS: 8 39 | OUTPUT_DIR: projects/PartGLEE/output/Inference/paco_SwinL/ -------------------------------------------------------------------------------- /projects/PartGLEE/configs/Training/Joint-Training-RN50.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../base_clip_frozen_image_r50.yaml" 2 | MODEL: 3 | WEIGHTS: "projects/PartGLEE/checkpoint/PartGLEE_converted_from_GLEE_RN50.pth" 4 | SEM_SEG_HEAD: 5 | NAME: "MaskDINOHead" 6 | IGNORE_VALUE: 255 7 | NUM_CLASSES: 531 8 | TEXT: 9 | ARCH: clip_teacher 10 | MaskDINO: 11 | NUM_OBJECT_QUERIES: 300 12 | NUM_PART_QUERIES: 10 13 | UNIFY_OBJECT_PART: True 14 | Q_FORMER: True 15 | OBJECT_PART_DECODER_LAYERS: 6 16 | DATASETS: 17 | TRAIN: ("sa1b_joint", "paco_lvis_v1_train", "ade20k_joint_train", "pascalvoc_joint_train", "pascal_joint_train", "partimagenet_joint_train", "coco_2017_train", "vg_train_joint", "lvis_v1_train",) 18 | TEST: ("paco_lvis_v1_val", ) 19 | SOLVER: 20 | IMS_PER_BATCH: 32 21 | BASE_LR: 0.00005 22 | STEPS: (60000, ) 23 | MAX_ITER: 90000 24 | CHECKPOINT_PERIOD: 5000 25 | TEST: 26 | EVAL_PERIOD: 5000 27 | INPUT: 28 | IMAGE_SIZE: 1024 29 | MIN_SCALE: 0.1 30 | MAX_SCALE: 2.0 31 | FORMAT: "RGB" 32 | DATASET_MAPPER_NAME: "joint_image_lsj" 33 | DATALOADER: 34 | SAMPLER_TRAIN: "MultiDatasetSampler" 35 | DATASET_RATIO: [2, 6, 1, 1, 1, 1, 1, 2, 2] 36 | FILTER_EMPTY_ANNOTATIONS: True 37 | USE_DIFF_BS_SIZE: True 38 | DATASET_BS: [1, 1, 1, 1, 1, 1, 1, 1, 1] 39 | USE_RFS: [False, True, False, False, False, False, False, False, True, False] 40 | DATASET_ANN: ['box', 'box', 'box', 'box', 'box', 'box', 'box', 'box', 'box', 'box', 'box', 'box', 'box', 'box', 'box'] 41 | NUM_WORKERS: 4 42 | OUTPUT_DIR: projects/PartGLEE/output/Training/Joint-Training-RN50/ 43 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from __future__ import division 3 | from __future__ import print_function 4 | 5 | 6 | from .config import add_partglee_config 7 | from .PartGLEE import PartGLEE 8 | from .data import build_detection_train_loader, build_detection_test_loader 9 | from .backbone.swin import D2SwinTransformer 10 | # from .backbone.internimage import D2InternImage 11 | from .backbone.eva02 import D2_EVA02 12 | from .backbone.eva01 import D2_EVA01 13 | 14 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_backbone 2 | 3 | from .resnet import * 4 | from .swin import * 5 | # from .focal import * 6 | # from .focal_dw import * 7 | from .backbone import * -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/backbone.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import torch.nn as nn 3 | 4 | from detectron2.modeling import ShapeSpec 5 | 6 | __all__ = ["Backbone"] 7 | 8 | 9 | class Backbone(nn.Module): 10 | """ 11 | Abstract base class for network backbones. 12 | """ 13 | 14 | def __init__(self): 15 | """ 16 | The `__init__` method of any subclass can specify its own set of arguments. 17 | """ 18 | super().__init__() 19 | 20 | def forward(self): 21 | """ 22 | Subclasses must override this method, but adhere to the same return type. 23 | 24 | Returns: 25 | dict[str->Tensor]: mapping from feature name (e.g., "res2") to tensor 26 | """ 27 | pass 28 | 29 | @property 30 | def size_divisibility(self) -> int: 31 | """ 32 | Some backbones require the input height and width to be divisible by a 33 | specific integer. This is typically true for encoder / decoder type networks 34 | with lateral connection (e.g., FPN) for which feature maps need to match 35 | dimension in the "bottom up" and "top down" paths. Set to 0 if no specific 36 | input size divisibility is required. 37 | """ 38 | return 0 39 | 40 | def output_shape(self): 41 | """ 42 | Returns: 43 | dict[str->ShapeSpec] 44 | """ 45 | # this is a backward-compatible default 46 | return { 47 | name: ShapeSpec( 48 | channels=self._out_feature_channels[name], stride=self._out_feature_strides[name] 49 | ) 50 | for name in self._out_features 51 | } 52 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/build.py: -------------------------------------------------------------------------------- 1 | from .registry import model_entrypoints 2 | from .registry import is_model 3 | 4 | from .backbone import * 5 | 6 | def build_backbone(config, **kwargs): 7 | model_name = config['MODEL']['BACKBONE']['NAME'] 8 | if not is_model(model_name): 9 | raise ValueError(f'Unkown model: {model_name}') 10 | model = model_entrypoints(model_name)(config, **kwargs) 11 | return model -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/ops_dcnv3/functions/__init__.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # InternImage 3 | # Copyright (c) 2022 OpenGVLab 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # -------------------------------------------------------- 6 | 7 | from .dcnv3_func import DCNv3Function, dcnv3_core_pytorch 8 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/ops_dcnv3/make.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # -------------------------------------------------------- 3 | # InternImage 4 | # Copyright (c) 2022 OpenGVLab 5 | # Licensed under The MIT License [see LICENSE for details] 6 | # -------------------------------------------------------- 7 | 8 | python3 setup.py build install 9 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/ops_dcnv3/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------- 2 | # InternImage 3 | # Copyright (c) 2022 OpenGVLab 4 | # Licensed under The MIT License [see LICENSE for details] 5 | # -------------------------------------------------------- 6 | 7 | from .dcnv3 import DCNv3, DCNv3_pytorch -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/ops_dcnv3/src/cpu/dcnv3_cpu.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * InternImage 4 | * Copyright (c) 2022 OpenGVLab 5 | * Licensed under The MIT License [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from 8 | *https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 9 | ************************************************************************************************** 10 | */ 11 | 12 | #pragma once 13 | #include 14 | 15 | at::Tensor dcnv3_cpu_forward(const at::Tensor &input, const at::Tensor &offset, 16 | const at::Tensor &mask, const int kernel_h, 17 | const int kernel_w, const int stride_h, 18 | const int stride_w, const int pad_h, 19 | const int pad_w, const int dilation_h, 20 | const int dilation_w, const int group, 21 | const int group_channels, const float offset_scale, 22 | const int im2col_step); 23 | 24 | std::vector 25 | dcnv3_cpu_backward(const at::Tensor &input, const at::Tensor &offset, 26 | const at::Tensor &mask, const int kernel_h, 27 | const int kernel_w, const int stride_h, const int stride_w, 28 | const int pad_h, const int pad_w, const int dilation_h, 29 | const int dilation_w, const int group, 30 | const int group_channels, const float offset_scale, 31 | const at::Tensor &grad_output, const int im2col_step); 32 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/ops_dcnv3/src/vision.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * InternImage 4 | * Copyright (c) 2022 OpenGVLab 5 | * Licensed under The MIT License [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from 8 | *https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 9 | ************************************************************************************************** 10 | */ 11 | 12 | #include "dcnv3.h" 13 | 14 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 15 | m.def("dcnv3_forward", &dcnv3_forward, "dcnv3_forward"); 16 | m.def("dcnv3_backward", &dcnv3_backward, "dcnv3_backward"); 17 | } 18 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/backbone/registry.py: -------------------------------------------------------------------------------- 1 | _model_entrypoints = {} 2 | 3 | 4 | def register_backbone(fn): 5 | module_name_split = fn.__module__.split('.') 6 | model_name = module_name_split[-1] 7 | _model_entrypoints[model_name] = fn 8 | return fn 9 | 10 | def model_entrypoints(model_name): 11 | return _model_entrypoints[model_name] 12 | 13 | def is_model(model_name): 14 | return model_name in _model_entrypoints 15 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_xdecoder_head -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/build.py: -------------------------------------------------------------------------------- 1 | from .registry import model_entrypoints 2 | from .registry import is_model 3 | 4 | from .xdecoder_head import * 5 | 6 | 7 | def build_xdecoder_head(config, *args, **kwargs): 8 | model_name = config['MODEL']['HEAD'] 9 | if not is_model(model_name): 10 | raise ValueError(f'Unkown model: {model_name}') 11 | 12 | body = model_entrypoints(model_name)(config, *args, **kwargs) 13 | return body -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/decoder/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_decoder -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/decoder/build.py: -------------------------------------------------------------------------------- 1 | from .registry import model_entrypoints 2 | from .registry import is_model 3 | 4 | from .seem import * 5 | 6 | def build_decoder(config, *args, **kwargs): 7 | model_name = config['MODEL']['DECODER']['NAME'] 8 | 9 | if not is_model(model_name): 10 | raise ValueError(f'Unkown model: {model_name}') 11 | 12 | return model_entrypoints(model_name)(config, *args, **kwargs) -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/decoder/registry.py: -------------------------------------------------------------------------------- 1 | _model_entrypoints = {} 2 | 3 | def register_decoder(fn): 4 | module_name_split = fn.__module__.split('.') 5 | model_name = module_name_split[-1] 6 | _model_entrypoints[model_name] = fn 7 | return fn 8 | 9 | def model_entrypoints(model_name): 10 | return _model_entrypoints[model_name] 11 | 12 | def is_model(model_name): 13 | return model_name in _model_entrypoints -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/decoder/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .utils import * 2 | from .attention_data_struct import * 3 | from .attn import * -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/decoder/utils/utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import copy 3 | from torch import nn, Tensor 4 | import os 5 | 6 | import math 7 | import torch.nn.functional as F 8 | from torch import nn 9 | 10 | 11 | def rand_sample(x, max_len): 12 | if x.shape[1] <= max_len: 13 | return x 14 | else: 15 | rand_idx = torch.randperm(x.shape[1])[:max_len] 16 | return x[:,rand_idx] 17 | 18 | def prepare_features(x, num_feature_levels, pe_layer, input_proj, level_embed): 19 | src = [] 20 | pos = [] 21 | size_list = [] 22 | 23 | # disable mask, it does not affect performance 24 | for i in range(num_feature_levels): 25 | size_list.append(x[i].shape[-2:]) 26 | pos.append(pe_layer(x[i], None).flatten(2)) 27 | src.append(input_proj[i](x[i]).flatten(2) + level_embed.weight[i][None, :, None]) 28 | 29 | # flatten NxCxHxW to HWxNxC 30 | pos[-1] = pos[-1].permute(2, 0, 1) 31 | src[-1] = src[-1].permute(2, 0, 1) 32 | return src, pos, size_list -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/__init__.py: -------------------------------------------------------------------------------- 1 | from .build import build_encoder -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/build.py: -------------------------------------------------------------------------------- 1 | from .registry import model_entrypoints 2 | from .registry import is_model 3 | 4 | from .transformer_encoder_fpn import * 5 | # from .transformer_encoder_deform import * 6 | 7 | def build_encoder(config, *args, **kwargs): 8 | model_name = config['MODEL']['ENCODER']['NAME'] 9 | 10 | if not is_model(model_name): 11 | raise ValueError(f'Unkown model: {model_name}') 12 | 13 | return model_entrypoints(model_name)(config, *args, **kwargs) -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/ops/functions/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------------------------------ 6 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 7 | # ------------------------------------------------------------------------------------------------ 8 | 9 | # Copyright (c) Facebook, Inc. and its affiliates. 10 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 11 | 12 | from .ms_deform_attn_func import MSDeformAttnFunction 13 | 14 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/ops/make.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------------------------------ 3 | # Deformable DETR 4 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | # ------------------------------------------------------------------------------------------------ 7 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | # ------------------------------------------------------------------------------------------------ 9 | 10 | # Copyright (c) Facebook, Inc. and its affiliates. 11 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 12 | 13 | python setup.py build install 14 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/ops/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------------------------------ 6 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 7 | # ------------------------------------------------------------------------------------------------ 8 | 9 | # Copyright (c) Facebook, Inc. and its affiliates. 10 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 11 | 12 | from .ms_deform_attn import MSDeformAttn 13 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/ops/src/cpu/ms_deform_attn_cpu.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | 22 | at::Tensor 23 | ms_deform_attn_cpu_forward( 24 | const at::Tensor &value, 25 | const at::Tensor &spatial_shapes, 26 | const at::Tensor &level_start_index, 27 | const at::Tensor &sampling_loc, 28 | const at::Tensor &attn_weight, 29 | const int im2col_step) 30 | { 31 | AT_ERROR("Not implement on cpu"); 32 | } 33 | 34 | std::vector 35 | ms_deform_attn_cpu_backward( 36 | const at::Tensor &value, 37 | const at::Tensor &spatial_shapes, 38 | const at::Tensor &level_start_index, 39 | const at::Tensor &sampling_loc, 40 | const at::Tensor &attn_weight, 41 | const at::Tensor &grad_output, 42 | const int im2col_step) 43 | { 44 | AT_ERROR("Not implement on cpu"); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/ops/src/cpu/ms_deform_attn_cpu.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #pragma once 17 | #include 18 | 19 | at::Tensor 20 | ms_deform_attn_cpu_forward( 21 | const at::Tensor &value, 22 | const at::Tensor &spatial_shapes, 23 | const at::Tensor &level_start_index, 24 | const at::Tensor &sampling_loc, 25 | const at::Tensor &attn_weight, 26 | const int im2col_step); 27 | 28 | std::vector 29 | ms_deform_attn_cpu_backward( 30 | const at::Tensor &value, 31 | const at::Tensor &spatial_shapes, 32 | const at::Tensor &level_start_index, 33 | const at::Tensor &sampling_loc, 34 | const at::Tensor &attn_weight, 35 | const at::Tensor &grad_output, 36 | const int im2col_step); 37 | 38 | 39 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/ops/src/cuda/ms_deform_attn_cuda.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #pragma once 17 | #include 18 | 19 | at::Tensor ms_deform_attn_cuda_forward( 20 | const at::Tensor &value, 21 | const at::Tensor &spatial_shapes, 22 | const at::Tensor &level_start_index, 23 | const at::Tensor &sampling_loc, 24 | const at::Tensor &attn_weight, 25 | const int im2col_step); 26 | 27 | std::vector ms_deform_attn_cuda_backward( 28 | const at::Tensor &value, 29 | const at::Tensor &spatial_shapes, 30 | const at::Tensor &level_start_index, 31 | const at::Tensor &sampling_loc, 32 | const at::Tensor &attn_weight, 33 | const at::Tensor &grad_output, 34 | const int im2col_step); 35 | 36 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/ops/src/vision.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #include "ms_deform_attn.h" 17 | 18 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 19 | m.def("ms_deform_attn_forward", &ms_deform_attn_forward, "ms_deform_attn_forward"); 20 | m.def("ms_deform_attn_backward", &ms_deform_attn_backward, "ms_deform_attn_backward"); 21 | } 22 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/encoder/registry.py: -------------------------------------------------------------------------------- 1 | _model_entrypoints = {} 2 | 3 | def register_encoder(fn): 4 | module_name_split = fn.__module__.split('.') 5 | model_name = module_name_split[-1] 6 | _model_entrypoints[model_name] = fn 7 | return fn 8 | 9 | def model_entrypoints(model_name): 10 | return _model_entrypoints[model_name] 11 | 12 | def is_model(model_name): 13 | return model_name in _model_entrypoints 14 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/body/registry.py: -------------------------------------------------------------------------------- 1 | _model_entrypoints = {} 2 | 3 | 4 | def register_body(fn): 5 | module_name_split = fn.__module__.split('.') 6 | model_name = module_name_split[-1] 7 | _model_entrypoints[model_name] = fn 8 | return fn 9 | 10 | def model_entrypoints(model_name): 11 | return _model_entrypoints[model_name] 12 | 13 | def is_model(model_name): 14 | return model_name in _model_entrypoints -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .vis_dataset_mapper import YTVISDatasetMapper 2 | from .coco_dataset_mapper import DetrDatasetMapper 3 | from .coco_instance_new_baseline_dataset_mapper import COCOInstanceNewBaselineDatasetMapper, COCOInstanceNewBaselineMixupDatasetMapper 4 | from .build import * 5 | from .datasets import * 6 | from .refcoco_dataset_mapper import RefCOCODatasetMapper 7 | from .custom_dataset_dataloader import * 8 | # from .ytvis_eval import YTVISEvaluator 9 | # from .omnilabel_eval import OMNILABEL_Evaluator 10 | from .two_crop_mapper import COCO_CLIP_DatasetMapper 11 | from .uni_video_image_mapper import UnivideoimageDatasetMapper 12 | from .uni_video_pseudo_mapper import UnivideopseudoDatasetMapper 13 | from .joint_image_dataset_LSJ_mapper import Joint_Image_LSJDatasetMapper 14 | from .pascal_part_new_baseline_dataset_mapper import PascalPartNewBaselineDatasetMapper 15 | from .paco_evaluation import PACOEvaluator 16 | from .pascal_part_openvocabulary_evaluation import PASCALPARTEvaluator 17 | from .joint_new_baseline_dataset_mapper import JointNewBaselineDatasetMapper 18 | from .object_part_mapper import SemanticObjPartDatasetMapper 19 | from .coco_panoptic_new_baseline_dataset_mapper import COCOPanopticNewBaselineDatasetMapper 20 | from .instance_evaluation import InstanceSegEvaluator 21 | from .seginw_dataset_mapper import SeginWDatasetMapper -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/ade20k_evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | from .generalized_sem_seg_evaluation import GeneralizedSemSegEvaluator 2 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | from . import builtin # ensure the builtin datasets are registered 2 | from . import paco 3 | 4 | __all__ = [k for k in globals().keys() if "builtin" not in k and not k.startswith("_")] 5 | 6 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/paco_eval_api/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | 3 | # This source code is licensed under the license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | from .eval import PACOEval 7 | from .paco import PACO 8 | from .results import PACOResults 9 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/seginw/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .config import * 2 | from .misc import * -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/seginw/utils/utils/Config.py: -------------------------------------------------------------------------------- 1 | from fvcore.common.config import CfgNode as _CfgNode 2 | 3 | class CfgNode(_CfgNode): 4 | """ 5 | The same as `fvcore.common.config.CfgNode`, but different in: 6 | 7 | 1. Use unsafe yaml loading by default. 8 | Note that this may lead to arbitrary code execution: you must not 9 | load a config file from untrusted sources before manually inspecting 10 | the content of the file. 11 | 2. Support config versioning. 12 | When attempting to merge an old config, it will convert the old config automatically. 13 | 14 | .. automethod:: clone 15 | .. automethod:: freeze 16 | .. automethod:: defrost 17 | .. automethod:: is_frozen 18 | .. automethod:: load_yaml_with_base 19 | .. automethod:: merge_from_list 20 | .. automethod:: merge_from_other_cfg 21 | """ 22 | 23 | def merge_from_dict(self, dict): 24 | pass 25 | 26 | node = CfgNode() -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/seginw/utils/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/projects/PartGLEE/partglee/data/seginw/utils/utils/__init__.py -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from fvcore.transforms.transform import Transform, TransformList # order them first 3 | from fvcore.transforms.transform import * 4 | from .transform import * 5 | from .augmentation import * 6 | from .augmentation_impl import * 7 | 8 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 9 | 10 | 11 | from detectron2.utils.env import fixup_module_metadata 12 | 13 | fixup_module_metadata(__name__, globals(), __all__) 14 | del fixup_module_metadata 15 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/data/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | 3 | # This source code is licensed under the license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | from .paco_query_utils import ( 7 | compute_similarity_matrix, 8 | ) 9 | 10 | __all__ = list(globals().keys()) 11 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/language/LangEncoder/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from __future__ import division 3 | from __future__ import print_function 4 | 5 | from .build import build_lang_encoder 6 | from .build import build_tokenizer 7 | 8 | from .transformer import * -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/language/LangEncoder/build.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from transformers import CLIPTokenizer, CLIPTokenizerFast 4 | from transformers import AutoTokenizer 5 | 6 | from .registry import lang_encoders 7 | from .registry import is_lang_encoder 8 | 9 | 10 | def build_lang_encoder(config_encoder, tokenizer, verbose, **kwargs): 11 | model_name = config_encoder['NAME'] 12 | 13 | if not is_lang_encoder(model_name): 14 | raise ValueError(f'Unkown model: {model_name}') 15 | 16 | return lang_encoders(model_name)(config_encoder, tokenizer, verbose, **kwargs) 17 | 18 | 19 | def build_tokenizer(config_encoder): 20 | tokenizer = None 21 | os.environ['TOKENIZERS_PARALLELISM'] = 'true' 22 | if config_encoder['TOKENIZER'] == 'clip': 23 | 24 | pretrained_tokenizer = config_encoder.get( 25 | 'PRETRAINED_TOKENIZER', 'openai/clip-vit-base-patch32' 26 | ) 27 | # tokenizer = CLIPTokenizer.from_pretrained(pretrained_tokenizer) 28 | tokenizer = CLIPTokenizer.from_pretrained('projects/STAnything/clip_vit_base_patch32') 29 | 30 | tokenizer.add_special_tokens({'cls_token': tokenizer.eos_token}) 31 | elif config_encoder['TOKENIZER'] == 'clip-fast': 32 | pretrained_tokenizer = config_encoder.get( 33 | 'PRETRAINED_TOKENIZER', 'openai/clip-vit-base-patch32' 34 | ) 35 | tokenizer = CLIPTokenizerFast.from_pretrained(pretrained_tokenizer, from_slow=True) 36 | else: 37 | tokenizer = AutoTokenizer.from_pretrained(config_encoder['TOKENIZER']) 38 | 39 | return tokenizer 40 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/language/LangEncoder/model.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | import time 4 | import pickle 5 | 6 | import torch 7 | import torch.distributed as dist 8 | 9 | from fvcore.nn import FlopCountAnalysis 10 | from fvcore.nn import flop_count_table 11 | from fvcore.nn import flop_count_str 12 | 13 | logger = logging.getLogger(__name__) 14 | 15 | 16 | NORM_MODULES = [ 17 | torch.nn.BatchNorm1d, 18 | torch.nn.BatchNorm2d, 19 | torch.nn.BatchNorm3d, 20 | torch.nn.SyncBatchNorm, 21 | # NaiveSyncBatchNorm inherits from BatchNorm2d 22 | torch.nn.GroupNorm, 23 | torch.nn.InstanceNorm1d, 24 | torch.nn.InstanceNorm2d, 25 | torch.nn.InstanceNorm3d, 26 | torch.nn.LayerNorm, 27 | torch.nn.LocalResponseNorm, 28 | ] 29 | 30 | def register_norm_module(cls): 31 | NORM_MODULES.append(cls) 32 | return cls -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/language/LangEncoder/registry.py: -------------------------------------------------------------------------------- 1 | _lang_encoders = {} 2 | 3 | 4 | def register_lang_encoder(fn): 5 | module_name_split = fn.__module__.split('.') 6 | model_name = module_name_split[-1] 7 | _lang_encoders[model_name] = fn 8 | 9 | return fn 10 | 11 | 12 | def lang_encoders(model_name): 13 | return _lang_encoders[model_name] 14 | 15 | 16 | def is_lang_encoder(model_name): 17 | return model_name in _lang_encoders 18 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/language/__init__.py: -------------------------------------------------------------------------------- 1 | from .fixvlpencoder import * 2 | from .vlpencoder import * 3 | from .build import build_language_encoder 4 | 5 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/language/build.py: -------------------------------------------------------------------------------- 1 | from .registry import model_entrypoints 2 | from .registry import is_model 3 | 4 | 5 | def build_language_encoder(config, **kwargs): 6 | model_name = config['MODEL']['TEXT']['ARCH'] 7 | 8 | if not is_model(model_name): 9 | raise ValueError(f'Unkown model: {model_name}') 10 | 11 | return model_entrypoints(model_name)(config, **kwargs) -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/language/fixvlpencoder.py: -------------------------------------------------------------------------------- 1 | from importlib.metadata import requires 2 | import torch 3 | import torch.nn as nn 4 | 5 | from .registry import register_model 6 | from .vlpencoder import LanguageEncoder 7 | 8 | class FixLanguageEncoder(LanguageEncoder): 9 | 10 | def __init__( 11 | self, 12 | *args, **kwargs): 13 | super(FixLanguageEncoder, self).__init__(*args, **kwargs) 14 | self.logit_scale = nn.Parameter(torch.ones([]), requires_grad=False) 15 | 16 | @torch.no_grad() 17 | def get_text_embeddings(self, *args, **kwargs): 18 | return super().get_text_embeddings(*args, **kwargs) 19 | 20 | @torch.no_grad() 21 | def get_text_token_embeddings(self, *args, **kwargs): 22 | return super().get_text_token_embeddings(*args, **kwargs) 23 | 24 | @torch.no_grad() 25 | def forward_language(self, *args, **kwargs): 26 | return super().forward_language(*args, **kwargs) 27 | 28 | @torch.no_grad() 29 | def forward_language_token(self, *args, **kwargs): 30 | return super().forward_language_token(*args, **kwargs) 31 | 32 | 33 | @register_model 34 | def get_language_model(cfg, **kwargs): 35 | return FixLanguageEncoder(cfg) -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/language/registry.py: -------------------------------------------------------------------------------- 1 | _model_entrypoints = {} 2 | 3 | def register_model(fn): 4 | module_name_split = fn.__module__.split('.') 5 | model_name = module_name_split[-1] 6 | _model_entrypoints[model_name] = fn 7 | return fn 8 | 9 | def model_entrypoints(model_name): 10 | return _model_entrypoints[model_name] 11 | 12 | def is_model(model_name): 13 | return model_name in _model_entrypoints -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/pixel_decoder/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) IDEA, Inc. and its affiliates. 2 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/pixel_decoder/ops/functions/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------------------------------ 6 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 7 | # ------------------------------------------------------------------------------------------------ 8 | 9 | # Copyright (c) Facebook, Inc. and its affiliates. 10 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 11 | 12 | from .ms_deform_attn_func import MSDeformAttnFunction 13 | 14 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/pixel_decoder/ops/make.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------------------------------ 3 | # Deformable DETR 4 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | # ------------------------------------------------------------------------------------------------ 7 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | # ------------------------------------------------------------------------------------------------ 9 | 10 | # Copyright (c) Facebook, Inc. and its affiliates. 11 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 12 | 13 | python3 setup.py build install --user 14 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/pixel_decoder/ops/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------------ 2 | # Deformable DETR 3 | # Copyright (c) 2020 SenseTime. All Rights Reserved. 4 | # Licensed under the Apache License, Version 2.0 [see LICENSE for details] 5 | # ------------------------------------------------------------------------------------------------ 6 | # Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 7 | # ------------------------------------------------------------------------------------------------ 8 | 9 | # Copyright (c) Facebook, Inc. and its affiliates. 10 | # Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 11 | 12 | from .ms_deform_attn import MSDeformAttn 13 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/pixel_decoder/ops/src/cpu/ms_deform_attn_cpu.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | 22 | at::Tensor 23 | ms_deform_attn_cpu_forward( 24 | const at::Tensor &value, 25 | const at::Tensor &spatial_shapes, 26 | const at::Tensor &level_start_index, 27 | const at::Tensor &sampling_loc, 28 | const at::Tensor &attn_weight, 29 | const int im2col_step) 30 | { 31 | AT_ERROR("Not implement on cpu"); 32 | } 33 | 34 | std::vector 35 | ms_deform_attn_cpu_backward( 36 | const at::Tensor &value, 37 | const at::Tensor &spatial_shapes, 38 | const at::Tensor &level_start_index, 39 | const at::Tensor &sampling_loc, 40 | const at::Tensor &attn_weight, 41 | const at::Tensor &grad_output, 42 | const int im2col_step) 43 | { 44 | AT_ERROR("Not implement on cpu"); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/pixel_decoder/ops/src/cpu/ms_deform_attn_cpu.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #pragma once 17 | #include 18 | 19 | at::Tensor 20 | ms_deform_attn_cpu_forward( 21 | const at::Tensor &value, 22 | const at::Tensor &spatial_shapes, 23 | const at::Tensor &level_start_index, 24 | const at::Tensor &sampling_loc, 25 | const at::Tensor &attn_weight, 26 | const int im2col_step); 27 | 28 | std::vector 29 | ms_deform_attn_cpu_backward( 30 | const at::Tensor &value, 31 | const at::Tensor &spatial_shapes, 32 | const at::Tensor &level_start_index, 33 | const at::Tensor &sampling_loc, 34 | const at::Tensor &attn_weight, 35 | const at::Tensor &grad_output, 36 | const int im2col_step); 37 | 38 | 39 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/pixel_decoder/ops/src/cuda/ms_deform_attn_cuda.h: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #pragma once 17 | #include 18 | 19 | at::Tensor ms_deform_attn_cuda_forward( 20 | const at::Tensor &value, 21 | const at::Tensor &spatial_shapes, 22 | const at::Tensor &level_start_index, 23 | const at::Tensor &sampling_loc, 24 | const at::Tensor &attn_weight, 25 | const int im2col_step); 26 | 27 | std::vector ms_deform_attn_cuda_backward( 28 | const at::Tensor &value, 29 | const at::Tensor &spatial_shapes, 30 | const at::Tensor &level_start_index, 31 | const at::Tensor &sampling_loc, 32 | const at::Tensor &attn_weight, 33 | const at::Tensor &grad_output, 34 | const int im2col_step); 35 | 36 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/pixel_decoder/ops/src/vision.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | ************************************************************************************************** 3 | * Deformable DETR 4 | * Copyright (c) 2020 SenseTime. All Rights Reserved. 5 | * Licensed under the Apache License, Version 2.0 [see LICENSE for details] 6 | ************************************************************************************************** 7 | * Modified from https://github.com/chengdazhi/Deformable-Convolution-V2-PyTorch/tree/pytorch_1.0.0 8 | ************************************************************************************************** 9 | */ 10 | 11 | /*! 12 | * Copyright (c) Facebook, Inc. and its affiliates. 13 | * Modified by Bowen Cheng from https://github.com/fundamentalvision/Deformable-DETR 14 | */ 15 | 16 | #include "ms_deform_attn.h" 17 | 18 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 19 | m.def("ms_deform_attn_forward", &ms_deform_attn_forward, "ms_deform_attn_forward"); 20 | m.def("ms_deform_attn_backward", &ms_deform_attn_backward, "ms_deform_attn_backward"); 21 | } 22 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/models/transformer_decoder/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) IDEA, Inc. and its affiliates. 2 | from .maskdino_decoder import MaskDINODecoder 3 | from .maskdino_part_decoder import MaskDINOPartDecoder 4 | 5 | -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/modules/__init__.py: -------------------------------------------------------------------------------- 1 | from .position_encoding import * 2 | from .attention import * 3 | from .postprocessing import * 4 | from .point_features import * -------------------------------------------------------------------------------- /projects/PartGLEE/partglee/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .config import * 2 | from .misc import * 3 | from .box_ops import * 4 | from .it_contrastive import * 5 | -------------------------------------------------------------------------------- /projects/PartGLEE/tools/converter.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import argparse 3 | 4 | if __name__ == '__main__': 5 | parser = argparse.ArgumentParser() 6 | parser.add_argument('--glee_weight_path', default='projects/PartGLEE/checkpoint/GLEE_Lite_scaleup.pth') 7 | parser.add_argument('--output_path', default='projects/PartGLEE/checkpoint/PartGLEE_converted_from_GLEE_RN50.pth') 8 | args = parser.parse_args() 9 | weights = torch.load(args.glee_weight_path, map_location='cpu') 10 | converted_weights = {} 11 | for key in weights.keys(): 12 | converted_key = key.replace('glee', 'partglee') 13 | if 'predictor' in key: 14 | converted_weights[converted_key.replace('predictor', 'object_predictor')] = weights[key] 15 | converted_weights[converted_key.replace('predictor', 'part_predictor')] = weights[key] 16 | else: 17 | converted_weights[converted_key] = weights[key] 18 | torch.save(converted_weights, args.output_path) -------------------------------------------------------------------------------- /projects/PartGLEE/tools/merge_sa1b.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | annbase = json.load(open('sa_000000_joint.json','rb')) 5 | for i in range(len(annbase['images'])): 6 | annbase['images'][i]['file_name'] = 'sa_000000/' + annbase['images'][i]['file_name'] 7 | 8 | for file_idx in range(1, 50): 9 | ann_i = json.load(open('sa_000{}_joint.json'.format(str(file_idx).zfill(3)),'rb')) 10 | for i in range(len(ann_i['images'])): 11 | ann_i['images'][i]['file_name'] = 'sa_000{}/'.format(str(file_idx).zfill(3)) + ann_i['images'][i]['file_name'] 12 | annbase['images'] += ann_i['images'] 13 | annbase['annotations'] += ann_i['annotations'] 14 | 15 | print('training images:',len(annbase['images'])) 16 | print('training annotations:',len(annbase['annotations'])) 17 | 18 | json.dump(annbase, open('sa1b_subtrain_500k.json' , 'w')) 19 | 20 | 21 | """ 22 | 23 | 10k 24 | training images: 11186 25 | training annotations: 516653 26 | 27 | 20k 28 | training images: 22372 29 | training annotations: 1030482 30 | 31 | 50k 32 | training images: 55930 33 | training annotations: 2573006 34 | 35 | 100k 36 | training images: 111860 37 | training annotations: 5158346 38 | 39 | 40 | 200k 41 | training images: 223720 42 | training annotations: 10342363 43 | 44 | 500k 45 | training images: 559300 46 | training annotations: 25875267 47 | """ -------------------------------------------------------------------------------- /projects/PartGLEE/tools/partimagenet_format_json.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import argparse 3 | import os 4 | import json 5 | 6 | if __name__ == '__main__': 7 | parser = argparse.ArgumentParser() 8 | parser.add_argument('--old_path', default='datasets/partimagenet/train.json') 9 | parser.add_argument('--new_path', default='datasets/partimagenet/train_format.json') 10 | args = parser.parse_args() 11 | 12 | print('Loading PartImageNet json') 13 | data = json.load(open(args.old_path, 'r')) 14 | 15 | for image in data['images']: 16 | file_name = image['file_name'] 17 | new_file_name = file_name[:9] +'/'+ file_name 18 | image['file_name'] = new_file_name 19 | 20 | for ann in data['annotations']: 21 | segs = ann['segmentation'] 22 | new_segs = [] 23 | for seg in segs: 24 | assert len(seg) > 0 and len(seg) % 2 == 0 25 | if len(seg) < 4: 26 | new_segs.append(seg + [0, 0, seg[0], seg[1]]) 27 | if len(seg) == 4: 28 | new_segs.append(seg + [seg[0], seg[1]]) 29 | else: 30 | new_segs.append(seg) 31 | ann['segmentation'] = new_segs 32 | 33 | print('Writing to', args.new_path) 34 | json.dump(data, open(args.new_path, 'w')) 35 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [isort] 2 | line_length=100 3 | multi_line_output=3 4 | include_trailing_comma=True 5 | known_standard_library=numpy,setuptools,mock 6 | skip=./datasets,docs 7 | skip_glob=*/__init__.py,**/configs/**,tests/config/** 8 | known_myself=detectron2 9 | known_third_party=fvcore,matplotlib,cv2,torch,torchvision,PIL,pycocotools,yacs,termcolor,cityscapesscripts,tabulate,tqdm,scipy,lvis,psutil,pkg_resources,caffe2,onnx,panopticapi,black,isort,av,iopath,omegaconf,hydra,yaml,pydoc,submitit,cloudpickle 10 | no_lines_before=STDLIB,THIRDPARTY 11 | sections=FUTURE,STDLIB,THIRDPARTY,myself,FIRSTPARTY,LOCALFOLDER 12 | default_section=FIRSTPARTY 13 | 14 | [mypy] 15 | python_version=3.6 16 | ignore_missing_imports = True 17 | warn_unused_configs = True 18 | disallow_untyped_defs = True 19 | check_untyped_defs = True 20 | warn_unused_ignores = True 21 | warn_redundant_casts = True 22 | show_column_numbers = True 23 | follow_imports = silent 24 | allow_redefinition = True 25 | ; Require all functions to be annotated 26 | disallow_incomplete_defs = True 27 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | ## Unit Tests 2 | 3 | To run the unittests, do: 4 | ``` 5 | cd detectron2 6 | python -m unittest discover -v -s ./tests 7 | ``` 8 | 9 | There are also end-to-end inference & training tests, in [dev/run_*_tests.sh](../dev). 10 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | -------------------------------------------------------------------------------- /tests/config/dir1/dir1_a.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | dir1a_str = "base_a_1" 3 | dir1a_dict = {"a": 1, "b": 2} 4 | -------------------------------------------------------------------------------- /tests/config/dir1/dir1_b.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from detectron2.config import LazyConfig 3 | 4 | # equivalent to relative import 5 | dir1a_str, dir1a_dict = LazyConfig.load_rel("dir1_a.py", ("dir1a_str", "dir1a_dict")) 6 | 7 | dir1b_str = dir1a_str + "_from_b" 8 | dir1b_dict = dir1a_dict 9 | 10 | # Every import is a reload: not modified by other config files 11 | assert dir1a_dict.a == 1 12 | -------------------------------------------------------------------------------- /tests/config/root_cfg.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from itertools import count 3 | 4 | from detectron2.config import LazyCall as L 5 | 6 | from .dir1.dir1_a import dir1a_dict, dir1a_str 7 | 8 | dir1a_dict.a = "modified" 9 | 10 | # modification above won't affect future imports 11 | from .dir1.dir1_b import dir1b_dict, dir1b_str 12 | 13 | 14 | lazyobj = L(count)(x=dir1a_str, y=dir1b_str) 15 | -------------------------------------------------------------------------------- /tests/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/tests/data/__init__.py -------------------------------------------------------------------------------- /tests/layers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/tests/layers/__init__.py -------------------------------------------------------------------------------- /tests/layers/test_nms.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | from __future__ import absolute_import, division, print_function, unicode_literals 3 | import unittest 4 | import torch 5 | 6 | from detectron2.layers import batched_nms 7 | from detectron2.utils.testing import random_boxes 8 | 9 | 10 | class TestNMS(unittest.TestCase): 11 | def _create_tensors(self, N): 12 | boxes = random_boxes(N, 200) 13 | scores = torch.rand(N) 14 | return boxes, scores 15 | 16 | def test_nms_scriptability(self): 17 | N = 2000 18 | num_classes = 50 19 | boxes, scores = self._create_tensors(N) 20 | idxs = torch.randint(0, num_classes, (N,)) 21 | scripted_batched_nms = torch.jit.script(batched_nms) 22 | err_msg = "NMS is incompatible with jit-scripted NMS for IoU={}" 23 | 24 | for iou in [0.2, 0.5, 0.8]: 25 | keep_ref = batched_nms(boxes, scores, idxs, iou) 26 | backup = boxes.clone() 27 | scripted_keep = scripted_batched_nms(boxes, scores, idxs, iou) 28 | assert torch.allclose(boxes, backup), "boxes modified by jit-scripted batched_nms" 29 | self.assertTrue(torch.equal(keep_ref, scripted_keep), err_msg.format(iou)) 30 | 31 | 32 | if __name__ == "__main__": 33 | unittest.main() 34 | -------------------------------------------------------------------------------- /tests/modeling/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/tests/modeling/__init__.py -------------------------------------------------------------------------------- /tests/modeling/test_backbone.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | import unittest 4 | import torch 5 | 6 | import detectron2.export.torchscript # apply patch # noqa 7 | from detectron2 import model_zoo 8 | from detectron2.config import get_cfg 9 | from detectron2.layers import ShapeSpec 10 | from detectron2.modeling.backbone import build_resnet_backbone 11 | from detectron2.modeling.backbone.fpn import build_resnet_fpn_backbone 12 | 13 | 14 | class TestBackBone(unittest.TestCase): 15 | def test_resnet_scriptability(self): 16 | cfg = get_cfg() 17 | resnet = build_resnet_backbone(cfg, ShapeSpec(channels=3)) 18 | 19 | scripted_resnet = torch.jit.script(resnet) 20 | 21 | inp = torch.rand(2, 3, 100, 100) 22 | out1 = resnet(inp)["res4"] 23 | out2 = scripted_resnet(inp)["res4"] 24 | self.assertTrue(torch.allclose(out1, out2)) 25 | 26 | def test_fpn_scriptability(self): 27 | cfg = model_zoo.get_config("Misc/scratch_mask_rcnn_R_50_FPN_3x_gn.yaml") 28 | bb = build_resnet_fpn_backbone(cfg, ShapeSpec(channels=3)) 29 | bb_s = torch.jit.script(bb) 30 | 31 | inp = torch.rand(2, 3, 128, 128) 32 | out1 = bb(inp)["p5"] 33 | out2 = bb_s(inp)["p5"] 34 | self.assertTrue(torch.allclose(out1, out2)) 35 | -------------------------------------------------------------------------------- /tests/structures/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/tests/structures/__init__.py -------------------------------------------------------------------------------- /tests/structures/test_keypoints.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import unittest 3 | import torch 4 | 5 | from detectron2.structures.keypoints import Keypoints 6 | 7 | 8 | class TestKeypoints(unittest.TestCase): 9 | def test_cat_keypoints(self): 10 | keypoints1 = Keypoints(torch.rand(2, 21, 3)) 11 | keypoints2 = Keypoints(torch.rand(4, 21, 3)) 12 | 13 | cat_keypoints = keypoints1.cat([keypoints1, keypoints2]) 14 | self.assertTrue(torch.all(cat_keypoints.tensor[:2] == keypoints1.tensor).item()) 15 | self.assertTrue(torch.all(cat_keypoints.tensor[2:] == keypoints2.tensor).item()) 16 | 17 | 18 | if __name__ == "__main__": 19 | unittest.main() 20 | -------------------------------------------------------------------------------- /tests/test_packaging.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import unittest 3 | 4 | from detectron2.utils.collect_env import collect_env_info 5 | 6 | 7 | class TestProjects(unittest.TestCase): 8 | def test_import(self): 9 | from detectron2.projects import point_rend 10 | 11 | _ = point_rend.add_pointrend_config 12 | 13 | import detectron2.projects.deeplab as deeplab 14 | 15 | _ = deeplab.add_deeplab_config 16 | 17 | # import detectron2.projects.panoptic_deeplab as panoptic_deeplab 18 | 19 | # _ = panoptic_deeplab.add_panoptic_deeplab_config 20 | 21 | 22 | class TestCollectEnv(unittest.TestCase): 23 | def test(self): 24 | _ = collect_env_info() 25 | -------------------------------------------------------------------------------- /tests/test_registry.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | import unittest 3 | import torch 4 | 5 | from detectron2.modeling.meta_arch import GeneralizedRCNN 6 | from detectron2.utils.registry import _convert_target_to_string, locate 7 | 8 | 9 | class A: 10 | class B: 11 | pass 12 | 13 | 14 | class TestLocate(unittest.TestCase): 15 | def _test_obj(self, obj): 16 | name = _convert_target_to_string(obj) 17 | newobj = locate(name) 18 | self.assertIs(obj, newobj) 19 | 20 | def test_basic(self): 21 | self._test_obj(GeneralizedRCNN) 22 | 23 | def test_inside_class(self): 24 | # requires using __qualname__ instead of __name__ 25 | self._test_obj(A.B) 26 | 27 | def test_builtin(self): 28 | self._test_obj(len) 29 | self._test_obj(dict) 30 | 31 | def test_pytorch_optim(self): 32 | # pydoc.locate does not work for it 33 | self._test_obj(torch.optim.SGD) 34 | 35 | def test_failure(self): 36 | with self.assertRaises(ImportError): 37 | locate("asdf") 38 | 39 | def test_compress_target(self): 40 | from detectron2.data.transforms import RandomCrop 41 | 42 | name = _convert_target_to_string(RandomCrop) 43 | # name shouldn't contain 'augmentation_impl' 44 | self.assertEqual(name, "detectron2.data.transforms.RandomCrop") 45 | self.assertIs(RandomCrop, locate(name)) 46 | -------------------------------------------------------------------------------- /tests/tracking/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/tests/tracking/__init__.py -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | 2 | This directory contains a few example scripts that demonstrate features of detectron2. 3 | 4 | 5 | * `train_net.py` 6 | 7 | An example training script that's made to train builtin models of detectron2. 8 | 9 | For usage, see [GETTING_STARTED.md](../GETTING_STARTED.md). 10 | 11 | * `plain_train_net.py` 12 | 13 | Similar to `train_net.py`, but implements a training loop instead of using `Trainer`. 14 | This script includes fewer features but it may be more friendly to hackers. 15 | 16 | * `benchmark.py` 17 | 18 | Benchmark the training speed, inference speed or data loading speed of a given config. 19 | 20 | Usage: 21 | ``` 22 | python benchmark.py --config-file config.yaml --task train/eval/data [optional DDP flags] 23 | ``` 24 | 25 | * `analyze_model.py` 26 | 27 | Analyze FLOPs, parameters, activations of a detectron2 model. See its `--help` for usage. 28 | 29 | * `visualize_json_results.py` 30 | 31 | Visualize the json instance detection/segmentation results dumped by `COCOEvalutor` or `LVISEvaluator` 32 | 33 | Usage: 34 | ``` 35 | python visualize_json_results.py --input x.json --output dir/ --dataset coco_2017_val 36 | ``` 37 | If not using a builtin dataset, you'll need your own script or modify this script. 38 | 39 | * `visualize_data.py` 40 | 41 | Visualize ground truth raw annotations or training data (after preprocessing/augmentations). 42 | 43 | Usage: 44 | ``` 45 | python visualize_data.py --config-file config.yaml --source annotation/dataloader --output-dir dir/ [--show] 46 | ``` 47 | 48 | NOTE: the script does not stop by itself when using `--source dataloader` because a training 49 | dataloader is usually infinite. 50 | -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProvenceStar/PartGLEE/8c6b83e0be076e8fe640943096059ee5c180de0e/tools/__init__.py -------------------------------------------------------------------------------- /tools/convert-pretrained-swin-model-to-d2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | import pickle as pkl 5 | import sys 6 | 7 | import torch 8 | 9 | """ 10 | Usage: 11 | # download pretrained swin model: 12 | wget https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth 13 | # run the conversion 14 | ./convert-pretrained-model-to-d2.py swin_tiny_patch4_window7_224.pth swin_tiny_patch4_window7_224.pkl 15 | # Then, use swin_tiny_patch4_window7_224.pkl with the following changes in config: 16 | MODEL: 17 | WEIGHTS: "/path/to/swin_tiny_patch4_window7_224.pkl" 18 | INPUT: 19 | FORMAT: "RGB" 20 | """ 21 | 22 | if __name__ == "__main__": 23 | input = sys.argv[1] 24 | 25 | obj = torch.load(input, map_location="cpu")["model"] 26 | 27 | res = {"model": obj, "__author__": "third_party", "matching_heuristics": True} 28 | 29 | with open(sys.argv[2], "wb") as f: 30 | pkl.dump(res, f) 31 | -------------------------------------------------------------------------------- /tools/deploy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # See https://pytorch.org/tutorials/advanced/cpp_frontend.html 3 | cmake_minimum_required(VERSION 3.12 FATAL_ERROR) 4 | project(torchscript_mask_rcnn) 5 | 6 | find_package(Torch REQUIRED) 7 | find_package(OpenCV REQUIRED) 8 | find_package(TorchVision REQUIRED) # needed by export-method=tracing/scripting 9 | 10 | add_executable(torchscript_mask_rcnn torchscript_mask_rcnn.cpp) 11 | target_link_libraries( 12 | torchscript_mask_rcnn 13 | -Wl,--no-as-needed TorchVision::TorchVision -Wl,--as-needed 14 | "${TORCH_LIBRARIES}" ${OpenCV_LIBS}) 15 | set_property(TARGET torchscript_mask_rcnn PROPERTY CXX_STANDARD 14) 16 | --------------------------------------------------------------------------------