├── .gitignore ├── GETTING_STARTED.md ├── INSTALL.md ├── LICENSE ├── MODEL_ZOO.md ├── README.md ├── 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 │ ├── retinanet_R_101_FPN_3x.yaml │ ├── 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.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.yaml │ ├── mask_rcnn_R_50_FPN_1x_giou.yaml │ ├── mask_rcnn_R_50_FPN_3x.yaml │ └── mask_rcnn_X_101_32x8d_FPN_3x.yaml ├── COCO-Keypoints │ ├── Base-Keypoint-RCNN-FPN.yaml │ ├── keypoint_rcnn_R_101_FPN_3x.yaml │ ├── 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.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 │ ├── 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 ├── PascalVOC-Detection │ ├── faster_rcnn_R_50_C4.yaml │ └── faster_rcnn_R_50_FPN.yaml └── 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 ├── README.md ├── prepare_cocofied_lvis.py ├── prepare_for_tests.sh └── prepare_panoptic_fpn.py ├── demo ├── README.md ├── demo.py └── predictor.py ├── detectron2 ├── __init__.py ├── checkpoint │ ├── __init__.py │ ├── c2_model_loading.py │ ├── catalog.py │ └── detection_checkpoint.py ├── config │ ├── __init__.py │ ├── compat.py │ ├── config.py │ └── defaults.py ├── data │ ├── __init__.py │ ├── build.py │ ├── catalog.py │ ├── common.py │ ├── dataset_mapper.py │ ├── datasets │ │ ├── README.md │ │ ├── __init__.py │ │ ├── builtin.py │ │ ├── builtin_meta.py │ │ ├── cityscapes.py │ │ ├── coco.py │ │ ├── lvis.py │ │ ├── lvis_v0_5_categories.py │ │ ├── lvis_v0_5_categories_head.py │ │ ├── lvis_v1_categories.py │ │ ├── lvis_v1_categories_head.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_evaluation.py │ ├── panoptic_evaluation.py │ ├── pascal_voc_evaluation.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 │ ├── patcher.py │ └── shared.py ├── layers │ ├── __init__.py │ ├── batch_norm.py │ ├── blocks.py │ ├── csrc │ │ ├── README.md │ │ ├── ROIAlign │ │ │ ├── ROIAlign.h │ │ │ ├── ROIAlign_cpu.cpp │ │ │ └── ROIAlign_cuda.cu │ │ ├── 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 │ ├── mask_ops.py │ ├── nms.py │ ├── roi_align.py │ ├── roi_align_rotated.py │ ├── rotated_boxes.py │ ├── shape_spec.py │ └── wrappers.py ├── model_zoo │ ├── __init__.py │ └── model_zoo.py ├── modeling │ ├── __init__.py │ ├── anchor_generator.py │ ├── backbone │ │ ├── __init__.py │ │ ├── backbone.py │ │ ├── build.py │ │ ├── fpn.py │ │ └── resnet.py │ ├── box_regression.py │ ├── matcher.py │ ├── meta_arch │ │ ├── __init__.py │ │ ├── build.py │ │ ├── panoptic_fpn.py │ │ ├── rcnn.py │ │ ├── retinanet.py │ │ └── semantic_seg.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 ├── 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 └── utils │ ├── README.md │ ├── __init__.py │ ├── analysis.py │ ├── collect_env.py │ ├── colormap.py │ ├── comm.py │ ├── env.py │ ├── events.py │ ├── logger.py │ ├── memory.py │ ├── registry.py │ ├── serialize.py │ ├── video_visualizer.py │ └── visualizer.py ├── detectron2_LICENSE ├── 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 ├── Dockerfile-circleci ├── README.md └── docker-compose.yml ├── docs ├── .gitignore ├── Makefile ├── README.md ├── _static │ └── css │ │ └── custom.css ├── conf.py ├── index.rst ├── modules │ ├── checkpoint.rst │ ├── config.rst │ ├── data.rst │ ├── engine.rst │ ├── evaluation.rst │ ├── export.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 │ ├── builtin_datasets.md │ ├── configs.md │ ├── data_loading.md │ ├── datasets.md │ ├── deployment.md │ ├── evaluation.md │ ├── extend.md │ ├── getting_started.md │ ├── index.rst │ ├── install.md │ ├── models.md │ ├── training.md │ └── write-models.md ├── projects ├── DensePose │ ├── README.md │ ├── apply_net.py │ ├── configs │ │ ├── Base-DensePose-RCNN-FPN.yaml │ │ ├── densepose_rcnn_R_101_FPN_DL_WC1_s1x.yaml │ │ ├── densepose_rcnn_R_101_FPN_DL_WC2_s1x.yaml │ │ ├── densepose_rcnn_R_101_FPN_DL_s1x.yaml │ │ ├── densepose_rcnn_R_101_FPN_WC1_s1x.yaml │ │ ├── densepose_rcnn_R_101_FPN_WC2_s1x.yaml │ │ ├── densepose_rcnn_R_101_FPN_s1x.yaml │ │ ├── densepose_rcnn_R_101_FPN_s1x_legacy.yaml │ │ ├── densepose_rcnn_R_50_FPN_DL_WC1_s1x.yaml │ │ ├── densepose_rcnn_R_50_FPN_DL_WC2_s1x.yaml │ │ ├── densepose_rcnn_R_50_FPN_DL_s1x.yaml │ │ ├── densepose_rcnn_R_50_FPN_WC1_s1x.yaml │ │ ├── densepose_rcnn_R_50_FPN_WC2_s1x.yaml │ │ ├── densepose_rcnn_R_50_FPN_s1x.yaml │ │ ├── densepose_rcnn_R_50_FPN_s1x_legacy.yaml │ │ ├── evolution │ │ │ ├── Base-RCNN-FPN-MC.yaml │ │ │ ├── densepose_R_101_FPN_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_101_FPN_DL_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_101_FPN_DL_WC1M_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_101_FPN_DL_WC1_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_101_FPN_WC1M_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_101_FPN_WC1_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_50_FPN_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_50_FPN_DL_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_50_FPN_DL_WC1M_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_50_FPN_DL_WC1_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_50_FPN_WC1M_1x_Atop10_toP.yaml │ │ │ ├── densepose_R_50_FPN_WC1_1x_Atop10_toP.yaml │ │ │ └── faster_rcnn_R_50_FPN_1x_MC.yaml │ │ └── quick_schedules │ │ │ ├── densepose_rcnn_R_50_FPN_DL_instant_test.yaml │ │ │ ├── densepose_rcnn_R_50_FPN_TTA_inference_acc_test.yaml │ │ │ ├── densepose_rcnn_R_50_FPN_WC1_instant_test.yaml │ │ │ ├── densepose_rcnn_R_50_FPN_WC2_instant_test.yaml │ │ │ ├── densepose_rcnn_R_50_FPN_inference_acc_test.yaml │ │ │ ├── densepose_rcnn_R_50_FPN_instant_test.yaml │ │ │ └── densepose_rcnn_R_50_FPN_training_acc_test.yaml │ ├── densepose │ │ ├── __init__.py │ │ ├── config.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ ├── build.py │ │ │ ├── combined_loader.py │ │ │ ├── dataset_mapper.py │ │ │ ├── datasets │ │ │ │ ├── __init__.py │ │ │ │ ├── builtin.py │ │ │ │ ├── chimpnsee.py │ │ │ │ ├── coco.py │ │ │ │ └── dataset_type.py │ │ │ ├── inference_based_loader.py │ │ │ ├── structures.py │ │ │ ├── transform │ │ │ │ ├── __init__.py │ │ │ │ └── image.py │ │ │ ├── utils.py │ │ │ └── video │ │ │ │ ├── __init__.py │ │ │ │ ├── frame_selector.py │ │ │ │ └── video_keyframe_dataset.py │ │ ├── densepose_coco_evaluation.py │ │ ├── densepose_head.py │ │ ├── engine │ │ │ ├── __init__.py │ │ │ └── trainer.py │ │ ├── evaluator.py │ │ ├── modeling │ │ │ └── test_time_augmentation.py │ │ ├── roi_head.py │ │ ├── utils │ │ │ ├── dbhelper.py │ │ │ ├── logger.py │ │ │ └── transform.py │ │ └── vis │ │ │ ├── base.py │ │ │ ├── bounding_box.py │ │ │ ├── densepose.py │ │ │ └── extractor.py │ ├── dev │ │ ├── README.md │ │ ├── run_inference_tests.sh │ │ └── run_instant_tests.sh │ ├── doc │ │ ├── GETTING_STARTED.md │ │ ├── MODEL_ZOO.md │ │ ├── TOOL_APPLY_NET.md │ │ ├── TOOL_QUERY_DB.md │ │ └── images │ │ │ ├── res_bbox_dp_contour.jpg │ │ │ ├── res_bbox_dp_segm.jpg │ │ │ ├── res_bbox_dp_u.jpg │ │ │ ├── res_bbox_dp_v.jpg │ │ │ ├── vis_bbox_dp_i.jpg │ │ │ ├── vis_bbox_dp_pts.jpg │ │ │ ├── vis_bbox_dp_segm.jpg │ │ │ ├── vis_bbox_dp_u.jpg │ │ │ └── vis_bbox_dp_v.jpg │ ├── query_db.py │ ├── tests │ │ ├── common.py │ │ ├── test_combine_data_loader.py │ │ ├── test_frame_selector.py │ │ ├── test_image_resize_transform.py │ │ ├── test_model_e2e.py │ │ ├── test_setup.py │ │ ├── test_structures.py │ │ └── test_video_keyframe_dataset.py │ └── train_net.py ├── PointRend │ ├── README.md │ ├── configs │ │ ├── InstanceSegmentation │ │ │ ├── Base-PointRend-RCNN-FPN.yaml │ │ │ ├── pointrend_rcnn_R_50_FPN_1x_cityscapes.yaml │ │ │ ├── pointrend_rcnn_R_50_FPN_1x_coco.yaml │ │ │ └── pointrend_rcnn_R_50_FPN_3x_coco.yaml │ │ └── SemanticSegmentation │ │ │ ├── Base-PointRend-Semantic-FPN.yaml │ │ │ ├── pointrend_semantic_R_101_FPN_1x_cityscapes.yaml │ │ │ └── pointrend_semantic_R_50_FPN_1x_coco.yaml │ ├── point_rend │ │ ├── __init__.py │ │ ├── coarse_mask_head.py │ │ ├── color_augmentation.py │ │ ├── config.py │ │ ├── dataset_mapper.py │ │ ├── point_features.py │ │ ├── point_head.py │ │ ├── roi_heads.py │ │ └── semantic_seg.py │ └── train_net.py ├── README.md ├── RIO │ ├── configs │ │ ├── Base-Memory-RCNN-FPN.yaml │ │ ├── Base-RCNN-C4.yaml │ │ ├── Base-RCNN-DilatedC5.yaml │ │ ├── Base-RCNN-FPN.yaml │ │ ├── Base-RetinaNet.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 │ │ │ ├── memory_mask_rcnn_R_101_FPN_1x.yaml │ │ │ ├── memory_mask_rcnn_R_50_FPN_1x.yaml │ │ │ └── memory_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 │ │ │ ├── memory_mask_rcnn_R_101_FPN_1x.yaml │ │ │ ├── memory_mask_rcnn_R_50_FPN_1x.yaml │ │ │ └── memory_mask_rcnn_X_101_32x8d_FPN_1x.yaml │ ├── lvis_categories_lists │ │ ├── lvis0.5_all_cats.txt │ │ ├── lvis0.5_common_cats.txt │ │ ├── lvis0.5_frequent_cats.txt │ │ ├── lvis0.5_rare_cats.txt │ │ ├── lvis0.5_rare_common30_cats.txt │ │ ├── lvis1_all_cats.txt │ │ ├── lvis1_common_cats.txt │ │ ├── lvis1_frequent_cats.txt │ │ ├── lvis1_rare_cats.txt │ │ └── lvis1_rare_common30_cats.txt │ ├── memory_bank │ │ ├── __init__.py │ │ ├── cfg.py │ │ ├── fast_rcnn.py │ │ ├── lvis_v0_5_categories.py │ │ ├── new_layers.py │ │ └── roi_heads.py │ └── memory_train_net.py ├── TensorMask │ ├── README.md │ ├── configs │ │ ├── Base-TensorMask.yaml │ │ ├── tensormask_R_50_FPN_1x.yaml │ │ └── tensormask_R_50_FPN_6x.yaml │ ├── setup.py │ ├── tensormask │ │ ├── __init__.py │ │ ├── arch.py │ │ ├── config.py │ │ └── layers │ │ │ ├── __init__.py │ │ │ ├── csrc │ │ │ ├── SwapAlign2Nat │ │ │ │ ├── SwapAlign2Nat.h │ │ │ │ └── SwapAlign2Nat_cuda.cu │ │ │ └── vision.cpp │ │ │ └── swap_align2nat.py │ ├── tests │ │ ├── __init__.py │ │ └── test_swap_align2nat.py │ └── train_net.py └── TridentNet │ ├── README.md │ ├── configs │ ├── Base-TridentNet-Fast-C4.yaml │ ├── tridentnet_fast_R_101_C4_3x.yaml │ ├── tridentnet_fast_R_50_C4_1x.yaml │ └── tridentnet_fast_R_50_C4_3x.yaml │ ├── train_net.py │ └── tridentnet │ ├── __init__.py │ ├── config.py │ ├── trident_backbone.py │ ├── trident_conv.py │ ├── trident_rcnn.py │ └── trident_rpn.py ├── resources └── github_thumbnail.png ├── setup.cfg ├── setup.py ├── tests ├── README.md ├── __init__.py ├── data │ ├── __init__.py │ ├── test_coco.py │ ├── test_coco_evaluation.py │ ├── test_detection_utils.py │ ├── test_rotation_transform.py │ ├── test_sampler.py │ └── test_transforms.py ├── layers │ ├── __init__.py │ ├── test_mask_ops.py │ ├── test_nms_rotated.py │ ├── test_roi_align.py │ └── test_roi_align_rotated.py ├── modeling │ ├── __init__.py │ ├── test_anchor_generator.py │ ├── test_box2box_transform.py │ ├── test_fast_rcnn.py │ ├── test_matcher.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_rotated_boxes.py ├── test_checkpoint.py ├── test_config.py ├── test_export_caffe2.py ├── test_model_analysis.py ├── test_model_zoo.py └── test_visualizer.py └── tools ├── README.md ├── analyze_model.py ├── benchmark.py ├── convert-torchvision-to-d2.py ├── deploy ├── CMakeLists.txt ├── README.md ├── caffe2_converter.py ├── caffe2_mask_rcnn.cpp └── torchscript_traced_mask_rcnn.cpp ├── plain_train_net.py ├── train_net.py ├── visualize_data.py └── visualize_json_results.py /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | *~ 3 | *.pdf 4 | *.so 5 | *.png 6 | *pycache_* 7 | *.DS_STORE 8 | *datasets/coco 9 | 10 | -------------------------------------------------------------------------------- /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/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.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.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.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-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.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 | -------------------------------------------------------------------------------- /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.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/quick_schedules/README.md: -------------------------------------------------------------------------------- 1 | These are quick configs for performance or accuracy regression tracking purposes. 2 | -------------------------------------------------------------------------------- /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 | DATASETS: 6 | TRAIN: ("keypoints_coco_2017_val_100",) 7 | TEST: ("keypoints_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/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", 38.73, 0.7], ["sem_seg", "mIoU", 64.73, 1.2], ["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 | -------------------------------------------------------------------------------- /datasets/prepare_for_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | # Download some files needed for running tests. 5 | 6 | cd "${0%/*}" 7 | 8 | BASE=https://dl.fbaipublicfiles.com/detectron2 9 | mkdir -p coco/annotations 10 | 11 | for anno in instances_val2017_100 \ 12 | person_keypoints_val2017_100 \ 13 | instances_minival2014_100 \ 14 | person_keypoints_minival2014_100; do 15 | 16 | dest=coco/annotations/$anno.json 17 | [[ -s $dest ]] && { 18 | echo "$dest exists. Skipping ..." 19 | } || { 20 | wget $BASE/annotations/coco/$anno.json -O $dest 21 | } 22 | done 23 | -------------------------------------------------------------------------------- /demo/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Detectron2 Demo 3 | 4 | We provide a command line tool to run a simple demo of builtin models. 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/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 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.1.3" 11 | -------------------------------------------------------------------------------- /detectron2/checkpoint/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | # File: 4 | 5 | 6 | from . import catalog as _UNUSED # register the handler 7 | from .detection_checkpoint import DetectionCheckpointer 8 | from fvcore.common.checkpoint import Checkpointer, PeriodicCheckpointer 9 | 10 | __all__ = ["Checkpointer", "PeriodicCheckpointer", "DetectionCheckpointer"] 11 | -------------------------------------------------------------------------------- /detectron2/config/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .compat import downgrade_config, upgrade_config 3 | from .config import CfgNode, get_cfg, global_cfg, set_global_cfg, configurable 4 | 5 | __all__ = [ 6 | "CfgNode", 7 | "get_cfg", 8 | "global_cfg", 9 | "set_global_cfg", 10 | "downgrade_config", 11 | "upgrade_config", 12 | "configurable", 13 | ] 14 | -------------------------------------------------------------------------------- /detectron2/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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 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. All Rights Reserved 2 | from .cityscapes import load_cityscapes_instances 3 | from .coco import load_coco_json, load_sem_seg 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 .register_coco import register_coco_instances, register_coco_panoptic_separated 7 | from . import builtin # ensure the builtin datasets are registered 8 | 9 | 10 | __all__ = [k for k in globals().keys() if "builtin" not in k and not k.startswith("_")] 11 | -------------------------------------------------------------------------------- /detectron2/data/samplers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .distributed_sampler import InferenceSampler, RepeatFactorTrainingSampler, TrainingSampler 3 | from .grouped_batch_sampler import GroupedBatchSampler 4 | 5 | __all__ = [ 6 | "GroupedBatchSampler", 7 | "TrainingSampler", 8 | "InferenceSampler", 9 | "RepeatFactorTrainingSampler", 10 | ] 11 | -------------------------------------------------------------------------------- /detectron2/data/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .transform import * 3 | from fvcore.transforms.transform import * 4 | from .augmentation import * 5 | from .augmentation_impl import * 6 | 7 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 8 | -------------------------------------------------------------------------------- /detectron2/engine/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 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. All Rights Reserved 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 | 12 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 13 | -------------------------------------------------------------------------------- /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 conversion tools. 11 | -------------------------------------------------------------------------------- /detectron2/export/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from .api import * 4 | 5 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 6 | -------------------------------------------------------------------------------- /detectron2/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .batch_norm import FrozenBatchNorm2d, get_norm, NaiveSyncBatchNorm 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 BatchNorm2d, Conv2d, ConvTranspose2d, cat, interpolate, Linear, nonzero_tuple 10 | from .blocks import CNNBlockBase 11 | 12 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 13 | -------------------------------------------------------------------------------- /detectron2/layers/blocks.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | from torch import nn 5 | 6 | from .batch_norm import FrozenBatchNorm2d 7 | 8 | 9 | class CNNBlockBase(nn.Module): 10 | """ 11 | A CNN block is assumed to have input channels, output channels and a stride. 12 | The input and output of `forward()` method must be NCHW tensors. 13 | The method can perform arbitrary computation but must match the given 14 | channels and stride specification. 15 | 16 | Attribute: 17 | in_channels (int): 18 | out_channels (int): 19 | stride (int): 20 | """ 21 | 22 | def __init__(self, in_channels, out_channels, stride): 23 | """ 24 | The `__init__` method of any subclass should also contain these arguments. 25 | 26 | Args: 27 | in_channels (int): 28 | out_channels (int): 29 | stride (int): 30 | """ 31 | super().__init__() 32 | self.in_channels = in_channels 33 | self.out_channels = out_channels 34 | self.stride = stride 35 | 36 | def freeze(self): 37 | """ 38 | Make this block not trainable. 39 | This method sets all parameters to `requires_grad=False`, 40 | and convert all BatchNorm layers to FrozenBatchNorm 41 | 42 | Returns: 43 | the block itself 44 | """ 45 | for p in self.parameters(): 46 | p.requires_grad = False 47 | FrozenBatchNorm2d.convert_frozen_batchnorm(self) 48 | return self 49 | -------------------------------------------------------------------------------- /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. All Rights Reserved 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("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. All Rights Reserved 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. All Rights Reserved. 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. All Rights Reserved 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 float 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 float 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 float 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("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. All Rights Reserved 2 | from __future__ import absolute_import, division, print_function, unicode_literals 3 | 4 | from detectron2 import _C 5 | 6 | 7 | def pairwise_iou_rotated(boxes1, boxes2): 8 | """ 9 | Return intersection-over-union (Jaccard index) of boxes. 10 | 11 | Both sets of boxes are expected to be in 12 | (x_center, y_center, width, height, angle) format. 13 | 14 | Arguments: 15 | boxes1 (Tensor[N, 5]) 16 | boxes2 (Tensor[M, 5]) 17 | 18 | Returns: 19 | iou (Tensor[N, M]): the NxM matrix containing the pairwise 20 | IoU values for every element in boxes1 and boxes2 21 | """ 22 | return _C.box_iou_rotated(boxes1, boxes2) 23 | -------------------------------------------------------------------------------- /detectron2/layers/shape_spec.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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 obtain the 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. All Rights Reserved 2 | """ 3 | Model Zoo API for Detectron2: a collection of functions to create common model architectures and 4 | optionally load pre-trained weights as released in 5 | `MODEL_ZOO.md `_. 6 | """ 7 | from .model_zoo import get, get_config_file, get_checkpoint_url 8 | 9 | __all__ = ["get_checkpoint_url", "get", "get_config_file"] 10 | -------------------------------------------------------------------------------- /detectron2/modeling/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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 | ) 26 | from .postprocessing import detector_postprocess 27 | from .proposal_generator import ( 28 | PROPOSAL_GENERATOR_REGISTRY, 29 | build_proposal_generator, 30 | RPN_HEAD_REGISTRY, 31 | build_rpn_head, 32 | ) 33 | from .roi_heads import ( 34 | ROI_BOX_HEAD_REGISTRY, 35 | ROI_HEADS_REGISTRY, 36 | ROI_KEYPOINT_HEAD_REGISTRY, 37 | ROI_MASK_HEAD_REGISTRY, 38 | ROIHeads, 39 | StandardROIHeads, 40 | BaseMaskRCNNHead, 41 | BaseKeypointRCNNHead, 42 | build_box_head, 43 | build_keypoint_head, 44 | build_mask_head, 45 | build_roi_heads, 46 | ) 47 | from .test_time_augmentation import DatasetMapperTTA, GeneralizedRCNNWithTTA 48 | 49 | _EXCLUDE = {"ShapeSpec"} 50 | __all__ = [k for k in globals().keys() if k not in _EXCLUDE and not k.startswith("_")] 51 | -------------------------------------------------------------------------------- /detectron2/modeling/backbone/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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 .resnet import ResNet, ResNetBlockBase, build_resnet_backbone, make_stage 7 | 8 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 9 | # TODO can expose more resnet blocks after careful consideration 10 | -------------------------------------------------------------------------------- /detectron2/modeling/backbone/backbone.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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): 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. All Rights Reserved 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 | It must returns an 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. All Rights Reserved 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 .retinanet import RetinaNet 11 | from .semantic_seg import SEM_SEG_HEADS_REGISTRY, SemanticSegmentor, build_sem_seg_head 12 | 13 | 14 | __all__ = list(globals().keys()) 15 | -------------------------------------------------------------------------------- /detectron2/modeling/meta_arch/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | import torch 3 | 4 | from detectron2.utils.registry import Registry 5 | 6 | META_ARCH_REGISTRY = Registry("META_ARCH") # noqa F401 isort:skip 7 | META_ARCH_REGISTRY.__doc__ = """ 8 | Registry for meta-architectures, i.e. the whole model. 9 | 10 | The registered object will be called with `obj(cfg)` 11 | and expected to return a `nn.Module` object. 12 | """ 13 | 14 | 15 | def build_model(cfg): 16 | """ 17 | Build the whole model architecture, defined by ``cfg.MODEL.META_ARCHITECTURE``. 18 | Note that it does not load any weights from ``cfg``. 19 | """ 20 | meta_arch = cfg.MODEL.META_ARCHITECTURE 21 | model = META_ARCH_REGISTRY.get(meta_arch)(cfg) 22 | model.to(torch.device(cfg.MODEL.DEVICE)) 23 | return model 24 | -------------------------------------------------------------------------------- /detectron2/modeling/proposal_generator/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .build import PROPOSAL_GENERATOR_REGISTRY, build_proposal_generator 3 | from .rpn import RPN_HEAD_REGISTRY, build_rpn_head, RPN 4 | 5 | __all__ = list(globals().keys()) 6 | -------------------------------------------------------------------------------- /detectron2/modeling/proposal_generator/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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. All Rights Reserved 2 | from .box_head import ROI_BOX_HEAD_REGISTRY, build_box_head 3 | from .keypoint_head import ROI_KEYPOINT_HEAD_REGISTRY, build_keypoint_head, BaseKeypointRCNNHead 4 | from .mask_head import ROI_MASK_HEAD_REGISTRY, build_mask_head, BaseMaskRCNNHead 5 | from .roi_heads import ( 6 | ROI_HEADS_REGISTRY, 7 | ROIHeads, 8 | Res5ROIHeads, 9 | StandardROIHeads, 10 | build_roi_heads, 11 | select_foreground_proposals, 12 | ) 13 | from .rotated_fast_rcnn import RROIHeads 14 | from .fast_rcnn import FastRCNNOutputLayers 15 | 16 | from . import cascade_rcnn # isort:skip 17 | 18 | __all__ = list(globals().keys()) 19 | -------------------------------------------------------------------------------- /detectron2/solver/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .build import build_lr_scheduler, build_optimizer 3 | from .lr_scheduler import WarmupCosineLR, WarmupMultiStepLR 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. All Rights Reserved 2 | from .boxes import Boxes, BoxMode, pairwise_iou 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, rasterize_polygons_within_box, polygons_to_bitmask 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 | -------------------------------------------------------------------------------- /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. All Rights Reserved 2 | -------------------------------------------------------------------------------- /detectron2/utils/registry.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | # Keep this module for backward compatibility. 4 | from fvcore.common.registry import Registry # noqa 5 | 6 | __all__ = ["Registry"] 7 | -------------------------------------------------------------------------------- /detectron2/utils/serialize.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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 | self._obj = obj 17 | 18 | def __reduce__(self): 19 | s = cloudpickle.dumps(self._obj) 20 | return cloudpickle.loads, (s,) 21 | 22 | def __call__(self, *args, **kwargs): 23 | return self._obj(*args, **kwargs) 24 | 25 | def __getattr__(self, attr): 26 | # Ensure that the wrapped object can be used seamlessly as the previous object. 27 | if attr not in ["_obj"]: 28 | return getattr(self._obj, attr) 29 | return getattr(self, attr) 30 | -------------------------------------------------------------------------------- /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. All Rights Reserved 3 | 4 | # Run this script at project root by "./dev/linter.sh" before you commit 5 | 6 | vergte() { 7 | [ "$2" = "$(echo -e "$1\\n$2" | sort -V | head -n1)" ] 8 | } 9 | 10 | { 11 | black --version | grep -E "(19.3b0.*6733274)|(19.3b0\\+8)" > /dev/null 12 | } || { 13 | echo "Linter requires 'black @ git+https://github.com/psf/black@673327449f86fce558adde153bb6cbe54bfebad2' !" 14 | exit 1 15 | } 16 | 17 | ISORT_TARGET_VERSION="4.3.21" 18 | ISORT_VERSION=$(isort -v | grep VERSION | awk '{print $2}') 19 | vergte "$ISORT_VERSION" "$ISORT_TARGET_VERSION" || { 20 | echo "Linter requires isort>=${ISORT_TARGET_VERSION} !" 21 | exit 1 22 | } 23 | 24 | set -v 25 | 26 | echo "Running isort ..." 27 | isort -y -sp . --atomic 28 | 29 | echo "Running black ..." 30 | black -l 100 . 31 | 32 | echo "Running flake8 ..." 33 | if [ -x "$(command -v flake8-3)" ]; then 34 | flake8-3 . 35 | else 36 | python3 -m flake8 . 37 | fi 38 | 39 | # echo "Running mypy ..." 40 | # Pytorch does not have enough type annotations 41 | # mypy detectron2/solver detectron2/structures detectron2/config 42 | 43 | echo "Running clang-format ..." 44 | find . -regex ".*\.\(cpp\|c\|cc\|cu\|cxx\|h\|hh\|hpp\|hxx\|tcc\|mm\|m\)" -print0 | xargs -0 clang-format -i 45 | 46 | command -v arc > /dev/null && arc lint 47 | -------------------------------------------------------------------------------- /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.4 10 | # ./dev/packaging/build_wheel.sh 11 | ``` 12 | 13 | ## To build all wheels for `CUDA {9.2,10.0,10.1}` x `Python {3.6,3.7,3.8}`: 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. All Rights Reserved 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 | 28 | for py in 3.6 3.7 3.8; do 29 | docker run -itd \ 30 | --name $container_name \ 31 | --mount type=bind,source="$(pwd)",target=/detectron2 \ 32 | pytorch/$container_name 33 | 34 | 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 | yum install ninja-build -y && ln -sv /usr/bin/ninja-build /usr/bin/ninja 19 | 20 | pip_install pip numpy -U 21 | pip_install "torch==$PYTORCH_VERSION" \ 22 | -f https://download.pytorch.org/whl/"$CU_VERSION"/torch_stable.html 23 | 24 | # use separate directories to allow parallel build 25 | BASE_BUILD_DIR=build/cu$CU_VERSION-py$PYTHON_VERSION-pt$PYTORCH_VERSION 26 | python setup.py \ 27 | build -b "$BASE_BUILD_DIR" \ 28 | bdist_wheel -b "$BASE_BUILD_DIR/build_dist" -d "wheels/$CU_VERSION/torch$PYTORCH_VERSION" 29 | rm -rf "$BASE_BUILD_DIR" 30 | -------------------------------------------------------------------------------- /dev/packaging/gen_wheel_index.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | 5 | root=$1 6 | if [[ -z "$root" ]]; then 7 | echo "Usage: ./gen_wheel_index.sh /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; do 18 | cd "$root/$cu" 19 | echo "Creating $PWD/index.html ..." 20 | # First sort by torch version, then stable sort by d2 version with unique. 21 | # As a result, the latest torch version for each d2 version is kept. 22 | for whl in $(find -type f -name '*.whl' -printf '%P\n' \ 23 | | sort -k 1 -r | sort -t '/' -k 2 --stable -r --unique); do 24 | echo "$whl
" 25 | done > index.html 26 | 27 | 28 | for torch in torch*; do 29 | cd "$root/$cu/$torch" 30 | 31 | # list all whl for each cuda,torch version 32 | echo "Creating $PWD/index.html ..." 33 | for whl in $(find . -type f -name '*.whl' -printf '%P\n' | sort -r); do 34 | echo "$whl
" 35 | done > index.html 36 | done 37 | done 38 | 39 | cd "$root" 40 | # Just list everything: 41 | echo "Creating $index ..." 42 | for whl in $(find . -type f -name '*.whl' -printf '%P\n' | sort -r); do 43 | echo "$whl
" 44 | done > "$index" 45 | 46 | -------------------------------------------------------------------------------- /dev/packaging/pkg_helpers.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | # Function to retry functions that sometimes timeout or have flaky failures 5 | retry () { 6 | $* || (sleep 1 && $*) || (sleep 2 && $*) || (sleep 4 && $*) || (sleep 8 && $*) 7 | } 8 | # Install with pip a bit more robustly than the default 9 | pip_install() { 10 | retry pip install --progress-bar off "$@" 11 | } 12 | 13 | 14 | setup_cuda() { 15 | # Now work out the CUDA settings 16 | # Like other torch domain libraries, we choose common GPU architectures only. 17 | export FORCE_CUDA=1 18 | case "$CU_VERSION" in 19 | cu102) 20 | export CUDA_HOME=/usr/local/cuda-10.2/ 21 | export TORCH_CUDA_ARCH_LIST="3.5;3.7;5.0;5.2;6.0+PTX;6.1+PTX;7.0+PTX;7.5+PTX" 22 | ;; 23 | cu101) 24 | export CUDA_HOME=/usr/local/cuda-10.1/ 25 | export TORCH_CUDA_ARCH_LIST="3.5;3.7;5.0;5.2;6.0+PTX;6.1+PTX;7.0+PTX;7.5+PTX" 26 | ;; 27 | cu100) 28 | export CUDA_HOME=/usr/local/cuda-10.0/ 29 | export TORCH_CUDA_ARCH_LIST="3.5;3.7;5.0;5.2;6.0+PTX;6.1+PTX;7.0+PTX;7.5+PTX" 30 | ;; 31 | cu92) 32 | export CUDA_HOME=/usr/local/cuda-9.2/ 33 | export TORCH_CUDA_ARCH_LIST="3.5;3.7;5.0;5.2;6.0+PTX;6.1+PTX;7.0+PTX" 34 | ;; 35 | cpu) 36 | unset FORCE_CUDA 37 | export CUDA_VISIBLE_DEVICES= 38 | ;; 39 | *) 40 | echo "Unrecognized CU_VERSION=$CU_VERSION" 41 | exit 1 42 | ;; 43 | esac 44 | } 45 | 46 | setup_wheel_python() { 47 | case "$PYTHON_VERSION" in 48 | 3.6) python_abi=cp36-cp36m ;; 49 | 3.7) python_abi=cp37-cp37m ;; 50 | 3.8) python_abi=cp38-cp38 ;; 51 | *) 52 | echo "Unrecognized PYTHON_VERSION=$PYTHON_VERSION" 53 | exit 1 54 | ;; 55 | esac 56 | export PATH="/opt/python/$python_abi/bin:$PATH" 57 | } 58 | -------------------------------------------------------------------------------- /dev/run_inference_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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. All Rights Reserved 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/Dockerfile-circleci: -------------------------------------------------------------------------------- 1 | FROM nvidia/cuda:10.1-cudnn7-devel 2 | # This dockerfile only aims to provide an environment for unittest on CircleCI 3 | 4 | ENV DEBIAN_FRONTEND noninteractive 5 | RUN apt-get update && apt-get install -y \ 6 | ca-certificates python3-dev git wget sudo ninja-build libglib2.0-0 && \ 7 | rm -rf /var/lib/apt/lists/* 8 | 9 | RUN wget -q https://bootstrap.pypa.io/get-pip.py && \ 10 | python3 get-pip.py && \ 11 | rm get-pip.py 12 | 13 | # install dependencies 14 | RUN pip install tensorboard opencv-python-headless 15 | ARG PYTORCH_VERSION 16 | ARG TORCHVISION_VERSION 17 | RUN pip install torch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION} -f https://download.pytorch.org/whl/cu101/torch_stable.html 18 | -------------------------------------------------------------------------------- /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 | # Run: 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 < 19.03) 18 | 19 | Install docker-compose and nvidia-docker2, then run: 20 | ``` 21 | cd docker && USER_ID=$UID docker-compose run detectron2 22 | ``` 23 | 24 | #### Using a persistent cache directory 25 | 26 | You can prevent models from being re-downloaded on every run, 27 | by storing them in a cache directory. 28 | 29 | To do this, add `--volume=$HOME/.torch/fvcore_cache:/tmp:rw` in the run command. 30 | 31 | ## Install new dependencies 32 | Add the following to `Dockerfile` to make persistent changes. 33 | ``` 34 | RUN sudo apt-get update && sudo apt-get install -y vim 35 | ``` 36 | Or run them in the container to make temporary changes. 37 | -------------------------------------------------------------------------------- /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 | runtime: nvidia # TODO: Exchange with "gpu: all" in the future (see https://github.com/facebookresearch/detectron2/pull/197/commits/00545e1f376918db4a8ce264d427a07c1e896c5a). 10 | shm_size: "8gb" 11 | ulimits: 12 | memlock: -1 13 | stack: 67108864 14 | volumes: 15 | - /tmp/.X11-unix:/tmp/.X11-unix:ro 16 | environment: 17 | - DISPLAY=$DISPLAY 18 | - NVIDIA_VISIBLE_DEVICES=all 19 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 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.0.0 12 | - recommonmark==0.6.0 13 | - sphinx_rtd_theme 14 | - mock 15 | 16 | 3. Run `make html` from this directory. 17 | -------------------------------------------------------------------------------- /docs/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | /* 2 | * some extra css to make markdown look similar between github/sphinx 3 | */ 4 | 5 | /* 6 | * Below is for install.md: 7 | */ 8 | .rst-content code { 9 | white-space: pre; 10 | border: 0px; 11 | } 12 | 13 | th { 14 | border: 1px solid #e1e4e5; 15 | } 16 | 17 | div.section > details { 18 | padding-bottom: 1em; 19 | } 20 | -------------------------------------------------------------------------------- /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 package 2 | ============================= 3 | 4 | .. automodule:: detectron2.checkpoint 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/config.rst: -------------------------------------------------------------------------------- 1 | detectron2.config package 2 | ========================= 3 | 4 | .. automodule:: detectron2.config 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :inherited-members: 9 | 10 | 11 | Config References 12 | ----------------- 13 | 14 | .. literalinclude:: ../../detectron2/config/defaults.py 15 | :language: python 16 | :linenos: 17 | :lines: 4- 18 | -------------------------------------------------------------------------------- /docs/modules/data.rst: -------------------------------------------------------------------------------- 1 | detectron2.data package 2 | ======================= 3 | 4 | .. automodule:: detectron2.data 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | detectron2.data.detection\_utils module 10 | --------------------------------------- 11 | 12 | .. automodule:: detectron2.data.detection_utils 13 | :members: 14 | :undoc-members: 15 | :show-inheritance: 16 | 17 | detectron2.data.datasets module 18 | --------------------------------------- 19 | 20 | .. automodule:: detectron2.data.datasets 21 | :members: 22 | :undoc-members: 23 | :show-inheritance: 24 | 25 | detectron2.data.samplers module 26 | --------------------------------------- 27 | 28 | .. automodule:: detectron2.data.samplers 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | 33 | 34 | detectron2.data.transforms module 35 | --------------------------------------- 36 | 37 | .. automodule:: detectron2.data.transforms 38 | :members: 39 | :undoc-members: 40 | :show-inheritance: 41 | -------------------------------------------------------------------------------- /docs/modules/engine.rst: -------------------------------------------------------------------------------- 1 | detectron2.engine package 2 | ========================= 3 | 4 | 5 | .. automodule:: detectron2.engine 6 | :members: 7 | :undoc-members: 8 | :show-inheritance: 9 | 10 | 11 | detectron2.engine.defaults module 12 | --------------------------------- 13 | 14 | .. automodule:: detectron2.engine.defaults 15 | :members: 16 | :undoc-members: 17 | :show-inheritance: 18 | 19 | detectron2.engine.hooks module 20 | --------------------------------- 21 | 22 | .. automodule:: detectron2.engine.hooks 23 | :members: 24 | :undoc-members: 25 | :show-inheritance: 26 | -------------------------------------------------------------------------------- /docs/modules/evaluation.rst: -------------------------------------------------------------------------------- 1 | detectron2.evaluation package 2 | ============================= 3 | 4 | .. automodule:: detectron2.evaluation 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/export.rst: -------------------------------------------------------------------------------- 1 | detectron2.export package 2 | ========================= 3 | 4 | .. automodule:: detectron2.export 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/index.rst: -------------------------------------------------------------------------------- 1 | API Documentation 2 | ================== 3 | 4 | .. toctree:: 5 | 6 | checkpoint 7 | config 8 | data 9 | engine 10 | evaluation 11 | layers 12 | model_zoo 13 | modeling 14 | solver 15 | structures 16 | utils 17 | export 18 | -------------------------------------------------------------------------------- /docs/modules/layers.rst: -------------------------------------------------------------------------------- 1 | detectron2.layers package 2 | ========================= 3 | 4 | .. automodule:: detectron2.layers 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/model_zoo.rst: -------------------------------------------------------------------------------- 1 | detectron2.model_zoo package 2 | ============================ 3 | 4 | .. automodule:: detectron2.model_zoo 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/modeling.rst: -------------------------------------------------------------------------------- 1 | detectron2.modeling package 2 | =========================== 3 | 4 | .. automodule:: detectron2.modeling 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | detectron2.modeling.poolers module 11 | --------------------------------------- 12 | 13 | .. automodule:: detectron2.modeling.poolers 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | 19 | detectron2.modeling.sampling module 20 | ------------------------------------ 21 | 22 | .. automodule:: detectron2.modeling.sampling 23 | :members: 24 | :undoc-members: 25 | :show-inheritance: 26 | 27 | 28 | detectron2.modeling.box_regression module 29 | ------------------------------------------ 30 | 31 | .. automodule:: detectron2.modeling.box_regression 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | 37 | Model Registries 38 | ----------------- 39 | 40 | These are different registries provided in modeling. 41 | Each registry provide you the ability to replace it with your customized component, 42 | without having to modify detectron2's code. 43 | 44 | Note that it is impossible to allow users to customize any line of code directly. 45 | Even just to add one line at some place, 46 | you'll likely need to find out the smallest registry which contains that line, 47 | and register your component to that registry. 48 | 49 | 50 | .. autodata:: detectron2.modeling.META_ARCH_REGISTRY 51 | .. autodata:: detectron2.modeling.BACKBONE_REGISTRY 52 | .. autodata:: detectron2.modeling.PROPOSAL_GENERATOR_REGISTRY 53 | .. autodata:: detectron2.modeling.RPN_HEAD_REGISTRY 54 | .. autodata:: detectron2.modeling.ANCHOR_GENERATOR_REGISTRY 55 | .. autodata:: detectron2.modeling.ROI_HEADS_REGISTRY 56 | .. autodata:: detectron2.modeling.ROI_BOX_HEAD_REGISTRY 57 | .. autodata:: detectron2.modeling.ROI_MASK_HEAD_REGISTRY 58 | .. autodata:: detectron2.modeling.ROI_KEYPOINT_HEAD_REGISTRY 59 | -------------------------------------------------------------------------------- /docs/modules/solver.rst: -------------------------------------------------------------------------------- 1 | detectron2.solver package 2 | ========================= 3 | 4 | .. automodule:: detectron2.solver 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/structures.rst: -------------------------------------------------------------------------------- 1 | detectron2.structures package 2 | ============================= 3 | 4 | .. automodule:: detectron2.structures 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules/utils.rst: -------------------------------------------------------------------------------- 1 | detectron2.utils package 2 | ======================== 3 | 4 | detectron2.utils.colormap module 5 | -------------------------------- 6 | 7 | .. automodule:: detectron2.utils.colormap 8 | :members: 9 | :undoc-members: 10 | :show-inheritance: 11 | 12 | detectron2.utils.comm module 13 | ---------------------------- 14 | 15 | .. automodule:: detectron2.utils.comm 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | 21 | detectron2.utils.events module 22 | ------------------------------ 23 | 24 | .. automodule:: detectron2.utils.events 25 | :members: 26 | :undoc-members: 27 | :show-inheritance: 28 | 29 | 30 | detectron2.utils.logger module 31 | ------------------------------ 32 | 33 | .. automodule:: detectron2.utils.logger 34 | :members: 35 | :undoc-members: 36 | :show-inheritance: 37 | 38 | 39 | detectron2.utils.registry module 40 | -------------------------------- 41 | 42 | .. automodule:: detectron2.utils.registry 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | detectron2.utils.memory module 48 | ---------------------------------- 49 | 50 | .. automodule:: detectron2.utils.memory 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | 56 | detectron2.utils.analysis module 57 | ---------------------------------- 58 | 59 | .. automodule:: detectron2.utils.analysis 60 | :members: 61 | :undoc-members: 62 | :show-inheritance: 63 | 64 | 65 | detectron2.utils.visualizer module 66 | ---------------------------------- 67 | 68 | .. automodule:: detectron2.utils.visualizer 69 | :members: 70 | :undoc-members: 71 | :show-inheritance: 72 | 73 | detectron2.utils.video\_visualizer module 74 | ----------------------------------------- 75 | 76 | .. automodule:: detectron2.utils.video_visualizer 77 | :members: 78 | :undoc-members: 79 | :show-inheritance: 80 | 81 | -------------------------------------------------------------------------------- /docs/notes/changelog.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ### Releases 4 | See release log at 5 | [https://github.com/facebookresearch/detectron2/releases](https://github.com/facebookresearch/detectron2/releases). 6 | 7 | ### Notable Backward Incompatible Changes: 8 | 9 | * 03/30/2020: Custom box head's `output_size` changed to `output_shape`. 10 | * 02/14/2020,02/18/2020: Mask head and keypoint head now include logic for losses & inference. Custom heads 11 | should overwrite the feature computation by `layers()` method. 12 | * 11/11/2019: `detectron2.data.detection_utils.read_image` transposes images with exif information. 13 | 14 | ### Config Version Change Log 15 | 16 | * v1: Rename `RPN_HEAD.NAME` to `RPN.HEAD_NAME`. 17 | * v2: A batch of rename of many configurations before release. 18 | 19 | ### Silent Regression in Historical Versions: 20 | 21 | We list a few silent regressions since they may silently produce incorrect results and will be hard to debug. 22 | 23 | * 04/01/2020 - 05/11/2020: Bad accuracy if `TRAIN_ON_PRED_BOXES` is set to True. 24 | * 03/30/2020 - 04/01/2020: ResNets are not correctly built. 25 | * 12/19/2019 - 12/26/2019: Using aspect ratio grouping causes a drop in accuracy. 26 | * release - 11/9/2019: Test time augmentation does not predict the last category. 27 | -------------------------------------------------------------------------------- /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 | termcolor 2 | numpy 3 | tqdm 4 | docutils==0.16 5 | Sphinx==3.0.0 6 | recommonmark==0.6.0 7 | sphinx_rtd_theme 8 | mock 9 | matplotlib 10 | termcolor 11 | yacs 12 | tabulate 13 | cloudpickle 14 | Pillow==6.2.2 15 | future 16 | requests 17 | six 18 | git+git://github.com/facebookresearch/fvcore.git 19 | https://download.pytorch.org/whl/cpu/torch-1.5.0%2Bcpu-cp37-cp37m-linux_x86_64.whl 20 | https://download.pytorch.org/whl/cpu/torchvision-0.6.0%2Bcpu-cp37-cp37m-linux_x86_64.whl 21 | -------------------------------------------------------------------------------- /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 | models 14 | write-models 15 | training 16 | evaluation 17 | configs 18 | deployment 19 | -------------------------------------------------------------------------------- /docs/tutorials/install.md: -------------------------------------------------------------------------------- 1 | ../../INSTALL.md -------------------------------------------------------------------------------- /projects/DensePose/configs/Base-DensePose-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 | 22 | DENSEPOSE_ON: True 23 | ROI_HEADS: 24 | NAME: "DensePoseROIHeads" 25 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 26 | NUM_CLASSES: 1 27 | ROI_BOX_HEAD: 28 | NAME: "FastRCNNConvFCHead" 29 | NUM_FC: 2 30 | POOLER_RESOLUTION: 7 31 | POOLER_SAMPLING_RATIO: 2 32 | POOLER_TYPE: "ROIAlign" 33 | ROI_DENSEPOSE_HEAD: 34 | NAME: "DensePoseV1ConvXHead" 35 | POOLER_TYPE: "ROIAlign" 36 | NUM_COARSE_SEGM_CHANNELS: 2 37 | DATASETS: 38 | TRAIN: ("densepose_coco_2014_train", "densepose_coco_2014_valminusminival") 39 | TEST: ("densepose_coco_2014_minival",) 40 | SOLVER: 41 | IMS_PER_BATCH: 16 42 | BASE_LR: 0.01 43 | STEPS: (60000, 80000) 44 | MAX_ITER: 90000 45 | WARMUP_FACTOR: 0.1 46 | INPUT: 47 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 48 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_101_FPN_DL_WC1_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | ROI_DENSEPOSE_HEAD: 7 | NAME: "DensePoseDeepLabHead" 8 | UV_CONFIDENCE: 9 | ENABLED: True 10 | TYPE: "iid_iso" 11 | POINT_REGRESSION_WEIGHTS: 0.0005 12 | SOLVER: 13 | CLIP_GRADIENTS: 14 | ENABLED: True 15 | MAX_ITER: 130000 16 | STEPS: (100000, 120000) 17 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_101_FPN_DL_WC2_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | ROI_DENSEPOSE_HEAD: 7 | NAME: "DensePoseDeepLabHead" 8 | UV_CONFIDENCE: 9 | ENABLED: True 10 | TYPE: "indep_aniso" 11 | POINT_REGRESSION_WEIGHTS: 0.0005 12 | SOLVER: 13 | CLIP_GRADIENTS: 14 | ENABLED: True 15 | MAX_ITER: 130000 16 | STEPS: (100000, 120000) 17 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_101_FPN_DL_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | ROI_DENSEPOSE_HEAD: 7 | NAME: "DensePoseDeepLabHead" 8 | SOLVER: 9 | MAX_ITER: 130000 10 | STEPS: (100000, 120000) 11 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_101_FPN_WC1_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | ROI_DENSEPOSE_HEAD: 7 | UV_CONFIDENCE: 8 | ENABLED: True 9 | TYPE: "iid_iso" 10 | POINT_REGRESSION_WEIGHTS: 0.0005 11 | SOLVER: 12 | CLIP_GRADIENTS: 13 | ENABLED: True 14 | MAX_ITER: 130000 15 | STEPS: (100000, 120000) 16 | WARMUP_FACTOR: 0.025 17 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_101_FPN_WC2_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | ROI_DENSEPOSE_HEAD: 7 | UV_CONFIDENCE: 8 | ENABLED: True 9 | TYPE: "indep_aniso" 10 | POINT_REGRESSION_WEIGHTS: 0.0005 11 | SOLVER: 12 | CLIP_GRADIENTS: 13 | ENABLED: True 14 | MAX_ITER: 130000 15 | STEPS: (100000, 120000) 16 | WARMUP_FACTOR: 0.025 17 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_101_FPN_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | SOLVER: 7 | MAX_ITER: 130000 8 | STEPS: (100000, 120000) 9 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_101_FPN_s1x_legacy.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | ROI_DENSEPOSE_HEAD: 7 | NUM_COARSE_SEGM_CHANNELS: 15 8 | POOLER_RESOLUTION: 14 9 | HEATMAP_SIZE: 56 10 | INDEX_WEIGHTS: 2.0 11 | PART_WEIGHTS: 0.3 12 | POINT_REGRESSION_WEIGHTS: 0.1 13 | DECODER_ON: False 14 | SOLVER: 15 | BASE_LR: 0.002 16 | MAX_ITER: 130000 17 | STEPS: (100000, 120000) 18 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_50_FPN_DL_WC1_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | ROI_DENSEPOSE_HEAD: 7 | NAME: "DensePoseDeepLabHead" 8 | UV_CONFIDENCE: 9 | ENABLED: True 10 | TYPE: "iid_iso" 11 | POINT_REGRESSION_WEIGHTS: 0.0005 12 | SOLVER: 13 | CLIP_GRADIENTS: 14 | ENABLED: True 15 | MAX_ITER: 130000 16 | STEPS: (100000, 120000) 17 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_50_FPN_DL_WC2_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | ROI_DENSEPOSE_HEAD: 7 | NAME: "DensePoseDeepLabHead" 8 | UV_CONFIDENCE: 9 | ENABLED: True 10 | TYPE: "indep_aniso" 11 | POINT_REGRESSION_WEIGHTS: 0.0005 12 | SOLVER: 13 | CLIP_GRADIENTS: 14 | ENABLED: True 15 | MAX_ITER: 130000 16 | STEPS: (100000, 120000) 17 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_50_FPN_DL_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | ROI_DENSEPOSE_HEAD: 7 | NAME: "DensePoseDeepLabHead" 8 | SOLVER: 9 | MAX_ITER: 130000 10 | STEPS: (100000, 120000) 11 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_50_FPN_WC1_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | ROI_DENSEPOSE_HEAD: 7 | UV_CONFIDENCE: 8 | ENABLED: True 9 | TYPE: "iid_iso" 10 | POINT_REGRESSION_WEIGHTS: 0.0005 11 | SOLVER: 12 | CLIP_GRADIENTS: 13 | ENABLED: True 14 | MAX_ITER: 130000 15 | STEPS: (100000, 120000) 16 | WARMUP_FACTOR: 0.025 17 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_50_FPN_WC2_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | ROI_DENSEPOSE_HEAD: 7 | UV_CONFIDENCE: 8 | ENABLED: True 9 | TYPE: "indep_aniso" 10 | POINT_REGRESSION_WEIGHTS: 0.0005 11 | SOLVER: 12 | CLIP_GRADIENTS: 13 | ENABLED: True 14 | MAX_ITER: 130000 15 | STEPS: (100000, 120000) 16 | WARMUP_FACTOR: 0.025 17 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_50_FPN_s1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | SOLVER: 7 | MAX_ITER: 130000 8 | STEPS: (100000, 120000) 9 | -------------------------------------------------------------------------------- /projects/DensePose/configs/densepose_rcnn_R_50_FPN_s1x_legacy.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | ROI_DENSEPOSE_HEAD: 7 | NUM_COARSE_SEGM_CHANNELS: 15 8 | POOLER_RESOLUTION: 14 9 | HEATMAP_SIZE: 56 10 | INDEX_WEIGHTS: 2.0 11 | PART_WEIGHTS: 0.3 12 | POINT_REGRESSION_WEIGHTS: 0.1 13 | DECODER_ON: False 14 | SOLVER: 15 | BASE_LR: 0.002 16 | MAX_ITER: 130000 17 | STEPS: (100000, 120000) 18 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_101_FPN_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseV1ConvXHead" 13 | POOLER_TYPE: "ROIAlign" 14 | NUM_COARSE_SEGM_CHANNELS: 2 15 | COARSE_SEGM_TRAINED_BY_MASKS: True 16 | INDEX_WEIGHTS: 1.0 17 | DATASETS: 18 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 19 | TEST: ("densepose_chimps",) 20 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_101_FPN_DL_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseDeepLabHead" 13 | POOLER_TYPE: "ROIAlign" 14 | NUM_COARSE_SEGM_CHANNELS: 2 15 | COARSE_SEGM_TRAINED_BY_MASKS: True 16 | INDEX_WEIGHTS: 1.0 17 | DATASETS: 18 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 19 | TEST: ("densepose_chimps",) 20 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_101_FPN_DL_WC1M_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseDeepLabHead" 13 | UV_CONFIDENCE: 14 | ENABLED: True 15 | TYPE: "iid_iso" 16 | SEGM_CONFIDENCE: 17 | ENABLED: True 18 | POINT_REGRESSION_WEIGHTS: 0.0005 19 | POOLER_TYPE: "ROIAlign" 20 | NUM_COARSE_SEGM_CHANNELS: 2 21 | COARSE_SEGM_TRAINED_BY_MASKS: True 22 | INDEX_WEIGHTS: 1.0 23 | SOLVER: 24 | CLIP_GRADIENTS: 25 | ENABLED: True 26 | WARMUP_FACTOR: 0.025 27 | DATASETS: 28 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 29 | TEST: ("densepose_chimps",) 30 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_101_FPN_DL_WC1_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseDeepLabHead" 13 | UV_CONFIDENCE: 14 | ENABLED: True 15 | TYPE: "iid_iso" 16 | POINT_REGRESSION_WEIGHTS: 0.0005 17 | POOLER_TYPE: "ROIAlign" 18 | NUM_COARSE_SEGM_CHANNELS: 2 19 | COARSE_SEGM_TRAINED_BY_MASKS: True 20 | INDEX_WEIGHTS: 1.0 21 | SOLVER: 22 | CLIP_GRADIENTS: 23 | ENABLED: True 24 | WARMUP_FACTOR: 0.025 25 | DATASETS: 26 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 27 | TEST: ("densepose_chimps",) 28 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_101_FPN_WC1M_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseV1ConvXHead" 13 | UV_CONFIDENCE: 14 | ENABLED: True 15 | TYPE: "iid_iso" 16 | SEGM_CONFIDENCE: 17 | ENABLED: True 18 | POINT_REGRESSION_WEIGHTS: 0.0005 19 | POOLER_TYPE: "ROIAlign" 20 | NUM_COARSE_SEGM_CHANNELS: 2 21 | COARSE_SEGM_TRAINED_BY_MASKS: True 22 | INDEX_WEIGHTS: 1.0 23 | SOLVER: 24 | CLIP_GRADIENTS: 25 | ENABLED: True 26 | WARMUP_FACTOR: 0.025 27 | DATASETS: 28 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 29 | TEST: ("densepose_chimps",) 30 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_101_FPN_WC1_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 4 | RESNETS: 5 | DEPTH: 101 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseV1ConvXHead" 13 | UV_CONFIDENCE: 14 | ENABLED: True 15 | TYPE: "iid_iso" 16 | POINT_REGRESSION_WEIGHTS: 0.0005 17 | POOLER_TYPE: "ROIAlign" 18 | NUM_COARSE_SEGM_CHANNELS: 2 19 | COARSE_SEGM_TRAINED_BY_MASKS: True 20 | INDEX_WEIGHTS: 1.0 21 | SOLVER: 22 | CLIP_GRADIENTS: 23 | ENABLED: True 24 | WARMUP_FACTOR: 0.025 25 | DATASETS: 26 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 27 | TEST: ("densepose_chimps",) 28 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_50_FPN_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseV1ConvXHead" 13 | POOLER_TYPE: "ROIAlign" 14 | NUM_COARSE_SEGM_CHANNELS: 2 15 | COARSE_SEGM_TRAINED_BY_MASKS: True 16 | INDEX_WEIGHTS: 1.0 17 | DATASETS: 18 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 19 | TEST: ("densepose_chimps",) 20 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_50_FPN_DL_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseDeepLabHead" 13 | POOLER_TYPE: "ROIAlign" 14 | NUM_COARSE_SEGM_CHANNELS: 2 15 | COARSE_SEGM_TRAINED_BY_MASKS: True 16 | INDEX_WEIGHTS: 1.0 17 | DATASETS: 18 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 19 | TEST: ("densepose_chimps",) 20 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_50_FPN_DL_WC1M_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseDeepLabHead" 13 | UV_CONFIDENCE: 14 | ENABLED: True 15 | TYPE: "iid_iso" 16 | SEGM_CONFIDENCE: 17 | ENABLED: True 18 | POINT_REGRESSION_WEIGHTS: 0.0005 19 | POOLER_TYPE: "ROIAlign" 20 | NUM_COARSE_SEGM_CHANNELS: 2 21 | COARSE_SEGM_TRAINED_BY_MASKS: True 22 | INDEX_WEIGHTS: 1.0 23 | SOLVER: 24 | CLIP_GRADIENTS: 25 | ENABLED: True 26 | WARMUP_FACTOR: 0.025 27 | DATASETS: 28 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 29 | TEST: ("densepose_chimps",) 30 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_50_FPN_DL_WC1_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseDeepLabHead" 13 | UV_CONFIDENCE: 14 | ENABLED: True 15 | TYPE: "iid_iso" 16 | POINT_REGRESSION_WEIGHTS: 0.0005 17 | POOLER_TYPE: "ROIAlign" 18 | NUM_COARSE_SEGM_CHANNELS: 2 19 | COARSE_SEGM_TRAINED_BY_MASKS: True 20 | INDEX_WEIGHTS: 1.0 21 | SOLVER: 22 | CLIP_GRADIENTS: 23 | ENABLED: True 24 | WARMUP_FACTOR: 0.025 25 | DATASETS: 26 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 27 | TEST: ("densepose_chimps",) 28 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_50_FPN_WC1M_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseV1ConvXHead" 13 | UV_CONFIDENCE: 14 | ENABLED: True 15 | TYPE: "iid_iso" 16 | SEGM_CONFIDENCE: 17 | ENABLED: True 18 | POINT_REGRESSION_WEIGHTS: 0.0005 19 | POOLER_TYPE: "ROIAlign" 20 | NUM_COARSE_SEGM_CHANNELS: 2 21 | COARSE_SEGM_TRAINED_BY_MASKS: True 22 | INDEX_WEIGHTS: 1.0 23 | SOLVER: 24 | CLIP_GRADIENTS: 25 | ENABLED: True 26 | WARMUP_FACTOR: 0.025 27 | DATASETS: 28 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 29 | TEST: ("densepose_chimps",) 30 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/densepose_R_50_FPN_WC1_1x_Atop10_toP.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | DENSEPOSE_ON: True 7 | ROI_HEADS: 8 | NAME: "DensePoseROIHeads" 9 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 10 | NUM_CLASSES: 1 11 | ROI_DENSEPOSE_HEAD: 12 | NAME: "DensePoseV1ConvXHead" 13 | UV_CONFIDENCE: 14 | ENABLED: True 15 | TYPE: "iid_iso" 16 | POINT_REGRESSION_WEIGHTS: 0.0005 17 | POOLER_TYPE: "ROIAlign" 18 | NUM_COARSE_SEGM_CHANNELS: 2 19 | COARSE_SEGM_TRAINED_BY_MASKS: True 20 | INDEX_WEIGHTS: 1.0 21 | SOLVER: 22 | CLIP_GRADIENTS: 23 | ENABLED: True 24 | WARMUP_FACTOR: 0.025 25 | DATASETS: 26 | TRAIN: ("base_coco_2017_train", "densepose_coco_2014_train") 27 | TEST: ("densepose_chimps",) 28 | -------------------------------------------------------------------------------- /projects/DensePose/configs/evolution/faster_rcnn_R_50_FPN_1x_MC.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-RCNN-FPN-MC.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | DENSEPOSE_ON: False 6 | RESNETS: 7 | DEPTH: 50 8 | -------------------------------------------------------------------------------- /projects/DensePose/configs/quick_schedules/densepose_rcnn_R_50_FPN_DL_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | ROI_DENSEPOSE_HEAD: 5 | NAME: "DensePoseDeepLabHead" 6 | DATASETS: 7 | TRAIN: ("densepose_coco_2014_minival_100",) 8 | TEST: ("densepose_coco_2014_minival_100",) 9 | SOLVER: 10 | MAX_ITER: 40 11 | STEPS: (30,) 12 | -------------------------------------------------------------------------------- /projects/DensePose/configs/quick_schedules/densepose_rcnn_R_50_FPN_TTA_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../densepose_rcnn_R_50_FPN_s1x.yaml" 2 | MODEL: 3 | WEIGHTS: "https://dl.fbaipublicfiles.com/densepose/densepose_rcnn_R_50_FPN_s1x/165712039/model_final_162be9.pkl" 4 | DATASETS: 5 | TRAIN: () 6 | TEST: ("densepose_coco_2014_minival_100",) 7 | TEST: 8 | AUG: 9 | ENABLED: True 10 | MIN_SIZES: (400, 500, 600, 700, 800, 900, 1000, 1100, 1200) 11 | MAX_SIZE: 4000 12 | FLIP: True 13 | EXPECTED_RESULTS: [["bbox_TTA", "AP", 61.74, 0.03], ["densepose_gps_TTA", "AP", 60.22, 0.03], ["densepose_gpsm_TTA", "AP", 63.85, 0.03]] 14 | -------------------------------------------------------------------------------- /projects/DensePose/configs/quick_schedules/densepose_rcnn_R_50_FPN_WC1_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | ROI_DENSEPOSE_HEAD: 7 | UV_CONFIDENCE: 8 | ENABLED: True 9 | TYPE: "iid_iso" 10 | POINT_REGRESSION_WEIGHTS: 0.0005 11 | DATASETS: 12 | TRAIN: ("densepose_coco_2014_minival_100",) 13 | TEST: ("densepose_coco_2014_minival_100",) 14 | SOLVER: 15 | CLIP_GRADIENTS: 16 | ENABLED: True 17 | MAX_ITER: 40 18 | STEPS: (30,) 19 | WARMUP_FACTOR: 0.025 20 | -------------------------------------------------------------------------------- /projects/DensePose/configs/quick_schedules/densepose_rcnn_R_50_FPN_WC2_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | ROI_DENSEPOSE_HEAD: 7 | UV_CONFIDENCE: 8 | ENABLED: True 9 | TYPE: "indep_aniso" 10 | POINT_REGRESSION_WEIGHTS: 0.0005 11 | DATASETS: 12 | TRAIN: ("densepose_coco_2014_minival_100",) 13 | TEST: ("densepose_coco_2014_minival_100",) 14 | SOLVER: 15 | CLIP_GRADIENTS: 16 | ENABLED: True 17 | MAX_ITER: 40 18 | STEPS: (30,) 19 | WARMUP_FACTOR: 0.025 20 | -------------------------------------------------------------------------------- /projects/DensePose/configs/quick_schedules/densepose_rcnn_R_50_FPN_inference_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../densepose_rcnn_R_50_FPN_s1x.yaml" 2 | MODEL: 3 | WEIGHTS: "https://dl.fbaipublicfiles.com/densepose/densepose_rcnn_R_50_FPN_s1x/165712039/model_final_162be9.pkl" 4 | DATASETS: 5 | TRAIN: () 6 | TEST: ("densepose_coco_2014_minival_100",) 7 | TEST: 8 | EXPECTED_RESULTS: [["bbox", "AP", 59.27, 0.025], ["densepose_gps", "AP", 60.11, 0.02], ["densepose_gpsm", "AP", 64.20, 0.02]] 9 | -------------------------------------------------------------------------------- /projects/DensePose/configs/quick_schedules/densepose_rcnn_R_50_FPN_instant_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | DATASETS: 5 | TRAIN: ("densepose_coco_2014_minival_100",) 6 | TEST: ("densepose_coco_2014_minival_100",) 7 | SOLVER: 8 | MAX_ITER: 40 9 | STEPS: (30,) 10 | -------------------------------------------------------------------------------- /projects/DensePose/configs/quick_schedules/densepose_rcnn_R_50_FPN_training_acc_test.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-DensePose-RCNN-FPN.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | ROI_HEADS: 5 | NUM_CLASSES: 1 6 | DATASETS: 7 | TRAIN: ("densepose_coco_2014_minival",) 8 | TEST: ("densepose_coco_2014_minival",) 9 | SOLVER: 10 | CLIP_GRADIENTS: 11 | ENABLED: True 12 | CLIP_TYPE: norm 13 | CLIP_VALUE: 1.0 14 | MAX_ITER: 6000 15 | STEPS: (5500, 5800) 16 | TEST: 17 | EXPECTED_RESULTS: [["bbox", "AP", 76.2477, 1.0], ["densepose_gps", "AP", 79.6090, 1.5], ["densepose_gpsm", "AP", 80.0061, 1.5]] 18 | 19 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .data.datasets import builtin # just to register data 3 | from .config import add_densepose_config, add_dataset_category_config 4 | from .densepose_head import ROI_DENSEPOSE_HEAD_REGISTRY 5 | from .evaluator import DensePoseCOCOEvaluator 6 | from .roi_head import DensePoseROIHeads 7 | from .data.structures import DensePoseDataRelative, DensePoseList, DensePoseTransformData 8 | from .modeling.test_time_augmentation import ( 9 | DensePoseGeneralizedRCNNWithTTA, 10 | DensePoseDatasetMapperTTA, 11 | ) 12 | from .utils.transform import load_from_cfg 13 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | from .build import ( 4 | build_detection_test_loader, 5 | build_detection_train_loader, 6 | build_combined_loader, 7 | build_frame_selector, 8 | ) 9 | from .combined_loader import CombinedDataLoader 10 | from .dataset_mapper import DatasetMapper 11 | from .inference_based_loader import InferenceBasedLoader 12 | from .utils import is_relative_local_path, maybe_prepend_base_path 13 | 14 | # ensure the builtin datasets are registered 15 | from . import datasets 16 | 17 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 18 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/combined_loader.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | import random 4 | from collections import deque 5 | from typing import Any, Collection, Deque, Iterable, Iterator, List, Sequence 6 | 7 | Loader = Iterable[Any] 8 | 9 | 10 | def _pooled_next(iterator: Iterator[Any], pool: Deque[Any]): 11 | if not pool: 12 | pool.extend(next(iterator)) 13 | return pool.popleft() 14 | 15 | 16 | class CombinedDataLoader: 17 | """ 18 | Combines data loaders using the provided sampling ratios 19 | """ 20 | 21 | BATCH_COUNT = 100 22 | 23 | def __init__(self, loaders: Collection[Loader], batch_size: int, ratios: Sequence[float]): 24 | self.loaders = loaders 25 | self.batch_size = batch_size 26 | self.ratios = ratios 27 | 28 | def __iter__(self) -> Iterator[List[Any]]: 29 | iters = [iter(loader) for loader in self.loaders] 30 | indices = [] 31 | pool = [deque()] * len(iters) 32 | # infinite iterator, as in D2 33 | while True: 34 | if not indices: 35 | # just a buffer of indices, its size doesn't matter 36 | # as long as it's a multiple of batch_size 37 | k = self.batch_size * self.BATCH_COUNT 38 | indices = random.choices(range(len(self.loaders)), self.ratios, k=k) 39 | try: 40 | batch = [_pooled_next(iters[i], pool[i]) for i in indices[: self.batch_size]] 41 | except StopIteration: 42 | break 43 | indices = indices[self.batch_size :] 44 | yield batch 45 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | from . import builtin # ensure the builtin datasets are registered 4 | 5 | __all__ = [k for k in globals().keys() if "builtin" not in k and not k.startswith("_")] 6 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/datasets/builtin.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .chimpnsee import register_dataset as register_chimpnsee_dataset 3 | from .coco import BASE_DATASETS as BASE_COCO_DATASETS 4 | from .coco import DATASETS as COCO_DATASETS 5 | from .coco import register_datasets as register_coco_datasets 6 | 7 | DEFAULT_DATASETS_ROOT = "datasets" 8 | 9 | 10 | register_coco_datasets(COCO_DATASETS, DEFAULT_DATASETS_ROOT) 11 | register_coco_datasets(BASE_COCO_DATASETS, DEFAULT_DATASETS_ROOT) 12 | 13 | register_chimpnsee_dataset(DEFAULT_DATASETS_ROOT) 14 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/datasets/chimpnsee.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | import os 4 | from typing import Optional 5 | 6 | from detectron2.data import DatasetCatalog, MetadataCatalog 7 | 8 | from ..utils import maybe_prepend_base_path 9 | from .dataset_type import DatasetType 10 | 11 | CHIMPNSEE_DATASET_NAME = "chimpnsee" 12 | 13 | 14 | def register_dataset(datasets_root: Optional[os.PathLike] = None): 15 | def empty_load_callback(): 16 | pass 17 | 18 | video_list_fpath = maybe_prepend_base_path( 19 | datasets_root, "chimpnsee/cdna.eva.mpg.de/video_list.txt" 20 | ) 21 | video_base_path = maybe_prepend_base_path(datasets_root, "chimpnsee/cdna.eva.mpg.de") 22 | 23 | DatasetCatalog.register(CHIMPNSEE_DATASET_NAME, empty_load_callback) 24 | MetadataCatalog.get(CHIMPNSEE_DATASET_NAME).set( 25 | dataset_type=DatasetType.VIDEO_LIST, 26 | video_list_fpath=video_list_fpath, 27 | video_base_path=video_base_path, 28 | ) 29 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/datasets/dataset_type.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | from enum import Enum 4 | 5 | 6 | class DatasetType(Enum): 7 | """ 8 | Dataset type, mostly used for datasets that contain data to bootstrap models on 9 | """ 10 | 11 | VIDEO_LIST = "video_list" 12 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/transform/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | from .image import ImageResizeTransform 4 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/transform/image.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | import torch 4 | 5 | 6 | class ImageResizeTransform: 7 | """ 8 | Transform that converts frames loaded from a dataset 9 | (RGB data in NHWC channel order, typically uint8) to a format ready to be 10 | consumed by DensePose training (BGR float32 data in NCHW channel order) 11 | """ 12 | 13 | def __init__(self, min_size: int = 800, max_size: int = 1333): 14 | self.min_size = min_size 15 | self.max_size = max_size 16 | 17 | def __call__(self, frames: torch.Tensor) -> torch.Tensor: 18 | """ 19 | Args: 20 | frames (torch.Tensor): tensor of size [N, H, W, 3] that contains 21 | RGB data (typically in uint8) 22 | Returns: 23 | frames (torch.Tensor): tensor of size [N, 3, H1, W1] where 24 | H1 and W1 are chosen to respect the specified min and max sizes 25 | and preserve the original aspect ratio, the data channels 26 | follow BGR order and the data type is `torch.float32` 27 | """ 28 | frames = frames[..., [2, 1, 0]] # RGB -> BGR 29 | frames = frames.permute(0, 3, 1, 2).float() # NHWC -> NCHW 30 | # resize with min size 31 | min_size = min(frames.shape[-2:]) 32 | max_size = max(frames.shape[-2:]) 33 | scale = min(self.min_size / min_size, self.max_size / max_size) 34 | frames = torch.nn.functional.interpolate( 35 | frames, scale_factor=scale, mode="bilinear", align_corners=False 36 | ) 37 | return frames 38 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | import os 4 | from typing import Optional 5 | 6 | 7 | def is_relative_local_path(path: os.PathLike): 8 | path_str = os.fsdecode(path) 9 | return ("://" not in path_str) and not os.path.isabs(path) 10 | 11 | 12 | def maybe_prepend_base_path(base_path: Optional[os.PathLike], path: os.PathLike): 13 | """ 14 | Prepends the provided path with a base path prefix if: 15 | 1) base path is not None; 16 | 2) path is a local path 17 | """ 18 | if base_path is None: 19 | return path 20 | if is_relative_local_path(path): 21 | return os.path.join(base_path, path) 22 | return path 23 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/data/video/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | from .frame_selector import ( 4 | FrameSelectionStrategy, 5 | RandomKFramesSelector, 6 | FirstKFramesSelector, 7 | LastKFramesSelector, 8 | FrameTsList, 9 | FrameSelector, 10 | ) 11 | 12 | from .video_keyframe_dataset import ( 13 | VideoKeyframeDataset, 14 | video_list_from_file, 15 | list_keyframes, 16 | read_keyframes, 17 | ) 18 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/engine/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | from .trainer import Trainer 4 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/utils/logger.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | import logging 3 | 4 | 5 | def verbosity_to_level(verbosity): 6 | if verbosity is not None: 7 | if verbosity == 0: 8 | return logging.WARNING 9 | elif verbosity == 1: 10 | return logging.INFO 11 | elif verbosity >= 2: 12 | return logging.DEBUG 13 | return logging.WARNING 14 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/utils/transform.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from fvcore.common.file_io import PathManager 3 | 4 | from detectron2.data import MetadataCatalog 5 | 6 | from densepose import DensePoseTransformData 7 | 8 | 9 | def load_for_dataset(dataset_name): 10 | path = MetadataCatalog.get(dataset_name).densepose_transform_src 11 | densepose_transform_data_fpath = PathManager.get_local_path(path) 12 | return DensePoseTransformData.load(densepose_transform_data_fpath) 13 | 14 | 15 | def load_from_cfg(cfg): 16 | return load_for_dataset(cfg.DATASETS.TEST[0]) 17 | -------------------------------------------------------------------------------- /projects/DensePose/densepose/vis/bounding_box.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .base import RectangleVisualizer, TextVisualizer 3 | 4 | 5 | class BoundingBoxVisualizer(object): 6 | def __init__(self): 7 | self.rectangle_visualizer = RectangleVisualizer() 8 | 9 | def visualize(self, image_bgr, boxes_xywh): 10 | for bbox_xywh in boxes_xywh: 11 | image_bgr = self.rectangle_visualizer.visualize(image_bgr, bbox_xywh) 12 | return image_bgr 13 | 14 | 15 | class ScoredBoundingBoxVisualizer(object): 16 | def __init__(self, bbox_visualizer_params=None, score_visualizer_params=None): 17 | if bbox_visualizer_params is None: 18 | bbox_visualizer_params = {} 19 | if score_visualizer_params is None: 20 | score_visualizer_params = {} 21 | self.visualizer_bbox = RectangleVisualizer(**bbox_visualizer_params) 22 | self.visualizer_score = TextVisualizer(**score_visualizer_params) 23 | 24 | def visualize(self, image_bgr, scored_bboxes): 25 | boxes_xywh, box_scores = scored_bboxes 26 | assert len(boxes_xywh) == len( 27 | box_scores 28 | ), "Number of bounding boxes {} should be equal to the number of scores {}".format( 29 | len(boxes_xywh), len(box_scores) 30 | ) 31 | for i, box_xywh in enumerate(boxes_xywh): 32 | score_i = box_scores[i] 33 | image_bgr = self.visualizer_bbox.visualize(image_bgr, box_xywh) 34 | score_txt = "{0:6.4f}".format(score_i) 35 | topleft_xy = box_xywh[0], box_xywh[1] 36 | image_bgr = self.visualizer_score.visualize(image_bgr, score_txt, topleft_xy) 37 | return image_bgr 38 | -------------------------------------------------------------------------------- /projects/DensePose/dev/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Some scripts for developers to use, include: 3 | 4 | - `run_instant_tests.sh`: run training for a few iterations. 5 | - `run_inference_tests.sh`: run inference on a small dataset. 6 | - `../../dev/linter.sh`: lint the codebase before commit 7 | - `../../dev/parse_results.sh`: parse results from log file. 8 | -------------------------------------------------------------------------------- /projects/DensePose/dev/run_inference_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | BIN="python train_net.py" 5 | OUTPUT="inference_test_output" 6 | NUM_GPUS=2 7 | IMS_PER_GPU=2 8 | IMS_PER_BATCH=$(( NUM_GPUS * IMS_PER_GPU )) 9 | 10 | CFG_LIST=( "${@:1}" ) 11 | 12 | if [ ${#CFG_LIST[@]} -eq 0 ]; then 13 | CFG_LIST=( ./configs/quick_schedules/*inference_acc_test.yaml ) 14 | fi 15 | 16 | echo "========================================================================" 17 | echo "Configs to run:" 18 | echo "${CFG_LIST[@]}" 19 | echo "========================================================================" 20 | 21 | for cfg in "${CFG_LIST[@]}"; do 22 | echo "========================================================================" 23 | echo "Running $cfg ..." 24 | echo "========================================================================" 25 | $BIN \ 26 | --eval-only \ 27 | --num-gpus $NUM_GPUS \ 28 | --config-file "$cfg" \ 29 | OUTPUT_DIR "$OUTPUT" \ 30 | SOLVER.IMS_PER_BATCH $IMS_PER_BATCH 31 | rm -rf $OUTPUT 32 | done 33 | 34 | -------------------------------------------------------------------------------- /projects/DensePose/dev/run_instant_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | BIN="python train_net.py" 5 | OUTPUT="instant_test_output" 6 | NUM_GPUS=2 7 | SOLVER_IMS_PER_BATCH=$((NUM_GPUS * 2)) 8 | 9 | CFG_LIST=( "${@:1}" ) 10 | if [ ${#CFG_LIST[@]} -eq 0 ]; then 11 | CFG_LIST=( ./configs/quick_schedules/*instant_test.yaml ) 12 | fi 13 | 14 | echo "========================================================================" 15 | echo "Configs to run:" 16 | echo "${CFG_LIST[@]}" 17 | echo "========================================================================" 18 | 19 | for cfg in "${CFG_LIST[@]}"; do 20 | echo "========================================================================" 21 | echo "Running $cfg ..." 22 | echo "========================================================================" 23 | $BIN --num-gpus $NUM_GPUS --config-file "$cfg" \ 24 | SOLVER.IMS_PER_BATCH $SOLVER_IMS_PER_BATCH \ 25 | OUTPUT_DIR "$OUTPUT" 26 | rm -rf "$OUTPUT" 27 | done 28 | 29 | -------------------------------------------------------------------------------- /projects/DensePose/doc/images/res_bbox_dp_contour.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/res_bbox_dp_contour.jpg -------------------------------------------------------------------------------- /projects/DensePose/doc/images/res_bbox_dp_segm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/res_bbox_dp_segm.jpg -------------------------------------------------------------------------------- /projects/DensePose/doc/images/res_bbox_dp_u.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/res_bbox_dp_u.jpg -------------------------------------------------------------------------------- /projects/DensePose/doc/images/res_bbox_dp_v.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/res_bbox_dp_v.jpg -------------------------------------------------------------------------------- /projects/DensePose/doc/images/vis_bbox_dp_i.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/vis_bbox_dp_i.jpg -------------------------------------------------------------------------------- /projects/DensePose/doc/images/vis_bbox_dp_pts.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/vis_bbox_dp_pts.jpg -------------------------------------------------------------------------------- /projects/DensePose/doc/images/vis_bbox_dp_segm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/vis_bbox_dp_segm.jpg -------------------------------------------------------------------------------- /projects/DensePose/doc/images/vis_bbox_dp_u.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/vis_bbox_dp_u.jpg -------------------------------------------------------------------------------- /projects/DensePose/doc/images/vis_bbox_dp_v.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/projects/DensePose/doc/images/vis_bbox_dp_v.jpg -------------------------------------------------------------------------------- /projects/DensePose/tests/test_combine_data_loader.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | 3 | import random 4 | import unittest 5 | from typing import Any, Iterable, Iterator, Tuple 6 | 7 | from densepose.data import CombinedDataLoader 8 | 9 | 10 | def _grouper(iterable: Iterable[Any], n: int, fillvalue=None) -> Iterator[Tuple[Any]]: 11 | """ 12 | Group elements of an iterable by chunks of size `n`, e.g. 13 | grouper(range(9), 4) -> 14 | (0, 1, 2, 3), (4, 5, 6, 7), (8, None, None, None) 15 | """ 16 | it = iter(iterable) 17 | while True: 18 | values = [] 19 | for _ in range(n): 20 | try: 21 | value = next(it) 22 | except StopIteration: 23 | values.extend([fillvalue] * (n - len(values))) 24 | yield tuple(values) 25 | return 26 | values.append(value) 27 | yield tuple(values) 28 | 29 | 30 | class TestCombinedDataLoader(unittest.TestCase): 31 | def test_combine_loaders_1(self): 32 | loader1 = _grouper([f"1_{i}" for i in range(10)], 2) 33 | loader2 = _grouper([f"2_{i}" for i in range(11)], 3) 34 | batch_size = 4 35 | ratios = (0.1, 0.9) 36 | random.seed(43) 37 | combined = CombinedDataLoader((loader1, loader2), batch_size, ratios) 38 | BATCHES_GT = [ 39 | ["1_0", "1_1", "2_0", "2_1"], 40 | ["2_2", "2_3", "2_4", "2_5"], 41 | ["1_2", "1_3", "2_6", "2_7"], 42 | ["2_8", "2_9", "2_10", None], 43 | ] 44 | for i, batch in enumerate(combined): 45 | self.assertEqual(len(batch), batch_size) 46 | self.assertEqual(batch, BATCHES_GT[i]) 47 | -------------------------------------------------------------------------------- /projects/DensePose/tests/test_image_resize_transform.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | import unittest 4 | import torch 5 | 6 | from densepose.data.transform import ImageResizeTransform 7 | 8 | 9 | class TestImageResizeTransform(unittest.TestCase): 10 | def test_image_resize_1(self): 11 | images_batch = torch.ones((3, 100, 100, 3), dtype=torch.uint8) * 100 12 | transform = ImageResizeTransform() 13 | images_transformed = transform(images_batch) 14 | IMAGES_GT = torch.ones((3, 3, 800, 800), dtype=torch.float) * 100 15 | self.assertEqual(images_transformed.size(), IMAGES_GT.size()) 16 | self.assertAlmostEqual(torch.abs(IMAGES_GT - images_transformed).max().item(), 0.0) 17 | -------------------------------------------------------------------------------- /projects/DensePose/tests/test_model_e2e.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | 3 | import unittest 4 | import torch 5 | 6 | from detectron2.structures import BitMasks, Boxes, Instances 7 | 8 | from .common import get_model 9 | 10 | 11 | # TODO(plabatut): Modularize detectron2 tests and re-use 12 | def make_model_inputs(image, instances=None): 13 | if instances is None: 14 | return {"image": image} 15 | 16 | return {"image": image, "instances": instances} 17 | 18 | 19 | def make_empty_instances(h, w): 20 | instances = Instances((h, w)) 21 | instances.gt_boxes = Boxes(torch.rand(0, 4)) 22 | instances.gt_classes = torch.tensor([]).to(dtype=torch.int64) 23 | instances.gt_masks = BitMasks(torch.rand(0, h, w)) 24 | return instances 25 | 26 | 27 | class ModelE2ETest(unittest.TestCase): 28 | CONFIG_PATH = "" 29 | 30 | def setUp(self): 31 | self.model = get_model(self.CONFIG_PATH) 32 | 33 | def _test_eval(self, sizes): 34 | inputs = [make_model_inputs(torch.rand(3, size[0], size[1])) for size in sizes] 35 | self.model.eval() 36 | self.model(inputs) 37 | 38 | 39 | class DensePoseRCNNE2ETest(ModelE2ETest): 40 | CONFIG_PATH = "densepose_rcnn_R_101_FPN_s1x.yaml" 41 | 42 | def test_empty_data(self): 43 | self._test_eval([(200, 250), (200, 249)]) 44 | -------------------------------------------------------------------------------- /projects/DensePose/tests/test_setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | 3 | import unittest 4 | 5 | from .common import ( 6 | get_config_files, 7 | get_evolution_config_files, 8 | get_quick_schedules_config_files, 9 | setup, 10 | ) 11 | 12 | 13 | class TestSetup(unittest.TestCase): 14 | def _test_setup(self, config_file): 15 | setup(config_file) 16 | 17 | def test_setup_configs(self): 18 | config_files = get_config_files() 19 | for config_file in config_files: 20 | self._test_setup(config_file) 21 | 22 | def test_setup_evolution_configs(self): 23 | config_files = get_evolution_config_files() 24 | for config_file in config_files: 25 | self._test_setup(config_file) 26 | 27 | def test_setup_quick_schedules_configs(self): 28 | config_files = get_quick_schedules_config_files() 29 | for config_file in config_files: 30 | self._test_setup(config_file) 31 | -------------------------------------------------------------------------------- /projects/DensePose/tests/test_structures.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | 3 | import unittest 4 | 5 | from densepose.data.structures import normalized_coords_transform 6 | 7 | 8 | class TestStructures(unittest.TestCase): 9 | def test_normalized_coords_transform(self): 10 | bbox = (32, 24, 288, 216) 11 | x0, y0, w, h = bbox 12 | xmin, ymin, xmax, ymax = x0, y0, x0 + w, y0 + h 13 | f = normalized_coords_transform(*bbox) 14 | # Top-left 15 | expected_p, actual_p = (-1, -1), f((xmin, ymin)) 16 | self.assertEqual(expected_p, actual_p) 17 | # Top-right 18 | expected_p, actual_p = (1, -1), f((xmax, ymin)) 19 | self.assertEqual(expected_p, actual_p) 20 | # Bottom-left 21 | expected_p, actual_p = (-1, 1), f((xmin, ymax)) 22 | self.assertEqual(expected_p, actual_p) 23 | # Bottom-right 24 | expected_p, actual_p = (1, 1), f((xmax, ymax)) 25 | self.assertEqual(expected_p, actual_p) 26 | -------------------------------------------------------------------------------- /projects/PointRend/configs/InstanceSegmentation/Base-PointRend-RCNN-FPN.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../../../configs/Base-RCNN-FPN.yaml" 2 | MODEL: 3 | ROI_HEADS: 4 | NAME: "PointRendROIHeads" 5 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 6 | ROI_BOX_HEAD: 7 | TRAIN_ON_PRED_BOXES: True 8 | ROI_MASK_HEAD: 9 | NAME: "CoarseMaskHead" 10 | FC_DIM: 1024 11 | NUM_FC: 2 12 | OUTPUT_SIDE_RESOLUTION: 7 13 | IN_FEATURES: ["p2"] 14 | POINT_HEAD_ON: True 15 | POINT_HEAD: 16 | FC_DIM: 256 17 | NUM_FC: 3 18 | IN_FEATURES: ["p2"] 19 | INPUT: 20 | # PointRend for instance segmenation does not work with "polygon" mask_format. 21 | MASK_FORMAT: "bitmask" 22 | -------------------------------------------------------------------------------- /projects/PointRend/configs/InstanceSegmentation/pointrend_rcnn_R_50_FPN_1x_cityscapes.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: Base-PointRend-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: 8 9 | POINT_HEAD: 10 | NUM_CLASSES: 8 11 | DATASETS: 12 | TEST: ("cityscapes_fine_instance_seg_val",) 13 | TRAIN: ("cityscapes_fine_instance_seg_train",) 14 | SOLVER: 15 | BASE_LR: 0.01 16 | IMS_PER_BATCH: 8 17 | MAX_ITER: 24000 18 | STEPS: (18000,) 19 | INPUT: 20 | MAX_SIZE_TEST: 2048 21 | MAX_SIZE_TRAIN: 2048 22 | MIN_SIZE_TEST: 1024 23 | MIN_SIZE_TRAIN: (800, 832, 864, 896, 928, 960, 992, 1024) 24 | -------------------------------------------------------------------------------- /projects/PointRend/configs/InstanceSegmentation/pointrend_rcnn_R_50_FPN_1x_coco.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: Base-PointRend-RCNN-FPN.yaml 2 | MODEL: 3 | WEIGHTS: detectron2://ImageNetPretrained/MSRA/R-50.pkl 4 | MASK_ON: true 5 | RESNETS: 6 | DEPTH: 50 7 | # To add COCO AP evaluation against the higher-quality LVIS annotations. 8 | # DATASETS: 9 | # TEST: ("coco_2017_val", "lvis_v0.5_val_cocofied") 10 | -------------------------------------------------------------------------------- /projects/PointRend/configs/InstanceSegmentation/pointrend_rcnn_R_50_FPN_3x_coco.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: Base-PointRend-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 | # To add COCO AP evaluation against the higher-quality LVIS annotations. 11 | # DATASETS: 12 | # TEST: ("coco_2017_val", "lvis_v0.5_val_cocofied") 13 | 14 | -------------------------------------------------------------------------------- /projects/PointRend/configs/SemanticSegmentation/Base-PointRend-Semantic-FPN.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../../../../configs/Base-RCNN-FPN.yaml" 2 | MODEL: 3 | META_ARCHITECTURE: "SemanticSegmentor" 4 | BACKBONE: 5 | FREEZE_AT: 0 6 | SEM_SEG_HEAD: 7 | NAME: "PointRendSemSegHead" 8 | POINT_HEAD: 9 | NUM_CLASSES: 54 10 | FC_DIM: 256 11 | NUM_FC: 3 12 | IN_FEATURES: ["p2"] 13 | TRAIN_NUM_POINTS: 1024 14 | SUBDIVISION_STEPS: 2 15 | SUBDIVISION_NUM_POINTS: 8192 16 | COARSE_SEM_SEG_HEAD_NAME: "SemSegFPNHead" 17 | DATASETS: 18 | TRAIN: ("coco_2017_train_panoptic_stuffonly",) 19 | TEST: ("coco_2017_val_panoptic_stuffonly",) 20 | -------------------------------------------------------------------------------- /projects/PointRend/configs/SemanticSegmentation/pointrend_semantic_R_101_FPN_1x_cityscapes.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: Base-PointRend-Semantic-FPN.yaml 2 | MODEL: 3 | WEIGHTS: detectron2://ImageNetPretrained/MSRA/R-101.pkl 4 | RESNETS: 5 | DEPTH: 101 6 | SEM_SEG_HEAD: 7 | NUM_CLASSES: 19 8 | POINT_HEAD: 9 | NUM_CLASSES: 19 10 | TRAIN_NUM_POINTS: 2048 11 | SUBDIVISION_NUM_POINTS: 8192 12 | DATASETS: 13 | TRAIN: ("cityscapes_fine_sem_seg_train",) 14 | TEST: ("cityscapes_fine_sem_seg_val",) 15 | SOLVER: 16 | BASE_LR: 0.01 17 | STEPS: (40000, 55000) 18 | MAX_ITER: 65000 19 | IMS_PER_BATCH: 32 20 | INPUT: 21 | MIN_SIZE_TRAIN: (512, 768, 1024, 1280, 1536, 1792, 2048) 22 | MIN_SIZE_TRAIN_SAMPLING: "choice" 23 | MIN_SIZE_TEST: 1024 24 | MAX_SIZE_TRAIN: 4096 25 | MAX_SIZE_TEST: 2048 26 | CROP: 27 | ENABLED: True 28 | TYPE: "absolute" 29 | SIZE: (512, 1024) 30 | SINGLE_CATEGORY_MAX_AREA: 0.75 31 | COLOR_AUG_SSD: True 32 | DATALOADER: 33 | NUM_WORKERS: 16 34 | -------------------------------------------------------------------------------- /projects/PointRend/configs/SemanticSegmentation/pointrend_semantic_R_50_FPN_1x_coco.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: Base-PointRend-Semantic-FPN.yaml 2 | MODEL: 3 | WEIGHTS: detectron2://ImageNetPretrained/MSRA/R-50.pkl 4 | RESNETS: 5 | DEPTH: 50 6 | -------------------------------------------------------------------------------- /projects/PointRend/point_rend/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .config import add_pointrend_config 3 | from .coarse_mask_head import CoarseMaskHead 4 | from .roi_heads import PointRendROIHeads 5 | from .dataset_mapper import SemSegDatasetMapper 6 | from .semantic_seg import PointRendSemSegHead 7 | -------------------------------------------------------------------------------- /projects/README.md: -------------------------------------------------------------------------------- 1 | 2 | Here are a few projects that are built on detectron2. 3 | They are examples of how to use detectron2 as a library, to make your projects more 4 | maintainable. 5 | 6 | ## Projects by Facebook 7 | 8 | Note that these are research projects, and therefore may not have the same level 9 | of support or stability of detectron2. 10 | 11 | + [DensePose: Dense Human Pose Estimation In The Wild](DensePose) 12 | + [Scale-Aware Trident Networks for Object Detection](TridentNet) 13 | + [TensorMask: A Foundation for Dense Object Segmentation](TensorMask) 14 | + [Mesh R-CNN](https://github.com/facebookresearch/meshrcnn) 15 | + [PointRend: Image Segmentation as Rendering](PointRend) 16 | + [Momentum Contrast for Unsupervised Visual Representation Learning](https://github.com/facebookresearch/moco/tree/master/detection) 17 | + [DETR: End-to-End Object Detection with Transformers](https://github.com/facebookresearch/detr/tree/master/d2) 18 | 19 | 20 | ## External Projects 21 | 22 | External projects in the community that use detectron2: 23 | 24 | 33 | 34 | + [AdelaiDet](https://github.com/aim-uofa/adet), a detection toolbox including FCOS, BlendMask, etc. 35 | + [CenterMask](https://github.com/youngwanLEE/centermask2) 36 | + [Res2Net backbones](https://github.com/Res2Net/Res2Net-detectron2) 37 | + [VoVNet backbones](https://github.com/youngwanLEE/vovnet-detectron2) 38 | -------------------------------------------------------------------------------- /projects/RIO/configs/Base-Memory-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: "MemoryROIHeads" 23 | IN_FEATURES: ["p2", "p3", "p4", "p5"] 24 | TEMP_S: 48 25 | MIN_CACHE: 5 26 | MAX_CACHE: 60 27 | RANDOM_SELECT: False 28 | CACHE_CAT_FILE: "lvis0.5_rare_cats.txt" 29 | CLS_LAYER: "cosine" 30 | RUN: 1 31 | ROI_BOX_HEAD: 32 | NAME: "FastRCNNConvFCHead" 33 | NUM_FC: 2 34 | POOLER_RESOLUTION: 7 35 | ROI_MASK_HEAD: 36 | NAME: "MaskRCNNConvUpsampleHead" 37 | NUM_CONV: 4 38 | POOLER_RESOLUTION: 14 39 | DATASETS: 40 | TRAIN: ("coco_2017_train",) 41 | TEST: ("coco_2017_val",) 42 | SOLVER: 43 | IMS_PER_BATCH: 16 44 | BASE_LR: 0.02 45 | STEPS: (60000, 80000) 46 | MAX_ITER: 90000 47 | INPUT: 48 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 49 | VERSION: 2 -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/configs/LVISv0.5-InstanceSegmentation/memory_mask_rcnn_R_101_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-Memory-RCNN-FPN.yaml" 2 | OUTPUT_DIR: "results/resnet101" 3 | MODEL: 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 5 | MASK_ON: True 6 | RESNETS: 7 | DEPTH: 101 8 | ROI_HEADS: 9 | NUM_CLASSES: 1230 10 | TEMP_S: 48 11 | MIN_CACHE: 20 12 | MAX_CACHE: 60 13 | RANDOM_SELECT: False 14 | CACHE_CAT_FILE: "lvis_categories_lists/lvis0.5_rare_common30_cats.txt" 15 | CLS_LAYER: "cosine" 16 | RUN: 1 17 | SCORE_THRESH_TEST: 0.0001 18 | INPUT: 19 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 20 | DATASETS: 21 | TRAIN: ("lvis_v0.5_train",) 22 | TEST: ("lvis_v0.5_val",) 23 | TEST: 24 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 25 | DATALOADER: 26 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 27 | REPEAT_THRESHOLD: 0.001 28 | -------------------------------------------------------------------------------- /projects/RIO/configs/LVISv0.5-InstanceSegmentation/memory_mask_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-Memory-RCNN-FPN.yaml" 2 | OUTPUT_DIR: "results/resnet50" 3 | MODEL: 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | MASK_ON: True 6 | RESNETS: 7 | DEPTH: 50 8 | ROI_HEADS: 9 | NUM_CLASSES: 1230 10 | TEMP_S: 48 11 | MIN_CACHE: 20 12 | MAX_CACHE: 60 13 | RANDOM_SELECT: False 14 | CACHE_CAT_FILE: "lvis_categories_lists/lvis0.5_rare_common30_cats.txt" 15 | CLS_LAYER: "cosine" 16 | RUN: 1 17 | SCORE_THRESH_TEST: 0.0001 18 | INPUT: 19 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 20 | DATASETS: 21 | TRAIN: ("lvis_v0.5_train",) 22 | TEST: ("lvis_v0.5_val",) 23 | TEST: 24 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 25 | DATALOADER: 26 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 27 | REPEAT_THRESHOLD: 0.001 28 | -------------------------------------------------------------------------------- /projects/RIO/configs/LVISv0.5-InstanceSegmentation/memory_mask_rcnn_X_101_32x8d_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-Memory-RCNN-FPN.yaml" 2 | OUTPUT_DIR: "results/resnext101" 3 | MODEL: 4 | WEIGHTS: "detectron2://ImageNetPretrained/FAIR/X-101-32x8d.pkl" 5 | PIXEL_STD: [57.375, 57.120, 58.395] 6 | MASK_ON: True 7 | RESNETS: 8 | STRIDE_IN_1X1: False # this is a C2 model 9 | NUM_GROUPS: 32 10 | WIDTH_PER_GROUP: 8 11 | DEPTH: 101 12 | ROI_HEADS: 13 | NUM_CLASSES: 1230 14 | TEMP_S: 48 15 | MIN_CACHE: 20 16 | MAX_CACHE: 60 17 | RANDOM_SELECT: False 18 | CACHE_CAT_FILE: "lvis_categories_lists/lvis0.5_rare_common30_cats.txt" 19 | CLS_LAYER: "cosine" 20 | RUN: 1 21 | SCORE_THRESH_TEST: 0.0001 22 | INPUT: 23 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 24 | DATASETS: 25 | TRAIN: ("lvis_v0.5_train",) 26 | TEST: ("lvis_v0.5_val",) 27 | TEST: 28 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 29 | DATALOADER: 30 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 31 | REPEAT_THRESHOLD: 0.001 -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/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 | -------------------------------------------------------------------------------- /projects/RIO/configs/LVISv1-InstanceSegmentation/memory_mask_rcnn_R_101_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-Memory-RCNN-FPN.yaml" 2 | OUTPUT_DIR: "results/resnet101/lvis1" 3 | MODEL: 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-101.pkl" 5 | MASK_ON: True 6 | RESNETS: 7 | DEPTH: 101 8 | ROI_HEADS: 9 | NUM_CLASSES: 1203 10 | TEMP_S: 48 11 | MIN_CACHE: 20 12 | MAX_CACHE: 60 13 | RANDOM_SELECT: False 14 | CACHE_CAT_FILE: "lvis_categories_lists/lvis1_rare_common30_cats.txt" 15 | CLS_LAYER: "cosine" 16 | RUN: 1 17 | SCORE_THRESH_TEST: 0.0001 18 | INPUT: 19 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 20 | DATASETS: 21 | TRAIN: ("lvis_v1_train",) 22 | TEST: ("lvis_v1_val",) 23 | TEST: 24 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 25 | DATALOADER: 26 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 27 | REPEAT_THRESHOLD: 0.001 28 | SOLVER: 29 | STEPS: (120000, 160000) 30 | MAX_ITER: 180000 # 180000 * 16 / 100000 ~ 28.8 epoch 31 | -------------------------------------------------------------------------------- /projects/RIO/configs/LVISv1-InstanceSegmentation/memory_mask_rcnn_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-Memory-RCNN-FPN.yaml" 2 | OUTPUT_DIR: "results/resnet50/lvis1" 3 | MODEL: 4 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 5 | MASK_ON: True 6 | RESNETS: 7 | DEPTH: 50 8 | ROI_HEADS: 9 | NUM_CLASSES: 1203 10 | TEMP_S: 48 11 | MIN_CACHE: 20 12 | MAX_CACHE: 60 13 | RANDOM_SELECT: False 14 | CACHE_CAT_FILE: "lvis_categories_lists/lvis1_rare_common30_cats.txt" 15 | CLS_LAYER: "cosine" 16 | RUN: 1 17 | SCORE_THRESH_TEST: 0.0001 18 | INPUT: 19 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 20 | DATASETS: 21 | TRAIN: ("lvis_v1_train",) 22 | TEST: ("lvis_v1_val",) 23 | TEST: 24 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 25 | DATALOADER: 26 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 27 | REPEAT_THRESHOLD: 0.001 28 | SOLVER: 29 | STEPS: (120000, 160000) 30 | MAX_ITER: 180000 # 180000 * 16 / 100000 ~ 28.8 epochs #total images 100,170 31 | -------------------------------------------------------------------------------- /projects/RIO/configs/LVISv1-InstanceSegmentation/memory_mask_rcnn_X_101_32x8d_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "../Base-Memory-RCNN-FPN.yaml" 2 | OUTPUT_DIR: "results/resnext101/lvis1" 3 | MODEL: 4 | WEIGHTS: "detectron2://ImageNetPretrained/FAIR/X-101-32x8d.pkl" 5 | PIXEL_STD: [57.375, 57.120, 58.395] 6 | MASK_ON: True 7 | RESNETS: 8 | STRIDE_IN_1X1: False # this is a C2 model 9 | NUM_GROUPS: 32 10 | WIDTH_PER_GROUP: 8 11 | DEPTH: 101 12 | ROI_HEADS: 13 | NUM_CLASSES: 1203 14 | TEMP_S: 48 15 | MIN_CACHE: 5 16 | MAX_CACHE: 100 17 | RANDOM_SELECT: False 18 | CACHE_CAT_FILE: "lvis_categories_lists/lvis1_rare_common30_cats.txt" 19 | CLS_LAYER: "cosine" 20 | RUN: 1 21 | SCORE_THRESH_TEST: 0.0001 22 | INPUT: 23 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 24 | DATASETS: 25 | TRAIN: ("lvis_v1_train",) 26 | TEST: ("lvis_v1_val",) 27 | TEST: 28 | DETECTIONS_PER_IMAGE: 300 # LVIS allows up to 300 29 | DATALOADER: 30 | SAMPLER_TRAIN: "RepeatFactorTrainingSampler" 31 | REPEAT_THRESHOLD: 0.001 32 | SOLVER: 33 | STEPS: (120000, 160000) 34 | MAX_ITER: 180000 # 180000 * 16 / 100000 ~ 28.8 epoch -------------------------------------------------------------------------------- /projects/RIO/memory_bank/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 2 | # 3 | # NVIDIA CORPORATION and its licensors retain all intellectual property 4 | # and proprietary rights in and to this software, related documentation 5 | # and any modifications thereto. Any use, reproduction, disclosure or 6 | # distribution of this software and related documentation without an express 7 | # license agreement from NVIDIA CORPORATION is strictly prohibited. 8 | 9 | from .roi_heads import * 10 | from .cfg import add_memory_config 11 | -------------------------------------------------------------------------------- /projects/RIO/memory_bank/cfg.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 2 | # 3 | # NVIDIA CORPORATION and its licensors retain all intellectual property 4 | # and proprietary rights in and to this software, related documentation 5 | # and any modifications thereto. Any use, reproduction, disclosure or 6 | # distribution of this software and related documentation without an express 7 | # license agreement from NVIDIA CORPORATION is strictly prohibited. 8 | 9 | 10 | def add_memory_config(cfg): 11 | """ 12 | Add config for Memory bank. 13 | """ 14 | cfg.MODEL.ROI_HEADS.TEMP_S = 48 15 | cfg.MODEL.ROI_HEADS.MIN_CACHE = 20 16 | cfg.MODEL.ROI_HEADS.MAX_CACHE = 60 17 | cfg.MODEL.ROI_HEADS.RANDOM_SELECT = False 18 | cfg.MODEL.ROI_HEADS.CACHE_CAT_FILE = "lvis0.5_rare_cats.txt" 19 | cfg.MODEL.ROI_HEADS.CLS_LAYER = "cosine" 20 | cfg.MODEL.ROI_HEADS.RUN = 1 21 | 22 | -------------------------------------------------------------------------------- /projects/RIO/memory_bank/new_layers.py: -------------------------------------------------------------------------------- 1 | # This code is modified from https://github.com/wyharveychen/CloserLookFewShot/ 2 | 3 | import torch 4 | import torch.nn as nn 5 | from torch.nn.utils.weight_norm import WeightNorm 6 | 7 | 8 | class distLinear(nn.Module): 9 | def __init__(self, indim, outdim): 10 | super(distLinear, self).__init__() 11 | self.L = nn.Linear(indim, outdim, bias=False) 12 | self.class_wise_learnable_norm = True 13 | if self.class_wise_learnable_norm: 14 | WeightNorm.apply(self.L, "weight", dim=0) 15 | 16 | def forward(self, x): 17 | x_norm = torch.norm(x, p=2, dim=1).unsqueeze(1).expand_as(x) 18 | x_normalized = x.div(x_norm + 0.00001) 19 | if not self.class_wise_learnable_norm: 20 | L_norm = ( 21 | torch.norm(self.L.weight.data, p=2, dim=1) 22 | .unsqueeze(1) 23 | .expand_as(self.L.weight.data) 24 | ) 25 | self.L.weight.data = self.L.weight.data.div(L_norm + 0.00001) 26 | cos_dist = self.L(x_normalized) 27 | 28 | return cos_dist 29 | -------------------------------------------------------------------------------- /projects/TensorMask/configs/Base-TensorMask.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "TensorMask" 3 | MASK_ON: True 4 | BACKBONE: 5 | NAME: "build_retinanet_resnet_fpn_backbone" 6 | RESNETS: 7 | OUT_FEATURES: ["res2", "res3", "res4", "res5"] 8 | ANCHOR_GENERATOR: 9 | SIZES: [[44, 60], [88, 120], [176, 240], [352, 480], [704, 960], [1408, 1920]] 10 | ASPECT_RATIOS: [[1.0]] 11 | FPN: 12 | IN_FEATURES: ["res2", "res3", "res4", "res5"] 13 | FUSE_TYPE: "avg" 14 | TENSOR_MASK: 15 | ALIGNED_ON: True 16 | BIPYRAMID_ON: True 17 | DATASETS: 18 | TRAIN: ("coco_2017_train",) 19 | TEST: ("coco_2017_val",) 20 | SOLVER: 21 | IMS_PER_BATCH: 16 22 | BASE_LR: 0.02 23 | STEPS: (60000, 80000) 24 | MAX_ITER: 90000 25 | VERSION: 2 26 | -------------------------------------------------------------------------------- /projects/TensorMask/configs/tensormask_R_50_FPN_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-TensorMask.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | -------------------------------------------------------------------------------- /projects/TensorMask/configs/tensormask_R_50_FPN_6x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-TensorMask.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | RESNETS: 5 | DEPTH: 50 6 | SOLVER: 7 | STEPS: (480000, 520000) 8 | MAX_ITER: 540000 9 | INPUT: 10 | MIN_SIZE_TRAIN_SAMPLING: "range" 11 | MIN_SIZE_TRAIN: (640, 800) 12 | -------------------------------------------------------------------------------- /projects/TensorMask/tensormask/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .config import add_tensormask_config 3 | from .arch import TensorMask 4 | -------------------------------------------------------------------------------- /projects/TensorMask/tensormask/config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | from detectron2.config import CfgNode as CN 5 | 6 | 7 | def add_tensormask_config(cfg): 8 | """ 9 | Add config for TensorMask. 10 | """ 11 | cfg.MODEL.TENSOR_MASK = CN() 12 | 13 | # Anchor parameters 14 | cfg.MODEL.TENSOR_MASK.IN_FEATURES = ["p2", "p3", "p4", "p5", "p6", "p7"] 15 | 16 | # Convolutions to use in the towers 17 | cfg.MODEL.TENSOR_MASK.NUM_CONVS = 4 18 | 19 | # Number of foreground classes. 20 | cfg.MODEL.TENSOR_MASK.NUM_CLASSES = 80 21 | # Channel size for the classification tower 22 | cfg.MODEL.TENSOR_MASK.CLS_CHANNELS = 256 23 | 24 | cfg.MODEL.TENSOR_MASK.SCORE_THRESH_TEST = 0.05 25 | # Only the top (1000 * #levels) candidate boxes across all levels are 26 | # considered jointly during test (to improve speed) 27 | cfg.MODEL.TENSOR_MASK.TOPK_CANDIDATES_TEST = 6000 28 | cfg.MODEL.TENSOR_MASK.NMS_THRESH_TEST = 0.5 29 | 30 | # Box parameters 31 | # Channel size for the box tower 32 | cfg.MODEL.TENSOR_MASK.BBOX_CHANNELS = 128 33 | # Weights on (dx, dy, dw, dh) 34 | cfg.MODEL.TENSOR_MASK.BBOX_REG_WEIGHTS = (1.5, 1.5, 0.75, 0.75) 35 | 36 | # Loss parameters 37 | cfg.MODEL.TENSOR_MASK.FOCAL_LOSS_GAMMA = 3.0 38 | cfg.MODEL.TENSOR_MASK.FOCAL_LOSS_ALPHA = 0.3 39 | 40 | # Mask parameters 41 | # Channel size for the mask tower 42 | cfg.MODEL.TENSOR_MASK.MASK_CHANNELS = 128 43 | # Mask loss weight 44 | cfg.MODEL.TENSOR_MASK.MASK_LOSS_WEIGHT = 2.0 45 | # weight on positive pixels within the mask 46 | cfg.MODEL.TENSOR_MASK.POSITIVE_WEIGHT = 1.5 47 | # Whether to predict in the aligned representation 48 | cfg.MODEL.TENSOR_MASK.ALIGNED_ON = False 49 | # Whether to use the bipyramid architecture 50 | cfg.MODEL.TENSOR_MASK.BIPYRAMID_ON = False 51 | -------------------------------------------------------------------------------- /projects/TensorMask/tensormask/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .swap_align2nat import SwapAlign2Nat, swap_align2nat 3 | 4 | __all__ = [k for k in globals().keys() if not k.startswith("_")] 5 | -------------------------------------------------------------------------------- /projects/TensorMask/tensormask/layers/csrc/SwapAlign2Nat/SwapAlign2Nat.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | #pragma once 3 | #include 4 | 5 | namespace tensormask { 6 | 7 | #if defined(WITH_CUDA) || defined(WITH_HIP) 8 | at::Tensor SwapAlign2Nat_forward_cuda( 9 | const at::Tensor& X, 10 | const int lambda_val, 11 | const float pad_val); 12 | 13 | at::Tensor SwapAlign2Nat_backward_cuda( 14 | const at::Tensor& gY, 15 | const int lambda_val, 16 | const int batch_size, 17 | const int channel, 18 | const int height, 19 | const int width); 20 | #endif 21 | 22 | inline at::Tensor SwapAlign2Nat_forward( 23 | const at::Tensor& X, 24 | const int lambda_val, 25 | const float pad_val) { 26 | if (X.type().is_cuda()) { 27 | #if defined(WITH_CUDA) || defined(WITH_HIP) 28 | return SwapAlign2Nat_forward_cuda(X, lambda_val, pad_val); 29 | #else 30 | AT_ERROR("Not compiled with GPU support"); 31 | #endif 32 | } 33 | AT_ERROR("Not implemented on the CPU"); 34 | } 35 | 36 | inline at::Tensor SwapAlign2Nat_backward( 37 | const at::Tensor& gY, 38 | const int lambda_val, 39 | const int batch_size, 40 | const int channel, 41 | const int height, 42 | const int width) { 43 | if (gY.type().is_cuda()) { 44 | #if defined(WITH_CUDA) || defined(WITH_HIP) 45 | return SwapAlign2Nat_backward_cuda( 46 | gY, lambda_val, batch_size, channel, height, width); 47 | #else 48 | AT_ERROR("Not compiled with GPU support"); 49 | #endif 50 | } 51 | AT_ERROR("Not implemented on the CPU"); 52 | } 53 | 54 | } // namespace tensormask 55 | -------------------------------------------------------------------------------- /projects/TensorMask/tensormask/layers/csrc/vision.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | #include 4 | #include "SwapAlign2Nat/SwapAlign2Nat.h" 5 | 6 | namespace tensormask { 7 | 8 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 9 | m.def( 10 | "swap_align2nat_forward", 11 | &SwapAlign2Nat_forward, 12 | "SwapAlign2Nat_forward"); 13 | m.def( 14 | "swap_align2nat_backward", 15 | &SwapAlign2Nat_backward, 16 | "SwapAlign2Nat_backward"); 17 | } 18 | 19 | } // namespace tensormask 20 | -------------------------------------------------------------------------------- /projects/TensorMask/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | -------------------------------------------------------------------------------- /projects/TensorMask/tests/test_swap_align2nat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | import unittest 5 | import torch 6 | from torch.autograd import gradcheck 7 | 8 | from tensormask.layers.swap_align2nat import SwapAlign2Nat 9 | 10 | 11 | class SwapAlign2NatTest(unittest.TestCase): 12 | @unittest.skipIf(not torch.cuda.is_available(), "CUDA not available") 13 | def test_swap_align2nat_gradcheck_cuda(self): 14 | dtype = torch.float64 15 | device = torch.device("cuda") 16 | m = SwapAlign2Nat(2).to(dtype=dtype, device=device) 17 | x = torch.rand(2, 4, 10, 10, dtype=dtype, device=device, requires_grad=True) 18 | 19 | self.assertTrue(gradcheck(m, x), "gradcheck failed for SwapAlign2Nat CUDA") 20 | 21 | def _swap_align2nat(self, tensor, lambda_val): 22 | """ 23 | The basic setup for testing Swap_Align 24 | """ 25 | op = SwapAlign2Nat(lambda_val, pad_val=0.0) 26 | input = torch.from_numpy(tensor[None, :, :, :].astype("float32")) 27 | output = op.forward(input.cuda()).cpu().numpy() 28 | return output[0] 29 | 30 | 31 | if __name__ == "__main__": 32 | unittest.main() 33 | -------------------------------------------------------------------------------- /projects/TridentNet/configs/Base-TridentNet-Fast-C4.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "GeneralizedRCNN" 3 | BACKBONE: 4 | NAME: "build_trident_resnet_backbone" 5 | ROI_HEADS: 6 | NAME: "TridentRes5ROIHeads" 7 | POSITIVE_FRACTION: 0.5 8 | BATCH_SIZE_PER_IMAGE: 128 9 | PROPOSAL_APPEND_GT: False 10 | PROPOSAL_GENERATOR: 11 | NAME: "TridentRPN" 12 | RPN: 13 | POST_NMS_TOPK_TRAIN: 500 14 | TRIDENT: 15 | NUM_BRANCH: 3 16 | BRANCH_DILATIONS: [1, 2, 3] 17 | TEST_BRANCH_IDX: 1 18 | TRIDENT_STAGE: "res4" 19 | DATASETS: 20 | TRAIN: ("coco_2017_train",) 21 | TEST: ("coco_2017_val",) 22 | SOLVER: 23 | IMS_PER_BATCH: 16 24 | BASE_LR: 0.02 25 | STEPS: (60000, 80000) 26 | MAX_ITER: 90000 27 | INPUT: 28 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 29 | VERSION: 2 30 | -------------------------------------------------------------------------------- /projects/TridentNet/configs/tridentnet_fast_R_101_C4_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-TridentNet-Fast-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 | -------------------------------------------------------------------------------- /projects/TridentNet/configs/tridentnet_fast_R_50_C4_1x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-TridentNet-Fast-C4.yaml" 2 | MODEL: 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | MASK_ON: False 5 | RESNETS: 6 | DEPTH: 50 7 | -------------------------------------------------------------------------------- /projects/TridentNet/configs/tridentnet_fast_R_50_C4_3x.yaml: -------------------------------------------------------------------------------- 1 | _BASE_: "Base-TridentNet-Fast-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 | -------------------------------------------------------------------------------- /projects/TridentNet/tridentnet/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .config import add_tridentnet_config 3 | from .trident_backbone import ( 4 | TridentBottleneckBlock, 5 | build_trident_resnet_backbone, 6 | make_trident_stage, 7 | ) 8 | from .trident_rpn import TridentRPN 9 | from .trident_rcnn import TridentRes5ROIHeads, TridentStandardROIHeads 10 | -------------------------------------------------------------------------------- /projects/TridentNet/tridentnet/config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 3 | 4 | from detectron2.config import CfgNode as CN 5 | 6 | 7 | def add_tridentnet_config(cfg): 8 | """ 9 | Add config for tridentnet. 10 | """ 11 | _C = cfg 12 | 13 | _C.MODEL.TRIDENT = CN() 14 | 15 | # Number of branches for TridentNet. 16 | _C.MODEL.TRIDENT.NUM_BRANCH = 3 17 | # Specify the dilations for each branch. 18 | _C.MODEL.TRIDENT.BRANCH_DILATIONS = [1, 2, 3] 19 | # Specify the stage for applying trident blocks. Default stage is Res4 according to the 20 | # TridentNet paper. 21 | _C.MODEL.TRIDENT.TRIDENT_STAGE = "res4" 22 | # Specify the test branch index TridentNet Fast inference: 23 | # - use -1 to aggregate results of all branches during inference. 24 | # - otherwise, only using specified branch for fast inference. Recommended setting is 25 | # to use the middle branch. 26 | _C.MODEL.TRIDENT.TEST_BRANCH_IDX = 1 27 | -------------------------------------------------------------------------------- /projects/TridentNet/tridentnet/trident_rpn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | import torch 3 | 4 | from detectron2.modeling import PROPOSAL_GENERATOR_REGISTRY 5 | from detectron2.modeling.proposal_generator.rpn import RPN 6 | from detectron2.structures import ImageList 7 | 8 | 9 | @PROPOSAL_GENERATOR_REGISTRY.register() 10 | class TridentRPN(RPN): 11 | """ 12 | Trident RPN subnetwork. 13 | """ 14 | 15 | def __init__(self, cfg, input_shape): 16 | super(TridentRPN, self).__init__(cfg, input_shape) 17 | 18 | self.num_branch = cfg.MODEL.TRIDENT.NUM_BRANCH 19 | self.trident_fast = cfg.MODEL.TRIDENT.TEST_BRANCH_IDX != -1 20 | 21 | def forward(self, images, features, gt_instances=None): 22 | """ 23 | See :class:`RPN.forward`. 24 | """ 25 | num_branch = self.num_branch if self.training or not self.trident_fast else 1 26 | # Duplicate images and gt_instances for all branches in TridentNet. 27 | all_images = ImageList( 28 | torch.cat([images.tensor] * num_branch), images.image_sizes * num_branch 29 | ) 30 | all_gt_instances = gt_instances * num_branch if gt_instances is not None else None 31 | 32 | return super(TridentRPN, self).forward(all_images, features, all_gt_instances) 33 | -------------------------------------------------------------------------------- /resources/github_thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/resources/github_thumbnail.png -------------------------------------------------------------------------------- /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 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 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. All Rights Reserved 2 | -------------------------------------------------------------------------------- /tests/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/tests/data/__init__.py -------------------------------------------------------------------------------- /tests/data/test_sampler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import unittest 3 | from torch.utils.data.sampler import SequentialSampler 4 | 5 | from detectron2.data.samplers import GroupedBatchSampler 6 | 7 | 8 | class TestGroupedBatchSampler(unittest.TestCase): 9 | def test_missing_group_id(self): 10 | sampler = SequentialSampler(list(range(100))) 11 | group_ids = [1] * 100 12 | samples = GroupedBatchSampler(sampler, group_ids, 2) 13 | 14 | for mini_batch in samples: 15 | self.assertEqual(len(mini_batch), 2) 16 | 17 | def test_groups(self): 18 | sampler = SequentialSampler(list(range(100))) 19 | group_ids = [1, 0] * 50 20 | samples = GroupedBatchSampler(sampler, group_ids, 2) 21 | 22 | for mini_batch in samples: 23 | self.assertEqual((mini_batch[0] + mini_batch[1]) % 2, 0) 24 | -------------------------------------------------------------------------------- /tests/layers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/tests/layers/__init__.py -------------------------------------------------------------------------------- /tests/modeling/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/tests/modeling/__init__.py -------------------------------------------------------------------------------- /tests/structures/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVlabs/RIO/29fc7701da4aea45da61435ba03e481c05033efd/tests/structures/__init__.py -------------------------------------------------------------------------------- /tests/structures/test_imagelist.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | 3 | import unittest 4 | from typing import Sequence 5 | import torch 6 | 7 | from detectron2.structures import ImageList 8 | 9 | 10 | class TestImageList(unittest.TestCase): 11 | def test_imagelist_padding_shape(self): 12 | class TensorToImageList(torch.nn.Module): 13 | def forward(self, tensors: Sequence[torch.Tensor]): 14 | return ImageList.from_tensors(tensors, 4).tensor 15 | 16 | func = torch.jit.trace( 17 | TensorToImageList(), ([torch.ones((3, 10, 10), dtype=torch.float32)],) 18 | ) 19 | ret = func([torch.ones((3, 15, 20), dtype=torch.float32)]) 20 | self.assertEqual(list(ret.shape), [1, 3, 16, 20], str(ret.shape)) 21 | 22 | func = torch.jit.trace( 23 | TensorToImageList(), 24 | ( 25 | [ 26 | torch.ones((3, 16, 10), dtype=torch.float32), 27 | torch.ones((3, 13, 11), dtype=torch.float32), 28 | ], 29 | ), 30 | ) 31 | ret = func( 32 | [ 33 | torch.ones((3, 25, 20), dtype=torch.float32), 34 | torch.ones((3, 10, 10), dtype=torch.float32), 35 | ] 36 | ) 37 | # does not support calling with different #images 38 | self.assertEqual(list(ret.shape), [2, 3, 28, 20], str(ret.shape)) 39 | -------------------------------------------------------------------------------- /tests/structures/test_instances.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | import unittest 3 | import torch 4 | 5 | from detectron2.structures import Instances 6 | 7 | 8 | class TestInstancesIndexing(unittest.TestCase): 9 | def test_int_indexing(self): 10 | attr1 = torch.tensor([[0.0, 0.0, 1.0], [0.0, 0.0, 0.5], [0.0, 0.0, 1.0], [0.0, 0.5, 0.5]]) 11 | attr2 = torch.tensor([0.1, 0.2, 0.3, 0.4]) 12 | instances = Instances((100, 100)) 13 | instances.attr1 = attr1 14 | instances.attr2 = attr2 15 | for i in range(-len(instances), len(instances)): 16 | inst = instances[i] 17 | self.assertEqual((inst.attr1 == attr1[i]).all(), True) 18 | self.assertEqual((inst.attr2 == attr2[i]).all(), True) 19 | 20 | self.assertRaises(IndexError, lambda: instances[len(instances)]) 21 | self.assertRaises(IndexError, lambda: instances[-len(instances) - 1]) 22 | 23 | 24 | if __name__ == "__main__": 25 | unittest.main() 26 | -------------------------------------------------------------------------------- /tests/test_checkpoint.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | import unittest 3 | from collections import OrderedDict 4 | import torch 5 | from torch import nn 6 | 7 | from detectron2.checkpoint.c2_model_loading import align_and_update_state_dicts 8 | from detectron2.utils.logger import setup_logger 9 | 10 | 11 | class TestCheckpointer(unittest.TestCase): 12 | def setUp(self): 13 | setup_logger() 14 | 15 | def create_complex_model(self): 16 | m = nn.Module() 17 | m.block1 = nn.Module() 18 | m.block1.layer1 = nn.Linear(2, 3) 19 | m.layer2 = nn.Linear(3, 2) 20 | m.res = nn.Module() 21 | m.res.layer2 = nn.Linear(3, 2) 22 | 23 | state_dict = OrderedDict() 24 | state_dict["layer1.weight"] = torch.rand(3, 2) 25 | state_dict["layer1.bias"] = torch.rand(3) 26 | state_dict["layer2.weight"] = torch.rand(2, 3) 27 | state_dict["layer2.bias"] = torch.rand(2) 28 | state_dict["res.layer2.weight"] = torch.rand(2, 3) 29 | state_dict["res.layer2.bias"] = torch.rand(2) 30 | return m, state_dict 31 | 32 | def test_complex_model_loaded(self): 33 | for add_data_parallel in [False, True]: 34 | model, state_dict = self.create_complex_model() 35 | if add_data_parallel: 36 | model = nn.DataParallel(model) 37 | model_sd = model.state_dict() 38 | 39 | align_and_update_state_dicts(model_sd, state_dict) 40 | for loaded, stored in zip(model_sd.values(), state_dict.values()): 41 | # different tensor references 42 | self.assertFalse(id(loaded) == id(stored)) 43 | # same content 44 | self.assertTrue(loaded.equal(stored)) 45 | 46 | 47 | if __name__ == "__main__": 48 | unittest.main() 49 | -------------------------------------------------------------------------------- /tests/test_model_zoo.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | import logging 3 | import unittest 4 | 5 | from detectron2 import model_zoo 6 | from detectron2.modeling import FPN, GeneralizedRCNN 7 | 8 | logger = logging.getLogger(__name__) 9 | 10 | 11 | class TestModelZoo(unittest.TestCase): 12 | def test_get_returns_model(self): 13 | model = model_zoo.get("Misc/scratch_mask_rcnn_R_50_FPN_3x_gn.yaml", trained=False) 14 | self.assertIsInstance(model, GeneralizedRCNN) 15 | self.assertIsInstance(model.backbone, FPN) 16 | 17 | def test_get_invalid_model(self): 18 | self.assertRaises(RuntimeError, model_zoo.get, "Invalid/config.yaml") 19 | 20 | def test_get_url(self): 21 | url = model_zoo.get_checkpoint_url("Misc/scratch_mask_rcnn_R_50_FPN_3x_gn.yaml") 22 | self.assertEqual( 23 | url, 24 | "https://dl.fbaipublicfiles.com/detectron2/Misc/scratch_mask_rcnn_R_50_FPN_3x_gn/138602908/model_final_01ca85.pkl", # noqa 25 | ) 26 | 27 | 28 | if __name__ == "__main__": 29 | unittest.main() 30 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | 2 | This directory contains a few scripts that use 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 | * `visualize_json_results.py` 26 | 27 | Visualize the json instance detection/segmentation results dumped by `COCOEvalutor` or `LVISEvaluator` 28 | 29 | Usage: 30 | ``` 31 | python visualize_json_results.py --input x.json --output dir/ --dataset coco_2017_val 32 | ``` 33 | If not using a builtin dataset, you'll need your own script or modify this script. 34 | 35 | * `visualize_data.py` 36 | 37 | Visualize ground truth raw annotations or training data (after preprocessing/augmentations). 38 | 39 | Usage: 40 | ``` 41 | python visualize_data.py --config-file config.yaml --source annotation/dataloader --output-dir dir/ [--show] 42 | ``` 43 | 44 | NOTE: the script does not stop by itself when using `--source dataloader` because a training 45 | dataloader is usually infinite. 46 | -------------------------------------------------------------------------------- /tools/convert-torchvision-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 | import torch 7 | 8 | """ 9 | Usage: 10 | # download one of the ResNet{18,34,50,101,152} models from torchvision: 11 | wget https://download.pytorch.org/models/resnet50-19c8e357.pth -O r50.pth 12 | # run the conversion 13 | ./convert-torchvision-to-d2.py r50.pth r50.pkl 14 | 15 | # Then, use r50.pkl with the following changes in config: 16 | 17 | MODEL: 18 | WEIGHTS: "/path/to/r50.pkl" 19 | PIXEL_MEAN: [123.675, 116.280, 103.530] 20 | PIXEL_STD: [58.395, 57.120, 57.375] 21 | RESNETS: 22 | DEPTH: 50 23 | STRIDE_IN_1X1: False 24 | INPUT: 25 | FORMAT: "RGB" 26 | 27 | These models typically produce slightly worse results than the 28 | pre-trained ResNets we use in official configs, which are the 29 | original ResNet models released by MSRA. 30 | """ 31 | 32 | if __name__ == "__main__": 33 | input = sys.argv[1] 34 | 35 | obj = torch.load(input, map_location="cpu") 36 | 37 | newmodel = {} 38 | for k in list(obj.keys()): 39 | old_k = k 40 | if "layer" not in k: 41 | k = "stem." + k 42 | for t in [1, 2, 3, 4]: 43 | k = k.replace("layer{}".format(t), "res{}".format(t + 1)) 44 | for t in [1, 2, 3]: 45 | k = k.replace("bn{}".format(t), "conv{}.norm".format(t)) 46 | k = k.replace("downsample.0", "shortcut") 47 | k = k.replace("downsample.1", "shortcut.norm") 48 | print(old_k, "->", k) 49 | newmodel[k] = obj.pop(old_k).detach().numpy() 50 | 51 | res = {"model": newmodel, "__author__": "torchvision", "matching_heuristics": True} 52 | 53 | with open(sys.argv[2], "wb") as f: 54 | pkl.dump(res, f) 55 | if obj: 56 | print("Unconverted keys:", obj.keys()) 57 | -------------------------------------------------------------------------------- /tools/deploy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | # See https://pytorch.org/tutorials/advanced/cpp_frontend.html 3 | cmake_minimum_required(VERSION 3.0 FATAL_ERROR) 4 | project(caffe2_mask_rcnn) 5 | 6 | find_package(Torch REQUIRED) 7 | find_package(gflags REQUIRED) 8 | find_package(OpenCV REQUIRED) 9 | 10 | add_executable(caffe2_mask_rcnn caffe2_mask_rcnn.cpp) 11 | target_link_libraries( 12 | caffe2_mask_rcnn 13 | "${TORCH_LIBRARIES}" gflags glog ${OpenCV_LIBS}) 14 | set_property(TARGET caffe2_mask_rcnn PROPERTY CXX_STANDARD 14) 15 | 16 | 17 | add_executable(torchscript_traced_mask_rcnn torchscript_traced_mask_rcnn.cpp) 18 | target_link_libraries( 19 | torchscript_traced_mask_rcnn 20 | "${TORCH_LIBRARIES}" ${OpenCV_LIBS}) 21 | set_property(TARGET torchscript_traced_mask_rcnn PROPERTY CXX_STANDARD 14) 22 | -------------------------------------------------------------------------------- /tools/deploy/README.md: -------------------------------------------------------------------------------- 1 | 2 | This directory contains: 3 | 4 | 1. A script that converts a detectron2 model to caffe2 format. 5 | 6 | 2. An example that loads a Mask R-CNN model in caffe2 format and runs inference. 7 | 8 | See [tutorial](https://detectron2.readthedocs.io/tutorials/deployment.html) 9 | for their usage. 10 | --------------------------------------------------------------------------------