How can I add a resizing layer to
model = Sequential()
using
model.add(...)
To resize an image from sha
The accepted answer uses the Reshape layer, which works like NumPy's reshape, which can be used to reshape a 4x4 matrix into a 2x8 matrix, but that will result in the image loosing locality information:
0 0 0 0
1 1 1 1 -> 0 0 0 0 1 1 1 1
2 2 2 2 2 2 2 2 3 3 3 3
3 3 3 3
Instead, image data should be rescaled / "resized" using, e.g., Tensorflows image_resize. But beware about the correct usage and the bugs! As shown in the related question, this can be used with a lambda layer:
model.add( keras.layers.Lambda(
lambda image: tf.image.resize_images(
image,
(224, 224),
method = tf.image.ResizeMethod.BICUBIC,
align_corners = True, # possibly important
preserve_aspect_ratio = True
)
))
In your case, as you have a 160x320 image, you also have to decide whether to keep the aspect ratio, or not. If you want to use a pre-trained network, then you should use the same kind of resizing that the network was trained for.