Daniel Kelvich
Daniel Kelvich

Reputation: 25

CNN batch with images of different size

I restored a pre-trained model for face detection which takes a single image at a time and returns bounding boxes. How can I make it take a batch of images if these images have different sizes?

Upvotes: 0

Views: 1003

Answers (1)

Amir
Amir

Reputation: 16587

You can use tf.image.resize_images method to achieve this. According to docs tf.image.resize_images:

Resize images to size using the specified method.

Resized images will be distorted if their original aspect ratio is not the same as size. To avoid distortions see tf.image.resize_image_with_pad.

How to use it?

import tensorflow as tf
from tensorflow.python.keras.models import Model

x = Input(shape=(None, None, 3), name='image_input')
resize_x = tf.image.resize_images(x, [32,32])
vgg_model = load_vgg()(resize_x)
model = Model(inputs=x, outputs=vgg_model.output)
model.compile(...)
model.predict(...)

Upvotes: 1

Related Questions