SBetzin
SBetzin

Reputation: 11

Custom Vision ONNX models stopped working with Windows 10 ML

I have trained a model using Custom Vision ai. Exporting the model as ONNX file.

In my C# .net core console application I have referenced the windows 10 sdk as described here: accessing windows ml from console apps

I am then creating a screenshot and converting it to a SoftwareBitmap -> VideoFrame and finally to a ImageFeatureValue based on the example: Using Image as Tensor input for ONNX models

finally I bind the tensor to my onnx model with:

var output = new OnnxModelOutput();
var session = await CreateSession(projectId);
var binding = new LearningModelBinding(session);

binding.Bind("data", imageFile);
binding.Bind("classLabel", output.ClassLabel);
binding.Bind("loss", output.Loss);

This worked fine for month! Since a few days it stopped working. It seems that the ONNX binding changed in custom vision ai. If compare an old model to a new one:

Old Model

name: data
type: float32[None,3,224,224]
denotation: Image(Bgr8)
Image(s) in BGR format. It is a [N, C, H, W]-tensor.
The 1st/2nd/3rd slices along the C-axis are blue, green, and red channels, respectively. input of old ONNX model

New Model

name: data
type: float32[None,3,224,224]
denotation: Image(Bgr8,Linear,NominalRange_0_255)
Image(s) in BGR format. It is a [N, C, H, W]-tensor.
The 1st/2nd/3rd slices along the C-axis are blue, green, and red channels, respectively
enter image description here

Question

With the current change in the new ONNX model the input binding fails with error: Model variable data, expects Float[-1,3,224,224,], but binding was attempted with an incompatible type Image[1174x729].'

So how to reflect the model input change in c# ???

Upvotes: 1

Views: 844

Answers (1)

JsonDork
JsonDork

Reputation: 718

I managed to solve it!

I downloaded this tool and opened up the model

https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Tools/WinMLDashboard

enter image description here

And then you need to remove the new metadata properties. That is to say you need to remove the Linear,NominalRange_0_255)

So once I removed this, it once more worked! enter image description here

Upvotes: 1

Related Questions