Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpy Batch Operations in Bboxes and Keypoints #1396

Open
wants to merge 182 commits into
base: main
Choose a base branch
from

Conversation

GdoongMathew
Copy link

@GdoongMathew GdoongMathew commented Feb 10, 2023

Changes

  1. Replace internal bbox & keypoint object with BboxesInternalType & KeypointsInternalType. Bboxes and keypoints will be converted to internal type in each DataProcessor's preprocess and back to original form in its postprocess.
  2. Reimplement most bboxes and keypoints related transformation function in numpy operation.
  3. Convert bboxes and keypoints internal target object from list to np.array as well. (updated on 12/24/2023)

Updated Transforms

  1. Crop Transforms
  2. CoarseDropout
  3. Geometric Transform (except ElasticTransform, OpticalDistortion & GridDistortion)

Benchmark

10 bboxes

Transformation imgaug albumentations(numpy) albumentations(for loop)
HorizontalFlip 0.203 0.317 0.824
VerticalFlip 0.168 0.276 1.298
Flip 0.267 0.273 1.13
Rotate 1.686 1.967 7.866
SafeRotate - 2.965 10.541
RandomRotate90 1.05 0.886 4.009
ShiftScaleRotate - 2.069 6.831
Transpose - 1.064 3.369
Pad 1.1835 1.263 3.601
Perspective 3.2145 2.492 10.504
RandomCropNearBBox - 0.183 0.666
BBoxSafeRandomCrop - 0.372 1.368
CenterCrop - 0.238 0.933
Crop 1.735 0.238 0.768
CropAndPad - 1.004 3.455
RandomCropFromBorders - 0.299 1.235
Affine 1.496 1.629 8.192
PiecewiseAffine 1254.1 369.816 1874.854
Sequence 8.541 7.021 8.599

unit: seconds / image

40 keypoints

Transformation imgaug albumentations(numpy) albumentations(for loops)
HorizontalFlip 0.223 0.346 0.24
VerticalFlip 0.1775 0.319 0.208
Flip 0.261 0.349 0.225
Rotate 1.7625 1.982 1.972
SafeRotate - 3.055 3.741
RandomRotate90 1.017 0.909 0.912
ShiftScaleRotate - 2.037 2.264
Transpose - 1.163 1.078
Pad 1.132 1.295 1.309
Perspective 2.312 2.308 2.618
RandomCropNearBBox - 0.13 0.116
CenterCrop - 0.119 0.11
Crop 1.595 0.143 0.116
CropAndPad - 1.058 1.129
RandomCropFromBorders - 0.304 0.205
Affine 1.495 1.562 2.483
PiecewiseAffine 1146.51 227.35 1151.898
Sequence 9.135 6.993 8.159

unit: seconds / image

  • Sequence: HorizontalFlip -> VerticalFlip -> Rotate -> RandomRotate90 -> Perspective -> Affine -> PadIfNeeded

Hardware

  • CPU: Intel i7-13700H
  • RAM: 16GB

GdoongMathew and others added 30 commits January 5, 2023 18:51
…_from_albumentations with batch of bboxes in numpy operations.
2. added implementation of bboxes_flip, bboxes_vflip, bboxes_hflip and bboxes_transpose in numpy operation.
…, VerticalFlip, HorizontalFlip, Flip's apply_to_bbox to numpy operations.
2. update ShiftScaleRotate apply_to_bboxes method.
2. add bboxes_transpose implementation.
…d normalize_bboxes_np.

2. add test cases for test_bboxes_flip, test_crop_bboxes_by_coords, test_bboxes_center_crop, test_bboxes_crop, test_bboxes_random_crop.
3. Add methods in benchmark_bbox.py.
2. optimize some array operation.
2. store label field data into label_buffer.
2. add imgaug bounding boxes augmentation benchmark.
2. add filter_label method in DataProcessor.
3. change filter_keypoints and filter_bboxes return value to a resulting data and the filtered indices.
2. decorate functional bboxes transformation with ensure_and_convert_bboxes
tests/test_bbox.py Outdated Show resolved Hide resolved
tests/test_bbox.py Outdated Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
albumentations/core/utils.py Outdated Show resolved Hide resolved
albumentations/core/utils.py Outdated Show resolved Hide resolved
albumentations/core/utils.py Outdated Show resolved Hide resolved
albumentations/core/transforms_interface.py Outdated Show resolved Hide resolved
albumentations/core/transforms_interface.py Outdated Show resolved Hide resolved
albumentations/core/keypoints_utils.py Outdated Show resolved Hide resolved
albumentations/core/keypoints_utils.py Outdated Show resolved Hide resolved
…nternal_format.

2. add BoxInternalType and KeypointInternalType as apply_to_bbox and apply_to_keypoint input.
3. raise error if comparing different object in BBoxesInternalType and KeypointsInternalType.
2. reformat parametrize arguments format.
@GdoongMathew
Copy link
Author

I've added a few fixes.

  1. converting bboxes / keypoints to internal type when testing transforming function.
  2. add targets back in the unittests.
  3. some requested changes.

point 1 and 2 were missing from the initial review, sorry for the additional corrections.

albumentations/core/transforms_interface.py Outdated Show resolved Hide resolved
albumentations/core/keypoints_utils.py Show resolved Hide resolved
@GdoongMathew
Copy link
Author

@Dipet Hi, changes have been made as requested.

…onvert_to_original_type` methods.

2. change `convert_to_albumentations` and `convert_from_albumentations` input/output's type hint to `InternalDtype`.
@GdoongMathew
Copy link
Author

Hi @Dipet,
since I haven't got further comments on this change request, I think currently it's best to just add the correct type hint instead of combining combine_bboxes_from_albumentations, convert_to_original_type & combine_bboxes_to_albumentations, convert_to_internal_type.

Feel free to give any further suggestions.

@GdoongMathew
Copy link
Author

Hi @Dipet
I think there was a mistake when merging master into this branch, accidentally renamed convert_bboxes_to_albumentations to a in bbox_utils.py?

@Dipet
Copy link
Collaborator

Dipet commented Mar 7, 2023

@GdoongMathew Please, fix it. I can not properly checkout to your branch and push to this PR from my workstation.

@GdoongMathew
Copy link
Author

@Dipet
Done.

@GdoongMathew
Copy link
Author

GdoongMathew commented Mar 7, 2023

Hi @Dipet
I think the version of scikit-image is the reason why the unittest failed.
Should I fix its version to scikit-image>=0.16.1,<0.20.0 in the setup file?
Or should I open an issue for this?

@GdoongMathew
Copy link
Author

@Dipet
Hi, is there anything that still needs to be changed or that I can help with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants