Spaces:
Runtime error
Runtime error
Commit
·
c3ae33a
0
Parent(s):
Duplicate from ClassCat/Medical-Image-Classification-with-MONAI
Browse filesCo-authored-by: ClassCat AI Research <ClassCat@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +68 -0
- requirements.txt +2 -0
- samples/mednist_AbdomenCT00.png +0 -0
- samples/mednist_CXR02.png +0 -0
- samples/mednist_ChestCT08.png +0 -0
- samples/mednist_Hand01.png +0 -0
- samples/mednist_HeadCT07.png +0 -0
- weights/mednist_model.pth +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Medical Image Classification With MONAI
|
| 3 |
+
emoji: 🔥
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.16.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
duplicated_from: ClassCat/Medical-Image-Classification-with-MONAI
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from monai.networks.nets import DenseNet121
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
#from PIL import Image
|
| 9 |
+
|
| 10 |
+
model = DenseNet121(spatial_dims=2, in_channels=1, out_channels=6)
|
| 11 |
+
model.load_state_dict(torch.load('weights/mednist_model.pth', map_location=torch.device('cpu')))
|
| 12 |
+
|
| 13 |
+
from monai.transforms import (
|
| 14 |
+
EnsureChannelFirst,
|
| 15 |
+
Compose,
|
| 16 |
+
LoadImage,
|
| 17 |
+
ScaleIntensity,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
test_transforms = Compose(
|
| 21 |
+
[LoadImage(image_only=True), EnsureChannelFirst(), ScaleIntensity()]
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
class_names = [
|
| 25 |
+
'AbdomenCT', 'BreastMRI', 'CXR', 'ChestCT', 'Hand', 'HeadCT'
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
import os, glob
|
| 29 |
+
|
| 30 |
+
#examples_dir = './samples'
|
| 31 |
+
#example_files = glob.glob(os.path.join(examples_dir, '*.jpg'))
|
| 32 |
+
|
| 33 |
+
def classify_image(image_filepath):
|
| 34 |
+
input = test_transforms(image_filepath)
|
| 35 |
+
|
| 36 |
+
model.eval()
|
| 37 |
+
with torch.no_grad():
|
| 38 |
+
pred = model(input.unsqueeze(dim=0))
|
| 39 |
+
|
| 40 |
+
prob = torch.nn.functional.softmax(pred[0], dim=0)
|
| 41 |
+
|
| 42 |
+
confidences = {class_names[i]: float(prob[i]) for i in range(6)}
|
| 43 |
+
print(confidences)
|
| 44 |
+
|
| 45 |
+
return confidences
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
with gr.Blocks(title="Medical Image Classification with MONAI - ClassCat",
|
| 49 |
+
css=".gradio-container {background:mintcream;}"
|
| 50 |
+
) as demo:
|
| 51 |
+
gr.HTML("""<div style="font-family:'Times New Roman', 'Serif'; font-size:16pt; font-weight:bold; text-align:center; color:royalblue;">Medical Image Classification with MONAI</div>""")
|
| 52 |
+
|
| 53 |
+
with gr.Row():
|
| 54 |
+
input_image = gr.Image(type="filepath", image_mode="L", shape=(64, 64))
|
| 55 |
+
output_label=gr.Label(label="Probabilities", num_top_classes=3)
|
| 56 |
+
|
| 57 |
+
send_btn = gr.Button("Infer")
|
| 58 |
+
send_btn.click(fn=classify_image, inputs=input_image, outputs=output_label)
|
| 59 |
+
|
| 60 |
+
with gr.Row():
|
| 61 |
+
gr.Examples(['./samples/mednist_AbdomenCT00.png'], label='Sample images : AbdomenCT', inputs=input_image)
|
| 62 |
+
gr.Examples(['./samples/mednist_CXR02.png'], label='CXR', inputs=input_image)
|
| 63 |
+
gr.Examples(['./samples/mednist_ChestCT08.png'], label='ChestCT', inputs=input_image)
|
| 64 |
+
gr.Examples(['./samples/mednist_Hand01.png'], label='Hand', inputs=input_image)
|
| 65 |
+
gr.Examples(['./samples/mednist_HeadCT07.png'], label='HeadCT', inputs=input_image)
|
| 66 |
+
|
| 67 |
+
#demo.queue(concurrency_count=3)
|
| 68 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
monai
|
samples/mednist_AbdomenCT00.png
ADDED
|
samples/mednist_CXR02.png
ADDED
|
samples/mednist_ChestCT08.png
ADDED
|
samples/mednist_Hand01.png
ADDED
|
samples/mednist_HeadCT07.png
ADDED
|
weights/mednist_model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b075868a962aa07b10282a93fc2b02930800535c57193da084c5cdb018b2c276
|
| 3 |
+
size 28437517
|