Skip to content

VectorToImageTransform conversion to estimator/transformer #2580

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 5 commits into from
Feb 21, 2019

Conversation

yaeldekel
Copy link

This is the remaining work for the public API of Microsoft.ML.ImageAnalytics.
Fixes #2269 .

if (!inputSchema.TryFindColumn(colInfo.InputColumnName, out var col))
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.InputColumnName);
if (col.Kind != SchemaShape.Column.VectorKind.Vector || (col.ItemType != NumberDataViewType.Single && col.ItemType != NumberDataViewType.Double && col.ItemType != NumberDataViewType.Byte))
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.InputColumnName, new ImageType().ToString(), col.GetTypeString());
Copy link
Contributor

@TomFinley TomFinley Feb 19, 2019

Choose a reason for hiding this comment

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

new ImageType().ToString() [](start = 107, length = 26)

This is not correct. You're saying the expected input type is an image type, yet, you are testing whether it is a known-size vector of float, double, or byte above. #Resolved

public bool Red { get { return (Colors & ColorBits.Red) != 0; } }
public bool Green { get { return (Colors & ColorBits.Green) != 0; } }
public bool Blue { get { return (Colors & ColorBits.Blue) != 0; } }
public bool Alpha { get { return (Colors & ImagePixelExtractingEstimator.ColorBits.Alpha) != 0; } }
Copy link
Contributor

@TomFinley TomFinley Feb 19, 2019

Choose a reason for hiding this comment

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

public bool Alpha { get { return (Colors & ImagePixelExtractingEstimator.ColorBits.Alpha) != 0; } } [](start = 12, length = 99)

Not a big deal, but if you wanted to bring this transplanted code up to "modern standards" by using => style syntax to make this a bit less crazy taht would be fine with me. #Resolved

if (sourceItemType == NumberDataViewType.Byte)
return GetterFromType<byte>(input, iinfo, ex, false);
else
throw Contracts.Except("We only support float or byte arrays");
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Feb 19, 2019

Choose a reason for hiding this comment

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

We only support float or byte arrays [](start = 44, length = 36)

From estimator: "known-size vector of type float, double or byte
Double get lost. #Resolved

@@ -201,13 +201,13 @@ public void TestBackAndForthConversionWithAlphaInterleave()
var cropped = new ImageResizingTransformer(env, "ImageCropped", imageWidth, imageHeight, "ImageReal").Transform(images);

var pixels = new ImagePixelExtractingTransformer(env, "ImagePixels", "ImageCropped", ImagePixelExtractingEstimator.ColorBits.All, true, 2f / 255, 127.5f).Transform(cropped);
IDataView backToBitmaps = new VectorToImageTransform(env, new VectorToImageTransform.Arguments()
IDataView backToBitmaps = VectorToImageConvertingTransformer.Create(env, new VectorToImageConvertingTransformer.Options()
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Feb 19, 2019

Choose a reason for hiding this comment

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

VectorToImageConvertingTransformer.Create [](start = 38, length = 41)

Please don't do that.

First it's a different style comparing to all other transformers.

Second Create method is IDataTransform which we want to get rid of. #Resolved

/// <param name="scale">The values are scaled by this value before being converted to pixels.</param>
/// <param name="offset">The offset is subtracted (before scaling) before converting the values to pixels.</param>
public static VectorToImageConvertingEstimator ConvertToImage(this TransformsCatalog catalog, int height, int width, string outputColumnName, string inputColumnName = null,
ImagePixelExtractingEstimator.ColorBits colors = ImagePixelExtractingEstimator.ColorBits.Rgb, bool interleave = false, float scale = 1, float offset = 0)
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka Feb 19, 2019

Choose a reason for hiding this comment

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

1 [](start = 145, length = 1)

would be nice to have Defaults class #Resolved

@codecov
Copy link

codecov bot commented Feb 19, 2019

Codecov Report

Merging #2580 into master will decrease coverage by <.01%.
The diff coverage is 77.9%.

@@            Coverage Diff             @@
##           master    #2580      +/-   ##
==========================================
- Coverage    71.5%   71.49%   -0.01%     
==========================================
  Files         801      800       -1     
  Lines      142023   141899     -124     
  Branches    16147    16133      -14     
==========================================
- Hits       101557   101455     -102     
  Misses      35998    35998              
+ Partials     4468     4446      -22
Flag Coverage Δ
#Debug 71.49% <77.9%> (-0.01%) ⬇️
#production 67.78% <76.44%> (-0.01%) ⬇️
#test 85.75% <100%> (+0.17%) ⬆️

//verWrittenCur: 0x00010001, // Initial
//verWrittenCur: 0x00010002, // Swith from OpenCV to Bitmap
verWrittenCur: 0x00010003, // don't serialize sizeof(Single)
verReadableCur: 0x00010003,
Copy link
Contributor

Choose a reason for hiding this comment

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

0x00010003 [](start = 32, length = 10)

You can always have check for model version and read one Int32 from stream if it's old one.

I have separate PR where I bump version for ImagePixelExtractor (I introduce colors order). So I plan do the same for VectorToImage and bump version again.
I can get rid of single and add order in same time.
Does it sound good for you?
If you still want to get rid of single in this iteration, I would suggest to keep old models readable.

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.

One small comment regarding VersionInfo.
Otherwise looks good.

/// </summary>
[Flags]
private enum ColorBits : byte
public IReadOnlyCollection<VectorToImageConvertingEstimator.ColumnInfo> Columns => _columns.AsReadOnly();
Copy link
Contributor

Choose a reason for hiding this comment

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

public [](start = 8, length = 6)

internal???

Copy link
Contributor

@zeahmed zeahmed 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

@TomFinley TomFinley left a comment

Choose a reason for hiding this comment

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

Thanks @yaeldekel ! In an ideal world we'd have backcompat as @Ivanidzo4ka suggests, but since AFAIK this was never added anywhere really public except for debugging purposes, this might not be too essential? I think we can correct it later in the unlikely event it does prove essential.

@yaeldekel yaeldekel merged commit ed7f706 into dotnet:master Feb 21, 2019
@yaeldekel yaeldekel deleted the vectortoimage branch February 21, 2019 18:03
@yaeldekel yaeldekel mentioned this pull request Feb 21, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 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.

5 participants