add gitignore, add option to not show heatmap
Browse files- .gitignore +170 -0
- app.py +24 -15
- skp/__pycache__/utils.cpython-312.pyc +0 -0
- skp/configs/__pycache__/__init__.cpython-312.pyc +0 -0
- skp/configs/__pycache__/base.cpython-312.pyc +0 -0
- skp/configs/boneage/__pycache__/cfg_crop_simple_resize.cpython-312.pyc +0 -0
- skp/configs/boneage/__pycache__/cfg_female_channel_reg_cls_match_hist.cpython-312.pyc +0 -0
- skp/models/__pycache__/modules.cpython-312.pyc +0 -0
- skp/models/__pycache__/pooling.cpython-312.pyc +0 -0
- skp/models/classification/__pycache__/net2d.cpython-312.pyc +0 -0
- skp/models/classification/__pycache__/net2d_multihead.cpython-312.pyc +0 -0
.gitignore
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# UV
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
#uv.lock
|
102 |
+
|
103 |
+
# poetry
|
104 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
105 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
106 |
+
# commonly ignored for libraries.
|
107 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
108 |
+
#poetry.lock
|
109 |
+
|
110 |
+
# pdm
|
111 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
112 |
+
#pdm.lock
|
113 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
114 |
+
# in version control.
|
115 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
116 |
+
.pdm.toml
|
117 |
+
.pdm-python
|
118 |
+
.pdm-build/
|
119 |
+
|
120 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
121 |
+
__pypackages__/
|
122 |
+
|
123 |
+
# Celery stuff
|
124 |
+
celerybeat-schedule
|
125 |
+
celerybeat.pid
|
126 |
+
|
127 |
+
# SageMath parsed files
|
128 |
+
*.sage.py
|
129 |
+
|
130 |
+
# Environments
|
131 |
+
.env
|
132 |
+
.venv
|
133 |
+
env/
|
134 |
+
venv/
|
135 |
+
ENV/
|
136 |
+
env.bak/
|
137 |
+
venv.bak/
|
138 |
+
|
139 |
+
# Spyder project settings
|
140 |
+
.spyderproject
|
141 |
+
.spyproject
|
142 |
+
|
143 |
+
# Rope project settings
|
144 |
+
.ropeproject
|
145 |
+
|
146 |
+
# mkdocs documentation
|
147 |
+
/site
|
148 |
+
|
149 |
+
# mypy
|
150 |
+
.mypy_cache/
|
151 |
+
.dmypy.json
|
152 |
+
dmypy.json
|
153 |
+
|
154 |
+
# Pyre type checker
|
155 |
+
.pyre/
|
156 |
+
|
157 |
+
# pytype static type analyzer
|
158 |
+
.pytype/
|
159 |
+
|
160 |
+
# Cython debug symbols
|
161 |
+
cython_debug/
|
162 |
+
|
163 |
+
# PyCharm
|
164 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
165 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
166 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
167 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
168 |
+
#.idea/
|
169 |
+
|
170 |
+
.gradio
|
app.py
CHANGED
@@ -70,7 +70,7 @@ greulich_and_pyle_ages = {k: np.asarray(v) for k, v in greulich_and_pyle_ages.it
|
|
70 |
model_grad_cam = ModelForGradCAM(model_list[0])
|
71 |
target_layers = [model_grad_cam.model.backbone.stages[-1]]
|
72 |
|
73 |
-
def predict_bone_age(Radiograph, Sex):
|
74 |
x0 = rearrange(Radiograph, "h w -> h w 1")
|
75 |
x = cfg_crop.val_transforms(image=x0)["image"]
|
76 |
x = torch.from_numpy(x)
|
@@ -115,23 +115,28 @@ def predict_bone_age(Radiograph, Sex):
|
|
115 |
closest1 = convert_bone_age_to_string(closest1)
|
116 |
closest2 = convert_bone_age_to_string(closest2)
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
127 |
|
128 |
return f"Predicted bone age: {bone_age_str}\n\nThe closest Greulich & Pyle bone ages are:\n 1) {closest1}\n 2) {closest2}", grad_cam_image
|
129 |
|
130 |
|
131 |
image = gr.Image(image_mode="L")
|
132 |
sex = gr.Radio(["Male", "Female"], type="index")
|
|
|
133 |
textbox = gr.Textbox(show_label=True, label="Result")
|
134 |
-
grad_cam_image = gr.Image(image_mode="RGB", label="Heatmap")
|
135 |
|
136 |
with gr.Blocks() as demo:
|
137 |
gr.Markdown(
|
@@ -144,6 +149,9 @@ with gr.Blocks() as demo:
|
|
144 |
The model achieves a mean absolute error of 4.26 months on the original test set comprising 200 multi-annotated hand radiographs,
|
145 |
which is competitive with [top solutions](https://pubs.rsna.org/doi/10.1148/radiol.2018180736) from the original challenge.
|
146 |
|
|
|
|
|
|
|
147 |
This model is for demonstration purposes only and has NOT been approved by any regulatory agency for clinical use. The user assumes
|
148 |
any and all responsibility regarding their own use of this model and its outputs. Do NOT upload any images containing protected
|
149 |
health information, as this demonstration is not compliant with patient privacy laws.
|
@@ -155,13 +163,14 @@ with gr.Blocks() as demo:
|
|
155 |
)
|
156 |
gr.Interface(
|
157 |
fn=predict_bone_age,
|
158 |
-
inputs=[image, sex],
|
159 |
outputs=[textbox, grad_cam_image],
|
160 |
examples=[
|
161 |
-
["examples/2639.png", "Female"],
|
162 |
-
["examples/10043.png", "Female"],
|
163 |
-
["examples/8888.png", "Female"],
|
164 |
],
|
|
|
165 |
)
|
166 |
|
167 |
if __name__ == "__main__":
|
|
|
70 |
model_grad_cam = ModelForGradCAM(model_list[0])
|
71 |
target_layers = [model_grad_cam.model.backbone.stages[-1]]
|
72 |
|
73 |
+
def predict_bone_age(Radiograph, Sex, Heatmap):
|
74 |
x0 = rearrange(Radiograph, "h w -> h w 1")
|
75 |
x = cfg_crop.val_transforms(image=x0)["image"]
|
76 |
x = torch.from_numpy(x)
|
|
|
115 |
closest1 = convert_bone_age_to_string(closest1)
|
116 |
closest2 = convert_bone_age_to_string(closest2)
|
117 |
|
118 |
+
if Heatmap:
|
119 |
+
targets = [ClassifierOutputTarget(round(bone_age))]
|
120 |
+
with GradCAM(model=model_grad_cam, target_layers=target_layers) as cam:
|
121 |
+
grayscale_cam = cam(input_tensor=x.to(device).float(), targets=targets, eigen_smooth=True)
|
122 |
+
|
123 |
+
heatmap = cv2.applyColorMap((grayscale_cam[0] * 255).astype("uint8"), cv2.COLORMAP_JET)
|
124 |
+
image = cv2.cvtColor(x[0, 0].cpu().numpy().astype("uint8"), cv2.COLOR_GRAY2RGB)
|
125 |
+
image_weight = 0.6
|
126 |
+
grad_cam_image = (1 - image_weight) * heatmap[..., ::-1] + image_weight * image
|
127 |
+
grad_cam_image = grad_cam_image.astype("uint8")
|
128 |
+
else:
|
129 |
+
# if no heatmap desired, just show image
|
130 |
+
grad_cam_image = cv2.cvtColor(x[0, 0].cpu().numpy().astype("uint8"), cv2.COLOR_GRAY2RGB)
|
131 |
|
132 |
return f"Predicted bone age: {bone_age_str}\n\nThe closest Greulich & Pyle bone ages are:\n 1) {closest1}\n 2) {closest2}", grad_cam_image
|
133 |
|
134 |
|
135 |
image = gr.Image(image_mode="L")
|
136 |
sex = gr.Radio(["Male", "Female"], type="index")
|
137 |
+
generate_heatmap = gr.Radio(["No", "Yes"], type="index")
|
138 |
textbox = gr.Textbox(show_label=True, label="Result")
|
139 |
+
grad_cam_image = gr.Image(image_mode="RGB", label="Heatmap / Image")
|
140 |
|
141 |
with gr.Blocks() as demo:
|
142 |
gr.Markdown(
|
|
|
149 |
The model achieves a mean absolute error of 4.26 months on the original test set comprising 200 multi-annotated hand radiographs,
|
150 |
which is competitive with [top solutions](https://pubs.rsna.org/doi/10.1148/radiol.2018180736) from the original challenge.
|
151 |
|
152 |
+
There is also an option to output a heatmap over the radiograph to show regions where the model is focusing on
|
153 |
+
to make its prediction. However, this takes extra computation and will increase the runtime.
|
154 |
+
|
155 |
This model is for demonstration purposes only and has NOT been approved by any regulatory agency for clinical use. The user assumes
|
156 |
any and all responsibility regarding their own use of this model and its outputs. Do NOT upload any images containing protected
|
157 |
health information, as this demonstration is not compliant with patient privacy laws.
|
|
|
163 |
)
|
164 |
gr.Interface(
|
165 |
fn=predict_bone_age,
|
166 |
+
inputs=[image, sex, generate_heatmap],
|
167 |
outputs=[textbox, grad_cam_image],
|
168 |
examples=[
|
169 |
+
["examples/2639.png", "Female", "Yes"],
|
170 |
+
["examples/10043.png", "Female", "No"],
|
171 |
+
["examples/8888.png", "Female", "Yes"],
|
172 |
],
|
173 |
+
cache_examples=False
|
174 |
)
|
175 |
|
176 |
if __name__ == "__main__":
|
skp/__pycache__/utils.cpython-312.pyc
CHANGED
Binary files a/skp/__pycache__/utils.cpython-312.pyc and b/skp/__pycache__/utils.cpython-312.pyc differ
|
|
skp/configs/__pycache__/__init__.cpython-312.pyc
CHANGED
Binary files a/skp/configs/__pycache__/__init__.cpython-312.pyc and b/skp/configs/__pycache__/__init__.cpython-312.pyc differ
|
|
skp/configs/__pycache__/base.cpython-312.pyc
CHANGED
Binary files a/skp/configs/__pycache__/base.cpython-312.pyc and b/skp/configs/__pycache__/base.cpython-312.pyc differ
|
|
skp/configs/boneage/__pycache__/cfg_crop_simple_resize.cpython-312.pyc
CHANGED
Binary files a/skp/configs/boneage/__pycache__/cfg_crop_simple_resize.cpython-312.pyc and b/skp/configs/boneage/__pycache__/cfg_crop_simple_resize.cpython-312.pyc differ
|
|
skp/configs/boneage/__pycache__/cfg_female_channel_reg_cls_match_hist.cpython-312.pyc
CHANGED
Binary files a/skp/configs/boneage/__pycache__/cfg_female_channel_reg_cls_match_hist.cpython-312.pyc and b/skp/configs/boneage/__pycache__/cfg_female_channel_reg_cls_match_hist.cpython-312.pyc differ
|
|
skp/models/__pycache__/modules.cpython-312.pyc
CHANGED
Binary files a/skp/models/__pycache__/modules.cpython-312.pyc and b/skp/models/__pycache__/modules.cpython-312.pyc differ
|
|
skp/models/__pycache__/pooling.cpython-312.pyc
CHANGED
Binary files a/skp/models/__pycache__/pooling.cpython-312.pyc and b/skp/models/__pycache__/pooling.cpython-312.pyc differ
|
|
skp/models/classification/__pycache__/net2d.cpython-312.pyc
CHANGED
Binary files a/skp/models/classification/__pycache__/net2d.cpython-312.pyc and b/skp/models/classification/__pycache__/net2d.cpython-312.pyc differ
|
|
skp/models/classification/__pycache__/net2d_multihead.cpython-312.pyc
CHANGED
Binary files a/skp/models/classification/__pycache__/net2d_multihead.cpython-312.pyc and b/skp/models/classification/__pycache__/net2d_multihead.cpython-312.pyc differ
|
|