├── README.md ├── custom_balloon ├── annotations │ ├── custom_train.json │ └── custom_val.json ├── train2017 │ ├── 10464445726_6f1e3bbe6a_k.jpg │ ├── 12037308314_e16fb3a0f7_k.jpg │ ├── 120853323_d4788431b9_b.jpg │ ├── 12288043903_fe1ea17a4e_k.jpg │ ├── 12288355124_5e340d3de3_k.jpg │ ├── 12288446656_2c6a90e6f5_k.jpg │ ├── 126700562_8e27720147_b.jpg │ ├── 1297451346_5b92bdac08_b.jpg │ ├── 14321263043_b76ef054d3_k.jpg │ ├── 145053828_e0e748717c_b.jpg │ ├── 14666848163_8be8e37562_k.jpg │ ├── 15290896925_884ab33fd3_k.jpg │ ├── 15331928994_d5b82eb368_k.jpg │ ├── 154446334_5d41cd1375_b.jpg │ ├── 155815494_800fc9aa32_b.jpg │ ├── 15717689633_5f7f78c28e_k.jpg │ ├── 16435593892_2aa8118f4a_k.jpg │ ├── 17156759330_5af4f5a5b8_k.jpg │ ├── 17178818589_16e58fc1e5_k.jpg │ ├── 18849792632_aad23ad513_k.jpg │ ├── 2311771643_f46392fcc0_b.jpg │ ├── 2354829160_3f65a6bf6f_b.jpg │ ├── 2385899600_94b68350af_b.jpg │ ├── 24362039530_b151b41a52_k.jpg │ ├── 25899693952_7c8b8b9edc_k.jpg │ ├── 2685563244_b0d5f7eb67_b.jpg │ ├── 2937599387_80e7d6e050_b.jpg │ ├── 321888854_3723b6f10b_b.jpg │ ├── 332344155_71be3a3b22_b.jpg │ ├── 3342804367_f43682bb80_b.jpg │ ├── 34020010494_e5cb88e1c4_k.jpg │ ├── 351678851_e2aeebdafd_b.jpg │ ├── 3646097131_e3e1215843_b.jpg │ ├── 3927754171_9011487133_b.jpg │ ├── 3945575930_ce99a7e98d_b.jpg │ ├── 4057490235_2ffdf7d68b_b.jpg │ ├── 4543126482_92254ef046_b.jpg │ ├── 4552737035_3a0a4105fb_b.jpg │ ├── 485227412_e335662bb5_b.jpg │ ├── 4864857993_edb62f16ef_b.jpg │ ├── 4887227769_acd2e6127d_b.jpg │ ├── 489752654_777853a0ba_b.jpg │ ├── 4955354786_337a598e4a_b.jpg │ ├── 5013250607_26359229b6_b.jpg │ ├── 5178670692_63a4365c9c_b.jpg │ ├── 518678836_94d58e3839_b.jpg │ ├── 5253122239_38b1e7f61c_b.jpg │ ├── 53500107_d24b11b3c2_b.jpg │ ├── 5560377994_cb597a4af5_b.jpg │ ├── 5674044810_2d9e2243ff_b.jpg │ ├── 605521662_a470fef77f_b.jpg │ ├── 6483318883_21facf57cd_b.jpg │ ├── 699765866_abaad7274d_b.jpg │ ├── 7178882742_f090f3ce56_k.jpg │ ├── 7308740338_591f27b631_k.jpg │ ├── 7488015492_0583857ca0_k.jpg │ ├── 8436015314_3a678c1005_k.jpg │ ├── 873768102_7d931e5fa3_b.jpg │ ├── 8758393087_76fcd56bd3_k.jpg │ ├── 9210739293_2b0e0d991e_k.jpg │ ├── 9330497995_4cf0438cb6_k.jpg │ └── custom_train.json └── val2017 │ ├── 14898532020_ba6199dd22_k.jpg │ ├── 16335852991_f55de7958d_k.jpg │ ├── 24631331976_defa3bb61f_k.jpg │ ├── 2917282960_06beee649a_b.jpg │ ├── 3800636873_ace2c2795f_b.jpg │ ├── 3825919971_93fb1ec581_b.jpg │ ├── 410488422_5f8991f26e_b.jpg │ ├── 4581425993_72b9b15fc0_b.jpg │ ├── 4838031651_3e7b5ea5c7_b.jpg │ ├── 5555705118_3390d70abe_b.jpg │ ├── 5603212091_2dfe16ea72_b.jpg │ ├── 6810773040_3d81036d05_k.jpg │ ├── 8053085540_a72bd21a64_k.jpg │ └── custom_val.json ├── object_detection_with_detectron2 ├── README.md ├── configs │ ├── detr_256_6_6_torchvision.yaml │ ├── dyhead_r50_atss_fpn_1x.yaml │ └── dyhead_swint_atss_fpn_2x_ms.yaml ├── inference.py ├── output_images │ ├── detr_output2.png │ ├── dyhead-fpn_output2.png │ ├── dyhead_output1.png │ └── dyhead_output2.png ├── resources │ ├── github.png │ ├── linkedin.png │ └── medium.png ├── training.py └── utils │ ├── __pycache__ │ └── dyhead_trainer.cpython-38.pyc │ └── dyhead_trainer.py └── object_detection_with_hugginggface ├── README.md ├── __MACOSX └── balloon │ ├── train │ ├── ._10464445726_6f1e3bbe6a_k.jpg │ ├── ._12037308314_e16fb3a0f7_k.jpg │ ├── ._120853323_d4788431b9_b.jpg │ ├── ._12288043903_fe1ea17a4e_k.jpg │ ├── ._12288355124_5e340d3de3_k.jpg │ ├── ._12288446656_2c6a90e6f5_k.jpg │ ├── ._126700562_8e27720147_b.jpg │ ├── ._1297451346_5b92bdac08_b.jpg │ ├── ._14321263043_b76ef054d3_k.jpg │ ├── ._145053828_e0e748717c_b.jpg │ ├── ._14666848163_8be8e37562_k.jpg │ ├── ._15290896925_884ab33fd3_k.jpg │ ├── ._15331928994_d5b82eb368_k.jpg │ ├── ._154446334_5d41cd1375_b.jpg │ ├── ._155815494_800fc9aa32_b.jpg │ ├── ._15717689633_5f7f78c28e_k.jpg │ ├── ._16435593892_2aa8118f4a_k.jpg │ ├── ._17156759330_5af4f5a5b8_k.jpg │ ├── ._17178818589_16e58fc1e5_k.jpg │ ├── ._18849792632_aad23ad513_k.jpg │ ├── ._2311771643_f46392fcc0_b.jpg │ ├── ._2354829160_3f65a6bf6f_b.jpg │ ├── ._2385899600_94b68350af_b.jpg │ ├── ._24362039530_b151b41a52_k.jpg │ ├── ._25899693952_7c8b8b9edc_k.jpg │ ├── ._2685563244_b0d5f7eb67_b.jpg │ ├── ._2937599387_80e7d6e050_b.jpg │ ├── ._321888854_3723b6f10b_b.jpg │ ├── ._332344155_71be3a3b22_b.jpg │ ├── ._3342804367_f43682bb80_b.jpg │ ├── ._34020010494_e5cb88e1c4_k.jpg │ ├── ._351678851_e2aeebdafd_b.jpg │ ├── ._3646097131_e3e1215843_b.jpg │ ├── ._3927754171_9011487133_b.jpg │ ├── ._3945575930_ce99a7e98d_b.jpg │ ├── ._4057490235_2ffdf7d68b_b.jpg │ ├── ._4543126482_92254ef046_b.jpg │ ├── ._4552737035_3a0a4105fb_b.jpg │ ├── ._485227412_e335662bb5_b.jpg │ ├── ._4864857993_edb62f16ef_b.jpg │ ├── ._4887227769_acd2e6127d_b.jpg │ ├── ._489752654_777853a0ba_b.jpg │ ├── ._4955354786_337a598e4a_b.jpg │ ├── ._5013250607_26359229b6_b.jpg │ ├── ._5178670692_63a4365c9c_b.jpg │ ├── ._518678836_94d58e3839_b.jpg │ ├── ._5253122239_38b1e7f61c_b.jpg │ ├── ._53500107_d24b11b3c2_b.jpg │ ├── ._5560377994_cb597a4af5_b.jpg │ ├── ._5674044810_2d9e2243ff_b.jpg │ ├── ._605521662_a470fef77f_b.jpg │ ├── ._6483318883_21facf57cd_b.jpg │ ├── ._699765866_abaad7274d_b.jpg │ ├── ._7178882742_f090f3ce56_k.jpg │ ├── ._7308740338_591f27b631_k.jpg │ ├── ._7488015492_0583857ca0_k.jpg │ ├── ._8436015314_3a678c1005_k.jpg │ ├── ._873768102_7d931e5fa3_b.jpg │ ├── ._8758393087_76fcd56bd3_k.jpg │ ├── ._9210739293_2b0e0d991e_k.jpg │ ├── ._9330497995_4cf0438cb6_k.jpg │ └── ._via_region_data.json │ └── val │ ├── ._14898532020_ba6199dd22_k.jpg │ ├── ._16335852991_f55de7958d_k.jpg │ ├── ._24631331976_defa3bb61f_k.jpg │ ├── ._2917282960_06beee649a_b.jpg │ ├── ._3800636873_ace2c2795f_b.jpg │ ├── ._3825919971_93fb1ec581_b.jpg │ ├── ._410488422_5f8991f26e_b.jpg │ ├── ._4581425993_72b9b15fc0_b.jpg │ ├── ._4838031651_3e7b5ea5c7_b.jpg │ ├── ._5555705118_3390d70abe_b.jpg │ ├── ._5603212091_2dfe16ea72_b.jpg │ ├── ._6810773040_3d81036d05_k.jpg │ ├── ._8053085540_a72bd21a64_k.jpg │ └── ._via_region_data.json ├── convert_coco.py ├── inference.py ├── output_images ├── obj-detec-params.png ├── original.jpg ├── output_cond-detr.png ├── output_def-detr.png ├── output_detr.png └── output_yolos.png ├── resources ├── github.png ├── linkedin.png └── medium.png └── training.py /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This project try to use Detectron2 and Huggingface framework to do object detection using transformer based architecture. 3 | 4 | 5 | # Object Detection with Trasformer using Huggingface 6 | 7 | With Huggingface framework, the following transformer based architectures are used 8 | 9 | - DETR(Detection Transformer). 10 | - Conditional DETR 11 | - Deformable DETR. 12 | - YOLOS. 13 | 14 | ## Dependencies 15 | - Install Huggingface by following steps mentioned in [link](https://huggingface.co/docs/transformers/installation). 16 | - pip install pytorch-lightning 17 | 18 | 19 | ## Dataset Preparation 20 | Ballon Dataset is converted to COCO format & present inside custom_balloon folder. 21 | 22 | ## Usage 23 | 24 | 25 | ### Training: 26 | 27 | Currently Huggingface only supports following trasformer based object detection algorithm: 28 | 29 | - DETR 30 | - Conditional DETR 31 | - Deformable DETR 32 | - YOLOS 33 | 34 | Run the below command for training 35 | 36 | - python3.8 training.py --arch [detr|cond-detr|yolos|def-detr] --path model_output/[detr|cond-detr|yolos|def-detr] --epochs 5000 --profile True. 37 | 38 | --path model_output: Use different folder for different architecture. 39 | 40 | ### Profiling 41 | 42 | ![obj-detec-params](https://user-images.githubusercontent.com/22910010/213909576-2b09d2fb-9dcd-4a9f-875f-a8253def6011.png) 43 | 44 | 45 | ### Inference: 46 | 47 | Run the below command 48 | 49 | python3.8 inference.py --model model_out/detr --arch detr/cond-detr/yolos/def-detr 50 | 51 | Evaluation time with different model is as follows: 52 | 53 | - Evaluation Time for arch: detr is 762.916088104248 ms. 54 | - Evaluation Time for arch: yolos is 384.78732109069824 ms. 55 | - Evaluation Time for arch: cond-detr is 776.5250205993652 ms. 56 | - Evaluation Time for arch: def-detr is 2585.845708847046 ms. 57 | 58 | ### Output: 59 | 60 | #### Original Image: 61 | 62 | ![original](https://user-images.githubusercontent.com/22910010/213909599-60b54893-42f0-40a4-b5e7-62a51965f971.jpg) 63 | 64 | 65 | #### DETR Output: 66 | 67 | ![output_detr](https://user-images.githubusercontent.com/22910010/213909671-04981745-273f-4fc0-8547-1d675f2579a9.png) 68 | 69 | 70 | #### Cond-DETR Output: 71 | 72 | ![output_cond-detr](https://user-images.githubusercontent.com/22910010/213909688-40481c83-a1e5-4e11-bca1-40ee79e33fcf.png) 73 | 74 | 75 | #### Deformable DETR Output: 76 | 77 | ![output_def-detr](https://user-images.githubusercontent.com/22910010/213909708-350e173c-460a-4968-8184-56445846b8b2.png) 78 | 79 | 80 | #### YOLOS Output: 81 | 82 | ![output_yolos](https://user-images.githubusercontent.com/22910010/213909737-f50e6476-e230-4df5-9f4e-40cdd4426dbc.png) 83 | 84 | 85 | ## Summary 86 | In the original image, only 7 balloons are present and it was detected correctly with Cond-Detr & Def-Detr. 87 | 88 | Detr model able to predict only 6 balloons & misses 1 prediction.Yolos is able to predict only 5 balloons & 89 | 90 | misses 2 predictions.However,Yolos is the fastest architecture among all,whereas Def-Detr takes longer time 91 | than others.(Note: All the models were trained for 500 epochs). 92 | 93 | So there is a clear trade-off between accuracy & speed.Please check the profiling data mentioned above. 94 | 95 | Accuracy can be improved by finetuning the hyper parameters or with more training. 96 | 97 | But the clear winner in terms of speed is Yolos & in terms of accuracy it's Cond-Detr & Def-Detr. 98 | 99 | # Object Detection with Trasformer Using Detectron2 100 | 101 | ## Dependencies 102 | 1. Install detectron2.[](https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md) (Prefer to use Conda version). 103 | 2. Install DyHead by following the steps present in [DynamicHead](https://github.com/microsoft/DynamicHead). 104 | 105 | You may face some building issue related to CUDA in DynamicHead/dyhead/csrc/cuda/{deform_conv_cuda.cu, SigmoidFocalLoss_cuda.cu}. 106 | Try to Fix them.Otherwise,let me know what is the error you are facing. 107 | 108 | ## Dataset Preparation 109 | Balloon dataset is converted to COCO format & is present inside custom_balloon folder. 110 | 111 | If you want to convert balloon dataset in to coco format & use it in Detectron2.Then, 112 | follow the below steps. 113 | 114 | - Download the balloon dataset from https://github.com/matterport/Mask_RCNN/releases/download/v2.1/balloon_dataset.zip. 115 | - git clone https://github.com/woctezuma/VIA2COCO 116 | - cd VIA2COCO/ 117 | git checkout fixes 118 | - run convert_coco.py 119 | 120 | 121 | ## Usage 122 | 123 | ### Enviornment Setup 124 | - For DyHead: 125 | 1. Download weights(for example, dyhead_r50_atss_fpn_1x.pth) from [DynamicHead](https://github.com/microsoft/DynamicHead) & keep them inside pretrained_model/ 126 | 2. Copy the config files from [](https://github.com/microsoft/DynamicHead/tree/master/configs) & keep them inside configs/ 127 | 128 | - For DETR: 129 | 1. git clone https://github.com/facebookresearch/detr/tree/master/d2. 130 | 2. Keep the converted_model.pth inside pretrained_model/ 131 | Here is the steps to get the converted_model.pth 132 | - python converter.py --source_model https://dl.fbaipublicfiles.com/detr/detr-r50-e632da11.pth --output_model converted_model.pth 133 | 3. Copy the config file https://github.com/facebookresearch/detr/tree/master/d2/configs/detr_256_6_6_torchvision.yaml & keep it inside configs/ 134 | 135 | ### Training 136 | - For DyHead with FPN backbone: 137 | 138 | python3.8 training.py --outdir [where model will be saved] --arch dyhead-fpn --config [file path] --weight [file path] --epochs [no of epochs]. 139 | 140 | For Example, 141 | python3.8 training.py --outdir out_dyhead_fpn/ --arch dyhead-fpn --config configs/dyhead_r50_atss_fpn_1x.yaml --weight pretrained_model/dyhead_r50_atss_fpn_1x.pth --epochs 5000 142 | 143 | - For DyHead with Swin-T transformer backbone: 144 | 145 | python3.8 training.py --outdir [where model will be saved] --arch dyhead-swint --config [file path] --weight [file path] --epochs [no of epochs] 146 | 147 | For Example, 148 | python3.8 training.py --outdir out_dyhead_swint/ --arch dyhead-swint --config configs/dyhead_swint_atss_fpn_2x_ms.yaml --weight pretrained_model/dyhead_swint_atss_fpn_2x_ms.pth --epochs 5000. 149 | 150 | - For DETR: 151 | 152 | python3.8 training.py --outdir [where model will be saved] --arch detr --config [file path] --weight [file path] --epochs [no of epochs]. 153 | 154 | For Example, 155 | python3.8 training.py --outdir out_test/ --arch detr --config configs/detr_256_6_6_torchvision.yaml --weight pretrained_model/converted_model.pth --epochs 5000 156 | 157 | ### Inference: 158 | 159 | - For DyHead with FPN backbone: 160 | 161 | python3.8 inference.py --outdir out_dyhead_fpn/ --arch dyhead-fpn --config configs/dyhead_r50_atss_fpn_1x.yaml --save True. 162 | 163 | Inference Time: 164 | 165 | Evaluation Time : {} ms 108.9015007019043 166 | Evaluation Time : {} ms 103.93381118774414 167 | 168 | ![dyhead_output2](https://user-images.githubusercontent.com/22910010/213909844-eb137c71-5012-4115-aea5-f0ad0b05c1d0.png) 169 | 170 | - For DyHead with Swin-T transformer backbone: 171 | python3.8 inference.py --outdir out_dyhead_swint/ --arch dyhead-swint --config configs/dyhead_swint_atss_fpn_2x_ms.yaml --save True. 172 | 173 | Inference Time: 174 | Evaluation Time : {} ms 157.5005054473877. 175 | Evaluation Time : {} ms 153.02109718322754 176 | 177 | - For DETR: 178 | 179 | python3.8 inference.py --outdir out_detr/ --arch detr --config configs/detr_256_6_6_torchvision.yaml --save True. 180 | 181 | Inference Time: 182 | 183 | Evaluation Time : {} ms 71.02847099304199 184 | Evaluation Time : {} ms 92.53978729248047 185 | 186 | 187 | ![detr_output2](https://user-images.githubusercontent.com/22910010/213909800-cf7d1edc-a395-438e-ad6c-a58895999e80.png) 188 | 189 | 190 | ## Summary: 191 | As you can see from output, DETR is slighly faster than DyHead.However,DETR is not that accurate as DyHead in predicting all the ballons. 192 | 193 | Please check the above output. 194 | 195 | We can try other DyHead configs such as dyhead_swint_atss_fpn_2x_ms.yaml and check the output. 196 | 197 | Here the idea is to demonstrate how to use trasformer based object detection using Detectron2 framework. 198 | Please feel free to share your feedback. 199 | 200 | ## References: 201 | 202 | - https://huggingface.co/docs/transformers/tasks/image_classification. 203 | - https://github.com/NielsRogge/Transformers-Tutorials. 204 | - https://arxiv.org/pdf/2005.12872. 205 | - https://arxiv.org/abs/2010.04159. 206 | - https://arxiv.org/pdf/2108.06152. 207 | - https://arxiv.org/pdf/2106.00666. 208 | - https://arxiv.org/pdf/2106.08322. 209 | - https://arxiv.org/abs/2202.09048. 210 | - https://arxiv.org/abs/2111.14330. 211 | - https://github.com/facebookresearch/detr/tree/master/d2. 212 | - https://github.com/microsoft/DynamicHead. 213 | 214 | --- 215 | Reach me @ 216 | 217 | [LinkedIn](https://www.linkedin.com/in/satya1507/) [GitHub](https://github.com/satya15july) [Medium](https://medium.com/@satya15july_11937) 218 | -------------------------------------------------------------------------------- /custom_balloon/annotations/custom_val.json: -------------------------------------------------------------------------------- 1 | {"info": {"description": "Example Dataset", "url": "https://github.com/waspinator/pycococreator", "version": "0.1.0", "year": 2018, "contributor": "waspinator", "date_created": "2022-11-09 04:25:00.554728"}, "licenses": [{"id": 1, "name": "Attribution-NonCommercial-ShareAlike License", "url": "http://creativecommons.org/licenses/by-nc-sa/2.0/"}], "categories": [{"id": 0, "name": "balloon", "supercategory": "N/A"}], "images": [{"id": 0, "file_name": "24631331976_defa3bb61f_k.jpg", "width": 1323, "height": 2048, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 1, "file_name": "16335852991_f55de7958d_k.jpg", "width": 1536, "height": 2048, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 2, "file_name": "14898532020_ba6199dd22_k.jpg", "width": 2048, "height": 1365, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 3, "file_name": "8053085540_a72bd21a64_k.jpg", "width": 2048, "height": 1595, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 4, "file_name": "6810773040_3d81036d05_k.jpg", "width": 2048, "height": 1536, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 5, "file_name": "5603212091_2dfe16ea72_b.jpg", "width": 768, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 6, "file_name": "5555705118_3390d70abe_b.jpg", "width": 683, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 7, "file_name": "4838031651_3e7b5ea5c7_b.jpg", "width": 1024, "height": 675, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 8, "file_name": "4581425993_72b9b15fc0_b.jpg", "width": 776, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 9, "file_name": "3825919971_93fb1ec581_b.jpg", "width": 683, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 10, "file_name": "3800636873_ace2c2795f_b.jpg", "width": 686, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 11, "file_name": "2917282960_06beee649a_b.jpg", "width": 1024, "height": 681, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 12, "file_name": "410488422_5f8991f26e_b.jpg", "width": 1024, "height": 768, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}], "annotations": [{"id": 0, "image_id": 0, "category_id": 0, "iscrowd": 0, "area": 8010.000000000034, "bbox": [580, 329, 336, 456], "segmentation": [[916, 515, 913, 583, 905, 616, 889, 656, 868, 696, 836, 737, 809, 753, 792, 767, 789, 777, 784, 785, 777, 785, 769, 778, 767, 768, 777, 766, 786, 760, 791, 755, 769, 755, 739, 743, 714, 728, 678, 702, 645, 670, 615, 629, 595, 588, 583, 539, 580, 500, 584, 458, 595, 425, 614, 394, 645, 360, 676, 342, 716, 329, 769, 331, 815, 347, 849, 371, 875, 398, 900, 442, 916, 504, 916, 515]]}, {"id": 1, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 3449.9999999999777, "bbox": [513, 168, 224, 222], "segmentation": [[588, 173, 617, 168, 649, 172, 673, 182, 692, 197, 708, 216, 722, 237, 730, 260, 737, 283, 718, 312, 706, 341, 699, 367, 697, 390, 676, 369, 650, 349, 613, 337, 580, 337, 552, 347, 534, 361, 520, 332, 513, 296, 513, 266, 521, 243, 526, 225, 541, 205, 560, 187, 588, 173]]}, {"id": 2, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 161.99999999998974, "bbox": [731, 213, 179, 86], "segmentation": [[845, 219, 861, 229, 880, 242, 892, 260, 902, 275, 910, 299, 889, 277, 869, 263, 844, 254, 813, 250, 785, 255, 762, 265, 745, 279, 739, 283, 731, 258, 746, 241, 767, 225, 790, 216, 821, 213, 845, 219]]}, {"id": 3, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 1348.5000000000332, "bbox": [698, 250, 233, 239], "segmentation": [[931, 378, 928, 402, 920, 435, 913, 454, 897, 475, 872, 460, 840, 450, 811, 449, 789, 450, 768, 460, 754, 469, 730, 489, 726, 486, 724, 459, 718, 426, 698, 390, 698, 367, 707, 335, 721, 306, 734, 290, 746, 278, 769, 261, 794, 252, 822, 250, 845, 254, 865, 261, 889, 277, 910, 299, 921, 323, 929, 354, 931, 378]]}, {"id": 4, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 896.9999999999895, "bbox": [852, 480, 140, 228], "segmentation": [[927, 486, 946, 498, 968, 516, 989, 553, 992, 593, 985, 630, 975, 649, 957, 668, 937, 686, 913, 700, 889, 707, 862, 707, 852, 708, 876, 691, 897, 675, 910, 656, 925, 635, 933, 610, 939, 587, 939, 562, 935, 538, 927, 512, 910, 492, 900, 480, 927, 486]]}, {"id": 5, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 4515.000000000053, "bbox": [690, 449, 249, 289], "segmentation": [[704, 664, 692, 631, 690, 604, 691, 580, 699, 545, 711, 521, 723, 498, 742, 480, 766, 461, 785, 452, 807, 449, 839, 449, 865, 457, 887, 469, 904, 484, 923, 506, 933, 532, 939, 565, 939, 584, 931, 620, 920, 643, 905, 662, 885, 682, 861, 701, 839, 713, 808, 719, 786, 723, 769, 728, 754, 733, 748, 731, 746, 738, 738, 737, 738, 729, 729, 720, 722, 708, 718, 690, 704, 664]]}, {"id": 6, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 3256.0000000000296, "bbox": [490, 338, 234, 287], "segmentation": [[526, 551, 509, 526, 497, 498, 493, 470, 490, 444, 493, 422, 501, 398, 512, 381, 526, 365, 546, 351, 573, 340, 603, 338, 626, 340, 662, 357, 688, 381, 709, 408, 721, 438, 724, 466, 724, 493, 719, 504, 704, 531, 694, 568, 691, 584, 691, 604, 682, 609, 683, 612, 687, 610, 688, 617, 684, 625, 682, 625, 679, 619, 676, 616, 664, 620, 648, 619, 620, 609, 587, 599, 564, 585, 548, 573, 526, 551]]}, {"id": 7, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 721.4999999999667, "bbox": [563, 596, 202, 176], "segmentation": [[594, 735, 579, 712, 567, 691, 563, 659, 564, 631, 568, 612, 579, 596, 605, 605, 631, 613, 656, 621, 671, 618, 676, 616, 682, 625, 684, 625, 687, 616, 687, 612, 684, 612, 684, 608, 691, 605, 691, 619, 694, 637, 702, 656, 711, 678, 719, 692, 722, 706, 729, 719, 737, 727, 738, 737, 746, 739, 749, 731, 756, 734, 765, 730, 757, 741, 728, 762, 714, 766, 683, 772, 654, 769, 623, 757, 594, 735]]}, {"id": 8, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 1096.4999999999554, "bbox": [615, 69, 223, 293], "segmentation": [[704, 71, 723, 69, 739, 70, 758, 76, 773, 82, 787, 91, 796, 101, 815, 121, 827, 143, 833, 168, 838, 196, 834, 228, 828, 252, 813, 278, 797, 301, 784, 319, 767, 332, 749, 343, 733, 347, 718, 351, 718, 355, 721, 359, 716, 362, 706, 354, 709, 354, 711, 352, 712, 351, 700, 349, 689, 342, 676, 330, 660, 313, 647, 295, 638, 278, 630, 259, 623, 239, 618, 217, 615, 191, 616, 170, 620, 150, 626, 131, 639, 109, 654, 95, 669, 84, 694, 73, 704, 71]]}, {"id": 9, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 294.0000000000021, "bbox": [574, 311, 60, 40], "segmentation": [[603, 311, 614, 313, 626, 319, 634, 327, 621, 329, 608, 332, 597, 336, 586, 340, 577, 347, 574, 351, 574, 341, 576, 333, 580, 325, 586, 319, 595, 313, 603, 311]]}, {"id": 10, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 173.9999999999973, "bbox": [517, 357, 45, 64], "segmentation": [[552, 371, 545, 382, 540, 394, 535, 409, 531, 421, 521, 411, 517, 398, 517, 385, 524, 370, 532, 360, 549, 357, 559, 358, 562, 360, 552, 371]]}, {"id": 11, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 2437.5000000000477, "bbox": [528, 329, 226, 282], "segmentation": [[741, 398, 750, 423, 754, 448, 754, 473, 748, 499, 741, 518, 725, 546, 707, 568, 693, 581, 678, 593, 659, 599, 660, 602, 664, 604, 664, 606, 652, 611, 651, 607, 652, 603, 654, 601, 653, 599, 640, 597, 626, 592, 609, 583, 589, 568, 569, 549, 552, 527, 540, 502, 533, 479, 528, 452, 529, 435, 532, 414, 541, 390, 554, 370, 568, 355, 591, 338, 621, 329, 647, 330, 671, 335, 690, 345, 711, 358, 727, 375, 741, 398]]}, {"id": 12, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 1151.999999999996, "bbox": [126, 419, 77, 80], "segmentation": [[197, 437, 203, 457, 200, 471, 194, 482, 184, 491, 169, 499, 156, 496, 144, 488, 134, 478, 128, 466, 126, 452, 130, 438, 138, 429, 147, 422, 162, 419, 177, 420, 188, 428, 197, 437]]}, {"id": 13, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 364.4999999999953, "bbox": [21, 541, 52, 63], "segmentation": [[69, 583, 62, 593, 53, 602, 42, 602, 38, 601, 36, 596, 33, 596, 33, 604, 21, 597, 24, 592, 28, 589, 30, 584, 30, 570, 28, 565, 30, 562, 26, 560, 23, 556, 23, 552, 21, 550, 22, 545, 27, 543, 38, 541, 48, 542, 55, 545, 60, 550, 66, 559, 70, 565, 73, 571, 69, 583]]}, {"id": 14, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 566.9999999999978, "bbox": [1963, 459, 55, 59], "segmentation": [[1997, 459, 2009, 462, 2016, 469, 2018, 488, 2015, 499, 2002, 512, 1989, 516, 1985, 516, 1984, 518, 1982, 517, 1982, 514, 1975, 511, 1969, 505, 1964, 494, 1963, 487, 1966, 475, 1972, 468, 1980, 463, 1989, 459, 1997, 459]]}, {"id": 15, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 47.49999999999685, "bbox": [1917, 465, 47, 53], "segmentation": [[1933, 466, 1941, 465, 1946, 465, 1957, 471, 1960, 479, 1964, 486, 1961, 496, 1956, 508, 1945, 515, 1945, 517, 1943, 518, 1942, 515, 1933, 514, 1924, 507, 1920, 500, 1918, 494, 1917, 487, 1920, 480, 1923, 474, 1925, 470, 1933, 466]]}, {"id": 16, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 569.999999999975, "bbox": [743, 1, 159, 71], "segmentation": [[878, 31, 858, 47, 843, 56, 830, 60, 816, 60, 820, 65, 819, 70, 818, 72, 808, 72, 804, 70, 804, 64, 807, 58, 798, 55, 778, 41, 765, 28, 752, 15, 743, 1, 902, 1, 895, 11, 887, 21, 878, 31]]}, {"id": 17, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 1305.0000000000043, "bbox": [906, 63, 118, 117], "segmentation": [[981, 66, 998, 74, 1008, 84, 1016, 97, 1023, 113, 1024, 133, 1023, 147, 1019, 158, 1014, 168, 1008, 177, 997, 169, 984, 165, 977, 163, 969, 163, 963, 164, 950, 167, 943, 170, 937, 174, 929, 180, 918, 168, 911, 154, 907, 138, 906, 124, 909, 107, 917, 90, 928, 76, 938, 70, 950, 66, 963, 63, 972, 63, 981, 66]]}, {"id": 18, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 719.9999999999976, "bbox": [990, 181, 110, 123], "segmentation": [[1085, 197, 1095, 212, 1098, 221, 1100, 233, 1100, 249, 1093, 266, 1083, 281, 1073, 290, 1055, 299, 1037, 304, 1019, 302, 1011, 300, 1002, 297, 998, 296, 995, 295, 991, 295, 990, 293, 993, 292, 994, 292, 994, 289, 1003, 283, 1010, 274, 1017, 261, 1023, 250, 1028, 229, 1028, 215, 1025, 198, 1019, 189, 1024, 185, 1035, 182, 1049, 181, 1061, 183, 1073, 188, 1085, 197]]}, {"id": 19, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 262.4999999999958, "bbox": [910, 163, 119, 142], "segmentation": [[917, 259, 914, 249, 911, 234, 910, 220, 913, 205, 919, 194, 926, 185, 934, 176, 946, 169, 958, 165, 973, 163, 987, 166, 999, 170, 1012, 182, 1023, 194, 1029, 215, 1027, 234, 1023, 248, 1015, 264, 1007, 277, 996, 287, 986, 293, 974, 297, 968, 299, 962, 299, 960, 302, 957, 305, 954, 304, 952, 301, 953, 298, 948, 294, 939, 288, 932, 283, 927, 278, 923, 272, 920, 266, 917, 259]]}, {"id": 20, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 255.99999999998542, "bbox": [824, 157, 104, 110], "segmentation": [[838, 175, 849, 167, 862, 159, 874, 157, 888, 157, 901, 161, 909, 163, 916, 168, 921, 172, 927, 178, 928, 180, 928, 182, 922, 189, 912, 205, 910, 223, 913, 242, 917, 258, 920, 266, 919, 267, 907, 256, 894, 245, 883, 241, 872, 239, 861, 239, 847, 245, 841, 252, 839, 254, 832, 245, 827, 234, 824, 218, 825, 205, 829, 191, 833, 183, 838, 175]]}, {"id": 21, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 1687.499999999997, "bbox": [924, 280, 86, 93], "segmentation": [[994, 352, 984, 363, 969, 372, 954, 373, 943, 373, 932, 370, 924, 366, 932, 361, 938, 356, 941, 350, 945, 349, 949, 351, 950, 347, 950, 343, 949, 342, 947, 344, 944, 344, 946, 334, 945, 318, 941, 303, 938, 295, 931, 284, 930, 280, 940, 290, 948, 294, 953, 298, 952, 301, 954, 305, 957, 304, 962, 300, 969, 299, 980, 295, 986, 292, 992, 288, 994, 290, 994, 292, 990, 293, 990, 295, 995, 296, 997, 296, 1006, 298, 1009, 305, 1010, 319, 1008, 329, 1006, 338, 1000, 347, 994, 352]]}, {"id": 22, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 1785.0000000000593, "bbox": [796, 239, 155, 135], "segmentation": [[900, 373, 879, 374, 857, 371, 842, 366, 821, 358, 806, 343, 797, 327, 796, 314, 799, 307, 803, 297, 808, 291, 815, 284, 825, 277, 827, 276, 829, 270, 833, 261, 838, 253, 847, 246, 861, 240, 870, 239, 885, 242, 895, 247, 909, 257, 919, 266, 925, 275, 933, 287, 941, 302, 945, 317, 946, 329, 946, 339, 944, 344, 948, 344, 949, 343, 951, 343, 951, 347, 950, 350, 949, 351, 946, 350, 944, 349, 937, 355, 929, 362, 921, 368, 908, 372, 900, 373]]}, {"id": 23, "image_id": 4, "category_id": 0, "iscrowd": 0, "area": 179.999999999999, "bbox": [1738, 527, 40, 41], "segmentation": [[1761, 527, 1771, 532, 1777, 538, 1778, 549, 1776, 558, 1772, 564, 1764, 568, 1750, 567, 1743, 559, 1739, 551, 1738, 542, 1743, 534, 1749, 529, 1761, 527]]}, {"id": 24, "image_id": 4, "category_id": 0, "iscrowd": 0, "area": 509.9999999999995, "bbox": [1414, 588, 53, 51], "segmentation": [[1455, 633, 1442, 639, 1430, 638, 1420, 633, 1414, 626, 1414, 612, 1418, 598, 1429, 591, 1442, 588, 1452, 589, 1461, 595, 1467, 610, 1466, 624, 1455, 633]]}, {"id": 25, "image_id": 4, "category_id": 0, "iscrowd": 0, "area": 337.99999999999847, "bbox": [964, 608, 59, 60], "segmentation": [[1011, 614, 1019, 623, 1023, 634, 1023, 647, 1015, 660, 1008, 668, 992, 668, 982, 666, 972, 658, 964, 645, 964, 625, 972, 614, 984, 608, 1004, 609, 1011, 614]]}, {"id": 26, "image_id": 4, "category_id": 0, "iscrowd": 0, "area": 693.0000000000015, "bbox": [260, 654, 59, 58], "segmentation": [[300, 655, 312, 664, 317, 676, 319, 690, 314, 700, 306, 709, 296, 712, 283, 712, 276, 710, 268, 701, 263, 693, 260, 680, 263, 670, 270, 660, 285, 654, 300, 655]]}, {"id": 27, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 6767.999999999958, "bbox": [269, 75, 284, 372], "segmentation": [[387, 77, 425, 75, 461, 83, 498, 108, 530, 143, 543, 175, 553, 208, 550, 254, 540, 294, 522, 326, 503, 359, 500, 362, 476, 374, 449, 392, 434, 411, 425, 424, 408, 430, 405, 439, 405, 444, 400, 447, 389, 442, 387, 436, 391, 433, 398, 432, 398, 428, 381, 425, 359, 413, 334, 385, 313, 360, 294, 327, 281, 294, 271, 260, 269, 212, 283, 163, 307, 124, 334, 102, 359, 86, 387, 77]]}, {"id": 28, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 2437.4999999999873, "bbox": [503, 225, 222, 229], "segmentation": [[645, 233, 660, 239, 695, 266, 712, 297, 724, 331, 725, 370, 718, 400, 708, 423, 694, 447, 689, 454, 674, 426, 659, 408, 638, 383, 614, 369, 589, 358, 563, 353, 532, 353, 503, 360, 517, 338, 534, 308, 545, 280, 548, 258, 551, 241, 576, 232, 608, 225, 631, 229, 645, 233]]}, {"id": 29, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 4312.9999999999145, "bbox": [401, 353, 293, 345], "segmentation": [[693, 480, 694, 512, 688, 547, 668, 593, 656, 612, 639, 628, 622, 645, 605, 656, 578, 672, 558, 679, 533, 688, 515, 691, 503, 690, 503, 695, 497, 698, 490, 692, 487, 685, 472, 673, 449, 649, 436, 631, 422, 609, 413, 588, 402, 551, 401, 522, 403, 493, 411, 455, 420, 435, 436, 409, 453, 390, 470, 379, 487, 369, 506, 359, 539, 353, 568, 355, 598, 361, 627, 375, 651, 397, 673, 426, 687, 456, 693, 480]]}, {"id": 30, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 5534.999999999963, "bbox": [138, 450, 277, 349], "segmentation": [[142, 631, 138, 593, 141, 560, 147, 540, 161, 513, 175, 495, 192, 480, 210, 465, 237, 455, 260, 450, 293, 450, 321, 454, 342, 469, 360, 480, 378, 497, 388, 513, 397, 527, 402, 537, 403, 557, 408, 573, 413, 588, 415, 609, 411, 637, 400, 669, 388, 694, 370, 724, 359, 744, 347, 764, 331, 780, 317, 787, 322, 790, 323, 791, 319, 796, 314, 799, 310, 798, 308, 792, 295, 792, 280, 788, 263, 778, 247, 769, 230, 758, 206, 736, 186, 717, 169, 694, 156, 672, 147, 647, 142, 631]]}, {"id": 31, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 6288.000000000001, "bbox": [307, 369, 118, 134], "segmentation": [[322, 447, 307, 429, 313, 410, 318, 389, 321, 369, 335, 385, 349, 403, 365, 417, 387, 427, 399, 428, 400, 433, 392, 432, 388, 436, 389, 443, 399, 448, 406, 446, 405, 439, 409, 431, 425, 425, 416, 444, 411, 456, 409, 468, 404, 487, 403, 495, 392, 496, 386, 496, 386, 503, 381, 500, 378, 494, 378, 492, 371, 490, 353, 476, 332, 460, 322, 447]]}, {"id": 32, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 2490.000000000036, "bbox": [67, 224, 254, 285], "segmentation": [[96, 270, 110, 254, 137, 235, 163, 227, 187, 224, 209, 225, 231, 231, 253, 243, 270, 255, 275, 277, 287, 309, 299, 337, 312, 359, 321, 370, 315, 403, 305, 433, 295, 450, 258, 450, 227, 458, 205, 468, 184, 486, 169, 503, 164, 509, 146, 497, 126, 478, 105, 456, 86, 426, 74, 395, 67, 363, 72, 320, 82, 291, 96, 270]]}, {"id": 33, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 39.99999999999972, "bbox": [31, 400, 35, 47], "segmentation": [[66, 425, 62, 433, 58, 440, 52, 444, 50, 445, 50, 446, 48, 447, 47, 447, 47, 446, 44, 445, 40, 442, 34, 434, 32, 425, 31, 414, 34, 407, 40, 403, 44, 400, 50, 400, 58, 402, 64, 409, 66, 416, 66, 425]]}, {"id": 34, "image_id": 6, "category_id": 0, "iscrowd": 0, "area": 3264.000000000039, "bbox": [247, 32, 289, 350], "segmentation": [[287, 86, 307, 64, 329, 50, 357, 37, 379, 36, 408, 32, 437, 40, 467, 50, 494, 76, 517, 100, 530, 136, 535, 165, 536, 196, 531, 236, 516, 274, 497, 301, 463, 338, 433, 356, 402, 372, 378, 375, 366, 375, 370, 382, 357, 380, 351, 375, 357, 372, 345, 368, 319, 357, 287, 322, 267, 280, 249, 224, 247, 181, 255, 141, 266, 111, 287, 86]]}, {"id": 35, "image_id": 7, "category_id": 0, "iscrowd": 0, "area": 892.9999999999847, "bbox": [277, 92, 129, 174], "segmentation": [[305, 106, 324, 97, 345, 92, 364, 97, 380, 106, 395, 121, 403, 143, 406, 165, 402, 196, 386, 221, 371, 242, 352, 258, 333, 266, 316, 258, 302, 242, 289, 220, 281, 196, 277, 173, 282, 145, 292, 121, 305, 106]]}, {"id": 36, "image_id": 7, "category_id": 0, "iscrowd": 0, "area": 152.99999999999997, "bbox": [701, 468, 11, 23], "segmentation": [[701, 480, 702, 473, 705, 469, 706, 468, 707, 469, 710, 469, 712, 469, 712, 470, 711, 473, 710, 477, 710, 481, 709, 486, 709, 488, 708, 488, 707, 490, 707, 491, 705, 491, 703, 488, 702, 485, 701, 480]]}, {"id": 37, "image_id": 7, "category_id": 0, "iscrowd": 0, "area": 15.00000000000006, "bbox": [737, 342, 10, 12], "segmentation": [[741, 342, 743, 342, 745, 343, 746, 344, 746, 347, 747, 349, 746, 350, 745, 351, 745, 354, 743, 354, 741, 354, 740, 352, 738, 349, 737, 347, 738, 345, 738, 343, 741, 342]]}, {"id": 38, "image_id": 8, "category_id": 0, "iscrowd": 0, "area": 513.4999999999991, "bbox": [345, 16, 141, 102], "segmentation": [[479, 64, 468, 81, 453, 97, 432, 110, 407, 114, 406, 118, 397, 116, 379, 107, 360, 83, 349, 59, 345, 35, 350, 16, 484, 16, 486, 37, 479, 64]]}, {"id": 39, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 1681.0000000000086, "bbox": [206, 153, 141, 176], "segmentation": [[260, 154, 277, 153, 291, 157, 302, 161, 316, 172, 327, 182, 337, 199, 344, 220, 347, 235, 347, 246, 345, 256, 342, 268, 337, 280, 329, 293, 324, 298, 319, 305, 316, 310, 314, 314, 310, 320, 304, 323, 302, 324, 300, 327, 299, 329, 296, 329, 294, 327, 285, 326, 282, 311, 276, 297, 268, 284, 255, 270, 244, 261, 231, 254, 217, 249, 207, 247, 206, 234, 206, 218, 208, 204, 214, 189, 221, 178, 230, 167, 240, 160, 250, 157, 260, 154]]}, {"id": 40, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 28.000000000140872, "bbox": [137, 247, 149, 176], "segmentation": [[159, 261, 170, 255, 179, 250, 189, 248, 198, 247, 205, 247, 213, 248, 221, 250, 228, 253, 238, 258, 247, 263, 260, 275, 265, 280, 272, 290, 277, 298, 280, 307, 284, 316, 285, 324, 286, 335, 286, 355, 283, 370, 282, 378, 282, 387, 282, 397, 281, 404, 279, 408, 274, 414, 274, 415, 274, 416, 276, 417, 278, 419, 278, 422, 275, 423, 271, 423, 268, 422, 268, 420, 268, 418, 265, 419, 261, 420, 256, 419, 252, 419, 242, 413, 232, 408, 220, 404, 210, 402, 203, 400, 190, 394, 177, 384, 161, 371, 152, 359, 143, 340, 137, 319, 138, 302, 139, 293, 145, 279, 149, 271, 155, 263, 159, 261]]}, {"id": 41, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 69.99999999999129, "bbox": [308, 343, 135, 145], "segmentation": [[357, 345, 364, 344, 376, 343, 387, 344, 400, 347, 415, 355, 428, 367, 434, 378, 441, 391, 443, 408, 443, 424, 440, 440, 433, 455, 424, 466, 412, 477, 396, 485, 380, 488, 368, 488, 358, 487, 347, 483, 333, 474, 319, 456, 309, 432, 308, 410, 308, 400, 317, 377, 325, 365, 337, 355, 347, 349, 357, 345]]}, {"id": 42, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 0.0, "bbox": [203, 327, 107, 119], "segmentation": [[305, 354, 307, 363, 309, 372, 310, 379, 309, 386, 309, 392, 307, 401, 303, 412, 300, 420, 292, 430, 286, 437, 279, 442, 268, 444, 258, 446, 246, 446, 236, 445, 227, 443, 219, 439, 216, 425, 211, 414, 205, 404, 203, 399, 214, 403, 226, 406, 239, 411, 249, 416, 257, 419, 263, 419, 267, 418, 267, 421, 270, 422, 273, 423, 278, 422, 279, 420, 277, 418, 275, 416, 274, 414, 279, 408, 282, 399, 283, 388, 283, 379, 284, 363, 286, 348, 287, 337, 286, 331, 286, 327, 288, 327, 294, 334, 301, 347, 305, 354]]}, {"id": 43, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 368.999999999989, "bbox": [56, 360, 166, 152], "segmentation": [[72, 384, 78, 378, 88, 371, 99, 366, 109, 361, 120, 360, 132, 360, 145, 362, 157, 366, 162, 371, 169, 378, 181, 386, 191, 394, 203, 400, 209, 412, 215, 424, 219, 441, 219, 453, 219, 465, 220, 473, 222, 478, 221, 484, 219, 489, 220, 494, 219, 496, 216, 497, 213, 498, 208, 502, 202, 504, 192, 505, 189, 505, 168, 511, 152, 512, 134, 512, 113, 506, 91, 494, 76, 478, 65, 463, 57, 440, 56, 421, 60, 403, 65, 392, 72, 384]]}, {"id": 44, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 840.000000000009, "bbox": [153, 440, 135, 132], "segmentation": [[260, 559, 246, 567, 232, 572, 218, 572, 210, 572, 198, 569, 188, 565, 176, 556, 168, 547, 162, 540, 158, 527, 155, 520, 153, 513, 169, 512, 180, 509, 188, 507, 198, 506, 208, 503, 213, 498, 220, 496, 220, 494, 220, 489, 222, 481, 221, 475, 219, 468, 219, 462, 220, 451, 219, 440, 227, 443, 246, 447, 255, 447, 265, 455, 273, 466, 280, 477, 285, 493, 288, 507, 287, 517, 283, 530, 279, 538, 272, 548, 268, 554, 260, 559]]}, {"id": 45, "image_id": 10, "category_id": 0, "iscrowd": 0, "area": 1966.49999999999, "bbox": [337, 84, 161, 161], "segmentation": [[339, 147, 348, 123, 363, 106, 379, 93, 401, 86, 425, 84, 452, 92, 477, 111, 494, 139, 498, 171, 488, 202, 470, 223, 445, 239, 413, 244, 388, 242, 373, 245, 369, 232, 353, 214, 343, 193, 337, 170, 339, 147]]}, {"id": 46, "image_id": 11, "category_id": 0, "iscrowd": 0, "area": 0.0, "bbox": [474, 248, 121, 128], "segmentation": [[585, 278, 589, 288, 593, 298, 595, 311, 594, 324, 590, 338, 584, 348, 576, 360, 569, 366, 563, 369, 563, 371, 567, 371, 569, 371, 568, 376, 567, 376, 566, 375, 565, 374, 561, 373, 559, 372, 552, 373, 543, 374, 534, 373, 524, 371, 508, 366, 496, 356, 486, 344, 478, 329, 474, 311, 476, 297, 478, 287, 485, 276, 490, 268, 501, 259, 507, 255, 518, 251, 530, 248, 541, 249, 550, 251, 556, 253, 563, 256, 551, 270, 544, 275, 532, 281, 525, 286, 522, 288, 521, 289, 520, 291, 522, 293, 526, 293, 535, 288, 538, 289, 538, 291, 538, 294, 533, 303, 530, 311, 530, 313, 531, 315, 533, 315, 535, 314, 535, 311, 537, 308, 539, 305, 542, 303, 543, 303, 542, 307, 542, 312, 541, 316, 542, 318, 544, 318, 546, 318, 547, 314, 548, 310, 550, 305, 549, 314, 548, 321, 548, 324, 551, 324, 552, 324, 554, 322, 554, 319, 554, 316, 555, 313, 556, 309, 556, 304, 558, 307, 558, 313, 559, 317, 561, 318, 563, 318, 563, 315, 563, 309, 562, 301, 563, 294, 565, 287, 566, 282, 570, 275, 573, 272, 577, 268, 582, 273, 585, 278]]}, {"id": 47, "image_id": 12, "category_id": 0, "iscrowd": 0, "area": 2749.9999999999563, "bbox": [144, 10, 235, 234], "segmentation": [[371, 166, 355, 192, 330, 217, 298, 236, 267, 244, 236, 242, 196, 227, 163, 191, 149, 158, 144, 122, 155, 83, 173, 53, 200, 32, 231, 16, 268, 10, 307, 13, 350, 25, 366, 40, 361, 60, 362, 84, 363, 111, 369, 134, 379, 145, 371, 166]]}, {"id": 48, "image_id": 12, "category_id": 0, "iscrowd": 0, "area": 6299.9999999999645, "bbox": [362, 0, 205, 226], "segmentation": [[453, 211, 417, 191, 393, 166, 382, 149, 371, 133, 364, 111, 362, 86, 363, 65, 364, 51, 368, 40, 381, 21, 394, 5, 399, 1, 524, 0, 548, 24, 559, 55, 567, 83, 565, 113, 557, 151, 545, 179, 528, 198, 514, 209, 514, 215, 522, 219, 522, 221, 515, 224, 509, 226, 507, 221, 507, 212, 489, 218, 466, 215, 453, 211]]}, {"id": 49, "image_id": 12, "category_id": 0, "iscrowd": 0, "area": 5400.000000000031, "bbox": [671, 1, 243, 253], "segmentation": [[705, 196, 684, 162, 672, 122, 671, 80, 683, 43, 702, 15, 716, 2, 878, 1, 893, 19, 906, 44, 914, 78, 913, 117, 907, 147, 895, 169, 870, 197, 844, 221, 809, 240, 787, 244, 784, 250, 786, 254, 782, 254, 779, 248, 774, 242, 754, 238, 734, 228, 718, 211, 705, 196]]}]} -------------------------------------------------------------------------------- /custom_balloon/train2017/10464445726_6f1e3bbe6a_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/10464445726_6f1e3bbe6a_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/12037308314_e16fb3a0f7_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/12037308314_e16fb3a0f7_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/120853323_d4788431b9_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/120853323_d4788431b9_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/12288043903_fe1ea17a4e_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/12288043903_fe1ea17a4e_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/12288355124_5e340d3de3_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/12288355124_5e340d3de3_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/12288446656_2c6a90e6f5_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/12288446656_2c6a90e6f5_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/126700562_8e27720147_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/126700562_8e27720147_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/1297451346_5b92bdac08_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/1297451346_5b92bdac08_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/14321263043_b76ef054d3_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/14321263043_b76ef054d3_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/145053828_e0e748717c_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/145053828_e0e748717c_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/14666848163_8be8e37562_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/14666848163_8be8e37562_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/15290896925_884ab33fd3_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/15290896925_884ab33fd3_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/15331928994_d5b82eb368_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/15331928994_d5b82eb368_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/154446334_5d41cd1375_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/154446334_5d41cd1375_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/155815494_800fc9aa32_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/155815494_800fc9aa32_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/15717689633_5f7f78c28e_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/15717689633_5f7f78c28e_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/16435593892_2aa8118f4a_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/16435593892_2aa8118f4a_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/17156759330_5af4f5a5b8_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/17156759330_5af4f5a5b8_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/17178818589_16e58fc1e5_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/17178818589_16e58fc1e5_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/18849792632_aad23ad513_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/18849792632_aad23ad513_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/2311771643_f46392fcc0_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/2311771643_f46392fcc0_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/2354829160_3f65a6bf6f_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/2354829160_3f65a6bf6f_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/2385899600_94b68350af_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/2385899600_94b68350af_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/24362039530_b151b41a52_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/24362039530_b151b41a52_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/25899693952_7c8b8b9edc_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/25899693952_7c8b8b9edc_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/2685563244_b0d5f7eb67_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/2685563244_b0d5f7eb67_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/2937599387_80e7d6e050_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/2937599387_80e7d6e050_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/321888854_3723b6f10b_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/321888854_3723b6f10b_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/332344155_71be3a3b22_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/332344155_71be3a3b22_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/3342804367_f43682bb80_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/3342804367_f43682bb80_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/34020010494_e5cb88e1c4_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/34020010494_e5cb88e1c4_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/351678851_e2aeebdafd_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/351678851_e2aeebdafd_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/3646097131_e3e1215843_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/3646097131_e3e1215843_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/3927754171_9011487133_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/3927754171_9011487133_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/3945575930_ce99a7e98d_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/3945575930_ce99a7e98d_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/4057490235_2ffdf7d68b_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/4057490235_2ffdf7d68b_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/4543126482_92254ef046_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/4543126482_92254ef046_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/4552737035_3a0a4105fb_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/4552737035_3a0a4105fb_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/485227412_e335662bb5_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/485227412_e335662bb5_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/4864857993_edb62f16ef_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/4864857993_edb62f16ef_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/4887227769_acd2e6127d_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/4887227769_acd2e6127d_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/489752654_777853a0ba_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/489752654_777853a0ba_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/4955354786_337a598e4a_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/4955354786_337a598e4a_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/5013250607_26359229b6_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/5013250607_26359229b6_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/5178670692_63a4365c9c_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/5178670692_63a4365c9c_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/518678836_94d58e3839_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/518678836_94d58e3839_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/5253122239_38b1e7f61c_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/5253122239_38b1e7f61c_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/53500107_d24b11b3c2_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/53500107_d24b11b3c2_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/5560377994_cb597a4af5_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/5560377994_cb597a4af5_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/5674044810_2d9e2243ff_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/5674044810_2d9e2243ff_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/605521662_a470fef77f_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/605521662_a470fef77f_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/6483318883_21facf57cd_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/6483318883_21facf57cd_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/699765866_abaad7274d_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/699765866_abaad7274d_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/7178882742_f090f3ce56_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/7178882742_f090f3ce56_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/7308740338_591f27b631_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/7308740338_591f27b631_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/7488015492_0583857ca0_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/7488015492_0583857ca0_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/8436015314_3a678c1005_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/8436015314_3a678c1005_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/873768102_7d931e5fa3_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/873768102_7d931e5fa3_b.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/8758393087_76fcd56bd3_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/8758393087_76fcd56bd3_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/9210739293_2b0e0d991e_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/9210739293_2b0e0d991e_k.jpg -------------------------------------------------------------------------------- /custom_balloon/train2017/9330497995_4cf0438cb6_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/train2017/9330497995_4cf0438cb6_k.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/14898532020_ba6199dd22_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/14898532020_ba6199dd22_k.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/16335852991_f55de7958d_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/16335852991_f55de7958d_k.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/24631331976_defa3bb61f_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/24631331976_defa3bb61f_k.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/2917282960_06beee649a_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/2917282960_06beee649a_b.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/3800636873_ace2c2795f_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/3800636873_ace2c2795f_b.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/3825919971_93fb1ec581_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/3825919971_93fb1ec581_b.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/410488422_5f8991f26e_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/410488422_5f8991f26e_b.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/4581425993_72b9b15fc0_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/4581425993_72b9b15fc0_b.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/4838031651_3e7b5ea5c7_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/4838031651_3e7b5ea5c7_b.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/5555705118_3390d70abe_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/5555705118_3390d70abe_b.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/5603212091_2dfe16ea72_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/5603212091_2dfe16ea72_b.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/6810773040_3d81036d05_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/6810773040_3d81036d05_k.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/8053085540_a72bd21a64_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/custom_balloon/val2017/8053085540_a72bd21a64_k.jpg -------------------------------------------------------------------------------- /custom_balloon/val2017/custom_val.json: -------------------------------------------------------------------------------- 1 | {"info": {"description": "Example Dataset", "url": "https://github.com/waspinator/pycococreator", "version": "0.1.0", "year": 2018, "contributor": "waspinator", "date_created": "2022-11-09 04:25:00.554728"}, "licenses": [{"id": 1, "name": "Attribution-NonCommercial-ShareAlike License", "url": "http://creativecommons.org/licenses/by-nc-sa/2.0/"}], "categories": [{"id": 0, "name": "balloon", "supercategory": "N/A"}], "images": [{"id": 0, "file_name": "24631331976_defa3bb61f_k.jpg", "width": 1323, "height": 2048, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 1, "file_name": "16335852991_f55de7958d_k.jpg", "width": 1536, "height": 2048, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 2, "file_name": "14898532020_ba6199dd22_k.jpg", "width": 2048, "height": 1365, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 3, "file_name": "8053085540_a72bd21a64_k.jpg", "width": 2048, "height": 1595, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 4, "file_name": "6810773040_3d81036d05_k.jpg", "width": 2048, "height": 1536, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 5, "file_name": "5603212091_2dfe16ea72_b.jpg", "width": 768, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 6, "file_name": "5555705118_3390d70abe_b.jpg", "width": 683, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 7, "file_name": "4838031651_3e7b5ea5c7_b.jpg", "width": 1024, "height": 675, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 8, "file_name": "4581425993_72b9b15fc0_b.jpg", "width": 776, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 9, "file_name": "3825919971_93fb1ec581_b.jpg", "width": 683, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 10, "file_name": "3800636873_ace2c2795f_b.jpg", "width": 686, "height": 1024, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 11, "file_name": "2917282960_06beee649a_b.jpg", "width": 1024, "height": 681, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}, {"id": 12, "file_name": "410488422_5f8991f26e_b.jpg", "width": 1024, "height": 768, "date_captured": "2022-11-09 04:25:00.510624", "license": 1, "coco_url": "", "flickr_url": ""}], "annotations": [{"id": 0, "image_id": 0, "category_id": 0, "iscrowd": 0, "area": 8010.000000000034, "bbox": [580, 329, 336, 456], "segmentation": [[916, 515, 913, 583, 905, 616, 889, 656, 868, 696, 836, 737, 809, 753, 792, 767, 789, 777, 784, 785, 777, 785, 769, 778, 767, 768, 777, 766, 786, 760, 791, 755, 769, 755, 739, 743, 714, 728, 678, 702, 645, 670, 615, 629, 595, 588, 583, 539, 580, 500, 584, 458, 595, 425, 614, 394, 645, 360, 676, 342, 716, 329, 769, 331, 815, 347, 849, 371, 875, 398, 900, 442, 916, 504, 916, 515]]}, {"id": 1, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 3449.9999999999777, "bbox": [513, 168, 224, 222], "segmentation": [[588, 173, 617, 168, 649, 172, 673, 182, 692, 197, 708, 216, 722, 237, 730, 260, 737, 283, 718, 312, 706, 341, 699, 367, 697, 390, 676, 369, 650, 349, 613, 337, 580, 337, 552, 347, 534, 361, 520, 332, 513, 296, 513, 266, 521, 243, 526, 225, 541, 205, 560, 187, 588, 173]]}, {"id": 2, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 161.99999999998974, "bbox": [731, 213, 179, 86], "segmentation": [[845, 219, 861, 229, 880, 242, 892, 260, 902, 275, 910, 299, 889, 277, 869, 263, 844, 254, 813, 250, 785, 255, 762, 265, 745, 279, 739, 283, 731, 258, 746, 241, 767, 225, 790, 216, 821, 213, 845, 219]]}, {"id": 3, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 1348.5000000000332, "bbox": [698, 250, 233, 239], "segmentation": [[931, 378, 928, 402, 920, 435, 913, 454, 897, 475, 872, 460, 840, 450, 811, 449, 789, 450, 768, 460, 754, 469, 730, 489, 726, 486, 724, 459, 718, 426, 698, 390, 698, 367, 707, 335, 721, 306, 734, 290, 746, 278, 769, 261, 794, 252, 822, 250, 845, 254, 865, 261, 889, 277, 910, 299, 921, 323, 929, 354, 931, 378]]}, {"id": 4, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 896.9999999999895, "bbox": [852, 480, 140, 228], "segmentation": [[927, 486, 946, 498, 968, 516, 989, 553, 992, 593, 985, 630, 975, 649, 957, 668, 937, 686, 913, 700, 889, 707, 862, 707, 852, 708, 876, 691, 897, 675, 910, 656, 925, 635, 933, 610, 939, 587, 939, 562, 935, 538, 927, 512, 910, 492, 900, 480, 927, 486]]}, {"id": 5, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 4515.000000000053, "bbox": [690, 449, 249, 289], "segmentation": [[704, 664, 692, 631, 690, 604, 691, 580, 699, 545, 711, 521, 723, 498, 742, 480, 766, 461, 785, 452, 807, 449, 839, 449, 865, 457, 887, 469, 904, 484, 923, 506, 933, 532, 939, 565, 939, 584, 931, 620, 920, 643, 905, 662, 885, 682, 861, 701, 839, 713, 808, 719, 786, 723, 769, 728, 754, 733, 748, 731, 746, 738, 738, 737, 738, 729, 729, 720, 722, 708, 718, 690, 704, 664]]}, {"id": 6, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 3256.0000000000296, "bbox": [490, 338, 234, 287], "segmentation": [[526, 551, 509, 526, 497, 498, 493, 470, 490, 444, 493, 422, 501, 398, 512, 381, 526, 365, 546, 351, 573, 340, 603, 338, 626, 340, 662, 357, 688, 381, 709, 408, 721, 438, 724, 466, 724, 493, 719, 504, 704, 531, 694, 568, 691, 584, 691, 604, 682, 609, 683, 612, 687, 610, 688, 617, 684, 625, 682, 625, 679, 619, 676, 616, 664, 620, 648, 619, 620, 609, 587, 599, 564, 585, 548, 573, 526, 551]]}, {"id": 7, "image_id": 1, "category_id": 0, "iscrowd": 0, "area": 721.4999999999667, "bbox": [563, 596, 202, 176], "segmentation": [[594, 735, 579, 712, 567, 691, 563, 659, 564, 631, 568, 612, 579, 596, 605, 605, 631, 613, 656, 621, 671, 618, 676, 616, 682, 625, 684, 625, 687, 616, 687, 612, 684, 612, 684, 608, 691, 605, 691, 619, 694, 637, 702, 656, 711, 678, 719, 692, 722, 706, 729, 719, 737, 727, 738, 737, 746, 739, 749, 731, 756, 734, 765, 730, 757, 741, 728, 762, 714, 766, 683, 772, 654, 769, 623, 757, 594, 735]]}, {"id": 8, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 1096.4999999999554, "bbox": [615, 69, 223, 293], "segmentation": [[704, 71, 723, 69, 739, 70, 758, 76, 773, 82, 787, 91, 796, 101, 815, 121, 827, 143, 833, 168, 838, 196, 834, 228, 828, 252, 813, 278, 797, 301, 784, 319, 767, 332, 749, 343, 733, 347, 718, 351, 718, 355, 721, 359, 716, 362, 706, 354, 709, 354, 711, 352, 712, 351, 700, 349, 689, 342, 676, 330, 660, 313, 647, 295, 638, 278, 630, 259, 623, 239, 618, 217, 615, 191, 616, 170, 620, 150, 626, 131, 639, 109, 654, 95, 669, 84, 694, 73, 704, 71]]}, {"id": 9, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 294.0000000000021, "bbox": [574, 311, 60, 40], "segmentation": [[603, 311, 614, 313, 626, 319, 634, 327, 621, 329, 608, 332, 597, 336, 586, 340, 577, 347, 574, 351, 574, 341, 576, 333, 580, 325, 586, 319, 595, 313, 603, 311]]}, {"id": 10, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 173.9999999999973, "bbox": [517, 357, 45, 64], "segmentation": [[552, 371, 545, 382, 540, 394, 535, 409, 531, 421, 521, 411, 517, 398, 517, 385, 524, 370, 532, 360, 549, 357, 559, 358, 562, 360, 552, 371]]}, {"id": 11, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 2437.5000000000477, "bbox": [528, 329, 226, 282], "segmentation": [[741, 398, 750, 423, 754, 448, 754, 473, 748, 499, 741, 518, 725, 546, 707, 568, 693, 581, 678, 593, 659, 599, 660, 602, 664, 604, 664, 606, 652, 611, 651, 607, 652, 603, 654, 601, 653, 599, 640, 597, 626, 592, 609, 583, 589, 568, 569, 549, 552, 527, 540, 502, 533, 479, 528, 452, 529, 435, 532, 414, 541, 390, 554, 370, 568, 355, 591, 338, 621, 329, 647, 330, 671, 335, 690, 345, 711, 358, 727, 375, 741, 398]]}, {"id": 12, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 1151.999999999996, "bbox": [126, 419, 77, 80], "segmentation": [[197, 437, 203, 457, 200, 471, 194, 482, 184, 491, 169, 499, 156, 496, 144, 488, 134, 478, 128, 466, 126, 452, 130, 438, 138, 429, 147, 422, 162, 419, 177, 420, 188, 428, 197, 437]]}, {"id": 13, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 364.4999999999953, "bbox": [21, 541, 52, 63], "segmentation": [[69, 583, 62, 593, 53, 602, 42, 602, 38, 601, 36, 596, 33, 596, 33, 604, 21, 597, 24, 592, 28, 589, 30, 584, 30, 570, 28, 565, 30, 562, 26, 560, 23, 556, 23, 552, 21, 550, 22, 545, 27, 543, 38, 541, 48, 542, 55, 545, 60, 550, 66, 559, 70, 565, 73, 571, 69, 583]]}, {"id": 14, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 566.9999999999978, "bbox": [1963, 459, 55, 59], "segmentation": [[1997, 459, 2009, 462, 2016, 469, 2018, 488, 2015, 499, 2002, 512, 1989, 516, 1985, 516, 1984, 518, 1982, 517, 1982, 514, 1975, 511, 1969, 505, 1964, 494, 1963, 487, 1966, 475, 1972, 468, 1980, 463, 1989, 459, 1997, 459]]}, {"id": 15, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 47.49999999999685, "bbox": [1917, 465, 47, 53], "segmentation": [[1933, 466, 1941, 465, 1946, 465, 1957, 471, 1960, 479, 1964, 486, 1961, 496, 1956, 508, 1945, 515, 1945, 517, 1943, 518, 1942, 515, 1933, 514, 1924, 507, 1920, 500, 1918, 494, 1917, 487, 1920, 480, 1923, 474, 1925, 470, 1933, 466]]}, {"id": 16, "image_id": 2, "category_id": 0, "iscrowd": 0, "area": 569.999999999975, "bbox": [743, 1, 159, 71], "segmentation": [[878, 31, 858, 47, 843, 56, 830, 60, 816, 60, 820, 65, 819, 70, 818, 72, 808, 72, 804, 70, 804, 64, 807, 58, 798, 55, 778, 41, 765, 28, 752, 15, 743, 1, 902, 1, 895, 11, 887, 21, 878, 31]]}, {"id": 17, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 1305.0000000000043, "bbox": [906, 63, 118, 117], "segmentation": [[981, 66, 998, 74, 1008, 84, 1016, 97, 1023, 113, 1024, 133, 1023, 147, 1019, 158, 1014, 168, 1008, 177, 997, 169, 984, 165, 977, 163, 969, 163, 963, 164, 950, 167, 943, 170, 937, 174, 929, 180, 918, 168, 911, 154, 907, 138, 906, 124, 909, 107, 917, 90, 928, 76, 938, 70, 950, 66, 963, 63, 972, 63, 981, 66]]}, {"id": 18, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 719.9999999999976, "bbox": [990, 181, 110, 123], "segmentation": [[1085, 197, 1095, 212, 1098, 221, 1100, 233, 1100, 249, 1093, 266, 1083, 281, 1073, 290, 1055, 299, 1037, 304, 1019, 302, 1011, 300, 1002, 297, 998, 296, 995, 295, 991, 295, 990, 293, 993, 292, 994, 292, 994, 289, 1003, 283, 1010, 274, 1017, 261, 1023, 250, 1028, 229, 1028, 215, 1025, 198, 1019, 189, 1024, 185, 1035, 182, 1049, 181, 1061, 183, 1073, 188, 1085, 197]]}, {"id": 19, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 262.4999999999958, "bbox": [910, 163, 119, 142], "segmentation": [[917, 259, 914, 249, 911, 234, 910, 220, 913, 205, 919, 194, 926, 185, 934, 176, 946, 169, 958, 165, 973, 163, 987, 166, 999, 170, 1012, 182, 1023, 194, 1029, 215, 1027, 234, 1023, 248, 1015, 264, 1007, 277, 996, 287, 986, 293, 974, 297, 968, 299, 962, 299, 960, 302, 957, 305, 954, 304, 952, 301, 953, 298, 948, 294, 939, 288, 932, 283, 927, 278, 923, 272, 920, 266, 917, 259]]}, {"id": 20, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 255.99999999998542, "bbox": [824, 157, 104, 110], "segmentation": [[838, 175, 849, 167, 862, 159, 874, 157, 888, 157, 901, 161, 909, 163, 916, 168, 921, 172, 927, 178, 928, 180, 928, 182, 922, 189, 912, 205, 910, 223, 913, 242, 917, 258, 920, 266, 919, 267, 907, 256, 894, 245, 883, 241, 872, 239, 861, 239, 847, 245, 841, 252, 839, 254, 832, 245, 827, 234, 824, 218, 825, 205, 829, 191, 833, 183, 838, 175]]}, {"id": 21, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 1687.499999999997, "bbox": [924, 280, 86, 93], "segmentation": [[994, 352, 984, 363, 969, 372, 954, 373, 943, 373, 932, 370, 924, 366, 932, 361, 938, 356, 941, 350, 945, 349, 949, 351, 950, 347, 950, 343, 949, 342, 947, 344, 944, 344, 946, 334, 945, 318, 941, 303, 938, 295, 931, 284, 930, 280, 940, 290, 948, 294, 953, 298, 952, 301, 954, 305, 957, 304, 962, 300, 969, 299, 980, 295, 986, 292, 992, 288, 994, 290, 994, 292, 990, 293, 990, 295, 995, 296, 997, 296, 1006, 298, 1009, 305, 1010, 319, 1008, 329, 1006, 338, 1000, 347, 994, 352]]}, {"id": 22, "image_id": 3, "category_id": 0, "iscrowd": 0, "area": 1785.0000000000593, "bbox": [796, 239, 155, 135], "segmentation": [[900, 373, 879, 374, 857, 371, 842, 366, 821, 358, 806, 343, 797, 327, 796, 314, 799, 307, 803, 297, 808, 291, 815, 284, 825, 277, 827, 276, 829, 270, 833, 261, 838, 253, 847, 246, 861, 240, 870, 239, 885, 242, 895, 247, 909, 257, 919, 266, 925, 275, 933, 287, 941, 302, 945, 317, 946, 329, 946, 339, 944, 344, 948, 344, 949, 343, 951, 343, 951, 347, 950, 350, 949, 351, 946, 350, 944, 349, 937, 355, 929, 362, 921, 368, 908, 372, 900, 373]]}, {"id": 23, "image_id": 4, "category_id": 0, "iscrowd": 0, "area": 179.999999999999, "bbox": [1738, 527, 40, 41], "segmentation": [[1761, 527, 1771, 532, 1777, 538, 1778, 549, 1776, 558, 1772, 564, 1764, 568, 1750, 567, 1743, 559, 1739, 551, 1738, 542, 1743, 534, 1749, 529, 1761, 527]]}, {"id": 24, "image_id": 4, "category_id": 0, "iscrowd": 0, "area": 509.9999999999995, "bbox": [1414, 588, 53, 51], "segmentation": [[1455, 633, 1442, 639, 1430, 638, 1420, 633, 1414, 626, 1414, 612, 1418, 598, 1429, 591, 1442, 588, 1452, 589, 1461, 595, 1467, 610, 1466, 624, 1455, 633]]}, {"id": 25, "image_id": 4, "category_id": 0, "iscrowd": 0, "area": 337.99999999999847, "bbox": [964, 608, 59, 60], "segmentation": [[1011, 614, 1019, 623, 1023, 634, 1023, 647, 1015, 660, 1008, 668, 992, 668, 982, 666, 972, 658, 964, 645, 964, 625, 972, 614, 984, 608, 1004, 609, 1011, 614]]}, {"id": 26, "image_id": 4, "category_id": 0, "iscrowd": 0, "area": 693.0000000000015, "bbox": [260, 654, 59, 58], "segmentation": [[300, 655, 312, 664, 317, 676, 319, 690, 314, 700, 306, 709, 296, 712, 283, 712, 276, 710, 268, 701, 263, 693, 260, 680, 263, 670, 270, 660, 285, 654, 300, 655]]}, {"id": 27, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 6767.999999999958, "bbox": [269, 75, 284, 372], "segmentation": [[387, 77, 425, 75, 461, 83, 498, 108, 530, 143, 543, 175, 553, 208, 550, 254, 540, 294, 522, 326, 503, 359, 500, 362, 476, 374, 449, 392, 434, 411, 425, 424, 408, 430, 405, 439, 405, 444, 400, 447, 389, 442, 387, 436, 391, 433, 398, 432, 398, 428, 381, 425, 359, 413, 334, 385, 313, 360, 294, 327, 281, 294, 271, 260, 269, 212, 283, 163, 307, 124, 334, 102, 359, 86, 387, 77]]}, {"id": 28, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 2437.4999999999873, "bbox": [503, 225, 222, 229], "segmentation": [[645, 233, 660, 239, 695, 266, 712, 297, 724, 331, 725, 370, 718, 400, 708, 423, 694, 447, 689, 454, 674, 426, 659, 408, 638, 383, 614, 369, 589, 358, 563, 353, 532, 353, 503, 360, 517, 338, 534, 308, 545, 280, 548, 258, 551, 241, 576, 232, 608, 225, 631, 229, 645, 233]]}, {"id": 29, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 4312.9999999999145, "bbox": [401, 353, 293, 345], "segmentation": [[693, 480, 694, 512, 688, 547, 668, 593, 656, 612, 639, 628, 622, 645, 605, 656, 578, 672, 558, 679, 533, 688, 515, 691, 503, 690, 503, 695, 497, 698, 490, 692, 487, 685, 472, 673, 449, 649, 436, 631, 422, 609, 413, 588, 402, 551, 401, 522, 403, 493, 411, 455, 420, 435, 436, 409, 453, 390, 470, 379, 487, 369, 506, 359, 539, 353, 568, 355, 598, 361, 627, 375, 651, 397, 673, 426, 687, 456, 693, 480]]}, {"id": 30, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 5534.999999999963, "bbox": [138, 450, 277, 349], "segmentation": [[142, 631, 138, 593, 141, 560, 147, 540, 161, 513, 175, 495, 192, 480, 210, 465, 237, 455, 260, 450, 293, 450, 321, 454, 342, 469, 360, 480, 378, 497, 388, 513, 397, 527, 402, 537, 403, 557, 408, 573, 413, 588, 415, 609, 411, 637, 400, 669, 388, 694, 370, 724, 359, 744, 347, 764, 331, 780, 317, 787, 322, 790, 323, 791, 319, 796, 314, 799, 310, 798, 308, 792, 295, 792, 280, 788, 263, 778, 247, 769, 230, 758, 206, 736, 186, 717, 169, 694, 156, 672, 147, 647, 142, 631]]}, {"id": 31, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 6288.000000000001, "bbox": [307, 369, 118, 134], "segmentation": [[322, 447, 307, 429, 313, 410, 318, 389, 321, 369, 335, 385, 349, 403, 365, 417, 387, 427, 399, 428, 400, 433, 392, 432, 388, 436, 389, 443, 399, 448, 406, 446, 405, 439, 409, 431, 425, 425, 416, 444, 411, 456, 409, 468, 404, 487, 403, 495, 392, 496, 386, 496, 386, 503, 381, 500, 378, 494, 378, 492, 371, 490, 353, 476, 332, 460, 322, 447]]}, {"id": 32, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 2490.000000000036, "bbox": [67, 224, 254, 285], "segmentation": [[96, 270, 110, 254, 137, 235, 163, 227, 187, 224, 209, 225, 231, 231, 253, 243, 270, 255, 275, 277, 287, 309, 299, 337, 312, 359, 321, 370, 315, 403, 305, 433, 295, 450, 258, 450, 227, 458, 205, 468, 184, 486, 169, 503, 164, 509, 146, 497, 126, 478, 105, 456, 86, 426, 74, 395, 67, 363, 72, 320, 82, 291, 96, 270]]}, {"id": 33, "image_id": 5, "category_id": 0, "iscrowd": 0, "area": 39.99999999999972, "bbox": [31, 400, 35, 47], "segmentation": [[66, 425, 62, 433, 58, 440, 52, 444, 50, 445, 50, 446, 48, 447, 47, 447, 47, 446, 44, 445, 40, 442, 34, 434, 32, 425, 31, 414, 34, 407, 40, 403, 44, 400, 50, 400, 58, 402, 64, 409, 66, 416, 66, 425]]}, {"id": 34, "image_id": 6, "category_id": 0, "iscrowd": 0, "area": 3264.000000000039, "bbox": [247, 32, 289, 350], "segmentation": [[287, 86, 307, 64, 329, 50, 357, 37, 379, 36, 408, 32, 437, 40, 467, 50, 494, 76, 517, 100, 530, 136, 535, 165, 536, 196, 531, 236, 516, 274, 497, 301, 463, 338, 433, 356, 402, 372, 378, 375, 366, 375, 370, 382, 357, 380, 351, 375, 357, 372, 345, 368, 319, 357, 287, 322, 267, 280, 249, 224, 247, 181, 255, 141, 266, 111, 287, 86]]}, {"id": 35, "image_id": 7, "category_id": 0, "iscrowd": 0, "area": 892.9999999999847, "bbox": [277, 92, 129, 174], "segmentation": [[305, 106, 324, 97, 345, 92, 364, 97, 380, 106, 395, 121, 403, 143, 406, 165, 402, 196, 386, 221, 371, 242, 352, 258, 333, 266, 316, 258, 302, 242, 289, 220, 281, 196, 277, 173, 282, 145, 292, 121, 305, 106]]}, {"id": 36, "image_id": 7, "category_id": 0, "iscrowd": 0, "area": 152.99999999999997, "bbox": [701, 468, 11, 23], "segmentation": [[701, 480, 702, 473, 705, 469, 706, 468, 707, 469, 710, 469, 712, 469, 712, 470, 711, 473, 710, 477, 710, 481, 709, 486, 709, 488, 708, 488, 707, 490, 707, 491, 705, 491, 703, 488, 702, 485, 701, 480]]}, {"id": 37, "image_id": 7, "category_id": 0, "iscrowd": 0, "area": 15.00000000000006, "bbox": [737, 342, 10, 12], "segmentation": [[741, 342, 743, 342, 745, 343, 746, 344, 746, 347, 747, 349, 746, 350, 745, 351, 745, 354, 743, 354, 741, 354, 740, 352, 738, 349, 737, 347, 738, 345, 738, 343, 741, 342]]}, {"id": 38, "image_id": 8, "category_id": 0, "iscrowd": 0, "area": 513.4999999999991, "bbox": [345, 16, 141, 102], "segmentation": [[479, 64, 468, 81, 453, 97, 432, 110, 407, 114, 406, 118, 397, 116, 379, 107, 360, 83, 349, 59, 345, 35, 350, 16, 484, 16, 486, 37, 479, 64]]}, {"id": 39, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 1681.0000000000086, "bbox": [206, 153, 141, 176], "segmentation": [[260, 154, 277, 153, 291, 157, 302, 161, 316, 172, 327, 182, 337, 199, 344, 220, 347, 235, 347, 246, 345, 256, 342, 268, 337, 280, 329, 293, 324, 298, 319, 305, 316, 310, 314, 314, 310, 320, 304, 323, 302, 324, 300, 327, 299, 329, 296, 329, 294, 327, 285, 326, 282, 311, 276, 297, 268, 284, 255, 270, 244, 261, 231, 254, 217, 249, 207, 247, 206, 234, 206, 218, 208, 204, 214, 189, 221, 178, 230, 167, 240, 160, 250, 157, 260, 154]]}, {"id": 40, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 28.000000000140872, "bbox": [137, 247, 149, 176], "segmentation": [[159, 261, 170, 255, 179, 250, 189, 248, 198, 247, 205, 247, 213, 248, 221, 250, 228, 253, 238, 258, 247, 263, 260, 275, 265, 280, 272, 290, 277, 298, 280, 307, 284, 316, 285, 324, 286, 335, 286, 355, 283, 370, 282, 378, 282, 387, 282, 397, 281, 404, 279, 408, 274, 414, 274, 415, 274, 416, 276, 417, 278, 419, 278, 422, 275, 423, 271, 423, 268, 422, 268, 420, 268, 418, 265, 419, 261, 420, 256, 419, 252, 419, 242, 413, 232, 408, 220, 404, 210, 402, 203, 400, 190, 394, 177, 384, 161, 371, 152, 359, 143, 340, 137, 319, 138, 302, 139, 293, 145, 279, 149, 271, 155, 263, 159, 261]]}, {"id": 41, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 69.99999999999129, "bbox": [308, 343, 135, 145], "segmentation": [[357, 345, 364, 344, 376, 343, 387, 344, 400, 347, 415, 355, 428, 367, 434, 378, 441, 391, 443, 408, 443, 424, 440, 440, 433, 455, 424, 466, 412, 477, 396, 485, 380, 488, 368, 488, 358, 487, 347, 483, 333, 474, 319, 456, 309, 432, 308, 410, 308, 400, 317, 377, 325, 365, 337, 355, 347, 349, 357, 345]]}, {"id": 42, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 0.0, "bbox": [203, 327, 107, 119], "segmentation": [[305, 354, 307, 363, 309, 372, 310, 379, 309, 386, 309, 392, 307, 401, 303, 412, 300, 420, 292, 430, 286, 437, 279, 442, 268, 444, 258, 446, 246, 446, 236, 445, 227, 443, 219, 439, 216, 425, 211, 414, 205, 404, 203, 399, 214, 403, 226, 406, 239, 411, 249, 416, 257, 419, 263, 419, 267, 418, 267, 421, 270, 422, 273, 423, 278, 422, 279, 420, 277, 418, 275, 416, 274, 414, 279, 408, 282, 399, 283, 388, 283, 379, 284, 363, 286, 348, 287, 337, 286, 331, 286, 327, 288, 327, 294, 334, 301, 347, 305, 354]]}, {"id": 43, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 368.999999999989, "bbox": [56, 360, 166, 152], "segmentation": [[72, 384, 78, 378, 88, 371, 99, 366, 109, 361, 120, 360, 132, 360, 145, 362, 157, 366, 162, 371, 169, 378, 181, 386, 191, 394, 203, 400, 209, 412, 215, 424, 219, 441, 219, 453, 219, 465, 220, 473, 222, 478, 221, 484, 219, 489, 220, 494, 219, 496, 216, 497, 213, 498, 208, 502, 202, 504, 192, 505, 189, 505, 168, 511, 152, 512, 134, 512, 113, 506, 91, 494, 76, 478, 65, 463, 57, 440, 56, 421, 60, 403, 65, 392, 72, 384]]}, {"id": 44, "image_id": 9, "category_id": 0, "iscrowd": 0, "area": 840.000000000009, "bbox": [153, 440, 135, 132], "segmentation": [[260, 559, 246, 567, 232, 572, 218, 572, 210, 572, 198, 569, 188, 565, 176, 556, 168, 547, 162, 540, 158, 527, 155, 520, 153, 513, 169, 512, 180, 509, 188, 507, 198, 506, 208, 503, 213, 498, 220, 496, 220, 494, 220, 489, 222, 481, 221, 475, 219, 468, 219, 462, 220, 451, 219, 440, 227, 443, 246, 447, 255, 447, 265, 455, 273, 466, 280, 477, 285, 493, 288, 507, 287, 517, 283, 530, 279, 538, 272, 548, 268, 554, 260, 559]]}, {"id": 45, "image_id": 10, "category_id": 0, "iscrowd": 0, "area": 1966.49999999999, "bbox": [337, 84, 161, 161], "segmentation": [[339, 147, 348, 123, 363, 106, 379, 93, 401, 86, 425, 84, 452, 92, 477, 111, 494, 139, 498, 171, 488, 202, 470, 223, 445, 239, 413, 244, 388, 242, 373, 245, 369, 232, 353, 214, 343, 193, 337, 170, 339, 147]]}, {"id": 46, "image_id": 11, "category_id": 0, "iscrowd": 0, "area": 0.0, "bbox": [474, 248, 121, 128], "segmentation": [[585, 278, 589, 288, 593, 298, 595, 311, 594, 324, 590, 338, 584, 348, 576, 360, 569, 366, 563, 369, 563, 371, 567, 371, 569, 371, 568, 376, 567, 376, 566, 375, 565, 374, 561, 373, 559, 372, 552, 373, 543, 374, 534, 373, 524, 371, 508, 366, 496, 356, 486, 344, 478, 329, 474, 311, 476, 297, 478, 287, 485, 276, 490, 268, 501, 259, 507, 255, 518, 251, 530, 248, 541, 249, 550, 251, 556, 253, 563, 256, 551, 270, 544, 275, 532, 281, 525, 286, 522, 288, 521, 289, 520, 291, 522, 293, 526, 293, 535, 288, 538, 289, 538, 291, 538, 294, 533, 303, 530, 311, 530, 313, 531, 315, 533, 315, 535, 314, 535, 311, 537, 308, 539, 305, 542, 303, 543, 303, 542, 307, 542, 312, 541, 316, 542, 318, 544, 318, 546, 318, 547, 314, 548, 310, 550, 305, 549, 314, 548, 321, 548, 324, 551, 324, 552, 324, 554, 322, 554, 319, 554, 316, 555, 313, 556, 309, 556, 304, 558, 307, 558, 313, 559, 317, 561, 318, 563, 318, 563, 315, 563, 309, 562, 301, 563, 294, 565, 287, 566, 282, 570, 275, 573, 272, 577, 268, 582, 273, 585, 278]]}, {"id": 47, "image_id": 12, "category_id": 0, "iscrowd": 0, "area": 2749.9999999999563, "bbox": [144, 10, 235, 234], "segmentation": [[371, 166, 355, 192, 330, 217, 298, 236, 267, 244, 236, 242, 196, 227, 163, 191, 149, 158, 144, 122, 155, 83, 173, 53, 200, 32, 231, 16, 268, 10, 307, 13, 350, 25, 366, 40, 361, 60, 362, 84, 363, 111, 369, 134, 379, 145, 371, 166]]}, {"id": 48, "image_id": 12, "category_id": 0, "iscrowd": 0, "area": 6299.9999999999645, "bbox": [362, 0, 205, 226], "segmentation": [[453, 211, 417, 191, 393, 166, 382, 149, 371, 133, 364, 111, 362, 86, 363, 65, 364, 51, 368, 40, 381, 21, 394, 5, 399, 1, 524, 0, 548, 24, 559, 55, 567, 83, 565, 113, 557, 151, 545, 179, 528, 198, 514, 209, 514, 215, 522, 219, 522, 221, 515, 224, 509, 226, 507, 221, 507, 212, 489, 218, 466, 215, 453, 211]]}, {"id": 49, "image_id": 12, "category_id": 0, "iscrowd": 0, "area": 5400.000000000031, "bbox": [671, 1, 243, 253], "segmentation": [[705, 196, 684, 162, 672, 122, 671, 80, 683, 43, 702, 15, 716, 2, 878, 1, 893, 19, 906, 44, 914, 78, 913, 117, 907, 147, 895, 169, 870, 197, 844, 221, 809, 240, 787, 244, 784, 250, 786, 254, 782, 254, 779, 248, 774, 242, 754, 238, 734, 228, 718, 211, 705, 196]]}]} -------------------------------------------------------------------------------- /object_detection_with_detectron2/README.md: -------------------------------------------------------------------------------- 1 | # Object Detection with Trasformer Using Detectron2 2 | 3 | ## Dependencies 4 | 1. Install detectron2.[](https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md) (Prefer to use Conda version). 5 | 2. Install DyHead by following the steps present in [DynamicHead](https://github.com/microsoft/DynamicHead). 6 | 7 | You may face some building issue related to CUDA in DynamicHead/dyhead/csrc/cuda/{deform_conv_cuda.cu, SigmoidFocalLoss_cuda.cu}. 8 | Try to Fix them.Otherwise,let me know what is the error you are facing. 9 | 10 | ## Dataset Preparation 11 | Balloon dataset is converted to COCO format & is present inside custom_balloon folder. 12 | 13 | If you want to convert balloon dataset in to coco format & use it in Detectron2.Then, 14 | follow the below steps. 15 | 16 | - Download the balloon dataset from https://github.com/matterport/Mask_RCNN/releases/download/v2.1/balloon_dataset.zip. 17 | - git clone https://github.com/woctezuma/VIA2COCO 18 | - cd VIA2COCO/ 19 | git checkout fixes 20 | - run convert_coco.py 21 | 22 | 23 | ## Usage 24 | 25 | ### Enviornment Setup 26 | - For DyHead: 27 | 1. Download weights(for example, dyhead_r50_atss_fpn_1x.pth) from [DynamicHead](https://github.com/microsoft/DynamicHead) & keep them inside pretrained_model/ 28 | 2. Copy the config files from [](https://github.com/microsoft/DynamicHead/tree/master/configs) & keep them inside configs/ 29 | 30 | - For DETR: 31 | 1. git clone https://github.com/facebookresearch/detr/tree/master/d2. 32 | 2. Keep the converted_model.pth inside pretrained_model/ 33 | Here is the steps to get the converted_model.pth 34 | - python converter.py --source_model https://dl.fbaipublicfiles.com/detr/detr-r50-e632da11.pth --output_model converted_model.pth 35 | 3. Copy the config file https://github.com/facebookresearch/detr/tree/master/d2/configs/detr_256_6_6_torchvision.yaml & keep it inside configs/ 36 | 37 | ### Training 38 | - For DyHead with FPN backbone: 39 | 40 | python3.8 training.py --outdir [where model will be saved] --arch dyhead-fpn --config [file path] --weight [file path] --epochs [no of epochs]. 41 | 42 | For Example, 43 | python3.8 training.py --outdir out_dyhead_fpn/ --arch dyhead-fpn --config configs/dyhead_r50_atss_fpn_1x.yaml --weight pretrained_model/dyhead_r50_atss_fpn_1x.pth --epochs 5000 44 | 45 | - For DyHead with Swin-T transformer backbone: 46 | 47 | python3.8 training.py --outdir [where model will be saved] --arch dyhead-swint --config [file path] --weight [file path] --epochs [no of epochs] 48 | 49 | For Example, 50 | python3.8 training.py --outdir out_dyhead_swint/ --arch dyhead-swint --config configs/dyhead_swint_atss_fpn_2x_ms.yaml --weight pretrained_model/dyhead_swint_atss_fpn_2x_ms.pth --epochs 5000. 51 | 52 | - For DETR: 53 | 54 | python3.8 training.py --outdir [where model will be saved] --arch detr --config [file path] --weight [file path] --epochs [no of epochs]. 55 | 56 | For Example, 57 | python3.8 training.py --outdir out_test/ --arch detr --config configs/detr_256_6_6_torchvision.yaml --weight pretrained_model/converted_model.pth --epochs 5000 58 | 59 | ### Inference: 60 | 61 | - For DyHead with FPN backbone: 62 | 63 | python3.8 inference.py --outdir out_dyhead_fpn/ --arch dyhead-fpn --config configs/dyhead_r50_atss_fpn_1x.yaml --save True. 64 | 65 | Inference Time: 66 | 67 | Evaluation Time : {} ms 108.9015007019043 68 | Evaluation Time : {} ms 103.93381118774414 69 | 70 | ![](output_images/dyhead_output2.png) 71 | 72 | - For DyHead with Swin-T transformer backbone: 73 | python3.8 inference.py --outdir out_dyhead_swint/ --arch dyhead-swint --config configs/dyhead_swint_atss_fpn_2x_ms.yaml --save True. 74 | 75 | Inference Time: 76 | Evaluation Time : {} ms 157.5005054473877. 77 | Evaluation Time : {} ms 153.02109718322754 78 | 79 | - For DETR: 80 | 81 | python3.8 inference.py --outdir out_detr/ --arch detr --config configs/detr_256_6_6_torchvision.yaml --save True. 82 | 83 | Inference Time: 84 | 85 | Evaluation Time : {} ms 71.02847099304199 86 | Evaluation Time : {} ms 92.53978729248047 87 | 88 | 89 | ![](output_images/detr_output2.png) 90 | 91 | ## Conclusion: 92 | As you can see from output, DETR is slighly faster than DyHead.However,DETR is not that accurate as DyHead in predicting all the ballons. 93 | 94 | Please check the above output. 95 | 96 | We can try other DyHead configs such as dyhead_swint_atss_fpn_2x_ms.yaml and check the output. 97 | 98 | Here the idea is to demonstrate how to use trasformer based object detection using Detectron2 framework. 99 | Please feel free to share your feedback. 100 | 101 | ## References: 102 | 103 | - https://github.com/facebookresearch/detr/tree/master/d2. 104 | - https://github.com/microsoft/DynamicHead. 105 | 106 | --- 107 | Reach me @ 108 | 109 | [LinkedIn](https://www.linkedin.com/in/satya1507/) [GitHub](https://github.com/satya15july) [Medium](https://medium.com/@satya15july_11937) 110 | 111 | -------------------------------------------------------------------------------- /object_detection_with_detectron2/configs/detr_256_6_6_torchvision.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "Detr" 3 | WEIGHTS: "detectron2://ImageNetPretrained/torchvision/R-50.pkl" 4 | PIXEL_MEAN: [123.675, 116.280, 103.530] 5 | PIXEL_STD: [58.395, 57.120, 57.375] 6 | MASK_ON: False 7 | RESNETS: 8 | DEPTH: 50 9 | STRIDE_IN_1X1: False 10 | OUT_FEATURES: ["res2", "res3", "res4", "res5"] 11 | DETR: 12 | GIOU_WEIGHT: 2.0 13 | L1_WEIGHT: 5.0 14 | NUM_OBJECT_QUERIES: 100 15 | DATASETS: 16 | TRAIN: ("coco_2017_train",) 17 | TEST: ("coco_2017_val",) 18 | SOLVER: 19 | IMS_PER_BATCH: 64 20 | BASE_LR: 0.0001 21 | STEPS: (369600,) 22 | MAX_ITER: 554400 23 | WARMUP_FACTOR: 1.0 24 | WARMUP_ITERS: 10 25 | WEIGHT_DECAY: 0.0001 26 | OPTIMIZER: "ADAMW" 27 | BACKBONE_MULTIPLIER: 0.1 28 | CLIP_GRADIENTS: 29 | ENABLED: True 30 | CLIP_TYPE: "full_model" 31 | CLIP_VALUE: 0.01 32 | NORM_TYPE: 2.0 33 | INPUT: 34 | MIN_SIZE_TRAIN: (480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800) 35 | CROP: 36 | ENABLED: True 37 | TYPE: "absolute_range" 38 | SIZE: (384, 600) 39 | FORMAT: "RGB" 40 | TEST: 41 | EVAL_PERIOD: 4000 42 | DATALOADER: 43 | FILTER_EMPTY_ANNOTATIONS: False 44 | NUM_WORKERS: 4 45 | VERSION: 2 46 | -------------------------------------------------------------------------------- /object_detection_with_detectron2/configs/dyhead_r50_atss_fpn_1x.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "ATSS" 3 | WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl" 4 | BACKBONE: 5 | NAME: "build_retinanet_resnet_fpn_dyhead_backbone" 6 | RESNETS: 7 | DEPTH: 50 8 | OUT_FEATURES: ["res3", "res4", "res5"] 9 | FPN: 10 | IN_FEATURES: ["res3", "res4", "res5"] 11 | DYHEAD: 12 | NUM_CONVS: 6 13 | CHANNELS: 256 14 | ANCHOR_GENERATOR: 15 | SIZES: !!python/object/apply:eval ["[[x*2,] for x in [32, 64, 128, 256, 512 ]]"] 16 | ASPECT_RATIOS: [1.0,] 17 | OFFSET: 0.5 18 | ATSS: 19 | NUM_CONVS: 0 20 | DATASETS: 21 | TRAIN: ("coco_2017_train",) 22 | TEST: ("coco_2017_val",) 23 | SOLVER: 24 | IMS_PER_BATCH: 16 25 | BASE_LR: 0.01 26 | STEPS: (60000, 80000) 27 | MAX_ITER: 90000 28 | VERSION: 2 -------------------------------------------------------------------------------- /object_detection_with_detectron2/configs/dyhead_swint_atss_fpn_2x_ms.yaml: -------------------------------------------------------------------------------- 1 | MODEL: 2 | META_ARCHITECTURE: "ATSS" 3 | WEIGHTS: "swin_tiny_patch4_window7_224_d2.pth" 4 | PIXEL_MEAN: [123.675, 116.28, 103.53] 5 | PIXEL_STD: [58.395, 57.12, 57.375] 6 | BACKBONE: 7 | NAME: "build_retinanet_swint_fpn_dyhead_backbone" 8 | SWINT: 9 | OUT_FEATURES: ["stage3", "stage4", "stage5"] 10 | FPN: 11 | IN_FEATURES: ["stage3", "stage4", "stage5"] 12 | DYHEAD: 13 | NUM_CONVS: 6 14 | CHANNELS: 256 15 | ANCHOR_GENERATOR: 16 | SIZES: !!python/object/apply:eval ["[[x*2,] for x in [32, 64, 128, 256, 512 ]]"] 17 | ASPECT_RATIOS: [1.0,] 18 | OFFSET: 0.5 19 | ATSS: 20 | NUM_CONVS: 0 21 | DATASETS: 22 | TRAIN: ("coco_2017_train",) 23 | TEST: ("coco_2017_val",) 24 | SOLVER: 25 | IMS_PER_BATCH: 32 26 | BASE_LR: 0.0001 27 | WEIGHT_DECAY: 0.05 28 | STEPS: (60000, 80000) 29 | MAX_ITER: 90000 30 | OPTIMIZER: "ADAMW" 31 | INPUT: 32 | FORMAT: "RGB" 33 | MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800) 34 | VERSION: 2 -------------------------------------------------------------------------------- /object_detection_with_detectron2/inference.py: -------------------------------------------------------------------------------- 1 | # Usage: python3.8 inference.py --outdir out_test --arch detr \ 2 | # --config configs/detr_256_6_6_torchvision.yaml --save True 3 | # 4 | 5 | import detectron2 6 | from detectron2.utils.logger import setup_logger 7 | setup_logger() 8 | import sys 9 | sys.path.append('detr') 10 | # import some common libraries 11 | import numpy as np 12 | import os, json, cv2, random 13 | 14 | # import some common detectron2 utilities 15 | from detectron2 import model_zoo 16 | from detectron2.engine import DefaultPredictor 17 | from detectron2.config import get_cfg 18 | from detectron2.utils.visualizer import Visualizer 19 | from detectron2.data import MetadataCatalog, DatasetCatalog 20 | from detectron2.data.datasets import register_coco_instances 21 | # from detectron2.engine import DefaultTrainer 22 | from d2.train_net import Trainer 23 | from d2.detr import add_detr_config 24 | 25 | from detectron2.evaluation import COCOEvaluator, inference_on_dataset 26 | from detectron2.data import build_detection_test_loader 27 | 28 | from dyhead import add_dyhead_config 29 | from extra import add_extra_config 30 | 31 | import matplotlib.pyplot as plt 32 | import time 33 | import argparse 34 | 35 | 36 | ap = argparse.ArgumentParser() 37 | ap.add_argument("-o", "--outdir", required=True, help="output path for the model") 38 | ap.add_argument('-a', '--arch', default='detr', choices=['detr', 'dyhead-fpn', 'dyhead-swint'], help='Choose different transformer based object detection architecture') 39 | ap.add_argument("-c", "--config", required=True, help="config file for the model") 40 | ap.add_argument("-s", '--save', default=False, type=bool, help='save predicted output') 41 | args = vars(ap.parse_args()) 42 | 43 | outdir_path = args['outdir'] 44 | config = args['config'] 45 | print("outdir path : {}".format(outdir_path)) 46 | print("config file : {}".format(config)) 47 | 48 | cfg = get_cfg() 49 | if args['arch'] == 'detr': 50 | add_detr_config(cfg) 51 | elif args['arch'] == 'dyhead-fpn' or args['arch'] == 'dyhead-swint': 52 | add_dyhead_config(cfg) 53 | add_extra_config(cfg) 54 | 55 | cfg.merge_from_file(config) 56 | 57 | LABELS = ["balloon"] 58 | 59 | cfg.DATASETS.TRAIN = ("custom_train",) 60 | cfg.DATASETS.TEST = ("custom_val",) 61 | 62 | cfg.OUTPUT_DIR = outdir_path 63 | 64 | cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, "model_final.pth") 65 | if args["arch"] == 'detr': 66 | cfg.MODEL.DETR.NUM_CLASSES = len(LABELS) 67 | elif args['arch'] == 'dyhead-fpn' or args['arch'] == 'dyhead-swint': 68 | cfg.MODEL.ATSS.NUM_CLASSES = len(LABELS) 69 | 70 | predictor = DefaultPredictor(cfg) 71 | 72 | register_coco_instances("custom_train", 73 | {}, 74 | "../custom_balloon/annotations/custom_train.json", 75 | "../custom_balloon/train2017/") 76 | 77 | register_coco_instances("custom_val", 78 | {}, 79 | "../custom_balloon/annotations/custom_val.json", 80 | "../custom_balloon/val2017/") 81 | 82 | 83 | 84 | for keyword in ['train', 'val']: 85 | MetadataCatalog.get('custom_{}'.format(keyword)).set(thing_classes=LABELS) 86 | 87 | custom_metadata = MetadataCatalog.get("custom_val") 88 | 89 | dataset_dicts = DatasetCatalog.get("custom_val") 90 | 91 | # Modification 92 | #dataset_name = cfg.DATASETS.TRAIN[0] 93 | #custom_metadata = MetadataCatalog.get(dataset_name) 94 | 95 | threshold = 0.7 96 | 97 | #dataset_dicts = DatasetCatalog.get("custom_val") 98 | 99 | def filter_predictions_from_outputs(outputs, 100 | threshold=0.7, 101 | verbose=True): 102 | predictions = outputs["instances"].to("cpu") 103 | if verbose: 104 | print(list(predictions.get_fields())) 105 | indices = [i 106 | for (i, s) in enumerate(predictions.scores) 107 | if s >= threshold 108 | ] 109 | 110 | filtered_predictions = predictions[indices] 111 | 112 | return filtered_predictions 113 | 114 | 115 | for d in random.sample(dataset_dicts, 3): 116 | im = cv2.imread(d["file_name"]) 117 | outputs = predictor(im) 118 | 119 | filtered_predictions = filter_predictions_from_outputs(outputs, 120 | threshold=threshold) 121 | 122 | v = Visualizer(im[:, :, ::-1], 123 | metadata=custom_metadata, 124 | scale=0.5, 125 | ) 126 | out = v.draw_instance_predictions(filtered_predictions) 127 | #cv2_imshow(out.get_image()[:, :, ::-1]) 128 | fig, ax = plt.subplots(ncols=2) 129 | ax[0].imshow(im[:, :, ::-1]) # BGR to RGB 130 | ax[0].set_title('Original Image ') 131 | ax[1].imshow(out.get_image()[:, :, ::-1]) # BGR to RGB 132 | ax[1].set_title('Detected Image') 133 | plt.show() 134 | 135 | 136 | evaluator = COCOEvaluator("custom_val", cfg, False, output_dir=outdir_path) 137 | val_loader = build_detection_test_loader(cfg, "custom_val") 138 | #print(inference_on_dataset(trainer.model, val_loader, evaluator)) 139 | 140 | 141 | def run_worflow(my_image, 142 | my_model, 143 | threshold = 0.7, 144 | verbose=False, filename=None): 145 | start = time.time() 146 | outputs = my_model(my_image) 147 | end = time.time() 148 | elapsed_time = (end - start) * 1000 149 | print("Evaluation Time : {} ms ", elapsed_time) 150 | 151 | filtered_predictions = filter_predictions_from_outputs(outputs, 152 | threshold=threshold, 153 | verbose=verbose) 154 | 155 | # We can use `Visualizer` to draw the predictions on the image. 156 | v = Visualizer(my_image[:, :, ::-1], 157 | custom_metadata, 158 | scale=1.2) 159 | out = v.draw_instance_predictions(filtered_predictions) 160 | #cv2_imshow(out.get_image()[:, :, ::-1]) 161 | fig, ax = plt.subplots(ncols=2, figsize=(20, 10)) 162 | fig.set_dpi(100) 163 | ax[0].imshow(my_image[:, :, ::-1]) # BGR to RGB 164 | ax[0].set_title('Original Image ') 165 | ax[1].imshow(out.get_image()[:, :, ::-1]) # BGR to RGB 166 | ax[1].set_title('Detected Image') 167 | if args['save']: 168 | plt.savefig(filename, dpi=100) 169 | plt.close(fig) 170 | else: 171 | plt.show() 172 | 173 | return 174 | 175 | img_name = '../custom_balloon/val2017/3825919971_93fb1ec581_b.jpg' 176 | im = cv2.imread(img_name) 177 | threshold = 0.7 178 | filename1 = "output_images/{}_output1.png".format(args['arch']) 179 | run_worflow(im, 180 | predictor, 181 | threshold = threshold, 182 | filename=filename1) 183 | 184 | img_name2 = '../custom_balloon/val2017/16335852991_f55de7958d_k.jpg' 185 | im2 = cv2.imread(img_name2) 186 | 187 | filename2 = "output_images/{}_output2.png".format(args['arch']) 188 | run_worflow(im2, 189 | predictor, 190 | threshold = threshold, 191 | filename=filename2) -------------------------------------------------------------------------------- /object_detection_with_detectron2/output_images/detr_output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_detectron2/output_images/detr_output2.png -------------------------------------------------------------------------------- /object_detection_with_detectron2/output_images/dyhead-fpn_output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_detectron2/output_images/dyhead-fpn_output2.png -------------------------------------------------------------------------------- /object_detection_with_detectron2/output_images/dyhead_output1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_detectron2/output_images/dyhead_output1.png -------------------------------------------------------------------------------- /object_detection_with_detectron2/output_images/dyhead_output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_detectron2/output_images/dyhead_output2.png -------------------------------------------------------------------------------- /object_detection_with_detectron2/resources/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_detectron2/resources/github.png -------------------------------------------------------------------------------- /object_detection_with_detectron2/resources/linkedin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_detectron2/resources/linkedin.png -------------------------------------------------------------------------------- /object_detection_with_detectron2/resources/medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_detectron2/resources/medium.png -------------------------------------------------------------------------------- /object_detection_with_detectron2/training.py: -------------------------------------------------------------------------------- 1 | # Usage : python3.8 training.py --outdir out_test/ --arch detr \ 2 | # --config configs/detr_256_6_6_torchvision.yaml \ 3 | # --weight pretrained_model/converted_model.pth --epochs 1 4 | # use dyhead_swint_atss_fpn_2x_ms.yaml for dyhead-swint 5 | 6 | import detectron2 7 | 8 | from detectron2.utils.logger import setup_logger 9 | setup_logger() 10 | import sys 11 | sys.path.append('detr') 12 | sys.path.append('DynamicHead/') 13 | # import some common libraries 14 | import os, json, cv2, random 15 | 16 | # import some common detectron2 utilities 17 | from detectron2.config import get_cfg 18 | from detectron2.utils.visualizer import Visualizer 19 | from detectron2.data import MetadataCatalog, DatasetCatalog 20 | from detectron2.data.datasets import register_coco_instances 21 | 22 | # from detectron2.engine import DefaultTrainer 23 | from d2.train_net import Trainer 24 | from d2.detr import add_detr_config 25 | 26 | from utils.dyhead_trainer import DyHeadTrainer 27 | import matplotlib.pyplot as plt 28 | 29 | import argparse 30 | 31 | from dyhead import add_dyhead_config 32 | from extra import add_extra_config 33 | 34 | ap = argparse.ArgumentParser() 35 | ap.add_argument("-o", "--outdir", required=True, help="output path for the model") 36 | ap.add_argument('-a', '--arch', default='detr', choices=['detr', 'dyhead-fpn', 'dyhead-swint'], help='Choose different transformer based object detection architecture') 37 | ap.add_argument("-c", "--config", required=True, help="config file for the model") 38 | ap.add_argument("-w", "--weight", required=True, help="model weight path") 39 | ap.add_argument("-e", "--epochs", type=int, help="No of Epochs for training") 40 | args = vars(ap.parse_args()) 41 | 42 | register_coco_instances("custom_train", 43 | {}, 44 | "../custom_balloon/annotations/custom_train.json", 45 | "../custom_balloon/train2017/") 46 | 47 | register_coco_instances("custom_val", 48 | {}, 49 | "../custom_balloon/annotations/custom_val.json", 50 | "../custom_balloon/val2017/") 51 | 52 | 53 | LABELS = ["balloon"] 54 | 55 | for keyword in ['train', 'val']: 56 | MetadataCatalog.get('custom_{}'.format(keyword)).set(thing_classes=LABELS) 57 | 58 | custom_metadata = MetadataCatalog.get("custom_train") 59 | 60 | dataset_dicts = DatasetCatalog.get("custom_train") 61 | for d in random.sample(dataset_dicts, 1): 62 | img = cv2.imread(d["file_name"]) 63 | visualizer = Visualizer(img[:, :, ::-1], metadata=custom_metadata, scale=0.5) 64 | out = visualizer.draw_dataset_dict(d) 65 | fig, ax = plt.subplots(ncols=2) 66 | ax[0].imshow(img[:, :, ::-1]) # BGR to RGB 67 | ax[0].set_title('Original Image ') 68 | ax[1].imshow(out.get_image()[:, :, ::-1]) # BGR to RGB 69 | ax[1].set_title('Detected Image') 70 | plt.show() 71 | 72 | 73 | outdir_path = args['outdir'] 74 | weight = args['weight'] 75 | config = args['config'] 76 | epochs = args['epochs'] 77 | print("outdir path : {}".format(outdir_path)) 78 | print("weight file : {}".format(weight)) 79 | print("config file : {}".format(config)) 80 | 81 | cfg = get_cfg() 82 | if args['arch'] == 'detr': 83 | add_detr_config(cfg) 84 | elif args['arch'] == 'dyhead-fpn' or args['arch'] == 'dyhead-swint': 85 | add_dyhead_config(cfg) 86 | add_extra_config(cfg) 87 | 88 | cfg.merge_from_file(config) 89 | 90 | cfg.DATASETS.TRAIN = ("custom_train",) 91 | cfg.DATASETS.TEST = ("custom_val",) 92 | 93 | cfg.OUTPUT_DIR = outdir_path 94 | #print("cfg: {}".format(cfg)) 95 | 96 | if args["arch"] == 'detr': 97 | cfg.MODEL.WEIGHTS = weight 98 | cfg.MODEL.DETR.NUM_CLASSES = len(LABELS) 99 | elif args['arch'] == 'dyhead-fpn': 100 | cfg.MODEL.WEIGHTS = weight #'pretrained_model/dyhead_r50_atss_fpn_1x.pth' 101 | cfg.MODEL.ATSS.NUM_CLASSES = len(LABELS) 102 | elif args['arch'] == 'dyhead-swint': 103 | cfg.MODEL.WEIGHTS = weight #'pretrained_model/dyhead_swint_atss_fpn_2x_ms.pth' 104 | cfg.MODEL.ATSS.NUM_CLASSES = len(LABELS) 105 | 106 | cfg.DATALOADER.NUM_WORKERS = 2 107 | if args["arch"] == 'dyhead-swint': 108 | cfg.SOLVER.IMS_PER_BATCH = 1 109 | else: 110 | cfg.SOLVER.IMS_PER_BATCH = 2 111 | cfg.SOLVER.BASE_LR = 0.00025 # pick a good LR 112 | cfg.SOLVER.MAX_ITER = epochs 113 | cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128 # (default: 512) 114 | cfg.MODEL.ROI_HEADS.NUM_CLASSES = len(LABELS) # only has one class (ballon) 115 | 116 | os.makedirs(cfg.OUTPUT_DIR, exist_ok=True) 117 | trainer = None 118 | if args['arch'] == 'detr': 119 | trainer = Trainer(cfg) 120 | elif args['arch'] == 'dyhead-fpn' or args['arch'] == 'dyhead-swint': 121 | trainer = DyHeadTrainer(cfg) 122 | 123 | trainer.resume_or_load(resume=False) 124 | trainer.train() 125 | -------------------------------------------------------------------------------- /object_detection_with_detectron2/utils/__pycache__/dyhead_trainer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_detectron2/utils/__pycache__/dyhead_trainer.cpython-38.pyc -------------------------------------------------------------------------------- /object_detection_with_detectron2/utils/dyhead_trainer.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import torch, os 3 | 4 | from detectron2.evaluation import COCOEvaluator, verify_results 5 | from detectron2.checkpoint import DetectionCheckpointer 6 | from detectron2.data import build_detection_train_loader, build_detection_test_loader 7 | from detectron2.data.build import get_detection_dataset_dicts 8 | import detectron2.utils.comm as comm 9 | from detectron2.solver.build import maybe_add_gradient_clipping 10 | from detectron2.engine import SimpleTrainer, DefaultTrainer, default_argument_parser, default_setup, launch 11 | 12 | class DyHeadTrainer(DefaultTrainer): 13 | """ 14 | Extension of the Trainer class adapted to DETR. 15 | """ 16 | 17 | def __init__(self, cfg): 18 | """ 19 | Args: 20 | cfg (CfgNode): 21 | """ 22 | super(DefaultTrainer, self).__init__() 23 | logger = logging.getLogger("detectron2") 24 | if not logger.isEnabledFor(logging.INFO): # setup_logger is not called for d2 25 | setup_logger() 26 | cfg = DefaultTrainer.auto_scale_workers(cfg, comm.get_world_size()) 27 | 28 | model = self.build_model(cfg) 29 | optimizer = self.build_optimizer(cfg, model) 30 | data_loader = self.build_train_loader(cfg) 31 | # Build DDP Model with find_unused_parameters to add flexibility. 32 | if comm.get_world_size() > 1: 33 | model = DistributedDataParallel( 34 | model, device_ids=[comm.get_local_rank()], broadcast_buffers=False, 35 | find_unused_parameters=True 36 | ) 37 | self._trainer = SimpleTrainer(model, data_loader, optimizer) 38 | self.scheduler = self.build_lr_scheduler(cfg, optimizer) 39 | self.checkpointer = DetectionCheckpointer( 40 | # Assume you want to save checkpoints together with logs/statistics 41 | model, 42 | cfg.OUTPUT_DIR, 43 | optimizer=optimizer, 44 | scheduler=self.scheduler, 45 | ) 46 | self.start_iter = 0 47 | self.max_iter = cfg.SOLVER.MAX_ITER 48 | self.cfg = cfg 49 | 50 | self.register_hooks(self.build_hooks()) 51 | 52 | @classmethod 53 | def build_evaluator(cls, cfg, dataset_name, output_folder=None): 54 | """ 55 | Create evaluator(s) for a given dataset. 56 | This uses the special metadata "evaluator_type" associated with each builtin dataset. 57 | For your own dataset, you can simply create an evaluator manually in your 58 | script and do not have to worry about the hacky if-else logic here. 59 | """ 60 | if output_folder is None: 61 | output_folder = os.path.join(cfg.OUTPUT_DIR, "inference") 62 | return COCOEvaluator(dataset_name, cfg, True, output_folder) 63 | 64 | @classmethod 65 | def build_train_loader(cls, cfg): 66 | dataset = get_detection_dataset_dicts( 67 | cfg.DATASETS.TRAIN, 68 | filter_empty=cfg.DATALOADER.FILTER_EMPTY_ANNOTATIONS, 69 | min_keypoints=cfg.MODEL.ROI_KEYPOINT_HEAD.MIN_KEYPOINTS_PER_IMAGE 70 | if cfg.MODEL.KEYPOINT_ON 71 | else 0, 72 | proposal_files=cfg.DATASETS.PROPOSAL_FILES_TRAIN if cfg.MODEL.LOAD_PROPOSALS else None, 73 | ) 74 | 75 | mapper = None 76 | if cfg.SEED!=-1: 77 | sampler = TrainingSampler(len(dataset), seed=cfg.SEED) 78 | else: 79 | sampler = None 80 | return build_detection_train_loader(cfg, dataset=dataset, mapper=mapper, sampler=sampler) 81 | 82 | @classmethod 83 | def build_test_loader(cls, cfg, dataset_name): 84 | mapper = None 85 | return build_detection_test_loader(cfg, mapper=mapper, dataset_name=dataset_name) 86 | 87 | @classmethod 88 | def build_optimizer(cls, cfg, model): 89 | params: List[Dict[str, Any]] = [] 90 | memo: Set[torch.nn.parameter.Parameter] = set() 91 | for key, value in model.named_parameters(recurse=True): 92 | if not value.requires_grad: 93 | continue 94 | # Avoid duplicating parameters 95 | if value in memo: 96 | continue 97 | memo.add(value) 98 | lr = cfg.SOLVER.BASE_LR 99 | #weight_decay = cfg.SOLVER.WEIGHT_DECAY 100 | weight_decay = 0.0001 101 | if "bias" in key: 102 | lr = cfg.SOLVER.BASE_LR * cfg.SOLVER.BIAS_LR_FACTOR 103 | #weight_decay = cfg.SOLVER.WEIGHT_DECAY_BIAS 104 | weight_decay = 0.0001 105 | params += [{"params": [value], "lr": lr, "weight_decay": weight_decay}] 106 | 107 | def maybe_add_full_model_gradient_clipping(optim): # optim: the optimizer class 108 | # detectron2 doesn't have full model gradient clipping now 109 | clip_norm_val = cfg.SOLVER.CLIP_GRADIENTS.CLIP_VALUE 110 | enable = ( 111 | cfg.SOLVER.CLIP_GRADIENTS.ENABLED 112 | and cfg.SOLVER.CLIP_GRADIENTS.CLIP_TYPE == "full_model" 113 | and clip_norm_val > 0.0 114 | ) 115 | 116 | class FullModelGradientClippingOptimizer(optim): 117 | def step(self, closure=None): 118 | all_params = itertools.chain(*[x["params"] for x in self.param_groups]) 119 | torch.nn.utils.clip_grad_norm_(all_params, clip_norm_val) 120 | super().step(closure=closure) 121 | 122 | return FullModelGradientClippingOptimizer if enable else optim 123 | 124 | optimizer_type = cfg.SOLVER.OPTIMIZER 125 | if optimizer_type == "SGD": 126 | optimizer = maybe_add_full_model_gradient_clipping(torch.optim.SGD)( 127 | params, cfg.SOLVER.BASE_LR, momentum=cfg.SOLVER.MOMENTUM 128 | ) 129 | elif optimizer_type == "ADAMW": 130 | optimizer = maybe_add_full_model_gradient_clipping(torch.optim.AdamW)( 131 | params, cfg.SOLVER.BASE_LR 132 | ) 133 | else: 134 | raise NotImplementedError(f"no optimizer type {optimizer_type}") 135 | if not cfg.SOLVER.CLIP_GRADIENTS.CLIP_TYPE == "full_model": 136 | optimizer = maybe_add_gradient_clipping(cfg, optimizer) 137 | return optimizer 138 | 139 | def resume_or_load(self, resume=True): 140 | checkpoint = self.checkpointer.resume_or_load(self.cfg.MODEL.WEIGHTS, resume=resume) 141 | if resume and self.checkpointer.has_checkpoint(): 142 | self.start_iter = checkpoint.get("iteration", -1) + 1 143 | -------------------------------------------------------------------------------- /object_detection_with_hugginggface/README.md: -------------------------------------------------------------------------------- 1 | # Object Detection with Trasformer using Huggingface 2 | 3 | ## Dependencies 4 | - Install Huggingface by following steps mentioned in [link](https://huggingface.co/docs/transformers/installation). 5 | - pip install pytorch-lightning 6 | 7 | 8 | ## Dataset Preparation 9 | Ballon Dataset is converted to COCO format & present inside custom_balloon folder. 10 | 11 | ## Usage 12 | 13 | 14 | ### Training: 15 | 16 | Currently Huggingface only supports following trasformer based object detection algorithm: 17 | 18 | - DETR 19 | - Conditional DETR 20 | - Deformable DETR 21 | - YOLOS 22 | 23 | Run the below command for training 24 | 25 | - python3.8 training.py --arch [detr|cond-detr|yolos|def-detr] --path model_output/[detr|cond-detr|yolos|def-detr] --epochs 5000 --profile True. 26 | 27 | --path model_output: Use different folder for different architecture. 28 | 29 | ### Profiling 30 | 31 | ![](output_images/obj-detec-params.png) 32 | 33 | ### Inference: 34 | 35 | Run the below command 36 | 37 | python3.8 inference.py --model model_out/detr --arch detr/cond-detr/yolos/def-detr 38 | 39 | Evaluation time with different model is as follows: 40 | 41 | - Evaluation Time for arch: detr is 762.916088104248 ms. 42 | - Evaluation Time for arch: yolos is 384.78732109069824 ms. 43 | - Evaluation Time for arch: cond-detr is 776.5250205993652 ms. 44 | - Evaluation Time for arch: def-detr is 2585.845708847046 ms. 45 | 46 | ### Output: 47 | 48 | #### Original Image: 49 | 50 | ![](output_images/original.jpg) 51 | 52 | #### DETR Output: 53 | 54 | ![](output_images/output_detr.png) 55 | 56 | #### Cond-DETR Output: 57 | 58 | ![](output_images/output_cond-detr.png) 59 | 60 | 61 | #### Deformable DETR Output: 62 | 63 | ![](output_images/output_def-detr.png) 64 | 65 | #### YOLOS Output: 66 | 67 | ![](output_images/output_yolos.png) 68 | 69 | 70 | ## Conclusion 71 | In the original image, only 7 balloons are present and it was detected correctly with Cond-Detr & Def-Detr. 72 | 73 | Detr model able to predict only 6 balloons & misses 1 prediction.Yolos is able to predict only 5 balloons & 74 | 75 | misses 2 predictions.However,Yolos is the fastest architecture among all,whereas Def-Detr takes longer time 76 | than others.(Note: All the models were trained for 500 epochs). 77 | 78 | So there is a clear trade-off between accuracy & speed.Please check the profiling data mentioned above. 79 | 80 | Accuracy can be improved by finetuning the hyper parameters or with more training. 81 | 82 | But the clear winner in terms of speed is Yolos & in terms of accuracy it's Cond-Detr & Def-Detr. 83 | 84 | 85 | ## References: 86 | 87 | - https://huggingface.co/docs/transformers/tasks/image_classification. 88 | - https://github.com/NielsRogge/Transformers-Tutorials. 89 | - https://arxiv.org/pdf/2005.12872. 90 | - https://arxiv.org/abs/2010.04159. 91 | - https://arxiv.org/pdf/2108.06152. 92 | - https://arxiv.org/pdf/2106.00666. 93 | - https://arxiv.org/pdf/2106.08322. 94 | - https://arxiv.org/abs/2202.09048. 95 | - https://arxiv.org/abs/2111.14330. 96 | 97 | --- 98 | Reach me @ 99 | 100 | [LinkedIn](https://www.linkedin.com/in/satya1507/) [GitHub](https://github.com/satya15july) [Medium](https://medium.com/@satya15july_11937) 101 | -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._10464445726_6f1e3bbe6a_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._10464445726_6f1e3bbe6a_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._12037308314_e16fb3a0f7_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._12037308314_e16fb3a0f7_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._120853323_d4788431b9_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._120853323_d4788431b9_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._12288043903_fe1ea17a4e_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._12288043903_fe1ea17a4e_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._12288355124_5e340d3de3_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._12288355124_5e340d3de3_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._12288446656_2c6a90e6f5_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._12288446656_2c6a90e6f5_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._126700562_8e27720147_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._126700562_8e27720147_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._1297451346_5b92bdac08_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._1297451346_5b92bdac08_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._14321263043_b76ef054d3_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._14321263043_b76ef054d3_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._145053828_e0e748717c_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._145053828_e0e748717c_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._14666848163_8be8e37562_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._14666848163_8be8e37562_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._15290896925_884ab33fd3_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._15290896925_884ab33fd3_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._15331928994_d5b82eb368_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._15331928994_d5b82eb368_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._154446334_5d41cd1375_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._154446334_5d41cd1375_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._155815494_800fc9aa32_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._155815494_800fc9aa32_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._15717689633_5f7f78c28e_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._15717689633_5f7f78c28e_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._16435593892_2aa8118f4a_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._16435593892_2aa8118f4a_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._17156759330_5af4f5a5b8_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._17156759330_5af4f5a5b8_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._17178818589_16e58fc1e5_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._17178818589_16e58fc1e5_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._18849792632_aad23ad513_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._18849792632_aad23ad513_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._2311771643_f46392fcc0_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._2311771643_f46392fcc0_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._2354829160_3f65a6bf6f_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._2354829160_3f65a6bf6f_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._2385899600_94b68350af_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._2385899600_94b68350af_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._24362039530_b151b41a52_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._24362039530_b151b41a52_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._25899693952_7c8b8b9edc_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._25899693952_7c8b8b9edc_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._2685563244_b0d5f7eb67_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._2685563244_b0d5f7eb67_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._2937599387_80e7d6e050_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._2937599387_80e7d6e050_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._321888854_3723b6f10b_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._321888854_3723b6f10b_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._332344155_71be3a3b22_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._332344155_71be3a3b22_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._3342804367_f43682bb80_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._3342804367_f43682bb80_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._34020010494_e5cb88e1c4_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._34020010494_e5cb88e1c4_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._351678851_e2aeebdafd_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._351678851_e2aeebdafd_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._3646097131_e3e1215843_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._3646097131_e3e1215843_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._3927754171_9011487133_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._3927754171_9011487133_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._3945575930_ce99a7e98d_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._3945575930_ce99a7e98d_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._4057490235_2ffdf7d68b_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._4057490235_2ffdf7d68b_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._4543126482_92254ef046_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._4543126482_92254ef046_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._4552737035_3a0a4105fb_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._4552737035_3a0a4105fb_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._485227412_e335662bb5_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._485227412_e335662bb5_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._4864857993_edb62f16ef_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._4864857993_edb62f16ef_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._4887227769_acd2e6127d_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._4887227769_acd2e6127d_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._489752654_777853a0ba_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._489752654_777853a0ba_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._4955354786_337a598e4a_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._4955354786_337a598e4a_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._5013250607_26359229b6_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._5013250607_26359229b6_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._5178670692_63a4365c9c_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._5178670692_63a4365c9c_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._518678836_94d58e3839_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._518678836_94d58e3839_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._5253122239_38b1e7f61c_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._5253122239_38b1e7f61c_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._53500107_d24b11b3c2_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._53500107_d24b11b3c2_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._5560377994_cb597a4af5_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._5560377994_cb597a4af5_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._5674044810_2d9e2243ff_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._5674044810_2d9e2243ff_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._605521662_a470fef77f_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._605521662_a470fef77f_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._6483318883_21facf57cd_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._6483318883_21facf57cd_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._699765866_abaad7274d_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._699765866_abaad7274d_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._7178882742_f090f3ce56_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._7178882742_f090f3ce56_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._7308740338_591f27b631_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._7308740338_591f27b631_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._7488015492_0583857ca0_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._7488015492_0583857ca0_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._8436015314_3a678c1005_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._8436015314_3a678c1005_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._873768102_7d931e5fa3_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._873768102_7d931e5fa3_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._8758393087_76fcd56bd3_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._8758393087_76fcd56bd3_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._9210739293_2b0e0d991e_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._9210739293_2b0e0d991e_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._9330497995_4cf0438cb6_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._9330497995_4cf0438cb6_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/train/._via_region_data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/train/._via_region_data.json -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._14898532020_ba6199dd22_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._14898532020_ba6199dd22_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._16335852991_f55de7958d_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._16335852991_f55de7958d_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._24631331976_defa3bb61f_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._24631331976_defa3bb61f_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._2917282960_06beee649a_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._2917282960_06beee649a_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._3800636873_ace2c2795f_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._3800636873_ace2c2795f_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._3825919971_93fb1ec581_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._3825919971_93fb1ec581_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._410488422_5f8991f26e_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._410488422_5f8991f26e_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._4581425993_72b9b15fc0_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._4581425993_72b9b15fc0_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._4838031651_3e7b5ea5c7_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._4838031651_3e7b5ea5c7_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._5555705118_3390d70abe_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._5555705118_3390d70abe_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._5603212091_2dfe16ea72_b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._5603212091_2dfe16ea72_b.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._6810773040_3d81036d05_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._6810773040_3d81036d05_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._8053085540_a72bd21a64_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._8053085540_a72bd21a64_k.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/__MACOSX/balloon/val/._via_region_data.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/__MACOSX/balloon/val/._via_region_data.json -------------------------------------------------------------------------------- /object_detection_with_hugginggface/convert_coco.py: -------------------------------------------------------------------------------- 1 | import convert as via2coco 2 | 3 | data_path = 'balloon/' 4 | 5 | first_class_index = 0 6 | 7 | for keyword in ['train', 'val']: 8 | 9 | input_dir = data_path + keyword + '/' 10 | input_json = input_dir + 'via_region_data.json' 11 | categories = ['balloon'] 12 | super_categories = ['N/A'] 13 | output_json = input_dir + 'custom_' + keyword + '.json' 14 | 15 | print('Converting {} from VIA format to COCO format'.format(input_json)) 16 | 17 | coco_dict = via2coco.convert( 18 | imgdir=input_dir, 19 | annpath=input_json, 20 | categories=categories, 21 | super_categories=super_categories, 22 | output_file_name=output_json, 23 | first_class_index=first_class_index, 24 | ) 25 | 26 | -------------------------------------------------------------------------------- /object_detection_with_hugginggface/inference.py: -------------------------------------------------------------------------------- 1 | # USAGE: python3.8 inference.py --model --arch <> --save True 2 | # For example, python3.8 inference.py --model model_out/detr --arch detr --save True 3 | import torchvision 4 | import os 5 | import numpy as np 6 | import os 7 | from PIL import Image, ImageDraw 8 | 9 | import pytorch_lightning as pl 10 | from transformers import DetrForObjectDetection, DetrFeatureExtractor, DeformableDetrForObjectDetection 11 | import torch 12 | from transformers import DetrFeatureExtractor 13 | import matplotlib.pyplot as plt 14 | from transformers import AutoModelForObjectDetection, AutoFeatureExtractor 15 | import time 16 | 17 | import argparse 18 | 19 | ap = argparse.ArgumentParser() 20 | ap.add_argument("-m", "--model", required=True, help="path to the model") 21 | ap.add_argument('-a', '--arch', default='detr', choices=['detr', 'cond-detr', 'yolos', 'def-detr'], help='Choose different transformer based object detection architecture') 22 | ap.add_argument("-s", '--save', default=False, type=bool, help='save predicted output') 23 | args = vars(ap.parse_args()) 24 | 25 | device = torch.device("cpu") 26 | 27 | class CocoDetection(torchvision.datasets.CocoDetection): 28 | def __init__(self, img_folder, feature_extractor, train=True): 29 | ann_file = os.path.join(img_folder, "custom_train.json" if train else "custom_val.json") 30 | super(CocoDetection, self).__init__(img_folder, ann_file) 31 | self.feature_extractor = feature_extractor 32 | 33 | def __getitem__(self, idx): 34 | # read in PIL image and target in COCO format 35 | img, target = super(CocoDetection, self).__getitem__(idx) 36 | 37 | # preprocess image and target (converting target to DETR format, resizing + normalization of both image and target) 38 | image_id = self.ids[idx] 39 | target = {'image_id': image_id, 'annotations': target} 40 | encoding = self.feature_extractor(images=img, annotations=target, return_tensors="pt") 41 | pixel_values = encoding["pixel_values"].squeeze() # remove batch dimension 42 | target = encoding["labels"][0] # remove batch dimension 43 | 44 | return pixel_values, target 45 | 46 | model = None 47 | feature_extractor = None 48 | 49 | model_path = args["model"] 50 | # load best saved model checkpoint from the current run 51 | if os.path.exists(model_path): 52 | if args["arch"] == 'detr': 53 | feature_extractor = DetrFeatureExtractor.from_pretrained("facebook/detr-resnet-50") 54 | model = DetrForObjectDetection.from_pretrained(model_path) 55 | 56 | elif args["arch"] == 'cond-detr': 57 | feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/conditional-detr-resnet-50") 58 | model = AutoModelForObjectDetection.from_pretrained(model_path) 59 | elif args["arch"] == 'yolos': 60 | feature_extractor = AutoFeatureExtractor.from_pretrained("hustvl/yolos-small", size=512, max_size=864) 61 | model = AutoModelForObjectDetection.from_pretrained(model_path) 62 | elif args["arch"] == 'def-detr': 63 | feature_extractor = AutoFeatureExtractor.from_pretrained("SenseTime/deformable-detr") 64 | model = DeformableDetrForObjectDetection.from_pretrained(model_path) 65 | print('Loaded {} model from this run.'.format(model_path)) 66 | 67 | train_dataset = CocoDetection(img_folder='../custom_balloon/train2017', feature_extractor=feature_extractor) 68 | val_dataset = CocoDetection(img_folder='../custom_balloon/val2017', feature_extractor=feature_extractor, train=False) 69 | 70 | print("Number of training examples:", len(train_dataset)) 71 | print("Number of validation examples:", len(val_dataset)) 72 | 73 | 74 | cats = train_dataset.coco.cats 75 | id2label = {k: v['name'] for k,v in cats.items()} 76 | print("id2label: {}".format(id2label)) 77 | 78 | #We can use the image_id in target to know which image it is 79 | pixel_values, target = val_dataset[1] 80 | 81 | pixel_values = pixel_values.unsqueeze(0).to(device) 82 | print(pixel_values.shape) 83 | 84 | if args["arch"] == 'detr' or args["arch"] == 'cond-detr' or args["arch"] == 'def-detr': 85 | # forward pass to get class logits and bounding boxes 86 | start = time.time() 87 | outputs = model(pixel_values=pixel_values, pixel_mask=None) 88 | end = time.time() 89 | elapsed_time = (end - start) * 1000 90 | print("Evaluation Time for arch: {} is {} ms ".format(args['arch'], elapsed_time)) 91 | elif args["arch"] == 'yolos': 92 | start = time.time() 93 | outputs = model(pixel_values=pixel_values) 94 | end = time.time() 95 | elapsed_time = (end - start) * 1000 96 | print("Evaluation Time for arch: {} is {} ms ".format(args['arch'],elapsed_time)) 97 | 98 | # colors for visualization 99 | COLORS = [[0.000, 0.447, 0.741], [0.850, 0.325, 0.098], [0.929, 0.694, 0.125], 100 | [0.494, 0.184, 0.556], [0.466, 0.674, 0.188], [0.301, 0.745, 0.933]] 101 | 102 | # for output bounding box post-processing 103 | def box_cxcywh_to_xyxy(x): 104 | x_c, y_c, w, h = x.unbind(1) 105 | b = [(x_c - 0.5 * w), (y_c - 0.5 * h), 106 | (x_c + 0.5 * w), (y_c + 0.5 * h)] 107 | return torch.stack(b, dim=1) 108 | 109 | def rescale_bboxes(out_bbox, size): 110 | img_w, img_h = size 111 | b = box_cxcywh_to_xyxy(out_bbox) 112 | b = b * torch.tensor([img_w, img_h, img_w, img_h], dtype=torch.float32) 113 | return b 114 | 115 | def plot_results(pil_img, prob, boxes): 116 | plt.figure(figsize=(16,10)) 117 | plt.imshow(pil_img) 118 | ax = plt.gca() 119 | colors = COLORS * 100 120 | for p, (xmin, ymin, xmax, ymax), c in zip(prob, boxes.tolist(), colors): 121 | ax.add_patch(plt.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, 122 | fill=False, color=c, linewidth=3)) 123 | cl = p.argmax() 124 | text = f'{id2label[cl.item()]}: {p[cl]:0.2f}' 125 | ax.text(xmin, ymin, text, fontsize=15, 126 | bbox=dict(facecolor='yellow', alpha=0.5)) 127 | plt.axis('off') 128 | if args['save']: 129 | filename = "output_images/output_{}.png".format(args['arch']) 130 | plt.savefig(filename, dpi=100) 131 | else: 132 | plt.show() 133 | 134 | def plot_output(pil_img, scores, labels, boxes): 135 | plt.figure(figsize=(16,10)) 136 | plt.imshow(pil_img) 137 | ax = plt.gca() 138 | colors = COLORS * 100 139 | for score, label, (xmin, ymin, xmax, ymax),c in zip(scores.tolist(), labels.tolist(), boxes.tolist(), colors): 140 | ax.add_patch(plt.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, 141 | fill=False, color=c, linewidth=3)) 142 | text = f'{model.model.config.id2label[label]}: {score:0.2f}' 143 | ax.text(xmin, ymin, text, fontsize=15, 144 | bbox=dict(facecolor='yellow', alpha=0.5)) 145 | plt.axis('off') 146 | if args['save']: 147 | filename = "output_images/output_{}.png".format(args['arch']) 148 | plt.savefig(filename, dpi=100) 149 | else: 150 | plt.show() 151 | 152 | def visualize_predictions(image, outputs, threshold=0.9): 153 | # keep only predictions with confidence >= threshold 154 | probas = outputs.logits.softmax(-1)[0, :, :-1] 155 | keep = probas.max(-1).values > threshold 156 | 157 | # convert predicted boxes from [0; 1] to image scales 158 | bboxes_scaled = rescale_bboxes(outputs.pred_boxes[0, keep].cpu(), image.size) 159 | 160 | # plot results 161 | plot_results(image, probas[keep], bboxes_scaled) 162 | 163 | 164 | image_id = target['image_id'].item() 165 | image = val_dataset.coco.loadImgs(image_id)[0] 166 | image = Image.open(os.path.join('../custom_balloon/val2017', image['file_name'])) 167 | #if args["save"]: 168 | # image.save('original.png') 169 | 170 | if args['arch'] == 'detr' or args['arch'] == 'yolos' : 171 | visualize_predictions(image, outputs) 172 | elif args["arch"] == 'cond-detr' or args['arch'] == 'def-detr': 173 | # rescale bounding boxes 174 | target_sizes = torch.tensor(image.size[::-1], device=device).unsqueeze(0) 175 | results = feature_extractor.post_process(outputs, target_sizes)[0] 176 | keep = results['scores'] > 0.3 177 | plot_output(image, results['scores'][keep], results['labels'][keep], results['boxes'][keep]) 178 | 179 | -------------------------------------------------------------------------------- /object_detection_with_hugginggface/output_images/obj-detec-params.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/output_images/obj-detec-params.png -------------------------------------------------------------------------------- /object_detection_with_hugginggface/output_images/original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/output_images/original.jpg -------------------------------------------------------------------------------- /object_detection_with_hugginggface/output_images/output_cond-detr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/output_images/output_cond-detr.png -------------------------------------------------------------------------------- /object_detection_with_hugginggface/output_images/output_def-detr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/output_images/output_def-detr.png -------------------------------------------------------------------------------- /object_detection_with_hugginggface/output_images/output_detr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/output_images/output_detr.png -------------------------------------------------------------------------------- /object_detection_with_hugginggface/output_images/output_yolos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/output_images/output_yolos.png -------------------------------------------------------------------------------- /object_detection_with_hugginggface/resources/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/resources/github.png -------------------------------------------------------------------------------- /object_detection_with_hugginggface/resources/linkedin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/resources/linkedin.png -------------------------------------------------------------------------------- /object_detection_with_hugginggface/resources/medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satya15july/object_detection_with_transformer/f79caba6b9ddeeff18cba1bece28a9c8ea1651f0/object_detection_with_hugginggface/resources/medium.png -------------------------------------------------------------------------------- /object_detection_with_hugginggface/training.py: -------------------------------------------------------------------------------- 1 | # USAGE train_detr.py --arch <> --path <> --epochs <> --profile True/False 2 | # For example, python3.8 training.py --arch detr --path model_output --epochs 300 3 | 4 | import torchvision 5 | import os 6 | import numpy as np 7 | import os 8 | from PIL import Image, ImageDraw 9 | 10 | import pytorch_lightning as pl 11 | from transformers import DetrConfig, DetrForObjectDetection, DeformableDetrForObjectDetection 12 | from transformers import AutoModelForObjectDetection 13 | from transformers import AutoFeatureExtractor 14 | from transformers import YolosFeatureExtractor, YolosForObjectDetection 15 | from ptflops import get_model_complexity_info 16 | 17 | import torch 18 | from pytorch_lightning import Trainer 19 | from transformers import DetrFeatureExtractor 20 | import matplotlib.pyplot as plt 21 | 22 | import argparse 23 | 24 | ap = argparse.ArgumentParser() 25 | ap.add_argument("-p", "--path", required=True, help="output path to the model") 26 | ap.add_argument('-a', '--arch', default='detr', choices=['detr', 'cond-detr', 'yolos', 'def-detr'], help='Choose different transformer based object detection architecture') 27 | ap.add_argument("-e", "--epochs", type=int, help="No of Epochs for training") 28 | ap.add_argument("-r", '--profile', default=False, type=bool, help='Profiling different model') 29 | 30 | args = vars(ap.parse_args()) 31 | 32 | device = None 33 | 34 | if args["arch"] == 'def-detr': 35 | device = torch.device("cpu") 36 | else: 37 | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 38 | print("device: {}".format(device)) 39 | 40 | class CocoDetection(torchvision.datasets.CocoDetection): 41 | def __init__(self, img_folder, feature_extractor, train=True): 42 | ann_file = os.path.join(img_folder, "custom_train.json" if train else "custom_val.json") 43 | super(CocoDetection, self).__init__(img_folder, ann_file) 44 | self.feature_extractor = feature_extractor 45 | 46 | def __getitem__(self, idx): 47 | # read in PIL image and target in COCO format 48 | img, target = super(CocoDetection, self).__getitem__(idx) 49 | 50 | # preprocess image and target (converting target to DETR format, resizing + normalization of both image and target) 51 | image_id = self.ids[idx] 52 | target = {'image_id': image_id, 'annotations': target} 53 | encoding = self.feature_extractor(images=img, annotations=target, return_tensors="pt") 54 | pixel_values = encoding["pixel_values"].squeeze() # remove batch dimension 55 | target = encoding["labels"][0] # remove batch dimension 56 | 57 | return pixel_values, target 58 | 59 | 60 | feature_extractor = None 61 | 62 | if args["arch"] == 'detr': 63 | feature_extractor = DetrFeatureExtractor.from_pretrained("facebook/detr-resnet-50") 64 | elif args["arch"] == 'cond-detr': 65 | feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/conditional-detr-resnet-50") 66 | elif args["arch"] == 'yolos': 67 | feature_extractor = AutoFeatureExtractor.from_pretrained("hustvl/yolos-small", size=512, max_size=864) 68 | elif args["arch"] == 'def-detr': 69 | feature_extractor = AutoFeatureExtractor.from_pretrained("SenseTime/deformable-detr") 70 | 71 | train_dataset = CocoDetection(img_folder='../custom_balloon/train2017', feature_extractor=feature_extractor) 72 | val_dataset = CocoDetection(img_folder='../custom_balloon/val2017', feature_extractor=feature_extractor, train=False) 73 | 74 | print("Number of training examples:", len(train_dataset)) 75 | print("Number of validation examples:", len(val_dataset)) 76 | 77 | 78 | # based on https://github.com/woctezuma/finetune-detr/blob/master/finetune_detr.ipynb 79 | image_ids = train_dataset.coco.getImgIds() 80 | # let's pick a random image 81 | image_id = image_ids[np.random.randint(0, len(image_ids))] 82 | print('Image n°{}'.format(image_id)) 83 | image = train_dataset.coco.loadImgs(image_id)[0] 84 | image = Image.open(os.path.join('../custom_balloon/train2017', image['file_name'])) 85 | 86 | annotations = train_dataset.coco.imgToAnns[image_id] 87 | draw = ImageDraw.Draw(image, "RGBA") 88 | 89 | cats = train_dataset.coco.cats 90 | id2label = {k: v['name'] for k,v in cats.items()} 91 | 92 | for annotation in annotations: 93 | box = annotation['bbox'] 94 | class_idx = annotation['category_id'] 95 | x,y,w,h = tuple(box) 96 | draw.rectangle((x,y,x+w,y+h), outline='red', width=1) 97 | draw.text((x, y), id2label[class_idx], fill='white') 98 | 99 | image.show() 100 | 101 | from torch.utils.data import DataLoader 102 | 103 | def collate_fn(batch): 104 | pixel_values = [item[0] for item in batch] 105 | encoding = feature_extractor.pad_and_create_pixel_mask(pixel_values, return_tensors="pt") 106 | labels = [item[1] for item in batch] 107 | batch = {} 108 | batch['pixel_values'] = encoding['pixel_values'] 109 | batch['pixel_mask'] = encoding['pixel_mask'] 110 | batch['labels'] = labels 111 | return batch 112 | 113 | 114 | def yolos_collate_fn(batch): 115 | pixel_values = [item[0] for item in batch] 116 | encoding = feature_extractor.pad(pixel_values, return_tensors="pt") 117 | labels = [item[1] for item in batch] 118 | batch = {} 119 | batch['pixel_values'] = encoding['pixel_values'] 120 | batch['labels'] = labels 121 | return batch 122 | 123 | if args["arch"] == 'yolos': 124 | train_dataloader = DataLoader(train_dataset, collate_fn=yolos_collate_fn, batch_size=1, shuffle=True) 125 | val_dataloader = DataLoader(val_dataset, collate_fn=yolos_collate_fn, batch_size=1) 126 | elif args["arch"] == 'def-detr': 127 | train_dataloader = DataLoader(train_dataset, collate_fn=collate_fn, batch_size=1, shuffle=True) 128 | val_dataloader = DataLoader(val_dataset, collate_fn=collate_fn, batch_size=1) 129 | else : 130 | train_dataloader = DataLoader(train_dataset, collate_fn=collate_fn, batch_size=4, shuffle=True) 131 | val_dataloader = DataLoader(val_dataset, collate_fn=collate_fn, batch_size=2) 132 | 133 | batch = next(iter(train_dataloader)) 134 | print(batch.keys()) 135 | 136 | pixel_values, target = train_dataset[0] 137 | 138 | print(pixel_values.shape) 139 | print(target) 140 | 141 | 142 | class ObjectDetector(pl.LightningModule): 143 | def __init__(self, lr, lr_backbone, weight_decay, architecture): 144 | super().__init__() 145 | # replace COCO classification head with custom head 146 | if architecture == 'detr': 147 | self.model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", 148 | num_labels=len(id2label), 149 | ignore_mismatched_sizes=True) 150 | elif architecture == 'cond-detr': 151 | self.model = AutoModelForObjectDetection.from_pretrained("microsoft/conditional-detr-resnet-50", 152 | id2label={0: "balloon"}, 153 | label2id={"balloon": 0}, 154 | ignore_mismatched_sizes=True) 155 | elif architecture == 'def-detr': 156 | self.model = DeformableDetrForObjectDetection.from_pretrained("SenseTime/deformable-detr", 157 | id2label={0: "balloon"}, 158 | label2id={"balloon": 0}, 159 | ignore_mismatched_sizes=True) 160 | self.lr = lr 161 | self.lr_backbone = lr_backbone 162 | self.weight_decay = weight_decay 163 | 164 | def forward(self, pixel_values, pixel_mask): 165 | outputs = self.model(pixel_values=pixel_values, pixel_mask=pixel_mask) 166 | return outputs 167 | 168 | def common_step(self, batch, batch_idx): 169 | pixel_values = batch["pixel_values"] 170 | pixel_mask = batch["pixel_mask"] 171 | labels = [{k: v.to(self.device) for k, v in t.items()} for t in batch["labels"]] 172 | 173 | outputs = self.model(pixel_values=pixel_values, pixel_mask=pixel_mask, labels=labels) 174 | 175 | loss = outputs.loss 176 | loss_dict = outputs.loss_dict 177 | 178 | return loss, loss_dict 179 | 180 | def training_step(self, batch, batch_idx): 181 | loss, loss_dict = self.common_step(batch, batch_idx) 182 | # logs metrics for each training_step, 183 | # and the average across the epoch 184 | self.log("training_loss", loss) 185 | for k,v in loss_dict.items(): 186 | self.log("train_" + k, v.item()) 187 | 188 | return loss 189 | 190 | def validation_step(self, batch, batch_idx): 191 | loss, loss_dict = self.common_step(batch, batch_idx) 192 | self.log("validation_loss", loss) 193 | for k,v in loss_dict.items(): 194 | self.log("validation_" + k, v.item()) 195 | 196 | return loss 197 | 198 | def configure_optimizers(self): 199 | param_dicts = [ 200 | {"params": [p for n, p in self.named_parameters() if "backbone" not in n and p.requires_grad]}, 201 | { 202 | "params": [p for n, p in self.named_parameters() if "backbone" in n and p.requires_grad], 203 | "lr": self.lr_backbone, 204 | }, 205 | ] 206 | optimizer = torch.optim.AdamW(param_dicts, lr=self.lr, 207 | weight_decay=self.weight_decay) 208 | 209 | return optimizer 210 | 211 | def train_dataloader(self): 212 | return train_dataloader 213 | 214 | def val_dataloader(self): 215 | return val_dataloader 216 | def save_model(self, path): 217 | self.model.save_pretrained(path) 218 | 219 | class YoloS(pl.LightningModule): 220 | def __init__(self, lr, weight_decay): 221 | super().__init__() 222 | # replace COCO classification head with custom head 223 | self.model = AutoModelForObjectDetection.from_pretrained("hustvl/yolos-small", 224 | num_labels=len(id2label), 225 | ignore_mismatched_sizes=True) 226 | # see https://github.com/PyTorchLightning/pytorch-lightning/pull/1896 227 | self.lr = lr 228 | self.weight_decay = weight_decay 229 | 230 | def forward(self, pixel_values): 231 | outputs = self.model(pixel_values=pixel_values) 232 | 233 | return outputs 234 | 235 | def common_step(self, batch, batch_idx): 236 | pixel_values = batch["pixel_values"] 237 | labels = [{k: v.to(self.device) for k, v in t.items()} for t in batch["labels"]] 238 | 239 | outputs = self.model(pixel_values=pixel_values, labels=labels) 240 | 241 | loss = outputs.loss 242 | loss_dict = outputs.loss_dict 243 | 244 | return loss, loss_dict 245 | 246 | def training_step(self, batch, batch_idx): 247 | loss, loss_dict = self.common_step(batch, batch_idx) 248 | # logs metrics for each training_step, 249 | # and the average across the epoch 250 | self.log("training_loss", loss) 251 | for k, v in loss_dict.items(): 252 | self.log("train_" + k, v.item()) 253 | 254 | return loss 255 | 256 | def validation_step(self, batch, batch_idx): 257 | loss, loss_dict = self.common_step(batch, batch_idx) 258 | self.log("validation_loss", loss) 259 | for k, v in loss_dict.items(): 260 | self.log("validation_" + k, v.item()) 261 | 262 | return loss 263 | 264 | def configure_optimizers(self): 265 | optimizer = torch.optim.AdamW(self.parameters(), lr=self.lr, 266 | weight_decay=self.weight_decay) 267 | 268 | return optimizer 269 | 270 | def train_dataloader(self): 271 | return train_dataloader 272 | 273 | def val_dataloader(self): 274 | return val_dataloader 275 | 276 | def save_model(self, path): 277 | self.model.save_pretrained(path) 278 | 279 | arch = args["arch"] 280 | model = None 281 | output = None 282 | 283 | if arch == 'detr' or arch == 'cond-detr' or arch == 'def-detr': 284 | model = ObjectDetector(lr=1e-4, lr_backbone=1e-5, weight_decay=1e-4, architecture=arch) 285 | outputs = model(pixel_values=batch['pixel_values'], pixel_mask=batch['pixel_mask']) 286 | elif arch == 'yolos': 287 | model = YoloS(lr=2.5e-5, weight_decay=1e-4) 288 | outputs = model(pixel_values=batch['pixel_values']) 289 | 290 | print("outputs.logits.shape {}".format(outputs.logits.shape)) 291 | 292 | #trainer = Trainer(gpus=1, max_steps=1, gradient_clip_val=0.1) 293 | trainer = Trainer(accelerator='gpu', devices=1, max_steps=args['epochs'], gradient_clip_val=0.1) 294 | trainer.fit(model) 295 | 296 | 297 | model_path = "{}".format(args["arch"]) 298 | outdir = args["path"] 299 | 300 | path = os.path.join(outdir, model_path) 301 | print("path {}".format(path)) 302 | 303 | if not os.path.exists(path): 304 | os.makedirs(os.path.join(outdir, model_path)) 305 | 306 | model.save_model(path) 307 | feature_extractor.save_pretrained(path) 308 | from detr.datasets import get_coco_api_from_dataset 309 | 310 | base_ds = get_coco_api_from_dataset(val_dataset) # this is actually just calling the coco attribute 311 | 312 | from detr.datasets.coco_eval import CocoEvaluator 313 | from tqdm import tqdm 314 | 315 | iou_types = ['bbox'] 316 | coco_evaluator = CocoEvaluator(base_ds, iou_types) # initialize evaluator with ground truths 317 | 318 | model.to(device) 319 | model.eval() 320 | 321 | print("Running evaluation...") 322 | 323 | for idx, batch in enumerate(tqdm(val_dataloader)): 324 | # get the inputs 325 | pixel_values = batch["pixel_values"].to(device) 326 | labels = [{k: v.to(device) for k, v in t.items()} for t in batch["labels"]] # these are in DETR format, resized + normalized 327 | if arch == 'detr' or arch == 'cond-detr': 328 | pixel_mask = batch["pixel_mask"].to(device) 329 | # forward pass 330 | outputs = model.model(pixel_values=pixel_values, pixel_mask=pixel_mask) 331 | elif arch == 'yolos': 332 | outputs = model.model(pixel_values=pixel_values) 333 | orig_target_sizes = torch.stack([target["orig_size"] for target in labels], dim=0) 334 | results = feature_extractor.post_process(outputs, orig_target_sizes) # convert outputs of model to COCO api 335 | res = {target['image_id'].item(): output for target, output in zip(labels, results)} 336 | coco_evaluator.update(res) 337 | 338 | coco_evaluator.synchronize_between_processes() 339 | coco_evaluator.accumulate() 340 | coco_evaluator.summarize() 341 | 342 | 343 | model.to(device) 344 | model.eval() 345 | 346 | #We can use the image_id in target to know which image it is 347 | pixel_values, target = val_dataset[1] 348 | 349 | pixel_values = pixel_values.unsqueeze(0).to(device) 350 | print("pixel_values.shape: {}".format(pixel_values.shape)) 351 | 352 | if args["profile"]: 353 | _, _, width, height = pixel_values.shape 354 | print("Profiling: Input width = {}, height = {}".format(width, height)) 355 | input = (3, width, height) 356 | print("=====START Profile With PTFLOPS========") 357 | macs, params = get_model_complexity_info(model.model, input, as_strings=True, 358 | print_per_layer_stat=True, verbose=True) 359 | print('{:<30} {:<8}'.format('Computational complexity: ', macs)) 360 | print('{:<30} {:<8}'.format('Number of parameters: ', params)) 361 | print("=====END Profile With PTFLOPS========") 362 | 363 | if arch == 'detr' or arch == 'cond-detr': 364 | # forward pass to get class logits and bounding boxes 365 | outputs = model.model(pixel_values=pixel_values, pixel_mask=None) 366 | elif arch == 'yolos': 367 | outputs = model.model(pixel_values=pixel_values) 368 | 369 | 370 | # colors for visualization 371 | COLORS = [[0.000, 0.447, 0.741], [0.850, 0.325, 0.098], [0.929, 0.694, 0.125], 372 | [0.494, 0.184, 0.556], [0.466, 0.674, 0.188], [0.301, 0.745, 0.933]] 373 | 374 | # for output bounding box post-processing 375 | def box_cxcywh_to_xyxy(x): 376 | x_c, y_c, w, h = x.unbind(1) 377 | b = [(x_c - 0.5 * w), (y_c - 0.5 * h), 378 | (x_c + 0.5 * w), (y_c + 0.5 * h)] 379 | return torch.stack(b, dim=1) 380 | 381 | def rescale_bboxes(out_bbox, size): 382 | img_w, img_h = size 383 | b = box_cxcywh_to_xyxy(out_bbox) 384 | b = b * torch.tensor([img_w, img_h, img_w, img_h], dtype=torch.float32) 385 | return b 386 | 387 | def plot_results(pil_img, prob, boxes): 388 | plt.figure(figsize=(16,10)) 389 | plt.imshow(pil_img) 390 | ax = plt.gca() 391 | colors = COLORS * 100 392 | for p, (xmin, ymin, xmax, ymax), c in zip(prob, boxes.tolist(), colors): 393 | ax.add_patch(plt.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, 394 | fill=False, color=c, linewidth=3)) 395 | cl = p.argmax() 396 | text = f'{id2label[cl.item()]}: {p[cl]:0.2f}' 397 | ax.text(xmin, ymin, text, fontsize=15, 398 | bbox=dict(facecolor='yellow', alpha=0.5)) 399 | plt.axis('off') 400 | plt.show() 401 | 402 | def plot_output(pil_img, scores, labels, boxes): 403 | plt.figure(figsize=(16,10)) 404 | plt.imshow(pil_img) 405 | ax = plt.gca() 406 | colors = COLORS * 100 407 | for score, label, (xmin, ymin, xmax, ymax),c in zip(scores.tolist(), labels.tolist(), boxes.tolist(), colors): 408 | ax.add_patch(plt.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, 409 | fill=False, color=c, linewidth=3)) 410 | text = f'{model.model.config.id2label[label]}: {score:0.2f}' 411 | ax.text(xmin, ymin, text, fontsize=15, 412 | bbox=dict(facecolor='yellow', alpha=0.5)) 413 | plt.axis('off') 414 | plt.show() 415 | 416 | def visualize_predictions(image, outputs, threshold=0.9): 417 | # keep only predictions with confidence >= threshold 418 | probas = outputs.logits.softmax(-1)[0, :, :-1] 419 | keep = probas.max(-1).values > threshold 420 | 421 | # convert predicted boxes from [0; 1] to image scales 422 | bboxes_scaled = rescale_bboxes(outputs.pred_boxes[0, keep].cpu(), image.size) 423 | 424 | # plot results 425 | plot_results(pil_img=image, prob=probas[keep], boxes=bboxes_scaled) 426 | 427 | #url = 'http://images.cocodataset.org/val2017/000000039769.jpg' 428 | #image = Image.open(requests.get(url, stream=True).raw) 429 | 430 | image_id = target['image_id'].item() 431 | image = val_dataset.coco.loadImgs(image_id)[0] 432 | image = Image.open(os.path.join('../custom_balloon/val2017', image['file_name'])) 433 | 434 | 435 | if args['arch'] == 'detr' or args['arch'] == 'yolos': 436 | visualize_predictions(image, outputs) 437 | elif args["arch"] == 'cond-detr': 438 | # rescale bounding boxes 439 | target_sizes = torch.tensor(image.size[::-1], device=device).unsqueeze(0) 440 | results = feature_extractor.post_process(outputs, target_sizes)[0] 441 | keep = results['scores'] > 0.3 442 | plot_output(image, results['scores'][keep], results['labels'][keep], results['boxes'][keep]) 443 | 444 | 445 | 446 | 447 | 448 | --------------------------------------------------------------------------------