diff --git a/.gitattributes b/.gitattributes index f434b47c60d80a08720a1bb4534742deb3f357f1..b4449ac557486fd9e2e47865a2aeca778690698e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -77,3 +77,15 @@ deployment/declip_quant/trt_engines/dummy_csa_eva_clip_b16_dummy_csa_560_fp8_bs6 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 +deployment/declip_quant/qq_xformer_512/trt_engines/qq_xformer_eva_clip_b16_qq_xformer_512_fp8.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/qq_xformer_512/trt_engines/vanilla_eva_clip_b16_vanilla_512_fp8.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/qq_xformer_512/trt_engines/qq_xformer_eva_clip_b16_qq_xformer_512_fp16.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/qq_xformer_512/trt_engines/vanilla_eva_clip_b16_vanilla_512_fp16.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16_bs32.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8_bs32.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8_bs64.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16_bs64.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16.trt filter=lfs diff=lfs merge=lfs -text +deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8.trt filter=lfs diff=lfs merge=lfs -text diff --git a/demo_images/train.jpg b/demo_images/train.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1e19c489e09040ea46bd3c53bc4d10bfa37ef093 --- /dev/null +++ b/demo_images/train.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:888a9040c79476ad578f9373132ce3961d31633025461c7d6f409667b9b2da61 +size 157378 diff --git a/demo_images/tree.png b/demo_images/tree.png new file mode 100644 index 0000000000000000000000000000000000000000..f397b33b3029dadb4c56014c2ce69fcb9a2c4d25 --- /dev/null +++ b/demo_images/tree.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:adc532c04855b6cd4707dd9661a93e2534b36527e7467de202a42b79b9b84a71 +size 65028 diff --git a/demo_images/wa.jpg b/demo_images/wa.jpg new file mode 100644 index 0000000000000000000000000000000000000000..469462cf7e6e9f5f575d2deed1170c9c5ec7c3cd --- /dev/null +++ b/demo_images/wa.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14a47c43e80defedbb460687e517acbaf3b1c1dedf84b239a22418dbc0130d44 +size 57850 diff --git a/demo_images/whitedog.jpg b/demo_images/whitedog.jpg new file mode 100644 index 0000000000000000000000000000000000000000..25399678f8599aa08f0ea45482d093e241f985d8 --- /dev/null +++ b/demo_images/whitedog.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bce0c48d7630f30e6e4af7cf3921d6ac3a5dd4cd73398494fe337a53308fe267 +size 278604 diff --git a/demo_images/xia.jpg b/demo_images/xia.jpg new file mode 100644 index 0000000000000000000000000000000000000000..de97fa97e94942493076be0fdd9b6ecd6064d665 --- /dev/null +++ b/demo_images/xia.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b2537f2ddee60ebb0777e46d37df4fbb5a63fc8c9646c22ed77882c1a4099a6 +size 30505 diff --git a/demo_images/yidali.jpg b/demo_images/yidali.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0e18759f91f3e8c51a2a626c33a3e3f2bf404237 --- /dev/null +++ b/demo_images/yidali.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1620ef12bd16a74db05fff7c8033644066aecc5db8c404ae2d7c0d02c3c87fbf +size 322498 diff --git a/demo_images/yidali2.jpg b/demo_images/yidali2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..335d9e0248caaf8bf80c94f8b550d9acbf0dd60d --- /dev/null +++ b/demo_images/yidali2.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87d491081720fb67b7b3090291dc74490d527e9d934e35d15bcffcde1e5d97e0 +size 253506 diff --git a/demo_images/youling.jpg b/demo_images/youling.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d4284a29cb6d3e3c9db57ff464ff821bedde23d9 --- /dev/null +++ b/demo_images/youling.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c22e186bcdce5e13e87169541d41bcbdd54e7c425f90e45eaac95baec901ed6 +size 331369 diff --git a/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-1-generating-bert-trt.png b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-1-generating-bert-trt.png new file mode 100644 index 0000000000000000000000000000000000000000..87db53dbded9cbee67f4d0e50111a87891175f32 --- /dev/null +++ b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-1-generating-bert-trt.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:865a1b50b9d0d04e898ea30660c2244013be7306978fc3dd7176089f4bd7259c +size 115418 diff --git a/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-2-workflow-to-perform-inference-with-trt.png b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-2-workflow-to-perform-inference-with-trt.png new file mode 100644 index 0000000000000000000000000000000000000000..034c9742d92507ba7a84a4fa3e8c93455dddb606 --- /dev/null +++ b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-2-workflow-to-perform-inference-with-trt.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27cc2eabd660ef66a4b0b0059bdca4f8a99e4695a241be40345943567b10450a +size 45834 diff --git a/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-5-optimizations-through-trt.jpg b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-5-optimizations-through-trt.jpg new file mode 100644 index 0000000000000000000000000000000000000000..71dcb7408e7f3de44a411364292fc2714545689f --- /dev/null +++ b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-5-optimizations-through-trt.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68d5d01cfdc97e4b80b0ad30ab539d19921170fb7fad0c0a0345c1ee31c321ce +size 67942 diff --git a/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-6-Compute-latency.jpg b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-6-Compute-latency.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2182f43ba2dece27a693f215d0fb72ee0243209e --- /dev/null +++ b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/Figure-6-Compute-latency.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15676400ab5fbfe9dff3d4f241bd8b5f3498b220465e9189d402216009f5ecd4 +size 23817 diff --git a/deployment/declip_quant/TensorRT/demo/BERT/notebooks/sparsity-diagram-600x338-r3.jpg b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/sparsity-diagram-600x338-r3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a62f0a395f71781d19db880b6e4686b161f35a2e --- /dev/null +++ b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/sparsity-diagram-600x338-r3.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bdceaf2180cf28a58521eebcf730d37dae3630284d35ebf90c72520ff4707817 +size 13302 diff --git a/deployment/declip_quant/TensorRT/demo/BERT/notebooks/structured_spare_matrix.jpg b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/structured_spare_matrix.jpg new file mode 100644 index 0000000000000000000000000000000000000000..eb2875671cb1bf9fbc1f0194331b75a25bd8de1c --- /dev/null +++ b/deployment/declip_quant/TensorRT/demo/BERT/notebooks/structured_spare_matrix.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7de545b4c5bf68577d4fe0617b050059392bdadea79d8d6b7674d3fdcc1e9c40 +size 65005 diff --git a/deployment/declip_quant/TensorRT/demo/Diffusion/calibration_data/calibration-images/rocket.png b/deployment/declip_quant/TensorRT/demo/Diffusion/calibration_data/calibration-images/rocket.png new file mode 100644 index 0000000000000000000000000000000000000000..0482887c35db3a7a25dd147ddd08f36249e9ea46 --- /dev/null +++ b/deployment/declip_quant/TensorRT/demo/Diffusion/calibration_data/calibration-images/rocket.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83e7729b516ba725cb2283eb397ec2c77fc4b120f52a83801f610eac353b63c4 +size 493509 diff --git a/deployment/declip_quant/qq_xformer_512/trt_engines/qq_xformer_eva_clip_b16_qq_xformer_512_fp16.trt b/deployment/declip_quant/qq_xformer_512/trt_engines/qq_xformer_eva_clip_b16_qq_xformer_512_fp16.trt new file mode 100644 index 0000000000000000000000000000000000000000..0dd156d393a1907f55126b67d816c631685132ee --- /dev/null +++ b/deployment/declip_quant/qq_xformer_512/trt_engines/qq_xformer_eva_clip_b16_qq_xformer_512_fp16.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f81fdd556ab697ab77653a475675588f76b923463c725b966e613ca4f1f51a0d +size 166397164 diff --git a/deployment/declip_quant/qq_xformer_512/trt_engines/qq_xformer_eva_clip_b16_qq_xformer_512_fp8.trt b/deployment/declip_quant/qq_xformer_512/trt_engines/qq_xformer_eva_clip_b16_qq_xformer_512_fp8.trt new file mode 100644 index 0000000000000000000000000000000000000000..c154450dba4e78306faf1bfe2d1b6fe4f9c16d9e --- /dev/null +++ b/deployment/declip_quant/qq_xformer_512/trt_engines/qq_xformer_eva_clip_b16_qq_xformer_512_fp8.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:78112ca61f982411d49cb8589b83df194680f07401ecdedf43af8c02ae03a2b4 +size 105538628 diff --git a/deployment/declip_quant/qq_xformer_512/trt_engines/vanilla_eva_clip_b16_vanilla_512_fp16.trt b/deployment/declip_quant/qq_xformer_512/trt_engines/vanilla_eva_clip_b16_vanilla_512_fp16.trt new file mode 100644 index 0000000000000000000000000000000000000000..ea08ca91e90f97224a42104f22408e2cf4b61919 --- /dev/null +++ b/deployment/declip_quant/qq_xformer_512/trt_engines/vanilla_eva_clip_b16_vanilla_512_fp16.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e38bf047ba03eaeee22647fee54678447b90d29825741aa09a3b12cbb03ff94d +size 180896364 diff --git a/deployment/declip_quant/qq_xformer_512/trt_engines/vanilla_eva_clip_b16_vanilla_512_fp8.trt b/deployment/declip_quant/qq_xformer_512/trt_engines/vanilla_eva_clip_b16_vanilla_512_fp8.trt new file mode 100644 index 0000000000000000000000000000000000000000..c3d9f377c793f75809c38200a5e7d179f5e308e5 --- /dev/null +++ b/deployment/declip_quant/qq_xformer_512/trt_engines/vanilla_eva_clip_b16_vanilla_512_fp8.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93e91d5751229e47678c7b2d47d6b95a24e46607757401472a6280663aa37dda +size 111459892 diff --git a/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16.trt b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16.trt new file mode 100644 index 0000000000000000000000000000000000000000..ef8f09cf12908006788058e1a7e1ccc9038260a2 --- /dev/null +++ b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c789d309748801fd7e531b7827552abbe75c33d5df6be49ca8edbf840c63cc85 +size 181380684 diff --git a/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16_bs32.trt b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16_bs32.trt new file mode 100644 index 0000000000000000000000000000000000000000..a7342621c08fc162a2bde58b430582b44a878189 --- /dev/null +++ b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16_bs32.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd113a28029a0c89772b5690c2f898fcfd4efb50500675d81fec994ba5de292c +size 177206588 diff --git a/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16_bs64.trt b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16_bs64.trt new file mode 100644 index 0000000000000000000000000000000000000000..ad05a1520428bc4ee8fe6b2e8810b4552a2fbf98 --- /dev/null +++ b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp16_bs64.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e9cdecbf4d13a452414838392e3094d6b7237c37fd1d370331507b752039f96 +size 177206404 diff --git a/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8.trt b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8.trt new file mode 100644 index 0000000000000000000000000000000000000000..ee09b1fd3be7be3a8a637324d75a1aa95cee3d27 --- /dev/null +++ b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b9dd4e30360b02da12e489496c04f0414c6ec840efe6371640b361d62c6c393 +size 111597372 diff --git a/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8_bs32.trt b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8_bs32.trt new file mode 100644 index 0000000000000000000000000000000000000000..e0f58acfc0772cffeb29244dec0671547a9eff79 --- /dev/null +++ b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8_bs32.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c5da662978a65bbee9dd702aeb15c996ecade93448e45fabd59ca24803fa1a38 +size 111984284 diff --git a/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8_bs64.trt b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8_bs64.trt new file mode 100644 index 0000000000000000000000000000000000000000..393fed83fe7b3a70273d0e28435ede92a12dd974 --- /dev/null +++ b/deployment/declip_quant/trt_engines/clip_eva_clip_b16_vanilla_560_fp8_bs64.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40485b81b29e5e00100fb7a058901371706828ee1e9a604b83123411f6ea2ec0 +size 111986020 diff --git a/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16.trt b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16.trt new file mode 100644 index 0000000000000000000000000000000000000000..f6d8c7a57354bfcebf843f9386c4ba1a27bc7666 --- /dev/null +++ b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp16.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3421d32b0b174241449ec720999d2cbcf89e9f3d1fef9d5ac28f6e02f8aff83b +size 168203316 diff --git a/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8.trt b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8.trt new file mode 100644 index 0000000000000000000000000000000000000000..e358a60330c1dc9c21272e022130d2d294b0da69 --- /dev/null +++ b/deployment/declip_quant/trt_engines/declip_eva_clip_b16_csa_560_fp8.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69a4325c7e7b1b35dd704fbe9fc3d8137fee6b5d01fe0ade1bc3626d945787c5 +size 107311436 diff --git a/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/Base-Cityscapes-SemanticSegmentation.yaml b/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/Base-Cityscapes-SemanticSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ca42fabfb1f71a82bb726a425dc691fd638a05aa --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/Base-Cityscapes-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" # use syncbn for cityscapes dataset + RES5_MULTI_GRID: [1, 1, 1] # not used +DATASETS: + TRAIN: ("cityscapes_fine_sem_seg_train",) + TEST: ("cityscapes_fine_sem_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_semantic" +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/semantic-segmentation/maskformer2_R101_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/maskformer2_R101_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1eb38dacd50b7217118211c757eed7ed8975cad5 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/semantic-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/semantic-segmentation/maskformer2_R50_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/maskformer2_R50_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d872fcd43f8f81e183091075711f39ad0d99ce6c --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/maskformer2_R50_bs16_90k.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-Cityscapes-SemanticSegmentation.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: False + PANOPTIC_ON: False + OVERLAP_THRESHOLD: 0.8 + OBJECT_MASK_THRESHOLD: 0.8 diff --git a/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/semantic-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/semantic-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/semantic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..25097174aa81aab88e0402e642de64619793ac14 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/semantic-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: 100 diff --git a/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/swin/maskformer2_swin_small_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/swin/maskformer2_swin_small_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..156ef9e1f57cfbccb5132a2877509dbd15366b7f --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/semantic-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/semantic-segmentation/swin/maskformer2_swin_tiny_bs16_90k.yaml b/third_party/Mask2Former/configs/cityscapes/semantic-segmentation/swin/maskformer2_swin_tiny_bs16_90k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0c56e2cc5287461bda7982f9b94a2f5a5a081dd4 --- /dev/null +++ b/third_party/Mask2Former/configs/cityscapes/semantic-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/coco/instance-segmentation/Base-COCO-InstanceSegmentation.yaml b/third_party/Mask2Former/configs/coco/instance-segmentation/Base-COCO-InstanceSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..98943d9cca85e7445e8fe4c8725e7749a3b0422e --- /dev/null +++ b/third_party/Mask2Former/configs/coco/instance-segmentation/Base-COCO-InstanceSegmentation.yaml @@ -0,0 +1,47 @@ +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: ("coco_2017_train",) + TEST: ("coco_2017_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + STEPS: (327778, 355092) + MAX_ITER: 368750 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 10 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + BACKBONE_MULTIPLIER: 0.1 + CLIP_GRADIENTS: + ENABLED: True + CLIP_TYPE: "full_model" + CLIP_VALUE: 0.01 + NORM_TYPE: 2.0 + AMP: + ENABLED: True +INPUT: + IMAGE_SIZE: 1024 + MIN_SCALE: 0.1 + MAX_SCALE: 2.0 + FORMAT: "RGB" + DATASET_MAPPER_NAME: "coco_instance_lsj" +TEST: + EVAL_PERIOD: 5000 +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/coco/instance-segmentation/maskformer2_R101_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/instance-segmentation/maskformer2_R101_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..77defd0023c63146d2c295c39fcbdca2d809e43d --- /dev/null +++ b/third_party/Mask2Former/configs/coco/instance-segmentation/maskformer2_R101_bs16_50ep.yaml @@ -0,0 +1,11 @@ +_BASE_: maskformer2_R50_bs16_50ep.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/coco/instance-segmentation/maskformer2_R50_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/instance-segmentation/maskformer2_R50_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4b9e76e32a68a58ad847da991890785d6792d9a5 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/instance-segmentation/maskformer2_R50_bs16_50ep.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-COCO-InstanceSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 255 + NUM_CLASSES: 80 + 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/coco/instance-segmentation/swin/maskformer2_swin_base_384_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_base_384_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..473299948005414679b15d7e720f39c1afea87e7 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_base_384_bs16_50ep.yaml @@ -0,0 +1,16 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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] diff --git a/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5dde9602fc5f935bb127a6775247293fad4dadf2 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_50ep.yaml @@ -0,0 +1,16 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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/coco/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_100ep.yaml b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_100ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b685cdb9bb469fc728233ded96543319b3a0c4ec --- /dev/null +++ b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_100ep.yaml @@ -0,0 +1,21 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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 +SOLVER: + STEPS: (655556, 710184) + MAX_ITER: 737500 diff --git a/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_small_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_small_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f9b1c56d5fd1abef908e3158a72b298c9163e282 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_small_bs16_50ep.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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/coco/instance-segmentation/swin/maskformer2_swin_tiny_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_tiny_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7f27bc52489618da5eda8ceba3c2a3b62ccf2f78 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/instance-segmentation/swin/maskformer2_swin_tiny_bs16_50ep.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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/coco/panoptic-segmentation/Base-COCO-PanopticSegmentation.yaml b/third_party/Mask2Former/configs/coco/panoptic-segmentation/Base-COCO-PanopticSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7560a730a973040346e8d10321a515e717ff9924 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/panoptic-segmentation/Base-COCO-PanopticSegmentation.yaml @@ -0,0 +1,47 @@ +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: ("coco_2017_train_panoptic",) + TEST: ("coco_2017_val_panoptic_with_sem_seg",) # to evaluate instance and semantic performance as well +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + STEPS: (327778, 355092) + MAX_ITER: 368750 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 10 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + BACKBONE_MULTIPLIER: 0.1 + CLIP_GRADIENTS: + ENABLED: True + CLIP_TYPE: "full_model" + CLIP_VALUE: 0.01 + NORM_TYPE: 2.0 + AMP: + ENABLED: True +INPUT: + IMAGE_SIZE: 1024 + MIN_SCALE: 0.1 + MAX_SCALE: 2.0 + FORMAT: "RGB" + DATASET_MAPPER_NAME: "coco_panoptic_lsj" +TEST: + EVAL_PERIOD: 5000 +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/coco/panoptic-segmentation/maskformer2_R101_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/panoptic-segmentation/maskformer2_R101_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..77defd0023c63146d2c295c39fcbdca2d809e43d --- /dev/null +++ b/third_party/Mask2Former/configs/coco/panoptic-segmentation/maskformer2_R101_bs16_50ep.yaml @@ -0,0 +1,11 @@ +_BASE_: maskformer2_R50_bs16_50ep.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/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9ebf4f1114fc9ac2dd7a706acf0643559563754c --- /dev/null +++ b/third_party/Mask2Former/configs/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml @@ -0,0 +1,45 @@ +_BASE_: Base-COCO-PanopticSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IN_FEATURES: ["res2", "res3", "res4", "res5"] + IGNORE_VALUE: 255 + NUM_CLASSES: 133 + 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/coco/panoptic-segmentation/swin/maskformer2_swin_base_384_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_base_384_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..473299948005414679b15d7e720f39c1afea87e7 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_base_384_bs16_50ep.yaml @@ -0,0 +1,16 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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] diff --git a/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5dde9602fc5f935bb127a6775247293fad4dadf2 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_base_IN21k_384_bs16_50ep.yaml @@ -0,0 +1,16 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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/coco/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_100ep.yaml b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_100ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b685cdb9bb469fc728233ded96543319b3a0c4ec --- /dev/null +++ b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_100ep.yaml @@ -0,0 +1,21 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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 +SOLVER: + STEPS: (655556, 710184) + MAX_ITER: 737500 diff --git a/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_small_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_small_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f9b1c56d5fd1abef908e3158a72b298c9163e282 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_small_bs16_50ep.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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/coco/panoptic-segmentation/swin/maskformer2_swin_tiny_bs16_50ep.yaml b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_tiny_bs16_50ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7f27bc52489618da5eda8ceba3c2a3b62ccf2f78 --- /dev/null +++ b/third_party/Mask2Former/configs/coco/panoptic-segmentation/swin/maskformer2_swin_tiny_bs16_50ep.yaml @@ -0,0 +1,15 @@ +_BASE_: ../maskformer2_R50_bs16_50ep.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/mapillary-vistas/panoptic-segmentation/Base-MapillaryVistas-PanopticSegmentation.yaml b/third_party/Mask2Former/configs/mapillary-vistas/panoptic-segmentation/Base-MapillaryVistas-PanopticSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..86629a3b3529cd17b13610a396f6982b758c3919 --- /dev/null +++ b/third_party/Mask2Former/configs/mapillary-vistas/panoptic-segmentation/Base-MapillaryVistas-PanopticSegmentation.yaml @@ -0,0 +1,56 @@ +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: ("mapillary_vistas_panoptic_train",) + TEST: ("mapillary_vistas_panoptic_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + MAX_ITER: 300000 + 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 * 2048) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 2048 + MAX_SIZE_TRAIN: 8192 + MAX_SIZE_TEST: 2048 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (1024, 1024) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: 1024 # used in dataset mapper + FORMAT: "RGB" + DATASET_MAPPER_NAME: "mask_former_panoptic" +TEST: + EVAL_PERIOD: 0 +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 10 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/mapillary-vistas/panoptic-segmentation/maskformer_R50_bs16_300k.yaml b/third_party/Mask2Former/configs/mapillary-vistas/panoptic-segmentation/maskformer_R50_bs16_300k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b19c9d4f6333235bd0c22e1b00137260edcfbf99 --- /dev/null +++ b/third_party/Mask2Former/configs/mapillary-vistas/panoptic-segmentation/maskformer_R50_bs16_300k.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-MapillaryVistas-PanopticSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 65 + NUM_CLASSES: 65 + 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: True + OVERLAP_THRESHOLD: 0.8 + OBJECT_MASK_THRESHOLD: 0.0 diff --git a/third_party/Mask2Former/configs/mapillary-vistas/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_300k.yaml b/third_party/Mask2Former/configs/mapillary-vistas/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_300k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e7a8c4c2897ed3b4d262a92e938d4fd32b0ccace --- /dev/null +++ b/third_party/Mask2Former/configs/mapillary-vistas/panoptic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_300k.yaml @@ -0,0 +1,18 @@ +_BASE_: ../maskformer_R50_bs16_300k.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/mapillary-vistas/semantic-segmentation/Base-MapillaryVistas-SemanticSegmentation.yaml b/third_party/Mask2Former/configs/mapillary-vistas/semantic-segmentation/Base-MapillaryVistas-SemanticSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f05fb28a2fb2aa5ddc3680aeae651a88deeb285b --- /dev/null +++ b/third_party/Mask2Former/configs/mapillary-vistas/semantic-segmentation/Base-MapillaryVistas-SemanticSegmentation.yaml @@ -0,0 +1,56 @@ +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: ("mapillary_vistas_sem_seg_train",) + TEST: ("mapillary_vistas_sem_seg_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + MAX_ITER: 300000 + 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 * 2048) for x in range(5, 21)]"] + MIN_SIZE_TRAIN_SAMPLING: "choice" + MIN_SIZE_TEST: 2048 + MAX_SIZE_TRAIN: 8192 + MAX_SIZE_TEST: 2048 + CROP: + ENABLED: True + TYPE: "absolute" + SIZE: (1024, 1024) + SINGLE_CATEGORY_MAX_AREA: 1.0 + COLOR_AUG_SSD: True + SIZE_DIVISIBILITY: 1024 # used in dataset mapper + FORMAT: "RGB" + DATASET_MAPPER_NAME: "mask_former_semantic" +TEST: + EVAL_PERIOD: 0 +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: True + NUM_WORKERS: 10 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/mapillary-vistas/semantic-segmentation/maskformer2_R50_bs16_300k.yaml b/third_party/Mask2Former/configs/mapillary-vistas/semantic-segmentation/maskformer2_R50_bs16_300k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e9977a12f2b1c2275573f80f090a989e4fe4a42f --- /dev/null +++ b/third_party/Mask2Former/configs/mapillary-vistas/semantic-segmentation/maskformer2_R50_bs16_300k.yaml @@ -0,0 +1,44 @@ +_BASE_: Base-MapillaryVistas-SemanticSegmentation.yaml +MODEL: + META_ARCHITECTURE: "MaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 65 + NUM_CLASSES: 65 + 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.0 diff --git a/third_party/Mask2Former/configs/mapillary-vistas/semantic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_300k.yaml b/third_party/Mask2Former/configs/mapillary-vistas/semantic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_300k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e336a1b9743463e007dedcbc647464ccf4131585 --- /dev/null +++ b/third_party/Mask2Former/configs/mapillary-vistas/semantic-segmentation/swin/maskformer2_swin_large_IN21k_384_bs16_300k.yaml @@ -0,0 +1,18 @@ +_BASE_: ../maskformer2_R50_bs16_300k.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: 100 diff --git a/third_party/Mask2Former/configs/youtubevis_2019/Base-YouTubeVIS-VideoInstanceSegmentation.yaml b/third_party/Mask2Former/configs/youtubevis_2019/Base-YouTubeVIS-VideoInstanceSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..76426ecb5236707ed71266d1b09908985d3f76f6 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2019/Base-YouTubeVIS-VideoInstanceSegmentation.yaml @@ -0,0 +1,53 @@ +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] + MASK_ON: True + 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: ("ytvis_2019_train",) + TEST: ("ytvis_2019_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + STEPS: (4000,) + MAX_ITER: 6000 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 10 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + 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_SAMPLING: "choice_by_clip" + RANDOM_FLIP: "flip_by_clip" + AUGMENTATIONS: [] + MIN_SIZE_TRAIN: (360, 480) + MIN_SIZE_TEST: 360 + CROP: + ENABLED: False + TYPE: "absolute_range" + SIZE: (600, 720) + FORMAT: "RGB" +TEST: + EVAL_PERIOD: 0 +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: False + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_base_IN21k_384_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_base_IN21k_384_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8068edf5a3c6daff7c1776e958c2576255c10ac5 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_base_IN21k_384_bs16_8ep.yaml @@ -0,0 +1,18 @@ +_BASE_: ../video_maskformer2_R50_bs16_8ep.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: "model_final_83d103.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TEST: 480 diff --git a/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_large_IN21k_384_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_large_IN21k_384_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..39788823e1bfbf48f94f777846c823e047cc0f39 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_large_IN21k_384_bs16_8ep.yaml @@ -0,0 +1,20 @@ +_BASE_: ../video_maskformer2_R50_bs16_8ep.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: "model_final_e5f453.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + MASK_FORMER: + NUM_OBJECT_QUERIES: 200 +INPUT: + MIN_SIZE_TEST: 480 diff --git a/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_small_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_small_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..767d30a55186bb97bfafa78a80b9cbd47dded0a0 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_small_bs16_8ep.yaml @@ -0,0 +1,17 @@ +_BASE_: ../video_maskformer2_R50_bs16_8ep.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: "model_final_1e7f22.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TEST: 480 diff --git a/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_tiny_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_tiny_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2d446e2ad9f7af7e94a89b3c3f71bc9e09e0ab19 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2019/swin/video_maskformer2_swin_tiny_bs16_8ep.yaml @@ -0,0 +1,17 @@ +_BASE_: ../video_maskformer2_R50_bs16_8ep.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: "model_final_86143f.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TEST: 480 diff --git a/third_party/Mask2Former/configs/youtubevis_2019/video_maskformer2_R101_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2019/video_maskformer2_R101_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fcc9c49346b3f5370111ff992a517eda4e01a5ae --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2019/video_maskformer2_R101_bs16_8ep.yaml @@ -0,0 +1,11 @@ +_BASE_: video_maskformer2_R50_bs16_8ep.yaml +MODEL: + WEIGHTS: "model_final_eba159.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/youtubevis_2019/video_maskformer2_R50_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2019/video_maskformer2_R50_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8af434dd2efbfb8654f9d958546e660ec46c7e60 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2019/video_maskformer2_R50_bs16_8ep.yaml @@ -0,0 +1,45 @@ +_BASE_: Base-YouTubeVIS-VideoInstanceSegmentation.yaml +MODEL: + WEIGHTS: "model_final_3c8ec9.pkl" + META_ARCHITECTURE: "VideoMaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 255 + NUM_CLASSES: 40 + 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: "VideoMultiScaleMaskedTransformerDecoder" + 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/youtubevis_2021/Base-YouTubeVIS-VideoInstanceSegmentation.yaml b/third_party/Mask2Former/configs/youtubevis_2021/Base-YouTubeVIS-VideoInstanceSegmentation.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6545cd11a73a53b7d49c52dccc56846302684e3c --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2021/Base-YouTubeVIS-VideoInstanceSegmentation.yaml @@ -0,0 +1,53 @@ +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] + MASK_ON: True + 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: ("ytvis_2021_train",) + TEST: ("ytvis_2021_val",) +SOLVER: + IMS_PER_BATCH: 16 + BASE_LR: 0.0001 + STEPS: (5500,) + MAX_ITER: 8000 + WARMUP_FACTOR: 1.0 + WARMUP_ITERS: 10 + WEIGHT_DECAY: 0.05 + OPTIMIZER: "ADAMW" + 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_SAMPLING: "choice_by_clip" + RANDOM_FLIP: "flip_by_clip" + AUGMENTATIONS: [] + MIN_SIZE_TRAIN: (360, 480) + MIN_SIZE_TEST: 360 + CROP: + ENABLED: False + TYPE: "absolute_range" + SIZE: (600, 720) + FORMAT: "RGB" +TEST: + EVAL_PERIOD: 0 +DATALOADER: + FILTER_EMPTY_ANNOTATIONS: False + NUM_WORKERS: 4 +VERSION: 2 diff --git a/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_base_IN21k_384_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_base_IN21k_384_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8068edf5a3c6daff7c1776e958c2576255c10ac5 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_base_IN21k_384_bs16_8ep.yaml @@ -0,0 +1,18 @@ +_BASE_: ../video_maskformer2_R50_bs16_8ep.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: "model_final_83d103.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TEST: 480 diff --git a/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_large_IN21k_384_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_large_IN21k_384_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2d20903f2f9c8fa2589d116cc6109122b403791a --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_large_IN21k_384_bs16_8ep.yaml @@ -0,0 +1,21 @@ +_BASE_: ../video_maskformer2_R50_bs16_8ep.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: "model_final_e5f453.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] + MASK_FORMER: + NUM_OBJECT_QUERIES: 200 +# OOM when using a larger test size +# INPUT: +# MIN_SIZE_TEST: 480 diff --git a/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_small_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_small_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..767d30a55186bb97bfafa78a80b9cbd47dded0a0 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_small_bs16_8ep.yaml @@ -0,0 +1,17 @@ +_BASE_: ../video_maskformer2_R50_bs16_8ep.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: "model_final_1e7f22.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TEST: 480 diff --git a/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_tiny_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_tiny_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2d446e2ad9f7af7e94a89b3c3f71bc9e09e0ab19 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2021/swin/video_maskformer2_swin_tiny_bs16_8ep.yaml @@ -0,0 +1,17 @@ +_BASE_: ../video_maskformer2_R50_bs16_8ep.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: "model_final_86143f.pkl" + PIXEL_MEAN: [123.675, 116.280, 103.530] + PIXEL_STD: [58.395, 57.120, 57.375] +INPUT: + MIN_SIZE_TEST: 480 diff --git a/third_party/Mask2Former/configs/youtubevis_2021/video_maskformer2_R101_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2021/video_maskformer2_R101_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fcc9c49346b3f5370111ff992a517eda4e01a5ae --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2021/video_maskformer2_R101_bs16_8ep.yaml @@ -0,0 +1,11 @@ +_BASE_: video_maskformer2_R50_bs16_8ep.yaml +MODEL: + WEIGHTS: "model_final_eba159.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/youtubevis_2021/video_maskformer2_R50_bs16_8ep.yaml b/third_party/Mask2Former/configs/youtubevis_2021/video_maskformer2_R50_bs16_8ep.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8af434dd2efbfb8654f9d958546e660ec46c7e60 --- /dev/null +++ b/third_party/Mask2Former/configs/youtubevis_2021/video_maskformer2_R50_bs16_8ep.yaml @@ -0,0 +1,45 @@ +_BASE_: Base-YouTubeVIS-VideoInstanceSegmentation.yaml +MODEL: + WEIGHTS: "model_final_3c8ec9.pkl" + META_ARCHITECTURE: "VideoMaskFormer" + SEM_SEG_HEAD: + NAME: "MaskFormerHead" + IGNORE_VALUE: 255 + NUM_CLASSES: 40 + 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: "VideoMultiScaleMaskedTransformerDecoder" + 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/demo/README.md b/third_party/Mask2Former/demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..005065278436590f0fd762e3e976e4188bad0aad --- /dev/null +++ b/third_party/Mask2Former/demo/README.md @@ -0,0 +1,4 @@ +## Mask2Former Demo + +We provide a command line tool to run a simple demo of builtin configs. +The usage is explained in [GETTING_STARTED.md](../GETTING_STARTED.md). diff --git a/third_party/Mask2Former/demo/demo.py b/third_party/Mask2Former/demo/demo.py new file mode 100644 index 0000000000000000000000000000000000000000..1b0b4d9db88555b99cec9ba6ef703a9ba9e7323d --- /dev/null +++ b/third_party/Mask2Former/demo/demo.py @@ -0,0 +1,194 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# Modified by Bowen Cheng from: https://github.com/facebookresearch/detectron2/blob/master/demo/demo.py +import argparse +import glob +import multiprocessing as mp +import os + +# fmt: off +import sys +sys.path.insert(1, os.path.join(sys.path[0], '..')) +# fmt: on + +import tempfile +import time +import warnings + +import cv2 +import numpy as np +import tqdm + +from detectron2.config import get_cfg +from detectron2.data.detection_utils import read_image +from detectron2.projects.deeplab import add_deeplab_config +from detectron2.utils.logger import setup_logger + +from mask2former import add_maskformer2_config +from predictor import VisualizationDemo + + +# constants +WINDOW_NAME = "mask2former demo" + + +def setup_cfg(args): + # load config from file and command-line arguments + cfg = get_cfg() + add_deeplab_config(cfg) + add_maskformer2_config(cfg) + cfg.merge_from_file(args.config_file) + cfg.merge_from_list(args.opts) + cfg.freeze() + return cfg + + +def get_parser(): + parser = argparse.ArgumentParser(description="maskformer2 demo for builtin configs") + parser.add_argument( + "--config-file", + default="configs/coco/panoptic-segmentation/maskformer2_R50_bs16_50ep.yaml", + metavar="FILE", + help="path to config file", + ) + parser.add_argument("--webcam", action="store_true", help="Take inputs from webcam.") + parser.add_argument("--video-input", help="Path to video file.") + parser.add_argument( + "--input", + nargs="+", + help="A list of space separated input images; " + "or a single glob pattern such as 'directory/*.jpg'", + ) + parser.add_argument( + "--output", + help="A file or directory to save output visualizations. " + "If not given, will show output in an OpenCV window.", + ) + + parser.add_argument( + "--confidence-threshold", + type=float, + default=0.5, + help="Minimum score for instance predictions to be shown", + ) + parser.add_argument( + "--opts", + help="Modify config options using the command-line 'KEY VALUE' pairs", + default=[], + nargs=argparse.REMAINDER, + ) + return parser + + +def test_opencv_video_format(codec, file_ext): + with tempfile.TemporaryDirectory(prefix="video_format_test") as dir: + filename = os.path.join(dir, "test_file" + file_ext) + writer = cv2.VideoWriter( + filename=filename, + fourcc=cv2.VideoWriter_fourcc(*codec), + fps=float(30), + frameSize=(10, 10), + isColor=True, + ) + [writer.write(np.zeros((10, 10, 3), np.uint8)) for _ in range(30)] + writer.release() + if os.path.isfile(filename): + return True + return False + + +if __name__ == "__main__": + mp.set_start_method("spawn", force=True) + args = get_parser().parse_args() + setup_logger(name="fvcore") + logger = setup_logger() + logger.info("Arguments: " + str(args)) + + cfg = setup_cfg(args) + + demo = VisualizationDemo(cfg) + + if args.input: + if len(args.input) == 1: + args.input = glob.glob(os.path.expanduser(args.input[0])) + assert args.input, "The input path(s) was not found" + for path in tqdm.tqdm(args.input, disable=not args.output): + # use PIL, to be consistent with evaluation + img = read_image(path, format="BGR") + start_time = time.time() + predictions, visualized_output = demo.run_on_image(img) + logger.info( + "{}: {} in {:.2f}s".format( + path, + "detected {} instances".format(len(predictions["instances"])) + if "instances" in predictions + else "finished", + time.time() - start_time, + ) + ) + + if args.output: + if os.path.isdir(args.output): + assert os.path.isdir(args.output), args.output + out_filename = os.path.join(args.output, os.path.basename(path)) + else: + assert len(args.input) == 1, "Please specify a directory with args.output" + out_filename = args.output + visualized_output.save(out_filename) + else: + cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_NORMAL) + cv2.imshow(WINDOW_NAME, visualized_output.get_image()[:, :, ::-1]) + if cv2.waitKey(0) == 27: + break # esc to quit + elif args.webcam: + assert args.input is None, "Cannot have both --input and --webcam!" + assert args.output is None, "output not yet supported with --webcam!" + cam = cv2.VideoCapture(0) + for vis in tqdm.tqdm(demo.run_on_video(cam)): + cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_NORMAL) + cv2.imshow(WINDOW_NAME, vis) + if cv2.waitKey(1) == 27: + break # esc to quit + cam.release() + cv2.destroyAllWindows() + elif args.video_input: + video = cv2.VideoCapture(args.video_input) + width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH)) + height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)) + frames_per_second = video.get(cv2.CAP_PROP_FPS) + num_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT)) + basename = os.path.basename(args.video_input) + codec, file_ext = ( + ("x264", ".mkv") if test_opencv_video_format("x264", ".mkv") else ("mp4v", ".mp4") + ) + if codec == ".mp4v": + warnings.warn("x264 codec not available, switching to mp4v") + if args.output: + if os.path.isdir(args.output): + output_fname = os.path.join(args.output, basename) + output_fname = os.path.splitext(output_fname)[0] + file_ext + else: + output_fname = args.output + assert not os.path.isfile(output_fname), output_fname + output_file = cv2.VideoWriter( + filename=output_fname, + # some installation of opencv may not support x264 (due to its license), + # you can try other format (e.g. MPEG) + fourcc=cv2.VideoWriter_fourcc(*codec), + fps=float(frames_per_second), + frameSize=(width, height), + isColor=True, + ) + assert os.path.isfile(args.video_input) + for vis_frame in tqdm.tqdm(demo.run_on_video(video), total=num_frames): + if args.output: + output_file.write(vis_frame) + else: + cv2.namedWindow(basename, cv2.WINDOW_NORMAL) + cv2.imshow(basename, vis_frame) + if cv2.waitKey(1) == 27: + break # esc to quit + video.release() + if args.output: + output_file.release() + else: + cv2.destroyAllWindows() diff --git a/third_party/Mask2Former/demo/predictor.py b/third_party/Mask2Former/demo/predictor.py new file mode 100644 index 0000000000000000000000000000000000000000..189ec7976f4283b7f3116b6e15b3191fb8fe969f --- /dev/null +++ b/third_party/Mask2Former/demo/predictor.py @@ -0,0 +1,219 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# Copied from: https://github.com/facebookresearch/detectron2/blob/master/demo/predictor.py +import atexit +import bisect +import multiprocessing as mp +from collections import deque + +import cv2 +import torch + +from detectron2.data import MetadataCatalog +from detectron2.engine.defaults import DefaultPredictor +from detectron2.utils.video_visualizer import VideoVisualizer +from detectron2.utils.visualizer import ColorMode, Visualizer + + +class VisualizationDemo(object): + def __init__(self, cfg, instance_mode=ColorMode.IMAGE, parallel=False): + """ + Args: + cfg (CfgNode): + instance_mode (ColorMode): + parallel (bool): whether to run the model in different processes from visualization. + Useful since the visualization logic can be slow. + """ + self.metadata = MetadataCatalog.get( + cfg.DATASETS.TEST[0] if len(cfg.DATASETS.TEST) else "__unused" + ) + self.cpu_device = torch.device("cpu") + self.instance_mode = instance_mode + + self.parallel = parallel + if parallel: + num_gpu = torch.cuda.device_count() + self.predictor = AsyncPredictor(cfg, num_gpus=num_gpu) + else: + self.predictor = DefaultPredictor(cfg) + + def run_on_image(self, image): + """ + Args: + image (np.ndarray): an image of shape (H, W, C) (in BGR order). + This is the format used by OpenCV. + Returns: + predictions (dict): the output of the model. + vis_output (VisImage): the visualized image output. + """ + vis_output = None + predictions = self.predictor(image) + # Convert image from OpenCV BGR format to Matplotlib RGB format. + image = image[:, :, ::-1] + visualizer = Visualizer(image, self.metadata, instance_mode=self.instance_mode) + if "panoptic_seg" in predictions: + panoptic_seg, segments_info = predictions["panoptic_seg"] + vis_output = visualizer.draw_panoptic_seg_predictions( + panoptic_seg.to(self.cpu_device), segments_info + ) + else: + if "sem_seg" in predictions: + vis_output = visualizer.draw_sem_seg( + predictions["sem_seg"].argmax(dim=0).to(self.cpu_device) + ) + if "instances" in predictions: + instances = predictions["instances"].to(self.cpu_device) + vis_output = visualizer.draw_instance_predictions(predictions=instances) + + return predictions, vis_output + + def _frame_from_video(self, video): + while video.isOpened(): + success, frame = video.read() + if success: + yield frame + else: + break + + def run_on_video(self, video): + """ + Visualizes predictions on frames of the input video. + Args: + video (cv2.VideoCapture): a :class:`VideoCapture` object, whose source can be + either a webcam or a video file. + Yields: + ndarray: BGR visualizations of each video frame. + """ + video_visualizer = VideoVisualizer(self.metadata, self.instance_mode) + + def process_predictions(frame, predictions): + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + if "panoptic_seg" in predictions: + panoptic_seg, segments_info = predictions["panoptic_seg"] + vis_frame = video_visualizer.draw_panoptic_seg_predictions( + frame, panoptic_seg.to(self.cpu_device), segments_info + ) + elif "instances" in predictions: + predictions = predictions["instances"].to(self.cpu_device) + vis_frame = video_visualizer.draw_instance_predictions(frame, predictions) + elif "sem_seg" in predictions: + vis_frame = video_visualizer.draw_sem_seg( + frame, predictions["sem_seg"].argmax(dim=0).to(self.cpu_device) + ) + + # Converts Matplotlib RGB format to OpenCV BGR format + vis_frame = cv2.cvtColor(vis_frame.get_image(), cv2.COLOR_RGB2BGR) + return vis_frame + + frame_gen = self._frame_from_video(video) + if self.parallel: + buffer_size = self.predictor.default_buffer_size + + frame_data = deque() + + for cnt, frame in enumerate(frame_gen): + frame_data.append(frame) + self.predictor.put(frame) + + if cnt >= buffer_size: + frame = frame_data.popleft() + predictions = self.predictor.get() + yield process_predictions(frame, predictions) + + while len(frame_data): + frame = frame_data.popleft() + predictions = self.predictor.get() + yield process_predictions(frame, predictions) + else: + for frame in frame_gen: + yield process_predictions(frame, self.predictor(frame)) + + +class AsyncPredictor: + """ + A predictor that runs the model asynchronously, possibly on >1 GPUs. + Because rendering the visualization takes considerably amount of time, + this helps improve throughput a little bit when rendering videos. + """ + + class _StopToken: + pass + + class _PredictWorker(mp.Process): + def __init__(self, cfg, task_queue, result_queue): + self.cfg = cfg + self.task_queue = task_queue + self.result_queue = result_queue + super().__init__() + + def run(self): + predictor = DefaultPredictor(self.cfg) + + while True: + task = self.task_queue.get() + if isinstance(task, AsyncPredictor._StopToken): + break + idx, data = task + result = predictor(data) + self.result_queue.put((idx, result)) + + def __init__(self, cfg, num_gpus: int = 1): + """ + Args: + cfg (CfgNode): + num_gpus (int): if 0, will run on CPU + """ + num_workers = max(num_gpus, 1) + self.task_queue = mp.Queue(maxsize=num_workers * 3) + self.result_queue = mp.Queue(maxsize=num_workers * 3) + self.procs = [] + for gpuid in range(max(num_gpus, 1)): + cfg = cfg.clone() + cfg.defrost() + cfg.MODEL.DEVICE = "cuda:{}".format(gpuid) if num_gpus > 0 else "cpu" + self.procs.append( + AsyncPredictor._PredictWorker(cfg, self.task_queue, self.result_queue) + ) + + self.put_idx = 0 + self.get_idx = 0 + self.result_rank = [] + self.result_data = [] + + for p in self.procs: + p.start() + atexit.register(self.shutdown) + + def put(self, image): + self.put_idx += 1 + self.task_queue.put((self.put_idx, image)) + + def get(self): + self.get_idx += 1 # the index needed for this request + if len(self.result_rank) and self.result_rank[0] == self.get_idx: + res = self.result_data[0] + del self.result_data[0], self.result_rank[0] + return res + + while True: + # make sure the results are returned in the correct order + idx, res = self.result_queue.get() + if idx == self.get_idx: + return res + insert = bisect.bisect(self.result_rank, idx) + self.result_rank.insert(insert, idx) + self.result_data.insert(insert, res) + + def __len__(self): + return self.put_idx - self.get_idx + + def __call__(self, image): + self.put(image) + return self.get() + + def shutdown(self): + for _ in self.procs: + self.task_queue.put(AsyncPredictor._StopToken()) + + @property + def default_buffer_size(self): + return len(self.procs) * 5 diff --git a/third_party/Mask2Former/demo_video/README.md b/third_party/Mask2Former/demo_video/README.md new file mode 100644 index 0000000000000000000000000000000000000000..704154131563d45b54ab6e9f3420fb5b6b7a9915 --- /dev/null +++ b/third_party/Mask2Former/demo_video/README.md @@ -0,0 +1,4 @@ +## Video Mask2Former Demo + +We provide a command line tool to run a simple demo of builtin configs. +The usage is explained in [GETTING_STARTED.md](../GETTING_STARTED.md). diff --git a/third_party/Mask2Former/demo_video/demo.py b/third_party/Mask2Former/demo_video/demo.py new file mode 100644 index 0000000000000000000000000000000000000000..7f30def39bf7ff87bf0f2a8275362091c2b6e6ca --- /dev/null +++ b/third_party/Mask2Former/demo_video/demo.py @@ -0,0 +1,194 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# Modified by Bowen Cheng from: https://github.com/facebookresearch/detectron2/blob/master/demo/demo.py +import argparse +import glob +import multiprocessing as mp +import os + +# fmt: off +import sys +sys.path.insert(1, os.path.join(sys.path[0], '..')) +# fmt: on + +import tempfile +import time +import warnings + +import cv2 +import numpy as np +import tqdm + +from torch.cuda.amp import autocast + +from detectron2.config import get_cfg +from detectron2.data.detection_utils import read_image +from detectron2.projects.deeplab import add_deeplab_config +from detectron2.utils.logger import setup_logger + +from mask2former import add_maskformer2_config +from mask2former_video import add_maskformer2_video_config +from predictor import VisualizationDemo + + +# constants +WINDOW_NAME = "mask2former video demo" + + +def setup_cfg(args): + # load config from file and command-line arguments + cfg = get_cfg() + 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() + return cfg + + +def get_parser(): + parser = argparse.ArgumentParser(description="maskformer2 demo for builtin configs") + parser.add_argument( + "--config-file", + default="configs/youtubevis_2019/video_maskformer2_R50_bs16_8ep.yaml", + metavar="FILE", + help="path to config file", + ) + parser.add_argument("--video-input", help="Path to video file.") + parser.add_argument( + "--input", + nargs="+", + help="A list of space separated input images; " + "or a single glob pattern such as 'directory/*.jpg'" + "this will be treated as frames of a video", + ) + parser.add_argument( + "--output", + help="A file or directory to save output visualizations. " + "If not given, will show output in an OpenCV window.", + ) + + parser.add_argument( + "--save-frames", + default=False, + help="Save frame level image outputs.", + ) + + parser.add_argument( + "--confidence-threshold", + type=float, + default=0.5, + help="Minimum score for instance predictions to be shown", + ) + parser.add_argument( + "--opts", + help="Modify config options using the command-line 'KEY VALUE' pairs", + default=[], + nargs=argparse.REMAINDER, + ) + return parser + + +def test_opencv_video_format(codec, file_ext): + with tempfile.TemporaryDirectory(prefix="video_format_test") as dir: + filename = os.path.join(dir, "test_file" + file_ext) + writer = cv2.VideoWriter( + filename=filename, + fourcc=cv2.VideoWriter_fourcc(*codec), + fps=float(30), + frameSize=(10, 10), + isColor=True, + ) + [writer.write(np.zeros((10, 10, 3), np.uint8)) for _ in range(30)] + writer.release() + if os.path.isfile(filename): + return True + return False + + +if __name__ == "__main__": + mp.set_start_method("spawn", force=True) + args = get_parser().parse_args() + setup_logger(name="fvcore") + logger = setup_logger() + logger.info("Arguments: " + str(args)) + + cfg = setup_cfg(args) + + demo = VisualizationDemo(cfg) + + if args.output: + os.makedirs(args.output, exist_ok=True) + + if args.input: + if len(args.input) == 1: + args.input = glob.glob(os.path.expanduser(args.input[0])) + assert args.input, "The input path(s) was not found" + + vid_frames = [] + for path in args.input: + img = read_image(path, format="BGR") + vid_frames.append(img) + + start_time = time.time() + with autocast(): + predictions, visualized_output = demo.run_on_video(vid_frames) + logger.info( + "detected {} instances per frame in {:.2f}s".format( + len(predictions["pred_scores"]), time.time() - start_time + ) + ) + + if args.output: + if args.save_frames: + for path, _vis_output in zip(args.input, visualized_output): + out_filename = os.path.join(args.output, os.path.basename(path)) + _vis_output.save(out_filename) + + H, W = visualized_output[0].height, visualized_output[0].width + + cap = cv2.VideoCapture(-1) + fourcc = cv2.VideoWriter_fourcc(*"mp4v") + out = cv2.VideoWriter(os.path.join(args.output, "visualization.mp4"), fourcc, 10.0, (W, H), True) + for _vis_output in visualized_output: + frame = _vis_output.get_image()[:, :, ::-1] + out.write(frame) + cap.release() + out.release() + + elif args.video_input: + video = cv2.VideoCapture(args.video_input) + + vid_frames = [] + while video.isOpened(): + success, frame = video.read() + if success: + vid_frames.append(frame) + else: + break + + start_time = time.time() + with autocast(): + predictions, visualized_output = demo.run_on_video(vid_frames) + logger.info( + "detected {} instances per frame in {:.2f}s".format( + len(predictions["pred_scores"]), time.time() - start_time + ) + ) + + if args.output: + if args.save_frames: + for idx, _vis_output in enumerate(visualized_output): + out_filename = os.path.join(args.output, f"{idx}.jpg") + _vis_output.save(out_filename) + + H, W = visualized_output[0].height, visualized_output[0].width + + cap = cv2.VideoCapture(-1) + fourcc = cv2.VideoWriter_fourcc(*"mp4v") + out = cv2.VideoWriter(os.path.join(args.output, "visualization.mp4"), fourcc, 10.0, (W, H), True) + for _vis_output in visualized_output: + frame = _vis_output.get_image()[:, :, ::-1] + out.write(frame) + cap.release() + out.release()