类型错误:“图像”对象不可使用 PIL 进行下标

Büş*_*ygu 1 ngrok tensorflow google-colaboratory streamlit image-classification

我正在尝试在 google colab 上开发一个网络应用程序。我想在这个 Web 应用程序中使用我之前训练过的模型制作一个图像分类器。当我在 Web 应用程序中从浏览器中选择要分类的图像时,出现以下错误:

TypeError: 'Image' object is not subscriptable.
Run Code Online (Sandbox Code Playgroud)

我的代码块:

TypeError: 'Image' object is not subscriptable.
Run Code Online (Sandbox Code Playgroud)

wlo*_*wlo 5

当您应该在图像数组上执行重塑操作时,您正在尝试对原始 Image 对象执行重塑操作。更改这一行:

img_reshape = _image[np.newaxis,...]
Run Code Online (Sandbox Code Playgroud)

到:

img_reshape = img[np.newaxis,...]
Run Code Online (Sandbox Code Playgroud)

你应该表现得很好。