microsoft / psi

Platform for Situated Intelligence
https://github.com/microsoft/psi/wiki
Other
542 stars 96 forks source link

Allow to overwrite ONNX Model Shape and multiple input and outputs #208

Open ankitbko opened 3 years ago

ankitbko commented 3 years ago

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 commented 3 years ago

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.

danbohus commented 2 years ago

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.

ankitbko commented 2 years ago

Sure will be happy to contribute.