glenn-jocher commited on
Commit
9d87307
1 Parent(s): d2e754b

YOLOv5 Hub URL inference bug fix (#2250)

Browse files

* Update common.py

* Update common.py

* Update common.py

Files changed (1) hide show
  1. models/common.py +3 -2
models/common.py CHANGED
@@ -199,7 +199,8 @@ class autoShape(nn.Module):
199
  shape0, shape1, files = [], [], [] # image and inference shapes, filenames
200
  for i, im in enumerate(imgs):
201
  if isinstance(im, str): # filename or uri
202
- im = Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im) # open
 
203
  files.append(Path(im.filename).with_suffix('.jpg').name if isinstance(im, Image.Image) else f'image{i}.jpg')
204
  im = np.array(im) # to numpy
205
  if im.shape[0] < 5: # image in CHW
@@ -253,7 +254,7 @@ class Detections:
253
  n = (pred[:, -1] == c).sum() # detections per class
254
  str += f"{n} {self.names[int(c)]}{'s' * (n > 1)}, " # add to string
255
  if show or save or render:
256
- img = Image.fromarray(img.astype(np.uint8)) if isinstance(img, np.ndarray) else img # from np
257
  for *box, conf, cls in pred: # xyxy, confidence, class
258
  # str += '%s %.2f, ' % (names[int(cls)], conf) # label
259
  ImageDraw.Draw(img).rectangle(box, width=4, outline=colors[int(cls) % 10]) # plot
 
199
  shape0, shape1, files = [], [], [] # image and inference shapes, filenames
200
  for i, im in enumerate(imgs):
201
  if isinstance(im, str): # filename or uri
202
+ im, f = Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im), im # open
203
+ im.filename = f # for uri
204
  files.append(Path(im.filename).with_suffix('.jpg').name if isinstance(im, Image.Image) else f'image{i}.jpg')
205
  im = np.array(im) # to numpy
206
  if im.shape[0] < 5: # image in CHW
 
254
  n = (pred[:, -1] == c).sum() # detections per class
255
  str += f"{n} {self.names[int(c)]}{'s' * (n > 1)}, " # add to string
256
  if show or save or render:
257
+ img = Image.fromarray(img) if isinstance(img, np.ndarray) else img # from np
258
  for *box, conf, cls in pred: # xyxy, confidence, class
259
  # str += '%s %.2f, ' % (names[int(cls)], conf) # label
260
  ImageDraw.Draw(img).rectangle(box, width=4, outline=colors[int(cls) % 10]) # plot