(self, txt_path, transform = None, target_transform = None)
| 46 | |
| 47 | class MyDataset(Dataset): |
| 48 | def __init__(self, txt_path, transform = None, target_transform = None): |
| 49 | fh = open(txt_path, 'r') |
| 50 | imgs = [] |
| 51 | for line in fh: |
| 52 | line = line.rstrip() |
| 53 | words = line.split() |
| 54 | imgs.append((words[0], int(words[1]))) |
| 55 | |
| 56 | self.imgs = imgs # 最主要就是要生成这个list, 然后DataLoader中给index,通过getitem读取图片数据 |
| 57 | self.transform = transform |
| 58 | self.target_transform = target_transform |
| 59 | |
| 60 | def __getitem__(self, index): |
| 61 | fn, label = self.imgs[index] |
nothing calls this directly
no outgoing calls
no test coverage detected