Spaces:
Running on Zero
Running on Zero
done
Browse files- TestSampleDataset.py +0 -27
- app.py +4 -6
TestSampleDataset.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
-
import torch
|
| 3 |
-
from torch.utils.data import Dataset
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
class TestDataset(Dataset):
|
| 7 |
-
|
| 8 |
-
def __init__(self, npz_path, transform=None):
|
| 9 |
-
data = np.load(npz_path)
|
| 10 |
-
|
| 11 |
-
self.images = data["images"]
|
| 12 |
-
self.labels = data["labels"]
|
| 13 |
-
self.transform = transform
|
| 14 |
-
|
| 15 |
-
def __len__(self):
|
| 16 |
-
return len(self.images)
|
| 17 |
-
|
| 18 |
-
def __getitem__(self, idx):
|
| 19 |
-
image = self.images[idx]
|
| 20 |
-
label = self.labels[idx]
|
| 21 |
-
|
| 22 |
-
if self.transform:
|
| 23 |
-
image = self.transform(image)
|
| 24 |
-
|
| 25 |
-
label = torch.tensor(label, dtype=torch.float32).squeeze()
|
| 26 |
-
|
| 27 |
-
return image, label
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -27,7 +27,6 @@ model = Predictor(n_labels=len(LABELS))
|
|
| 27 |
|
| 28 |
model_file = hf_hub_download(
|
| 29 |
repo_id="Hali5/Mae-Model-MedMNIST-Predictor",
|
| 30 |
-
# Create a read-only text box to display the column for Truth Labels
|
| 31 |
filename="checkpoints/model_linear_v2_epoch_100.pt"
|
| 32 |
)
|
| 33 |
|
|
@@ -81,7 +80,7 @@ with gradio.Blocks() as demo:
|
|
| 81 |
|
| 82 |
with gradio.Tab("Predict"):
|
| 83 |
gradio.Markdown("Upload a tissue patch image for classification.")
|
| 84 |
-
input_img = gradio.Image()
|
| 85 |
output_lbl = gradio.Label(num_top_classes=3)
|
| 86 |
btn = gradio.Button("Predict")
|
| 87 |
btn.click(fn=predict, inputs=input_img, outputs=output_lbl)
|
|
@@ -89,11 +88,10 @@ with gradio.Blocks() as demo:
|
|
| 89 |
with gradio.Tab("Examples"):
|
| 90 |
gradio.Markdown("Click an example below to test the model against the PathMNIST test dataset.")
|
| 91 |
|
| 92 |
-
with gradio.
|
| 93 |
-
|
|
|
|
| 94 |
truth_box = gradio.Textbox(label="Ground Truth Label", interactive=False)
|
| 95 |
-
|
| 96 |
-
with gradio.Column():
|
| 97 |
output_lbl_ex = gradio.Label(num_top_classes=3, label="Model Prediction")
|
| 98 |
|
| 99 |
gradio.Examples(
|
|
|
|
| 27 |
|
| 28 |
model_file = hf_hub_download(
|
| 29 |
repo_id="Hali5/Mae-Model-MedMNIST-Predictor",
|
|
|
|
| 30 |
filename="checkpoints/model_linear_v2_epoch_100.pt"
|
| 31 |
)
|
| 32 |
|
|
|
|
| 80 |
|
| 81 |
with gradio.Tab("Predict"):
|
| 82 |
gradio.Markdown("Upload a tissue patch image for classification.")
|
| 83 |
+
input_img = gradio.Image(height=512, width=512)
|
| 84 |
output_lbl = gradio.Label(num_top_classes=3)
|
| 85 |
btn = gradio.Button("Predict")
|
| 86 |
btn.click(fn=predict, inputs=input_img, outputs=output_lbl)
|
|
|
|
| 88 |
with gradio.Tab("Examples"):
|
| 89 |
gradio.Markdown("Click an example below to test the model against the PathMNIST test dataset.")
|
| 90 |
|
| 91 |
+
with gradio.Row():
|
| 92 |
+
with gradio.Column():
|
| 93 |
+
input_img_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
|
| 94 |
truth_box = gradio.Textbox(label="Ground Truth Label", interactive=False)
|
|
|
|
|
|
|
| 95 |
output_lbl_ex = gradio.Label(num_top_classes=3, label="Model Prediction")
|
| 96 |
|
| 97 |
gradio.Examples(
|