获取5种随机作物-TypeError:图片应为PIL图像或ndarray。得到了<type'tuple'=“”>

时间:2019-03-24 12:31:25

标签: conv-neural-network pytorch vision

我对图像进行如下转换(与RandCrop一起使用):(来自此数据加载器脚本:https://github.com/jeffreyhuang1/two-stream-action-recognition/blob/master/dataloader/motion_dataloader.py

def train(self):
training_set = motion_dataset(dic=self.dic_video_train, in_channel=self.in_channel, root_dir=self.data_path,
mode=‘train’,
transform = transforms.Compose([
transforms.Resize([256,256]),
transforms.FiveCrop([224, 224]),
#transforms.RandomCrop([224, 224]),
transforms.ToTensor(),
#transforms.Normalize([0.5], [0.5])
]))
print ‘==> Training data :’,len(training_set),’ videos’,training_set[1][0].size()

    train_loader = DataLoader(
        dataset=training_set, 
        batch_size=self.BATCH_SIZE,
        shuffle=True,
        num_workers=self.num_workers,
        pin_memory=True
        )

    return train_loader

但是当我尝试获取五种作物时,会出现此错误:

Traceback (most recent call last):
File “motion_cnn.py”, line 267, in 
main()
File “motion_cnn.py”, line 51, in main
train_loader,test_loader, test_video = data_loader.run()
File “/media/d/DATA_2/two-stream-action-recognition-master/dataloader/motion_dataloader.py”, line 120, in run
train_loader = self.train()
File “/media/d/DATA_2/two-stream-action-recognition-master/dataloader/motion_dataloader.py”, line 156, in train
print ‘==> Training data :’,len(training_set),’ videos’,training_set[1][0].size()
File “/media/d/DATA_2/two-stream-action-recognition-master/dataloader/motion_dataloader.py”, line 77, in getitem
data = self.stackopf()
File “/media/d/DATA_2/two-stream-action-recognition-master/dataloader/motion_dataloader.py”, line 51, in stackopf
H = self.transform(imgH)
File “/media/d/DATA_2/two-stream-action-recognition-master/venv/local/lib/python2.7/site-packages/torchvision/transforms/transforms.py”, line 60, in call
img = t(img)
File “/media/d/DATA_2/two-stream-action-recognition-master/venv/local/lib/python2.7/site-packages/torchvision/transforms/transforms.py”, line 91, in call
return F.to_tensor(pic)
File “/media/d/DATA_2/two-stream-action-recognition-master/venv/local/lib/python2.7/site-packages/torchvision/transforms/functional.py”, line 50, in to_tensor
raise TypeError(‘pic should be PIL Image or ndarray. Got {}’.format(type(pic)))
TypeError: pic should be PIL Image or ndarray. Got <type ‘tuple’>

要获得5种随机作物,我应该处理一堆图像而不是一个PIL图像-所以我使用Lambda,但是然后在stackopf的第55行出现了错误 流[2 *(j),:,:] = H

  

RuntimeError:expand(torch.FloatTensor {[5,1,224,224]},size = [224,   224]):提供的尺寸数(2)必须大于或等于   张量中的维数(4)

当我尝试设置flow = torch.FloatTensor(5,2 * self.in_channel,self.img_rows,self.img_cols)

在stackopf中,我得到了motion_dataloader.py“,第55行 流[:,2 *(j),:,:] = H

  

RuntimeError:expand(torch.FloatTensor {[5,1,224,224]},size = [5,   224,224]):提供的尺寸数(3)必须大于或等于   到张量中的维数(4)

当我将返回的火车批次大小乘以5时,我也会遇到相同的错误。

0 个答案:

没有答案