3v324v23 commited on
Commit
30e9fdb
·
1 Parent(s): 144b594
Files changed (1) hide show
  1. pages/Model_Evaluation.py +20 -25
pages/Model_Evaluation.py CHANGED
@@ -60,37 +60,32 @@ def apply_gaussian_filter(image, kernel_size=(5, 5), sigma=1.0):
60
  return cv2.GaussianBlur(image, kernel_size, sigma)
61
 
62
  # ---- Custom Dataset ----
63
- class DDRDataset(Dataset):
64
- def __init__(self, csv_path, transform=None):
65
- self.data = pd.read_csv(csv_path)
66
- self.image_paths = self.data['new_path'].tolist()
67
- self.labels = self.data['label'].tolist()
68
- self.transform = transform
69
 
70
- def __len__(self):
71
- return len(self.image_paths)
72
-
73
- def __getitem__(self, idx):
74
- img_url = self.image_paths[idx]
75
- label = int(self.labels[idx])
76
-
77
- # Load image from URL
78
  response = requests.get(img_url)
79
- image = Image.open(BytesIO(response.content)).convert('RGB')
80
- image = np.array(image) # Convert PIL image to NumPy array for OpenCV functions
 
 
 
 
81
 
82
- # Apply OpenCV preprocessing
83
- image = apply_median_filter(image)
84
- image = apply_clahe(image)
85
- image = apply_gamma_correction(image)
86
- image = apply_gaussian_filter(image)
87
 
88
- image = Image.fromarray(image) # Back to PIL for transforms
 
 
 
89
 
90
- if self.transform:
91
- image = self.transform(image)
 
92
 
93
- return image, torch.tensor(label, dtype=torch.long)
94
 
95
  # ---- Image Transforms ----
96
  val_transform = transforms.Compose([
 
60
  return cv2.GaussianBlur(image, kernel_size, sigma)
61
 
62
  # ---- Custom Dataset ----
63
+ def __getitem__(self, idx):
64
+ img_url = self.image_paths[idx]
65
+ label = int(self.labels[idx])
 
 
 
66
 
67
+ try:
68
+ print(f"Downloading: {img_url}")
 
 
 
 
 
 
69
  response = requests.get(img_url)
70
+ if response.status_code != 200:
71
+ raise ValueError(f"Failed to download image from {img_url} - status code: {response.status_code}")
72
+
73
+ image = Image.open(BytesIO(response.content)).convert("RGB")
74
+ except Exception as e:
75
+ raise RuntimeError(f"Error loading image from {img_url}: {e}")
76
 
77
+ image = np.array(image)
 
 
 
 
78
 
79
+ image = apply_median_filter(image)
80
+ image = apply_clahe(image)
81
+ image = apply_gamma_correction(image)
82
+ image = apply_gaussian_filter(image)
83
 
84
+ image = Image.fromarray(image)
85
+ if self.transform:
86
+ image = self.transform(image)
87
 
88
+ return image, torch.tensor(label, dtype=torch.long)
89
 
90
  # ---- Image Transforms ----
91
  val_transform = transforms.Compose([