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

Add Augmentations for Robustness Experiments #64

Open
SakshayMahna opened this issue Jun 23, 2022 · 10 comments
Open

Add Augmentations for Robustness Experiments #64

SakshayMahna opened this issue Jun 23, 2022 · 10 comments

Comments

@SakshayMahna
Copy link

The robustness experiments include:

  • Translations of the Camera
  • Rotations of the Camera

Currently, we use the albumentations library to introduce the different augmentations. The appropriate function for this use case would be the Affine function.

https://albumentations.ai/docs/api_reference/augmentations/geometric/transforms/

However, the camera rotation operation is a Homography Operation, which does not seem to be available in the library.

@sergiopaniego
Copy link
Member

I have applied Affine using Albumentations to one of the images in the dataset, so we can discuss if it enough with this function or we need to implement something more complex.

Normal image

normal

Normal image with affine (Rotation and translation)

normal_affine

Cropped image

cropped

Cropped image with affine (rotation and translation)

cropped_affine

What do you think? Could you share image examples of applying the transformation on a model level so we can compare and decide?

The code that I have used is quite simple:

# Examples made with x=-0.1, x=0.1, y=-0.1, y=0.1
augmentation_option = Compose([Affine(translate_percent={'x': -0.1, 'y': 0}, always_apply=True)])

@SakshayMahna
Copy link
Author

That's a nice trick. Here are the original model images:

Translation

Original

translate

Cropped

cropped_translate

Rotation

Original

rotate

Cropped

cropped_rotate

@SakshayMahna
Copy link
Author

SakshayMahna commented Jun 24, 2022

I think the Affine Transform does approximate the translation and rotation, but in some cases, when we crop the image, it would capture some black background as well. Any idea how to avoid that?

Conventional methods seem to use Reflection and other techniques, should we use that?

@sergiopaniego
Copy link
Member

I'm sharing the results for the different types of available border_modes so we can decide if any fits out needs.

mode=cv2.BORDER_REPLICATE

normal (1)
normal_affine (1)
cropped (1)
cropped_affine (1)

@sergiopaniego
Copy link
Member

sergiopaniego commented Jun 24, 2022

mode=cv2.BORDER_REFLECT

normal (2)
normal_affine (2)
cropped (2)
cropped_affine (2)

@sergiopaniego
Copy link
Member

mode=cv2.BORDER_WRAP

normal (3)
cropped_affine (3)
cropped (3)
normal_affine (3)

@sergiopaniego
Copy link
Member

mode=cv2.BORDER_REFLECT_101

normal (4)
normal_affine (4)
cropped (4)
cropped_affine (4)

@sergiopaniego
Copy link
Member

These are the available options.
IMO, mode=cv2.BORDER_REPLICATE or mode=cv2.BORDER_REFLECT are the best two options. What do you think @SakshayMahna ?

The images are not exactly the same as the ones you've shared. I'm suggesting this solution because of its simplicity of integration and implementation but we can still explore the raw opencv option you suggested.

@SakshayMahna
Copy link
Author

Yes, these two seem to be the best options. Let's go with REPLICATE. I'll try training the model with the same. In the meantime, study the opencv option as well.

@SakshayMahna
Copy link
Author

I also did some experiments with the homography operation. Here are the results:

Original Rotation

original

Homography Operation

rotate

Homography with Adjusted Background

rotate_nb

The accuracy of these operations may be much higher. But, the problem with this approach is that they are extremely hardcoded. We have to input specific points (4 for each image) to transform the image. Due to this, we will only have specific rotation values, like -20, -10, +10, +20.

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

No branches or pull requests

2 participants