Spaces:
Sleeping
Sleeping
new
Browse files- 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 |
-
|
64 |
-
|
65 |
-
|
66 |
-
self.image_paths = self.data['new_path'].tolist()
|
67 |
-
self.labels = self.data['label'].tolist()
|
68 |
-
self.transform = transform
|
69 |
|
70 |
-
|
71 |
-
|
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 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
81 |
|
82 |
-
|
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 |
-
|
|
|
|
|
|
|
89 |
|
90 |
-
|
91 |
-
|
|
|
92 |
|
93 |
-
|
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([
|