我正在尝试将照片加载到 ML 项目,但出现错误:路径应该是路径类或 io.BytesIO,而不是
我正在尝试将照片加载到 ML 项目,但出现错误:路径应该是路径类或 io.BytesIO,而不是
def load_image_pixels(filename, shape):
# load the image to get its shape
image = load_img(filename)
width, height = image.size
# load the image with the required size
image = load_img(filename, target_size=shape)
# convert to numpy array
image = img_to_array(image)
# scale pixel values to [0, 1]
image = image.astype('float32')
image /= 255.0
# add a dimension so that we have one sample
image = expand_dims(image, 0)
return image, width, height
photo_filename = Image.open(r'C:\ML\Pies.jpg')
# define the expected input shape for the model
input_w, input_h = 167, 221
# load and prepare image
image, image_w, image_h = load_image_pixels(photo_filename, (net_w, net_w))
我看到照片已加载,但函数无法处理它。如何解决这个问题。
在我工作的其他代码中,以这种方式打开的图像可以像将图像转换为数组然后对其进行处理一样进行处理。
image = Image.open(r'C:\ML\Pies.jpg')
image = np.array(image)