Spaces:
Runtime error
Runtime error
Added working model!
Browse files- DummyModel.py +1 -1
- Model.py +11 -4
- app.py +9 -3
- backend.py +6 -2
- requirements.txt +5 -3
DummyModel.py
CHANGED
@@ -16,7 +16,7 @@ class DummyModel(torch.nn.Module):
|
|
16 |
super().__init__()
|
17 |
|
18 |
def forward(self, x:list):
|
19 |
-
return torch.softmax(torch.rand(len(x), 5), 1)
|
20 |
|
21 |
def __call__(self, x:list):
|
22 |
return self.forward(x)
|
|
|
16 |
super().__init__()
|
17 |
|
18 |
def forward(self, x:list):
|
19 |
+
return torch.softmax(torch.rand(len(x), 5), 1), 0
|
20 |
|
21 |
def __call__(self, x:list):
|
22 |
return self.forward(x)
|
Model.py
CHANGED
@@ -1,13 +1,20 @@
|
|
|
|
1 |
from nail_classification.inference import Inference
|
2 |
|
3 |
|
4 |
class Model:
|
5 |
-
def __init__(self):
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
self.inference = Inference(file_paths)
|
9 |
|
10 |
-
|
11 |
def predict(self, x):
|
12 |
y_hat, uncertainty = self.inference.predict(x)
|
13 |
return y_hat, uncertainty
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
from nail_classification.inference import Inference
|
3 |
|
4 |
|
5 |
class Model:
|
6 |
+
def __init__(self, DEBUG):
|
7 |
+
if DEBUG:
|
8 |
+
base = r"C:\Users\follels\Documents\hand-ki-model-weights\DeepNAPSIModel\inference_checkpoints_v1"
|
9 |
+
file_paths = [os.path.join(base, f"version_{v}") for v in range(10, 15)]
|
10 |
+
else:
|
11 |
+
file_paths = [hf_hub_download("lfolle/DeepNAPSIModel", f"version_{v}.ckpt",
|
12 |
+
use_auth_token=os.environ['DeepNAPSIModel']) for v in [10, 11, 12, 13, 14]]
|
13 |
self.inference = Inference(file_paths)
|
14 |
|
|
|
15 |
def predict(self, x):
|
16 |
y_hat, uncertainty = self.inference.predict(x)
|
17 |
return y_hat, uncertainty
|
18 |
+
|
19 |
+
def __call__(self, x):
|
20 |
+
return self.predict(x)
|
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
from backend import Infer
|
4 |
|
@@ -6,11 +7,16 @@ DEBUG = True
|
|
6 |
|
7 |
infer = Infer(DEBUG)
|
8 |
|
9 |
-
|
|
|
10 |
with gr.Column():
|
11 |
-
gr.Markdown("
|
|
|
|
|
12 |
with gr.Column():
|
13 |
-
|
|
|
|
|
14 |
with gr.Row():
|
15 |
image_button = gr.Button("Predict NAPSI")
|
16 |
outputs = []
|
|
|
1 |
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
|
4 |
from backend import Infer
|
5 |
|
|
|
7 |
|
8 |
infer = Infer(DEBUG)
|
9 |
|
10 |
+
|
11 |
+
with gr.Blocks(analytics_enabled=False, title="DeepNAPSI") as demo:
|
12 |
with gr.Column():
|
13 |
+
gr.Markdown("## Welcome to the DeepNAPSI application!")
|
14 |
+
gr.Markdown("Upload an image of the one hand and click **Predict NAPSI** to see the output.\n" \
|
15 |
+
"> Note: Make sure there are no identifying information present in the image. The prediction can take up to 1 minute.")
|
16 |
with gr.Column():
|
17 |
+
with gr.Row():
|
18 |
+
image_input = gr.Image()
|
19 |
+
example_images = gr.Examples(["assets/example_1.jpg", "assets/example_2.jpg", "assets/example_3.jpg"], image_input)
|
20 |
with gr.Row():
|
21 |
image_button = gr.Button("Predict NAPSI")
|
22 |
outputs = []
|
backend.py
CHANGED
@@ -5,11 +5,13 @@ from huggingface_hub import hf_hub_download
|
|
5 |
from nail_detection.main import get_nails
|
6 |
|
7 |
from DummyModel import load_dummy_model
|
|
|
8 |
|
9 |
|
10 |
class Infer():
|
11 |
def __init__(self, DEBUG):
|
12 |
-
self.model = load_dummy_model(DEBUG)
|
|
|
13 |
|
14 |
def predict(self, data):
|
15 |
nails = get_nails(cv2.cvtColor(data, cv2.COLOR_RGB2BGR))
|
@@ -20,7 +22,9 @@ class Infer():
|
|
20 |
predictions.append(np.zeros((64, 64, 3)))
|
21 |
predictions.append(-1)
|
22 |
else:
|
23 |
-
|
|
|
|
|
24 |
napsi_sum = int(napsi_predictions.sum().detach().cpu())
|
25 |
predictions.append(napsi_sum)
|
26 |
for napsi_prediction, nail in zip(napsi_predictions, nails):
|
|
|
5 |
from nail_detection.main import get_nails
|
6 |
|
7 |
from DummyModel import load_dummy_model
|
8 |
+
from Model import Model
|
9 |
|
10 |
|
11 |
class Infer():
|
12 |
def __init__(self, DEBUG):
|
13 |
+
# self.model = load_dummy_model(DEBUG)
|
14 |
+
self.model = Model(DEBUG)
|
15 |
|
16 |
def predict(self, data):
|
17 |
nails = get_nails(cv2.cvtColor(data, cv2.COLOR_RGB2BGR))
|
|
|
22 |
predictions.append(np.zeros((64, 64, 3)))
|
23 |
predictions.append(-1)
|
24 |
else:
|
25 |
+
model_prediction, uncertainty = self.model(nails)
|
26 |
+
model_prediction = model_prediction[0]
|
27 |
+
napsi_predictions = torch.argmax(model_prediction, 1)
|
28 |
napsi_sum = int(napsi_predictions.sum().detach().cpu())
|
29 |
predictions.append(napsi_sum)
|
30 |
for napsi_prediction, nail in zip(napsi_predictions, nails):
|
requirements.txt
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
-
|
2 |
numpy
|
3 |
-
git+https://
|
4 |
gradio
|
5 |
huggingface_hub
|
6 |
-
|
|
|
|
|
|
1 |
+
opencv-python
|
2 |
numpy
|
3 |
+
git+https://git5.cs.fau.de/folle/hand-ki-model.git
|
4 |
gradio
|
5 |
huggingface_hub
|
6 |
+
--extra-index-url https://download.pytorch.org/whl/cu116
|
7 |
+
torch
|
8 |
+
torchvision
|