【发布时间】:2022-12-17 20:44:06
【问题描述】:
我正在为 Streamlit 应用程序编写一些代码,我希望用户在其中上传一个 .jpg 图像文件,它给了我这个错误,“UnidentifiedImageError:无法识别图像文件 <_io.BytesIO object at 0x00000293778F98B0>”
我的代码如下:
import streamlit as st
import pandas as pd
import numpy as np
from PIL import Image
st.title("Image classification Web App")
# loading images
def load_image(image):
image = image.resize((224,224))
im_array = np.array(image)/255 # a normalised 2D array
im_array = im_array.reshape(-1, 224, 224, 3) # to shape as (1, 224, 224, 3)
return im_array
...
if st.button("Try with the Default Image"):
image=load_image(Image.open('C:/Users/.../image21.jpg'))
st.subheader("Human is detected")
st.image(image)
st.image(initialize_model(model_name, image))
st.subheader("Upload an image file")
uploaded_file = st.file_uploader("Upload a JPG image file", type=["jpg", "jpeg"])
if uploaded_file:
image = load_image(Image.open(uploaded_file))
st.image(initialize_model(model_name, image))
但是,我用这条线上传图片没问题,
st.image(Image.open('C:/Users/../image21.jpg'))
谁能告诉我这里出了什么问题?
谢谢。
【问题讨论】:
标签: image image-processing python-imaging-library streamlit