Updated filename attributes for YOLOv5 Hub BytesIO (#2718)

Fix 2 for 'Model predict with forward will fail if PIL image does not have filename attribute' #2702
This commit is contained in:
Glenn Jocher authored and GitHub committed 2021-04-06 13:18:56 +02:00
1 parent 74276d5189
commit ec8979f1d2
1 file changed
+1 -1
+1 -1
View File
@@ -258,7 +258,7 @@ class autoShape(nn.Module):
if isinstance(im, str): # filename or uri if isinstance(im, str): # filename or uri
im, f = np.asarray(Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im)), im im, f = np.asarray(Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im)), im
elif isinstance(im, Image.Image): # PIL Image elif isinstance(im, Image.Image): # PIL Image
im, f = np.asarray(im), getattr(im, 'filename', f) im, f = np.asarray(im), getattr(im, 'filename', f) or f
files.append(Path(f).with_suffix('.jpg').name) files.append(Path(f).with_suffix('.jpg').name)
if im.shape[0] < 5: # image in CHW if im.shape[0] < 5: # image in CHW
im = im.transpose((1, 2, 0)) # reverse dataloader .transpose(2, 0, 1) im = im.transpose((1, 2, 0)) # reverse dataloader .transpose(2, 0, 1)