Unverified 提交 9d873077 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

YOLOv5 Hub URL inference bug fix (#2250)

* Update common.py * Update common.py * Update common.py
上级 d2e754b6
...@@ -199,7 +199,8 @@ class autoShape(nn.Module): ...@@ -199,7 +199,8 @@ class autoShape(nn.Module):
shape0, shape1, files = [], [], [] # image and inference shapes, filenames shape0, shape1, files = [], [], [] # image and inference shapes, filenames
for i, im in enumerate(imgs): for i, im in enumerate(imgs):
if isinstance(im, str): # filename or uri if isinstance(im, str): # filename or uri
im = Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im) # open im, f = Image.open(requests.get(im, stream=True).raw if im.startswith('http') else im), im # open
im.filename = f # for uri
files.append(Path(im.filename).with_suffix('.jpg').name if isinstance(im, Image.Image) else f'image{i}.jpg') files.append(Path(im.filename).with_suffix('.jpg').name if isinstance(im, Image.Image) else f'image{i}.jpg')
im = np.array(im) # to numpy im = np.array(im) # to numpy
if im.shape[0] < 5: # image in CHW if im.shape[0] < 5: # image in CHW
...@@ -253,7 +254,7 @@ class Detections: ...@@ -253,7 +254,7 @@ class Detections:
n = (pred[:, -1] == c).sum() # detections per class n = (pred[:, -1] == c).sum() # detections per class
str += f"{n} {self.names[int(c)]}{'s' * (n > 1)}, " # add to string str += f"{n} {self.names[int(c)]}{'s' * (n > 1)}, " # add to string
if show or save or render: if show or save or render:
img = Image.fromarray(img.astype(np.uint8)) if isinstance(img, np.ndarray) else img # from np img = Image.fromarray(img) if isinstance(img, np.ndarray) else img # from np
for *box, conf, cls in pred: # xyxy, confidence, class for *box, conf, cls in pred: # xyxy, confidence, class
# str += '%s %.2f, ' % (names[int(cls)], conf) # label # str += '%s %.2f, ' % (names[int(cls)], conf) # label
ImageDraw.Draw(img).rectangle(box, width=4, outline=colors[int(cls) % 10]) # plot ImageDraw.Draw(img).rectangle(box, width=4, outline=colors[int(cls) % 10]) # plot
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论