mirror of
https://github.com/huggingface/pytorch-image-models.git
synced 2025-06-03 15:01:08 +08:00
Small tweak of timm ToTensor for clarity
This commit is contained in:
parent
5a58f4d3dc
commit
7d121ac2ef
@ -32,16 +32,12 @@ class ToNumpy:
|
|||||||
|
|
||||||
|
|
||||||
class ToTensor:
|
class ToTensor:
|
||||||
|
""" ToTensor with no rescaling of values"""
|
||||||
def __init__(self, dtype=torch.float32):
|
def __init__(self, dtype=torch.float32):
|
||||||
self.dtype = dtype
|
self.dtype = dtype
|
||||||
|
|
||||||
def __call__(self, pil_img):
|
def __call__(self, pil_img):
|
||||||
np_img = np.array(pil_img, dtype=np.uint8)
|
return F.pil_to_tensor(pil_img).to(dtype=self.dtype)
|
||||||
if np_img.ndim < 3:
|
|
||||||
np_img = np.expand_dims(np_img, axis=-1)
|
|
||||||
np_img = np.rollaxis(np_img, 2) # HWC to CHW
|
|
||||||
return torch.from_numpy(np_img).to(dtype=self.dtype)
|
|
||||||
|
|
||||||
|
|
||||||
# Pillow is deprecating the top-level resampling attributes (e.g., Image.BILINEAR) in
|
# Pillow is deprecating the top-level resampling attributes (e.g., Image.BILINEAR) in
|
||||||
|
Loading…
x
Reference in New Issue
Block a user