Spaces:
Sleeping
Sleeping
DDRDATASET
Browse files- pages/Model_Evaluation.py +25 -0
pages/Model_Evaluation.py
CHANGED
@@ -106,6 +106,31 @@ def load_test_data_from_huggingface():
|
|
106 |
csv_path = "test_labels_temp.csv"
|
107 |
df.to_csv(csv_path, index=False)
|
108 |
dataset = DDRDataset(csv_path=csv_path, transform=val_transform)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
return DataLoader(dataset, batch_size=32, shuffle=False)
|
110 |
|
111 |
# ---- Load Model from Hugging Face (cached) ----
|
|
|
106 |
csv_path = "test_labels_temp.csv"
|
107 |
df.to_csv(csv_path, index=False)
|
108 |
dataset = DDRDataset(csv_path=csv_path, transform=val_transform)
|
109 |
+
|
110 |
+
# ---- DDRDataset Class Definition ----
|
111 |
+
class DDRDataset(Dataset):
|
112 |
+
def __init__(self, csv_path, transform=None):
|
113 |
+
self.data = pd.read_csv(csv_path)
|
114 |
+
self.image_paths = self.data['image_path']
|
115 |
+
self.labels = self.data['label']
|
116 |
+
self.transform = transform
|
117 |
+
|
118 |
+
def __len__(self):
|
119 |
+
return len(self.data)
|
120 |
+
|
121 |
+
def __getitem__(self, idx):
|
122 |
+
img_path = self.image_paths[idx]
|
123 |
+
label = self.labels[idx]
|
124 |
+
|
125 |
+
try:
|
126 |
+
image = Image.open(img_path).convert("RGB")
|
127 |
+
except Exception as e:
|
128 |
+
raise RuntimeError(f"Error loading image from {img_path}: {e}")
|
129 |
+
|
130 |
+
if self.transform:
|
131 |
+
image = self.transform(image)
|
132 |
+
|
133 |
+
return image, torch.tensor(label, dtype=torch.long)
|
134 |
return DataLoader(dataset, batch_size=32, shuffle=False)
|
135 |
|
136 |
# ---- Load Model from Hugging Face (cached) ----
|