Unity-Technologies / barracuda-release

Other
567 stars 78 forks source link

Could not read tensor data for constant tensor #139

Closed killerantz closed 3 years ago

killerantz commented 3 years ago

Trying to import an ONNX model into Unity produces this error.

OnnxLayerImportException: Could not read tensor data for constant tensor. Unity.Barracuda.ONNX.ONNXTensor..ctor (Onnx.TensorProto onnxTensor) (at Library/PackageCache/com.unity.barracuda@1.3.0-preview/Barracuda/Runtime/ONNX/ONNXTensor.cs:165) Unity.Barracuda.ONNX.ONNXModelConverter.ConvertOnnxModel (Onnx.ModelProto onnxModel) (at Library/PackageCache/com.unity.barracuda@1.3.0-preview/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:2585) Unity.Barracuda.ONNX.ONNXModelConverter.Convert (Google.Protobuf.CodedInputStream inputStream) (at Library/PackageCache/com.unity.barracuda@1.3.0-preview/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:104) Unity.Barracuda.ONNX.ONNXModelConverter.Convert (System.String filePath) (at Library/PackageCache/com.unity.barracuda@1.3.0-preview/Barracuda/Runtime/ONNX/ONNXModelConverter.cs:83) Unity.Barracuda.ONNXModelImporter.OnImportAsset (UnityEditor.Experimental.AssetImporters.AssetImportContext ctx) (at Library/PackageCache/com.unity.barracuda@1.3.0-preview/Barracuda/Editor/ONNXModelImporter.cs:58) UnityEditor.Experimental.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.Experimental.AssetImporters.AssetImportContext ctx) (at :0) UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

This occurs in versions 1.3.0 and 1.0.4. The model was produced by Lobe, tried exporting as ResNet-50 V2 and MobileNetV2.

See the attached MobileNet version and signature files in the zip. Peace ONNX.zip

I'm also experimenting with Teachable Machine, but they only export as TensorFlow types right now, which need to be converted to ONNX. I'm still learning about the different model types and formats, really just experimenting with different workflows including ML-Agents, for different types of AI tasks. Thanks for any help.

AlexRibard commented 3 years ago

Thanks for providing the model, I will check.

AlexRibard commented 3 years ago

Hi @killerantz I've checked your model. For some reason the last Gather op, the indices are stored as an array of string... Looking into it it is worth "[ \"RGVmYXVsdA==\", \"UGVhY2U=\" ]" so not sure which encoding it is using... So there must have been a bug in how you exported your model. Not knowing which values to take for the indices. I removed the last bit of the model image As this can be done easily on the CPU once you have the output. After that I validated that your model imports and runs correctly (against onnxruntime). So things should be good. I've also given you the script to edit the model (just rename it to .py) Let me know if you have any other questions. modifyonnxmodel.txt

killerantz commented 3 years ago

Thanks for the help!