Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,27 @@
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
-
import
|
4 |
-
from matplotlib import pyplot as plt
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
|
7 |
-
def create_model_for_provider(model_path, provider="CPUExecutionProvider"):
|
8 |
-
options = ort.SessionOptions()
|
9 |
-
options.intra_op_num_threads = 1
|
10 |
-
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
|
11 |
-
session = ort.InferenceSession(str(model_path), options, providers=[provider])
|
12 |
-
session.disable_fallback()
|
13 |
-
return session
|
14 |
-
|
15 |
def inference(repo_id, model_name, img):
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
-
|
24 |
|
25 |
-
return
|
|
|
26 |
|
27 |
title="deepflash2"
|
28 |
description='deepflash2 is a deep-learning pipeline for the segmentation of ambiguous microscopic images.\n deepflash2 uses deep model ensembles to achieve more accurate and reliable results. Thus, inference time will be more than a minute in this space.'
|
29 |
-
examples=[['matjesg/deepflash2_demo', '
|
30 |
-
['matjesg/deepflash2_demo', '
|
31 |
]
|
32 |
|
33 |
gr.Interface(inference,
|
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
+
import torch
|
|
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def inference(repo_id, model_name, img):
|
7 |
+
#model_path = hf_hub_download(repo_id=repo_id, filename=model_name)
|
8 |
+
model_path = 'trained_models/cFOS_in_HC/cFOS_in_HC_ensemble_1.pt'
|
9 |
+
model = torch.jit.load(model_path, map_location='cpu')
|
10 |
+
n_channels = len(model.norm.mean)
|
11 |
|
12 |
+
# Remove redundant channels
|
13 |
+
img = img[...,:n_channels]
|
14 |
+
inp = torch.from_numpy(img).float()
|
15 |
|
16 |
+
argmax, softmax, stdeviation = model(inp)
|
17 |
|
18 |
+
return argmax*255, stdeviation
|
19 |
+
|
20 |
|
21 |
title="deepflash2"
|
22 |
description='deepflash2 is a deep-learning pipeline for the segmentation of ambiguous microscopic images.\n deepflash2 uses deep model ensembles to achieve more accurate and reliable results. Thus, inference time will be more than a minute in this space.'
|
23 |
+
examples=[['matjesg/deepflash2_demo', 'cFOS_in_HC_ensemble.pt', 'cFOS_example.png'],
|
24 |
+
['matjesg/deepflash2_demo', 'YFP_in_CTX_ensemble.pt', 'YFP_example.png']
|
25 |
]
|
26 |
|
27 |
gr.Interface(inference,
|