From 64e28897a950d1646bfd71fda421a199f496bd0d Mon Sep 17 00:00:00 2001 From: ly015 Date: Wed, 15 Feb 2023 15:05:56 +0800 Subject: [PATCH] transpose tensor instead of nparray --- mmpose/datasets/transforms/formatting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mmpose/datasets/transforms/formatting.py b/mmpose/datasets/transforms/formatting.py index 0bc521de12..6a2c7e85c9 100644 --- a/mmpose/datasets/transforms/formatting.py +++ b/mmpose/datasets/transforms/formatting.py @@ -3,7 +3,7 @@ import numpy as np import torch -from mmcv.transforms import BaseTransform, to_tensor +from mmcv.transforms import BaseTransform from mmengine.structures import InstanceData, PixelData from mmengine.utils import is_seq_of @@ -27,8 +27,8 @@ def image_to_tensor(img: Union[np.ndarray, if isinstance(img, np.ndarray): if len(img.shape) < 3: img = np.expand_dims(img, -1) - img = np.ascontiguousarray(img.transpose(2, 0, 1)) - tensor = to_tensor(img) + + tensor = torch.from_numpy(img).permute(2, 0, 1).contiguous() else: assert is_seq_of(img, np.ndarray) tensor = torch.stack([image_to_tensor(_img) for _img in img])