Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Onnx import failed - Cannot reshape array of size *** into shape of multiple of *** elements

Discussion in 'Barracuda' started by AlexisDelforges, Feb 18, 2022.

  1. AlexisDelforges

    AlexisDelforges

    Joined:
    Nov 30, 2021
    Posts:
    20
    Hello,

    We're trying to use Barracuda with some Onnx files, works great so far.

    We struggle with this onnx in particular : https://socrategroupe-my.sharepoint...JKlJyUq8QgvIYBQO8Km1J4kwhA_Ia1aFQsXA?e=qcQckx

    During the import, unity logs out errors and warning (full editor logs) :

    Code (CSharp):
    1. tart ondemand import (priority ImportantBackground): Assets/Models/pspnet50.onnx (Guid(26fab18c732bb47019663ba30476d0e7) Importer(815301076,1909f56bfc062723c751e8b465ee728b))
    2. 2022-02-18 09:13:10.174 Unity[4370:31046] CAMetalLayer ignoring invalid setDrawableSize width=0.000000 height=0.000000
    3. 2022-02-18 09:13:10.177 Unity[4370:31046] CAMetalLayer ignoring invalid setDrawableSize width=0.000000 height=0.000000
    4. Refresh completed in 0.129645 seconds.
    5. RefreshInfo: RefreshV2(AllowForceSynchronousImport) scanfilter:
    6. RefreshProfiler: Total: 129.633ms
    7. Refresh completed in 0.104998 seconds.
    8. RefreshInfo: RefreshV2(AllowForceSynchronousImport) scanfilter:
    9. RefreshProfiler: Total: 104.986ms
    10. 2022-02-18 09:15:13.622 Unity[4370:31046] CAMetalLayer ignoring invalid setDrawableSize width=0.000000 height=0.000000
    11. 2022-02-18 09:15:13.628 Unity[4370:31046] CAMetalLayer ignoring invalid setDrawableSize width=0.000000 height=0.000000
    12. 2022-02-18 09:15:13.682 Unity[4370:31046] NSEventModifierFlagFunction specified to -setKeyEquivalentModifierMask: for item <NSMenuItem: 0x60000282c1c0 Font Asset, ke='Command-F12'>, but is only supported for system-provided menu items; will not be used
    13. Refresh completed in 0.118381 seconds.
    14. RefreshInfo: RefreshV2(AllowForceSynchronousImport) scanfilter:
    15. RefreshProfiler: Total: 118.368ms
    16. Refresh completed in 0.095572 seconds.
    17. RefreshInfo: RefreshV2(AllowForceSynchronousImport) scanfilter:
    18. RefreshProfiler: Total: 95.560ms
    19. 2022-02-18 09:17:44.687 Unity[4370:31046] NSEventModifierFlagFunction specified to -setKeyEquivalentModifierMask: for item <NSMenuItem: 0x60000284b170 Font Asset, ke='Command-F12'>, but is only supported for system-provided menu items; will not be used
    20. 2022-02-18 09:17:47.503 Unity[4370:31046] NSEventModifierFlagFunction specified to -setKeyEquivalentModifierMask: for item <NSMenuItem: 0x600002885490 Font Asset, ke='Command-F12'"Assets/Models/output.onnx" > ArgumentException: Cannot reshape array of size 34560000 into shape with multiple of 223729 elements
    21. Unity.Barracuda.TensorExtensions.Reshape (Unity.Barracuda.TensorShape shape, System.Int32[] size4Dor8D) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Runtime/Core/TensorExtensions.cs:579)
    22. Unity.Barracuda.ModelAnalyzer.ListTemporaryTensorShapes (Unity.Barracuda.Model model, System.Collections.Generic.IDictionary`2[TKey,TValue] inputShapes, System.Collections.Generic.IDictionary`2[System.String,System.Nullable`1[Unity.Barracuda.TensorShape]]& shapesByName) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Runtime/Core/Backends/ModelAnalyzer.cs:432)
    23. Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.CorrectOutputLayoutToMatchNHWCLayout (Unity.Barracuda.Model& nhwc) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWC/CorrectOutputLayoutToMatchNHWCLayout.cs:19)
    24. Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.Rewrite (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWCPass.cs:157)
    25. Unity.Barracuda.Compiler.Passes.NCHWToNHWCPass.Run (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Runtime/Core/Compiler/Passes/NCHWToNHWCPass.cs:39)
    26. Unity.Barracuda.Compiler.Passes.IntermediateToRunnableNHWCPass.Run (Unity.Barracuda.Model& model) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Runtime/Core/Compiler/Passes/IntermediateToRunnableNHWCPass.cs:38)
    27. Unity.Barracuda.ONNX.ONNXModelConverter.Convert (Google.Protobuf.CodedInputStream inputStream) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:188)
    28. Unity.Barracuda.ONNX.ONNXModelConverter.Convert (System.String filePath) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:98)
    29. Unity.Barracuda.ONNXModelImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at Library/PackageCache/com.unity.barracuda@2.4.0-preview/Barracuda/Editor/ONNXModelImporter.cs:65)
    30. UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at /Users/bokken/buildslave/unity/build/Modules/AssetPipelineEditor/Public/ScriptedImporter.cs:22)
    31. UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean)
    32. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
    33. UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37)
    34. UnityEditor.DragAndDropService:DefaultProjectBrowserDropHandler (int,string,bool) (at /Users/bokken/buildslave/unity/build/Editor/Mono/DragAndDropService.cs:127)
    35. System.Reflection.MonoMethod:Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo)
    36. System.Reflection.MethodBase:Invoke (object,object[])
    37. System.Delegate:DynamicInvokeImpl (object[])
    38. System.MulticastDelegate:DynamicInvokeImpl (object[])
    39. System.Delegate:DynamicInvoke (object[])
    40. UnityEditor.DragAndDropService:Drop (int,object[]) (at /Users/bokken/buildslave/unity/build/Editor/Mono/DragAndDropService.cs:96)
    41. UnityEditor.ObjectListArea/LocalGroup:DoDrag (int,bool) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ObjectListLocalGroup.cs:1383)
    42. UnityEditor.ObjectListArea/LocalGroup:HandleUnusedDragEvents (single) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ObjectListLocalGroup.cs:303)
    43. UnityEditor.ObjectListArea/Group:Draw (single,UnityEngine.Vector2,int&) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ObjectListGroup.cs:154)
    44. UnityEditor.ObjectListArea:HandleListArea () (at /Users/bokken/buildslave/unity/build/Editor/Mono/ObjectListArea.cs:1077)
    45. UnityEditor.ObjectListArea:OnGUI (UnityEngine.Rect,int) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ObjectListArea.cs:394)
    46. UnityEditor.ProjectBrowser:OnGUI () (at /Users/bokken/buildslave/unity/build/Editor/Mono/ProjectBrowser.cs:1905)
    47. UnityEditor.HostView:InvokeOnGUI (UnityEngine.Rect,UnityEngine.Rect) (at /Users/bokken/buildslave/unity/build/Editor/Mono/HostView.cs:403)
    48. UnityEditor.DockArea:DrawView (UnityEngine.Rect,UnityEngine.Rect) (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:381)
    49. UnityEditor.DockArea:OldOnGUI () (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:372)
    50. UnityEngine.UIElements.IMGUIContainer:DoOnGUI (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,bool,UnityEngine.Rect,System.Action,bool) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:333)
    51. UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,System.Action,bool) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:663)
    52. UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,System.Action,bool) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:635)
    53. UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,bool) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:628)
    54. UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase,bool,bool) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:594)
    55. UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUI (UnityEngine.UIElements.EventBase,bool,bool) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:583)
    56. UnityEngine.UIElements.IMGUIContainer:HandleEvent (UnityEngine.UIElements.EventBase) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:516)
    57. UnityEngine.UIElements.EventDispatchUtilities:PropagateEvent (UnityEngine.UIElements.EventBase) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Events/IEventDispatchingStrategy.cs:113)
    58. UnityEngine.UIElements.MouseEventDispatchingStrategy:SendEventToRegularTarget (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.BaseVisualElementPanel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Events/MouseEventDispatchingStrategy.cs:35)
    59. UnityEngine.UIElements.MouseEventDispatchingStrategy:SendEventToTarget (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.BaseVisualElementPanel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Events/MouseEventDispatchingStrategy.cs:26)
    60. UnityEngine.UIElements.MouseEventDispatchingStrategy:DispatchEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Events/MouseEventDispatchingStrategy.cs:19)
    61. UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,bool) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:373)
    62. UnityEngine.UIElements.EventDispatcher:ProcessEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:336)
    63. UnityEngine.UIElements.EventDispatcher:Dispatch (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,UnityEngine.UIElements.DispatchMode) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:216)
    64. UnityEngine.UIElements.BaseVisualElementPanel:SendEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.DispatchMode) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Panel.cs:372)
    65. UnityEngine.UIElements.UIElementsUtility:DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/UIElementsUtility.cs:461)
    66. UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (int,intptr,bool&) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/UIElementsUtility.cs:209)
    67. UnityEngine.UIElements.UIEventRegistration:ProcessEvent (int,intptr) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/UIElementsUtility.cs:74)
    68. UnityEngine.UIElements.UIEventRegistration/<>c:<.cctor>b__1_2 (int,intptr) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/UIElementsUtility.cs:28)
    69. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
    70.  
    If you can give us clue of what's wrong in the pipeline of conversion, maybe we could try different export settings or try to transform the model to make it works with barracuda.

    Thanks in advance, Alexis
     
  2. fguinier

    fguinier

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    146
    Hi @AlexisDelforges ,

    The key is here is line 20/21 in the log:

    Code (CSharp):
    1. 2022-02-18 09:17:47.503 Unity[4370:31046] NSEventModifierFlagFunction specified to -setKeyEquivalentModifierMask: for item <NSMenuItem: 0x600002885490 Font Asset, ke='Command-F12'"Assets/Models/output.onnx" > ArgumentException: Cannot reshape array of size 34560000 into shape with multiple of 223729 elements
    2.  
    It means our importer was unable to convert the model usually because the model is too flexible for what we currently support. An option could be to try onnxSimplifier to make the model more static: https://github.com/daquexian/onnx-simplifier. Please note that we are actively working on improving the varierty of network we support.

    Thanks
    Florent
     
  3. AlexisDelforges

    AlexisDelforges

    Joined:
    Nov 30, 2021
    Posts:
    20
    Thanks @fguinier !
    Tried the github without success. I won't go too deep on this as the model doesn't match barracuda requirements for now as you said.
    Will try eventually in a few months to see if it's possible to import in Unity,
     
    fguinier likes this.