-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Allow user to overwrite unknown shapes loaded from ONNX model #3963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -226,36 +328,17 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat | |||
/// <param name="modelFile">Model file path.</param> | |||
/// <param name="gpuDeviceId">Optional GPU device ID to run execution on. Null for CPU.</param> | |||
/// <param name="fallbackToCpu">If GPU error, raise exception or fallback to CPU.</param> | |||
internal OnnxTransformer(IHostEnvironment env, string modelFile, int? gpuDeviceId = null, bool fallbackToCpu = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ctor is not used at all, so I removed it. #Resolved
Add a command line test Remove unused code
=> new OnnxScoringEstimator(CatalogUtils.GetEnvironment(catalog), modelFile, gpuDeviceId, fallbackToCpu); | ||
bool fallbackToCpu = false, | ||
IDictionary<string, int[]> shapeDictionary = null) | ||
=> new OnnxScoringEstimator(CatalogUtils.GetEnvironment(catalog), modelFile, gpuDeviceId, fallbackToCpu, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a breaking change. I am afraid API compat is not active for this assembly. I will open an issue about it and fix it in the meantime.
Unfortunately the signature of the function changes if you add another parameter. The only way to do this change without being a breaking change is to add a new overload with the new parameter. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a PR on reactivating API compat, could you approve it and rebase afterwards?
In reply to: 301718819 [](ancestors = 301718819)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void TestOnnxTransformWithCustomShapes() | ||
{ | ||
// The loaded model has input shape [-1, 3] and output shape [-1]. | ||
var modelFile = Path.Combine(Directory.GetCurrentDirectory(), "unknowndimensions", "test_unknowndimensions_float.onnx"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_unknowndimensions_float [](start = 96, length = 28)
nit: Could we use CSharp style for file names?
If that was the original name of the model, maybe it's fine like this. #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in another repo and I feel it looks just fine.
In reply to: 301724967 [](ancestors = 301724967)
public void TestOnnxTransformWithCustomShapes() | ||
{ | ||
// The loaded model has input shape [-1, 3] and output shape [-1]. | ||
var modelFile = Path.Combine(Directory.GetCurrentDirectory(), "unknowndimensions", "test_unknowndimensions_float.onnx"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_unknowndimensions_float [](start = 96, length = 28)
Could you add a link to the description of the onnx model this test is using? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no such a description for those internal ONNX models but I can add a link to its source.
In reply to: 301726035 [](ancestors = 301726035)
/// </summary> | ||
/// <param name="shapeDictionary">Dictionary of tensor shapes. Keys are tensor names | ||
/// while values the associated shapes.</param> | ||
private void TryModwlWithCustomShapesHelper(IDictionary<string, int[]> shapeDictionary) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TryModwlWithCustomShapesHelper [](start = 21, length = 30)
I think there might be a small typo: Modwl -> Model #Resolved
It would be very nice to have in a comment the layout of the binary format like we do in other transformers. Refers to: src/Microsoft.ML.OnnxTransformer/OnnxTransform.cs:327 in ab6424c. [](commit_id = ab6424c, deletion_comment = False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds an extra argument to
ApplyOnnxModel
functions./// <param name="shapeDictionary">ONNX shape should be used to over those loaded from <paramref name="modelFile"/>.</param>
If a key-value pair, (
tensor_name
,[1, 2, 3]
) exists, thetensor_name
's shape loaded from ONNX model file will be replaced by[1, 2, 3]
. It's allows user to replace unknown shapes in their applications.Fix #3932.
With this PR, FasterRCNN mentioned in #3932 can be run as the example below.