Skip to content

Add ResizingMode.Fill to ImageResizerTransformer #2362

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

Merged
merged 4 commits into from
Feb 3, 2019

Conversation

mareklinka
Copy link
Contributor

@mareklinka mareklinka commented Feb 1, 2019

This PR adds a new resizing mode to the ImageResizerTransformer. This mode is called Fill and when used, the transformer ignores aspect ratio and squeezes/stretches the source image into the target dimensions.

The idea for this mode came up in #2022 - when attempting to score a Keras-trained model it turned out that Keras resizes images in a way that ML.NET cannot do on its own. To increase interoperability, the Fill mode was proposed.

I also included a test for the new mode. This tests uses a specially prepared image, runs the resizing transformation, and then checks whether the result fulfills the specification for the resizing mode.

Fixes #2022

@Ivanidzo4ka
Copy link
Contributor

@mareklinka Can you please unskip locally RegenerateEntryPointCatalog test, run it, and push changes in core_ep-list.tsv?

@@ -710,5 +711,59 @@ public void TestBackAndForthConversionWithoutAlphaNoInterleaveNoOffset()
Done();
}
}

[Fact]
public void ImageResizerTransform_ResizingModeFill()
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Feb 1, 2019

Choose a reason for hiding this comment

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

ImageResizerTransform_ResizingModeFill [](start = 20, length = 38)

Some of us have strong feelings regarding Python_style_of_defining_names, can you forgive us, and change it to C# style of ImageResizerTransformResizingModeFill ? #Resolved

Copy link
Contributor Author

@mareklinka mareklinka Feb 1, 2019

Choose a reason for hiding this comment

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

No problem 😄 #Resolved

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:

@mareklinka
Copy link
Contributor Author

mareklinka commented Feb 1, 2019

@mareklinka Can you please unskip locally RegenerateEntryPointCatalog test, run it, and push changes in core_ep-list.tsv?

Is it possible the test only changed core_manifest.json? I see no changes in core_ep-list.tsv. #Resolved

var leftMid = bitmap.GetPixel(bitmap.Width / 3, bitmap.Height / 2);
var rightMid = bitmap.GetPixel(bitmap.Width / 3 * 2, bitmap.Height / 2);

Assert.All(new[] { topLeft, topRight, bottomLeft, bottomRight, middle }, c =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Assert.All(new[] { topLeft, topRight, bottomLeft, bottomRight, middle }, c => [](start = 14, length = 79)

The joy of multi environment support. Mac OS and Linux fails because some of values become 254 instead of 255.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, weird. Some kind of rounding error, I guess. I'll rewrite the test to be a little more permissive.

@Ivanidzo4ka
Copy link
Contributor

Sorry, sometimes I forget which one is which. If you have changes in arguments it's manifest if you have changes in class names it's list.


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

@codecov
Copy link

codecov bot commented Feb 1, 2019

Codecov Report

Merging #2362 into master will increase coverage by 0.07%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2362      +/-   ##
==========================================
+ Coverage   71.17%   71.25%   +0.07%     
==========================================
  Files         780      783       +3     
  Lines      140404   140781     +377     
  Branches    16053    16088      +35     
==========================================
+ Hits        99936   100309     +373     
+ Misses      36018    36017       -1     
- Partials     4450     4455       +5
Flag Coverage Δ
#Debug 71.25% <100%> (+0.07%) ⬆️
#production 67.6% <100%> (+0.04%) ⬆️
#test 85.3% <100%> (+0.1%) ⬆️

@@ -44,7 +44,10 @@ public enum ResizingKind : byte
IsoPad = 0,

[TGUI(Label = "Isotropic with Cropping")]
IsoCrop = 1
IsoCrop = 1,

Copy link
Contributor

@artidoro artidoro Feb 3, 2019

Choose a reason for hiding this comment

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

Would be great if you could add a summary tag above these options, this will make it show in the documentation online and in the intellisense for future users.

Suggested change
/// <summary>
/// Ignore aspect ratio and squeeze/stretch into target dimensions.
/// </summary>

Copy link
Contributor

@artidoro artidoro left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you for doing this @mareklinka
Would be great if you could one last thing so that this option appears both in the online API documentation and in intellisense.

@@ -44,7 +44,10 @@ public enum ResizingKind : byte
IsoPad = 0,

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// <summary>
/// Isotropic with cropping.
/// </summary>

@@ -44,7 +44,10 @@ public enum ResizingKind : byte
IsoPad = 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
IsoPad = 0,
/// <summary>
  /// Isotropic with padding.
  /// </summary>
IsoPad = 0,

@artidoro artidoro merged commit 5b98e0c into dotnet:master Feb 3, 2019
@artidoro
Copy link
Contributor

artidoro commented Feb 3, 2019

Thanks again!

@mareklinka mareklinka deleted the feature/2022_ResizingKindFill branch February 4, 2019 15:51
@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 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.

3 participants