我已经用node.js创建了一个REST API,然后python-shell调用了python脚本,到目前为止一切都很好。我想将base64解码为图像并发送模型。但是,即使已经安装了枕头,也会出现错误。我正在使用Windows 10和python 3.7.4
File "..\ml.py", line 19, in <module> img = image.load_img(file,target_size=(224,224))
File "C:..\AppData\Roaming\Python\Python37\site-packages\keras_preprocessing\image\utils.py", line 111, in load_img
raise ImportError('Could not import PIL.Image.')
ImportError: Could not import PIL.Image. The use of `load_img` requires PIL.
from keras.preprocessing import image
import numpy as np
import matplotlib as plt
from keras.models import load_model
import base64
def decode(str):
imgdata = base64.b64decode(str)
filename = 'some_image.jpg'
with open(filename, 'wb') as f:
f.write(imgdata)
return filename
str = ""
for line in sys.stdin:
str = str + line
file = decode(str)
img = image.load_img(file,target_size=(224,224))
img = np.asarray(img)
img = np.expand_dims(img, axis=0)
saved_model = load_model("model.h5")
output = saved_model.predict(img)