-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcustom_datasets.py
More file actions
30 lines (25 loc) · 941 Bytes
/
Copy pathcustom_datasets.py
File metadata and controls
30 lines (25 loc) · 941 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
from torch.utils.data import Dataset
from PIL import Image
from random import shuffle
from torchvision import transforms
class AL_Dataset(Dataset):
def __init__(self, unlabeled_imgs, limit, transform = None):
self.unlabeled_imgs = unlabeled_imgs
self.transform = transforms.Compose([
transforms.Resize((224,224)),
transforms.ToTensor()])
if limit == -1:
print("Getting confidences for entire unlabeled dataset")
else:
print(f"Getting Confidences from random {limit} data")
shuffle(self.unlabeled_imgs)
self.unlabeled_imgs = self.unlabeled_imgs[:limit]
self.transform = transform
def __len__(self):
return len(self.unlabeled_imgs)
def __getitem__(self, index):
img_path = self.unlabeled_imgs[index]
img = Image.open(img_path).convert('RGB')
if self.transform:
img = self.transform(img)
return img, img_path