From bc56d25f17e42899b2c04c317de1de3191fcccb6 Mon Sep 17 00:00:00 2001 From: Bobholamovic Date: Tue, 31 May 2022 16:52:42 +0800 Subject: [PATCH] [Fix] Fix predictor and imgdecoder --- paddlers/deploy/predictor.py | 2 +- paddlers/transforms/operators.py | 42 +++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/paddlers/deploy/predictor.py b/paddlers/deploy/predictor.py index 2569f2f..a556012 100644 --- a/paddlers/deploy/predictor.py +++ b/paddlers/deploy/predictor.py @@ -275,7 +275,7 @@ class Predictor(object): self.timer.img_num = len(images) self.timer.info(average=True) - if isinstance(img_file, (str, np.ndarray)): + if isinstance(img_file, (str, np.ndarray, tuple)): results = results[0] return results diff --git a/paddlers/transforms/operators.py b/paddlers/transforms/operators.py index 4671716..1a34b99 100644 --- a/paddlers/transforms/operators.py +++ b/paddlers/transforms/operators.py @@ -35,13 +35,33 @@ from .functions import normalize, horizontal_flip, permute, vertical_flip, cente to_intensity, to_uint8, img_flip, img_simple_rotate __all__ = [ - "Compose", "ImgDecoder", "Resize", "RandomResize", "ResizeByShort", - "RandomResizeByShort", "ResizeByLong", "RandomHorizontalFlip", - "RandomVerticalFlip", "Normalize", "CenterCrop", "RandomCrop", - "RandomScaleAspect", "RandomExpand", "Padding", "MixupImage", - "RandomDistort", "RandomBlur", "RandomSwap", "Defogging", "DimReducing", - "BandSelecting", "ArrangeSegmenter", "ArrangeChangeDetector", - "ArrangeClassifier", "ArrangeDetector", "RandomFlipOrRotation", + "Compose", + "ImgDecoder", + "Resize", + "RandomResize", + "ResizeByShort", + "RandomResizeByShort", + "ResizeByLong", + "RandomHorizontalFlip", + "RandomVerticalFlip", + "Normalize", + "CenterCrop", + "RandomCrop", + "RandomScaleAspect", + "RandomExpand", + "Padding", + "MixupImage", + "RandomDistort", + "RandomBlur", + "RandomSwap", + "Defogging", + "DimReducing", + "BandSelecting", + "ArrangeSegmenter", + "ArrangeChangeDetector", + "ArrangeClassifier", + "ArrangeDetector", + "RandomFlipOrRotation", ] interp_dict = { @@ -179,13 +199,17 @@ class ImgDecoder(Transform): def apply(self, sample): """ Args: - sample (dict): Input sample, containing 'image' at least. + sample (dict): Input sample. Returns: dict: Decoded sample. """ if 'image' in sample: sample['image'] = self.apply_im(sample['image']) - else: # image_tx + if 'image2' in sample: + sample['image2'] = self.apply_im(sample['image2']) + if 'image_t1' in sample and not 'image' in sample: + if not ('image_t2' in sample and 'image2' not in sample): + raise ValueError sample['image'] = self.apply_im(sample['image_t1']) sample['image2'] = self.apply_im(sample['image_t2']) if 'mask' in sample: