-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
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()); |
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.
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; } } |
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 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"); |
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.
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() |
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.
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) |
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.
1 [](start = 145, length = 1)
would be nice to have Defaults
class #Resolved
Codecov Report
@@ 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
|
//verWrittenCur: 0x00010001, // Initial | ||
//verWrittenCur: 0x00010002, // Swith from OpenCV to Bitmap | ||
verWrittenCur: 0x00010003, // don't serialize sizeof(Single) | ||
verReadableCur: 0x00010003, |
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.
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.
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.
One small comment regarding VersionInfo.
Otherwise looks good.
/// </summary> | ||
[Flags] | ||
private enum ColorBits : byte | ||
public IReadOnlyCollection<VectorToImageConvertingEstimator.ColumnInfo> Columns => _columns.AsReadOnly(); |
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 [](start = 8, length = 6)
internal???
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 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.
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.
This is the remaining work for the public API of Microsoft.ML.ImageAnalytics.
Fixes #2269 .