I’m running through the first lesson, and I downloaded an image of a dog from google, uploaded it with the widget, but now when I run this code:
img = PILImage.create(uploader.data[0])
is_cat,_,probs = learn.predict(img)
print(f"Is this a cat?: {is_cat}.")
print(f"Probability it's a cat: {probs[1].item():.6f}")
I get this error:
UnidentifiedImageError Traceback (most recent call last)
in
----> 1 img = PILImage.create(uploader.data[0])
2 is_cat,_,probs = learn.predict(img)
3 print(f"Is this a cat?: {is_cat}.")
4 print(f"Probability it’s a cat: {probs[1].item():.6f}")
/opt/conda/lib/python3.7/site-packages/fastai/vision/core.py in create(cls, fn, **kwargs)
108 if isinstance(fn,ndarray): return cls(Image.fromarray(fn))
109 if isinstance(fn,bytes): fn = io.BytesIO(fn)
–> 110 return cls(load_image(fn, **merge(cls._open_args, kwargs)))
111
112 def show(self, ctx=None, **kwargs):
/opt/conda/lib/python3.7/site-packages/fastai/vision/core.py in load_image(fn, mode)
83 def load_image(fn, mode=None):
84 "Open and load a PIL.Image
and convert to mode
"
—> 85 im = Image.open(fn)
86 im.load()
87 im = im._new(im.im)
/opt/conda/lib/python3.7/site-packages/PIL/Image.py in open(fp, mode)
2929 warnings.warn(message)
2930 raise UnidentifiedImageError(
-> 2931 “cannot identify image file %r” % (filename if filename else fp)
2932 )
2933
UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f93d9bb5410>
Can anyone help me understand why it’s not recognizing the byte data? I printed out uploader.data[0] and it’s a long bytestring, so it should be able to be processed by PILImage.create, from what I understand.