Spaces:
Sleeping
Sleeping
added /tmp/external_xrays_299x299x3 to have imgs int the same repo instead on dataset repo
Browse files- app.py +1 -1
- base.py +28 -18
- tmp/external_xrays_299x299x3/COVID-102.png +0 -0
- tmp/external_xrays_299x299x3/COVID-27.png +0 -0
- tmp/external_xrays_299x299x3/COVID-28.png +0 -0
- tmp/external_xrays_299x299x3/COVID-32.png +0 -0
- tmp/external_xrays_299x299x3/COVID-37.png +0 -0
- tmp/external_xrays_299x299x3/Lung_Opacity-1.png +0 -0
- tmp/external_xrays_299x299x3/Lung_Opacity-34.png +0 -0
- tmp/external_xrays_299x299x3/Lung_Opacity-36.png +0 -0
- tmp/external_xrays_299x299x3/Lung_Opacity-76.png +0 -0
- tmp/external_xrays_299x299x3/Lung_Opacity-99.png +0 -0
- tmp/external_xrays_299x299x3/Normal-1.png +0 -0
- tmp/external_xrays_299x299x3/Normal-31.png +0 -0
- tmp/external_xrays_299x299x3/Normal-41.png +0 -0
- tmp/external_xrays_299x299x3/Normal-77.png +0 -0
- tmp/external_xrays_299x299x3/Normal-78.png +0 -0
- tmp/external_xrays_299x299x3/Viral Pneumonia-12.png +0 -0
- tmp/external_xrays_299x299x3/Viral Pneumonia-25.png +0 -0
- tmp/external_xrays_299x299x3/Viral Pneumonia-27.png +0 -0
- tmp/external_xrays_299x299x3/Viral Pneumonia-3.png +0 -0
- tmp/external_xrays_299x299x3/Viral Pneumonia-39.png +0 -0
app.py
CHANGED
|
@@ -61,6 +61,6 @@ if __name__ == "__main__":
|
|
| 61 |
print("Python version used:", sys.version)
|
| 62 |
|
| 63 |
if is_spaces:
|
| 64 |
-
demo.launch(debug=True, allowed_paths=[str(IMG_DIR
|
| 65 |
else:
|
| 66 |
demo.launch(share=True, debug=True, server_name="127.0.0.1", server_port=7860)
|
|
|
|
| 61 |
print("Python version used:", sys.version)
|
| 62 |
|
| 63 |
if is_spaces:
|
| 64 |
+
demo.launch(debug=True, allowed_paths=[str(IMG_DIR), str(Path(local_dataset_dir))],)
|
| 65 |
else:
|
| 66 |
demo.launch(share=True, debug=True, server_name="127.0.0.1", server_port=7860)
|
base.py
CHANGED
|
@@ -11,12 +11,16 @@ from defs import class_to_disease_map
|
|
| 11 |
import pandas as pd
|
| 12 |
from typing import Mapping
|
| 13 |
from pathlib import Path
|
|
|
|
| 14 |
|
| 15 |
# -------CONSTANTS-------#
|
| 16 |
TARGET_SIZE = (256, 256) # target size for masked images
|
| 17 |
# Your dataset repo on HF
|
| 18 |
DATASET_REPO = "valste/lung-disease-xrays"
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# Download (or reuse cache) in the Space
|
| 21 |
local_dataset_dir = snapshot_download(repo_id=DATASET_REPO, repo_type="dataset", allow_patterns=["external_xrays_299x299/*"],)
|
| 22 |
print("Local dataset dir:", local_dataset_dir)
|
|
@@ -94,23 +98,22 @@ else:
|
|
| 94 |
capsnet_model_path = os.path.join(
|
| 95 |
".", "models", "capsnet-4class-lung-disease-classifier", "model.keras"
|
| 96 |
)
|
| 97 |
-
#capsnet_knl5_path = Path(r"C:\Users\User\VS_CODE_WORKSPACES\DataScience\ds_aug24_lung_desease_classification\mlruns_capsnet\923962217935764323\af22305e09b44dd686b2405b0f6c01d5\artifacts\model\data\model.keras") #conv2d_1 krnl=5
|
| 98 |
gan_model_path = os.path.join(".", "models", "lung-segmentation-gan", "model.keras")
|
| 99 |
-
data_dir = os.path.join(".", "
|
| 100 |
-
dataset = load_dataset(
|
| 101 |
-
|
| 102 |
-
)
|
| 103 |
-
for ex in dataset:
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
|
| 115 |
|
| 116 |
#----Load models----#
|
|
@@ -123,8 +126,15 @@ model_capsnet = tf.keras.models.load_model(capsnet_model_path, custom_objects=ca
|
|
| 123 |
# ------------------------------------------------------------
|
| 124 |
|
| 125 |
# Build example lists once
|
| 126 |
-
img_paths = sorted(str(p) for p in IMG_DIR.glob("*.png"))
|
| 127 |
-
img_names = [os.path.basename(p) for p in img_paths]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
|
| 130 |
# ------------------------------------------------------------
|
|
|
|
| 11 |
import pandas as pd
|
| 12 |
from typing import Mapping
|
| 13 |
from pathlib import Path
|
| 14 |
+
import shutil
|
| 15 |
|
| 16 |
# -------CONSTANTS-------#
|
| 17 |
TARGET_SIZE = (256, 256) # target size for masked images
|
| 18 |
# Your dataset repo on HF
|
| 19 |
DATASET_REPO = "valste/lung-disease-xrays"
|
| 20 |
|
| 21 |
+
EXAMPLES_DIR = Path("/tmp/external_xrays_299x299x3")
|
| 22 |
+
EXAMPLES_DIR.mkdir(parents=True, exist_ok=True)
|
| 23 |
+
|
| 24 |
# Download (or reuse cache) in the Space
|
| 25 |
local_dataset_dir = snapshot_download(repo_id=DATASET_REPO, repo_type="dataset", allow_patterns=["external_xrays_299x299/*"],)
|
| 26 |
print("Local dataset dir:", local_dataset_dir)
|
|
|
|
| 98 |
capsnet_model_path = os.path.join(
|
| 99 |
".", "models", "capsnet-4class-lung-disease-classifier", "model.keras"
|
| 100 |
)
|
|
|
|
| 101 |
gan_model_path = os.path.join(".", "models", "lung-segmentation-gan", "model.keras")
|
| 102 |
+
# data_dir = os.path.join(".", "external_xrays_299x299x3")
|
| 103 |
+
# dataset = load_dataset(
|
| 104 |
+
# "imagefolder", data_dir=data_dir, split="train" # path to your local folder
|
| 105 |
+
# )
|
| 106 |
+
# for ex in dataset:
|
| 107 |
+
# if "image" in ex:
|
| 108 |
+
# imgs.append(ex["image"])
|
| 109 |
+
# path = getattr(ex["image"], "filename", None) # string
|
| 110 |
+
# if path:
|
| 111 |
+
# img_paths.append([path])
|
| 112 |
+
# img_names.append(os.path.basename(path))
|
| 113 |
+
# else:
|
| 114 |
+
# raise DemoException("Missing path")
|
| 115 |
+
# else:
|
| 116 |
+
# raise DemoException("Dataset examples do not contain 'image' field.")
|
| 117 |
|
| 118 |
|
| 119 |
#----Load models----#
|
|
|
|
| 126 |
# ------------------------------------------------------------
|
| 127 |
|
| 128 |
# Build example lists once
|
| 129 |
+
# img_paths = sorted(str(p) for p in IMG_DIR.glob("*.png"))
|
| 130 |
+
# img_names = [os.path.basename(p) for p in img_paths]
|
| 131 |
+
|
| 132 |
+
for p in sorted(IMG_DIR.glob("*.png"))[:20]:
|
| 133 |
+
dst = EXAMPLES_DIR / p.name
|
| 134 |
+
shutil.copyfile(p, dst)
|
| 135 |
+
|
| 136 |
+
img_paths.append([str(dst)]) # gr.Examples expects list-of-inputs
|
| 137 |
+
img_names.append(p.name)
|
| 138 |
|
| 139 |
|
| 140 |
# ------------------------------------------------------------
|
tmp/external_xrays_299x299x3/COVID-102.png
ADDED
|
tmp/external_xrays_299x299x3/COVID-27.png
ADDED
|
tmp/external_xrays_299x299x3/COVID-28.png
ADDED
|
tmp/external_xrays_299x299x3/COVID-32.png
ADDED
|
tmp/external_xrays_299x299x3/COVID-37.png
ADDED
|
tmp/external_xrays_299x299x3/Lung_Opacity-1.png
ADDED
|
tmp/external_xrays_299x299x3/Lung_Opacity-34.png
ADDED
|
tmp/external_xrays_299x299x3/Lung_Opacity-36.png
ADDED
|
tmp/external_xrays_299x299x3/Lung_Opacity-76.png
ADDED
|
tmp/external_xrays_299x299x3/Lung_Opacity-99.png
ADDED
|
tmp/external_xrays_299x299x3/Normal-1.png
ADDED
|
tmp/external_xrays_299x299x3/Normal-31.png
ADDED
|
tmp/external_xrays_299x299x3/Normal-41.png
ADDED
|
tmp/external_xrays_299x299x3/Normal-77.png
ADDED
|
tmp/external_xrays_299x299x3/Normal-78.png
ADDED
|
tmp/external_xrays_299x299x3/Viral Pneumonia-12.png
ADDED
|
tmp/external_xrays_299x299x3/Viral Pneumonia-25.png
ADDED
|
tmp/external_xrays_299x299x3/Viral Pneumonia-27.png
ADDED
|
tmp/external_xrays_299x299x3/Viral Pneumonia-3.png
ADDED
|
tmp/external_xrays_299x299x3/Viral Pneumonia-39.png
ADDED
|