diff --git a/.gitattributes b/.gitattributes index 3ebe319e56a46e1d03df052e27133de47908f074..f434b47c60d80a08720a1bb4534742deb3f357f1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -67,3 +67,13 @@ analysis/failure_case_analysis/ov_coco/results_legacy/declip_vitl14/predictions. analysis/failure_case_analysis/ov_coco/results_legacy/declip_vitb16/predictions.json filter=lfs diff=lfs merge=lfs -text analysis/failure_case_analysis/ov_coco/results_legacy/clearclip_vitb16/predictions.json filter=lfs diff=lfs merge=lfs -text analysis/failure_case_analysis/ov_coco/results_legacy/clipself_vitb16/predictions.json filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16_bs32.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8_bs32.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8_bs64.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16_bs64.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs32.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs64.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16_bs32.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16_bs64.trt filter=lfs diff=lfs merge=lfs -text diff --git a/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16_bs32.trt b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16_bs32.trt new file mode 100644 index 0000000000000000000000000000000000000000..cfcedaeaad4504c2b0f1959f7d5c697f11b1056e --- /dev/null +++ b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16_bs32.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29b917b175b25acfac2ad0655e65bac25930e34ab3ad16eac9b977043da06c15 +size 173568420 diff --git a/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16_bs64.trt b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16_bs64.trt new file mode 100644 index 0000000000000000000000000000000000000000..50fa4f334bf6b54a5eac181185ba21d1db5dcfbf --- /dev/null +++ b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16_bs64.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ef1b69ed47b2dc1f660c6c79cd1bb0720e7ba27e26a6d4c02bc33ac9121e3ee +size 179789044 diff --git a/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8_bs32.trt b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8_bs32.trt new file mode 100644 index 0000000000000000000000000000000000000000..9c7c0afe614cb0d78497da6105f228dba9c6b6c6 --- /dev/null +++ b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8_bs32.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd9c42d4b29c266b311c0da88a26019dbd7052a78e673bd3b391bebaaf6f21d4 +size 113287940 diff --git a/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8_bs64.trt b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8_bs64.trt new file mode 100644 index 0000000000000000000000000000000000000000..0eeb325c10b50623b05d1dbf26341a71e4e3c51a --- /dev/null +++ b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8_bs64.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e17813f4bfcdc782a1b73009479ad92b73614ea059a5c88797fa73aaf069defb +size 119305716 diff --git a/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16.trt b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16.trt new file mode 100644 index 0000000000000000000000000000000000000000..ec526d32afe505f343eb45fa3a50c61bf2f5ca2d --- /dev/null +++ b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8df71cefc34c4c82187af94f9b320bdf71b60cbb8bb752baf5178bab13fada8c +size 167892740 diff --git a/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16_bs32.trt b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16_bs32.trt new file mode 100644 index 0000000000000000000000000000000000000000..25b6568e0e67426c42936c104dd45ebede488886 --- /dev/null +++ b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16_bs32.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99aa670f5b9b6437476227b406c447f80e641d257d83972e486a3c33fe9790e7 +size 167758308 diff --git a/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16_bs64.trt b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16_bs64.trt new file mode 100644 index 0000000000000000000000000000000000000000..e3afc3e305ddb6fd332271e5ed4ad4e3216bf852 --- /dev/null +++ b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp16_bs64.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31c88f82f75b113c3e3b1521a6a7720f03deb100ff276eb3761c635e5f66a65e +size 167758124 diff --git a/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8.trt b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8.trt new file mode 100644 index 0000000000000000000000000000000000000000..2c38b6c1c8a082d9049cd1add3c7720c4841f140 --- /dev/null +++ b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91a12f04ea949494f2b2d99e13526d87b8ec1c4ed9b6adc72b68d76f2c62d260 +size 107050604 diff --git a/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs32.trt b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs32.trt new file mode 100644 index 0000000000000000000000000000000000000000..d8e0aaddd28ce15bbb4eb330b1e1b018718afce0 --- /dev/null +++ b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs32.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88f459cf16201454da07a9f6c6bb94b97df79a3a5e045809bd1b3ac9b6ff0106 +size 107211564 diff --git a/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs64.trt b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs64.trt new file mode 100644 index 0000000000000000000000000000000000000000..1e8ec7dd5b1d4a61b11376842ed450c5d561ef0d --- /dev/null +++ b/deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs64.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d9b997b23437c243d23b0319990e0afaf3a89ebabd0b9081c9ec3354d14c3ac +size 107287300 diff --git a/downstream/CLIPSelf/clipself_method.jpg b/downstream/CLIPSelf/clipself_method.jpg new file mode 100644 index 0000000000000000000000000000000000000000..27db8454756e22b5324ecb700d9ea834132568a9 --- /dev/null +++ b/downstream/CLIPSelf/clipself_method.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:770b9921130054785e265bc478b2f3b47770f1bab90f750f91f93e69fcb36349 +size 744257 diff --git a/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_EVACLIP_ViTB16.npy b/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_EVACLIP_ViTB16.npy new file mode 100644 index 0000000000000000000000000000000000000000..c89e4c2381a718cccb6e527543494dfb13b0d48b --- /dev/null +++ b/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_EVACLIP_ViTB16.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f680c3d7273b1585341c4d3691fbee4f0756a1db98a507a57edbeb9ca6bd141 +size 272512 diff --git a/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_EVACLIP_ViTL14x336.npy b/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_EVACLIP_ViTL14x336.npy new file mode 100644 index 0000000000000000000000000000000000000000..90fbb909f3d78e5e4dca67183ca8d3ccda5f3b67 --- /dev/null +++ b/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_EVACLIP_ViTL14x336.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63b8bc4912be9e9f30ab8f7e38983ed343f04770a99e3cc322fe0ab8e251061e +size 408704 diff --git a/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_ViTB16.npy b/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_ViTB16.npy new file mode 100644 index 0000000000000000000000000000000000000000..1231a76fc42900a684a0a3681bab73ed9b90566f --- /dev/null +++ b/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_ViTB16.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:feb021a6835fb1bf85e9216d1bbbd3498f1398bb3ea565a98f6cdb61c59843b7 +size 136320 diff --git a/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_ViTL14x336.npy b/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_ViTL14x336.npy new file mode 100644 index 0000000000000000000000000000000000000000..dad3c54a8939f1b6390189b89c01bc1754d5e6dd --- /dev/null +++ b/downstream/CLIPSelf/metadata/coco_panoptic_clip_hand_craft_ViTL14x336.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:42bf7546facaef2a3c49b9451551934aae35d1038cc1bef56388cdc1ad381e59 +size 408704 diff --git a/downstream/CLIPSelf/metadata/coco_pseudo_4764_clip_hand_craft_EVACLIP_ViTB16.npy b/downstream/CLIPSelf/metadata/coco_pseudo_4764_clip_hand_craft_EVACLIP_ViTB16.npy new file mode 100644 index 0000000000000000000000000000000000000000..968ef394ce70fece0f2d5c4e953f7ecc20f2b38f --- /dev/null +++ b/downstream/CLIPSelf/metadata/coco_pseudo_4764_clip_hand_craft_EVACLIP_ViTB16.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c1fb256cd17d203f43ba7562fdb0db80c1fde0a644d5d4d0e6dd0b9489c953e +size 9756800 diff --git a/downstream/CLIPSelf/metadata/coco_pseudo_4764_clip_hand_craft_EVACLIP_ViTL14x336.npy b/downstream/CLIPSelf/metadata/coco_pseudo_4764_clip_hand_craft_EVACLIP_ViTL14x336.npy new file mode 100644 index 0000000000000000000000000000000000000000..9a2c0f9e339f0406ca82a0247cb8cac6b5339ba3 --- /dev/null +++ b/downstream/CLIPSelf/metadata/coco_pseudo_4764_clip_hand_craft_EVACLIP_ViTL14x336.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4555020695b5b06fe824df9e581b2e386ff88e0155da21c1073492f38cd18e98 +size 14635136 diff --git a/downstream/CLIPSelf/src/open_clip/bpe_simple_vocab_16e6.txt.gz b/downstream/CLIPSelf/src/open_clip/bpe_simple_vocab_16e6.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..36a15856e00a06a9fbed8cdd34d2393fea4a3113 --- /dev/null +++ b/downstream/CLIPSelf/src/open_clip/bpe_simple_vocab_16e6.txt.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:924691ac288e54409236115652ad4aa250f48203de50a9e4722a6ecd48d6804a +size 1356917 diff --git a/downstream/CLIPSelf/src/open_clip/eva_clip/bpe_simple_vocab_16e6.txt.gz b/downstream/CLIPSelf/src/open_clip/eva_clip/bpe_simple_vocab_16e6.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..36a15856e00a06a9fbed8cdd34d2393fea4a3113 --- /dev/null +++ b/downstream/CLIPSelf/src/open_clip/eva_clip/bpe_simple_vocab_16e6.txt.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:924691ac288e54409236115652ad4aa250f48203de50a9e4722a6ecd48d6804a +size 1356917 diff --git a/downstream/ProxyCLIP_TPAMI/assets/framework.jpg b/downstream/ProxyCLIP_TPAMI/assets/framework.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0db358b175aab85800ad9795526a03f4e9c2ab92 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/assets/framework.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eb2b4b6dc414eb53e697ca412699da520a2d1a8a7e8626c37f636ccc587d189f +size 267028 diff --git a/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/bpe_simple_vocab_16e6.txt.gz b/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/bpe_simple_vocab_16e6.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..36a15856e00a06a9fbed8cdd34d2393fea4a3113 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/bpe_simple_vocab_16e6.txt.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:924691ac288e54409236115652ad4aa250f48203de50a9e4722a6ecd48d6804a +size 1356917 diff --git a/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/eva_clip/bpe_simple_vocab_16e6.txt.gz b/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/eva_clip/bpe_simple_vocab_16e6.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..36a15856e00a06a9fbed8cdd34d2393fea4a3113 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/eva_clip/bpe_simple_vocab_16e6.txt.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:924691ac288e54409236115652ad4aa250f48203de50a9e4722a6ecd48d6804a +size 1356917 diff --git a/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/tiny_clip/bpe_simple_vocab_16e6.txt.gz b/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/tiny_clip/bpe_simple_vocab_16e6.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..36a15856e00a06a9fbed8cdd34d2393fea4a3113 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/clipself/src/open_clip/tiny_clip/bpe_simple_vocab_16e6.txt.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:924691ac288e54409236115652ad4aa250f48203de50a9e4722a6ecd48d6804a +size 1356917 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/000000029675.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/000000029675.jpg new file mode 100644 index 0000000000000000000000000000000000000000..30d88d2ad59ee8717947fdd0deba62c88a1f49b8 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/000000029675.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59647741cd07304fd4ef6309bf4707c6abf96bc8e654ce632be41f590e5cf65d +size 198588 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/000000045090.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/000000045090.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8da4b88f090b8c90a2f5040e44a18d18d6683165 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/000000045090.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:131ff9a0a419179b934091c97a57ea257b02b8ed80762bc59d639d980a9707e5 +size 83841 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/000000074733.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/000000074733.jpg new file mode 100644 index 0000000000000000000000000000000000000000..bbde5ca0d3b149b9089368228f97d4aef6ac23d5 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/000000074733.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d99c93fb6d22a5d51bbb6e09ca5f10c11bdcf90a711abf6cc83188df52cc456a +size 178821 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/000000080659.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/000000080659.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a6acf9d12284db898696b61a6d03d2e6a8f4621a --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/000000080659.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3bb95ef4d109bf61336656d795b1ba66785c46d23bfdda66a26679cb17da1cf9 +size 187480 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/000000125850.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/000000125850.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5af0dd04ac845de91d27c3c64cc83602fbf973e7 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/000000125850.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51d0940c01b87029725eb725bca9865289c9b350c3bccfb35fca1747440a1857 +size 136641 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/000000130613.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/000000130613.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4ea069b121ba689890592aec79529d459f2f699e --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/000000130613.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b4c5672770a7c09656d7d6feb33381985c4d7e325a59c8758bf93f1151fada7 +size 203291 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/2008_000558.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/2008_000558.jpg new file mode 100644 index 0000000000000000000000000000000000000000..01f272aadbefd1a960bded96de0dd62e0087b16f --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/2008_000558.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:febd0015b69884278a4e25a894d5fb78bc9fef3f5730b52dbaea5d030b004eea +size 105633 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/2008_001135.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/2008_001135.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f2c0d861708f5c7ecd1de045b65e601c45c15230 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/2008_001135.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:76360481a5729b3e002bceb7f7e30fb3c6904fd86efb4ffb84784a53d245003a +size 138199 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/ADE_val_00001101.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/ADE_val_00001101.jpg new file mode 100644 index 0000000000000000000000000000000000000000..995448a78a2c10723f206435a008c4b9e4ee4cb9 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/ADE_val_00001101.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa50dca0baf153c601f1cda3bc397e3fc4ac2f65f116e36f59fffd1d2fe7a9d9 +size 8373 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/airplane.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/airplane.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e2b3c5aef6a6c8366355a31e408622d63d1a485c --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/airplane.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:144df5a7be301bc43d210401e45f216c31b60359b287385695d47ed80316099e +size 42489 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/bailong.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/bailong.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5fc74c7523739e1e66d48c4b4a3a9fb034748d48 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/bailong.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b58a8786fd5351518797ce930b52e3888b0b8fd460204fd5b022831396625480 +size 37717 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/bird.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/bird.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c478a335df322dd1631629363504e0a09bda3d01 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/bird.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8df20dec54eeb3ff9cc3cdc4c5a58e7eab2e02445a3dfa4ff16fa7a65a71bec4 +size 19136 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/bird4.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/bird4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..32930af192af5bca7b3816942c017fea90fe8681 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/bird4.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d5b42eb4e9ac645c2a882e6d3028235761641c652fc25de9df4bcc39e6f80ee +size 197660 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/birds.png b/downstream/ProxyCLIP_TPAMI/demo_images/birds.png new file mode 100644 index 0000000000000000000000000000000000000000..247d8f08572b9f07198e1cc7f36418c1cd902c93 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/birds.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57fceee22cd76dcbd21d9f849447b3eb76f67b735322695db031b7a499c0bdb7 +size 2778642 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/cat.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/cat.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4fab0498027600ff20d454f78588b6c52a78f658 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/cat.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:734498e6d4c39a0ed7a2b767454a07fc9e26d2a24682f48bb2b6707ff9e79c86 +size 88212 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/demo1.jpeg b/downstream/ProxyCLIP_TPAMI/demo_images/demo1.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..6a9bf64328c35594f982edf23c2f441df7b0e646 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/demo1.jpeg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a275beca1977b058ed5b958f952d45b8d48682800f56e7b1ef59b900d1b6c91 +size 235339 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/demo2.png b/downstream/ProxyCLIP_TPAMI/demo_images/demo2.png new file mode 100644 index 0000000000000000000000000000000000000000..651dec820ec7da3c10232c6d49149a4cd22be93a --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/demo2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a152e9cffb4490dd447ab89818c0b778d11bf5c9f612e935174f12a70c935a9f +size 1691738 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/demo3.png b/downstream/ProxyCLIP_TPAMI/demo_images/demo3.png new file mode 100644 index 0000000000000000000000000000000000000000..9e4d06d93e8fe3b8201c085145c32f968b8e793c --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/demo3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8fee342ddd4a761d6d4eb50931615364e506e959da0a9d9203f43d613bfd919a +size 1579419 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/demo4.png b/downstream/ProxyCLIP_TPAMI/demo_images/demo4.png new file mode 100644 index 0000000000000000000000000000000000000000..e7a8952008be484501659142a25c2e9704a6de4c --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/demo4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d9862e51188d9ada3da7bd28e77be4b4ad4ff0a9e4b0283eb6b6fecbfc60368 +size 1411157 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/demo5.png b/downstream/ProxyCLIP_TPAMI/demo_images/demo5.png new file mode 100644 index 0000000000000000000000000000000000000000..86feca1c74feb1f4562e77b6e4397a44e9dd7042 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/demo5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:119875121c22ca1bbae1808232d314c87b64b61648c151d51e336a899ece6238 +size 1784000 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/demo6.png b/downstream/ProxyCLIP_TPAMI/demo_images/demo6.png new file mode 100644 index 0000000000000000000000000000000000000000..065f977109aa0cd19e9bdb9e7d198b0ec8617899 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/demo6.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eff3d14e2cff7bd62a41f39e199296816b3cc96a9c5aa2eba288d31ff4a5c6ba +size 1527484 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/demo7.png b/downstream/ProxyCLIP_TPAMI/demo_images/demo7.png new file mode 100644 index 0000000000000000000000000000000000000000..af963330bc935a9d73abbfa93fa3bcc3d2bf1456 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/demo7.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:24fd5a4242b38180788f2b7e6600ed73de8e454cf4b102f1bedff38eb2535e53 +size 1656515 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/dog.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/dog.jpg new file mode 100644 index 0000000000000000000000000000000000000000..779d280c9f8060cfc94ade68d35aaab7be4fe0c9 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/dog.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4c09f24feb428d9b00c37e2a254a2c61f997097632834355a4ba5f5c30a492e +size 205649 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/dongman.png b/downstream/ProxyCLIP_TPAMI/demo_images/dongman.png new file mode 100644 index 0000000000000000000000000000000000000000..36eaaaa9d957c094c66f1cdca25e5de44e6f7f1c --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/dongman.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c48d8d04d05f98de455acb5333bab596c2855549fc82d618b9fb85fa925e9649 +size 1993267 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/door.png b/downstream/ProxyCLIP_TPAMI/demo_images/door.png new file mode 100644 index 0000000000000000000000000000000000000000..bb6b8501e4868cffac0e297e8daf270b6ba3af63 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/door.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4baa3e5a00813f383a364a91035b8adddbe7c0e80869f47429029a6b15fcc32 +size 62320 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/frankfurt_000000_020215_leftImg8bit.png b/downstream/ProxyCLIP_TPAMI/demo_images/frankfurt_000000_020215_leftImg8bit.png new file mode 100644 index 0000000000000000000000000000000000000000..b2aaa78689cde7045dd6c400336a15036ee0a217 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/frankfurt_000000_020215_leftImg8bit.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08ebee14fb28957b94d4dd5d963f33c6975fe15ac05761155ba2160f304db3cf +size 2501902 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/frankfurt_000001_020693_leftImg8bit.png b/downstream/ProxyCLIP_TPAMI/demo_images/frankfurt_000001_020693_leftImg8bit.png new file mode 100644 index 0000000000000000000000000000000000000000..9741d07606c8911feca7d3de60a1ba552643b7cc --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/frankfurt_000001_020693_leftImg8bit.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1a57d5aba63a5868f96c148decd28632095e5cf41808eb6348a9f5065ca510c +size 2519147 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/horses.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/horses.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2e24986628df0542b3a0a872860487a433ff2199 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/horses.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bdb5acb53dfc78e74008d113b22f5a2fb1e2c7b33cb8eadf4983d709bfe366ba +size 335061 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/hudie.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/hudie.jpg new file mode 100644 index 0000000000000000000000000000000000000000..65513f4330b4aab1d832cd25e8d738869a18b989 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/hudie.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:24185521b8ef8a4a91d9ebc8b41011765354bf2694dccc0e475c5087a9cc5187 +size 630272 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/hudie2.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/hudie2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a2fa270a856e87adb801249db0bcd54692772a0c --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/hudie2.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9afe055f9760e8f444f8a6488fb6cf837f733baf4d6f3f1f26a91d78a5b0264 +size 114844 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/labubu.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/labubu.jpg new file mode 100644 index 0000000000000000000000000000000000000000..30a662b35c609493c5dbb99efa2b4c4dea57437d --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/labubu.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a6fea35437704574bdd38cd48c9a4f42d77be7db9e1de2992297f518018d5fe +size 366723 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/labubu2.png b/downstream/ProxyCLIP_TPAMI/demo_images/labubu2.png new file mode 100644 index 0000000000000000000000000000000000000000..5041b7fa21ca5a58fac3a524ed36980800d3f69c --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/labubu2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c52bf1d0e3dc15f4b66fdcc1f3d3a60cd3d5bc62be8e0019640da5b55bce31ed +size 1822265 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/longmao2.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/longmao2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..050108caf16c168630d06f569c692749680724ee --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/longmao2.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e7ca33109033c2ff1352b2a6505f2b39237364d67656a6a829ba6df6196d4d7 +size 87198 diff --git a/downstream/ProxyCLIP_TPAMI/demo_images/longmao3.jpg b/downstream/ProxyCLIP_TPAMI/demo_images/longmao3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..df2f59a38e668fdd15cbc49473338ebbb8d38c04 --- /dev/null +++ b/downstream/ProxyCLIP_TPAMI/demo_images/longmao3.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb0cb09f2dadf8d184f80802a907b65496dae94a90a80793d82eeed43b7be3b4 +size 98248 diff --git a/third_party/Mask2Former/.gitignore b/third_party/Mask2Former/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9372dae1adc4688ef5f01766cd32365fa0ee2b7a --- /dev/null +++ b/third_party/Mask2Former/.gitignore @@ -0,0 +1,53 @@ +# output dir +output +instant_test_output +inference_test_output + + +*.png +*.json +*.diff +*.jpg +!/projects/DensePose/doc/images/*.jpg + +# compilation and distribution +__pycache__ +_ext +*.pyc +*.pyd +*.so +*.dll +*.egg-info/ +build/ +dist/ +wheels/ + +# pytorch/python/numpy formats +*.pth +*.pkl +*.npy +*.ts +model_ts*.txt + +# ipython/jupyter notebooks +*.ipynb +**/.ipynb_checkpoints/ + +# Editor temporaries +*.swn +*.swo +*.swp +*~ + +# editor settings +.idea +.vscode +_darcs + +# project dirs +/detectron2/model_zoo/configs +/datasets/* +!/datasets/*.* +/projects/*/datasets +/models +/snippet \ No newline at end of file diff --git a/third_party/Mask2Former/ADVANCED_USAGE.md b/third_party/Mask2Former/ADVANCED_USAGE.md new file mode 100644 index 0000000000000000000000000000000000000000..bf595d155c11014e424a9a32747e5ea2140cb61e --- /dev/null +++ b/third_party/Mask2Former/ADVANCED_USAGE.md @@ -0,0 +1,37 @@ +## Advanced Usage of Mask2Former + +This document provides a brief intro of the advanced usage of Mask2Former for research purpose. + +Mask2Former is highly modulized, it consists of three components: a backbone, a pixel decoder and a Transformer decoder. +You can easily replace each of these three components with your own implementation. + +### Test Mask2Former with your own backbone + +1. Define and register your backbone under `mask2former/modeling/backbone`. You can follow the Swin Transformer as an example. +2. Change the config file accordingly. + +### Test Mask2Former with your own pixel decoder + +1. Define and register your pixel decoder under `mask2former/modeling/pixel_decoder`. +2. Change the config file accordingly. + +Note that, your pixel decoder must have a `self.forward_features(features)` methods that returns three values: +1. `mask_features`, which is the per-pixel embeddings with resolution 1/4 of the original image. This is used to produce binary masks. +2. `None`, you can simply return `None` for the second value. +3. `multi_scale_features`, which is the multi-scale inputs to the Transformer decoder. This must be a list with length 3. +We use resolution 1/32, 1/16, and 1/8 but you can use arbitrary resolutions here. + +Example config to use a Transformer-encoder enhanced FPN instead of MSDeformAttn: +``` +MODEL: + SEM_SEG_HEAD: + # pixel decoder + PIXEL_DECODER_NAME: "TransformerEncoderPixelDecoder" + IN_FEATURES: ["res2", "res3", "res4", "res5"] + COMMON_STRIDE: 4 + TRANSFORMER_ENC_LAYERS: 6 +``` + +### Build a new Transformer decoder. + +Transformer decoders are defined under `mask2former/modeling/transformer_decoder`. diff --git a/third_party/Mask2Former/CODE_OF_CONDUCT.md b/third_party/Mask2Former/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000000000000000000000000000000000..0f7ad8bfc173eac554f0b6ef7c684861e8014bbe --- /dev/null +++ b/third_party/Mask2Former/CODE_OF_CONDUCT.md @@ -0,0 +1,5 @@ +# Code of Conduct + +Facebook has adopted a Code of Conduct that we expect project participants to adhere to. +Please read the [full text](https://code.fb.com/codeofconduct/) +so that you can understand what actions will and will not be tolerated. diff --git a/third_party/Mask2Former/CONTRIBUTING.md b/third_party/Mask2Former/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..816c0e21c6b50e6883f6f76df3fc1ff5baf6f662 --- /dev/null +++ b/third_party/Mask2Former/CONTRIBUTING.md @@ -0,0 +1,39 @@ +# Contributing to maskformer2 +We want to make contributing to this project as easy and transparent as +possible. + +## Our Development Process +Minor changes and improvements will be released on an ongoing basis. Larger changes (e.g., changesets implementing a new paper) will be released on a more periodic basis. + +## Pull Requests +We actively welcome your pull requests. + +1. Fork the repo and create your branch from `main`. +2. If you've added code that should be tested, add tests. +3. If you've changed APIs, update the documentation. +4. Ensure the test suite passes. +5. Make sure your code lints. +6. If you haven't already, complete the Contributor License Agreement ("CLA"). + +## Contributor License Agreement ("CLA") +In order to accept your pull request, we need you to submit a CLA. You only need +to do this once to work on any of Facebook's open source projects. + +Complete your CLA here: + +## Issues +We use GitHub issues to track public bugs. Please ensure your description is +clear and has sufficient instructions to be able to reproduce the issue. + +Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe +disclosure of security bugs. In those cases, please go through the process +outlined on that page and do not file a public issue. + +## Coding Style +* 4 spaces for indentation rather than tabs +* 80 character line length +* PEP8 formatting following [Black](https://black.readthedocs.io/en/stable/) + +## License +By contributing to MaskFormer, you agree that your contributions will be licensed +under the LICENSE file in the root directory of this source tree. diff --git a/third_party/Mask2Former/GETTING_STARTED.md b/third_party/Mask2Former/GETTING_STARTED.md new file mode 100644 index 0000000000000000000000000000000000000000..f6fc9a85be12fbc2668f4d83858d06b570645c7f --- /dev/null +++ b/third_party/Mask2Former/GETTING_STARTED.md @@ -0,0 +1,65 @@ +## Getting Started with Mask2Former + +This document provides a brief intro of the usage of Mask2Former. + +Please see [Getting Started with Detectron2](https://github.com/facebookresearch/detectron2/blob/master/GETTING_STARTED.md) for full usage. + + +### Inference Demo with Pre-trained Models + +1. Pick a model and its config file from + [model zoo](MODEL_ZOO.md), + for example, `configs/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml`. +2. We provide `demo.py` that is able to demo builtin configs. Run it with: +``` +cd demo/ +python demo.py --config-file ../configs/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml \ + --input input1.jpg input2.jpg \ + [--other-options] + --opts MODEL.WEIGHTS /path/to/checkpoint_file +``` +The configs are made for training, therefore we need to specify `MODEL.WEIGHTS` to a model from model zoo for evaluation. +This command will run the inference and show visualizations in an OpenCV window. + +For details of the command line arguments, see `demo.py -h` or look at its source code +to understand its behavior. Some common arguments are: +* To run __on your webcam__, replace `--input files` with `--webcam`. +* To run __on a video__, replace `--input files` with `--video-input video.mp4`. +* To run __on cpu__, add `MODEL.DEVICE cpu` after `--opts`. +* To save outputs to a directory (for images) or a file (for webcam or video), use `--output`. + + +### Training & Evaluation in Command Line + +We provide a script `train_net.py`, that is made to train all the configs provided in Mask2Former. + +To train a model with "train_net.py", first +setup the corresponding datasets following +[datasets/README.md](./datasets/README.md), +then run: +``` +python train_net.py --num-gpus 8 \ + --config-file configs/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml +``` + +The configs are made for 8-GPU training. +Since we use ADAMW optimizer, it is not clear how to scale learning rate with batch size. +To train on 1 GPU, you need to figure out learning rate and batch size by yourself: +``` +python train_net.py \ + --config-file configs/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml \ + --num-gpus 1 SOLVER.IMS_PER_BATCH SET_TO_SOME_REASONABLE_VALUE SOLVER.BASE_LR SET_TO_SOME_REASONABLE_VALUE +``` + +To evaluate a model's performance, use +``` +python train_net.py \ + --config-file configs/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml \ + --eval-only MODEL.WEIGHTS /path/to/checkpoint_file +``` +For more options, see `python train_net.py -h`. + + +### Video instance segmentation +Please use `demo_video/demo.py` for video instance segmentation demo and `train_net_video.py` to train +and evaluate video instance segmentation models. diff --git a/third_party/Mask2Former/INSTALL.md b/third_party/Mask2Former/INSTALL.md new file mode 100644 index 0000000000000000000000000000000000000000..e0bbead06e431aca3ce622ffd8a0fa9cc5b7a3a0 --- /dev/null +++ b/third_party/Mask2Former/INSTALL.md @@ -0,0 +1,48 @@ +## Installation + +### Requirements +- Linux or macOS with Python ≥ 3.6 +- PyTorch ≥ 1.9 and [torchvision](https://github.com/pytorch/vision/) that matches the PyTorch installation. + Install them together at [pytorch.org](https://pytorch.org) to make sure of this. Note, please check + PyTorch version matches that is required by Detectron2. +- Detectron2: follow [Detectron2 installation instructions](https://detectron2.readthedocs.io/tutorials/install.html). +- OpenCV is optional but needed by demo and visualization +- `pip install -r requirements.txt` + +### CUDA kernel for MSDeformAttn +After preparing the required environment, run the following command to compile CUDA kernel for MSDeformAttn: + +`CUDA_HOME` must be defined and points to the directory of the installed CUDA toolkit. + +```bash +cd mask2former/modeling/pixel_decoder/ops +sh make.sh +``` + +#### Building on another system +To build on a system that does not have a GPU device but provide the drivers: +```bash +TORCH_CUDA_ARCH_LIST='8.0' FORCE_CUDA=1 python setup.py build install +``` + +### Example conda environment setup +```bash +conda create --name mask2former python=3.8 -y +conda activate mask2former +conda install pytorch==1.9.0 torchvision==0.10.0 cudatoolkit=11.1 -c pytorch -c nvidia +pip install -U opencv-python + +# under your working directory +git clone git@github.com:facebookresearch/detectron2.git +cd detectron2 +pip install -e . +pip install git+https://github.com/cocodataset/panopticapi.git +pip install git+https://github.com/mcordts/cityscapesScripts.git + +cd .. +git clone git@github.com:facebookresearch/Mask2Former.git +cd Mask2Former +pip install -r requirements.txt +cd mask2former/modeling/pixel_decoder/ops +sh make.sh +``` diff --git a/third_party/Mask2Former/LICENSE b/third_party/Mask2Former/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..e884cf166ce12caea257ffb3741ff1e8a3cca79d --- /dev/null +++ b/third_party/Mask2Former/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2022 Meta, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/third_party/Mask2Former/MODEL_ZOO.md b/third_party/Mask2Former/MODEL_ZOO.md new file mode 100644 index 0000000000000000000000000000000000000000..531de4f5686f59b87b0495ba4239a7486c73adcc --- /dev/null +++ b/third_party/Mask2Former/MODEL_ZOO.md @@ -0,0 +1,767 @@ +# Mask2Former Model Zoo and Baselines + +## Introduction + +This file documents a collection of models reported in our paper. +All numbers were obtained on [Big Basin](https://engineering.fb.com/data-center-engineering/introducing-big-basin-our-next-generation-ai-hardware/) +servers with 8 NVIDIA V100 GPUs & NVLink (except Swin-L models are trained with 16 NVIDIA V100 GPUs). + +#### How to Read the Tables +* The "Name" column contains a link to the config file. Running `train_net.py --num-gpus 8` with this config file + will reproduce the model (except Swin-L models are trained with 16 NVIDIA V100 GPUs with distributed training on two nodes). +* The *model id* column is provided for ease of reference. + To check downloaded file integrity, any model on this page contains its md5 prefix in its file name. + +#### Detectron2 ImageNet Pretrained Models + +It's common to initialize from backbone models pre-trained on ImageNet classification tasks. The following backbone models are available: + +* [R-50.pkl (torchvision)](https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/torchvision/R-50.pkl): converted copy of [torchvision's ResNet-50](https://pytorch.org/docs/stable/torchvision/models.html#torchvision.models.resnet50) model. + More details can be found in [the conversion script](tools/convert-torchvision-to-d2.py). +* [R-103.pkl](https://dl.fbaipublicfiles.com/detectron2/DeepLab/R-103.pkl): a ResNet-101 with its first 7x7 convolution replaced by 3 3x3 convolutions. This modification has been used in most semantic segmentation papers (a.k.a. ResNet101c in our paper). We pre-train this backbone on ImageNet using the default recipe of [pytorch examples](https://github.com/pytorch/examples/tree/master/imagenet). + +Note: below are available pretrained models in Detectron2 that we do not use in our paper. +* [R-50.pkl](https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/MSRA/R-50.pkl): converted copy of [MSRA's original ResNet-50](https://github.com/KaimingHe/deep-residual-networks) model. +* [R-101.pkl](https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/MSRA/R-101.pkl): converted copy of [MSRA's original ResNet-101](https://github.com/KaimingHe/deep-residual-networks) model. +* [X-101-32x8d.pkl](https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/FAIR/X-101-32x8d.pkl): ResNeXt-101-32x8d model trained with Caffe2 at FB. + +#### Third-party ImageNet Pretrained Models + +Our paper also uses ImageNet pretrained models that are not part of Detectron2, please refer to [tools](https://github.com/facebookresearch/MaskFormer/tree/master/tools) to get those pretrained models. + +#### License + +All models available for download through this document are licensed under the +[Creative Commons Attribution-NonCommercial 4.0 International License](https://creativecommons.org/licenses/by-nc/4.0/). + +## COCO Model Zoo + +### Panoptic Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneepochsPQAPmIoUmodel iddownload
Mask2FormerR505051.941.761.747430278_4model
Mask2FormerR1015052.642.662.447992113_1model
Mask2FormerSwin-T5053.243.363.248558700_1model
Mask2FormerSwin-S5054.644.764.248558700_3model
Mask2FormerSwin-B5055.145.265.148558700_5model
Mask2FormerSwin-B (IN21k)5056.446.367.148558700_7model
Mask2Former (200 queries)Swin-L (IN21k)10057.848.667.447429163_0model
+ + +### Instance Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneepochsAPBoundary APmodel iddownload
Mask2FormerR505043.730.647430277_2model
Mask2FormerR1015044.231.147992113_0model
Mask2FormerSwin-T5045.031.848558700_0model
Mask2FormerSwin-S5046.332.948558700_2model
Mask2FormerSwin-B5046.733.248558700_4model
Mask2FormerSwin-B (IN21k)5048.134.448558700_6model
Mask2Former (200 queries)Swin-L (IN21k)10050.136.248235555model
+ + +## Cityscapes Model Zoo + +### Panoptic Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsPQAPmIoUmodel iddownload
Mask2FormerR5090k62.137.377.548267400_0model
Mask2FormerR10190k62.437.778.648267400_11model
Mask2FormerSwin-T90k63.939.180.548333144_2model
Mask2FormerSwin-S90k64.840.781.848381916model
Mask2FormerSwin-B (IN21k)90k66.142.882.748333157_2model
Mask2Former (200 queries)Swin-L (IN21k)90k66.643.682.948318254_2model
+ + +### Instance Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsAPAP50model iddownload
Mask2FormerR5090k37.461.948267400_8model
Mask2FormerR10190k38.563.948267400_16model
Mask2FormerSwin-T90k39.766.948333144_4model
Mask2FormerSwin-S90k41.870.448333149_4model
Mask2FormerSwin-B (IN21k)90k42.068.848333157_4model
Mask2Former (200 queries)Swin-L (IN21k)90k43.771.449111004_2model
+ + +### Semantic Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsmIoUmIoU (ms+flip)model iddownload
Mask2FormerR5090k79.482.248267400_4model
Mask2FormerR10190k80.181.948267400_13model
Mask2FormerSwin-T90k82.183.048333144_3model
Mask2FormerSwin-S90k82.683.648333149_3model
Mask2FormerSwin-B (IN21k)90k83.384.548333157_3model
Mask2FormerSwin-L (IN21k)90k83.384.348318254_5model
+ + +## ADE20K Model Zoo + +### Panoptic Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsPQAPmIoUmodel iddownload
Mask2FormerR50160k39.726.546.148243028_0model
Mask2Former (200 queries)Swin-L (IN21k)160k48.134.254.548267279model
+ + +### Instance Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsAPmodel iddownload
Mask2FormerR50160k26.447429167_7model
Mask2Former (200 queries)R50160k34.949040271_0model
+ + +### Semantic Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsmIoUmIoU (ms+flip)model iddownload
Mask2FormerR50160k47.249.247429167_5model
Mask2FormerR101160k47.850.148243040_0model
Mask2FormerSwin-T160k47.749.648333144_5model
Mask2FormerSwin-S160k51.352.448333149_5model
Mask2FormerSwin-B160k52.453.748333153_5model
Mask2FormerSwin-B (IN21k)160k53.955.148333157_5model
Mask2FormerSwin-L (IN21k)160k56.157.348004474_0model
+ + +## Mapillary Vistas Model Zoo + +### Panoptic Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsPQmIoUmodel iddownload
Mask2FormerR50300k36.350.749392417_0model
Mask2Former (200 queries)Swin-L (IN21k)300k45.560.848267065_4model
+ + +### Semantic Segmentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsmIoUmIoU (ms+flip)model iddownload
Mask2FormerR50300k57.459.049189528_1model
Mask2FormerSwin-L (IN21k)300k63.264.749189528_0model
+ + +## Video Instance Segmentation +### YouTubeVIS 2019 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsAPmodel iddownload
Mask2FormerR506k46.451130652_3model
Mask2FormerR1016k49.250897581_1model
Mask2FormerSwin-T6k51.550897611_3model
Mask2FormerSwin-S6k54.350897661_2model
Mask2FormerSwin-B (IN21k)6k59.550897733_2model
Mask2Former (200 queries)Swin-L (IN21k)6k60.450908813_0model
+ + +### YouTubeVIS 2021 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameBackboneiterationsAPmodel iddownload
Mask2FormerR508k40.651130652_7model
Mask2FormerR1018k42.450897581_8model
Mask2FormerSwin-T8k45.950897611_7model
Mask2FormerSwin-S8k48.650897661_7model
Mask2FormerSwin-B (IN21k)8k52.050897733_9model
Mask2Former (200 queries)Swin-L (IN21k)8k52.650908813_6model
diff --git a/third_party/Mask2Former/README.md b/third_party/Mask2Former/README.md new file mode 100644 index 0000000000000000000000000000000000000000..fe0efc036070f97e889e133564fb5f8a84422a93 --- /dev/null +++ b/third_party/Mask2Former/README.md @@ -0,0 +1,78 @@ +# Mask2Former: Masked-attention Mask Transformer for Universal Image Segmentation (CVPR 2022) + +[Bowen Cheng](https://bowenc0221.github.io/), [Ishan Misra](https://imisra.github.io/), [Alexander G. Schwing](https://alexander-schwing.de/), [Alexander Kirillov](https://alexander-kirillov.github.io/), [Rohit Girdhar](https://rohitgirdhar.github.io/) + +[[`arXiv`](https://arxiv.org/abs/2112.01527)] [[`Project`](https://bowenc0221.github.io/mask2former)] [[`BibTeX`](#CitingMask2Former)] + +
+ +

+ +### Features +* A single architecture for panoptic, instance and semantic segmentation. +* Support major segmentation datasets: ADE20K, Cityscapes, COCO, Mapillary Vistas. + +## Updates +* Add Google Colab demo. +* Video instance segmentation is now supported! Please check our [tech report](https://arxiv.org/abs/2112.10764) for more details. + +## Installation + +See [installation instructions](INSTALL.md). + +## Getting Started + +See [Preparing Datasets for Mask2Former](datasets/README.md). + +See [Getting Started with Mask2Former](GETTING_STARTED.md). + +Run our demo using Colab: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1uIWE5KbGFSjrxey2aRd5pWkKNY1_SaNq) + +Integrated into [Huggingface Spaces 🤗](https://huggingface.co/spaces) using [Gradio](https://github.com/gradio-app/gradio). Try out the Web Demo: [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/akhaliq/Mask2Former) + +Replicate web demo and docker image is available here: [![Replicate](https://replicate.com/facebookresearch/mask2former/badge)](https://replicate.com/facebookresearch/mask2former) + +## Advanced usage + +See [Advanced Usage of Mask2Former](ADVANCED_USAGE.md). + +## Model Zoo and Baselines + +We provide a large set of baseline results and trained models available for download in the [Mask2Former Model Zoo](MODEL_ZOO.md). + +## License + +Shield: [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) + +The majority of Mask2Former is licensed under a [MIT License](LICENSE). + + +However portions of the project are available under separate license terms: Swin-Transformer-Semantic-Segmentation is licensed under the [MIT license](https://github.com/SwinTransformer/Swin-Transformer-Semantic-Segmentation/blob/main/LICENSE), Deformable-DETR is licensed under the [Apache-2.0 License](https://github.com/fundamentalvision/Deformable-DETR/blob/main/LICENSE). + +## Citing Mask2Former + +If you use Mask2Former in your research or wish to refer to the baseline results published in the [Model Zoo](MODEL_ZOO.md), please use the following BibTeX entry. + +```BibTeX +@inproceedings{cheng2021mask2former, + title={Masked-attention Mask Transformer for Universal Image Segmentation}, + author={Bowen Cheng and Ishan Misra and Alexander G. Schwing and Alexander Kirillov and Rohit Girdhar}, + journal={CVPR}, + year={2022} +} +``` + +If you find the code useful, please also consider the following BibTeX entry. + +```BibTeX +@inproceedings{cheng2021maskformer, + title={Per-Pixel Classification is Not All You Need for Semantic Segmentation}, + author={Bowen Cheng and Alexander G. Schwing and Alexander Kirillov}, + journal={NeurIPS}, + year={2021} +} +``` + +## Acknowledgement + +Code is largely based on MaskFormer (https://github.com/facebookresearch/MaskFormer). diff --git a/third_party/Mask2Former/cog.yaml b/third_party/Mask2Former/cog.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4476c3a61c8892d22f85ac27bc0a0f4cf76ab04a --- /dev/null +++ b/third_party/Mask2Former/cog.yaml @@ -0,0 +1,28 @@ +build: + gpu: true + cuda: "10.1" + python_version: "3.8" + system_packages: + - "libgl1-mesa-glx" + - "libglib2.0-0" + python_packages: + - "ipython==7.30.1" + - "numpy==1.21.4" + - "torch==1.8.1" + - "torchvision==0.9.1" + - "opencv-python==4.5.5.62" + - "Shapely==1.8.0" + - "h5py==3.6.0" + - "scipy==1.7.3" + - "submitit==1.4.1" + - "scikit-image==0.19.1" + - "Cython==0.29.27" + - "timm==0.4.12" + run: + - pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.8/index.html + - pip install git+https://github.com/cocodataset/panopticapi.git + - pip install git+https://github.com/mcordts/cityscapesScripts.git + - git clone https://github.com/facebookresearch/Mask2Former + - TORCH_CUDA_ARCH_LIST='7.5' FORCE_CUDA=1 python Mask2Former/mask2former/modeling/pixel_decoder/ops/setup.py build install + +predict: "predict.py:Predictor" diff --git a/third_party/Mask2Former/configs/ade20k/instance-segmentation/Base-ADE20K-InstanceSegmentation.yaml b/third_party/Mask2Former/configs/ade20k/instance-segmentation/Base-ADE20K-InstanceSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..50a1c139bd4610a1217696d149c38cf67b25b632 --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/instance-segmentation/Base-ADE20K-InstanceSegmentation.yaml @@ -0,0 +1,61 @@ +MODEL: + BACKBONE: + FREEZE_AT: 0 + NAME: "build_resnet_backbone" + WEIGHTS: "detectron2://ImageNetPretrained/torchvision/R-50.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + RESNETS: + DEPTH: 50 + STEM_TYPE: "basic" # not used + STEM_OUT_CHANNELS: 64 + STRIDE_IN_1X1: False + OUT_FEATURES: ["res2", "res3", "res4", "res5"] + # NORM: "SyncBN" + RES5_MULTI_GRID: [1, 1, 1] # not used +DATASETS: + TRAIN: ("ade20k_instance_train",) + TEST: ("ade20k_instance_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + MAX_ITER: 160000 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 0 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + LR_SCHEDULER_NAME: "WarmupPolyLR" + BACKBONE_MULTIPLIER: 0.1 + CLIP_GRADIENTS: + ENABLED: True + CLIP_TYPE: "full_model" + CLIP_VALUE: 0.01 + NORM_TYPE: 2.0 + AMP: + ENABLED: True +INPUT: + MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 640) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 640 + MAX_SIZE_TRAIN: 2560 + MAX_SIZE_TEST: 2560 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (640, 640) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: 640 # used in dataset mapper + FORMAT: "RGB" + DATASET_MAPPER_NAME: "mask_former_instance" +TEST: + EVAL_PERIOD: 5000 + AUG: + ENABLED: False + MIN_SIZES: [320, 480, 640, 800, 960, 1120] + MAX_SIZE: 4480 + FLIP: True +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/ade20k/instance-segmentation/maskformer2_R50_bs16_160k.yaml b/third_party/Mask2Former/configs/ade20k/instance-segmentation/maskformer2_R50_bs16_160k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e37bcfba579c06fd7d326c2f189e69506c5afb20 --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/instance-segmentation/maskformer2_R50_bs16_160k.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-ADE20K-InstanceSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 255 + NUM_CLASSES: 100 + LOSS_WEIGHT: 1.0 + CONVS_DIM: 256 + MASK_DIM: 256 + NORM: "GN" + # pixel decoder + PIXEL_DECODER_NAME: "MSDeformAttnPixelDecoder" + IN_FEATURES: ["res2", "res3", "res4", "res5"] + DEFORMABLE_TRANSFORMER_ENCODER_IN_FEATURES: ["res3", "res4", "res5"] + COMMON_STRIDE: 4 + TRANSFORMER_ENC_LAYERS: 6 + MASK_FORMER: + TRANSFORMER_DECODER_NAME: "MultiScaleMaskedTransformerDecoder" + TRANSFORMER_IN_FEATURE: "multi_scale_pixel_decoder" + DEEP_SUPERVISION: True + NO_OBJECT_WEIGHT: 0.1 + CLASS_WEIGHT: 2.0 + MASK_WEIGHT: 5.0 + DICE_WEIGHT: 5.0 + HIDDEN_DIM: 256 + NUM_OBJECT_QUERIES: 100 + NHEADS: 8 + DROPOUT: 0.0 + DIM_FEEDFORWARD: 2048 + ENC_LAYERS: 0 + PRE_NORM: False + ENFORCE_INPUT_PROJ: False + SIZE_DIVISIBILITY: 32 + DEC_LAYERS: 10 # 9 decoder layers, add one for the loss on learnable query + TRAIN_NUM_POINTS: 12544 + OVERSAMPLE_RATIO: 3.0 + IMPORTANCE_SAMPLE_RATIO: 0.75 + TEST: + SEMANTIC_ON: True + INSTANCE_ON: True + PANOPTIC_ON: True + OVERLAP_THRESHOLD: 0.8 + OBJECT_MASK_THRESHOLD: 0.8 diff --git a/third_party/Mask2Former/configs/ade20k/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k.yaml b/third_party/Mask2Former/configs/ade20k/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..af03d4d3738f587105eaf35adcfa6643707ba01d --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k.yaml @@ -0,0 +1,18 @@ +_BASE_: ../maskformer2_R50_bs16_160k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 192 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [6, 12, 24, 48] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_large_patch4_window12_384_22k.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + MASK_FORMER: + NUM_OBJECT_QUERIES: 200 diff --git a/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/Base-ADE20K-PanopticSegmentation.yaml b/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/Base-ADE20K-PanopticSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..559be07a1853eb7795b026bc41f94dbe9bcbeebe --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/Base-ADE20K-PanopticSegmentation.yaml @@ -0,0 +1,61 @@ +MODEL: + BACKBONE: + FREEZE_AT: 0 + NAME: "build_resnet_backbone" + WEIGHTS: "detectron2://ImageNetPretrained/torchvision/R-50.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + RESNETS: + DEPTH: 50 + STEM_TYPE: "basic" # not used + STEM_OUT_CHANNELS: 64 + STRIDE_IN_1X1: False + OUT_FEATURES: ["res2", "res3", "res4", "res5"] + # NORM: "SyncBN" + RES5_MULTI_GRID: [1, 1, 1] # not used +DATASETS: + TRAIN: ("ade20k_panoptic_train",) + TEST: ("ade20k_panoptic_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + MAX_ITER: 160000 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 0 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + LR_SCHEDULER_NAME: "WarmupPolyLR" + BACKBONE_MULTIPLIER: 0.1 + CLIP_GRADIENTS: + ENABLED: True + CLIP_TYPE: "full_model" + CLIP_VALUE: 0.01 + NORM_TYPE: 2.0 + AMP: + ENABLED: True +INPUT: + MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 640) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 640 + MAX_SIZE_TRAIN: 2560 + MAX_SIZE_TEST: 2560 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (640, 640) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: 640 # used in dataset mapper + FORMAT: "RGB" + DATASET_MAPPER_NAME: "mask_former_panoptic" +TEST: + EVAL_PERIOD: 5000 + AUG: + ENABLED: False + MIN_SIZES: [320, 480, 640, 800, 960, 1120] + MAX_SIZE: 4480 + FLIP: True +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/maskformer2_R50_bs16_160k.yaml b/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/maskformer2_R50_bs16_160k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..82c0828ce08594790af450cd0bfcd1fc330225fa --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/maskformer2_R50_bs16_160k.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-ADE20K-PanopticSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 255 + NUM_CLASSES: 150 + LOSS_WEIGHT: 1.0 + CONVS_DIM: 256 + MASK_DIM: 256 + NORM: "GN" + # pixel decoder + PIXEL_DECODER_NAME: "MSDeformAttnPixelDecoder" + IN_FEATURES: ["res2", "res3", "res4", "res5"] + DEFORMABLE_TRANSFORMER_ENCODER_IN_FEATURES: ["res3", "res4", "res5"] + COMMON_STRIDE: 4 + TRANSFORMER_ENC_LAYERS: 6 + MASK_FORMER: + TRANSFORMER_DECODER_NAME: "MultiScaleMaskedTransformerDecoder" + TRANSFORMER_IN_FEATURE: "multi_scale_pixel_decoder" + DEEP_SUPERVISION: True + NO_OBJECT_WEIGHT: 0.1 + CLASS_WEIGHT: 2.0 + MASK_WEIGHT: 5.0 + DICE_WEIGHT: 5.0 + HIDDEN_DIM: 256 + NUM_OBJECT_QUERIES: 100 + NHEADS: 8 + DROPOUT: 0.0 + DIM_FEEDFORWARD: 2048 + ENC_LAYERS: 0 + PRE_NORM: False + ENFORCE_INPUT_PROJ: False + SIZE_DIVISIBILITY: 32 + DEC_LAYERS: 10 # 9 decoder layers, add one for the loss on learnable query + TRAIN_NUM_POINTS: 12544 + OVERSAMPLE_RATIO: 3.0 + IMPORTANCE_SAMPLE_RATIO: 0.75 + TEST: + SEMANTIC_ON: True + INSTANCE_ON: True + PANOPTIC_ON: True + OVERLAP_THRESHOLD: 0.8 + OBJECT_MASK_THRESHOLD: 0.8 diff --git a/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k.yaml b/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..af03d4d3738f587105eaf35adcfa6643707ba01d --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k.yaml @@ -0,0 +1,18 @@ +_BASE_: ../maskformer2_R50_bs16_160k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 192 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [6, 12, 24, 48] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_large_patch4_window12_384_22k.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + MASK_FORMER: + NUM_OBJECT_QUERIES: 200 diff --git a/third_party/Mask2Former/configs/ade20k/semantic-segmentation/Base-ADE20K-SemanticSegmentation.yaml b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/Base-ADE20K-SemanticSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..dcbba3e5a85d09535b3f08077764b6e0bb55f36c --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/Base-ADE20K-SemanticSegmentation.yaml @@ -0,0 +1,61 @@ +MODEL: + BACKBONE: + FREEZE_AT: 0 + NAME: "build_resnet_backbone" + WEIGHTS: "detectron2://ImageNetPretrained/torchvision/R-50.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + RESNETS: + DEPTH: 50 + STEM_TYPE: "basic" # not used + STEM_OUT_CHANNELS: 64 + STRIDE_IN_1X1: False + OUT_FEATURES: ["res2", "res3", "res4", "res5"] + # NORM: "SyncBN" + RES5_MULTI_GRID: [1, 1, 1] # not used +DATASETS: + TRAIN: ("ade20k_sem_seg_train",) + TEST: ("ade20k_sem_seg_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + MAX_ITER: 160000 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 0 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + LR_SCHEDULER_NAME: "WarmupPolyLR" + BACKBONE_MULTIPLIER: 0.1 + CLIP_GRADIENTS: + ENABLED: True + CLIP_TYPE: "full_model" + CLIP_VALUE: 0.01 + NORM_TYPE: 2.0 + AMP: + ENABLED: True +INPUT: + MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 512) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 512 + MAX_SIZE_TRAIN: 2048 + MAX_SIZE_TEST: 2048 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (512, 512) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: 512 # used in dataset mapper + FORMAT: "RGB" + DATASET_MAPPER_NAME: "mask_former_semantic" +TEST: + EVAL_PERIOD: 5000 + AUG: + ENABLED: False + MIN_SIZES: [256, 384, 512, 640, 768, 896] + MAX_SIZE: 3584 + FLIP: True +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/ade20k/semantic-segmentation/maskformer2_R101_bs16_90k.yaml b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/maskformer2_R101_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..49407b2a7ebccc62acbe100275fcd26ed8085671 --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/maskformer2_R101_bs16_90k.yaml @@ -0,0 +1,11 @@ +_BASE_: maskformer2_R50_bs16_160k.yaml +MODEL: + WEIGHTS: "R-101.pkl" + RESNETS: + DEPTH: 101 + STEM_TYPE: "basic" # not used + STEM_OUT_CHANNELS: 64 + STRIDE_IN_1X1: False + OUT_FEATURES: ["res2", "res3", "res4", "res5"] + NORM: "SyncBN" + RES5_MULTI_GRID: [1, 1, 1] # not used diff --git a/third_party/Mask2Former/configs/ade20k/semantic-segmentation/maskformer2_R50_bs16_160k.yaml b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/maskformer2_R50_bs16_160k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..cd6d9810926aefdff3b0c63b455746366a9962ad --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/maskformer2_R50_bs16_160k.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-ADE20K-SemanticSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 255 + NUM_CLASSES: 150 + LOSS_WEIGHT: 1.0 + CONVS_DIM: 256 + MASK_DIM: 256 + NORM: "GN" + # pixel decoder + PIXEL_DECODER_NAME: "MSDeformAttnPixelDecoder" + IN_FEATURES: ["res2", "res3", "res4", "res5"] + DEFORMABLE_TRANSFORMER_ENCODER_IN_FEATURES: ["res3", "res4", "res5"] + COMMON_STRIDE: 4 + TRANSFORMER_ENC_LAYERS: 6 + MASK_FORMER: + TRANSFORMER_DECODER_NAME: "MultiScaleMaskedTransformerDecoder" + TRANSFORMER_IN_FEATURE: "multi_scale_pixel_decoder" + DEEP_SUPERVISION: True + NO_OBJECT_WEIGHT: 0.1 + CLASS_WEIGHT: 2.0 + MASK_WEIGHT: 5.0 + DICE_WEIGHT: 5.0 + HIDDEN_DIM: 256 + NUM_OBJECT_QUERIES: 100 + NHEADS: 8 + DROPOUT: 0.0 + DIM_FEEDFORWARD: 2048 + ENC_LAYERS: 0 + PRE_NORM: False + ENFORCE_INPUT_PROJ: False + SIZE_DIVISIBILITY: 32 + DEC_LAYERS: 10 # 9 decoder layers, add one for the loss on learnable query + TRAIN_NUM_POINTS: 12544 + OVERSAMPLE_RATIO: 3.0 + IMPORTANCE_SAMPLE_RATIO: 0.75 + TEST: + SEMANTIC_ON: True + INSTANCE_ON: False + PANOPTIC_ON: False + OVERLAP_THRESHOLD: 0.8 + OBJECT_MASK_THRESHOLD: 0.8 diff --git a/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_base_384_bs16_160k_res640.yaml b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_base_384_bs16_160k_res640.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f2c1964fba09b3662a96647d3745185714db1aeb --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_base_384_bs16_160k_res640.yaml @@ -0,0 +1,37 @@ +_BASE_: ../maskformer2_R50_bs16_160k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 128 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [4, 8, 16, 32] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_base_patch4_window12_384.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 640) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 640 + MAX_SIZE_TRAIN: 2560 + MAX_SIZE_TEST: 2560 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (640, 640) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: 640 # used in dataset mapper + FORMAT: "RGB" +TEST: + EVAL_PERIOD: 5000 + AUG: + ENABLED: False + MIN_SIZES: [320, 480, 640, 800, 960, 1120] + MAX_SIZE: 4480 + FLIP: True diff --git a/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_160k_res640.yaml b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_160k_res640.yaml new file mode 100644 index 0000000000000000000000000000000000000000..68d7e839cd775945362626d0571f3563c7461190 --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_160k_res640.yaml @@ -0,0 +1,37 @@ +_BASE_: ../maskformer2_R50_bs16_160k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 128 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [4, 8, 16, 32] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_base_patch4_window12_384_22k.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 640) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 640 + MAX_SIZE_TRAIN: 2560 + MAX_SIZE_TEST: 2560 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (640, 640) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: 640 # used in dataset mapper + FORMAT: "RGB" +TEST: + EVAL_PERIOD: 5000 + AUG: + ENABLED: False + MIN_SIZES: [320, 480, 640, 800, 960, 1120] + MAX_SIZE: 4480 + FLIP: True diff --git a/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k_res640.yaml b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k_res640.yaml new file mode 100644 index 0000000000000000000000000000000000000000..30d7bb00f1a557654dbcd3af66e0d1534e6ee6d3 --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_160k_res640.yaml @@ -0,0 +1,37 @@ +_BASE_: ../maskformer2_R50_bs16_160k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 192 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [6, 12, 24, 48] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_large_patch4_window12_384_22k.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 640) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 640 + MAX_SIZE_TRAIN: 2560 + MAX_SIZE_TEST: 2560 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (640, 640) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: 640 # used in dataset mapper + FORMAT: "RGB" +TEST: + EVAL_PERIOD: 5000 + AUG: + ENABLED: False + MIN_SIZES: [320, 480, 640, 800, 960, 1120] + MAX_SIZE: 4480 + FLIP: True diff --git a/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_small_bs16_160k.yaml b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_small_bs16_160k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f75a51ed969df634a79f204fac6452bc7e655b35 --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_small_bs16_160k.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_160k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 96 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [3, 6, 12, 24] + WINDOW_SIZE: 7 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + WEIGHTS: "swin_small_patch4_window7_224.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] diff --git a/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_tiny_bs16_160k.yaml b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_tiny_bs16_160k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b0bbc38428758812ca527caae795ee5fd541ccca --- /dev/null +++ b/third_party/Mask2Former/configs/ade20k/semantic-segmentation/swin/maskformer2_swin_tiny_bs16_160k.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_160k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 96 + DEPTHS: [2, 2, 6, 2] + NUM_HEADS: [3, 6, 12, 24] + WINDOW_SIZE: 7 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + WEIGHTS: "swin_tiny_patch4_window7_224.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] diff --git a/third_party/Mask2Former/configs/cityscapes/instance-segmentation/Base-Cityscapes-InstanceSegmentation.yaml b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/Base-Cityscapes-InstanceSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..28833e72e7173a12f1fd0dc352d18c15b5a996c8 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/Base-Cityscapes-InstanceSegmentation.yaml @@ -0,0 +1,61 @@ +MODEL: + BACKBONE: + FREEZE_AT: 0 + NAME: "build_resnet_backbone" + WEIGHTS: "detectron2://ImageNetPretrained/torchvision/R-50.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + RESNETS: + DEPTH: 50 + STEM_TYPE: "basic" # not used + STEM_OUT_CHANNELS: 64 + STRIDE_IN_1X1: False + OUT_FEATURES: ["res2", "res3", "res4", "res5"] + NORM: "SyncBN" # use syncbn for cityscapes dataset + RES5_MULTI_GRID: [1, 1, 1] # not used +DATASETS: + TRAIN: ("cityscapes_fine_instance_seg_train",) + TEST: ("cityscapes_fine_instance_seg_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + MAX_ITER: 90000 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 0 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + LR_SCHEDULER_NAME: "WarmupPolyLR" + BACKBONE_MULTIPLIER: 0.1 + CLIP_GRADIENTS: + ENABLED: True + CLIP_TYPE: "full_model" + CLIP_VALUE: 0.01 + NORM_TYPE: 2.0 + AMP: + ENABLED: True +INPUT: + MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 1024) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 1024 + MAX_SIZE_TRAIN: 4096 + MAX_SIZE_TEST: 2048 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (512, 1024) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: -1 + FORMAT: "RGB" + DATASET_MAPPER_NAME: "mask_former_instance" +TEST: + EVAL_PERIOD: 5000 + AUG: + ENABLED: False + MIN_SIZES: [512, 768, 1024, 1280, 1536, 1792] + MAX_SIZE: 4096 + FLIP: True +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/cityscapes/instance-segmentation/maskformer2_R101_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/maskformer2_R101_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1eb38dacd50b7217118211c757eed7ed8975cad5 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/maskformer2_R101_bs16_90k.yaml @@ -0,0 +1,11 @@ +_BASE_: maskformer2_R50_bs16_90k.yaml +MODEL: + WEIGHTS: "R-101.pkl" + RESNETS: + DEPTH: 101 + STEM_TYPE: "basic" # not used + STEM_OUT_CHANNELS: 64 + STRIDE_IN_1X1: False + OUT_FEATURES: ["res2", "res3", "res4", "res5"] + NORM: "SyncBN" + RES5_MULTI_GRID: [1, 1, 1] # not used diff --git a/third_party/Mask2Former/configs/cityscapes/instance-segmentation/maskformer2_R50_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/maskformer2_R50_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..16b215bf269b54991c36edb8184f0824dd44f3b9 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/maskformer2_R50_bs16_90k.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-Cityscapes-InstanceSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 255 + NUM_CLASSES: 8 + LOSS_WEIGHT: 1.0 + CONVS_DIM: 256 + MASK_DIM: 256 + NORM: "GN" + # pixel decoder + PIXEL_DECODER_NAME: "MSDeformAttnPixelDecoder" + IN_FEATURES: ["res2", "res3", "res4", "res5"] + DEFORMABLE_TRANSFORMER_ENCODER_IN_FEATURES: ["res3", "res4", "res5"] + COMMON_STRIDE: 4 + TRANSFORMER_ENC_LAYERS: 6 + MASK_FORMER: + TRANSFORMER_DECODER_NAME: "MultiScaleMaskedTransformerDecoder" + TRANSFORMER_IN_FEATURE: "multi_scale_pixel_decoder" + DEEP_SUPERVISION: True + NO_OBJECT_WEIGHT: 0.1 + CLASS_WEIGHT: 2.0 + MASK_WEIGHT: 5.0 + DICE_WEIGHT: 5.0 + HIDDEN_DIM: 256 + NUM_OBJECT_QUERIES: 100 + NHEADS: 8 + DROPOUT: 0.0 + DIM_FEEDFORWARD: 2048 + ENC_LAYERS: 0 + PRE_NORM: False + ENFORCE_INPUT_PROJ: False + SIZE_DIVISIBILITY: 32 + DEC_LAYERS: 10 # 9 decoder layers, add one for the loss on learnable query + TRAIN_NUM_POINTS: 12544 + OVERSAMPLE_RATIO: 3.0 + IMPORTANCE_SAMPLE_RATIO: 0.75 + TEST: + SEMANTIC_ON: False + INSTANCE_ON: True + PANOPTIC_ON: False + OVERLAP_THRESHOLD: 0.8 + OBJECT_MASK_THRESHOLD: 0.8 diff --git a/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2956571482f8badb00eaccdb1c58fcba9417a5ae --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_90k.yaml @@ -0,0 +1,16 @@ +_BASE_: ../maskformer2_R50_bs16_90k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 128 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [4, 8, 16, 32] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_base_patch4_window12_384_22k.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] diff --git a/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..72860d91f53ac1de36626624250f5753488834ac --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_90k.yaml @@ -0,0 +1,18 @@ +_BASE_: ../maskformer2_R50_bs16_90k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 192 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [6, 12, 24, 48] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_large_patch4_window12_384_22k.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + MASK_FORMER: + NUM_OBJECT_QUERIES: 200 diff --git a/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_small_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_small_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..156ef9e1f57cfbccb5132a2877509dbd15366b7f --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_small_bs16_90k.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_90k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 96 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [3, 6, 12, 24] + WINDOW_SIZE: 7 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + WEIGHTS: "swin_small_patch4_window7_224.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] diff --git a/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_tiny_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_tiny_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0c56e2cc5287461bda7982f9b94a2f5a5a081dd4 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/instance-segmentation/swin/maskformer2_swin_tiny_bs16_90k.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_90k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 96 + DEPTHS: [2, 2, 6, 2] + NUM_HEADS: [3, 6, 12, 24] + WINDOW_SIZE: 7 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + WEIGHTS: "swin_tiny_patch4_window7_224.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] diff --git a/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/Base-Cityscapes-PanopticSegmentation.yaml b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/Base-Cityscapes-PanopticSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..022567c1c5acc9a73051cc0c350a90e873af4deb --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/Base-Cityscapes-PanopticSegmentation.yaml @@ -0,0 +1,61 @@ +MODEL: + BACKBONE: + FREEZE_AT: 0 + NAME: "build_resnet_backbone" + WEIGHTS: "detectron2://ImageNetPretrained/torchvision/R-50.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + RESNETS: + DEPTH: 50 + STEM_TYPE: "basic" # not used + STEM_OUT_CHANNELS: 64 + STRIDE_IN_1X1: False + OUT_FEATURES: ["res2", "res3", "res4", "res5"] + NORM: "SyncBN" # use syncbn for cityscapes dataset + RES5_MULTI_GRID: [1, 1, 1] # not used +DATASETS: + TRAIN: ("cityscapes_fine_panoptic_train",) + TEST: ("cityscapes_fine_panoptic_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + MAX_ITER: 90000 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 0 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + LR_SCHEDULER_NAME: "WarmupPolyLR" + BACKBONE_MULTIPLIER: 0.1 + CLIP_GRADIENTS: + ENABLED: True + CLIP_TYPE: "full_model" + CLIP_VALUE: 0.01 + NORM_TYPE: 2.0 + AMP: + ENABLED: True +INPUT: + MIN_SIZE_TRAIN: !!python/object/apply:eval ["[int(x * 0.1 * 1024) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 1024 + MAX_SIZE_TRAIN: 4096 + MAX_SIZE_TEST: 2048 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (512, 1024) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: -1 + FORMAT: "RGB" + DATASET_MAPPER_NAME: "mask_former_panoptic" +TEST: + EVAL_PERIOD: 5000 + AUG: + ENABLED: False + MIN_SIZES: [512, 768, 1024, 1280, 1536, 1792] + MAX_SIZE: 4096 + FLIP: True +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/maskformer2_R101_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/maskformer2_R101_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1eb38dacd50b7217118211c757eed7ed8975cad5 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/maskformer2_R101_bs16_90k.yaml @@ -0,0 +1,11 @@ +_BASE_: maskformer2_R50_bs16_90k.yaml +MODEL: + WEIGHTS: "R-101.pkl" + RESNETS: + DEPTH: 101 + STEM_TYPE: "basic" # not used + STEM_OUT_CHANNELS: 64 + STRIDE_IN_1X1: False + OUT_FEATURES: ["res2", "res3", "res4", "res5"] + NORM: "SyncBN" + RES5_MULTI_GRID: [1, 1, 1] # not used diff --git a/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/maskformer2_R50_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/maskformer2_R50_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3c2d679fcff0720da6f8977a7a582583b77185c7 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/maskformer2_R50_bs16_90k.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-Cityscapes-PanopticSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 255 + NUM_CLASSES: 19 + LOSS_WEIGHT: 1.0 + CONVS_DIM: 256 + MASK_DIM: 256 + NORM: "GN" + # pixel decoder + PIXEL_DECODER_NAME: "MSDeformAttnPixelDecoder" + IN_FEATURES: ["res2", "res3", "res4", "res5"] + DEFORMABLE_TRANSFORMER_ENCODER_IN_FEATURES: ["res3", "res4", "res5"] + COMMON_STRIDE: 4 + TRANSFORMER_ENC_LAYERS: 6 + MASK_FORMER: + TRANSFORMER_DECODER_NAME: "MultiScaleMaskedTransformerDecoder" + TRANSFORMER_IN_FEATURE: "multi_scale_pixel_decoder" + DEEP_SUPERVISION: True + NO_OBJECT_WEIGHT: 0.1 + CLASS_WEIGHT: 2.0 + MASK_WEIGHT: 5.0 + DICE_WEIGHT: 5.0 + HIDDEN_DIM: 256 + NUM_OBJECT_QUERIES: 100 + NHEADS: 8 + DROPOUT: 0.0 + DIM_FEEDFORWARD: 2048 + ENC_LAYERS: 0 + PRE_NORM: False + ENFORCE_INPUT_PROJ: False + SIZE_DIVISIBILITY: 32 + DEC_LAYERS: 10 # 9 decoder layers, add one for the loss on learnable query + TRAIN_NUM_POINTS: 12544 + OVERSAMPLE_RATIO: 3.0 + IMPORTANCE_SAMPLE_RATIO: 0.75 + TEST: + SEMANTIC_ON: True + INSTANCE_ON: True + PANOPTIC_ON: True + OVERLAP_THRESHOLD: 0.8 + OBJECT_MASK_THRESHOLD: 0.8 diff --git a/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2956571482f8badb00eaccdb1c58fcba9417a5ae --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_90k.yaml @@ -0,0 +1,16 @@ +_BASE_: ../maskformer2_R50_bs16_90k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 128 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [4, 8, 16, 32] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_base_patch4_window12_384_22k.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] diff --git a/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..72860d91f53ac1de36626624250f5753488834ac --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_90k.yaml @@ -0,0 +1,18 @@ +_BASE_: ../maskformer2_R50_bs16_90k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 192 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [6, 12, 24, 48] + WINDOW_SIZE: 12 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + PRETRAIN_IMG_SIZE: 384 + WEIGHTS: "swin_large_patch4_window12_384_22k.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + MASK_FORMER: + NUM_OBJECT_QUERIES: 200 diff --git a/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_small_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_small_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..156ef9e1f57cfbccb5132a2877509dbd15366b7f --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_small_bs16_90k.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_90k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 96 + DEPTHS: [2, 2, 18, 2] + NUM_HEADS: [3, 6, 12, 24] + WINDOW_SIZE: 7 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + WEIGHTS: "swin_small_patch4_window7_224.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] diff --git a/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_tiny_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_tiny_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0c56e2cc5287461bda7982f9b94a2f5a5a081dd4 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/panoptic-segmentation/swin/maskformer2_swin_tiny_bs16_90k.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_90k.yaml +MODEL: + BACKBONE: + NAME: "D2SwinTransformer" + SWIN: + EMBED_DIM: 96 + DEPTHS: [2, 2, 6, 2] + NUM_HEADS: [3, 6, 12, 24] + WINDOW_SIZE: 7 + APE: False + DROP_PATH_RATE: 0.3 + PATCH_NORM: True + WEIGHTS: "swin_tiny_patch4_window7_224.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] diff --git a/third_party/Mask2Former/predict.py b/third_party/Mask2Former/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..453479c2429b65aa37bb8f8cdad70101ea7f6988 --- /dev/null +++ b/third_party/Mask2Former/predict.py @@ -0,0 +1,54 @@ +import sys +sys.path.insert(0, "Mask2Former") +import tempfile +from pathlib import Path +import numpy as np +import cv2 +import cog + +# import some common detectron2 utilities +from detectron2.config import CfgNode as CN +from detectron2.engine import DefaultPredictor +from detectron2.config import get_cfg +from detectron2.utils.visualizer import Visualizer, ColorMode +from detectron2.data import MetadataCatalog +from detectron2.projects.deeplab import add_deeplab_config + +# import Mask2Former project +from mask2former import add_maskformer2_config + + +class Predictor(cog.Predictor): + def setup(self): + cfg = get_cfg() + add_deeplab_config(cfg) + add_maskformer2_config(cfg) + cfg.merge_from_file("Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_100ep.yaml") + cfg.MODEL.WEIGHTS = 'model_final_f07440.pkl' + cfg.MODEL.MASK_FORMER.TEST.SEMANTIC_ON = True + cfg.MODEL.MASK_FORMER.TEST.INSTANCE_ON = True + cfg.MODEL.MASK_FORMER.TEST.PANOPTIC_ON = True + self.predictor = DefaultPredictor(cfg) + self.coco_metadata = MetadataCatalog.get("coco_2017_val_panoptic") + + + @cog.input( + "image", + type=Path, + help="Input image for segmentation. Output will be the concatenation of Panoptic segmentation (top), " + "instance segmentation (middle), and semantic segmentation (bottom).", + ) + def predict(self, image): + im = cv2.imread(str(image)) + outputs = self.predictor(im) + v = Visualizer(im[:, :, ::-1], self.coco_metadata, scale=1.2, instance_mode=ColorMode.IMAGE_BW) + panoptic_result = v.draw_panoptic_seg(outputs["panoptic_seg"][0].to("cpu"), + outputs["panoptic_seg"][1]).get_image() + v = Visualizer(im[:, :, ::-1], self.coco_metadata, scale=1.2, instance_mode=ColorMode.IMAGE_BW) + instance_result = v.draw_instance_predictions(outputs["instances"].to("cpu")).get_image() + v = Visualizer(im[:, :, ::-1], self.coco_metadata, scale=1.2, instance_mode=ColorMode.IMAGE_BW) + semantic_result = v.draw_sem_seg(outputs["sem_seg"].argmax(0).to("cpu")).get_image() + result = np.concatenate((panoptic_result, instance_result, semantic_result), axis=0)[:, :, ::-1] + out_path = Path(tempfile.mkdtemp()) / "out.png" + cv2.imwrite(str(out_path), result) + return out_path diff --git a/third_party/Mask2Former/requirements.txt b/third_party/Mask2Former/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/third_party/Mask2Former/setup.py b/third_party/Mask2Former/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..391ed5456983db28a1cd851c82576cba19b77820 --- /dev/null +++ b/third_party/Mask2Former/setup.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# Copyright (c) Facebook, Inc. and its affiliates. + +import glob +import os +from os import path +from setuptools import find_packages, setup +import torch +from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension + +torch_ver = [int(x) for x in torch.__version__.split(".")[:2]] +assert torch_ver >= [1, 8], "Requires PyTorch >= 1.8" + + +def get_version(): + init_py_path = path.join(path.abspath(path.dirname(__file__)), "mask2former", "__init__.py") + init_py = open(init_py_path, "r").readlines() + version_line = [l.strip() for l in init_py if l.startswith("__version__")][0] + version = version_line.split("=")[-1].strip().strip("'\"") + + return version + + +# Copied from Detectron2 +def get_extensions(): + # skip building + if not (os.environ.get("FORCE_CUDA") or torch.cuda.is_available()) or CUDA_HOME is None: + return [] + + this_dir = os.path.dirname(os.path.abspath(__file__)) + extensions_dir = os.path.join(this_dir, "mask2former/modeling/pixel_decoder/ops/src") + + main_file = glob.glob(os.path.join(extensions_dir, "*.cpp")) + source_cpu = glob.glob(os.path.join(extensions_dir, "cpu", "*.cpp")) + source_cuda = glob.glob(os.path.join(extensions_dir, "cuda", "*.cu")) + + sources = main_file + source_cpu + extension = CppExtension + extra_compile_args = {"cxx": []} + define_macros = [] + + # Force cuda since torch ask for a device, not if cuda is in fact available. + if (os.environ.get("FORCE_CUDA") or torch.cuda.is_available()) and CUDA_HOME is not None: + extension = CUDAExtension + sources += source_cuda + define_macros += [("WITH_CUDA", None)] + extra_compile_args["nvcc"] = [ + "-DCUDA_HAS_FP16=1", + "-D__CUDA_NO_HALF_OPERATORS__", + "-D__CUDA_NO_HALF_CONVERSIONS__", + "-D__CUDA_NO_HALF2_OPERATORS__", + ] + else: + if CUDA_HOME is None: + raise NotImplementedError( + "CUDA_HOME is None. Please set environment variable CUDA_HOME." + ) + else: + raise NotImplementedError( + "No CUDA runtime is found. Please set FORCE_CUDA=1 or test it by running torch.cuda.is_available()." # noqa + ) + + sources = [os.path.join(extensions_dir, s) for s in sources] + include_dirs = [extensions_dir] + ext_modules = [ + extension( + "MultiScaleDeformableAttention", + sources, + include_dirs=include_dirs, + define_macros=define_macros, + extra_compile_args=extra_compile_args, + ) + ] + return ext_modules + + +setup( + name="mask2former", + version=get_version(), + author="Bowen Cheng", # Thanks Bowen! + url="https://github.com/facebook/mask2former", + description="A pip installable version of mask2former", + packages=find_packages(exclude=("configs", "tests*")), + python_requires=">=3.6", + install_requires=[ + ], + ext_modules=get_extensions(), + cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension}, +) diff --git a/third_party/Mask2Former/train_net.py b/third_party/Mask2Former/train_net.py new file mode 100644 index 0000000000000000000000000000000000000000..4c0af983fccd0b1042e67d1771bee922567d419c --- /dev/null +++ b/third_party/Mask2Former/train_net.py @@ -0,0 +1,328 @@ +# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved +""" +MaskFormer Training Script. + +This script is a simplified version of the training script in detectron2/tools. +""" +try: + # ignore ShapelyDeprecationWarning from fvcore + from shapely.errors import ShapelyDeprecationWarning + import warnings + warnings.filterwarnings('ignore', category=ShapelyDeprecationWarning) +except: + pass + +import copy +import itertools +import logging +import os + +from collections import OrderedDict +from typing import Any, Dict, List, Set + +import torch + +import detectron2.utils.comm as comm +from detectron2.checkpoint import DetectionCheckpointer +from detectron2.config import get_cfg +from detectron2.data import MetadataCatalog, build_detection_train_loader +from detectron2.engine import ( + DefaultTrainer, + default_argument_parser, + default_setup, + launch, +) +from detectron2.evaluation import ( + CityscapesInstanceEvaluator, + CityscapesSemSegEvaluator, + COCOEvaluator, + COCOPanopticEvaluator, + DatasetEvaluators, + LVISEvaluator, + SemSegEvaluator, + verify_results, +) +from detectron2.projects.deeplab import add_deeplab_config, build_lr_scheduler +from detectron2.solver.build import maybe_add_gradient_clipping +from detectron2.utils.logger import setup_logger + +# MaskFormer +from mask2former import ( + COCOInstanceNewBaselineDatasetMapper, + COCOPanopticNewBaselineDatasetMapper, + InstanceSegEvaluator, + MaskFormerInstanceDatasetMapper, + MaskFormerPanopticDatasetMapper, + MaskFormerSemanticDatasetMapper, + SemanticSegmentorWithTTA, + add_maskformer2_config, +) + + +class Trainer(DefaultTrainer): + """ + Extension of the Trainer class adapted to MaskFormer. + """ + + @classmethod + def build_evaluator(cls, cfg, dataset_name, output_folder=None): + """ + Create evaluator(s) for a given dataset. + This uses the special metadata "evaluator_type" associated with each + builtin dataset. For your own dataset, you can simply create an + evaluator manually in your script and do not have to worry about the + hacky if-else logic here. + """ + if output_folder is None: + output_folder = os.path.join(cfg.OUTPUT_DIR, "inference") + evaluator_list = [] + evaluator_type = MetadataCatalog.get(dataset_name).evaluator_type + # semantic segmentation + if evaluator_type in ["sem_seg", "ade20k_panoptic_seg"]: + evaluator_list.append( + SemSegEvaluator( + dataset_name, + distributed=True, + output_dir=output_folder, + ) + ) + # instance segmentation + if evaluator_type == "coco": + evaluator_list.append(COCOEvaluator(dataset_name, output_dir=output_folder)) + # panoptic segmentation + if evaluator_type in [ + "coco_panoptic_seg", + "ade20k_panoptic_seg", + "cityscapes_panoptic_seg", + "mapillary_vistas_panoptic_seg", + ]: + if cfg.MODEL.MASK_FORMER.TEST.PANOPTIC_ON: + evaluator_list.append(COCOPanopticEvaluator(dataset_name, output_folder)) + # COCO + if evaluator_type == "coco_panoptic_seg" and cfg.MODEL.MASK_FORMER.TEST.INSTANCE_ON: + evaluator_list.append(COCOEvaluator(dataset_name, output_dir=output_folder)) + if evaluator_type == "coco_panoptic_seg" and cfg.MODEL.MASK_FORMER.TEST.SEMANTIC_ON: + evaluator_list.append(SemSegEvaluator(dataset_name, distributed=True, output_dir=output_folder)) + # Mapillary Vistas + if evaluator_type == "mapillary_vistas_panoptic_seg" and cfg.MODEL.MASK_FORMER.TEST.INSTANCE_ON: + evaluator_list.append(InstanceSegEvaluator(dataset_name, output_dir=output_folder)) + if evaluator_type == "mapillary_vistas_panoptic_seg" and cfg.MODEL.MASK_FORMER.TEST.SEMANTIC_ON: + evaluator_list.append(SemSegEvaluator(dataset_name, distributed=True, output_dir=output_folder)) + # Cityscapes + if evaluator_type == "cityscapes_instance": + assert ( + torch.cuda.device_count() > comm.get_rank() + ), "CityscapesEvaluator currently do not work with multiple machines." + return CityscapesInstanceEvaluator(dataset_name) + if evaluator_type == "cityscapes_sem_seg": + assert ( + torch.cuda.device_count() > comm.get_rank() + ), "CityscapesEvaluator currently do not work with multiple machines." + return CityscapesSemSegEvaluator(dataset_name) + if evaluator_type == "cityscapes_panoptic_seg": + if cfg.MODEL.MASK_FORMER.TEST.SEMANTIC_ON: + assert ( + torch.cuda.device_count() > comm.get_rank() + ), "CityscapesEvaluator currently do not work with multiple machines." + evaluator_list.append(CityscapesSemSegEvaluator(dataset_name)) + if cfg.MODEL.MASK_FORMER.TEST.INSTANCE_ON: + assert ( + torch.cuda.device_count() > comm.get_rank() + ), "CityscapesEvaluator currently do not work with multiple machines." + evaluator_list.append(CityscapesInstanceEvaluator(dataset_name)) + # ADE20K + if evaluator_type == "ade20k_panoptic_seg" and cfg.MODEL.MASK_FORMER.TEST.INSTANCE_ON: + evaluator_list.append(InstanceSegEvaluator(dataset_name, output_dir=output_folder)) + # LVIS + if evaluator_type == "lvis": + return LVISEvaluator(dataset_name, output_dir=output_folder) + if len(evaluator_list) == 0: + raise NotImplementedError( + "no Evaluator for the dataset {} with the type {}".format( + dataset_name, evaluator_type + ) + ) + elif len(evaluator_list) == 1: + return evaluator_list[0] + return DatasetEvaluators(evaluator_list) + + @classmethod + def build_train_loader(cls, cfg): + # Semantic segmentation dataset mapper + if cfg.INPUT.DATASET_MAPPER_NAME == "mask_former_semantic": + mapper = MaskFormerSemanticDatasetMapper(cfg, True) + return build_detection_train_loader(cfg, mapper=mapper) + # Panoptic segmentation dataset mapper + elif cfg.INPUT.DATASET_MAPPER_NAME == "mask_former_panoptic": + mapper = MaskFormerPanopticDatasetMapper(cfg, True) + return build_detection_train_loader(cfg, mapper=mapper) + # Instance segmentation dataset mapper + elif cfg.INPUT.DATASET_MAPPER_NAME == "mask_former_instance": + mapper = MaskFormerInstanceDatasetMapper(cfg, True) + return build_detection_train_loader(cfg, mapper=mapper) + # coco instance segmentation lsj new baseline + elif cfg.INPUT.DATASET_MAPPER_NAME == "coco_instance_lsj": + mapper = COCOInstanceNewBaselineDatasetMapper(cfg, True) + return build_detection_train_loader(cfg, mapper=mapper) + # coco panoptic segmentation lsj new baseline + elif cfg.INPUT.DATASET_MAPPER_NAME == "coco_panoptic_lsj": + mapper = COCOPanopticNewBaselineDatasetMapper(cfg, True) + return build_detection_train_loader(cfg, mapper=mapper) + else: + mapper = None + return build_detection_train_loader(cfg, mapper=mapper) + + @classmethod + def build_lr_scheduler(cls, cfg, optimizer): + """ + It now calls :func:`detectron2.solver.build_lr_scheduler`. + Overwrite it if you'd like a different scheduler. + """ + return build_lr_scheduler(cfg, optimizer) + + @classmethod + def build_optimizer(cls, cfg, model): + weight_decay_norm = cfg.SOLVER.WEIGHT_DECAY_NORM + weight_decay_embed = cfg.SOLVER.WEIGHT_DECAY_EMBED + + defaults = {} + defaults["lr"] = cfg.SOLVER.BASE_LR + defaults["weight_decay"] = cfg.SOLVER.WEIGHT_DECAY + + norm_module_types = ( + torch.nn.BatchNorm1d, + torch.nn.BatchNorm2d, + torch.nn.BatchNorm3d, + torch.nn.SyncBatchNorm, + # NaiveSyncBatchNorm inherits from BatchNorm2d + torch.nn.GroupNorm, + torch.nn.InstanceNorm1d, + torch.nn.InstanceNorm2d, + torch.nn.InstanceNorm3d, + torch.nn.LayerNorm, + torch.nn.LocalResponseNorm, + ) + + params: List[Dict[str, Any]] = [] + memo: Set[torch.nn.parameter.Parameter] = set() + for module_name, module in model.named_modules(): + for module_param_name, value in module.named_parameters(recurse=False): + if not value.requires_grad: + continue + # Avoid duplicating parameters + if value in memo: + continue + memo.add(value) + + hyperparams = copy.copy(defaults) + if "backbone" in module_name: + hyperparams["lr"] = hyperparams["lr"] * cfg.SOLVER.BACKBONE_MULTIPLIER + if ( + "relative_position_bias_table" in module_param_name + or "absolute_pos_embed" in module_param_name + ): + print(module_param_name) + hyperparams["weight_decay"] = 0.0 + if isinstance(module, norm_module_types): + hyperparams["weight_decay"] = weight_decay_norm + if isinstance(module, torch.nn.Embedding): + hyperparams["weight_decay"] = weight_decay_embed + params.append({"params": [value], **hyperparams}) + + def maybe_add_full_model_gradient_clipping(optim): + # detectron2 doesn't have full model gradient clipping now + clip_norm_val = cfg.SOLVER.CLIP_GRADIENTS.CLIP_VALUE + enable = ( + cfg.SOLVER.CLIP_GRADIENTS.ENABLED + and cfg.SOLVER.CLIP_GRADIENTS.CLIP_TYPE == "full_model" + and clip_norm_val > 0.0 + ) + + class FullModelGradientClippingOptimizer(optim): + def step(self, closure=None): + all_params = itertools.chain(*[x["params"] for x in self.param_groups]) + torch.nn.utils.clip_grad_norm_(all_params, clip_norm_val) + super().step(closure=closure) + + return FullModelGradientClippingOptimizer if enable else optim + + optimizer_type = cfg.SOLVER.OPTIMIZER + if optimizer_type == "SGD": + optimizer = maybe_add_full_model_gradient_clipping(torch.optim.SGD)( + params, cfg.SOLVER.BASE_LR, momentum=cfg.SOLVER.MOMENTUM + ) + elif optimizer_type == "ADAMW": + optimizer = maybe_add_full_model_gradient_clipping(torch.optim.AdamW)( + params, cfg.SOLVER.BASE_LR + ) + else: + raise NotImplementedError(f"no optimizer type {optimizer_type}") + if not cfg.SOLVER.CLIP_GRADIENTS.CLIP_TYPE == "full_model": + optimizer = maybe_add_gradient_clipping(cfg, optimizer) + return optimizer + + @classmethod + def test_with_TTA(cls, cfg, model): + logger = logging.getLogger("detectron2.trainer") + # In the end of training, run an evaluation with TTA. + logger.info("Running inference with test-time augmentation ...") + model = SemanticSegmentorWithTTA(cfg, model) + evaluators = [ + cls.build_evaluator( + cfg, name, output_folder=os.path.join(cfg.OUTPUT_DIR, "inference_TTA") + ) + for name in cfg.DATASETS.TEST + ] + res = cls.test(cfg, model, evaluators) + res = OrderedDict({k + "_TTA": v for k, v in res.items()}) + return res + + +def setup(args): + """ + Create configs and perform basic setups. + """ + cfg = get_cfg() + # for poly lr schedule + add_deeplab_config(cfg) + add_maskformer2_config(cfg) + cfg.merge_from_file(args.config_file) + cfg.merge_from_list(args.opts) + cfg.freeze() + default_setup(cfg, args) + # Setup logger for "mask_former" module + setup_logger(output=cfg.OUTPUT_DIR, distributed_rank=comm.get_rank(), name="mask2former") + return cfg + + +def main(args): + cfg = setup(args) + + if args.eval_only: + model = Trainer.build_model(cfg) + DetectionCheckpointer(model, save_dir=cfg.OUTPUT_DIR).resume_or_load( + cfg.MODEL.WEIGHTS, resume=args.resume + ) + res = Trainer.test(cfg, model) + if cfg.TEST.AUG.ENABLED: + res.update(Trainer.test_with_TTA(cfg, model)) + if comm.is_main_process(): + verify_results(cfg, res) + return res + + trainer = Trainer(cfg) + trainer.resume_or_load(resume=args.resume) + return trainer.train() + + +if __name__ == "__main__": + args = default_argument_parser().parse_args() + print("Command Line Args:", args) + launch( + main, + args.num_gpus, + num_machines=args.num_machines, + machine_rank=args.machine_rank, + dist_url=args.dist_url, + args=(args,), + ) diff --git a/third_party/Mask2Former/train_net_video.py b/third_party/Mask2Former/train_net_video.py new file mode 100644 index 0000000000000000000000000000000000000000..2d22345ed9659acfe70ed8d536b9775c748623f0 --- /dev/null +++ b/third_party/Mask2Former/train_net_video.py @@ -0,0 +1,290 @@ +# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved +""" +MaskFormer Training Script. + +This script is a simplified version of the training script in detectron2/tools. +""" +try: + # ignore ShapelyDeprecationWarning from fvcore + from shapely.errors import ShapelyDeprecationWarning + import warnings + warnings.filterwarnings('ignore', category=ShapelyDeprecationWarning) +except: + pass + +import copy +import itertools +import logging +import os + +from collections import OrderedDict +from typing import Any, Dict, List, Set + +import torch + +import detectron2.utils.comm as comm +from detectron2.checkpoint import DetectionCheckpointer +from detectron2.config import get_cfg +from detectron2.data import MetadataCatalog +from detectron2.engine import ( + DefaultTrainer, + default_argument_parser, + default_setup, + launch, +) +from detectron2.evaluation import ( + DatasetEvaluator, + inference_on_dataset, + print_csv_format, + verify_results, +) +from detectron2.projects.deeplab import add_deeplab_config, build_lr_scheduler +from detectron2.solver.build import maybe_add_gradient_clipping +from detectron2.utils.logger import setup_logger + +# MaskFormer +from mask2former import add_maskformer2_config +from mask2former_video import ( + YTVISDatasetMapper, + YTVISEvaluator, + add_maskformer2_video_config, + build_detection_train_loader, + build_detection_test_loader, + get_detection_dataset_dicts, +) + + +class Trainer(DefaultTrainer): + """ + Extension of the Trainer class adapted to MaskFormer. + """ + + @classmethod + def build_evaluator(cls, cfg, dataset_name, output_folder=None): + """ + Create evaluator(s) for a given dataset. + This uses the special metadata "evaluator_type" associated with each builtin dataset. + For your own dataset, you can simply create an evaluator manually in your + script and do not have to worry about the hacky if-else logic here. + """ + if output_folder is None: + output_folder = os.path.join(cfg.OUTPUT_DIR, "inference") + os.makedirs(output_folder, exist_ok=True) + + return YTVISEvaluator(dataset_name, cfg, True, output_folder) + + @classmethod + def build_train_loader(cls, cfg): + dataset_name = cfg.DATASETS.TRAIN[0] + mapper = YTVISDatasetMapper(cfg, is_train=True) + + dataset_dict = get_detection_dataset_dicts( + dataset_name, + filter_empty=cfg.DATALOADER.FILTER_EMPTY_ANNOTATIONS, + proposal_files=cfg.DATASETS.PROPOSAL_FILES_TRAIN if cfg.MODEL.LOAD_PROPOSALS else None, + ) + + return build_detection_train_loader(cfg, mapper=mapper, dataset=dataset_dict) + + @classmethod + def build_test_loader(cls, cfg, dataset_name): + dataset_name = cfg.DATASETS.TEST[0] + mapper = YTVISDatasetMapper(cfg, is_train=False) + return build_detection_test_loader(cfg, dataset_name, mapper=mapper) + + @classmethod + def build_lr_scheduler(cls, cfg, optimizer): + """ + It now calls :func:`detectron2.solver.build_lr_scheduler`. + Overwrite it if you'd like a different scheduler. + """ + return build_lr_scheduler(cfg, optimizer) + + @classmethod + def build_optimizer(cls, cfg, model): + weight_decay_norm = cfg.SOLVER.WEIGHT_DECAY_NORM + weight_decay_embed = cfg.SOLVER.WEIGHT_DECAY_EMBED + + defaults = {} + defaults["lr"] = cfg.SOLVER.BASE_LR + defaults["weight_decay"] = cfg.SOLVER.WEIGHT_DECAY + + norm_module_types = ( + torch.nn.BatchNorm1d, + torch.nn.BatchNorm2d, + torch.nn.BatchNorm3d, + torch.nn.SyncBatchNorm, + # NaiveSyncBatchNorm inherits from BatchNorm2d + torch.nn.GroupNorm, + torch.nn.InstanceNorm1d, + torch.nn.InstanceNorm2d, + torch.nn.InstanceNorm3d, + torch.nn.LayerNorm, + torch.nn.LocalResponseNorm, + ) + + params: List[Dict[str, Any]] = [] + memo: Set[torch.nn.parameter.Parameter] = set() + for module_name, module in model.named_modules(): + for module_param_name, value in module.named_parameters(recurse=False): + if not value.requires_grad: + continue + # Avoid duplicating parameters + if value in memo: + continue + memo.add(value) + + hyperparams = copy.copy(defaults) + if "backbone" in module_name: + hyperparams["lr"] = hyperparams["lr"] * cfg.SOLVER.BACKBONE_MULTIPLIER + if ( + "relative_position_bias_table" in module_param_name + or "absolute_pos_embed" in module_param_name + ): + print(module_param_name) + hyperparams["weight_decay"] = 0.0 + if isinstance(module, norm_module_types): + hyperparams["weight_decay"] = weight_decay_norm + if isinstance(module, torch.nn.Embedding): + hyperparams["weight_decay"] = weight_decay_embed + params.append({"params": [value], **hyperparams}) + + def maybe_add_full_model_gradient_clipping(optim): + # detectron2 doesn't have full model gradient clipping now + clip_norm_val = cfg.SOLVER.CLIP_GRADIENTS.CLIP_VALUE + enable = ( + cfg.SOLVER.CLIP_GRADIENTS.ENABLED + and cfg.SOLVER.CLIP_GRADIENTS.CLIP_TYPE == "full_model" + and clip_norm_val > 0.0 + ) + + class FullModelGradientClippingOptimizer(optim): + def step(self, closure=None): + all_params = itertools.chain(*[x["params"] for x in self.param_groups]) + torch.nn.utils.clip_grad_norm_(all_params, clip_norm_val) + super().step(closure=closure) + + return FullModelGradientClippingOptimizer if enable else optim + + optimizer_type = cfg.SOLVER.OPTIMIZER + if optimizer_type == "SGD": + optimizer = maybe_add_full_model_gradient_clipping(torch.optim.SGD)( + params, cfg.SOLVER.BASE_LR, momentum=cfg.SOLVER.MOMENTUM + ) + elif optimizer_type == "ADAMW": + optimizer = maybe_add_full_model_gradient_clipping(torch.optim.AdamW)( + params, cfg.SOLVER.BASE_LR + ) + else: + raise NotImplementedError(f"no optimizer type {optimizer_type}") + if not cfg.SOLVER.CLIP_GRADIENTS.CLIP_TYPE == "full_model": + optimizer = maybe_add_gradient_clipping(cfg, optimizer) + return optimizer + + @classmethod + def test(cls, cfg, model, evaluators=None): + """ + Evaluate the given model. The given model is expected to already contain + weights to evaluate. + Args: + cfg (CfgNode): + model (nn.Module): + evaluators (list[DatasetEvaluator] or None): if None, will call + :meth:`build_evaluator`. Otherwise, must have the same length as + ``cfg.DATASETS.TEST``. + Returns: + dict: a dict of result metrics + """ + from torch.cuda.amp import autocast + logger = logging.getLogger(__name__) + if isinstance(evaluators, DatasetEvaluator): + evaluators = [evaluators] + if evaluators is not None: + assert len(cfg.DATASETS.TEST) == len(evaluators), "{} != {}".format( + len(cfg.DATASETS.TEST), len(evaluators) + ) + + results = OrderedDict() + for idx, dataset_name in enumerate(cfg.DATASETS.TEST): + data_loader = cls.build_test_loader(cfg, dataset_name) + # When evaluators are passed in as arguments, + # implicitly assume that evaluators can be created before data_loader. + if evaluators is not None: + evaluator = evaluators[idx] + else: + try: + evaluator = cls.build_evaluator(cfg, dataset_name) + except NotImplementedError: + logger.warn( + "No evaluator found. Use `DefaultTrainer.test(evaluators=)`, " + "or implement its `build_evaluator` method." + ) + results[dataset_name] = {} + continue + with autocast(): + results_i = inference_on_dataset(model, data_loader, evaluator) + results[dataset_name] = results_i + if comm.is_main_process(): + assert isinstance( + results_i, dict + ), "Evaluator must return a dict on the main process. Got {} instead.".format( + results_i + ) + logger.info("Evaluation results for {} in csv format:".format(dataset_name)) + print_csv_format(results_i) + + if len(results) == 1: + results = list(results.values())[0] + return results + + +def setup(args): + """ + Create configs and perform basic setups. + """ + cfg = get_cfg() + # for poly lr schedule + add_deeplab_config(cfg) + add_maskformer2_config(cfg) + add_maskformer2_video_config(cfg) + cfg.merge_from_file(args.config_file) + cfg.merge_from_list(args.opts) + cfg.freeze() + default_setup(cfg, args) + # Setup logger for "mask_former" module + setup_logger(name="mask2former") + setup_logger(output=cfg.OUTPUT_DIR, distributed_rank=comm.get_rank(), name="mask2former_video") + return cfg + + +def main(args): + cfg = setup(args) + + if args.eval_only: + model = Trainer.build_model(cfg) + DetectionCheckpointer(model, save_dir=cfg.OUTPUT_DIR).resume_or_load( + cfg.MODEL.WEIGHTS, resume=args.resume + ) + res = Trainer.test(cfg, model) + if cfg.TEST.AUG.ENABLED: + raise NotImplementedError + if comm.is_main_process(): + verify_results(cfg, res) + return res + + trainer = Trainer(cfg) + trainer.resume_or_load(resume=args.resume) + return trainer.train() + + +if __name__ == "__main__": + args = default_argument_parser().parse_args() + print("Command Line Args:", args) + launch( + main, + args.num_gpus, + num_machines=args.num_machines, + machine_rank=args.machine_rank, + dist_url=args.dist_url, + args=(args,), + )