Skip to content

Commit cf66708

Browse files
author
zyan3
committed
[video transforms]in ToTensorVideo, divide value by 255.0
1 parent 406efa4 commit cf66708

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

test/test_transforms_video.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_random_crop_video(self):
1919
width = random.randint(10, 32) * 2
2020
oheight = random.randint(5, (height - 2) / 2) * 2
2121
owidth = random.randint(5, (width - 2) / 2) * 2
22-
clip = torch.ones((numFrames, height, width, 3), dtype=torch.uint8)
22+
clip = torch.randint(0, 256, (numFrames, height, width, 3), dtype=torch.uint8)
2323
result = transforms.Compose([
2424
transforms.ToTensorVideo(),
2525
transforms.RandomCropVideo((oheight, owidth)),
@@ -35,7 +35,7 @@ def test_random_resized_crop_video(self):
3535
width = random.randint(10, 32) * 2
3636
oheight = random.randint(5, (height - 2) / 2) * 2
3737
owidth = random.randint(5, (width - 2) / 2) * 2
38-
clip = torch.ones((numFrames, height, width, 3), dtype=torch.uint8)
38+
clip = torch.randint(0, 256, (numFrames, height, width, 3), dtype=torch.uint8)
3939
result = transforms.Compose([
4040
transforms.ToTensorVideo(),
4141
transforms.RandomResizedCropVideo((oheight, owidth)),
@@ -52,7 +52,7 @@ def test_center_crop_video(self):
5252
oheight = random.randint(5, (height - 2) / 2) * 2
5353
owidth = random.randint(5, (width - 2) / 2) * 2
5454

55-
clip = torch.ones([numFrames, height, width, 3], dtype=torch.uint8)
55+
clip = torch.ones((numFrames, height, width, 3), dtype=torch.uint8) * 255
5656
oh1 = (height - oheight) // 2
5757
ow1 = (width - owidth) // 2
5858
clipNarrow = clip[:, oh1:oh1 + oheight, ow1:ow1 + owidth, :]

torchvision/transforms/functional_video.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def center_crop(clip, crop_size):
5959

6060
def to_tensor(clip):
6161
"""
62-
Convert tensor data type to be float and permute the dimenions of clip tensor
62+
Convert tensor data type from uint8 to float, divide value by 255.0 and
63+
permute the dimenions of clip tensor
6364
Args:
6465
clip (torch.tensor, dtype=torch.uint8): Size is (T, H, W, C)
6566
Return:
@@ -68,7 +69,7 @@ def to_tensor(clip):
6869
_is_tensor_video_clip(clip)
6970
if not clip.dtype == torch.uint8:
7071
raise TypeError("clip tensor should have data type uint8. Got %s" % str(clip.dtype))
71-
return clip.float().permute(3, 0, 1, 2)
72+
return clip.float().permute(3, 0, 1, 2) / 255.0
7273

7374

7475
def normalize(clip, mean, std, inplace=False):

torchvision/transforms/transforms_video.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ def __repr__(self):
126126

127127
class ToTensorVideo(object):
128128
"""
129-
Convert tensor data type to be float and permute the dimenions of clip tensor
129+
Convert tensor data type from uint8 to float, divide value by 255.0 and
130+
permute the dimenions of clip tensor
130131
"""
131132

132133
def __init__(self):
133134
pass
134135

135136
def __call__(self, clip):
136137
"""
137-
Convert tensor data type to be float and permute the dimenions of clip tensor
138138
Args:
139139
clip (torch.tensor, dtype=torch.uint8): Size is (T, H, W, C)
140140
Return:
@@ -157,7 +157,6 @@ def __init__(self, p=0.5):
157157

158158
def __call__(self, clip):
159159
"""
160-
Convert tensor data type to be float and permute the dimenions of clip tensor
161160
Args:
162161
clip (torch.tensor): Size is (C, T, H, W)
163162
Return:

0 commit comments

Comments
 (0)