I am using a file_uploader
from streamlit to get images into PIL JpegImageFile
format :
import streamlit as st
inferencer = load_learner(path)
img_bytes = st.file_uploader("Squash It!!", type=['png', 'jpg', 'jpeg'])
if img_bytes is not None:
st.write("Image Uploaded Successfully:")
img = PIL.Image.open(img_bytes)
pred_class, pred_idx, outputs = inferencer.predict(img)
for out in outputs:
st.write(out)
st.write("Decision: ", pred_class)
However, I can’t find a method in the docs that will convert a PIL Image to a fastai Image. It seems without having that fastai wrapper, I can’t do inference. I get the error:
'JpegImageFile' object has no attribute 'apply_tfms'
File "C:\Users\WNeill\PycharmProjects\fastai-homework\Lesson2-v3\inference.py", line 20, in <module>
pred_class, pred_idx, outputs = inferencer.predict(img)