preprocessed image with Image library
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
I_image = Image.open('2.jpg')
size = (224, 224)
I_image = ImageOps.fit(I_image, size, Image.ANTIALIAS)
image_array = np.asarray(I_image)
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
data[0] = normalized_image_array
data[0].shape
(224, 224, 3)
Want to do same processing using keras, what will be the equivalent method
k_data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
image_path = '2.jpg'
k_image = tensorflow.keras.preprocessing.image.load_img(image_path, target_size=(224,224))
input_arr = keras.preprocessing.image.img_to_array(k_image)
input_arr = np.asarray(input_arr)
input_arr = (input_arr.astype(np.float32) / 127.0) - 1
k_data[0] = input_arr
k_data.shape
(1, 224, 224, 3)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…