video-representations-extractor 1.5.16__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.
- build/lib/examples/batched_experiment/batched_experiment.py +38 -0
- build/lib/examples/semantic_mapper/semantic_mapper.py +381 -0
- build/lib/test/fake_representation.py +25 -0
- build/lib/test/integration/readers/test_multitask_dataset.py +99 -0
- build/lib/test/integration/representations/semantic_segmentation/test_i_mask2former.py +29 -0
- build/lib/test/integration/representations/soft_segmentation/test_i_fastsam.py +15 -0
- build/lib/test/integration/test_no_vre_setup_if_not_needed.py +60 -0
- build/lib/test/integration/test_vre.py +112 -0
- build/lib/test/integration/test_vre_batched.py +164 -0
- build/lib/test/integration/test_vre_taskmapped_representations.py +78 -0
- build/lib/test/unit/representations/color/test_hsv.py +31 -0
- build/lib/test/unit/representations/color/test_rgb.py +30 -0
- build/lib/test/unit/representations/depth/test_dpt.py +26 -0
- build/lib/test/unit/representations/depth/test_marigold.py +27 -0
- build/lib/test/unit/representations/edges/test_canny.py +23 -0
- build/lib/test/unit/representations/edges/test_dexined.py +26 -0
- build/lib/test/unit/representations/normals/test_depth_normals_svd.py +26 -0
- build/lib/test/unit/representations/optical_flow/test_raft.py +26 -0
- build/lib/test/unit/representations/optical_flow/test_rife.py +26 -0
- build/lib/test/unit/representations/semantic_segmentation/test_mask2former.py +26 -0
- build/lib/test/unit/representations/semantic_segmentation/test_safeuav.py +29 -0
- build/lib/test/unit/representations/soft_segmentation/test_fastssam.py +33 -0
- build/lib/test/unit/representations/soft_segmentation/test_generalized_boundaries.py +25 -0
- build/lib/test/unit/representations/soft_segmentation/test_halftone.py +24 -0
- build/lib/test/unit/representations/test_build_representations.py +135 -0
- build/lib/test/unit/representations/test_representation.py +22 -0
- build/lib/test/unit/test_data_writer_storer.py +74 -0
- build/lib/test/unit/test_vre_runtime_args.py +32 -0
- build/lib/test/unit/utils/test_fake_video.py +20 -0
- build/lib/vre/__init__.py +25 -0
- build/lib/vre/data_storer.py +77 -0
- build/lib/vre/data_writer.py +116 -0
- build/lib/vre/logger.py +3 -0
- build/lib/vre/metadata.py +26 -0
- build/lib/vre/readers/__init__.py +2 -0
- build/lib/vre/readers/multitask_dataset.py +322 -0
- build/lib/vre/readers/statistics.py +93 -0
- build/lib/vre/representations/__init__.py +13 -0
- build/lib/vre/representations/build_representations.py +163 -0
- build/lib/vre/representations/color/__init__.py +3 -0
- build/lib/vre/representations/color/hsv.py +69 -0
- build/lib/vre/representations/color/rgb.py +26 -0
- build/lib/vre/representations/compute_representation_mixin.py +67 -0
- build/lib/vre/representations/cv_representations.py +116 -0
- build/lib/vre/representations/depth/__init__.py +0 -0
- build/lib/vre/representations/depth/dpt/__init__.py +2 -0
- build/lib/vre/representations/depth/dpt/depth_dpt.py +67 -0
- build/lib/vre/representations/depth/dpt/dpt_impl/__init__.py +3 -0
- build/lib/vre/representations/depth/dpt/dpt_impl/base_model.py +17 -0
- build/lib/vre/representations/depth/dpt/dpt_impl/blocks.py +341 -0
- build/lib/vre/representations/depth/dpt/dpt_impl/dpt_depth.py +107 -0
- build/lib/vre/representations/depth/dpt/dpt_impl/utils.py +27 -0
- build/lib/vre/representations/depth/dpt/dpt_impl/vit.py +492 -0
- build/lib/vre/representations/depth/marigold/__init__.py +2 -0
- build/lib/vre/representations/depth/marigold/marigold.py +194 -0
- build/lib/vre/representations/depth/marigold/marigold_impl/__init__.py +2 -0
- build/lib/vre/representations/depth/marigold/marigold_impl/ensemble.py +160 -0
- build/lib/vre/representations/depth/marigold/marigold_impl/marigold_pipeline.py +252 -0
- build/lib/vre/representations/depth/marigold/marigold_impl/marigold_util.py +64 -0
- build/lib/vre/representations/edges/__init__.py +0 -0
- build/lib/vre/representations/edges/canny.py +36 -0
- build/lib/vre/representations/edges/dexined/__init__.py +2 -0
- build/lib/vre/representations/edges/dexined/dexined.py +75 -0
- build/lib/vre/representations/edges/dexined/model_dexined.py +279 -0
- build/lib/vre/representations/io_representation_mixin.py +139 -0
- build/lib/vre/representations/learned_representation_mixin.py +48 -0
- build/lib/vre/representations/normals/__init__.py +0 -0
- build/lib/vre/representations/normals/depth_svd/__init__.py +2 -0
- build/lib/vre/representations/normals/depth_svd/depth_normals_svd.py +67 -0
- build/lib/vre/representations/normals/depth_svd/depth_svd_impl/__init__.py +3 -0
- build/lib/vre/representations/normals/depth_svd/depth_svd_impl/cam.py +77 -0
- build/lib/vre/representations/normals/depth_svd/depth_svd_impl/utils.py +84 -0
- build/lib/vre/representations/normed_representation_mixin.py +53 -0
- build/lib/vre/representations/np_io_representation.py +52 -0
- build/lib/vre/representations/optical_flow/__init__.py +0 -0
- build/lib/vre/representations/optical_flow/raft/__init__.py +2 -0
- build/lib/vre/representations/optical_flow/raft/flow_raft.py +98 -0
- build/lib/vre/representations/optical_flow/raft/raft_impl/__init__.py +3 -0
- build/lib/vre/representations/optical_flow/raft/raft_impl/corr.py +92 -0
- build/lib/vre/representations/optical_flow/raft/raft_impl/datasets.py +236 -0
- build/lib/vre/representations/optical_flow/raft/raft_impl/extractor.py +268 -0
- build/lib/vre/representations/optical_flow/raft/raft_impl/raft.py +129 -0
- build/lib/vre/representations/optical_flow/raft/raft_impl/update.py +140 -0
- build/lib/vre/representations/optical_flow/raft/raft_impl/utils.py +50 -0
- build/lib/vre/representations/optical_flow/rife/__init__.py +2 -0
- build/lib/vre/representations/optical_flow/rife/flow_rife.py +86 -0
- build/lib/vre/representations/optical_flow/rife/rife_impl/IFNet_HD.py +122 -0
- build/lib/vre/representations/optical_flow/rife/rife_impl/IFNet_HDv2.py +96 -0
- build/lib/vre/representations/optical_flow/rife/rife_impl/RIFE_HDv2.py +216 -0
- build/lib/vre/representations/optical_flow/rife/rife_impl/__init__.py +2 -0
- build/lib/vre/representations/optical_flow/rife/rife_impl/loss.py +85 -0
- build/lib/vre/representations/optical_flow/rife/rife_impl/warplayer.py +24 -0
- build/lib/vre/representations/representation.py +63 -0
- build/lib/vre/representations/semantic_segmentation/__init__.py +0 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/__init__.py +2 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/convert.py +845 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former.py +120 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/__init__.py +4 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/config.py +155 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/__init__.py +7 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/blocks.py +116 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/deform_conv.py +509 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/norm.py +265 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/shape_spec.py +19 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/wrappers.py +45 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/maskformer_model.py +405 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/__init__.py +5 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/backbone/__init__.py +0 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/backbone/swin.py +770 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/meta_arch/__init__.py +0 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/meta_arch/mask_former_head.py +123 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/pixel_decoder/__init__.py +0 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/pixel_decoder/fpn.py +294 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/pixel_decoder/ms_deform_attn.py +140 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/pixel_decoder/msdeformattn.py +354 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/resnet.py +741 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/__init__.py +4 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/mask2former_transformer_decoder.py +454 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/maskformer_transformer_decoder.py +178 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/position_encoding.py +65 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/transformer.py +370 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/resources/__init__.py +0 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/structures/__init__.py +4 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/structures/boxes.py +185 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/structures/instances.py +195 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/utils.py +11 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/weight_init.py +32 -0
- build/lib/vre/representations/semantic_segmentation/mask2former/mask2former_impl/yacs_config.py +527 -0
- build/lib/vre/representations/semantic_segmentation/safeuav/Map2Map.py +109 -0
- build/lib/vre/representations/semantic_segmentation/safeuav/__init__.py +2 -0
- build/lib/vre/representations/semantic_segmentation/safeuav/safeuav.py +107 -0
- build/lib/vre/representations/soft_segmentation/__init__.py +0 -0
- build/lib/vre/representations/soft_segmentation/fastsam/__init__.py +3 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam.py +208 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam_impl/__init__.py +7 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam_impl/decoder.py +131 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam_impl/model.py +193 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam_impl/ops.py +285 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam_impl/predict.py +174 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam_impl/prompt.py +445 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam_impl/results.py +828 -0
- build/lib/vre/representations/soft_segmentation/fastsam/fastsam_impl/utils.py +260 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/__init__.py +1 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/nn/__init__.py +3 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/__init__.py +29 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/block.py +305 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/conv.py +298 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/head.py +373 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/transformer.py +379 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/utils.py +79 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/nn/tasks.py +94 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/yolo/__init__.py +1 -0
- build/lib/vre/representations/soft_segmentation/fastsam/ultralytics/yolo/utils/__init__.py +20 -0
- build/lib/vre/representations/soft_segmentation/generalized_boundaries/__init__.py +2 -0
- build/lib/vre/representations/soft_segmentation/generalized_boundaries/gb_impl/__init__.py +0 -0
- build/lib/vre/representations/soft_segmentation/generalized_boundaries/gb_impl/softseg.py +111 -0
- build/lib/vre/representations/soft_segmentation/generalized_boundaries/gb_impl/util.py +85 -0
- build/lib/vre/representations/soft_segmentation/generalized_boundaries/generalized_boundaries.py +39 -0
- build/lib/vre/representations/soft_segmentation/halftone/__init__.py +2 -0
- build/lib/vre/representations/soft_segmentation/halftone/halftone.py +173 -0
- build/lib/vre/representations/task_mapper.py +50 -0
- build/lib/vre/utils/__init__.py +9 -0
- build/lib/vre/utils/colorized_sem_seg.py +338 -0
- build/lib/vre/utils/colorizer.py +29 -0
- build/lib/vre/utils/cv2_utils.py +105 -0
- build/lib/vre/utils/image.py +150 -0
- build/lib/vre/utils/pil_utils.py +110 -0
- build/lib/vre/utils/resources.py +79 -0
- build/lib/vre/utils/topological_sort.py +37 -0
- build/lib/vre/utils/utils.py +102 -0
- build/lib/vre/utils/vre_video.py +137 -0
- build/lib/vre/video_representations_extractor.py +184 -0
- build/lib/vre/vre_runtime_args.py +61 -0
- examples/batched_experiment/batched_experiment.py +38 -0
- examples/semantic_mapper/semantic_mapper.py +381 -0
- test/fake_representation.py +25 -0
- test/integration/readers/test_multitask_dataset.py +99 -0
- test/integration/representations/semantic_segmentation/test_i_mask2former.py +29 -0
- test/integration/representations/soft_segmentation/test_i_fastsam.py +15 -0
- test/integration/test_no_vre_setup_if_not_needed.py +60 -0
- test/integration/test_vre.py +112 -0
- test/integration/test_vre_batched.py +164 -0
- test/integration/test_vre_taskmapped_representations.py +78 -0
- test/unit/representations/color/test_hsv.py +31 -0
- test/unit/representations/color/test_rgb.py +30 -0
- test/unit/representations/depth/test_dpt.py +26 -0
- test/unit/representations/depth/test_marigold.py +27 -0
- test/unit/representations/edges/test_canny.py +23 -0
- test/unit/representations/edges/test_dexined.py +26 -0
- test/unit/representations/normals/test_depth_normals_svd.py +26 -0
- test/unit/representations/optical_flow/test_raft.py +26 -0
- test/unit/representations/optical_flow/test_rife.py +26 -0
- test/unit/representations/semantic_segmentation/test_mask2former.py +26 -0
- test/unit/representations/semantic_segmentation/test_safeuav.py +29 -0
- test/unit/representations/soft_segmentation/test_fastssam.py +33 -0
- test/unit/representations/soft_segmentation/test_generalized_boundaries.py +25 -0
- test/unit/representations/soft_segmentation/test_halftone.py +24 -0
- test/unit/representations/test_build_representations.py +135 -0
- test/unit/representations/test_representation.py +22 -0
- test/unit/test_data_writer_storer.py +74 -0
- test/unit/test_vre_runtime_args.py +32 -0
- test/unit/utils/test_fake_video.py +20 -0
- video_representations_extractor-1.5.16.data/data/47429163_0_cfg.json +1 -0
- video_representations_extractor-1.5.16.data/data/49189528_0_cfg.json +1 -0
- video_representations_extractor-1.5.16.data/data/49189528_1_cfg.json +1 -0
- video_representations_extractor-1.5.16.data/data/README.md +25 -0
- video_representations_extractor-1.5.16.data/data/coco_metadata.json +1 -0
- video_representations_extractor-1.5.16.data/data/empty_text_embed.pkl +0 -0
- video_representations_extractor-1.5.16.data/data/mapillary_metadata.json +1 -0
- video_representations_extractor-1.5.16.data/data/mapillary_metadata2.json +1 -0
- video_representations_extractor-1.5.16.data/scripts/vre +86 -0
- video_representations_extractor-1.5.16.data/scripts/vre_collage +106 -0
- video_representations_extractor-1.5.16.dist-info/LICENSE.TXT +7 -0
- video_representations_extractor-1.5.16.dist-info/METADATA +193 -0
- video_representations_extractor-1.5.16.dist-info/RECORD +361 -0
- video_representations_extractor-1.5.16.dist-info/WHEEL +5 -0
- video_representations_extractor-1.5.16.dist-info/top_level.txt +8 -0
- vre/__init__.py +25 -0
- vre/data_storer.py +77 -0
- vre/data_writer.py +116 -0
- vre/logger.py +3 -0
- vre/metadata.py +26 -0
- vre/readers/__init__.py +2 -0
- vre/readers/multitask_dataset.py +322 -0
- vre/readers/statistics.py +93 -0
- vre/representations/__init__.py +13 -0
- vre/representations/build_representations.py +163 -0
- vre/representations/color/__init__.py +3 -0
- vre/representations/color/hsv.py +69 -0
- vre/representations/color/rgb.py +26 -0
- vre/representations/compute_representation_mixin.py +67 -0
- vre/representations/cv_representations.py +116 -0
- vre/representations/depth/__init__.py +0 -0
- vre/representations/depth/dpt/__init__.py +2 -0
- vre/representations/depth/dpt/depth_dpt.py +67 -0
- vre/representations/depth/dpt/dpt_impl/__init__.py +3 -0
- vre/representations/depth/dpt/dpt_impl/base_model.py +17 -0
- vre/representations/depth/dpt/dpt_impl/blocks.py +341 -0
- vre/representations/depth/dpt/dpt_impl/dpt_depth.py +107 -0
- vre/representations/depth/dpt/dpt_impl/utils.py +27 -0
- vre/representations/depth/dpt/dpt_impl/vit.py +492 -0
- vre/representations/depth/marigold/__init__.py +2 -0
- vre/representations/depth/marigold/marigold.py +194 -0
- vre/representations/depth/marigold/marigold_impl/__init__.py +2 -0
- vre/representations/depth/marigold/marigold_impl/ensemble.py +160 -0
- vre/representations/depth/marigold/marigold_impl/marigold_pipeline.py +252 -0
- vre/representations/depth/marigold/marigold_impl/marigold_util.py +64 -0
- vre/representations/edges/__init__.py +0 -0
- vre/representations/edges/canny.py +36 -0
- vre/representations/edges/dexined/__init__.py +2 -0
- vre/representations/edges/dexined/dexined.py +75 -0
- vre/representations/edges/dexined/model_dexined.py +279 -0
- vre/representations/io_representation_mixin.py +139 -0
- vre/representations/learned_representation_mixin.py +48 -0
- vre/representations/normals/__init__.py +0 -0
- vre/representations/normals/depth_svd/__init__.py +2 -0
- vre/representations/normals/depth_svd/depth_normals_svd.py +67 -0
- vre/representations/normals/depth_svd/depth_svd_impl/__init__.py +3 -0
- vre/representations/normals/depth_svd/depth_svd_impl/cam.py +77 -0
- vre/representations/normals/depth_svd/depth_svd_impl/utils.py +84 -0
- vre/representations/normed_representation_mixin.py +53 -0
- vre/representations/np_io_representation.py +52 -0
- vre/representations/optical_flow/__init__.py +0 -0
- vre/representations/optical_flow/raft/__init__.py +2 -0
- vre/representations/optical_flow/raft/flow_raft.py +98 -0
- vre/representations/optical_flow/raft/raft_impl/__init__.py +3 -0
- vre/representations/optical_flow/raft/raft_impl/corr.py +92 -0
- vre/representations/optical_flow/raft/raft_impl/datasets.py +236 -0
- vre/representations/optical_flow/raft/raft_impl/extractor.py +268 -0
- vre/representations/optical_flow/raft/raft_impl/raft.py +129 -0
- vre/representations/optical_flow/raft/raft_impl/update.py +140 -0
- vre/representations/optical_flow/raft/raft_impl/utils.py +50 -0
- vre/representations/optical_flow/rife/__init__.py +2 -0
- vre/representations/optical_flow/rife/flow_rife.py +86 -0
- vre/representations/optical_flow/rife/rife_impl/IFNet_HD.py +122 -0
- vre/representations/optical_flow/rife/rife_impl/IFNet_HDv2.py +96 -0
- vre/representations/optical_flow/rife/rife_impl/RIFE_HDv2.py +216 -0
- vre/representations/optical_flow/rife/rife_impl/__init__.py +2 -0
- vre/representations/optical_flow/rife/rife_impl/loss.py +85 -0
- vre/representations/optical_flow/rife/rife_impl/warplayer.py +24 -0
- vre/representations/representation.py +63 -0
- vre/representations/semantic_segmentation/__init__.py +0 -0
- vre/representations/semantic_segmentation/mask2former/__init__.py +2 -0
- vre/representations/semantic_segmentation/mask2former/convert.py +845 -0
- vre/representations/semantic_segmentation/mask2former/mask2former.py +120 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/__init__.py +4 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/config.py +155 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/__init__.py +7 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/blocks.py +116 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/deform_conv.py +509 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/norm.py +265 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/shape_spec.py +19 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/layers/wrappers.py +45 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/maskformer_model.py +405 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/__init__.py +5 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/backbone/__init__.py +0 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/backbone/swin.py +770 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/meta_arch/__init__.py +0 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/meta_arch/mask_former_head.py +123 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/pixel_decoder/__init__.py +0 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/pixel_decoder/fpn.py +294 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/pixel_decoder/ms_deform_attn.py +140 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/pixel_decoder/msdeformattn.py +354 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/resnet.py +741 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/__init__.py +4 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/mask2former_transformer_decoder.py +454 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/maskformer_transformer_decoder.py +178 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/position_encoding.py +65 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/modeling/transformer_decoder/transformer.py +370 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/resources/__init__.py +0 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/structures/__init__.py +4 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/structures/boxes.py +185 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/structures/instances.py +195 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/utils.py +11 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/weight_init.py +32 -0
- vre/representations/semantic_segmentation/mask2former/mask2former_impl/yacs_config.py +527 -0
- vre/representations/semantic_segmentation/safeuav/Map2Map.py +109 -0
- vre/representations/semantic_segmentation/safeuav/__init__.py +2 -0
- vre/representations/semantic_segmentation/safeuav/safeuav.py +107 -0
- vre/representations/soft_segmentation/__init__.py +0 -0
- vre/representations/soft_segmentation/fastsam/__init__.py +3 -0
- vre/representations/soft_segmentation/fastsam/fastsam.py +208 -0
- vre/representations/soft_segmentation/fastsam/fastsam_impl/__init__.py +7 -0
- vre/representations/soft_segmentation/fastsam/fastsam_impl/decoder.py +131 -0
- vre/representations/soft_segmentation/fastsam/fastsam_impl/model.py +193 -0
- vre/representations/soft_segmentation/fastsam/fastsam_impl/ops.py +285 -0
- vre/representations/soft_segmentation/fastsam/fastsam_impl/predict.py +174 -0
- vre/representations/soft_segmentation/fastsam/fastsam_impl/prompt.py +445 -0
- vre/representations/soft_segmentation/fastsam/fastsam_impl/results.py +828 -0
- vre/representations/soft_segmentation/fastsam/fastsam_impl/utils.py +260 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/__init__.py +1 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/nn/__init__.py +3 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/__init__.py +29 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/block.py +305 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/conv.py +298 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/head.py +373 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/transformer.py +379 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/nn/modules/utils.py +79 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/nn/tasks.py +94 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/yolo/__init__.py +1 -0
- vre/representations/soft_segmentation/fastsam/ultralytics/yolo/utils/__init__.py +20 -0
- vre/representations/soft_segmentation/generalized_boundaries/__init__.py +2 -0
- vre/representations/soft_segmentation/generalized_boundaries/gb_impl/__init__.py +0 -0
- vre/representations/soft_segmentation/generalized_boundaries/gb_impl/softseg.py +111 -0
- vre/representations/soft_segmentation/generalized_boundaries/gb_impl/util.py +85 -0
- vre/representations/soft_segmentation/generalized_boundaries/generalized_boundaries.py +39 -0
- vre/representations/soft_segmentation/halftone/__init__.py +2 -0
- vre/representations/soft_segmentation/halftone/halftone.py +173 -0
- vre/representations/task_mapper.py +50 -0
- vre/utils/__init__.py +9 -0
- vre/utils/colorized_sem_seg.py +338 -0
- vre/utils/colorizer.py +29 -0
- vre/utils/cv2_utils.py +105 -0
- vre/utils/image.py +150 -0
- vre/utils/pil_utils.py +110 -0
- vre/utils/resources.py +79 -0
- vre/utils/topological_sort.py +37 -0
- vre/utils/utils.py +102 -0
- vre/utils/vre_video.py +137 -0
- vre/video_representations_extractor.py +184 -0
- vre/vre_runtime_args.py +61 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""experiment using batches of frames"""
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from omegaconf import OmegaConf
|
|
6
|
+
import shutil
|
|
7
|
+
import json
|
|
8
|
+
import pandas as pd
|
|
9
|
+
|
|
10
|
+
from vre import VRE
|
|
11
|
+
from vre.representations import build_representations_from_cfg
|
|
12
|
+
from vre.utils import get_project_root, FFmpegVideo
|
|
13
|
+
|
|
14
|
+
def main():
|
|
15
|
+
"""main fn"""
|
|
16
|
+
video = FFmpegVideo(get_project_root() / "resources/test_video.mp4")
|
|
17
|
+
representations = build_representations_from_cfg(OmegaConf.load(Path(__file__).parent / "cfg.yaml"))
|
|
18
|
+
vre = VRE(video, representations)
|
|
19
|
+
frames = list(range(1000, 1000 + (5 if len(sys.argv) == 1 else int(sys.argv[1]))))
|
|
20
|
+
batch_sizes = [1, 3, 5]
|
|
21
|
+
out_dirs = [Path(__file__).parent / f"experiment_{batch_size}" for batch_size in batch_sizes]
|
|
22
|
+
|
|
23
|
+
for batch_size, out_dir in zip(batch_sizes, out_dirs):
|
|
24
|
+
shutil.rmtree(out_dir, ignore_errors=True)
|
|
25
|
+
vre.set_compute_params(batch_size=batch_size)
|
|
26
|
+
vre.run(out_dir, frames=frames, n_threads_data_storer=2, exception_mode="skip_representation")
|
|
27
|
+
|
|
28
|
+
jsons = [json.load(open(next((out_dir/".logs").glob("*.json")), "r")) for out_dir in out_dirs]
|
|
29
|
+
dfs = [pd.DataFrame(_json["run_stats"], index=frames).replace(1 <<31, float("nan")) for _json in jsons]
|
|
30
|
+
avgs = pd.concat([df.mean() for df in dfs], axis=1)
|
|
31
|
+
avgs.columns = [f"{bs=}" for bs in batch_sizes]
|
|
32
|
+
for bs in batch_sizes[1:]:
|
|
33
|
+
avgs[f"speedup-{bs}/{batch_sizes[0]}"] = avgs["bs=1"] / avgs[f"{bs=}"]
|
|
34
|
+
print(avgs)
|
|
35
|
+
avgs.to_csv("avgs.csv")
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
main()
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""semantic_mapper.py -- primivites for new tasks based on existing CV/dronescapes tasks"""
|
|
3
|
+
from overrides import overrides
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from vre.utils import semantic_mapper, colorize_semantic_segmentation
|
|
7
|
+
from vre.representations import TaskMapper, NpIORepresentation, Representation
|
|
8
|
+
from vre.representations.cv_representations import DepthRepresentation, NormalsRepresentation, SemanticRepresentation
|
|
9
|
+
|
|
10
|
+
coco_classes = ["person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light",
|
|
11
|
+
"fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow",
|
|
12
|
+
"elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee",
|
|
13
|
+
"skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
|
|
14
|
+
"tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple",
|
|
15
|
+
"sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch",
|
|
16
|
+
"potted plant", "bed", "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard",
|
|
17
|
+
"cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase",
|
|
18
|
+
"scissors", "teddy bear", "hair drier", "toothbrush", "banner", "blanket", "bridge", "cardboard",
|
|
19
|
+
"counter", "curtain", "door-stuff", "floor-wood", "flower", "fruit", "gravel", "house", "light",
|
|
20
|
+
"mirror-stuff", "net", "pillow", "platform", "playingfield", "railroad", "river", "road", "roof",
|
|
21
|
+
"sand", "sea", "shelf", "snow", "stairs", "tent", "towel", "wall-brick", "wall-stone", "wall-tile",
|
|
22
|
+
"wall-wood", "water-other", "window-blind", "window-other", "tree-merged", "fence-merged",
|
|
23
|
+
"ceiling-merged", "sky-other-merged", "cabinet-merged", "table-merged", "floor-other-merged",
|
|
24
|
+
"pavement-merged", "mountain-merged", "grass-merged", "dirt-merged", "paper-merged",
|
|
25
|
+
"food-other-merged", "building-other-merged", "rock-merged", "wall-other-merged", "rug-merged"]
|
|
26
|
+
coco_color_map = [[220, 20, 60], [119, 11, 32], [0, 0, 142], [0, 0, 230], [106, 0, 228], [0, 60, 100], [0, 80, 100],
|
|
27
|
+
[0, 0, 70], [0, 0, 192], [250, 170, 30], [100, 170, 30], [220, 220, 0], [175, 116, 175], [250, 0, 30],
|
|
28
|
+
[165, 42, 42], [255, 77, 255], [0, 226, 252], [182, 182, 255], [0, 82, 0], [120, 166, 157],
|
|
29
|
+
[110, 76, 0], [174, 57, 255], [199, 100, 0], [72, 0, 118], [255, 179, 240], [0, 125, 92],
|
|
30
|
+
[209, 0, 151], [188, 208, 182], [0, 220, 176], [255, 99, 164], [92, 0, 73], [133, 129, 255],
|
|
31
|
+
[78, 180, 255], [0, 228, 0], [174, 255, 243], [45, 89, 255], [134, 134, 103], [145, 148, 174],
|
|
32
|
+
[255, 208, 186], [197, 226, 255], [171, 134, 1], [109, 63, 54], [207, 138, 255], [151, 0, 95],
|
|
33
|
+
[9, 80, 61], [84, 105, 51], [74, 65, 105], [166, 196, 102], [208, 195, 210], [255, 109, 65],
|
|
34
|
+
[0, 143, 149], [179, 0, 194], [209, 99, 106], [5, 121, 0], [227, 255, 205], [147, 186, 208],
|
|
35
|
+
[153, 69, 1], [3, 95, 161], [163, 255, 0], [119, 0, 170], [0, 182, 199], [0, 165, 120],
|
|
36
|
+
[183, 130, 88], [95, 32, 0], [130, 114, 135], [110, 129, 133], [166, 74, 118], [219, 142, 185],
|
|
37
|
+
[79, 210, 114], [178, 90, 62], [65, 70, 15], [127, 167, 115], [59, 105, 106], [142, 108, 45],
|
|
38
|
+
[196, 172, 0], [95, 54, 80], [128, 76, 255], [201, 57, 1], [246, 0, 122], [191, 162, 208],
|
|
39
|
+
[255, 255, 128], [147, 211, 203], [150, 100, 100], [168, 171, 172], [146, 112, 198],
|
|
40
|
+
[210, 170, 100], [92, 136, 89], [218, 88, 184], [241, 129, 0], [217, 17, 255], [124, 74, 181],
|
|
41
|
+
[70, 70, 70], [255, 228, 255], [154, 208, 0], [193, 0, 92], [76, 91, 113], [255, 180, 195],
|
|
42
|
+
[106, 154, 176], [230, 150, 140], [60, 143, 255], [128, 64, 128], [92, 82, 55], [254, 212, 124],
|
|
43
|
+
[73, 77, 174], [255, 160, 98], [255, 255, 255], [104, 84, 109], [169, 164, 131], [225, 199, 255],
|
|
44
|
+
[137, 54, 74], [135, 158, 223], [7, 246, 231], [107, 255, 200], [58, 41, 149], [183, 121, 142],
|
|
45
|
+
[255, 73, 97], [107, 142, 35], [190, 153, 153], [146, 139, 141], [70, 130, 180], [134, 199, 156],
|
|
46
|
+
[209, 226, 140], [96, 36, 108], [96, 96, 96], [64, 170, 64], [152, 251, 152], [208, 229, 228],
|
|
47
|
+
[206, 186, 171], [152, 161, 64], [116, 112, 0], [0, 114, 143], [102, 102, 156], [250, 141, 255]]
|
|
48
|
+
mapillary_classes = ["Bird", "Ground Animal", "Curb", "Fence", "Guard Rail", "Barrier", "Wall", "Bike Lane",
|
|
49
|
+
"Crosswalk - Plain", "Curb Cut", "Parking", "Pedestrian Area", "Rail Track", "Road",
|
|
50
|
+
"Service Lane", "Sidewalk", "Bridge", "Building", "Tunnel", "Person", "Bicyclist",
|
|
51
|
+
"Motorcyclist", "Other Rider", "Lane Marking - Crosswalk", "Lane Marking - General",
|
|
52
|
+
"Mountain", "Sand", "Sky", "Snow", "Terrain", "Vegetation", "Water", "Banner", "Bench",
|
|
53
|
+
"Bike Rack", "Billboard", "Catch Basin", "CCTV Camera", "Fire Hydrant", "Junction Box",
|
|
54
|
+
"Mailbox", "Manhole", "Phone Booth", "Pothole", "Street Light", "Pole", "Traffic Sign Frame",
|
|
55
|
+
"Utility Pole", "Traffic Light", "Traffic Sign (Back)", "Traffic Sign (Front)", "Trash Can",
|
|
56
|
+
"Bicycle", "Boat", "Bus", "Car", "Caravan", "Motorcycle", "On Rails", "Other Vehicle", "Trailer",
|
|
57
|
+
"Truck", "Wheeled Slow", "Car Mount", "Ego Vehicle"]
|
|
58
|
+
mapillary_color_map = [[165, 42, 42], [0, 192, 0], [196, 196, 196], [190, 153, 153], [180, 165, 180], [90, 120, 150],
|
|
59
|
+
[102, 102, 156], [128, 64, 255], [140, 140, 200], [170, 170, 170], [250, 170, 160], [96, 96, 96],
|
|
60
|
+
[230, 150, 140], [128, 64, 128], [110, 110, 110], [244, 35, 232], [150, 100, 100], [70, 70, 70],
|
|
61
|
+
[150, 120, 90], [220, 20, 60], [255, 0, 0], [255, 0, 100], [255, 0, 200], [200, 128, 128],
|
|
62
|
+
[255, 255, 255], [64, 170, 64], [230, 160, 50], [70, 130, 180], [190, 255, 255], [152, 251, 152],
|
|
63
|
+
[107, 142, 35], [0, 170, 30], [255, 255, 128], [250, 0, 30], [100, 140, 180], [220, 220, 220],
|
|
64
|
+
[220, 128, 128], [222, 40, 40], [100, 170, 30], [40, 40, 40], [33, 33, 33], [100, 128, 160],
|
|
65
|
+
[142, 0, 0], [70, 100, 150], [210, 170, 100], [153, 153, 153], [128, 128, 128], [0, 0, 80],
|
|
66
|
+
[250, 170, 30], [192, 192, 192], [220, 220, 0], [140, 140, 20], [119, 11, 32], [150, 0, 255],
|
|
67
|
+
[0, 60, 100], [0, 0, 142], [0, 0, 90], [0, 0, 230], [0, 80, 100], [128, 64, 64], [0, 0, 110],
|
|
68
|
+
[0, 0, 70], [0, 0, 192], [32, 32, 32], [120, 10, 10]]
|
|
69
|
+
|
|
70
|
+
m2f_coco = SemanticRepresentation("semantic_mask2former_coco_47429163_0", classes=coco_classes,
|
|
71
|
+
color_map=coco_color_map)
|
|
72
|
+
m2f_mapillary = SemanticRepresentation("semantic_mask2former_mapillary_49189528_0", classes=mapillary_classes,
|
|
73
|
+
color_map=mapillary_color_map)
|
|
74
|
+
marigold = DepthRepresentation("depth_marigold", min_depth=0, max_depth=1)
|
|
75
|
+
normals_svd_marigold = NormalsRepresentation("normals_svd(depth_marigold)")
|
|
76
|
+
|
|
77
|
+
class SemanticMask2FormerMapillaryConvertedPaper(TaskMapper, NpIORepresentation):
|
|
78
|
+
def __init__(self, name: str, dependencies: list[Representation]):
|
|
79
|
+
TaskMapper.__init__(self, name=name, n_channels=8, dependencies=dependencies)
|
|
80
|
+
NpIORepresentation.__init__(self)
|
|
81
|
+
self.mapping = {
|
|
82
|
+
"land": ["Terrain", "Sand", "Snow"],
|
|
83
|
+
"forest": ["Vegetation"],
|
|
84
|
+
"residential": ["Building", "Utility Pole", "Pole", "Fence", "Wall", "Manhole", "Street Light", "Curb",
|
|
85
|
+
"Guard Rail", "Caravan", "Junction Box", "Traffic Sign (Front)", "Billboard", "Banner",
|
|
86
|
+
"Mailbox", "Traffic Sign (Back)", "Bench", "Fire Hydrant", "Trash Can", "CCTV Camera",
|
|
87
|
+
"Traffic Light", "Barrier", "Rail Track", "Phone Booth", "Curb Cut", "Traffic Sign Frame",
|
|
88
|
+
"Bike Rack"],
|
|
89
|
+
"road": ["Road", "Lane Marking - General", "Sidewalk", "Bridge", "Other Vehicle", "Motorcyclist", "Pothole",
|
|
90
|
+
"Catch Basin", "Car Mount", "Tunnel", "Parking", "Service Lane", "Lane Marking - Crosswalk",
|
|
91
|
+
"Pedestrian Area", "On Rails", "Bike Lane", "Crosswalk - Plain"],
|
|
92
|
+
"little-objects": ["Car", "Person", "Truck", "Boat", "Wheeled Slow", "Trailer", "Ground Animal", "Bicycle",
|
|
93
|
+
"Motorcycle", "Bird", "Bus", "Ego Vehicle", "Bicyclist", "Other Rider"],
|
|
94
|
+
"water": ["Water"],
|
|
95
|
+
"sky": ["Sky"],
|
|
96
|
+
"hill": ["Mountain"]
|
|
97
|
+
}
|
|
98
|
+
self.color_map = [[0, 255, 0], [0, 127, 0], [255, 255, 0], [255, 255, 255],
|
|
99
|
+
[255, 0, 0], [0, 0, 255], [0, 255, 255], [127, 127, 63]]
|
|
100
|
+
self.original_classes = mapillary_classes
|
|
101
|
+
self.classes = list(self.mapping.keys())
|
|
102
|
+
self.n_classes = len(self.classes)
|
|
103
|
+
self.output_dtype = "uint8"
|
|
104
|
+
|
|
105
|
+
@overrides
|
|
106
|
+
def make_images(self) -> np.ndarray:
|
|
107
|
+
res = [colorize_semantic_segmentation(item.argmax(-1).astype(int), self.classes, self.color_map,
|
|
108
|
+
original_rgb=None, font_size_scale=2) for item in self.data.output]
|
|
109
|
+
return np.array(res)
|
|
110
|
+
|
|
111
|
+
@overrides
|
|
112
|
+
def merge_fn(self, dep_data: list[np.ndarray]) -> np.ndarray:
|
|
113
|
+
m2f_mapillary = dep_data[0].argmax(-1)
|
|
114
|
+
m2f_mapillary_converted = semantic_mapper(m2f_mapillary, self.mapping, self.original_classes)
|
|
115
|
+
return self.disk_to_memory_fmt(m2f_mapillary_converted)
|
|
116
|
+
|
|
117
|
+
@overrides
|
|
118
|
+
def memory_to_disk_fmt(self, memory_data: np.ndarray) -> np.ndarray:
|
|
119
|
+
return memory_data.argmax(-1).astype(np.uint8)
|
|
120
|
+
|
|
121
|
+
@overrides
|
|
122
|
+
def disk_to_memory_fmt(self, disk_data: np.ndarray) -> np.ndarray:
|
|
123
|
+
return np.eye(self.n_classes)[disk_data.astype(int)]
|
|
124
|
+
|
|
125
|
+
class SemanticMask2FormerCOCOConverted(TaskMapper, NpIORepresentation):
|
|
126
|
+
def __init__(self, name: str, dependencies: list[Representation]):
|
|
127
|
+
TaskMapper.__init__(self, name=name, n_channels=8, dependencies=dependencies)
|
|
128
|
+
NpIORepresentation.__init__(self)
|
|
129
|
+
self.mapping = {
|
|
130
|
+
"land": ["grass-merged", "dirt-merged", "sand", "gravel", "flower", "playingfield", "snow", "platform"],
|
|
131
|
+
"forest": ["tree-merged"],
|
|
132
|
+
"residential": ["building-other-merged", "house", "roof", "fence-merged", "wall-other-merged", "wall-brick",
|
|
133
|
+
"rock-merged", "tent", "bridge", "bench", "window-other", "fire hydrant", "traffic light",
|
|
134
|
+
"umbrella", "wall-stone", "clock", "chair", "sports ball", "floor-other-merged",
|
|
135
|
+
"floor-wood", "stop sign", "door-stuff", "banner", "light", "net", "surfboard", "frisbee",
|
|
136
|
+
"rug-merged", "potted plant", "parking meter"],
|
|
137
|
+
"road": ["road", "railroad", "pavement-merged", "stairs"],
|
|
138
|
+
"little-objects": ["truck", "car", "boat", "horse", "person", "train", "elephant", "bus", "bird", "sheep",
|
|
139
|
+
"cow", "motorcycle", "dog", "bicycle", "airplane", "kite"],
|
|
140
|
+
"water": ["river", "water-other", "sea"],
|
|
141
|
+
"sky": ["sky-other-merged"],
|
|
142
|
+
"hill": ["mountain-merged"]
|
|
143
|
+
}
|
|
144
|
+
self.color_map = [[0, 255, 0], [0, 127, 0], [255, 255, 0], [255, 255, 255],
|
|
145
|
+
[255, 0, 0], [0, 0, 255], [0, 255, 255], [127, 127, 63]]
|
|
146
|
+
self.original_classes = coco_classes
|
|
147
|
+
self.classes = list(self.mapping.keys())
|
|
148
|
+
self.n_classes = len(self.classes)
|
|
149
|
+
self.output_dtype = "uint8"
|
|
150
|
+
|
|
151
|
+
@overrides
|
|
152
|
+
def make_images(self) -> np.ndarray:
|
|
153
|
+
res = [colorize_semantic_segmentation(item.argmax(-1).astype(int), self.classes, self.color_map,
|
|
154
|
+
original_rgb=None, font_size_scale=2) for item in self.data.output]
|
|
155
|
+
return np.array(res)
|
|
156
|
+
|
|
157
|
+
@overrides
|
|
158
|
+
def merge_fn(self, dep_data: list[np.ndarray]) -> np.ndarray:
|
|
159
|
+
m2f_mapillary = dep_data[0].argmax(-1)
|
|
160
|
+
m2f_mapillary_converted = semantic_mapper(m2f_mapillary, self.mapping, self.original_classes)
|
|
161
|
+
res = self.disk_to_memory_fmt(m2f_mapillary_converted)
|
|
162
|
+
return res
|
|
163
|
+
|
|
164
|
+
@overrides
|
|
165
|
+
def memory_to_disk_fmt(self, memory_data: np.ndarray) -> np.ndarray:
|
|
166
|
+
return memory_data.argmax(-1).astype(np.uint8)
|
|
167
|
+
|
|
168
|
+
@overrides
|
|
169
|
+
def disk_to_memory_fmt(self, disk_data: np.ndarray) -> np.ndarray:
|
|
170
|
+
return np.eye(self.n_classes)[disk_data.astype(int)]
|
|
171
|
+
|
|
172
|
+
class BinaryMapper(TaskMapper, NpIORepresentation):
|
|
173
|
+
"""
|
|
174
|
+
Note for future self: this is never generic enough to be in VRE -- we'll keep it in this separate code only
|
|
175
|
+
TaskMapper is the only high level interface that makes sense, so we should focus on keeping that generic and easy.
|
|
176
|
+
"""
|
|
177
|
+
def __init__(self, name: str, dependencies: list[Representation], mapping: list[dict[str, list]],
|
|
178
|
+
mode: str = "all_agree"):
|
|
179
|
+
TaskMapper.__init__(self, name=name, dependencies=dependencies, n_channels=2)
|
|
180
|
+
NpIORepresentation.__init__(self)
|
|
181
|
+
assert mode in ("all_agree", "at_least_one"), mode
|
|
182
|
+
assert len(mapping[0]) == 2, mapping
|
|
183
|
+
assert len(mapping) == len(dependencies), (len(mapping), len(dependencies))
|
|
184
|
+
assert all(mapping[0].keys() == m.keys() for m in mapping), [m.keys() for m in mapping]
|
|
185
|
+
self.original_classes = [dep.classes for dep in dependencies]
|
|
186
|
+
self.mapping = mapping
|
|
187
|
+
self.classes = list(mapping[0].keys())
|
|
188
|
+
self.n_classes = len(self.classes)
|
|
189
|
+
self.mode = mode
|
|
190
|
+
self.color_map = [[255, 255, 255], [0, 0, 0]]
|
|
191
|
+
self.output_dtype = "bool"
|
|
192
|
+
|
|
193
|
+
@overrides
|
|
194
|
+
def make_images(self) -> np.ndarray:
|
|
195
|
+
res = [colorize_semantic_segmentation(item.argmax(-1).astype(int), self.classes, color_map=self.color_map,
|
|
196
|
+
original_rgb=None, font_size_scale=2) for item in self.data.output]
|
|
197
|
+
return np.array(res)
|
|
198
|
+
|
|
199
|
+
@overrides
|
|
200
|
+
def disk_to_memory_fmt(self, disk_data: np.ndarray) -> np.ndarray:
|
|
201
|
+
return np.eye(2)[disk_data.astype(int)].astype(np.float32)
|
|
202
|
+
|
|
203
|
+
@overrides
|
|
204
|
+
def memory_to_disk_fmt(self, memory_data: np.ndarray) -> np.ndarray:
|
|
205
|
+
return memory_data.argmax(-1).astype(bool)
|
|
206
|
+
|
|
207
|
+
@overrides
|
|
208
|
+
def merge_fn(self, dep_data: list[np.ndarray]) -> np.ndarray:
|
|
209
|
+
dep_data_converted = [semantic_mapper(x.argmax(-1), mapping, oc)
|
|
210
|
+
for x, mapping, oc in zip(dep_data, self.mapping, self.original_classes)]
|
|
211
|
+
res_argmax = sum(dep_data_converted) > (0 if self.mode == "all_agree" else 1)
|
|
212
|
+
return np.eye(2)[res_argmax.astype(int)].astype(np.float32)
|
|
213
|
+
|
|
214
|
+
class BuildingsFromM2FDepth(TaskMapper, NpIORepresentation):
|
|
215
|
+
def __init__(self, name: str, original_classes: tuple[list[str], list[str]]):
|
|
216
|
+
buildings_mapping = [
|
|
217
|
+
{
|
|
218
|
+
"buildings": (cls := ["Building", "Utility Pole", "Pole", "Fence", "Wall"]),
|
|
219
|
+
"others": [x for x in mapillary_classes if x not in cls],
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"buildings": (cls := ["building-other-merged", "house", "roof"]),
|
|
223
|
+
"others": [x for x in coco_classes if x not in cls]
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
|
|
227
|
+
dependencies = [m2f_mapillary, m2f_coco, marigold]
|
|
228
|
+
TaskMapper.__init__(self, name=name, dependencies=dependencies, n_channels=2)
|
|
229
|
+
NpIORepresentation.__init__(self)
|
|
230
|
+
self.color_map = [[255, 255, 255], [0, 0, 0]]
|
|
231
|
+
self.original_classes = original_classes
|
|
232
|
+
self.mapping = buildings_mapping
|
|
233
|
+
self.classes = list(buildings_mapping[0].keys())
|
|
234
|
+
self.n_classes = len(self.classes)
|
|
235
|
+
|
|
236
|
+
@overrides
|
|
237
|
+
def make_images(self) -> np.ndarray:
|
|
238
|
+
res = [colorize_semantic_segmentation(item.argmax(-1).astype(int), self.classes, self.color_map,
|
|
239
|
+
original_rgb=None, font_size_scale=2) for item in self.data.output]
|
|
240
|
+
return np.array(res)
|
|
241
|
+
|
|
242
|
+
def merge_fn(self, dep_data: list[np.ndarray]) -> np.ndarray:
|
|
243
|
+
m2f_mapillary, m2f_coco = dep_data[0].argmax(-1), dep_data[1].argmax(-1)
|
|
244
|
+
depth = dep_data[2].squeeze()
|
|
245
|
+
m2f_mapillary_converted = semantic_mapper(m2f_mapillary, self.mapping[0], self.original_classes[0])
|
|
246
|
+
m2f_coco_converted = semantic_mapper(m2f_coco, self.mapping[1], self.original_classes[1])
|
|
247
|
+
thr = 0.3 # np.percentile(depth.numpy(), 0.8)
|
|
248
|
+
combined = (m2f_mapillary_converted + m2f_coco_converted + (depth > thr)) != 0
|
|
249
|
+
return np.eye(2)[combined.astype(int)]
|
|
250
|
+
|
|
251
|
+
class SafeLandingAreas(TaskMapper, NpIORepresentation):
|
|
252
|
+
def __init__(self, name: str, original_classes: tuple[list[str], list[str]], include_semantics: bool = False,
|
|
253
|
+
sky_water: BinaryMapper | None = None):
|
|
254
|
+
self.include_semantics = include_semantics
|
|
255
|
+
dependencies = [m2f_mapillary, m2f_coco, marigold, normals_svd_marigold]
|
|
256
|
+
TaskMapper.__init__(self, name, dependencies=dependencies, n_channels=2)
|
|
257
|
+
NpIORepresentation.__init__(self)
|
|
258
|
+
self.color_map = [[0, 255, 0], [255, 0, 0]]
|
|
259
|
+
self.original_classes = original_classes
|
|
260
|
+
self.classes = ["safe-landing", "unsafe-landing"]
|
|
261
|
+
self.n_classes = len(self.classes)
|
|
262
|
+
self.sky_water = sky_water
|
|
263
|
+
|
|
264
|
+
@overrides
|
|
265
|
+
def make_images(self) -> np.ndarray:
|
|
266
|
+
res = [colorize_semantic_segmentation(item.argmax(-1).astype(int), self.classes, color_map=self.color_map,
|
|
267
|
+
original_rgb=None, font_size_scale=2) for item in self.data.output]
|
|
268
|
+
return np.array(res)
|
|
269
|
+
|
|
270
|
+
@overrides
|
|
271
|
+
def merge_fn(self, dep_data: list[np.ndarray]) -> np.ndarray:
|
|
272
|
+
normals, depth = dep_data[3], dep_data[2].squeeze()
|
|
273
|
+
v1, v2, v3 = normals.transpose(2, 0, 1)
|
|
274
|
+
where_safe = (v2 > 0.8) * ((v1 + v3) < 1.2)
|
|
275
|
+
if self.include_semantics:
|
|
276
|
+
sw = self.sky_water.merge_fn(dep_data).argmax(-1)
|
|
277
|
+
where_safe = (where_safe * sw * (depth < 0.9)).astype(bool)
|
|
278
|
+
return np.eye(2)[(~where_safe).astype(int)]
|
|
279
|
+
|
|
280
|
+
def get_new_semantic_mapped_tasks(tasks_subset: list[str] | None = None) -> dict[str, TaskMapper]:
|
|
281
|
+
"""The exported function for VRE!"""
|
|
282
|
+
buildings_mapping = [
|
|
283
|
+
{
|
|
284
|
+
"buildings": (cls := ["Building", "Utility Pole", "Pole", "Fence", "Wall"]),
|
|
285
|
+
"others": [x for x in mapillary_classes if x not in cls],
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"buildings": (cls := ["building-other-merged", "house", "roof"]),
|
|
289
|
+
"others": [x for x in coco_classes if x not in cls]
|
|
290
|
+
}
|
|
291
|
+
]
|
|
292
|
+
|
|
293
|
+
living_mapping = [
|
|
294
|
+
{
|
|
295
|
+
"living": (cls := ["Person", "Bicyclist", "Motorcyclist", "Other Rider", "Bird", "Ground Animal"]),
|
|
296
|
+
"others": [c for c in mapillary_classes if c not in cls],
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
"living": (cls := ["person", "bird", "cat", "dog", "horse", "sheep", "cow",
|
|
300
|
+
"elephant", "bear", "zebra", "giraffe"]),
|
|
301
|
+
"others": [c for c in coco_classes if c not in cls],
|
|
302
|
+
}
|
|
303
|
+
]
|
|
304
|
+
|
|
305
|
+
sky_and_water_mapping = [
|
|
306
|
+
{
|
|
307
|
+
"sky-and-water": (cls := ["Sky", "Water"]),
|
|
308
|
+
"others": [c for c in mapillary_classes if c not in cls],
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"sky-and-water": (cls := ["sky-other-merged", "water-other"]),
|
|
312
|
+
"others": [c for c in coco_classes if c not in cls],
|
|
313
|
+
},
|
|
314
|
+
]
|
|
315
|
+
|
|
316
|
+
transportation_mapping = [
|
|
317
|
+
{
|
|
318
|
+
"transportation": (cls := ["Bike Lane", "Crosswalk - Plain", "Curb Cut", "Parking", "Rail Track",
|
|
319
|
+
"Road", "Service Lane", "Sidewalk", "Bridge", "Tunnel", "Bicyclist",
|
|
320
|
+
"Motorcyclist",
|
|
321
|
+
"Other Rider", "Lane Marking - Crosswalk", "Lane Marking - General",
|
|
322
|
+
"Traffic Light",
|
|
323
|
+
"Traffic Sign (Back)", "Traffic Sign (Front)", "Bicycle", "Boat", "Bus", "Car",
|
|
324
|
+
"Caravan", "Motorcycle", "On Rails", "Other Vehicle", "Trailer", "Truck",
|
|
325
|
+
"Wheeled Slow", "Car Mount", "Ego Vehicle"]),
|
|
326
|
+
"others": [c for c in mapillary_classes if c not in cls]
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"transportation": (cls := ["bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat"]),
|
|
330
|
+
"others": [c for c in coco_classes if c not in cls]
|
|
331
|
+
}
|
|
332
|
+
]
|
|
333
|
+
|
|
334
|
+
containing_mapping = [
|
|
335
|
+
{
|
|
336
|
+
"containing": (cls := [
|
|
337
|
+
"Terrain", "Sand", "Mountain", "Road", "Sidewalk", "Pedestrian Area", "Rail Track", "Parking",
|
|
338
|
+
"Service Lane", "Bridge", "Water", "Vegetation", "Curb", "Fence", "Wall", "Guard Rail",
|
|
339
|
+
"Barrier", "Curb Cut", "Snow"
|
|
340
|
+
]),
|
|
341
|
+
"contained": [c for c in mapillary_classes if c not in cls], # Buildings and constructions will be here
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
"containing": (cls := [
|
|
345
|
+
"floor-wood", "floor-other-merged", "pavement-merged", "mountain-merged", "sand", "road",
|
|
346
|
+
"sea", "river", "railroad", "platform", "grass-merged", "snow", "stairs", "tent"
|
|
347
|
+
]),
|
|
348
|
+
"contained": [c for c in coco_classes if c not in cls], # Buildings and constructions will be here
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
|
|
352
|
+
vegetation_mapping = [
|
|
353
|
+
{
|
|
354
|
+
"vegetation": (cls := ["Mountain", "Sand", "Sky", "Snow", "Terrain", "Vegetation"]),
|
|
355
|
+
"others": [x for x in mapillary_classes if x not in cls],
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
"vegetation": (cls := ["tree-merged", "grass-merged", "dirt-merged", "flower", "potted plant", "river",
|
|
359
|
+
"sea", "water-other", "mountain-merged", "rock-merged"]),
|
|
360
|
+
"others": [x for x in coco_classes if x not in cls],
|
|
361
|
+
}
|
|
362
|
+
]
|
|
363
|
+
|
|
364
|
+
available_tasks: list[TaskMapper] = [
|
|
365
|
+
SemanticMask2FormerMapillaryConvertedPaper("semantic_mask2former_swin_mapillary_converted", [m2f_mapillary]),
|
|
366
|
+
SemanticMask2FormerCOCOConverted("semantic_mask2former_swin_coco_converted", [m2f_coco]),
|
|
367
|
+
BinaryMapper("buildings", [m2f_mapillary, m2f_coco], buildings_mapping),
|
|
368
|
+
BinaryMapper("living-vs-non-living", [m2f_mapillary, m2f_coco], living_mapping),
|
|
369
|
+
sky_water := BinaryMapper("sky-and-water", [m2f_mapillary, m2f_coco], sky_and_water_mapping,
|
|
370
|
+
mode="at_least_one"),
|
|
371
|
+
BinaryMapper("transportation", [m2f_mapillary, m2f_coco], transportation_mapping, mode="at_least_one"),
|
|
372
|
+
BinaryMapper("containing", [m2f_mapillary, m2f_coco], containing_mapping),
|
|
373
|
+
BinaryMapper("vegetation", [m2f_mapillary, m2f_coco], vegetation_mapping),
|
|
374
|
+
BuildingsFromM2FDepth("buildings(nearby)", [mapillary_classes, coco_classes]),
|
|
375
|
+
SafeLandingAreas("safe-landing-no-sseg", [mapillary_classes, coco_classes]),
|
|
376
|
+
SafeLandingAreas("safe-landing-semantics", [mapillary_classes, coco_classes],
|
|
377
|
+
include_semantics=True, sky_water=sky_water),
|
|
378
|
+
]
|
|
379
|
+
if tasks_subset is None:
|
|
380
|
+
return {t.name: t for t in available_tasks}
|
|
381
|
+
return {t.name: t for t in available_tasks if t.name in tasks_subset}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""FakeRepresentation module for tests"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import numpy as np
|
|
4
|
+
from overrides import overrides
|
|
5
|
+
|
|
6
|
+
from vre.utils import VREVideo
|
|
7
|
+
from vre.representations import Representation, ReprOut, ComputeRepresentationMixin, NpIORepresentation
|
|
8
|
+
|
|
9
|
+
class FakeRepresentation(Representation, ComputeRepresentationMixin, NpIORepresentation):
|
|
10
|
+
"""FakeRepresentation that is used in unit tests and some basic classes, like RGB."""
|
|
11
|
+
def __init__(self, *args, **kwargs):
|
|
12
|
+
Representation.__init__(self, *args, **kwargs)
|
|
13
|
+
ComputeRepresentationMixin.__init__(self)
|
|
14
|
+
NpIORepresentation.__init__(self)
|
|
15
|
+
assert len(self.dependencies) == 0, self.dependencies
|
|
16
|
+
|
|
17
|
+
@overrides
|
|
18
|
+
def compute(self, video: VREVideo, ixs: list[int]):
|
|
19
|
+
assert self.data is None, "data must not be computed before calling this"
|
|
20
|
+
self.data = ReprOut(frames=np.array(video[ixs]), output=np.array(video[ixs]), key=ixs)
|
|
21
|
+
|
|
22
|
+
@overrides
|
|
23
|
+
def make_images(self) -> np.ndarray:
|
|
24
|
+
assert self.data is not None, f"[{self}] data must be first computed using compute()"
|
|
25
|
+
return self.data.output
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from tempfile import TemporaryDirectory
|
|
3
|
+
from vre.readers import MultiTaskDataset
|
|
4
|
+
from vre.representations.cv_representations import RGBRepresentation, DepthRepresentation, SemanticRepresentation
|
|
5
|
+
from vre.representations import NormedRepresentationMixin
|
|
6
|
+
from torch.utils.data import DataLoader
|
|
7
|
+
import numpy as np
|
|
8
|
+
import torch as tr
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
color_map_8classes = [[0, 255, 0], [0, 127, 0], [255, 255, 0], [255, 255, 255],
|
|
12
|
+
[255, 0, 0], [0, 0, 255], [0, 255, 255], [127, 127, 63]]
|
|
13
|
+
fake_dronescapes_task_types = {
|
|
14
|
+
"rgb": RGBRepresentation("rgb"),
|
|
15
|
+
"depth_sfm_manual202204": DepthRepresentation("depth_sfm_manual202204", min_depth=0, max_depth=300),
|
|
16
|
+
"semantic_segprop8": SemanticRepresentation("semantic_segprop8", classes=8, color_map=color_map_8classes),
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def _dataset_path() -> Path:
|
|
20
|
+
(temp_dir := Path(TemporaryDirectory().name)).mkdir(exist_ok=False)
|
|
21
|
+
task_names = ("rgb", "semantic_segprop8", "depth_sfm_manual202204")
|
|
22
|
+
|
|
23
|
+
N, H, W = 33, 16, 25
|
|
24
|
+
n_classes = fake_dronescapes_task_types["semantic_segprop8"].n_classes
|
|
25
|
+
min_depth, max_depth = 0, 300
|
|
26
|
+
data = {
|
|
27
|
+
"rgb": np.random.randint(0, 255, size=(N, H, W, 3)).astype(np.uint8),
|
|
28
|
+
"semantic_segprop8": np.random.randint(0, n_classes, size=(N, H, W)).astype(np.uint16),
|
|
29
|
+
"depth_sfm_manual202204": np.random.random(size=(N, H, W, 1)).astype(np.float32) \
|
|
30
|
+
* (max_depth - min_depth) + min_depth,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for task in task_names:
|
|
34
|
+
Path(temp_dir / task).mkdir(exist_ok=False, parents=False)
|
|
35
|
+
for i, item in enumerate(data[task]):
|
|
36
|
+
np.savez(temp_dir / task / f"{i}.npz", item)
|
|
37
|
+
return temp_dir
|
|
38
|
+
|
|
39
|
+
@pytest.fixture
|
|
40
|
+
def dataset_path() -> Path: return _dataset_path()
|
|
41
|
+
|
|
42
|
+
def test_MultiTaskDataset_ctor_shapes_and_types(dataset_path: Path):
|
|
43
|
+
N, H, W = 33, 16, 25
|
|
44
|
+
dataset = MultiTaskDataset(dataset_path, task_names=list(fake_dronescapes_task_types.keys()),
|
|
45
|
+
task_types=fake_dronescapes_task_types, normalization=None)
|
|
46
|
+
assert len(dataset) == N
|
|
47
|
+
assert dataset.task_names == ["depth_sfm_manual202204", "rgb", "semantic_segprop8"], dataset.task_names # inferred
|
|
48
|
+
expected_shapes = {"rgb": (H, W, 3), "semantic_segprop8": (H, W, 8), "depth_sfm_manual202204": (H, W, 1)}
|
|
49
|
+
assert (A := dataset.data_shape) == (B := expected_shapes), f"\n- {A} vs\n- {B}"
|
|
50
|
+
x, _, __ = dataset[0]
|
|
51
|
+
|
|
52
|
+
assert x["rgb"].min() == 0 and x["rgb"].max() >= 240 and x["rgb"].max() <= 255, x["rgb"]
|
|
53
|
+
assert x["rgb"].dtype == tr.uint8, x["rgb"]
|
|
54
|
+
assert x["rgb"].shape == (H, W, 3)
|
|
55
|
+
assert x["depth_sfm_manual202204"].min() <= 10 and x["depth_sfm_manual202204"].max() >= 290, \
|
|
56
|
+
x["depth_sfm_manual202204"]
|
|
57
|
+
assert x["depth_sfm_manual202204"].dtype == tr.float32, x["depth_sfm_manual202204"]
|
|
58
|
+
assert x["depth_sfm_manual202204"].shape == (H, W, 1)
|
|
59
|
+
assert x["semantic_segprop8"].unique().tolist() == [0, 1], x["semantic_segprop8"]
|
|
60
|
+
assert x["semantic_segprop8"].dtype == tr.float32 # overwrite in dronescapes representation
|
|
61
|
+
assert x["semantic_segprop8"].shape == (H, W, 8)
|
|
62
|
+
|
|
63
|
+
@pytest.mark.parametrize("normalization", ["standardization", "min_max"])
|
|
64
|
+
def test_MultiTaskDataset_normalization(dataset_path: Path, normalization: str):
|
|
65
|
+
dataset = MultiTaskDataset(dataset_path, task_names=list(fake_dronescapes_task_types.keys()),
|
|
66
|
+
task_types=fake_dronescapes_task_types, normalization=normalization)
|
|
67
|
+
x, _, __ = dataset[0]
|
|
68
|
+
for task in dataset.task_names:
|
|
69
|
+
assert x[task].dtype == tr.float32, x[task].dtype
|
|
70
|
+
if normalization == "min_max":
|
|
71
|
+
assert x[task].min() >= 0 and x[task].max() <= 1, x[task]
|
|
72
|
+
else:
|
|
73
|
+
if not isinstance(dataset.name_to_task[task], NormedRepresentationMixin):
|
|
74
|
+
continue
|
|
75
|
+
MAX_MEAN_DIFF, MAX_STD_DIFF, MIN_STD, MAX_STD = 0.2, 0.2, -5, 5 # TODO: why so big??
|
|
76
|
+
assert x[task].min() >= MIN_STD and x[task].max() <= MAX_STD, x[task]
|
|
77
|
+
assert x[task].mean().abs() < MAX_MEAN_DIFF and (x[task].std() - 1).abs() < MAX_STD_DIFF, \
|
|
78
|
+
(task, x[task].mean(), x[task].std())
|
|
79
|
+
|
|
80
|
+
def test_MultiTaskDataset_getitem(dataset_path):
|
|
81
|
+
reader = MultiTaskDataset(dataset_path, task_names=list(fake_dronescapes_task_types.keys()),
|
|
82
|
+
task_types=fake_dronescapes_task_types, normalization=None)
|
|
83
|
+
|
|
84
|
+
rand_ix = np.random.randint(len(reader))
|
|
85
|
+
data, _, repr_names = reader[rand_ix] # get a random single data point
|
|
86
|
+
assert all(len(x.shape) == 3 for x in data.values()), data
|
|
87
|
+
assert set(repr_names) == set(reader.task_names)
|
|
88
|
+
|
|
89
|
+
data, _, repr_names = reader[rand_ix: min(len(reader), rand_ix + 5)] # get a random batch
|
|
90
|
+
assert all(len(x.shape) == 4 for x in data.values()), data
|
|
91
|
+
assert set(repr_names) == set(reader.task_names)
|
|
92
|
+
|
|
93
|
+
loader = DataLoader(reader, collate_fn=reader.collate_fn, batch_size=5, shuffle=True)
|
|
94
|
+
data, _, repr_names = next(iter(loader)) # get a random batch using torch DataLoader
|
|
95
|
+
assert all(len(x.shape) == 4 for x in data.values()), data
|
|
96
|
+
assert set(repr_names) == set(reader.task_names)
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
test_MultiTaskDataset_normalization(_dataset_path(), "min_max")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from types import SimpleNamespace
|
|
2
|
+
from tempfile import NamedTemporaryFile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import random
|
|
5
|
+
import numpy as np
|
|
6
|
+
from vre.representations.semantic_segmentation.mask2former.mask2former import main as m2f_main
|
|
7
|
+
from vre.utils import get_project_root
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
@pytest.mark.parametrize("variant", ["47429163_0", "49189528_1", "49189528_0"])
|
|
11
|
+
def test_i_mask2former(variant):
|
|
12
|
+
args = SimpleNamespace(
|
|
13
|
+
model_id=variant,
|
|
14
|
+
input_image=get_project_root() / "resources/demo1.jpg",
|
|
15
|
+
output_path=Path(NamedTemporaryFile(suffix=".jpg").name),
|
|
16
|
+
)
|
|
17
|
+
semantic_result = m2f_main(args)
|
|
18
|
+
|
|
19
|
+
# Sanity checks
|
|
20
|
+
rtol = 1e-2
|
|
21
|
+
if args.model_id == "47429163_0" and args.input_image.name == "demo1.jpg":
|
|
22
|
+
assert np.allclose(mean := semantic_result.mean(), 129.41, rtol=rtol), (mean, semantic_result.std())
|
|
23
|
+
assert np.allclose(std := semantic_result.std(), 53.33, rtol=rtol), std
|
|
24
|
+
elif args.model_id == "49189528_1" and args.input_image.name == "demo1.jpg":
|
|
25
|
+
assert np.allclose(mean := semantic_result.mean(), 125.23, rtol=rtol), (mean, semantic_result.std())
|
|
26
|
+
assert np.allclose(std := semantic_result.std(), 48.89, rtol=rtol), std
|
|
27
|
+
elif args.model_id == "49189528_0" and args.input_image.name == "demo1.jpg":
|
|
28
|
+
assert np.allclose(mean := semantic_result.mean(), 118.47, rtol=rtol), (mean, semantic_result.std())
|
|
29
|
+
assert np.allclose(std := semantic_result.std(), 52.08, rtol=rtol), std
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from types import SimpleNamespace
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from vre.representations.soft_segmentation.fastsam.fastsam import main as fastsam_main
|
|
4
|
+
from vre.utils import get_project_root
|
|
5
|
+
from tempfile import NamedTemporaryFile
|
|
6
|
+
import random
|
|
7
|
+
|
|
8
|
+
def test_i_mask2former():
|
|
9
|
+
variants = ["fastsam-x", "fastsam-s"]
|
|
10
|
+
args = SimpleNamespace(
|
|
11
|
+
model_id=random.choice(variants),
|
|
12
|
+
input_image=get_project_root() / "resources/demo1.jpg",
|
|
13
|
+
output_path=Path(NamedTemporaryFile(suffix=".jpg").name),
|
|
14
|
+
)
|
|
15
|
+
fastsam_main(args)
|