tumuyan2 commited on
Commit
6b67881
·
1 Parent(s): 72c8c5e
Files changed (2) hide show
  1. app.py +27 -27
  2. pth2onnx.py +1 -1
app.py CHANGED
@@ -154,33 +154,33 @@ async def _process_model(model_input: Union[str, gr.File], tilesize: int, output
154
 
155
  with gr.Blocks() as demo:
156
  gr.Markdown("# 模型转换工具")
157
- # with gr.Row():
158
- with gr.Column():
159
- input_type = gr.Radio(['模型链接', '上传模型文件'], label='输入类型')
160
- url_input = gr.Textbox(label='模型链接')
161
- file_input = gr.File(label='上传模型文件', visible=False)
162
 
163
-
164
- def show_input(input_type):
165
- if input_type == '模型链接':
166
- return gr.update(visible=True), gr.update(visible=False)
167
- else:
168
- return gr.update(visible=False), gr.update(visible=True)
169
-
170
- input_type.change(show_input, inputs=input_type, outputs=[url_input, file_input])
171
-
172
- tilesize = gr.Number(label="Tilesize", value=0, precision=0)
173
- # 添加fp16和try_run复选框
174
- fp16 = gr.Checkbox(label="FP16", value=False)
175
- try_run = gr.Checkbox(label="测试mnn推理", value=False)
176
- convert_btn = gr.Button("开始转换")
177
- with gr.Column():
178
- log_box = gr.Textbox(label="转换日志", lines=10, interactive=False)
179
- # with gr.Row():
180
- onnx_output = gr.File(label="ONNX 模型输出")
181
- mnn_output = gr.File(label="MNN 模型输出")
182
-
183
- async def process_model(input_type, url_input, file_input, tilesize, fp16, try_run, log_box):
184
  global task_counter
185
  task_counter += 1
186
  output_dir = os.path.join(os.getcwd(), f"output_{task_counter}")
@@ -225,7 +225,7 @@ with gr.Blocks() as demo:
225
 
226
  convert_btn.click(
227
  process_model,
228
- inputs=[input_type, url_input, file_input, tilesize, log_box],
229
  outputs=[onnx_output, mnn_output, log_box],
230
  api_name="convert_model"
231
  )
 
154
 
155
  with gr.Blocks() as demo:
156
  gr.Markdown("# 模型转换工具")
157
+ with gr.Row():
158
+ with gr.Column():
159
+ input_type = gr.Radio(['模型链接', '上传模型文件'], label='输入类型')
160
+ url_input = gr.Textbox(label='模型链接')
161
+ file_input = gr.File(label='上传模型文件', visible=False)
162
 
163
+
164
+ def show_input(input_type):
165
+ if input_type == '模型链接':
166
+ return gr.update(visible=True), gr.update(visible=False)
167
+ else:
168
+ return gr.update(visible=False), gr.update(visible=True)
169
+
170
+ input_type.change(show_input, inputs=input_type, outputs=[url_input, file_input])
171
+
172
+ tilesize = gr.Number(label="Tilesize", value=0, precision=0)
173
+ # 添加fp16和try_run复选框
174
+ fp16 = gr.Checkbox(label="FP16", value=False)
175
+ try_run = gr.Checkbox(label="测试mnn推理", value=False)
176
+ convert_btn = gr.Button("开始转换")
177
+ with gr.Column():
178
+ # with gr.Row():
179
+ log_box = gr.Textbox(label="转换日志", lines=10, interactive=False)
180
+ onnx_output = gr.File(label="ONNX 模型输出")
181
+ mnn_output = gr.File(label="MNN 模型输出")
182
+
183
+ async def process_model(input_type, url_input, file_input, tilesize, fp16, try_run):
184
  global task_counter
185
  task_counter += 1
186
  output_dir = os.path.join(os.getcwd(), f"output_{task_counter}")
 
225
 
226
  convert_btn.click(
227
  process_model,
228
+ inputs=[input_type, url_input, file_input, tilesize, fp16, try_run],
229
  outputs=[onnx_output, mnn_output, log_box],
230
  api_name="convert_model"
231
  )
pth2onnx.py CHANGED
@@ -73,7 +73,7 @@ def convert_pth_to_onnx(pth_path: str, onnx_path: str=None, channel:int=0, tiles
73
  print(f'文件名 {filename} 包含匹配模式。')
74
  else:
75
  base_path = f"{base_path}-x{scale}"
76
-
77
  onnx_path = base_path + ("-Grayscale" if channel==1 else "") + ("-fp16.onnx" if use_fp16 else ".onnx")
78
 
79
  # 处理相对路径情况
 
73
  print(f'文件名 {filename} 包含匹配模式。')
74
  else:
75
  base_path = f"{base_path}-x{scale}"
76
+ print("final use_fp16", str(use_fp16) )
77
  onnx_path = base_path + ("-Grayscale" if channel==1 else "") + ("-fp16.onnx" if use_fp16 else ".onnx")
78
 
79
  # 处理相对路径情况