Skip to content

Commit

Permalink
Fix data pipeline (#3418)
Browse files Browse the repository at this point in the history
- Fix #3379
    - Remove numpy -> tensor after transform
    - Add `NumpytoTVTensorMixin`
  • Loading branch information
sungchul2 authored May 2, 2024
1 parent 151a94e commit 2fc7777
Show file tree
Hide file tree
Showing 31 changed files with 237 additions and 131 deletions.
210 changes: 118 additions & 92 deletions src/otx/core/data/transform_libs/torchvision.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/otx/recipe/_base_/data/mmseg_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ config:
- 2.0
antialias: True
- class_path: otx.core.data.transform_libs.torchvision.PhotoMetricDistortion
init_args:
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.RandomHorizontalFlip
init_args:
p: 0.5
Expand Down
4 changes: 3 additions & 1 deletion src/otx/recipe/classification/h_label_cls/deit_tiny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ overrides:
init_args:
scale: 224
backend: cv2
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -73,6 +74,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -88,7 +90,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ overrides:
init_args:
scale: 224
backend: cv2
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -73,6 +74,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -88,7 +90,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip
init_args:
prob: 0.5
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -75,7 +76,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -91,7 +92,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip
init_args:
prob: 0.5
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -80,7 +81,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -96,7 +97,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
5 changes: 3 additions & 2 deletions src/otx/recipe/classification/multi_class_cls/deit_tiny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ overrides:
init_args:
scale: 224
backend: cv2
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -67,7 +68,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -83,7 +84,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
5 changes: 3 additions & 2 deletions src/otx/recipe/classification/multi_class_cls/dino_v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ overrides:
init_args:
scale: 224
backend: cv2
is_numpy_to_tvtensor: true
sampler:
class_path: otx.algo.samplers.balanced_sampler.BalancedSampler
val_subset:
Expand All @@ -68,7 +69,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
test_subset:
batch_size: 64
transforms:
Expand All @@ -83,4 +84,4 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.RandomResizedCrop
init_args:
scale: 224
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -67,6 +68,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -82,7 +84,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: False
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip
init_args:
prob: 0.5
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -69,7 +70,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -85,7 +86,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip
init_args:
prob: 0.5
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -74,7 +75,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -90,7 +91,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
4 changes: 3 additions & 1 deletion src/otx/recipe/classification/multi_label_cls/deit_tiny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ overrides:
init_args:
scale: 224
backend: cv2
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -71,6 +72,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -86,7 +88,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ overrides:
init_args:
scale: 224
backend: cv2
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -71,6 +72,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -86,7 +88,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip
init_args:
prob: 0.5
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -73,7 +74,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -89,7 +90,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip
init_args:
prob: 0.5
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -78,7 +79,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -94,7 +95,7 @@ overrides:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
scale: 224
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
4 changes: 4 additions & 0 deletions src/otx/recipe/detection/atss_mobilenetv2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ overrides:
- 992
- 736
keep_ratio: false
transform_bbox: true
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip
init_args:
prob: 0.5
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -79,6 +81,7 @@ overrides:
- 736
keep_ratio: false
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -98,6 +101,7 @@ overrides:
- 736
keep_ratio: false
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
4 changes: 4 additions & 0 deletions src/otx/recipe/detection/atss_mobilenetv2_tile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ overrides:
- 992
- 736
keep_ratio: false
transform_bbox: true
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip
init_args:
prob: 0.5
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -82,6 +84,7 @@ overrides:
- 736
keep_ratio: false
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand All @@ -101,6 +104,7 @@ overrides:
- 736
keep_ratio: false
transform_bbox: false
is_numpy_to_tvtensor: true
- class_path: torchvision.transforms.v2.ToDtype
init_args:
dtype: ${as_torch_dtype:torch.float32}
Expand Down
Loading

0 comments on commit 2fc7777

Please sign in to comment.