anindya-hf-2002 commited on
Commit
7f5db1f
1 Parent(s): 2a70d27

delete dataset.py

Browse files
Files changed (1) hide show
  1. src/dataset.py +0 -65
src/dataset.py DELETED
@@ -1,65 +0,0 @@
1
- from PIL import Image
2
- from torch.utils.data import Dataset
3
- from torchvision import transforms
4
- import os
5
-
6
- class ClassifierDataset(Dataset):
7
- def __init__(self, root_dir, transform=None):
8
- self.root_dir = root_dir
9
- self.transform = transform
10
-
11
- self.classes = ['0', '1']
12
- self.class_to_idx = {cls: idx for idx, cls in enumerate(self.classes)}
13
-
14
- self.samples = self._make_dataset()
15
-
16
- def _make_dataset(self):
17
- samples = []
18
- for class_name in self.classes:
19
- class_dir = os.path.join(self.root_dir, class_name)
20
- for img_name in os.listdir(class_dir):
21
- img_path = os.path.join(class_dir, img_name)
22
- samples.append((img_path, self.class_to_idx[class_name]))
23
- return samples
24
-
25
- def __len__(self):
26
- return len(self.samples)
27
-
28
- def __getitem__(self, idx):
29
- img_path, label = self.samples[idx]
30
- img = Image.open(img_path).convert('L') # Convert to grayscale
31
- if self.transform:
32
- img = self.transform(img)
33
- return img, label
34
-
35
-
36
-
37
- class CustomDataset(Dataset):
38
- def __init__(self, root_dir, train_N, train_P, img_res):
39
- self.root_dir = root_dir
40
- self.train_N = train_N
41
- self.train_P = train_P
42
- self.img_res = img_res
43
- self.transforms = transforms.Compose([
44
- transforms.Resize(img_res),
45
- transforms.ToTensor(),
46
- transforms.Normalize(mean=[0.5], std=[0.5]) # Assuming grayscale images
47
- ])
48
-
49
- def __len__(self):
50
- return min(len(os.listdir(os.path.join(self.root_dir, self.train_N))),
51
- len(os.listdir(os.path.join(self.root_dir, self.train_P))))
52
-
53
- def __getitem__(self, idx):
54
- normal_path = os.path.join(self.root_dir, self.train_N, os.listdir(os.path.join(self.root_dir, self.train_N))[idx])
55
- pneumo_path = os.path.join(self.root_dir, self.train_P, os.listdir(os.path.join(self.root_dir, self.train_P))[idx])
56
-
57
- normal_img = Image.open(normal_path).convert("L") # Load as grayscale
58
- pneumo_img = Image.open(pneumo_path).convert("L") # Load as grayscale
59
-
60
- normal_img = self.transforms(normal_img)
61
- pneumo_img = self.transforms(pneumo_img)
62
-
63
- return normal_img, pneumo_img
64
-
65
-