Thumbnail article
Imagedatagenerator nearest vs reflect

Imagedatagenerator can be used in data augmentation stage. Data augmentation is a process in image data processing. Augmentation is the process of changing or modifying images in such a way that the computer will detect that the changed image is a different image, but humans can still know that the changed image is the same image. Augmentation can increase the accuracy of the trained CNN model because with augmentation the model gets additional data that can be useful for making models that can generalize better. Imagedatagenerator can created a new data base on the original image. There are plenty parameter that can be used in imagedatagenerator. One of parameter called fill_mode. This parameter accept some value like nearest or reflect. You can see the image below to see the differences. Nearest image

Nearest

Reflect image

Reflect

Nearest fill the empty space using the closest pixel. Reflect fill the empty space using mirroring the image. We used this code to generating a new data.

#Nearest
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip=True,
fill_mode='nearest')

# Reflect
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip=True,
fill_mode='reflect')

On this test, nearest and reflect treated in the same way. The real total data is 200 images. We generate 10x of data using imagedatagenerator so the total become 2000 images. 1600 for training and 400 for validation. The result showed that nearest have a higher accuracy. Nearest get accuracy 96.5 and the reflect get accuracy 96. https://github.com/Garudabyte/imagedatagenerator-nearest-vs-reflect. And then We tried to increasing the total images. The real total data is 4000. We generate 10x of data so the total data become 40.000. It showed a different result. The reflect has a higher accuracy. Reflect has 97.19% accuracy while the nearest has 96.74%. It might be have a differences result if it have a different object. It totally depend with your data, if nearest fit and look good for your data you can go for it, so do the reflect.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *