From 2fe3812f982ee11f688b3cf5d0ade1db9274a89e Mon Sep 17 00:00:00 2001 From: "xianzhe.xxz" Date: Tue, 11 Apr 2023 19:59:59 +0800 Subject: [PATCH] add compatibility for torchvision>0.10.0 add compatibility for torchvision>0.10.0 Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/12292460 --- .../box_level_augs/geometric_augs.py | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/modelscope/models/cv/tinynas_detection/damo/augmentations/box_level_augs/geometric_augs.py b/modelscope/models/cv/tinynas_detection/damo/augmentations/box_level_augs/geometric_augs.py index b7984a8b..ee61adef 100644 --- a/modelscope/models/cv/tinynas_detection/damo/augmentations/box_level_augs/geometric_augs.py +++ b/modelscope/models/cv/tinynas_detection/damo/augmentations/box_level_augs/geometric_augs.py @@ -73,14 +73,25 @@ def _geometric_aug_func(x, labels_new.append(labels[i]) else: x_crop = transforms.functional.to_pil_image(x_crop.cpu()) - x_crop = transforms.functional.affine( - x_crop, - angle, - translate, - scale, - shear, - resample=2, - fillcolor=tuple([int(i) for i in pixel_mean])) + try: + x_crop = transforms.functional.affine( + x_crop, + angle, + translate, + scale, + shear, + resample=2, + fillcolor=tuple([int(i) for i in pixel_mean])) + except Exception: + x_crop = transforms.functional.affine( + x_crop, + angle, + translate, + scale, + shear, + interpolation=2, + fill=tuple([int(i) for i in pixel_mean])) + x_crop = transforms.functional.to_tensor(x_crop).to(x.device) x_crops.append(x_crop) y = _transform(x, x_crops, boxes_crops, translate)