Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Exception: Must have input rank for 165 in order to convert axis for NHWC op

Discussion in 'Barracuda' started by KirinBlue, Mar 3, 2022.

  1. KirinBlue

    KirinBlue

    Joined:
    Apr 14, 2019
    Posts:
    1
    Hi, I encounter this problem when I try to import a custom trained yolov3-tiny model into Unity.
    I am using Barracuda 2.4.0
    and the model is convert into onnx from pytorch file(.pth)

    Exception: Must have input rank for 165 in order to convert axis for NHWC op
    Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.ConvertAxis (Unity.Barracuda.Layer layer, Unity.Barracuda.ModelBuilder net) (at Library/PackageCache/com.unity.barracuda@b1eac6c34b/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWC/RewriterNCHWToNHWC.cs:467)
    Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.Rewrite (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@b1eac6c34b/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWCPass.cs:139)
    Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.Run (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@b1eac6c34b/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWCPass.cs:39)
    Unity.Barracuda.Compiler.Passes.IntermediateToRunnableNHWCPass.Run (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@b1eac6c34b/Barracuda/Runtime/Core/Compiler/Passes/IntermediateToRunnableNHWCPass.cs:38)
    Unity.Barracuda.ONNX.ONNXModelConverter.Convert (Google.Protobuf.CodedInputStream inputStream) (at Library/PackageCache/com.unity.barracuda@b1eac6c34b/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:188)
    Unity.Barracuda.ONNX.ONNXModelConverter.Convert (System.String filePath) (at Library/PackageCache/com.unity.barracuda@b1eac6c34b/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:98)
    Unity.Barracuda.ONNXModelImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at Library/PackageCache/com.unity.barracuda@b1eac6c34b/Barracuda/Editor/ONNXModelImporter.cs:65)
    UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at <55729f52d042492e9efc384182ae2feb>:0)
    UnityEditorInternal.InternalEditorUtility:projectWindowDrag(HierarchyProperty, Boolean)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)

    If anybody can give me any suggestion on how to fix it, that would be great.

    Thanks in advance.
     

    Attached Files:

    TriceHelix likes this.
  2. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    Bumping this.
    I am having the same issue with another NN and have tried using different opset versions, with no avail.
     
  3. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    Update: I have found the issue, but it could be a bug on Barracuda's side.

    The asset import error disappeared after exporting the ONNX model without the dynamic_axes parameter in PyTorch's
    torch.onnx.export()
    function. The model works perfectly fine with constant size inputs (the ones sepcified while exporting). That's confusing, considering the Barracuda docs clearly state that dynamic input sizes and shapes are supported.
    Maybe it's a bug on Barracuda's side?
     
  4. alexandreribard_unity

    alexandreribard_unity

    Unity Technologies

    Joined:
    Sep 18, 2019
    Posts:
    53
    We are more robust with constant input size. Dynamic input sizes are supported, but can cause some problems for us right now. But we are working on making that more flexible.
    So it is probably a bug on our side. I'd recommend sticking to fixed input size for now until we release the dynamic shape handling improvements
     
  5. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    Thanks for the quick reply!
    Definitely looking forward to those improvements since my trained model is specifically made with flexible input size in mind, so getting to use that would be sweet.
     
  6. wechat_os_Qy0-kMueajtZ0r9IGpirFtgEg

    wechat_os_Qy0-kMueajtZ0r9IGpirFtgEg

    Joined:
    Sep 26, 2021
    Posts:
    1
    I am using a Barracuda 3.0.0 and I encounter the same problem when I try to import a custom model into Unity.

    Exception: Must have input rank for 169 in order to convert Reshape to NHWC
    Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.<InstantiateRewriterNCHWToNHWC>b__4_0 (Unity.Barracuda.Layer layer, Unity.Barracuda.ModelBuilder net) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWC/RewriterNCHWToNHWC.cs:80)
    Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.Rewrite (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWCPass.cs:139)
    Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.Run (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWCPass.cs:39)
    Unity.Barracuda.Compiler.Passes.IntermediateToRunnableNHWCPass.Run (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Runtime/Core/Compiler/Passes/IntermediateToRunnableNHWCPass.cs:38)
    Unity.Barracuda.ONNX.ONNXModelConverter.Convert (Google.Protobuf.CodedInputStream inputStream) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:188)
    Unity.Barracuda.ONNX.ONNXModelConverter.Convert (System.String filePath) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:98)
    Unity.Barracuda.ONNXModelImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Editor/ONNXModelImporter.cs:65)
    UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at <5456dbfeccf644f7ab5b4d4a01ccf33e>:0)
    UnityEditorInternal.InternalEditorUtility:projectWindowDrag(HierarchyProperty, Boolean)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

    My input size is fixed,that is (1,2121), but the net include some operators about shape in Transformer. I found that if the tensors don't go through the attention layer,the import process of onnx file is ok. How to figure out this issue?
    upload_2023-10-9_17-35-25.png
     
  7. liutaurasvysniauskas_unity

    liutaurasvysniauskas_unity

    Unity Technologies

    Joined:
    Jun 14, 2022
    Posts:
    16
    Hi,

    I recommend testing this with the Sentis package, as it's a newer version of Barracuda and there's a high chance that the issue is already fixed there.

    If you still manage to reproduce the issue with Sentis, please write about it in the Discussion forum Sentis category and we will investigate it further.

    More about Sentis: https://discussions.unity.com/t/about-sentis-beta/260899