From 894665c48a4ddfdac41a1692b3afc13d10429a3e Mon Sep 17 00:00:00 2001 From: xujiao Date: Tue, 25 Nov 2025 20:22:51 +0800 Subject: [PATCH] refactor(netrans) --- README.md | 4 +++- script/netrans | 2 +- src/netrans/netrans.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 705511e..a011da4 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,8 @@ from netrans import Netrans # 定义模型路径,模型路径默认为工作路径。 model_path='~/app/netrans/examples/infer_with_pre_post_process/yolov8s' +import sys +model_path=sys.argv[1] # 初始化netrans net = Netrans() @@ -113,7 +115,7 @@ net.load(model_path, mean=[128,128,128] ,scale=[1,1,1] ) # 模型量化 net.quantize("asymu8", pre = False, post= False) # 前后处理添加进推理 -net.add_prepost_to_graph("asymu8") +net.add_pre_post("asymu8") # 模型导出 net.export("asymu8") ``` diff --git a/script/netrans b/script/netrans index 42c8451..cf27460 100755 --- a/script/netrans +++ b/script/netrans @@ -322,7 +322,7 @@ def handle_add_prepost(args): model = Netrans() # 使用Python API添加前后处理 - model.add_prepost_to_graph( + model.add_pre_post( args.quant_type, model_path=args.model_path, pre=pre, diff --git a/src/netrans/netrans.py b/src/netrans/netrans.py index 48d8f6a..3449e0a 100644 --- a/src/netrans/netrans.py +++ b/src/netrans/netrans.py @@ -225,7 +225,7 @@ class Netrans(): in_out_quantized, ) if pre or post : - self.add_prepost_to_graph(quantized, pre, post) + self.add_pre_post(quantized, pre, post) @_ensure_meta @chdir @@ -299,7 +299,7 @@ class Netrans(): @_ensure_meta @chdir - def add_prepost_to_graph(self, + def add_pre_post(self, quantized, *, model_path: Optional[str] = None,