-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataset.py
More file actions
36 lines (28 loc) · 863 Bytes
/
dataset.py
File metadata and controls
36 lines (28 loc) · 863 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
30
31
32
33
34
35
36
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue May 23 2023
"""
from torch.utils.data import Dataset
import torch
import numpy as np
import os
import random
class XYC(Dataset):
def __init__(self, path_dir):
self.data_path = os.path.join(path_dir, "xyc.npz")
self.data_zip = np.load(self.data_path)
self.data = self.data_zip['imgs']
self.labels = self.data_zip['labs']
def __len__(self):
return self.data.shape[0]
def __getitem__(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
sample = self.data[idx]
label = self.labels[idx]
sample = torch.from_numpy(np.expand_dims(sample, axis = 0))
label = torch.from_numpy(np.expand_dims(label, axis = 0))
sample = {'x':sample,
'y':label}
return sample