Skip to content
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

Added support for inserting batch dimension in inputs in TensorFlow. #2935

Merged
merged 1 commit into from
Mar 18, 2019

Conversation

zeahmed
Copy link
Contributor

@zeahmed zeahmed commented Mar 12, 2019

This PR fixes #2778.

It is difficult to induce shape of the inputs from the data or model when the model accepts input of any shape but internal operators requires the input in particular shape. This is the problem with the inception model available at the following location.

https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip

The model takes input data of any shape. There is a convolution layer just after the input which requires 4-D input. The first dimension for Conv2D operation in TensorFlow is the batch dimension. That's causing failure of samples in #2778. The ML.NET input is [224, 244, 3] while convolution layer in the above model requires [-1, 224, 224, 3]. The ultimate solution to this problem is to have reshape transform #765.

However, it will take time implement. To unblock #2778, the temporary solution implemented here is to add a parameter in options class or other public interfaces called “AddBatchDimensionInput”. When user set it to true, batch dimension would be added to the inputs otherwise not.

NOTE: Once we have the ReshapeTransform. This change needs to be reverted.

@Ivanidzo4ka
Copy link
Contributor

while convolution layer in the above model requires [-1, 224, 224, 3]

Are you sure about that? I though we properly handle variable length tensors, and that [-1,244,244,3] would be casted to [1,244,244,3] and we internally would stretch our image [244,244,3] into it.

Then I look into it - input layer had [1,244,244,3] and that was reason why we can't handle it, since it's not variable length, it's fixed 4 dimensional tensor instead of tensor of variable length.

@zeahmed
Copy link
Contributor Author

zeahmed commented Mar 12, 2019

Yes, the input is variable length with unknown shape. However, model actually wants input in [B, H, W, C] format and this shape cannot be inferred automatically.


In reply to: 472221487 [](ancestors = 472221487)

@codecov
Copy link

codecov bot commented Mar 12, 2019

Codecov Report

Merging #2935 into master will decrease coverage by <.01%.
The diff coverage is 67.39%.

@@            Coverage Diff             @@
##           master    #2935      +/-   ##
==========================================
- Coverage   72.19%   72.18%   -0.01%     
==========================================
  Files         796      796              
  Lines      142005   142025      +20     
  Branches    16044    16047       +3     
==========================================
+ Hits       102514   102522       +8     
- Misses      35114    35123       +9     
- Partials     4377     4380       +3
Flag Coverage Δ
#Debug 72.18% <67.39%> (-0.01%) ⬇️
#production 67.97% <70.45%> (-0.01%) ⬇️
#test 88.3% <0%> (ø) ⬆️
Impacted Files Coverage Δ
src/Microsoft.ML.TensorFlow/TensorflowCatalog.cs 100% <ø> (ø) ⬆️
...cenariosWithDirectInstantiation/TensorflowTests.cs 90.81% <0%> (ø) ⬆️
...ensorFlow.StaticPipe/TensorFlowStaticExtensions.cs 100% <100%> (ø) ⬆️
src/Microsoft.ML.TensorFlow/TensorFlowModel.cs 100% <100%> (ø) ⬆️
src/Microsoft.ML.TensorFlow/TensorflowTransform.cs 79.12% <56.66%> (-0.65%) ⬇️
src/Microsoft.ML.Maml/MAML.cs 24.75% <0%> (-1.46%) ⬇️
...ML.Transforms/Text/StopWordsRemovingTransformer.cs 85.53% <0%> (-0.17%) ⬇️

Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Contributor

@shauheen shauheen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@zeahmed zeahmed merged commit a41e6d9 into dotnet:master Mar 18, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible Bug Tensorflow in v0.11 - Invalid argument: input must be 4-dimensional[224,224,3]
3 participants