MCPcopy Create free account
hub / github.com/Sirwenhao/Deep-Learning-Notes / MyDataSet

Class MyDataSet

CV/Pytorch_classification/DenseNet/my_dataset.py:7–32  ·  view source on GitHub ↗

自定义数据集

Source from the content-addressed store, hash-verified

5from torch.utils.data import Dataset
6
7class MyDataSet(Dataset):
8 """自定义数据集"""
9 def __init__(self, images_path, images_class, transform=None):
10 self.images_path = images_path
11 self.images_class = images_class
12 self.transform = transform
13
14 def __len__(self):
15 return len(self.images_path)
16
17 def __gettiem__(self, item):
18 img = Image.open(self.images_path[item])
19 if img.mode != 'RGB':
20 raise ValueError("image: {} isn't RGB mode.".format(self.images_path[item]))
21 label = self.images_class[item]
22
23 if self.transform is not None:
24 img = self.transform(img)
25 return img, label
26
27 @staticmethod
28 def collate_fn(batch):
29 images, label = tuple(zip(*batch))
30 images = torch.stack(images, dim=0)
31 labels = torch.as_tensor(labels)
32 return images, labels
33
34

Callers 3

mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected