Seeed-Studio / ModelAssistant

Seeed SenseCraft Model Assistant is an open-source project focused on embedded AI. 🔥🔥🔥
https://sensecraftma.seeed.cc/
377 stars 45 forks source link

export.py里面的export_pnnx函数import不了pnnx.wrapper #287

Open WilliamGwok opened 2 weeks ago

WilliamGwok commented 2 weeks ago

def export_pnnx(args, model): import os.path as osp import sys

import pnnx
from pnnx.wrapper import convert_inputshape_to_cmd

无法找到正确的pnnx版本

WilliamGwok commented 2 weeks ago

用的是2.0.0版本的model assistant

baorepo commented 1 week ago
@baorepo ➜ /workspaces/ModelAssistant (2.0.0) $ git diff 
diff --git a/tools/export.py b/tools/export.py
index bf22eff..1673021 100644
--- a/tools/export.py
+++ b/tools/export.py
@@ -286,12 +286,28 @@ def get_exported_file_name_from_precision(args, precision, ext: str = '') -> str
     )

+def convert_inputshape_to_cmd(input_shape):
+    """
+    Converts the input shape to a command-line argument string for pnnx.
+
+    Args:
+        input_shape (torch.Size or list): The input shape of the model.
+
+    Returns:
+        str: A command-line argument string representing the input shape.
+    """
+    if not isinstance(input_shape, (list, tuple)):
+        raise ValueError("Input shape must be a list or tuple")
+
+    cmd = "inputshape=" + ",".join(map(str, input_shape))
+    return cmd
+
+
 def export_pnnx(args, model):
     import os.path as osp
     import sys

     import pnnx
-    from pnnx.wrapper import convert_inputshape_to_cmd

     model.eval()
     pnnx_bin_path = osp.join(osp.dirname(pnnx.__file__), 'bin')

@WilliamGwok 试一下