Joker1212 commited on
Commit
3fe2685
·
1 Parent(s): 0b86350

feat: add models

Browse files

(cherry picked from commit 539fb282fd3e9e4030fc4bd3e867ba730702deec)

Files changed (4) hide show
  1. app.py +31 -9
  2. config.yaml +38 -0
  3. images/demo.jpg +0 -0
  4. requirements.txt +1 -1
app.py CHANGED
@@ -1,11 +1,12 @@
1
  import gradio as gr
 
2
  from rapid_unwrap.inference import DocUnwrapper
3
-
4
  # 初始化模型
5
- model_path = "models/uvdoc.onnx"
6
- doc_unwrapper = DocUnwrapper(model_path=model_path)
7
  # 添加示例
8
  example_images = [
 
9
  "images/demo1.jpg",
10
  "images/demo1.png",
11
  "images/demo2.png",
@@ -14,10 +15,25 @@ example_images = [
14
  ]
15
 
16
 
17
- def process_image(img_path):
18
- unwrapped_img, elapse = doc_unwrapper(img_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  print(f"doc unwrap elapse: {elapse}")
20
- return unwrapped_img
21
 
22
 
23
  def main():
@@ -37,7 +53,7 @@ def main():
37
  }
38
  """) as demo:
39
  gr.HTML(
40
- "<h1 style='text-align: center;'><a href='https://github.com/Joker1212/RapidUnWrap'>RapidUnWrap</a></h1>"
41
  )
42
  gr.HTML('''
43
  <div class="header-links">
@@ -60,12 +76,18 @@ def main():
60
  outputs=img_input,
61
  cache_examples=False
62
  )
 
 
 
 
 
63
  run_button = gr.Button("summit")
 
64
  with gr.Column(scale=2): # 右边占2/3
65
  output_image = gr.Image(label="output")
66
-
67
  # 绑定按钮点击事件
68
- run_button.click(fn=process_image, inputs=img_input, outputs=output_image)
69
 
70
  # 启动应用
71
  demo.launch()
 
1
  import gradio as gr
2
+ from rapid_undistorted.inference import InferenceEngine
3
  from rapid_unwrap.inference import DocUnwrapper
4
+ import numpy as np
5
  # 初始化模型
6
+ engine = InferenceEngine()
 
7
  # 添加示例
8
  example_images = [
9
+ "images/demo.jpg",
10
  "images/demo1.jpg",
11
  "images/demo1.png",
12
  "images/demo2.png",
 
15
  ]
16
 
17
 
18
+ # 定义任务和模型选项
19
+ tasks = {
20
+ "unwrap": ["UVDoc", None],
21
+ "unshadow": ["GCDnet", None],
22
+ "unblur": ["OpenCvBilateral", "NAFDPM", None]
23
+ }
24
+
25
+ def process_image(img_path, unwrap_model, unshadow_model, unblur_model):
26
+ task_list = []
27
+ if unwrap_model:
28
+ task_list.append(("unwrap", unwrap_model))
29
+ if unshadow_model:
30
+ task_list.append(("unshadow", unshadow_model))
31
+ if unblur_model:
32
+ task_list.append(("unblur", unblur_model))
33
+
34
+ unwrapped_img, elapse = engine(img_path, task_list)
35
  print(f"doc unwrap elapse: {elapse}")
36
+ return unwrapped_img.astype(np.uint8),elapse
37
 
38
 
39
  def main():
 
53
  }
54
  """) as demo:
55
  gr.HTML(
56
+ "<h1 style='text-align: center;'><a href='https://github.com/Joker1212/RapidUnWrap'>RapidUnDistort</a></h1>"
57
  )
58
  gr.HTML('''
59
  <div class="header-links">
 
76
  outputs=img_input,
77
  cache_examples=False
78
  )
79
+
80
+ unwrap_dropdown = gr.Dropdown(label="Select Unwrap Model", choices=tasks["unwrap"], value="UVDoc")
81
+ unshadow_dropdown = gr.Dropdown(label="Select Unshadow Model", choices=tasks["unshadow"], value="GCDnet")
82
+ unblur_dropdown = gr.Dropdown(label="Select Unblur Model", choices=tasks["unblur"], value="OpenCvBilateral")
83
+
84
  run_button = gr.Button("summit")
85
+
86
  with gr.Column(scale=2): # 右边占2/3
87
  output_image = gr.Image(label="output")
88
+ elapse_textbox = gr.Textbox(label="Elapsed Time", interactive=False)
89
  # 绑定按钮点击事件
90
+ run_button.click(fn=process_image, inputs=[img_input, unwrap_dropdown, unshadow_dropdown, unblur_dropdown],outputs=[output_image, elapse_textbox])
91
 
92
  # 启动应用
93
  demo.launch()
config.yaml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tasks:
2
+ unwrap:
3
+ models:
4
+ - type: "UVDoc"
5
+ path: "models/uvdoc.onnx"
6
+ use_cuda: false
7
+ use_dml: false
8
+
9
+ unshadow:
10
+ models:
11
+ - type: "GCDnet"
12
+ sub_models:
13
+ - type: "GCDnet"
14
+ path: "models/gcnet.onnx"
15
+ use_cuda: false
16
+ use_dml: false
17
+ - type: "DRnet"
18
+ path: "models/drnet.onnx"
19
+ use_cuda: false
20
+ use_dml: false
21
+
22
+ binarize:
23
+ models:
24
+ - type: "UnetCnn"
25
+ path: "models/unetcnn.onnx"
26
+ use_cuda: false
27
+ use_dml: false
28
+
29
+ unblur:
30
+ models:
31
+ - type: "OpenCvBilateral"
32
+ path:
33
+ - type: "NAFDPM"
34
+ path: "models/nafdpm.onnx"
35
+ use_cuda: false
36
+ use_dml: false
37
+
38
+
images/demo.jpg ADDED
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- rapid_unwrap
2
  gradio
 
1
+ rapid-undistorted
2
  gradio