glenn-jocher commited on
Commit
ec8979f
·
unverified ·
1 Parent(s): 74276d5

Updated filename attributes for YOLOv5 Hub BytesIO (#2718)

Browse files

Fix 2 for 'Model predict with forward will fail if PIL image does not have filename attribute' #2702

Files changed (1) hide show
  1. models/common.py +1 -1
models/common.py CHANGED
@@ -258,7 +258,7 @@ class autoShape(nn.Module):
258
  if isinstance(im, str): # filename or uri
259
  im, f = np.asarray(Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im)), im
260
  elif isinstance(im, Image.Image): # PIL Image
261
- im, f = np.asarray(im), getattr(im, 'filename', f)
262
  files.append(Path(f).with_suffix('.jpg').name)
263
  if im.shape[0] < 5: # image in CHW
264
  im = im.transpose((1, 2, 0)) # reverse dataloader .transpose(2, 0, 1)
 
258
  if isinstance(im, str): # filename or uri
259
  im, f = np.asarray(Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im)), im
260
  elif isinstance(im, Image.Image): # PIL Image
261
+ im, f = np.asarray(im), getattr(im, 'filename', f) or f
262
  files.append(Path(f).with_suffix('.jpg').name)
263
  if im.shape[0] < 5: # image in CHW
264
  im = im.transpose((1, 2, 0)) # reverse dataloader .transpose(2, 0, 1)