From c0e7a776cd55e8c01b63714f6f7fea3d53f6bf5b Mon Sep 17 00:00:00 2001 From: cher-liang <88578531+cher-liang@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:18:02 +0800 Subject: [PATCH] Faster pre-processing for gray image input (#9009) * faster 1 channel to 3 channels image conversion * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher --- models/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index 4f93887..f914c9d 100644 --- a/models/common.py +++ b/models/common.py @@ -617,7 +617,7 @@ class AutoShape(nn.Module): 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) - im = im[..., :3] if im.ndim == 3 else np.tile(im[..., None], 3) # enforce 3ch input + im = im[..., :3] if im.ndim == 3 else cv2.cvtColor(im, cv2.COLOR_GRAY2BGR) # enforce 3ch input s = im.shape[:2] # HWC shape0.append(s) # image shape g = (size / max(s)) # gain