def preprocess_image(image_file):
resized_image = Image.open(image_file).resize((224, 224))
#plt.imshow(resized_image) #对图像进行处理,并显示其格式
plt.show() #将plt.imshow()处理后的函数显示出来
image_data = np.asarray(resized_image).astype("float32")
# convert HWC to CHW
#image_data = image_data.transpose((2, 0, 1))
# after expand_dims, we have format NCHW
image_data = np.expand_dims(image_data, axis=0)
image_data[:, 0, :, :] = 2.0 / 255.0 * image_data[:, 0, :, :] - 1
image_data[:, 1, :, :] = 2.0 / 255.0 * image_data[:, 1, :, :] - 1
image_data[:, 2, :, :] = 2.0 / 255.0 * image_data[:, 2, :, :] - 1
print("input", image_data.shape)
return image_data
注释掉 plt.imshow(resized_image) 代码运行正常
加上就出现错误:段错误 (核心已转储)