import torchvision
from torch.utils.data import Dataset, DataLoader
from torch import from_numpy, tensor
import numpy as np
trans = transforms.Compose(
[
transforms.Resize(128),
transforms.ToTensor()
])
class UBFCDataset(Dataset):
def __init__(self):
xy = np.loadtxt('/content/drive/My Drive/Subject3hr.csv')
self.x_data = torch.from_numpy(xy[:])
self.len = xy.shape[0]
def __len__(self):
return self.len
def __getitem__(self, index):
train_data_tensor = torchvision.datasets.ImageFolder("/content/drive/My Drive/Meta-rPPG-master/da", transform=trans)
return train_data_tensor[index], self.x_data[index]
dataset = UBFCDataset()
dataset[0]
train_loader = DataLoader(dataset=dataset,batch_size=128,shuffle=True)
for epoch in range(2):
for i, data in enumerate(train_loader, 0):
# get the inputs
inputs, labels = data
print(inputs.shape)
# Run your training process
print(f'Epoch: {i} | Inputs {inputs} | Labels {labels}')
Error:
AttributeError Traceback (most recent call last)
<ipython-input-156-fecbaf453580> in <module>()
4 inputs, labels = data
5
----> 6 print(inputs.shape)
7 # Run your training process
8 print(f'Epoch: {i} | Inputs {inputs} | Labels {labels}')
AttributeError: 'list' object has no attribute 'shape'
You're assuming the variable type is a numpy array, while it is actually a primitive list. Here is the fixed code:
for epoch in range(2):
for i, data in enumerate(train_loader, 0):
# get the inputs
inputs, labels = data
inputs = np.array(inputs)
print(inputs.shape)
# Run your training process
print(f'Epoch: {i} | Inputs {inputs} | Labels {labels}')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.