79321586

Date: 2025-01-01 12:30:50
Score: 2
Natty:
Report link

After taking a look at the code in ImageDataGenerator, the alternative I could come up is to use image-preprocessing layers and image-augmentation layers. the old ImageDataGenerator:

`train_datagen = ImageDataGenerator(
         rotation_range=40,# rotate the image 40 degrees
         width_shift_range=0.2, # Shift the pic width by a max of 10%
         height_shift_range=0.2, # Shift the pic height by a max of 10%
         rescale=1./255, # Rescale the image by normalzing it.
         shear_range=0.2, # Shear means cutting away part of the image (max 20%)
         zoom_range=0.2, # Zoom in by 10% max
         horizontal_flip=True) # Allow horizontal flipping`

the alternative by image-preprocessing layers and image-augmentation layers:

from keras.models import Sequential
from keras.layers import Rescaling, RandomFlip, RandomRotation, RandomTranslation, RandomZoom
from keras.layers import Flatten, Dense

train_datagen = Sequential()
train_datagen.add(Rescaling(1./255)) # Rescale the image by normalzing it.
train_datagen.add(RandomFlip(mode='horizontal')) # Allow horizontal flipping
train_datagen.add(RandomTranslation(0.2, 0.2)) # Shift the pic width and height by a max of 10%
train_datagen.add(RandomRotation(1./9)) # [-1.* 2*pi/18 radian, 1. * 2*pi/18 radian]
train_datagen.add(RandomZoom(0.2)) # Zoom in by 10% max

However, the missing part is RandomShear which I have no clue how to implement and the example of random_shear from tf.keras.preprocessing.image as seen here seems to be deprecated. Any better suggestion would be appreciated. REF: https://www.atmosera.com/blog/data-augmentation/

Reasons:
  • Blacklisted phrase (1): appreciated
  • RegEx Blacklisted phrase (2): Any better suggestion
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Wisarut Bholsithi