|
@@ -1,5 +1,6 @@
|
|
from flask import Flask, jsonify, request
|
|
from flask import Flask, jsonify, request
|
|
-
|
|
|
|
|
|
+import subprocess
|
|
|
|
+import os
|
|
from watermark_verify.exceptions import BusinessException
|
|
from watermark_verify.exceptions import BusinessException
|
|
from watermark_verify import verify_tool_mix
|
|
from watermark_verify import verify_tool_mix
|
|
|
|
|
|
@@ -24,5 +25,43 @@ def create_app():
|
|
result = verify_tool_mix.label_verification(model_filename=model_filename, framework=framework, mode=mode, model_type=model_type)
|
|
result = verify_tool_mix.label_verification(model_filename=model_filename, framework=framework, mode=mode, model_type=model_type)
|
|
print(f"模型水印检测结果: {result}")
|
|
print(f"模型水印检测结果: {result}")
|
|
return jsonify({"result": result})
|
|
return jsonify({"result": result})
|
|
|
|
+
|
|
|
|
+ @app.route("/verify_tool_accuracy_test", methods=['POST'])
|
|
|
|
+ def verify_tool_accuracy():
|
|
|
|
+ """
|
|
|
|
+ 在接口中执行模型水印验证脚本。
|
|
|
|
+
|
|
|
|
+ 参数:
|
|
|
|
+ base_path: 根路径(替代 $BASE_PATH)
|
|
|
|
+
|
|
|
|
+ 返回:
|
|
|
|
+ dict,包含返回码、stdout、stderr
|
|
|
|
+ """
|
|
|
|
+ data = request.json
|
|
|
|
+ base_path = data.get('base_path')
|
|
|
|
+
|
|
|
|
+ script_path = os.path.join(base_path, "code/model_watermark_detect/tests/verify_tool_accuracy_test.py")
|
|
|
|
+ target_dir = os.path.join(base_path, "checkpoints/pytorch-yolox-blackbox/onnx")
|
|
|
|
+ env = os.environ.copy()
|
|
|
|
+ env["PYTHONPATH"] = os.path.join(base_path, "code/model_watermark_detect")
|
|
|
|
+
|
|
|
|
+ cmd = [
|
|
|
|
+ "python",
|
|
|
|
+ script_path,
|
|
|
|
+ "--target_dir", target_dir,
|
|
|
|
+ "--except_result", "True",
|
|
|
|
+ "--framework", "pytorch",
|
|
|
|
+ "--mode", "blackbox",
|
|
|
|
+ "--model_type", "yolox"
|
|
|
|
+ ]
|
|
|
|
+
|
|
|
|
+ print("[INFO] 正在执行命令:", " ".join(cmd))
|
|
|
|
+
|
|
|
|
+ result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8", env=env)
|
|
|
|
+ return jsonify({
|
|
|
|
+ "returncode": result.returncode,
|
|
|
|
+ "stdout": result.stdout,
|
|
|
|
+ "stderr": result.stderr
|
|
|
|
+ })
|
|
|
|
|
|
return app
|
|
return app
|