Skip to content

Image support #528

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 26 commits into from
Jul 31, 2018
Merged

Image support #528

merged 26 commits into from
Jul 31, 2018

Conversation

Ivanidzo4ka
Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka commented Jul 13, 2018

address #489
need create issue about IDataView datatype extensibility.

{
Contracts.CheckParam(height > 0, nameof(height));
Contracts.CheckParam(width > 0, nameof(width));
Contracts.CheckParam((long)height * width <= int.MaxValue / 4, nameof(height), "height * width is too large");
Copy link
Contributor

@TomFinley TomFinley Jul 13, 2018

Choose a reason for hiding this comment

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

height [](start = 92, length = 6)

nameof for params in this message? #Closed

public override string ToString()
{
if (Height == 0 && Width == 0)
return "Picture";
Copy link
Contributor

@TomFinley TomFinley Jul 13, 2018

Choose a reason for hiding this comment

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

Picture [](start = 24, length = 7)

It's a little weird that the image type identifies itself as picture, is it not? #Closed

return false;
if (Width != tmp.Width)
return false;
return true;
Copy link
Contributor

@TomFinley TomFinley Jul 13, 2018

Choose a reason for hiding this comment

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

Maybe restructure as return Width == tmp.Width. #Closed

if (other == this)
return true;
var tmp = other as ImageType;
if (tmp == null)
Copy link
Contributor

@TomFinley TomFinley Jul 13, 2018

Choose a reason for hiding this comment

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

Will if (other as ImageType tmp == null) work? #Closed

{
}

public override bool Equals(ColumnType other)
Copy link
Contributor

@TomFinley TomFinley Jul 13, 2018

Choose a reason for hiding this comment

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

Equals [](start = 29, length = 6)

There's something a bit strange about this. ColumnType implements IEquatable<ColumnType>, and the guidelines for that say it should also overload Equals(object) and GetHashCode. Though to be fair to you I think all ColumnTypes have this problem. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe file a separate issue, we can address later?


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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#547


In reply to: 203182127 [](ancestors = 203182127,202379905)

@@ -0,0 +1,3 @@
banana.jpg banana
hotdog.jpg hotdog
tomato.jpg tomato
Copy link
Contributor

@TomFinley TomFinley Jul 13, 2018

Choose a reason for hiding this comment

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

I feel like this should have been "not hotdog." 😃 #Closed

namespace Microsoft.ML.Runtime.Data
{
// REVIEW: Rewrite as LambdaTransform to simplify.
public sealed class ImagePixelExtractorTransform : OneToOneTransformBase
Copy link
Member

@sfilipi sfilipi Jul 16, 2018

Choose a reason for hiding this comment

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

ImagePixelExtractorTransform [](start = 24, length = 28)

Are you planning to add their entry point classes next? #Resolved

namespace Microsoft.ML.Runtime.Data
{
// REVIEW: Rewrite as LambdaTransform to simplify.
public sealed class ImageResizerTransform : OneToOneTransformBase
Copy link
Member

@sfilipi sfilipi Jul 16, 2018

Choose a reason for hiding this comment

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

Let's get in the rhythm of adding one line of

for all public classes. #Resolved

namespace Microsoft.ML.Runtime.Data
{
// REVIEW: Rewrite as LambdaTransform to simplify.
public sealed class ImagePixelExtractorTransform : OneToOneTransformBase
Copy link
Member

@sfilipi sfilipi Jul 16, 2018

Choose a reason for hiding this comment

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

ImagePixelExtractorTransform [](start = 24, length = 28)

Let's get in the rhythm of adding one line of

for all public classes. #Resolved

namespace Microsoft.ML.Runtime.Data
{
// REVIEW: Rewrite as LambdaTransform to simplify.
public sealed class ImageLoaderTransform : OneToOneTransformBase
Copy link
Member

@sfilipi sfilipi Jul 16, 2018

Choose a reason for hiding this comment

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

ImageLoaderTransform [](start = 24, length = 20)

summary #Resolved


/// <summary>
/// Public constructor corresponding to SignatureDataTransform.
/// </summary>
Copy link
Member

@sfilipi sfilipi Jul 16, 2018

Choose a reason for hiding this comment

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

I know we use this allover, and it's plenty meaningful as a code comment, but it will appear in the docs site as well, where might confuse users. Maybe turn it into a code comment removing the triple ///, and

.
Ideally add a meaningful line for the actual documentation. #Resolved

Copy link
Member

@sfilipi sfilipi left a comment

Choose a reason for hiding this comment

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

:shipit:

Ivan Matantsev added 4 commits July 16, 2018 13:11
@Ivanidzo4ka
Copy link
Contributor Author

@dotnet-bot test Windows_NT Release

@Ivanidzo4ka
Copy link
Contributor Author

@dotnet-bot test Linux Debug

{
Contracts.CheckParam(height > 0, nameof(height));
Contracts.CheckParam(width > 0, nameof(width));
Contracts.CheckParam((long)height * width <= int.MaxValue / 4, nameof(height), $"{nameof(height)} * {nameof(width)} is too large");
Copy link
Contributor

@TomFinley TomFinley Jul 17, 2018

Choose a reason for hiding this comment

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

$"{nameof(height)} * {nameof(width)} is too large" [](start = 91, length = 50)

If you really want it as format strings I'd encourage you to make this follow the if (...) throw Contracts.Except pattern. Or you could continue to make it a string literal by making this nameof(height) + " * " + nameof(width) + " is too large" or something. #Closed

public string ImageFolder;
}

internal const string Summary = "Load images from a file.";
Copy link
Contributor

@TomFinley TomFinley Jul 17, 2018

Choose a reason for hiding this comment

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

a file [](start = 58, length = 6)

You forgot to pluralize this. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is "a files" ok, or it should be something else?


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

Copy link
Contributor

@TomFinley TomFinley Jul 28, 2018

Choose a reason for hiding this comment

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

Correct would be "load images from files." FYI @Ivanidzo4ka I feel like this is the only thing standing in the way of this being merged.


In reply to: 205597457 [](ancestors = 205597457,203182343)

Ivan Matantsev added 2 commits July 17, 2018 14:56
Grayscale
return exception catching
@safern safern closed this Jul 23, 2018
@safern safern reopened this Jul 23, 2018
Ivan Matantsev added 2 commits July 23, 2018 09:41
@Ivanidzo4ka Ivanidzo4ka reopened this Jul 23, 2018
@Ivanidzo4ka Ivanidzo4ka changed the title WIP Image support Image support Jul 24, 2018
@Ivanidzo4ka Ivanidzo4ka requested a review from Zruty0 July 24, 2018 16:39
@Zruty0
Copy link
Contributor

Zruty0 commented Jul 25, 2018

@Ivanidzo4ka , you have surely added a lot of code here :) I would much rather ask @TomFinley to finish his review, rather than jump in and try to grok all this myself.

@TomFinley , if for some reason this doesn't work for you, please let me know and I'll start the review


private const string RegistrationName = "ImageGrayscale";

/// Public constructor corresponding to SignatureDataTransform.
Copy link
Contributor

@TomFinley TomFinley Jul 25, 2018

Choose a reason for hiding this comment

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

/// [](start = 8, length = 4)

Did you mean this to be // and not /// , since it is not really terribly sensible for callers? #Closed

return Infos[iinfo].TypeSrc;
}

public ColorMatrix GreyscaleColorMatrix = new ColorMatrix(
Copy link
Contributor

@TomFinley TomFinley Jul 25, 2018

Choose a reason for hiding this comment

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

public ColorMatrix GreyscaleColorMatrix [](start = 8, length = 39)

This is a mutable, public instance level field that affects the functionality of the transform.

Probably want this to be private (or at least internal if somehow it is referenced somewhere else), static, and almost certainly readonly. #Closed

//verWrittenCur: 0x00010001, // Initial
verWrittenCur: 0x00010002, // Swith from OpenCV to Bitmap
verReadableCur: 0x00010002,
verWeCanReadBack: 0x00010002,
Copy link
Contributor

@TomFinley TomFinley Jul 25, 2018

Choose a reason for hiding this comment

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

0x00010002 [](start = 34, length = 10)

What would happen if you were to read a 0x00010001 model? Would it just be a little bit off? Or is it just fundamentally different?

I think possibly it might be better to load those old models, just use the new types under the hood. If we were to, say, hypothetically change from using DvText to ReadOnlySpan<char> or something like that, we almost certainly would not refuse to load all models just on the basis of the type change alone. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In past Loader/Resizer and Pixel extractor was tangled bundle which works together.
From what I found in my investigation during comparing System.Bitmap with old version, Pixel extractor was buggy and throw exception in case of rectangular shape (people used square shape all the time, but maybe rectangle image make sense as well) and Resizer instead of resizing image actually just pick subset of image from top left corner and count it as "Resized" image. Which is fine if you pass real width and height to transform, but if you actually want to resize them, not so great.

That's why I'm bumping versions in all 3 of them.


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

Copy link
Contributor

@TomFinley TomFinley Jul 28, 2018

Choose a reason for hiding this comment

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

Ah OK. So they were not just somewhat different, the old ones were fundamentally broken. That's nice. I guess that's a good enough reason to break backcompat. #Closed

private static VersionInfo GetVersionInfo()
{
return new VersionInfo(
modelSignature: "IMGGREY ",
Copy link
Contributor

@TomFinley TomFinley Jul 25, 2018

Choose a reason for hiding this comment

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

IMGGREY [](start = 33, length = 8)

You had a signature of IMGLOADT for that. Why is this not IMGGREYT?

Also: is it intentional that this be GREY? Elsewhere we are using "gray."

If models already exist with this signature I guess we have to keep it, not sure if that's the case though since you didn't bump the version. :) (I'm not suggesting you bump the version to be clear.) #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

English are so confusing, grey and gray is apparent to have same meaning, but my brain apparently throw coin during typing and at some point I had code with both spelling all across code. Which I tried to unified, but this one slip from my attention.
This is a new transform which we never had before, and I add it "just in case", and "maybe it will prove useful". So i think it make sense to start from version 1.


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

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh sure @Ivanidzo4ka grey and gray are synonymous, though elsewhere you use gray. Also my impression is that we generally favor American spellings (gray) of words vs. British ones (grey).

...Even though I was brought up to use "grey," and had to correct myself since later in my life people thought I was weird. So now I hypercorrect, and you reap the benefits. :D


In reply to: 205597316 [](ancestors = 205597316,205265843)

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.

Thank you @Ivanidzo4ka !

@Ivanidzo4ka
Copy link
Contributor Author

@dotnet-bot test VSTS: public-CI

@Ivanidzo4ka Ivanidzo4ka merged commit bdb742d into dotnet:master Jul 31, 2018
Ivanidzo4ka added a commit that referenced this pull request Jul 31, 2018
codemzs pushed a commit to codemzs/machinelearning that referenced this pull request Aug 1, 2018
Add images support based on System.Drawing
@ghost ghost locked as resolved and limited conversation to collaborators Mar 29, 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