Reputation: 66
I downloaded a dataset for facial key point detection the image and the labels were in a CSV file I extracted it using pandas but I don't know how to convert it into a tensor and load it into a data loader for training.
dataframe = pd.read_csv("training_facial_keypoints.csv")
dataframe['Image'] = dataframe['Image'].apply(lambda i: np.fromstring(i, sep=' '))
dataframe= dataframe.dropna()
images_array = np.vstack(dataframe['Image'].values)/255.0
images_array = images_array.astype(np.float32)
images_array = images_array.reshape(-1, 96, 96, 1)
print(images_array.shape)
labels_array = dataframe[dataframe.columns[:-1]].values
labels_array = (labels_array-48)/48
labels_array = labels_array.astype(np.float32)
I have the images and labels in two arrays. How do I create a training set from this and use transforms.
Then load it using a dataloader
.
Upvotes: 0
Views: 876
Reputation: 901
Create a subclass of torch.utils.data.Dataset
, fill it with your data.
You can pass desired torchvision.transforms
to it and apply them to your data in __getitem__(self, index)
.
Than you can pass it to torch.utils.data.DataLoader
which allows multi-threaded loading of data.
And PyTorch has an overwhelming documentation you should first refer to.
Upvotes: 1