From 24e41bec439b81a14bc602f548c385cbe9b508c9 Mon Sep 17 00:00:00 2001 From: Jem Date: Tue, 15 Oct 2019 16:21:40 +0800 Subject: [PATCH] fix(preprocessor): add numpy transform --- gnes/preprocessor/helper.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gnes/preprocessor/helper.py b/gnes/preprocessor/helper.py index 0cec1116..b7be20c8 100644 --- a/gnes/preprocessor/helper.py +++ b/gnes/preprocessor/helper.py @@ -388,9 +388,12 @@ def detect_peak_boundary(distances: List[float], def torch_transform(img): - import torchvision.transforms as transforms - return transforms.Compose([transforms.ToTensor(), - transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))])(img) + try: + import torchvision.transforms as transforms + return transforms.Compose([transforms.ToTensor(), + transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))])(img) + except (ImportError, ModuleNotFoundError): + return np.asarray(img) * 2 / 255. - 1. def get_all_subarea(img):