-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
31 lines (22 loc) · 1019 Bytes
/
dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
""" Custom PyTorch Dataset Class """
import torch
import pandas as pd
from PIL import Image
from torch.utils.data import Dataset
from torchvision.io import read_image
class HuskyDataset(Dataset):
def __init__(self, dataframe, transform=None):
self.dataframe = dataframe
self.transform = transform
def __len__(self):
return len(self.dataframe)
def __getitem__(self, index):
image_path = self.dataframe.iloc[index]['image']
measurements = self.dataframe.iloc[index]['measurements']
image = Image.open(image_path)
if self.transform:
image = self.transform(image)
linear = torch.tensor([measurements['linear']['x'], measurements['linear']['y'], measurements['linear']['z']])
angular = torch.tensor([measurements['angular']['x'], measurements['angular']['y'], measurements['angular']['z']])
measurements_tensor = torch.cat([linear, angular])
return image, measurements_tensor