psi icon indicating copy to clipboard operation
psi copied to clipboard

Allow to overwrite ONNX Model Shape and multiple input and outputs

Open ankitbko opened this issue 3 years ago • 3 comments
trafficstars

I was unable to run DB_TD500_resnet50.onnx model (https://docs.opencv.org/4.x/d4/d43/tutorial_dnn_text_spotting.html) using OnnxModel as it was throwing following error - Length of memory (1625088) must match product of dimensions (3).

The only way to fix it was to duplicate OnnxModel locally and pass the correct shapeDictionary when applying ONNX Model

this.context.Transforms.ApplyOnnxModel(
      modelFile: configuration.ModelFileName,
      outputColumnNames: new[] { configuration.OutputVectorName },
      inputColumnNames: new[] { configuration.InputVectorName },
      gpuDeviceId: configuration.GpuDeviceId,
      shapeDictionary: new Dictionary<string, int[]>()
          {
             { "input", new[] { 1, 3, 736, 736} }
          });

Request is to allow overriding shapeDictionary when creating OnnxModel. This overriding requirement also exist to run FasterRCNN model https://github.com/dotnet/machinelearning/pull/3963

ankitbko avatar Nov 28 '21 14:11 ankitbko

I am adding another ask to same issue as it deals with same config class - Allow multiple input and output column names to be passed to OnnxModel. The ApplyOnnxModel accepts list of output and input names so OnnxModelConfiguration should also accept a list along with shape data for each.

ankitbko avatar Nov 29 '21 03:11 ankitbko

Thanks for flagging this! Agreed, the OnnxModel and OnnxModelConfiguration classes should be updated to allow for configuring lists of input/output names, and to enable the shapeDictionary parameter. The change seems relatively straightforward, and we would welcome a PR on this. Let us know if you plan to make this contribution. Otherwise we'll try to get to it in the near future.

danbohus avatar Dec 06 '21 17:12 danbohus

Sure will be happy to contribute.

ankitbko avatar Dec 09 '21 06:12 ankitbko