任何帮助都将不胜感激。transforms.py 中的代码表示该变换应该/会应用于 PIL 图像和 ndarrays。
给定以下变换:
我希望对从其他代码中获得的ndarrays应用变换。假设它是x_data,其形状为(1000,120,160,3),其中维度为(总行数,宽度,高度,通道)。
以下操作失败了(我所尝试的只是应用一个变换):
带有以下信息:
data_transforms = {
'train': transforms.Compose([
transforms.Scale(256),
transforms.Pad(4,0),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
]),
'val': transforms.Compose([
transforms.Scale(256),
transforms.Pad(4,0),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
]),
}
我希望对从其他代码中获得的ndarrays应用变换。假设它是x_data,其形状为(1000,120,160,3),其中维度为(总行数,宽度,高度,通道)。
以下操作失败了(我所尝试的只是应用一个变换):
foo = data_transforms['train']
bar = foo(x_data[0])
带有以下信息:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-93-a703e3b9c76d> in <module>()
----> 1 foo(x_data[1])
~/anaconda3/envs/pytorch/lib/python3.5/site-packages/torchvision-0.1.9-py3.5.egg/torchvision/transforms.py in __call__(self, img)
32 def __call__(self, img):
33 for t in self.transforms:
---> 34 img = t(img)
35 return img
36
~/anaconda3/envs/pytorch/lib/python3.5/site-packages/torchvision-0.1.9-py3.5.egg/torchvision/transforms.py in __call__(self, img)
185 """
186 if isinstance(self.size, int):
--> 187 w, h = img.size
188 if (w <= h and w == self.size) or (h <= w and h == self.size):
189 return img
TypeError: 'int' object is not iterable