Spaces:
Runtime error
Runtime error
updated the csv
Browse files- pages/Model_Evaluation.py +13 -15
pages/Model_Evaluation.py
CHANGED
|
@@ -16,7 +16,9 @@ import streamlit as st
|
|
| 16 |
import matplotlib.pyplot as plt
|
| 17 |
from fpdf import FPDF
|
| 18 |
from datasets import load_dataset
|
| 19 |
-
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# ---- Streamlit State Initialization ----
|
| 22 |
if 'stop_eval' not in st.session_state:
|
|
@@ -69,23 +71,27 @@ class DDRDataset(Dataset):
|
|
| 69 |
return len(self.image_paths)
|
| 70 |
|
| 71 |
def __getitem__(self, idx):
|
| 72 |
-
|
| 73 |
label = int(self.labels[idx])
|
| 74 |
|
| 75 |
-
image
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
|
|
|
| 78 |
image = apply_median_filter(image)
|
| 79 |
image = apply_clahe(image)
|
| 80 |
image = apply_gamma_correction(image)
|
| 81 |
image = apply_gaussian_filter(image)
|
| 82 |
|
| 83 |
-
image = Image.fromarray(image)
|
|
|
|
| 84 |
if self.transform:
|
| 85 |
image = self.transform(image)
|
| 86 |
|
| 87 |
return image, torch.tensor(label, dtype=torch.long)
|
| 88 |
-
|
| 89 |
# ---- Image Transforms ----
|
| 90 |
val_transform = transforms.Compose([
|
| 91 |
transforms.Resize((224, 224)),
|
|
@@ -98,20 +104,12 @@ val_transform = transforms.Compose([
|
|
| 98 |
def load_test_data_from_huggingface():
|
| 99 |
dataset = load_dataset(
|
| 100 |
"Ci-Dave/DDR_dataset_train_test",
|
| 101 |
-
data_files={"test": "splits/
|
| 102 |
split="test"
|
| 103 |
)
|
| 104 |
df = dataset.to_pandas()
|
| 105 |
-
|
| 106 |
-
# 🔍 Check actual column names if needed:
|
| 107 |
-
# st.write(df.columns)
|
| 108 |
-
|
| 109 |
-
# 🔧 Use correct column name for image paths
|
| 110 |
-
df["new_path"] = "test/" + df["id_code"].astype(str)
|
| 111 |
-
|
| 112 |
csv_path = "test_labels_temp.csv"
|
| 113 |
df.to_csv(csv_path, index=False)
|
| 114 |
-
|
| 115 |
dataset = DDRDataset(csv_path=csv_path, transform=val_transform)
|
| 116 |
return DataLoader(dataset, batch_size=32, shuffle=False)
|
| 117 |
|
|
|
|
| 16 |
import matplotlib.pyplot as plt
|
| 17 |
from fpdf import FPDF
|
| 18 |
from datasets import load_dataset
|
| 19 |
+
from huggingface_hub import hf_hub_download
|
| 20 |
+
import requests
|
| 21 |
+
from io import BytesIO
|
| 22 |
|
| 23 |
# ---- Streamlit State Initialization ----
|
| 24 |
if 'stop_eval' not in st.session_state:
|
|
|
|
| 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([
|
| 97 |
transforms.Resize((224, 224)),
|
|
|
|
| 104 |
def load_test_data_from_huggingface():
|
| 105 |
dataset = load_dataset(
|
| 106 |
"Ci-Dave/DDR_dataset_train_test",
|
| 107 |
+
data_files={"test": "splits/test_labels_updated.csv"},
|
| 108 |
split="test"
|
| 109 |
)
|
| 110 |
df = dataset.to_pandas()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
csv_path = "test_labels_temp.csv"
|
| 112 |
df.to_csv(csv_path, index=False)
|
|
|
|
| 113 |
dataset = DDRDataset(csv_path=csv_path, transform=val_transform)
|
| 114 |
return DataLoader(dataset, batch_size=32, shuffle=False)
|
| 115 |
|