1

I'm working with a dataset having a size of more than 30Gb, the problem is that the images(RGB) in the dataset aren't of the same dimension. As I'm implementing custom CNN I'll be required to give input_size for the first convolutional layer. Is there any way to add zero-padding generically. I've initially implemented a pre-trained model(ResNet-50) and used the following method

from tensorflow.keras.applications.resnet50 import preprocess_input 
ImageDataGenerator(preprocess_input ,validation_split=0.2)

This made my dataset compatible with the model, is there any similar way where I can add zero-padding on the dataset but for a custom CNN model.

Ali Sehran
  • 41
  • 4

1 Answers1

0

Although zero-padding might not be an ideal solution for handling images of various sizes, you can zero-pad images in python by the following methods.

  1. Numpy method reference
padded_image = np.zeros(result_shape)
padded_image[:image.shape[0],:image.shape[1]] = image
  1. Tensorflow method documentation
padded_image = tf.image.pad_to_bounding_box(image, top_padding, left_padding, target_height, target_width)
krenerd
  • 741
  • 4
  • 22