NickSwardh / YoloDotNet

YoloDotNet - A C# .NET 8.0 project for Classification, Object Detection, OBB Detection, Segmentation and Pose Estimation in both images and videos.
GNU General Public License v3.0
158 stars 28 forks source link

Exception Encountered #5

Closed SandipBR closed 7 months ago

SandipBR commented 8 months ago

Hi I am using visual studio 2022 and the project is in .net8. The exception comes when loading the onnx model. I exported the model from .pt to .onnx in pytorch.

I am using nuget.

The exception is : 'The given key 'date' was not present in the dictionary.'

Please help

billkearson commented 7 months ago

Hello, I am getting the same exception from YOLOv8.dll. VS2022, .net8, Win11, using cpu for now. Exception: System.Collections.Generic.KeyNotFoundException: 'The given key 'date' was not present in the dictionary.'

I commented out the Date line 28 "//Date = DateTime.Parse(metaData[NameOf(MetaData.Date)]), in the method "public static OnnxModel GetOnnxProperties(this InferenceSession session)" in OnnxPropertiesExtension.cs and it seems to work.

Not sure the impact or what the better solution is.

NickSwardh commented 7 months ago

Hi guys, I've made some changes to YoloDotNet. The date is a custom metadata-tag inside the onnx file, and it seems like this tag is not always present in the final onnx for some reason. Maybe it has something to do with how the model is being exported to onnx. No Idea, just guessing.

Anyways, the only metatag of importance for YoloDotNet, is the "Name" tag since it contains all the labels. The other tags are just extra "fun-to-have-tags". So, instead of mapping them to properties, the tags are now just pulled out from the onnx file as a Dictionary<string, string> and can be accessed from yolo.OnnxModel.CustomMetaData if needed.

By the way, I've also added a new Classification feature and updated the Nuget package to include the changes. Check the ReadMe for more info.

Best regards, Nick

gtsonkov commented 6 months ago

I encounter a similar exception when trying to load yolov4.onnx or similar. In my case, the error message is: "The given key "task" was not present in the dictionary."