From e1f2009273ba16bc7a58803b2c1a8f21d567c0e6 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 6 Apr 2021 13:18:56 +0200 Subject: [PATCH] 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 (cherry picked from commit ec8979f1d2f99b6873c2eafe05ec5bc2febad468) --- models/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index f6da7ad3113b..4fd1a8159c64 100644 --- a/models/common.py +++ b/models/common.py @@ -258,7 +258,7 @@ def forward(self, imgs, size=640, augment=False, profile=False): 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 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) if im.shape[0] < 5: # image in CHW im = im.transpose((1, 2, 0)) # reverse dataloader .transpose(2, 0, 1)