Python ImportError:无法导入PIL.Image。“load_img”的使用要求PIL在VSCode中使用keras
我用node.js创建了一个RESTAPI,然后python shell调用了python脚本,到目前为止一切正常。我想将base64解码为图像并发送模型。但我得到一个错误,即使枕头已经安装。我正在使用Windows10和python 3.7.4Python ImportError:无法导入PIL.Image。“load_img”的使用要求PIL在VSCode中使用keras,python,machine-learning,keras,visual-studio-code,importerror,Python,Machine Learning,Keras,Visual Studio Code,Importerror,我用node.js创建了一个RESTAPI,然后python shell调用了python脚本,到目前为止一切正常。我想将base64解码为图像并发送模型。但我得到一个错误,即使枕头已经安装。我正在使用Windows10和python 3.7.4 文件“.\ml.py”,第19行,img=image.load\u img(文件,目标大小=(224)) 文件“C:..\AppData\Roaming\Python\Python37\site packages\keras\u preprocessi
文件“.\ml.py”,第19行,img=image.load\u img(文件,目标大小=(224))
文件“C:..\AppData\Roaming\Python\Python37\site packages\keras\u preprocessing\image\utils.py”,第111行,在load\u img中
raise ImportError('无法导入PIL.Image')
ImportError:无法导入PIL.Image。使用'load_img'需要PIL。
我没有为vscode创建虚拟环境。我已经创建了虚拟环境,然后激活虚拟环境。现在可以了!您可以查看更多信息&我没有为vscode创建虚拟环境。我已经创建了虚拟环境,然后激活虚拟环境。现在可以了!您可以查看更多信息&
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)