mblt-vision-python 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mblt_vision/__init__.py +86 -0
- mblt_vision/_api.py +53 -0
- mblt_vision/_compat.py +227 -0
- mblt_vision/_model_paths.py +137 -0
- mblt_vision/_tasks.py +30 -0
- mblt_vision/benchmark/__init__.py +1 -0
- mblt_vision/benchmark/argparse_utils.py +106 -0
- mblt_vision/benchmark/chart_utils.py +146 -0
- mblt_vision/benchmark/io_utils.py +64 -0
- mblt_vision/benchmark/summary_utils.py +770 -0
- mblt_vision/cli/__init__.py +5 -0
- mblt_vision/cli/__main__.py +5 -0
- mblt_vision/cli/_vision.py +337 -0
- mblt_vision/cli/compile.py +117 -0
- mblt_vision/cli/main.py +35 -0
- mblt_vision/cli/predict.py +64 -0
- mblt_vision/cli/val.py +562 -0
- mblt_vision/compile/__init__.py +21 -0
- mblt_vision/compile/vision.py +1120 -0
- mblt_vision/datasets/__init__.py +15 -0
- mblt_vision/datasets/ade20k.yaml +164 -0
- mblt_vision/datasets/cityscapes.yaml +54 -0
- mblt_vision/datasets/coco.yaml +178 -0
- mblt_vision/datasets/dotav1.yaml +28 -0
- mblt_vision/datasets/imagenet.yaml +1019 -0
- mblt_vision/datasets/imagenet_synsets.txt +1000 -0
- mblt_vision/datasets/nyu-depth.yaml +7 -0
- mblt_vision/datasets/registry.py +158 -0
- mblt_vision/datasets/widerface.yaml +9 -0
- mblt_vision/depth_estimation/__init__.py +19 -0
- mblt_vision/face_detection/__init__.py +43 -0
- mblt_vision/image_classification/__init__.py +311 -0
- mblt_vision/instance_segmentation/__init__.py +65 -0
- mblt_vision/models/AlexNet.yaml +23 -0
- mblt_vision/models/CAFormer_B36.yaml +22 -0
- mblt_vision/models/CAFormer_M36.yaml +22 -0
- mblt_vision/models/CAFormer_S18.yaml +22 -0
- mblt_vision/models/CAFormer_S36.yaml +22 -0
- mblt_vision/models/CoAtNet_0_RW_224.yaml +22 -0
- mblt_vision/models/CoAtNet_1_RW_224.yaml +22 -0
- mblt_vision/models/CoAtNet_2_RW_224.yaml +22 -0
- mblt_vision/models/ConvFormer_B36.yaml +22 -0
- mblt_vision/models/ConvFormer_M36.yaml +22 -0
- mblt_vision/models/ConvFormer_S18.yaml +22 -0
- mblt_vision/models/ConvFormer_S36.yaml +22 -0
- mblt_vision/models/ConvNext_Base.yaml +23 -0
- mblt_vision/models/ConvNext_Large.yaml +23 -0
- mblt_vision/models/ConvNext_Small.yaml +23 -0
- mblt_vision/models/ConvNext_Tiny.yaml +23 -0
- mblt_vision/models/DeiT3_Base_Patch16_224.yaml +22 -0
- mblt_vision/models/DeiT3_Base_Patch16_384.yaml +22 -0
- mblt_vision/models/DeiT3_Large_Patch16_224.yaml +22 -0
- mblt_vision/models/DeiT3_Large_Patch16_384.yaml +22 -0
- mblt_vision/models/DeiT3_Medium_Patch16_224.yaml +22 -0
- mblt_vision/models/DeiT3_Small_Patch16_224.yaml +22 -0
- mblt_vision/models/DeiT3_Small_Patch16_384.yaml +22 -0
- mblt_vision/models/DeiT_Base_Patch16_224.yaml +22 -0
- mblt_vision/models/DeiT_Base_Patch16_384.yaml +22 -0
- mblt_vision/models/DeiT_Small_Patch16_224.yaml +22 -0
- mblt_vision/models/DeiT_Tiny_Patch16_224.yaml +22 -0
- mblt_vision/models/DenseNet121.yaml +23 -0
- mblt_vision/models/DenseNet161.yaml +23 -0
- mblt_vision/models/DenseNet169.yaml +23 -0
- mblt_vision/models/DenseNet201.yaml +23 -0
- mblt_vision/models/EfficientFormer_L1.yaml +22 -0
- mblt_vision/models/EfficientFormer_L3.yaml +22 -0
- mblt_vision/models/EfficientFormer_L7.yaml +22 -0
- mblt_vision/models/EfficientNet_B0.yaml +23 -0
- mblt_vision/models/EfficientNet_B1.yaml +32 -0
- mblt_vision/models/EfficientNet_B2.yaml +23 -0
- mblt_vision/models/EfficientNet_B3.yaml +23 -0
- mblt_vision/models/EfficientNet_B4.yaml +23 -0
- mblt_vision/models/EfficientNet_B5.yaml +23 -0
- mblt_vision/models/EfficientNet_B6.yaml +23 -0
- mblt_vision/models/EfficientNet_B7.yaml +23 -0
- mblt_vision/models/EfficientNet_V2_L.yaml +23 -0
- mblt_vision/models/EfficientNet_V2_M.yaml +23 -0
- mblt_vision/models/EfficientNet_V2_S.yaml +23 -0
- mblt_vision/models/FlexiVit_Base.yaml +22 -0
- mblt_vision/models/FlexiVit_Large.yaml +22 -0
- mblt_vision/models/FlexiVit_Small.yaml +22 -0
- mblt_vision/models/GELANc-seg.yaml +29 -0
- mblt_vision/models/GELANc.yaml +28 -0
- mblt_vision/models/GELANe.yaml +28 -0
- mblt_vision/models/GELANm.yaml +28 -0
- mblt_vision/models/GELANs.yaml +28 -0
- mblt_vision/models/GoogLeNet.yaml +23 -0
- mblt_vision/models/Inception_V3.yaml +23 -0
- mblt_vision/models/LeViT_Conv_128.yaml +22 -0
- mblt_vision/models/LeViT_Conv_128S.yaml +22 -0
- mblt_vision/models/LeViT_Conv_192.yaml +22 -0
- mblt_vision/models/LeViT_Conv_256.yaml +22 -0
- mblt_vision/models/LeViT_Conv_384.yaml +22 -0
- mblt_vision/models/MNASNet0_5.yaml +23 -0
- mblt_vision/models/MNASNet0_75.yaml +23 -0
- mblt_vision/models/MNASNet1_0.yaml +23 -0
- mblt_vision/models/MNASNet1_3.yaml +23 -0
- mblt_vision/models/MobileNet_V2.yaml +32 -0
- mblt_vision/models/MobileNet_V3_Large.yaml +32 -0
- mblt_vision/models/MobileNet_V3_Small.yaml +23 -0
- mblt_vision/models/RegNet_X_16GF.yaml +32 -0
- mblt_vision/models/RegNet_X_1_6GF.yaml +32 -0
- mblt_vision/models/RegNet_X_32GF.yaml +32 -0
- mblt_vision/models/RegNet_X_3_2GF.yaml +32 -0
- mblt_vision/models/RegNet_X_400MF.yaml +32 -0
- mblt_vision/models/RegNet_X_800MF.yaml +32 -0
- mblt_vision/models/RegNet_X_8GF.yaml +32 -0
- mblt_vision/models/RegNet_Y_16GF.yaml +76 -0
- mblt_vision/models/RegNet_Y_1_6GF.yaml +32 -0
- mblt_vision/models/RegNet_Y_32GF.yaml +76 -0
- mblt_vision/models/RegNet_Y_3_2GF.yaml +32 -0
- mblt_vision/models/RegNet_Y_400MF.yaml +32 -0
- mblt_vision/models/RegNet_Y_800MF.yaml +32 -0
- mblt_vision/models/RegNet_Y_8GF.yaml +32 -0
- mblt_vision/models/RepViT_M0_9.yaml +22 -0
- mblt_vision/models/RepViT_M1.yaml +22 -0
- mblt_vision/models/RepViT_M1_0.yaml +22 -0
- mblt_vision/models/RepViT_M1_1.yaml +22 -0
- mblt_vision/models/RepViT_M1_5.yaml +22 -0
- mblt_vision/models/RepViT_M2.yaml +22 -0
- mblt_vision/models/RepViT_M2_3.yaml +22 -0
- mblt_vision/models/RepViT_M3.yaml +22 -0
- mblt_vision/models/ResNeXt101_32X8D.yaml +32 -0
- mblt_vision/models/ResNeXt101_64X4D.yaml +23 -0
- mblt_vision/models/ResNeXt50_32X4D.yaml +32 -0
- mblt_vision/models/ResNet101.yaml +32 -0
- mblt_vision/models/ResNet152.yaml +32 -0
- mblt_vision/models/ResNet18.yaml +23 -0
- mblt_vision/models/ResNet34.yaml +23 -0
- mblt_vision/models/ResNet50.yaml +32 -0
- mblt_vision/models/ShuffleNet_V2_X0_5.yaml +23 -0
- mblt_vision/models/ShuffleNet_V2_X1_0.yaml +23 -0
- mblt_vision/models/ShuffleNet_V2_X1_5.yaml +23 -0
- mblt_vision/models/ShuffleNet_V2_X2_0.yaml +23 -0
- mblt_vision/models/SqueezeNet1_0.yaml +23 -0
- mblt_vision/models/SqueezeNet1_1.yaml +23 -0
- mblt_vision/models/Swin_B.yaml +23 -0
- mblt_vision/models/Swin_S.yaml +23 -0
- mblt_vision/models/Swin_T.yaml +23 -0
- mblt_vision/models/VGG11.yaml +23 -0
- mblt_vision/models/VGG11_BN.yaml +23 -0
- mblt_vision/models/VGG13.yaml +23 -0
- mblt_vision/models/VGG13_BN.yaml +23 -0
- mblt_vision/models/VGG16.yaml +23 -0
- mblt_vision/models/VGG16_BN.yaml +23 -0
- mblt_vision/models/VGG19.yaml +23 -0
- mblt_vision/models/VGG19_BN.yaml +23 -0
- mblt_vision/models/ViT_B_16.yaml +67 -0
- mblt_vision/models/ViT_B_32.yaml +23 -0
- mblt_vision/models/ViT_Base_Patch16_224.yaml +22 -0
- mblt_vision/models/ViT_Base_Patch16_384.yaml +22 -0
- mblt_vision/models/ViT_Base_Patch32_224.yaml +22 -0
- mblt_vision/models/ViT_Base_Patch32_384.yaml +22 -0
- mblt_vision/models/ViT_Base_Patch8_224.yaml +22 -0
- mblt_vision/models/ViT_L_16.yaml +67 -0
- mblt_vision/models/ViT_L_32.yaml +23 -0
- mblt_vision/models/ViT_Large_Patch16_224.yaml +22 -0
- mblt_vision/models/ViT_Large_Patch16_384.yaml +22 -0
- mblt_vision/models/ViT_Large_Patch32_384.yaml +22 -0
- mblt_vision/models/ViT_Small_Patch16_224.yaml +22 -0
- mblt_vision/models/ViT_Small_Patch16_384.yaml +22 -0
- mblt_vision/models/ViT_Small_Patch32_224.yaml +22 -0
- mblt_vision/models/ViT_Small_Patch32_384.yaml +22 -0
- mblt_vision/models/ViT_Tiny_Patch16_224.yaml +22 -0
- mblt_vision/models/ViT_Tiny_Patch16_384.yaml +22 -0
- mblt_vision/models/VisFormer_Small.yaml +22 -0
- mblt_vision/models/VisFormer_Tiny.yaml +22 -0
- mblt_vision/models/Wide_ResNet101_2.yaml +32 -0
- mblt_vision/models/Wide_ResNet50_2.yaml +32 -0
- mblt_vision/models/YOLO11l-cls.yaml +23 -0
- mblt_vision/models/YOLO11l-face.yaml +27 -0
- mblt_vision/models/YOLO11l-obb.yaml +28 -0
- mblt_vision/models/YOLO11l-pose.yaml +28 -0
- mblt_vision/models/YOLO11l-seg.yaml +28 -0
- mblt_vision/models/YOLO11l.yaml +27 -0
- mblt_vision/models/YOLO11m-cls.yaml +23 -0
- mblt_vision/models/YOLO11m-face.yaml +27 -0
- mblt_vision/models/YOLO11m-obb.yaml +28 -0
- mblt_vision/models/YOLO11m-pose.yaml +28 -0
- mblt_vision/models/YOLO11m-seg.yaml +28 -0
- mblt_vision/models/YOLO11m.yaml +27 -0
- mblt_vision/models/YOLO11n-cls.yaml +23 -0
- mblt_vision/models/YOLO11n-face.yaml +27 -0
- mblt_vision/models/YOLO11n-obb.yaml +28 -0
- mblt_vision/models/YOLO11n-pose.yaml +28 -0
- mblt_vision/models/YOLO11n-seg.yaml +28 -0
- mblt_vision/models/YOLO11n.yaml +27 -0
- mblt_vision/models/YOLO11s-cls.yaml +23 -0
- mblt_vision/models/YOLO11s-face.yaml +27 -0
- mblt_vision/models/YOLO11s-obb.yaml +28 -0
- mblt_vision/models/YOLO11s-pose.yaml +28 -0
- mblt_vision/models/YOLO11s-seg.yaml +28 -0
- mblt_vision/models/YOLO11s.yaml +27 -0
- mblt_vision/models/YOLO11x-cls.yaml +23 -0
- mblt_vision/models/YOLO11x-obb.yaml +28 -0
- mblt_vision/models/YOLO11x-pose.yaml +28 -0
- mblt_vision/models/YOLO11x-seg.yaml +28 -0
- mblt_vision/models/YOLO11x.yaml +27 -0
- mblt_vision/models/YOLO12l-face.yaml +27 -0
- mblt_vision/models/YOLO12l-seg.yaml +28 -0
- mblt_vision/models/YOLO12l.yaml +27 -0
- mblt_vision/models/YOLO12m-face.yaml +27 -0
- mblt_vision/models/YOLO12m-seg.yaml +28 -0
- mblt_vision/models/YOLO12m.yaml +27 -0
- mblt_vision/models/YOLO12n-face.yaml +27 -0
- mblt_vision/models/YOLO12n-seg.yaml +28 -0
- mblt_vision/models/YOLO12n.yaml +27 -0
- mblt_vision/models/YOLO12s-face.yaml +27 -0
- mblt_vision/models/YOLO12s-seg.yaml +28 -0
- mblt_vision/models/YOLO12s.yaml +27 -0
- mblt_vision/models/YOLO12x-seg.yaml +28 -0
- mblt_vision/models/YOLO12x.yaml +27 -0
- mblt_vision/models/YOLO26l-cls.yaml +23 -0
- mblt_vision/models/YOLO26l-depth.yaml +17 -0
- mblt_vision/models/YOLO26l-distill.yaml +27 -0
- mblt_vision/models/YOLO26l-obb.yaml +28 -0
- mblt_vision/models/YOLO26l-pose.yaml +28 -0
- mblt_vision/models/YOLO26l-seg.yaml +28 -0
- mblt_vision/models/YOLO26l-sem-ade20k.yaml +17 -0
- mblt_vision/models/YOLO26l-sem.yaml +17 -0
- mblt_vision/models/YOLO26l.yaml +27 -0
- mblt_vision/models/YOLO26m-cls.yaml +23 -0
- mblt_vision/models/YOLO26m-depth.yaml +17 -0
- mblt_vision/models/YOLO26m-distill.yaml +27 -0
- mblt_vision/models/YOLO26m-obb.yaml +28 -0
- mblt_vision/models/YOLO26m-pose.yaml +28 -0
- mblt_vision/models/YOLO26m-seg.yaml +28 -0
- mblt_vision/models/YOLO26m-sem-ade20k.yaml +17 -0
- mblt_vision/models/YOLO26m-sem.yaml +17 -0
- mblt_vision/models/YOLO26m.yaml +27 -0
- mblt_vision/models/YOLO26n-cls.yaml +23 -0
- mblt_vision/models/YOLO26n-depth.yaml +17 -0
- mblt_vision/models/YOLO26n-distill.yaml +27 -0
- mblt_vision/models/YOLO26n-obb.yaml +28 -0
- mblt_vision/models/YOLO26n-pose.yaml +28 -0
- mblt_vision/models/YOLO26n-seg.yaml +28 -0
- mblt_vision/models/YOLO26n-sem-ade20k.yaml +17 -0
- mblt_vision/models/YOLO26n-sem.yaml +17 -0
- mblt_vision/models/YOLO26n.yaml +27 -0
- mblt_vision/models/YOLO26s-cls.yaml +23 -0
- mblt_vision/models/YOLO26s-depth.yaml +17 -0
- mblt_vision/models/YOLO26s-distill.yaml +27 -0
- mblt_vision/models/YOLO26s-obb.yaml +28 -0
- mblt_vision/models/YOLO26s-pose.yaml +28 -0
- mblt_vision/models/YOLO26s-seg.yaml +28 -0
- mblt_vision/models/YOLO26s-sem-ade20k.yaml +17 -0
- mblt_vision/models/YOLO26s-sem.yaml +17 -0
- mblt_vision/models/YOLO26s.yaml +27 -0
- mblt_vision/models/YOLO26x-cls.yaml +23 -0
- mblt_vision/models/YOLO26x-depth.yaml +17 -0
- mblt_vision/models/YOLO26x-distill.yaml +27 -0
- mblt_vision/models/YOLO26x-obb.yaml +28 -0
- mblt_vision/models/YOLO26x-pose.yaml +28 -0
- mblt_vision/models/YOLO26x-seg.yaml +28 -0
- mblt_vision/models/YOLO26x-sem-ade20k.yaml +17 -0
- mblt_vision/models/YOLO26x-sem.yaml +17 -0
- mblt_vision/models/YOLO26x.yaml +27 -0
- mblt_vision/models/YOLOv10b.yaml +28 -0
- mblt_vision/models/YOLOv10l-face.yaml +28 -0
- mblt_vision/models/YOLOv10l.yaml +28 -0
- mblt_vision/models/YOLOv10m-face.yaml +28 -0
- mblt_vision/models/YOLOv10m.yaml +28 -0
- mblt_vision/models/YOLOv10n-face.yaml +28 -0
- mblt_vision/models/YOLOv10n.yaml +28 -0
- mblt_vision/models/YOLOv10s-face.yaml +28 -0
- mblt_vision/models/YOLOv10s.yaml +28 -0
- mblt_vision/models/YOLOv10x.yaml +28 -0
- mblt_vision/models/YOLOv3-spp.yaml +44 -0
- mblt_vision/models/YOLOv3-sppu.yaml +27 -0
- mblt_vision/models/YOLOv3-tiny.yaml +38 -0
- mblt_vision/models/YOLOv3-tinyu.yaml +27 -0
- mblt_vision/models/YOLOv3.yaml +44 -0
- mblt_vision/models/YOLOv3u.yaml +27 -0
- mblt_vision/models/YOLOv5l-cls.yaml +22 -0
- mblt_vision/models/YOLOv5l-seg.yaml +45 -0
- mblt_vision/models/YOLOv5l.yaml +44 -0
- mblt_vision/models/YOLOv5l6.yaml +50 -0
- mblt_vision/models/YOLOv5l6u.yaml +27 -0
- mblt_vision/models/YOLOv5lu.yaml +27 -0
- mblt_vision/models/YOLOv5m-cls.yaml +22 -0
- mblt_vision/models/YOLOv5m-seg.yaml +45 -0
- mblt_vision/models/YOLOv5m.yaml +45 -0
- mblt_vision/models/YOLOv5m6.yaml +50 -0
- mblt_vision/models/YOLOv5m6u.yaml +27 -0
- mblt_vision/models/YOLOv5mu.yaml +27 -0
- mblt_vision/models/YOLOv5n-cls.yaml +22 -0
- mblt_vision/models/YOLOv5n-seg.yaml +45 -0
- mblt_vision/models/YOLOv5n.yaml +44 -0
- mblt_vision/models/YOLOv5n6.yaml +50 -0
- mblt_vision/models/YOLOv5n6u.yaml +27 -0
- mblt_vision/models/YOLOv5nu.yaml +27 -0
- mblt_vision/models/YOLOv5s-cls.yaml +22 -0
- mblt_vision/models/YOLOv5s-seg.yaml +45 -0
- mblt_vision/models/YOLOv5s.yaml +44 -0
- mblt_vision/models/YOLOv5s6.yaml +50 -0
- mblt_vision/models/YOLOv5s6u.yaml +27 -0
- mblt_vision/models/YOLOv5su.yaml +27 -0
- mblt_vision/models/YOLOv5x-cls.yaml +22 -0
- mblt_vision/models/YOLOv5x-seg.yaml +45 -0
- mblt_vision/models/YOLOv5x.yaml +44 -0
- mblt_vision/models/YOLOv5x6.yaml +50 -0
- mblt_vision/models/YOLOv5x6u.yaml +27 -0
- mblt_vision/models/YOLOv5xu.yaml +27 -0
- mblt_vision/models/YOLOv6m-face.yaml +27 -0
- mblt_vision/models/YOLOv6n-face.yaml +27 -0
- mblt_vision/models/YOLOv7.yaml +44 -0
- mblt_vision/models/YOLOv7d6.yaml +50 -0
- mblt_vision/models/YOLOv7e6.yaml +50 -0
- mblt_vision/models/YOLOv7e6e.yaml +50 -0
- mblt_vision/models/YOLOv7w6.yaml +50 -0
- mblt_vision/models/YOLOv7x.yaml +44 -0
- mblt_vision/models/YOLOv8l-cls.yaml +23 -0
- mblt_vision/models/YOLOv8l-face.yaml +27 -0
- mblt_vision/models/YOLOv8l-obb.yaml +28 -0
- mblt_vision/models/YOLOv8l-pose.yaml +28 -0
- mblt_vision/models/YOLOv8l-seg.yaml +28 -0
- mblt_vision/models/YOLOv8l.yaml +27 -0
- mblt_vision/models/YOLOv8m-cls.yaml +23 -0
- mblt_vision/models/YOLOv8m-face.yaml +27 -0
- mblt_vision/models/YOLOv8m-obb.yaml +28 -0
- mblt_vision/models/YOLOv8m-pose.yaml +28 -0
- mblt_vision/models/YOLOv8m-seg.yaml +28 -0
- mblt_vision/models/YOLOv8m.yaml +27 -0
- mblt_vision/models/YOLOv8n-cls.yaml +23 -0
- mblt_vision/models/YOLOv8n-face.yaml +27 -0
- mblt_vision/models/YOLOv8n-obb.yaml +28 -0
- mblt_vision/models/YOLOv8n-pose.yaml +28 -0
- mblt_vision/models/YOLOv8n-seg.yaml +28 -0
- mblt_vision/models/YOLOv8n.yaml +27 -0
- mblt_vision/models/YOLOv8s-cls.yaml +23 -0
- mblt_vision/models/YOLOv8s-obb.yaml +28 -0
- mblt_vision/models/YOLOv8s-pose.yaml +28 -0
- mblt_vision/models/YOLOv8s-seg.yaml +28 -0
- mblt_vision/models/YOLOv8s.yaml +27 -0
- mblt_vision/models/YOLOv8x-cls.yaml +23 -0
- mblt_vision/models/YOLOv8x-obb.yaml +28 -0
- mblt_vision/models/YOLOv8x-pose-p6.yaml +28 -0
- mblt_vision/models/YOLOv8x-pose.yaml +28 -0
- mblt_vision/models/YOLOv8x-seg.yaml +28 -0
- mblt_vision/models/YOLOv8x.yaml +27 -0
- mblt_vision/models/YOLOv9c-seg.yaml +28 -0
- mblt_vision/models/YOLOv9c.yaml +27 -0
- mblt_vision/models/YOLOv9e-seg.yaml +28 -0
- mblt_vision/models/YOLOv9e.yaml +27 -0
- mblt_vision/models/YOLOv9m.yaml +27 -0
- mblt_vision/models/YOLOv9s.yaml +27 -0
- mblt_vision/models/YOLOv9t.yaml +27 -0
- mblt_vision/obb/__init__.py +39 -0
- mblt_vision/object_detection/__init__.py +153 -0
- mblt_vision/pose_estimation/__init__.py +41 -0
- mblt_vision/py.typed +1 -0
- mblt_vision/semantic_segmentation/__init__.py +29 -0
- mblt_vision/utils/__init__.py +0 -0
- mblt_vision/utils/datasets/__init__.py +85 -0
- mblt_vision/utils/datasets/ade20k.py +41 -0
- mblt_vision/utils/datasets/cityscapes.py +66 -0
- mblt_vision/utils/datasets/coco.py +243 -0
- mblt_vision/utils/datasets/dataloader.py +1016 -0
- mblt_vision/utils/datasets/dotav1.py +59 -0
- mblt_vision/utils/datasets/imagenet.py +29 -0
- mblt_vision/utils/datasets/organizer.py +2145 -0
- mblt_vision/utils/datasets/readiness.py +1063 -0
- mblt_vision/utils/evaluation/__init__.py +51 -0
- mblt_vision/utils/evaluation/_result.py +22 -0
- mblt_vision/utils/evaluation/eval_ade20k.py +302 -0
- mblt_vision/utils/evaluation/eval_cityscapes.py +32 -0
- mblt_vision/utils/evaluation/eval_coco.py +465 -0
- mblt_vision/utils/evaluation/eval_dota.py +878 -0
- mblt_vision/utils/evaluation/eval_imagenet.py +151 -0
- mblt_vision/utils/evaluation/eval_nyu_depth.py +189 -0
- mblt_vision/utils/evaluation/eval_widerface.py +440 -0
- mblt_vision/utils/letterbox.py +118 -0
- mblt_vision/utils/postprocess/__init__.py +9 -0
- mblt_vision/utils/postprocess/_letterbox.py +102 -0
- mblt_vision/utils/postprocess/base.py +743 -0
- mblt_vision/utils/postprocess/build_post.py +120 -0
- mblt_vision/utils/postprocess/cls_post.py +117 -0
- mblt_vision/utils/postprocess/common.py +1571 -0
- mblt_vision/utils/postprocess/depth_post.py +106 -0
- mblt_vision/utils/postprocess/semantic_seg_post.py +192 -0
- mblt_vision/utils/postprocess/yolo_anchor_post.py +469 -0
- mblt_vision/utils/postprocess/yolo_anchorless_post.py +952 -0
- mblt_vision/utils/postprocess/yolo_dflfree_post.py +983 -0
- mblt_vision/utils/postprocess/yolo_nmsfree_post.py +176 -0
- mblt_vision/utils/preprocess/__init__.py +27 -0
- mblt_vision/utils/preprocess/_validation.py +66 -0
- mblt_vision/utils/preprocess/base.py +157 -0
- mblt_vision/utils/preprocess/build_pre.py +48 -0
- mblt_vision/utils/preprocess/center_crop.py +75 -0
- mblt_vision/utils/preprocess/letterbox.py +123 -0
- mblt_vision/utils/preprocess/normalize.py +94 -0
- mblt_vision/utils/preprocess/order.py +74 -0
- mblt_vision/utils/preprocess/reader.py +94 -0
- mblt_vision/utils/preprocess/resize.py +202 -0
- mblt_vision/utils/preprocess/yolo_pre.py +7 -0
- mblt_vision/utils/results.py +725 -0
- mblt_vision/utils/types.py +15 -0
- mblt_vision/wrapper.py +1121 -0
- mblt_vision_python-0.0.0.dist-info/METADATA +152 -0
- mblt_vision_python-0.0.0.dist-info/RECORD +404 -0
- mblt_vision_python-0.0.0.dist-info/WHEEL +5 -0
- mblt_vision_python-0.0.0.dist-info/entry_points.txt +2 -0
- mblt_vision_python-0.0.0.dist-info/licenses/LICENSE +28 -0
- mblt_vision_python-0.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"""
|
|
2
|
+
YOLO anchor-based postprocessing.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Any, cast
|
|
8
|
+
|
|
9
|
+
import torch
|
|
10
|
+
|
|
11
|
+
from .base import YOLODetectionPostBase
|
|
12
|
+
from .common import YOLOSegPostMixin, non_max_suppression
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class YOLOAnchorDetectionPost(YOLODetectionPostBase):
|
|
16
|
+
"""Postprocessing for YOLO models with anchors."""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self, pre_cfg: dict[str, Any], post_cfg: dict[str, Any], **kwargs: Any
|
|
20
|
+
) -> None:
|
|
21
|
+
"""Initialize anchor-based YOLO detection postprocessing.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
pre_cfg (dict): Preprocessing configuration.
|
|
25
|
+
post_cfg (dict): Postprocessing configuration.
|
|
26
|
+
**kwargs: Optional runtime overrides for postprocess behavior.
|
|
27
|
+
"""
|
|
28
|
+
super().__init__(pre_cfg, post_cfg, **kwargs)
|
|
29
|
+
self.no = self.nc + 5 + self.n_extra
|
|
30
|
+
self.grid: torch.Tensor
|
|
31
|
+
self.anchor_grid: torch.Tensor
|
|
32
|
+
self.make_anchor_grid()
|
|
33
|
+
|
|
34
|
+
def non_e2e(self, x: list[torch.Tensor]) -> torch.Tensor | list[torch.Tensor]:
|
|
35
|
+
"""Return the export-style output tensor for anchor-based YOLO models."""
|
|
36
|
+
if len(x) == 1:
|
|
37
|
+
converted = self.conversion(x)
|
|
38
|
+
if isinstance(converted, torch.Tensor):
|
|
39
|
+
return self._converted_to_batch_output(converted)
|
|
40
|
+
det_out, proto_out = converted
|
|
41
|
+
return [self._converted_to_batch_output(det_out), proto_out]
|
|
42
|
+
|
|
43
|
+
rearranged = self.rearrange(x)
|
|
44
|
+
if isinstance(rearranged, tuple):
|
|
45
|
+
det_out, proto_out = rearranged
|
|
46
|
+
return [self.decode_batch(det_out), proto_out.permute(0, 3, 1, 2)]
|
|
47
|
+
return self.decode_batch(rearranged)
|
|
48
|
+
|
|
49
|
+
def _converted_to_batch_output(self, x: torch.Tensor) -> torch.Tensor:
|
|
50
|
+
"""Normalize converted outputs to the export-style batched layout."""
|
|
51
|
+
while x.ndim == 4 and 1 in (x.shape[0], x.shape[1]):
|
|
52
|
+
if x.shape[0] == 1:
|
|
53
|
+
x = x.squeeze(0)
|
|
54
|
+
elif x.shape[1] == 1:
|
|
55
|
+
x = x.squeeze(1)
|
|
56
|
+
if x.ndim != 3:
|
|
57
|
+
raise ValueError(
|
|
58
|
+
f"Expected 3D converted tensor, got shape {tuple(x.shape)}."
|
|
59
|
+
)
|
|
60
|
+
if x.shape[-1] == self.no:
|
|
61
|
+
return x
|
|
62
|
+
if x.shape[1] == self.no:
|
|
63
|
+
return x.transpose(1, 2)
|
|
64
|
+
raise ValueError(
|
|
65
|
+
f"Unsupported converted tensor shape {tuple(x.shape)} for non-e2e output."
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def decode_batch(self, x: torch.Tensor) -> torch.Tensor:
|
|
69
|
+
"""Decode every anchor without filtering and preserve batch shape."""
|
|
70
|
+
batch_size = x.shape[0]
|
|
71
|
+
grid = self.grid.unsqueeze(0).expand(batch_size, -1, -1)
|
|
72
|
+
anchor_grid = self.anchor_grid.unsqueeze(0).expand(batch_size, -1, -1)
|
|
73
|
+
stride = self.stride_as_tensor().unsqueeze(0).expand(batch_size, -1, -1)
|
|
74
|
+
|
|
75
|
+
decoded = x.clone()
|
|
76
|
+
decoded[..., :2] = (
|
|
77
|
+
decoded[..., :2].sigmoid().mul(2.0).add(grid).add(-0.5).mul(stride)
|
|
78
|
+
)
|
|
79
|
+
decoded[..., 2:4] = (
|
|
80
|
+
decoded[..., 2:4].sigmoid().mul(2.0).pow(2.0).mul(anchor_grid)
|
|
81
|
+
)
|
|
82
|
+
conf = decoded[..., 4:5].sigmoid()
|
|
83
|
+
decoded[..., 4:5] = conf
|
|
84
|
+
decoded[..., 5 : 5 + self.nc] = decoded[..., 5 : 5 + self.nc].sigmoid()
|
|
85
|
+
if self.task == "instance_segmentation" and self.n_extra > 0:
|
|
86
|
+
decoded[..., 5 + self.nc :] = decoded[..., 5 + self.nc :] * conf
|
|
87
|
+
return decoded
|
|
88
|
+
|
|
89
|
+
def rearrange(
|
|
90
|
+
self, x: list[torch.Tensor]
|
|
91
|
+
) -> torch.Tensor | tuple[torch.Tensor, torch.Tensor]:
|
|
92
|
+
"""Rearranges raw model output tensors into a concatenated decode input.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
x (list[torch.Tensor]): Raw output tensors from the model detection heads.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
torch.Tensor | tuple[torch.Tensor, torch.Tensor]: Concatenated tensor in
|
|
99
|
+
``(batch, anchors, no)`` format, optionally paired with prototype masks in
|
|
100
|
+
segmentation subclasses.
|
|
101
|
+
"""
|
|
102
|
+
if len(x) != self.nl:
|
|
103
|
+
raise ValueError(f"Expected {self.nl} detection heads, got {len(x)}.")
|
|
104
|
+
y = []
|
|
105
|
+
for i in range(self.nl):
|
|
106
|
+
tmp = x[i]
|
|
107
|
+
if tmp.shape[3] == self.no * self.na:
|
|
108
|
+
y.append(
|
|
109
|
+
tmp.permute(0, 3, 1, 2)
|
|
110
|
+
) # (b, 80, 80, 255) -> (b, 255, 80, 80)
|
|
111
|
+
else:
|
|
112
|
+
raise NotImplementedError(
|
|
113
|
+
f"Got unsupported shape for input: {tmp.shape}."
|
|
114
|
+
)
|
|
115
|
+
# sort by image size descending
|
|
116
|
+
y = sorted(y, key=lambda x: x.numel(), reverse=True)
|
|
117
|
+
return torch.cat(
|
|
118
|
+
[
|
|
119
|
+
xi.reshape(xi.shape[0], self.na, self.no, xi.shape[-2], xi.shape[-1])
|
|
120
|
+
.permute(0, 1, 3, 4, 2)
|
|
121
|
+
.reshape(xi.shape[0], -1, self.no)
|
|
122
|
+
for xi in y
|
|
123
|
+
],
|
|
124
|
+
dim=1,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def decode(self, x: torch.Tensor) -> list[torch.Tensor]:
|
|
128
|
+
"""Decodes model outputs into box coordinates and class scores.
|
|
129
|
+
|
|
130
|
+
Applies sigmoid to predictions and transforms boxes from anchor-relative
|
|
131
|
+
to image-relative coordinates.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
x (torch.Tensor): Concatenated output tensor from `rearrange`.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
list[torch.Tensor]: Per-image decoded detections after confidence filtering.
|
|
138
|
+
"""
|
|
139
|
+
return [self.process_box_cls(box_cls) for box_cls in x]
|
|
140
|
+
|
|
141
|
+
def process_box_cls(self, x: torch.Tensor) -> torch.Tensor:
|
|
142
|
+
"""Processes a single image's detection tensor.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
x: Raw detections for one image.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
Decoded boxes, confidence, and scores.
|
|
149
|
+
"""
|
|
150
|
+
ic = x[:, 4] > self.inv_conf_thres # candidates
|
|
151
|
+
box_cls = x[ic] # (n, 85)
|
|
152
|
+
if box_cls.numel() == 0:
|
|
153
|
+
return box_cls.new_zeros((0, 5 + self.nc + self.n_extra))
|
|
154
|
+
|
|
155
|
+
grid = self.grid[ic, :] # (n, 2)
|
|
156
|
+
anchor_grid = self.anchor_grid[ic, :] # (n, 2)
|
|
157
|
+
stride = self.stride_as_tensor()[ic, :] # (n, 2)
|
|
158
|
+
|
|
159
|
+
# Advanced indexing above materializes ``box_cls``, so in-place decode avoids a second output allocation.
|
|
160
|
+
box_cls[:, :2] = (
|
|
161
|
+
box_cls[:, :2].sigmoid_().mul_(2.0).add_(grid).add_(-0.5).mul_(stride)
|
|
162
|
+
)
|
|
163
|
+
box_cls[:, 2:4] = (
|
|
164
|
+
box_cls[:, 2:4].sigmoid_().mul_(2.0).pow_(2.0).mul_(anchor_grid)
|
|
165
|
+
)
|
|
166
|
+
conf = box_cls[:, 4:5].sigmoid_()
|
|
167
|
+
box_cls[:, 5 : 5 + self.nc].sigmoid_()
|
|
168
|
+
if self.task == "instance_segmentation" and self.n_extra > 0:
|
|
169
|
+
box_cls[:, 5 + self.nc :] *= conf
|
|
170
|
+
return box_cls
|
|
171
|
+
|
|
172
|
+
def filter_conversion(self, x: torch.Tensor) -> list[torch.Tensor]:
|
|
173
|
+
"""Filters out low-confidence detections from a single concatenated output tensor.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
x (torch.Tensor): Concatenated output tensor from the model.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
list[torch.Tensor]: Filtered detections for each image in the batch.
|
|
180
|
+
"""
|
|
181
|
+
x_list = torch.split(
|
|
182
|
+
self._converted_to_batch_output(x), 1, dim=0
|
|
183
|
+
) # [(1, 25200, 85), ...]
|
|
184
|
+
|
|
185
|
+
def process_conversion(x: torch.Tensor) -> torch.Tensor:
|
|
186
|
+
x = x.squeeze(0) # (25200, 85)
|
|
187
|
+
ic = x[:, 4] > self.conf_thres # candidates
|
|
188
|
+
x = x[ic] # (n, 85)
|
|
189
|
+
if len(x) == 0:
|
|
190
|
+
return x.new_zeros((0, self.no))
|
|
191
|
+
return x
|
|
192
|
+
|
|
193
|
+
return [process_conversion(xi) for xi in x_list]
|
|
194
|
+
|
|
195
|
+
def _nms_single(
|
|
196
|
+
self,
|
|
197
|
+
xi: torch.Tensor,
|
|
198
|
+
max_det: int,
|
|
199
|
+
max_nms: int,
|
|
200
|
+
max_wh: int,
|
|
201
|
+
*,
|
|
202
|
+
multi_label: bool,
|
|
203
|
+
) -> torch.Tensor:
|
|
204
|
+
"""Apply anchor-based NMS to a single decoded image tensor."""
|
|
205
|
+
mi = 5 + self.nc # mask index
|
|
206
|
+
if xi.numel() == 0:
|
|
207
|
+
return xi.new_zeros((0, 6 + self.n_extra))
|
|
208
|
+
|
|
209
|
+
scores = xi[:, 5:mi] * xi[:, 4:5]
|
|
210
|
+
if multi_label:
|
|
211
|
+
match_index = (scores > self.conf_thres).nonzero(as_tuple=False)
|
|
212
|
+
if match_index.numel() == 0:
|
|
213
|
+
return xi.new_zeros((0, 6 + self.n_extra))
|
|
214
|
+
i, j = match_index[:, 0], match_index[:, 1]
|
|
215
|
+
rows = xi[i]
|
|
216
|
+
row_scores = scores[i, j]
|
|
217
|
+
else:
|
|
218
|
+
row_scores, j = scores.max(dim=1)
|
|
219
|
+
keep = row_scores > self.conf_thres
|
|
220
|
+
if not bool(keep.any()):
|
|
221
|
+
return xi.new_zeros((0, 6 + self.n_extra))
|
|
222
|
+
rows, row_scores, j = xi[keep], row_scores[keep], j[keep]
|
|
223
|
+
boxes_xywh = rows[:, :4]
|
|
224
|
+
out = torch.empty(
|
|
225
|
+
(rows.shape[0], 6 + self.n_extra), dtype=rows.dtype, device=rows.device
|
|
226
|
+
)
|
|
227
|
+
out[:, 0] = boxes_xywh[:, 0] - boxes_xywh[:, 2] / 2
|
|
228
|
+
out[:, 1] = boxes_xywh[:, 1] - boxes_xywh[:, 3] / 2
|
|
229
|
+
out[:, 2] = boxes_xywh[:, 0] + boxes_xywh[:, 2] / 2
|
|
230
|
+
out[:, 3] = boxes_xywh[:, 1] + boxes_xywh[:, 3] / 2
|
|
231
|
+
out[:, 4] = row_scores
|
|
232
|
+
out[:, 5] = j.to(rows.dtype)
|
|
233
|
+
if self.n_extra > 0:
|
|
234
|
+
out[:, 6:] = rows[:, mi:]
|
|
235
|
+
out = out[out[:, 4].argsort(descending=True)[:max_nms]]
|
|
236
|
+
c = out[:, 5:6] * max_wh
|
|
237
|
+
boxes, score = out[:, :4] + c, out[:, 4]
|
|
238
|
+
i_idx = non_max_suppression(boxes, score, self.iou_thres, max_det)
|
|
239
|
+
return out[i_idx]
|
|
240
|
+
|
|
241
|
+
def nms(
|
|
242
|
+
self,
|
|
243
|
+
x: torch.Tensor | list[torch.Tensor],
|
|
244
|
+
max_det: int = 300,
|
|
245
|
+
max_nms: int = 30000,
|
|
246
|
+
max_wh: int = 7680,
|
|
247
|
+
multi_label: bool = False,
|
|
248
|
+
) -> list[torch.Tensor]:
|
|
249
|
+
"""
|
|
250
|
+
Perform Non-Maximum Suppression (NMS) on the decoded detections.
|
|
251
|
+
Args:
|
|
252
|
+
x (list[torch.Tensor]): Decoded detections for each image.
|
|
253
|
+
max_det (int, optional): Maximum number of detections to keep. Defaults to 300.
|
|
254
|
+
max_nms (int, optional): Maximum number of candidates to consider for NMS.
|
|
255
|
+
Defaults to 30000.
|
|
256
|
+
max_wh (int, optional): Maximum box width/height for offset calculation.
|
|
257
|
+
Defaults to 7680.
|
|
258
|
+
Returns:
|
|
259
|
+
list[torch.Tensor]: Post-NMS detections for each image.
|
|
260
|
+
"""
|
|
261
|
+
if isinstance(x, list):
|
|
262
|
+
return [
|
|
263
|
+
self._nms_single(
|
|
264
|
+
xi,
|
|
265
|
+
max_det=max_det,
|
|
266
|
+
max_nms=max_nms,
|
|
267
|
+
max_wh=max_wh,
|
|
268
|
+
multi_label=multi_label,
|
|
269
|
+
)
|
|
270
|
+
for xi in x
|
|
271
|
+
]
|
|
272
|
+
return [
|
|
273
|
+
self._nms_single(
|
|
274
|
+
xi,
|
|
275
|
+
max_det=max_det,
|
|
276
|
+
max_nms=max_nms,
|
|
277
|
+
max_wh=max_wh,
|
|
278
|
+
multi_label=multi_label,
|
|
279
|
+
)
|
|
280
|
+
for xi in x
|
|
281
|
+
]
|
|
282
|
+
|
|
283
|
+
def nms_multilabel(
|
|
284
|
+
self, x: torch.Tensor | list[torch.Tensor]
|
|
285
|
+
) -> list[torch.Tensor]:
|
|
286
|
+
"""Perform Ultralytics-compatible multi-label NMS for validation."""
|
|
287
|
+
|
|
288
|
+
return self.nms(x, multi_label=True)
|
|
289
|
+
|
|
290
|
+
def make_anchor_grid(self) -> None:
|
|
291
|
+
"""
|
|
292
|
+
Pre-calculate the anchor grid for decoding.
|
|
293
|
+
"""
|
|
294
|
+
grid_parts: list[torch.Tensor] = []
|
|
295
|
+
anchor_grid_parts: list[torch.Tensor] = []
|
|
296
|
+
stride_parts: list[torch.Tensor] = []
|
|
297
|
+
strides = [2 ** (3 + i) for i in range(self.nl)]
|
|
298
|
+
if self.nl == 2:
|
|
299
|
+
strides = [strd * 2 for strd in strides]
|
|
300
|
+
out_sizes = [
|
|
301
|
+
[self.imh // strd, self.imw // strd] for strd in strides
|
|
302
|
+
] # (80, 80), (40, 40), (20, 20)
|
|
303
|
+
for anchr, (ny, nx), strd in zip(self.anchors_as_list(), out_sizes, strides):
|
|
304
|
+
yv, xv = torch.meshgrid(
|
|
305
|
+
torch.arange(ny, dtype=torch.float32, device=self.device),
|
|
306
|
+
torch.arange(nx, dtype=torch.float32, device=self.device),
|
|
307
|
+
indexing="ij",
|
|
308
|
+
)
|
|
309
|
+
grid = torch.stack((xv, yv), 2).expand(self.na, ny, nx, 2)
|
|
310
|
+
grid_parts.append(grid)
|
|
311
|
+
anchr_tensor = torch.broadcast_to(
|
|
312
|
+
torch.tensor(anchr).reshape(self.na, 1, 1, 2),
|
|
313
|
+
(self.na, ny, nx, 2),
|
|
314
|
+
)
|
|
315
|
+
anchor_grid_parts.append(anchr_tensor)
|
|
316
|
+
stride_parts.append(strd * torch.ones(self.na, ny, nx, 2))
|
|
317
|
+
self.grid = torch.cat([grd.reshape(-1, 2) for grd in grid_parts], dim=0)
|
|
318
|
+
self.anchor_grid = torch.cat(
|
|
319
|
+
[anc.reshape(-1, 2) for anc in anchor_grid_parts], dim=0
|
|
320
|
+
)
|
|
321
|
+
self.stride = torch.cat([strd.reshape(-1, 2) for strd in stride_parts], dim=0)
|
|
322
|
+
|
|
323
|
+
def chop(self, npu_out: torch.Tensor, idx: int = 0) -> tuple[torch.Tensor, ...]:
|
|
324
|
+
"""Splits the detection tensor into individual components (xy, wh, conf, scores, extra).
|
|
325
|
+
|
|
326
|
+
Args:
|
|
327
|
+
npu_out (torch.Tensor): Raw detection tensor from one detection head.
|
|
328
|
+
idx (int, optional): Detection head index. Defaults to 0.
|
|
329
|
+
|
|
330
|
+
Returns:
|
|
331
|
+
tuple: (xy, wh, conf, scores, extra).
|
|
332
|
+
"""
|
|
333
|
+
xy, wh, conf, scores, extra = torch.split(
|
|
334
|
+
npu_out, [2, 2, 1, self.nc, self.n_extra], dim=-1
|
|
335
|
+
)
|
|
336
|
+
return xy, wh, conf, scores, extra
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
class YOLOAnchorSegPost(YOLOSegPostMixin, YOLOAnchorDetectionPost):
|
|
340
|
+
"""Postprocessing for YOLO segmentation models with anchors."""
|
|
341
|
+
|
|
342
|
+
def non_e2e(self, x: list[torch.Tensor]) -> torch.Tensor | list[torch.Tensor]:
|
|
343
|
+
"""Return the export-style output tensor for anchor-based YOLO segmentation models.
|
|
344
|
+
|
|
345
|
+
Args:
|
|
346
|
+
x: Checked raw model outputs.
|
|
347
|
+
|
|
348
|
+
Returns:
|
|
349
|
+
A detection tensor, or detections paired with prototype masks.
|
|
350
|
+
"""
|
|
351
|
+
if any(xi.ndim <= 4 and self.no in xi.shape[1:] for xi in x):
|
|
352
|
+
converted, proto_outs = self.conversion(x)
|
|
353
|
+
return [
|
|
354
|
+
self._converted_to_batch_output(converted),
|
|
355
|
+
self._proto_to_nchw(proto_outs),
|
|
356
|
+
]
|
|
357
|
+
return super().non_e2e(x)
|
|
358
|
+
|
|
359
|
+
def _proto_to_nchw(self, proto: torch.Tensor) -> torch.Tensor:
|
|
360
|
+
"""Convert prototype tensors to ``(B, C, H, W)`` if needed.
|
|
361
|
+
|
|
362
|
+
Args:
|
|
363
|
+
proto: Prototype tensor from a model runtime.
|
|
364
|
+
|
|
365
|
+
Returns:
|
|
366
|
+
Prototype tensor in channel-first batch layout.
|
|
367
|
+
"""
|
|
368
|
+
if proto.ndim == 4 and proto.shape[1] == self.n_extra:
|
|
369
|
+
return proto
|
|
370
|
+
if proto.ndim == 4 and proto.shape[-1] == self.n_extra:
|
|
371
|
+
return proto.permute(0, 3, 1, 2)
|
|
372
|
+
raise ValueError(
|
|
373
|
+
f"Unsupported proto tensor shape {tuple(proto.shape)} for non-e2e output."
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
def _pre_process(self, x: list[torch.Tensor]) -> tuple[Any, torch.Tensor | None]:
|
|
377
|
+
"""Preprocesses intermediate inputs into (boxes, proto) format.
|
|
378
|
+
|
|
379
|
+
Args:
|
|
380
|
+
x (list[torch.Tensor]): Raw model output tensors.
|
|
381
|
+
|
|
382
|
+
Returns:
|
|
383
|
+
tuple: (decoded_detections, prototype_masks).
|
|
384
|
+
"""
|
|
385
|
+
if any(xi.ndim <= 4 and self.no in xi.shape[1:] for xi in x):
|
|
386
|
+
converted, proto_outs = cast(
|
|
387
|
+
tuple[torch.Tensor, torch.Tensor], self.conversion(x)
|
|
388
|
+
)
|
|
389
|
+
return self.filter_conversion(converted), proto_outs
|
|
390
|
+
rearranged, proto_outs = self.rearrange(x)
|
|
391
|
+
return self.decode(rearranged), proto_outs
|
|
392
|
+
|
|
393
|
+
def conversion(self, x: list[torch.Tensor]) -> tuple[torch.Tensor, torch.Tensor]:
|
|
394
|
+
"""Converts raw model output tensors into detections and prototypes.
|
|
395
|
+
|
|
396
|
+
Args:
|
|
397
|
+
x (list[torch.Tensor]): List of raw output tensors.
|
|
398
|
+
|
|
399
|
+
Returns:
|
|
400
|
+
tuple: (detections, prototypes)
|
|
401
|
+
"""
|
|
402
|
+
det_out: torch.Tensor | None = None
|
|
403
|
+
proto_out: torch.Tensor | None = None
|
|
404
|
+
for xi in x:
|
|
405
|
+
if xi.ndim <= 4 and self.no in xi.shape[1:]:
|
|
406
|
+
det_out = xi
|
|
407
|
+
elif xi.ndim == 4 and self.n_extra in xi.shape[1:]:
|
|
408
|
+
proto_out = xi
|
|
409
|
+
if det_out is None or proto_out is None:
|
|
410
|
+
shapes = ", ".join(str(tuple(xi.shape)) for xi in x)
|
|
411
|
+
raise NotImplementedError(
|
|
412
|
+
f"Input shapes not supported for anchor segmentation: {shapes}."
|
|
413
|
+
)
|
|
414
|
+
return det_out, proto_out
|
|
415
|
+
|
|
416
|
+
def rearrange(self, x: list[torch.Tensor]) -> tuple[torch.Tensor, torch.Tensor]:
|
|
417
|
+
"""Rearranges model output tensors for segmentation tasks.
|
|
418
|
+
|
|
419
|
+
Args:
|
|
420
|
+
x (list[torch.Tensor]): Raw output tensors from detection and prototype heads.
|
|
421
|
+
|
|
422
|
+
Returns:
|
|
423
|
+
tuple[torch.Tensor, torch.Tensor]: Concatenated detections and prototype masks.
|
|
424
|
+
"""
|
|
425
|
+
proto: torch.Tensor | None = None
|
|
426
|
+
for i, xi in enumerate(x):
|
|
427
|
+
if self.n_extra == xi.shape[-1]:
|
|
428
|
+
proto = x.pop(i)
|
|
429
|
+
break
|
|
430
|
+
if proto is None:
|
|
431
|
+
raise ValueError("Proto output is missing.")
|
|
432
|
+
y = []
|
|
433
|
+
for xi in x:
|
|
434
|
+
if xi.shape[-1] == self.no * self.nl:
|
|
435
|
+
y.append(xi.permute(0, 3, 1, 2))
|
|
436
|
+
else:
|
|
437
|
+
raise ValueError(f"Wrong shape of input: {xi.shape}")
|
|
438
|
+
# sort by image size descending
|
|
439
|
+
y = sorted(y, key=lambda x: x.numel(), reverse=True)
|
|
440
|
+
return (
|
|
441
|
+
torch.cat(
|
|
442
|
+
[
|
|
443
|
+
xi.reshape(
|
|
444
|
+
xi.shape[0], self.na, self.no, xi.shape[-2], xi.shape[-1]
|
|
445
|
+
)
|
|
446
|
+
.permute(0, 1, 3, 4, 2)
|
|
447
|
+
.reshape(xi.shape[0], -1, self.no)
|
|
448
|
+
for xi in y
|
|
449
|
+
],
|
|
450
|
+
dim=1,
|
|
451
|
+
),
|
|
452
|
+
proto,
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
def chop(self, npu_out: torch.Tensor, idx: int = 0) -> tuple[torch.Tensor, ...]:
|
|
456
|
+
"""Splits the detection tensor for segmentation tasks.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
npu_out (torch.Tensor): Raw detection tensor.
|
|
460
|
+
idx (int, optional): Detection head index. Defaults to 0.
|
|
461
|
+
|
|
462
|
+
Returns:
|
|
463
|
+
tuple: (xy, wh, conf, scores, masks).
|
|
464
|
+
"""
|
|
465
|
+
xy, wh, conf, scores, masks = torch.split(
|
|
466
|
+
npu_out, [2, 2, 1, self.nc, self.n_extra], dim=-1
|
|
467
|
+
)
|
|
468
|
+
masks = masks * conf.sigmoid()
|
|
469
|
+
return xy, wh, conf, scores, masks
|