load_img
是 Keras 库中的一个函数,用于加载图像文件并将其转换为一个形状为 (height, width, channels) 的 NumPy 数组。这个函数主要用于图像预处理阶段,将图像数据转换为适合神经网络模型输入的形式.
from keras.preprocessing.image import load_img
# 加载图像文件 img = load_img('path/to/your/image.jpg')
# 显示图像 import matplotlib.pyplot as plt plt.imshow(img)
plt.show()
from keras.preprocessing.image import load_img # 加载图像文件 img = load_img('path/to/your/image.jpg') # 显示图像 import matplotlib.pyplot as plt plt.imshow(img) plt.show()
在较新的 Keras 版本中,load_img
已经被移除,取而代之的是 tf.keras.utils.load_img
。所以,你需要将导入语句