实验步骤 1、载入库 import matplotlib.pyplot as plt import tensorflow as tf import numpy as np 2、读取照片 image_data = tf.keras.preprocessing.image.load_img('d:/data/1.jpg','rb') plt.imshow(image_data) plt.show() img_data = tf.keras.preprocessing.image.img_to_array(image_data) 3、图像缩放 利用双线性插值法 ResizeMethod.BILINEAR,对应method=0 resized = tf.image.resize(img_data,[256,256]) print("Digital type: ",resized.dtype) resized1 = np.asarray(resized,dtype='uint8') plt.imshow(resized1) plt.show() print("Digital type: ",resized1.dtype) 最近邻插值法NEAREST_NEIGHBOR,对应method=1 resized2 = tf.image.resize(img_data,[256,512],method='nearest') resized2 = np.asarray(resized2, dtype='uint8') plt.imshow(resized2) plt.show()