From ec85baaba69ae7d4d2f70db27a52700442c54dc9 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 2 Apr 2021 12:36:38 +0200 Subject: [PATCH] autoShape forward im = np.asarray(im) # to numpy (#2689) Slight speedup. --- models/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index 9970fbc8e2d9..713297c14433 100644 --- a/models/common.py +++ b/models/common.py @@ -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