forked from visitworld123/Twin-sight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pseduo_dataset.py
74 lines (50 loc) · 1.9 KB
/
pseduo_dataset.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import logging
import numpy as np
import torch.utils.data as data
from PIL import Image
from torchvision.datasets import CIFAR10
import torch
class Generate_Pseduo_Label_Dataset(data.Dataset):
def __init__(self, data, targets, weak_transform=None, strong_transform=None, target_transform=None):
self.data = data
self.targets = targets
self.weak_transform = weak_transform
self.strong_transform = strong_transform
self.target_transform = target_transform
def __getitem__(self, index):
"""
Args:
index (int): Index
Returns:
tuple: (image, targets) where targets is index of the targets class.
"""
img, targets = self.data[index], self.targets[index]
img = Image.fromarray(img)
if self.weak_transform is not None and self.strong_transform is not None:
weka_img = self.weak_transform(img)
strong_img = self.strong_transform(img)
else:
raise RuntimeError("Transform Lacking in Pseduo Label Dataset Generating")
if self.target_transform is not None:
targets = self.target_transform(targets)
return weka_img, strong_img, targets
def __len__(self):
return len(self.data)
class Pseduo_Label_Dataset(data.Dataset):
def __init__(self, data, targets, target_transform=None):
self.data = data
self.targets = targets
self.target_transform = target_transform
def __getitem__(self, index):
"""
Args:
index (int): Index
Returns:
tuple: (image, targets) where targets is index of the targets class.
"""
img, targets = self.data[index],self.targets[index]
if self.target_transform is not None:
targets = self.target_transform(targets)
return img, targets
def __len__(self):
return len(self.data)