我恢复了一个预训练的模型用于人脸检测,该模型一次处理一张图像并返回边界框。如果这些图像尺寸不同,我如何让它处理一批图像?
回答:
你可以使用 tf.image.resize_images
方法来实现这一点。根据 文档,tf.image.resize_images
的描述如下:
使用指定的方法将图像调整到指定大小。
如果图像的原始宽高比与指定大小不同,则调整后的图像可能会失真。要避免失真,请查看
tf.image.resize_image_with_pad
。
如何使用它?
import tensorflow as tffrom tensorflow.python.keras.models import Modelx = 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(...)