How to get ONNX input/output class from signature file?
Hello: I have installed Lobe Application in my Windows 10 PC, from this URL: https://www.lobe.ai/ I used a small dataset to train and get an ONNX model. This model is an image converter, it is not a classifier.
The following is the signature JSON file: { "doc_id": "2cc072ae-dbda-43c5-8db7-4c2515e0548d", "doc_name": "model", "doc_version": "9c8be1ab541b4591f46bb01fc60116cf", "format": "onnx", "version": 5, "inputs": { "Image": { "dtype": "float32", "shape": [null, 224, 224, 3], "name": "Image:0" } }, "outputs": { "Confidences": { "dtype": "float32", "shape": [null, 2], "name": "2cc072ae-dbda-43c5-8db7-4c2515e0548d.9554adfa-5d26-484f-88d3-dea9f2f46f01/dense_2/Softmax:0" } }, "tags": [], "classes": { "Label": ["test_A", "test_B"] }, "filename": "model.onnx", "export_model_version": 1 }
I also use mlgen for Visual Studio 2019 from this URL, to generate some C# wrapper class, like this: public sealed class ModelInput { public TensorFloat Image00; // shape(-1,224,224,3) }
public sealed class ModelOutput
{
public TensorFloat output2cc072ae0dbda043c508db704c2515e0548d09554adfa05d260484f088d30dea9f2f46f010dense_20Softmax00; // shape(-1,2)
}
public sealed class ModelModel
{
private LearningModel model;
private LearningModelSession session;
private LearningModelBinding binding;
public static async Task<ModelModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
{
ModelModel learningModel = new ModelModel();
learningModel.model = await LearningModel.LoadFromStreamAsync(stream);
learningModel.session = new LearningModelSession(learningModel.model);
learningModel.binding = new LearningModelBinding(learningModel.session);
return learningModel;
}
public async Task<ModelOutput> EvaluateAsync(ModelInput input)
{
binding.Bind("Image:0", input.Image00);
var result = await session.EvaluateAsync(binding, "0");
var output = new ModelOutput();
output.output2cc072ae0dbda043c508db704c2515e0548d09554adfa05d260484f088d30dea9f2f46f010dense_20Softmax00 = result.Outputs["2cc072ae-dbda-43c5-8db7-4c2515e0548d.9554adfa-5d26-484f-88d3-dea9f2f46f01/dense_2/Softmax:0"] as TensorFloat;
return output;
}
But I don’t quite understand the meaning of the above class. If I want to use an input image and generate an output image from the ONNX model. How I can write an OnnxInput and OnnxOutputClass? I have no idea about the input shape [null, …] means what and output shape [null, 2] means what?
By the way, the input/output name seems to be very long and meaningless. Can I use python code to change the ONNX model, so it will show some meaningful names for input/output? For example, if I want to use output name like: Iamge2Sketch, not like this one: "name": "2cc072ae-dbda-43c5-8db7-4c2515e0548d.9554adfa-5d26-484f-88d3-dea9f2f46f01/dense_2/Softmax:0"
I am using Visual Studio 2022 and 2019 on Windows 10, I also installed Python 3.9. Please advise, Thanks,