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,94 @@
|
|
|
1
|
+
"""Normalization operation for image preprocessing."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
import torch
|
|
7
|
+
from PIL import Image
|
|
8
|
+
|
|
9
|
+
from ..types import TensorLike
|
|
10
|
+
from .base import PreOps
|
|
11
|
+
|
|
12
|
+
STYLE_PARAMS = {
|
|
13
|
+
"torch": ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
|
14
|
+
"tf": ([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]),
|
|
15
|
+
"openai": (
|
|
16
|
+
[0.48145466, 0.4578275, 0.40821073],
|
|
17
|
+
[0.26862954, 0.26130258, 0.27577711],
|
|
18
|
+
),
|
|
19
|
+
"cv": ([0.0, 0.0, 0.0], [1.0, 1.0, 1.0]),
|
|
20
|
+
}
|
|
21
|
+
STYLE_LIST = list(STYLE_PARAMS.keys())
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Normalize(PreOps):
|
|
25
|
+
"""Normalization layer to scale and shift image data.
|
|
26
|
+
|
|
27
|
+
Attributes:
|
|
28
|
+
style: Data source style (e.g., 'torch', 'tf', 'openai', 'cv').
|
|
29
|
+
mean: Array of mean values for normalization.
|
|
30
|
+
std: Array of standard deviation values for normalization.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, style: str) -> None:
|
|
34
|
+
"""Initializes the Normalize layer with a specific style.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
style: The preprocessing style to use. Must be one of STYLE_LIST.
|
|
38
|
+
"""
|
|
39
|
+
super().__init__()
|
|
40
|
+
|
|
41
|
+
if not isinstance(style, str):
|
|
42
|
+
raise TypeError(
|
|
43
|
+
f"Normalize style must be a string, got {type(style).__name__}."
|
|
44
|
+
)
|
|
45
|
+
if style.lower() not in STYLE_LIST:
|
|
46
|
+
raise ValueError(
|
|
47
|
+
f"Unsupported Normalize style {style!r}; expected one of {STYLE_LIST}."
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
self.style = style.lower()
|
|
51
|
+
mean, std = STYLE_PARAMS[self.style]
|
|
52
|
+
self.mean = np.array(mean)
|
|
53
|
+
self.std = np.array(std)
|
|
54
|
+
|
|
55
|
+
def __call__(self, x: TensorLike | Image.Image) -> np.ndarray:
|
|
56
|
+
"""Applies normalization to the input image or tensor.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
x (TensorLike | Image.Image): Input data as a torch.Tensor, PIL Image, or numpy-like array.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
np.ndarray: The normalized image as a float32 numpy array.
|
|
63
|
+
"""
|
|
64
|
+
if isinstance(x, torch.Tensor):
|
|
65
|
+
x = x.detach().cpu().numpy()
|
|
66
|
+
elif isinstance(x, Image.Image):
|
|
67
|
+
x = np.array(x)
|
|
68
|
+
elif not isinstance(x, np.ndarray):
|
|
69
|
+
raise TypeError(
|
|
70
|
+
f"Normalize expects a NumPy array, tensor, or PIL image, got {type(x).__name__}."
|
|
71
|
+
)
|
|
72
|
+
if x.ndim != 3:
|
|
73
|
+
raise ValueError(
|
|
74
|
+
f"Normalize expects a three-dimensional image, got shape {x.shape}."
|
|
75
|
+
)
|
|
76
|
+
x = x.astype(np.float32) / 255.0
|
|
77
|
+
channels_first = x.shape[0] == len(self.mean)
|
|
78
|
+
channels_last = x.shape[-1] == len(self.mean)
|
|
79
|
+
if channels_first and channels_last:
|
|
80
|
+
raise ValueError(
|
|
81
|
+
f"Normalize cannot infer channel order from ambiguous shape {x.shape}."
|
|
82
|
+
)
|
|
83
|
+
if channels_last:
|
|
84
|
+
mean, std = self.mean, self.std
|
|
85
|
+
elif channels_first:
|
|
86
|
+
mean = self.mean[:, None, None]
|
|
87
|
+
std = self.std[:, None, None]
|
|
88
|
+
else:
|
|
89
|
+
raise ValueError(
|
|
90
|
+
f"Normalize expects HWC or CHW data with {len(self.mean)} channels, "
|
|
91
|
+
f"got shape {x.shape}."
|
|
92
|
+
)
|
|
93
|
+
x = (x - mean) / std
|
|
94
|
+
return x.astype(np.float32)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Channel order preprocessing.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import torch
|
|
9
|
+
|
|
10
|
+
from ..types import TensorLike
|
|
11
|
+
from .base import PreOps
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SetOrder(PreOps):
|
|
15
|
+
"""Sets the channel order of the image to either HWC or CHW format."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, shape: str = "HWC") -> None:
|
|
18
|
+
"""Initializes the SetOrder operation.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
shape (str, optional): Target channel order, either "HWC" or "CHW".
|
|
22
|
+
Defaults to "HWC".
|
|
23
|
+
"""
|
|
24
|
+
super().__init__()
|
|
25
|
+
if not isinstance(shape, str):
|
|
26
|
+
raise TypeError(
|
|
27
|
+
f"SetOrder shape must be a string, got {type(shape).__name__}."
|
|
28
|
+
)
|
|
29
|
+
if shape.lower() not in {"hwc", "chw"}:
|
|
30
|
+
raise ValueError(
|
|
31
|
+
f"Unsupported channel order {shape!r}; expected 'HWC' or 'CHW'."
|
|
32
|
+
)
|
|
33
|
+
self.shape = shape.lower()
|
|
34
|
+
|
|
35
|
+
def __call__(self, x: TensorLike) -> TensorLike:
|
|
36
|
+
"""Reorders the dimensions of the input image.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
x (TensorLike): Input image of shape (3, H, W) or (H, W, 3).
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
TensorLike: Image with the specified channel order.
|
|
43
|
+
"""
|
|
44
|
+
if not isinstance(x, (np.ndarray, torch.Tensor)):
|
|
45
|
+
raise TypeError(
|
|
46
|
+
f"SetOrder expects a NumPy array or tensor, got {type(x).__name__}."
|
|
47
|
+
)
|
|
48
|
+
if x.ndim != 3:
|
|
49
|
+
raise ValueError(
|
|
50
|
+
f"SetOrder expects a three-dimensional color image, got shape {x.shape}."
|
|
51
|
+
)
|
|
52
|
+
channels_first = x.shape[0] == 3
|
|
53
|
+
channels_last = x.shape[-1] == 3
|
|
54
|
+
if channels_first and channels_last:
|
|
55
|
+
raise ValueError(
|
|
56
|
+
f"SetOrder cannot infer channel order from ambiguous shape {x.shape}."
|
|
57
|
+
)
|
|
58
|
+
if channels_first:
|
|
59
|
+
cdim = 0
|
|
60
|
+
elif channels_last:
|
|
61
|
+
cdim = 2
|
|
62
|
+
else:
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f"SetOrder expects HWC or CHW data with three channels, got shape {x.shape}."
|
|
65
|
+
)
|
|
66
|
+
if cdim == 0 and self.shape == "hwc":
|
|
67
|
+
if isinstance(x, torch.Tensor):
|
|
68
|
+
return torch.permute(x, (1, 2, 0))
|
|
69
|
+
return np.transpose(x, (1, 2, 0))
|
|
70
|
+
elif cdim == 2 and self.shape == "chw":
|
|
71
|
+
if isinstance(x, torch.Tensor):
|
|
72
|
+
return torch.permute(x, (2, 0, 1))
|
|
73
|
+
return np.transpose(x, (2, 0, 1))
|
|
74
|
+
return x
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Image reader preprocessing.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import cv2
|
|
10
|
+
import numpy as np
|
|
11
|
+
import torch
|
|
12
|
+
from PIL import Image
|
|
13
|
+
|
|
14
|
+
from ..types import TensorLike
|
|
15
|
+
from ._validation import normalize_uint8_rgb_array
|
|
16
|
+
from .base import PreOps
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Reader(PreOps):
|
|
20
|
+
"""
|
|
21
|
+
Reader for loading images from file paths or converting existing objects.
|
|
22
|
+
Supports "pil" and "numpy" reading styles.
|
|
23
|
+
|
|
24
|
+
For ``style="pil"``, arrays must be ``uint8`` RGB values or finite floating-point
|
|
25
|
+
RGB values. Floating-point arrays in ``[0, 1]`` are treated as normalized RGB and
|
|
26
|
+
scaled to ``[0, 255]``; other floating-point arrays must already be in ``[0, 255]``.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, style: str) -> None:
|
|
30
|
+
"""Initializes the Reader operation.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
style (str): Reading style, either "pil" or "numpy".
|
|
34
|
+
"""
|
|
35
|
+
super().__init__()
|
|
36
|
+
if not isinstance(style, str):
|
|
37
|
+
raise TypeError(
|
|
38
|
+
f"Reader style must be a string, got {type(style).__name__}."
|
|
39
|
+
)
|
|
40
|
+
if style.lower() not in {"pil", "numpy"}:
|
|
41
|
+
raise ValueError(
|
|
42
|
+
f"Unsupported Reader style {style!r}; expected 'pil' or 'numpy'."
|
|
43
|
+
)
|
|
44
|
+
self.style = style.lower()
|
|
45
|
+
|
|
46
|
+
def __call__(
|
|
47
|
+
self, x: str | Path | TensorLike | Image.Image
|
|
48
|
+
) -> np.ndarray | Image.Image:
|
|
49
|
+
"""Reads/converts the input into an image object.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
x (str | Path | TensorLike | Image.Image): Input image path or image object.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
np.ndarray | Image.Image: Read image in the specified style.
|
|
56
|
+
"""
|
|
57
|
+
if self.style == "numpy":
|
|
58
|
+
if isinstance(x, np.ndarray):
|
|
59
|
+
return x
|
|
60
|
+
elif isinstance(x, torch.Tensor):
|
|
61
|
+
return x.detach().cpu().numpy()
|
|
62
|
+
elif isinstance(x, (str, Path)):
|
|
63
|
+
image = cv2.imread(str(x))
|
|
64
|
+
if image is None:
|
|
65
|
+
raise FileNotFoundError(f"Image not found: {x}")
|
|
66
|
+
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
|
67
|
+
elif isinstance(x, Image.Image):
|
|
68
|
+
return np.array(x)
|
|
69
|
+
else:
|
|
70
|
+
raise TypeError(
|
|
71
|
+
f"Reader(style='numpy') does not support input type {type(x).__name__}."
|
|
72
|
+
)
|
|
73
|
+
elif self.style == "pil":
|
|
74
|
+
if isinstance(x, np.ndarray):
|
|
75
|
+
return Image.fromarray(
|
|
76
|
+
normalize_uint8_rgb_array(x, operation="Reader(style='pil')")
|
|
77
|
+
)
|
|
78
|
+
elif isinstance(x, torch.Tensor):
|
|
79
|
+
x = x.detach().cpu().numpy()
|
|
80
|
+
return Image.fromarray(
|
|
81
|
+
normalize_uint8_rgb_array(x, operation="Reader(style='pil')")
|
|
82
|
+
)
|
|
83
|
+
elif isinstance(x, (str, Path)):
|
|
84
|
+
return Image.open(x).convert("RGB")
|
|
85
|
+
elif isinstance(x, Image.Image):
|
|
86
|
+
return x
|
|
87
|
+
else:
|
|
88
|
+
raise TypeError(
|
|
89
|
+
f"Reader(style='pil') does not support input type {type(x).__name__}."
|
|
90
|
+
)
|
|
91
|
+
else:
|
|
92
|
+
raise RuntimeError(
|
|
93
|
+
f"Reader has an invalid validated style: {self.style!r}."
|
|
94
|
+
)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Image resizing preprocessing.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import torch
|
|
9
|
+
import torch.nn.functional as F
|
|
10
|
+
from PIL import Image
|
|
11
|
+
|
|
12
|
+
from ..types import TensorLike
|
|
13
|
+
from ._validation import normalize_image_size
|
|
14
|
+
from .base import PreOps
|
|
15
|
+
|
|
16
|
+
PIL_INTERP_CODES = {
|
|
17
|
+
"nearest": Image.Resampling.NEAREST,
|
|
18
|
+
"bilinear": Image.Resampling.BILINEAR,
|
|
19
|
+
"bicubic": Image.Resampling.BICUBIC,
|
|
20
|
+
"box": Image.Resampling.BOX,
|
|
21
|
+
"hamming": Image.Resampling.HAMMING,
|
|
22
|
+
"lanczos": Image.Resampling.LANCZOS,
|
|
23
|
+
}
|
|
24
|
+
TORCH_INTERPOLATION_MODES = frozenset({"nearest", "bilinear", "bicubic"})
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Resize(PreOps):
|
|
28
|
+
"""Resizes the image to a specified size using various interpolation modes.
|
|
29
|
+
|
|
30
|
+
Supports PyTorch tensors in CHW or BCHW format, HWC NumPy arrays, and PIL images.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
size: int | list[int],
|
|
36
|
+
interpolation: str,
|
|
37
|
+
) -> None:
|
|
38
|
+
"""
|
|
39
|
+
Initialize the Resize operation.
|
|
40
|
+
Args:
|
|
41
|
+
size (int | list[int]): Target size. If int, the shorter edge is resized to this size
|
|
42
|
+
maintaining aspect ratio. If [h, w], it is resized to exactly this size.
|
|
43
|
+
interpolation (str): Interpolation mode (e.g., "bilinear", "bicubic", "nearest").
|
|
44
|
+
"""
|
|
45
|
+
# Note that this behaves different for npy image and PIL image
|
|
46
|
+
super().__init__()
|
|
47
|
+
self.size = (
|
|
48
|
+
size
|
|
49
|
+
if isinstance(size, int) and not isinstance(size, bool)
|
|
50
|
+
else normalize_image_size(size)
|
|
51
|
+
)
|
|
52
|
+
if isinstance(self.size, int) and self.size <= 0:
|
|
53
|
+
raise ValueError(f"size must be positive, got {self.size}.")
|
|
54
|
+
if interpolation not in PIL_INTERP_CODES:
|
|
55
|
+
raise ValueError(
|
|
56
|
+
f"Unsupported resize interpolation {interpolation!r}; expected one of {sorted(PIL_INTERP_CODES)}."
|
|
57
|
+
)
|
|
58
|
+
self.interpolation = interpolation
|
|
59
|
+
|
|
60
|
+
def __call__(
|
|
61
|
+
self, x: TensorLike | Image.Image
|
|
62
|
+
) -> np.ndarray | torch.Tensor | Image.Image:
|
|
63
|
+
"""Resizes the input image.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
x (TensorLike | Image.Image): Image to be resized.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
np.ndarray | torch.Tensor | Image.Image: Resized image in the same format as input.
|
|
70
|
+
|
|
71
|
+
Raises:
|
|
72
|
+
TypeError: If input type is not supported.
|
|
73
|
+
ValueError: If an input has an invalid layout or uses a PIL-only interpolation mode.
|
|
74
|
+
"""
|
|
75
|
+
if isinstance(x, np.ndarray):
|
|
76
|
+
self._validate_tensor_interpolation()
|
|
77
|
+
if x.ndim != 3:
|
|
78
|
+
raise ValueError(
|
|
79
|
+
f"Expected an HWC NumPy array, but got x.shape={x.shape}."
|
|
80
|
+
)
|
|
81
|
+
img_h, img_w = x.shape[:2]
|
|
82
|
+
new_h, new_w = self._compute_resized_output_size(img_h, img_w)
|
|
83
|
+
if [img_h, img_w] == [new_h, new_w]:
|
|
84
|
+
return x
|
|
85
|
+
|
|
86
|
+
tensor_x = torch.from_numpy(x).to(self.device)
|
|
87
|
+
tensor_x = tensor_x.permute(2, 0, 1)
|
|
88
|
+
tensor_x, need_cast, need_squeeze, out_dtype = self._cast_squeeze_in(
|
|
89
|
+
tensor_x, [torch.float32, torch.float64]
|
|
90
|
+
)
|
|
91
|
+
tensor_x = F.interpolate(
|
|
92
|
+
tensor_x,
|
|
93
|
+
size=(new_h, new_w),
|
|
94
|
+
mode=self.interpolation,
|
|
95
|
+
align_corners=(
|
|
96
|
+
False if self.interpolation in ["bilinear", "bicubic"] else None
|
|
97
|
+
),
|
|
98
|
+
antialias=self.interpolation in ["bilinear", "bicubic"],
|
|
99
|
+
)
|
|
100
|
+
tensor_x = self._cast_squeeze_out(
|
|
101
|
+
tensor_x, need_cast, need_squeeze, out_dtype
|
|
102
|
+
)
|
|
103
|
+
return tensor_x.permute(1, 2, 0).cpu().numpy()
|
|
104
|
+
elif isinstance(x, torch.Tensor):
|
|
105
|
+
self._validate_tensor_interpolation()
|
|
106
|
+
tensor_x = x.to(self.device)
|
|
107
|
+
elif isinstance(x, Image.Image):
|
|
108
|
+
img_w, img_h = x.size
|
|
109
|
+
new_h, new_w = self._compute_resized_output_size(img_h, img_w)
|
|
110
|
+
if [img_h, img_w] == [new_h, new_w]:
|
|
111
|
+
return x
|
|
112
|
+
return x.resize(
|
|
113
|
+
size=(new_w, new_h),
|
|
114
|
+
resample=PIL_INTERP_CODES[self.interpolation],
|
|
115
|
+
)
|
|
116
|
+
else:
|
|
117
|
+
raise TypeError(f"Got unexpected type for x={type(x)}.")
|
|
118
|
+
|
|
119
|
+
if tensor_x.ndim not in (3, 4):
|
|
120
|
+
raise ValueError(
|
|
121
|
+
f"Expected a CHW or BCHW tensor, but got x.shape={tensor_x.shape}."
|
|
122
|
+
)
|
|
123
|
+
img_h, img_w = tensor_x.shape[-2:]
|
|
124
|
+
new_h, new_w = self._compute_resized_output_size(img_h, img_w)
|
|
125
|
+
if [img_h, img_w] == [new_h, new_w]:
|
|
126
|
+
return tensor_x
|
|
127
|
+
tensor_x, need_cast, need_squeeze, out_dtype = self._cast_squeeze_in(
|
|
128
|
+
tensor_x, [torch.float32, torch.float64]
|
|
129
|
+
)
|
|
130
|
+
tensor_x = F.interpolate(
|
|
131
|
+
tensor_x,
|
|
132
|
+
size=(new_h, new_w),
|
|
133
|
+
mode=self.interpolation,
|
|
134
|
+
align_corners=(
|
|
135
|
+
False if self.interpolation in ["bilinear", "bicubic"] else None
|
|
136
|
+
),
|
|
137
|
+
antialias=self.interpolation in ["bilinear", "bicubic"],
|
|
138
|
+
)
|
|
139
|
+
tensor_x = self._cast_squeeze_out(tensor_x, need_cast, need_squeeze, out_dtype)
|
|
140
|
+
return tensor_x.to(self.device)
|
|
141
|
+
|
|
142
|
+
def _validate_tensor_interpolation(self) -> None:
|
|
143
|
+
"""Reject interpolation modes unsupported by PyTorch tensors."""
|
|
144
|
+
|
|
145
|
+
if self.interpolation not in TORCH_INTERPOLATION_MODES:
|
|
146
|
+
raise ValueError(
|
|
147
|
+
f"Resize interpolation {self.interpolation!r} is supported only for PIL images; "
|
|
148
|
+
f"NumPy arrays and tensors require one of {sorted(TORCH_INTERPOLATION_MODES)}."
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def _compute_resized_output_size(self, img_h: int, img_w: int) -> list[int]:
|
|
152
|
+
if isinstance(self.size, int):
|
|
153
|
+
# to match the shortest side to self.size with the same ratio
|
|
154
|
+
if img_w <= img_h:
|
|
155
|
+
new_w = self.size
|
|
156
|
+
new_h = int(self.size * img_h / img_w)
|
|
157
|
+
else:
|
|
158
|
+
new_h = self.size
|
|
159
|
+
new_w = int(self.size * img_w / img_h)
|
|
160
|
+
elif isinstance(self.size, list):
|
|
161
|
+
new_h, new_w = self.size
|
|
162
|
+
else:
|
|
163
|
+
raise RuntimeError(f"Resize has an invalid validated size: {self.size!r}.")
|
|
164
|
+
return [new_h, new_w]
|
|
165
|
+
|
|
166
|
+
def _cast_squeeze_in(
|
|
167
|
+
self, img: torch.Tensor, req_dtypes: list[torch.dtype]
|
|
168
|
+
) -> tuple[torch.Tensor, bool, bool, torch.dtype]:
|
|
169
|
+
need_squeeze = False
|
|
170
|
+
# make image NCHW
|
|
171
|
+
if img.ndim < 4:
|
|
172
|
+
img = img.unsqueeze(dim=0)
|
|
173
|
+
need_squeeze = True
|
|
174
|
+
out_dtype = img.dtype
|
|
175
|
+
need_cast = False
|
|
176
|
+
if out_dtype not in req_dtypes:
|
|
177
|
+
need_cast = True
|
|
178
|
+
req_dtype = req_dtypes[0]
|
|
179
|
+
img = img.to(req_dtype)
|
|
180
|
+
return img, need_cast, need_squeeze, out_dtype
|
|
181
|
+
|
|
182
|
+
def _cast_squeeze_out(
|
|
183
|
+
self,
|
|
184
|
+
img: torch.Tensor,
|
|
185
|
+
need_cast: bool,
|
|
186
|
+
need_squeeze: bool,
|
|
187
|
+
out_dtype: torch.dtype,
|
|
188
|
+
) -> torch.Tensor:
|
|
189
|
+
if need_squeeze:
|
|
190
|
+
img = img.squeeze(dim=0)
|
|
191
|
+
if need_cast:
|
|
192
|
+
if out_dtype in (
|
|
193
|
+
torch.uint8,
|
|
194
|
+
torch.int8,
|
|
195
|
+
torch.int16,
|
|
196
|
+
torch.int32,
|
|
197
|
+
torch.int64,
|
|
198
|
+
):
|
|
199
|
+
# it is better to round before cast
|
|
200
|
+
img = torch.round(img)
|
|
201
|
+
img = img.to(out_dtype)
|
|
202
|
+
return img
|