Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ import torch.autograd as autograd
|
|
11 |
import numpy as np
|
12 |
import os
|
13 |
from datetime import datetime
|
14 |
-
|
15 |
def creatMask(Image, threshold=5):
|
16 |
##This program try to creat the mask for the filed-of-view
|
17 |
##Input original image (RGB or green channel), threshold (user set parameter, default 10)
|
@@ -279,10 +279,9 @@ def GetResult_out_big(Net, k, use_cuda=False, dataset='', is_kill_border=False,
|
|
279 |
return ArteryPred, VeinPred, VesselPred, Mask, ArteryPred, VeinPred, VesselPred,
|
280 |
|
281 |
|
282 |
-
def out_test(cfg, output_dir='', evaluate_metrics=False, img_name='out_test'):
|
283 |
device = torch.device("cuda" if cfg.use_cuda else "cpu")
|
284 |
-
|
285 |
-
model_path = os.path.join(model_root, 'G_' + str(cfg.model_step_pretrained_G) + '.pkl')
|
286 |
net = torch.load(model_path, map_location=device)
|
287 |
|
288 |
image_color = modelEvalution_out_big(net,
|
@@ -298,6 +297,11 @@ def out_test(cfg, output_dir='', evaluate_metrics=False, img_name='out_test'):
|
|
298 |
def segment_by_out_test(image,model_name):
|
299 |
print("✅ 传到后端的模型名:", model_name)
|
300 |
|
|
|
|
|
|
|
|
|
|
|
301 |
cfg.set_dataset(model_name)
|
302 |
if image is None:
|
303 |
raise gr.Error("请上传一张图像(upload a fundus image)。")
|
@@ -306,7 +310,7 @@ def segment_by_out_test(image,model_name):
|
|
306 |
temp_path = f"./examples/tmp_upload_{timestamp}.png"
|
307 |
image.save(temp_path)
|
308 |
|
309 |
-
image_color = out_test(cfg, output_dir='', evaluate_metrics=False, img_name=temp_path)
|
310 |
return Image.fromarray(image_color)
|
311 |
|
312 |
def gradio_interface():
|
@@ -361,7 +365,7 @@ def gradio_interface():
|
|
361 |
label="示例图像",
|
362 |
examples_per_page=5
|
363 |
)
|
364 |
-
with gr.Accordion("📖
|
365 |
gr.Markdown(model_info_md)
|
366 |
|
367 |
# 功能连接
|
|
|
11 |
import numpy as np
|
12 |
import os
|
13 |
from datetime import datetime
|
14 |
+
from huggingface_hub import hf_hub_download
|
15 |
def creatMask(Image, threshold=5):
|
16 |
##This program try to creat the mask for the filed-of-view
|
17 |
##Input original image (RGB or green channel), threshold (user set parameter, default 10)
|
|
|
279 |
return ArteryPred, VeinPred, VesselPred, Mask, ArteryPred, VeinPred, VesselPred,
|
280 |
|
281 |
|
282 |
+
def out_test(cfg,model_path='', output_dir='', evaluate_metrics=False, img_name='out_test'):
|
283 |
device = torch.device("cuda" if cfg.use_cuda else "cpu")
|
284 |
+
model_path = model_path
|
|
|
285 |
net = torch.load(model_path, map_location=device)
|
286 |
|
287 |
image_color = modelEvalution_out_big(net,
|
|
|
297 |
def segment_by_out_test(image,model_name):
|
298 |
print("✅ 传到后端的模型名:", model_name)
|
299 |
|
300 |
+
model_path = hf_hub_download(
|
301 |
+
repo_id="weidai00/RIP-AV-sulab", # 模型库的名字
|
302 |
+
filename=f"G_{model_name}.pkl", # 文件名
|
303 |
+
repo_type="model" # 模型库必须写 repo_type
|
304 |
+
)
|
305 |
cfg.set_dataset(model_name)
|
306 |
if image is None:
|
307 |
raise gr.Error("请上传一张图像(upload a fundus image)。")
|
|
|
310 |
temp_path = f"./examples/tmp_upload_{timestamp}.png"
|
311 |
image.save(temp_path)
|
312 |
|
313 |
+
image_color = out_test(cfg,model_path=model_path, output_dir='', evaluate_metrics=False, img_name=temp_path)
|
314 |
return Image.fromarray(image_color)
|
315 |
|
316 |
def gradio_interface():
|
|
|
365 |
label="示例图像",
|
366 |
examples_per_page=5
|
367 |
)
|
368 |
+
with gr.Accordion("📖 模型说明-Description(点击展开)", open=False):
|
369 |
gr.Markdown(model_info_md)
|
370 |
|
371 |
# 功能连接
|