tumuyan2 commited on
Commit
3ba1191
·
1 Parent(s): be653aa
Files changed (2) hide show
  1. .gitignore +3 -0
  2. app.py +31 -12
.gitignore CHANGED
@@ -4,3 +4,6 @@
4
  *.onnx
5
  *.param
6
  *.zip
 
 
 
 
4
  *.onnx
5
  *.param
6
  *.zip
7
+ *.mnn
8
+ *.onnx
9
+
app.py CHANGED
@@ -162,20 +162,35 @@ def start_process(input_file, input_url, input2, shape0_str, shape1_str, output_
162
  yield [], log
163
  output_base = output_folder + "/" + input2
164
  pt_path = output_base + ".pt"
 
165
  input_tensor0 = torch.rand(shape0) if any(shape0) else None
166
  input_tensor1 = torch.rand(shape1) if any(shape1) else None
167
- if "Fixed" in output_type and input_tensor0 is not None and input_tensor1 is not None:
168
  example_input = (input_tensor0, input_tensor1)
169
  # 修改此处,去除 shape 字符串中的空格
170
- command = f"pnnx {pt_path} inputshape={str(shape0).replace(' ', '')} inputshape2={str(shape1).replace(' ', '')}"
171
- elif "Fixed" in output_type and input_tensor0 is not None:
 
172
  example_input = input_tensor0
173
- command = f"pnnx {pt_path} inputshape={str(shape0).replace(' ', '')}"
 
174
  else:
175
  example_input = input_tensor1
176
  command = f"pnnx {pt_path}"
177
- print_log(task_id, input2, "生成输入张量", "完成")
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  # 确保 output_folder 存在
181
  if not os.path.exists(output_folder):
@@ -283,11 +298,13 @@ def start_process(input_file, input_url, input2, shape0_str, shape1_str, output_
283
  yield [], log
284
  returncode = process.poll()
285
  if returncode != 0:
 
286
  log += f"执行mnn命令失败,返回码: {returncode},命令: {mnn_command} \n"
287
  else:
288
  log += f"执行命令成功: {mnn_command} \n"
289
  except Exception as e:
290
  log += f"执行命令: {mnn_command} 失败,错误信息: {str(e)}\n"
 
291
 
292
  if "NCNN" in output_type:
293
  print_log(task_id, input2, "执行命令" + command, "开始")
@@ -310,10 +327,12 @@ def start_process(input_file, input_url, input2, shape0_str, shape1_str, output_
310
  returncode = process.poll()
311
  if returncode != 0:
312
  log += f"执行命令失败,返回码: {returncode},命令: {command} \n"
 
313
  else:
314
  log += f"执行命令成功: {command} \n"
315
  except Exception as e:
316
  log += f"执行命令: {command} 失败,错误信息: {str(e)}\n"
 
317
 
318
  # 查找 output_folder 目录下以 .ncnn.bin 和 .ncnn.param 结尾的文件
319
  bin_files = [f for f in os.listdir(output_folder) if f.endswith('.ncnn.bin')]
@@ -387,7 +406,7 @@ with gr.Blocks() as demo:
387
  # 绑定事件,修改输入参数
388
  process = start_button.click(
389
  fn=start_process,
390
- inputs=[input1_file, input1, input2, output_type, shape0_str, shape1_str,output_type],
391
  outputs=[output, log_textbox]
392
  )
393
  # 为取消按钮添加点击事件绑定,使用 cancels 属性取消 start_process 任务
@@ -405,11 +424,11 @@ with gr.Blocks() as demo:
405
  ["","https://github.com/Phhofm/models/releases/download/1xDeJPG/1xDeJPG_SRFormer_light.pth", "", "1,3,128,128", "0,0,0,0"],
406
  ["","https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-WTP-ColorDS.pth", "", "1,3,128,128", "0,0,0,0"],
407
  ]
408
- gr.Examples(
409
- examples=examples,
410
- inputs=[input1_file, input1, input2, shape0_str, shape1_str],
411
- outputs=[output, log_textbox],
412
- fn=start_process
413
- )
414
 
415
  demo.launch()
 
162
  yield [], log
163
  output_base = output_folder + "/" + input2
164
  pt_path = output_base + ".pt"
165
+ command = f"pnnx {pt_path}"
166
  input_tensor0 = torch.rand(shape0) if any(shape0) else None
167
  input_tensor1 = torch.rand(shape1) if any(shape1) else None
168
+ if input_tensor0 is not None and input_tensor1 is not None:
169
  example_input = (input_tensor0, input_tensor1)
170
  # 修改此处,去除 shape 字符串中的空格
171
+ if "Fixed" in output_type:
172
+ command = f"pnnx {pt_path} inputshape={str(shape0).replace(' ', '')} inputshape2={str(shape1).replace(' ', '')}"
173
+ elif input_tensor0 is not None:
174
  example_input = input_tensor0
175
+ if "Fixed" in output_type:
176
+ command = f"pnnx {pt_path} inputshape={str(shape0).replace(' ', '')}"
177
  else:
178
  example_input = input_tensor1
179
  command = f"pnnx {pt_path}"
 
180
 
181
+ input_tensor_str = ""
182
+ if input_tensor0 is not None:
183
+ input_tensor_str += str(input_tensor0.shape)
184
+ else:
185
+ input_tensor_str += "None"
186
+
187
+ if input_tensor1 is not None:
188
+ input_tensor_str += ", " + str(input_tensor1.shape)
189
+ else:
190
+ input_tensor_str += ", None"
191
+ print_log(task_id, input2, "生成输入张量"+input_tensor_str, "完成")
192
+ log +=input_tensor_str+ "\n"
193
+ yield [], log
194
 
195
  # 确保 output_folder 存在
196
  if not os.path.exists(output_folder):
 
298
  yield [], log
299
  returncode = process.poll()
300
  if returncode != 0:
301
+ print_log(task_id, input2, f"转换为MNN模型,返回码: {returncode},命令: {mnn_command} ", "失败")
302
  log += f"执行mnn命令失败,返回码: {returncode},命令: {mnn_command} \n"
303
  else:
304
  log += f"执行命令成功: {mnn_command} \n"
305
  except Exception as e:
306
  log += f"执行命令: {mnn_command} 失败,错误信息: {str(e)}\n"
307
+ print_log(task_id, input2, f"转换为MNN模型,错误信息: {str(e)}", "错误")
308
 
309
  if "NCNN" in output_type:
310
  print_log(task_id, input2, "执行命令" + command, "开始")
 
327
  returncode = process.poll()
328
  if returncode != 0:
329
  log += f"执行命令失败,返回码: {returncode},命令: {command} \n"
330
+ print_log(task_id, input2, f"返回码: {returncode},命令: {command} ", "失败")
331
  else:
332
  log += f"执行命令成功: {command} \n"
333
  except Exception as e:
334
  log += f"执行命令: {command} 失败,错误信息: {str(e)}\n"
335
+ print_log(task_id, input2, f"错误信息: {str(e)}", "错误")
336
 
337
  # 查找 output_folder 目录下以 .ncnn.bin 和 .ncnn.param 结尾的文件
338
  bin_files = [f for f in os.listdir(output_folder) if f.endswith('.ncnn.bin')]
 
406
  # 绑定事件,修改输入参数
407
  process = start_button.click(
408
  fn=start_process,
409
+ inputs=[input1_file, input1, input2, shape0_str, shape1_str, output_type],
410
  outputs=[output, log_textbox]
411
  )
412
  # 为取消按钮添加点击事件绑定,使用 cancels 属性取消 start_process 任务
 
424
  ["","https://github.com/Phhofm/models/releases/download/1xDeJPG/1xDeJPG_SRFormer_light.pth", "", "1,3,128,128", "0,0,0,0"],
425
  ["","https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-WTP-ColorDS.pth", "", "1,3,128,128", "0,0,0,0"],
426
  ]
427
+ # gr.Examples(
428
+ # examples=examples,
429
+ # inputs=[input1_file, input1, input2, shape0_str, shape1_str],
430
+ # outputs=[output, log_textbox],
431
+ # fn=start_process
432
+ # )
433
 
434
  demo.launch()