Skip to content

Commit

Permalink
autoShape forward im = np.asarray(im) # to numpy (ultralytics#2689)
Browse files Browse the repository at this point in the history
Slight speedup.
  • Loading branch information
glenn-jocher authored Apr 2, 2021
1 parent 0ad24e2 commit f8cd5af
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ def forward(self, imgs, size=640, augment=False, profile=False):
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')
im = np.array(im) # to numpy
if not isinstance(im, np.ndarray):
im = np.asarray(im) # to numpy
if im.shape[0] < 5: # image in CHW
im = im.transpose((1, 2, 0)) # reverse dataloader .transpose(2, 0, 1)
im = im[:, :, :3] if im.ndim == 3 else np.tile(im[:, :, None], 3) # enforce 3ch input
Expand Down

0 comments on commit f8cd5af

Please sign in to comment.