python - errors with tensorflow reshape and resize layer ...
stackoverflow.com › questions › 64388154Oct 16, 2020 · import numpy as np import tensorflow as tf img_test = np.zeros((120,160)).astype(np.float32) img_test_flat = img_test.reshape(1, -1) reshape_model = tf.keras.Sequential() reshape_model.add(tf.keras.layers.InputLayer(input_shape=(img_test_flat.shape[1:]))) reshape_model.add(tf.keras.layers.Reshape((120, 160,1))) reshape_model.add(tf.keras.layers.Lambda(lambda x: tf.image.resize(x, (28, 28)))) result = reshape_model(img_test_flat) print(result.shape)
Data augmentation | TensorFlow Core
www.tensorflow.org › tutorials › imagesFeb 23, 2022 · You can use the Keras preprocessing layers to resize your images to a consistent shape (with tf.keras.layers.Resizing), and to rescale pixel values (with tf.keras.layers.Rescaling). IMG_SIZE = 180 resize_and_rescale = tf.keras.Sequential([ layers.Resizing(IMG_SIZE, IMG_SIZE), layers.Rescaling(1./255) ]) Note: The rescaling layer above standardizes pixel values to the [0, 1] range. If instead you wanted it to be [-1, 1], you would write tf.keras.layers.Rescaling(1./127.5, offset=-1).