-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.py
More file actions
29 lines (25 loc) · 693 Bytes
/
Copy pathdataset.py
File metadata and controls
29 lines (25 loc) · 693 Bytes
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
import os
import sys
import csv
import argparse
import pandas as pd
import torch
from torch.utils.data import Dataset
class MnistDataset(Dataset):
"""
returns: (image, label) -> (C,H,W), ()
"""
def __init__(self, csv_path):
self.label_image = pd.read_csv(csv_path)
self.labels = self.label_image.iloc[:, 0]
self.images = self.label_image.iloc[:, 1:]
def __len__(self):
return len(self.labels)
def __getitem__(self, idx):
image = torch.Tensor(self.images.iloc[idx, :]).reshape(1, 28, 28)
label = torch.tensor(self.labels.iloc[idx])
return image, label
def main():
pass
if __name__ == "__main__":
main()