Skip to content

Commit

Permalink
VectorToImageTransform conversion to estimator/transformer (dotnet#2580)
Browse files Browse the repository at this point in the history
* Convert VectorToImageTransform to estimator/transformer

* Rename Schema, Row, etc.

* Code review comments, and fix baseline of EntryPointCatalog test

* Code review comments

* Fix EntryPointCatalog baseline
  • Loading branch information
yaeldMS authored Feb 21, 2019
1 parent eb60021 commit ed7f706
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 295 deletions.
8 changes: 4 additions & 4 deletions src/Microsoft.ML.ImageAnalytics/EntryPoints/ImageAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public static CommonOutputs.TransformOutput ImageGrayscale(IHostEnvironment env,
};
}

[TlcModule.EntryPoint(Name = "Transforms.VectorToImage", Desc = VectorToImageTransform.Summary,
UserName = VectorToImageTransform.UserName, ShortName = VectorToImageTransform.LoaderSignature)]
public static CommonOutputs.TransformOutput VectorToImage(IHostEnvironment env, VectorToImageTransform.Arguments input)
[TlcModule.EntryPoint(Name = "Transforms.VectorToImage", Desc = VectorToImageConvertingTransformer.Summary,
UserName = VectorToImageConvertingTransformer.UserName, ShortName = VectorToImageConvertingTransformer.LoaderSignature)]
public static CommonOutputs.TransformOutput VectorToImage(IHostEnvironment env, VectorToImageConvertingTransformer.Options input)
{
var h = EntryPointUtils.CheckArgsAndCreateHost(env, "VectorToImageTransform", input);
var xf = new VectorToImageTransform(h, input, input.Data);
var xf = VectorToImageConvertingTransformer.Create(h, input, input.Data);
return new CommonOutputs.TransformOutput()
{
Model = new TransformModelImpl(h, xf, input.Data),
Expand Down
30 changes: 29 additions & 1 deletion src/Microsoft.ML.ImageAnalytics/ExtensionsCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static ImagePixelExtractingEstimator ExtractPixels(this TransformsCatalog

/// <include file='doc.xml' path='doc/members/member[@name="ImagePixelExtractingEstimator"]/*' />
/// <param name="catalog">The transform's catalog.</param>
/// <param name="columns">The name of the columns containing the image paths, and per-column configurations.</param>
/// <param name="columns">The name of the columns containing the images, and per-column configurations.</param>
public static ImagePixelExtractingEstimator ExtractPixels(this TransformsCatalog catalog, params ImagePixelExtractingEstimator.ColumnInfo[] columns)
=> new ImagePixelExtractingEstimator(CatalogUtils.GetEnvironment(catalog), columns);

Expand Down Expand Up @@ -133,5 +133,33 @@ public static ImageResizingEstimator ResizeImages(this TransformsCatalog catalog
/// </example>
public static ImageResizingEstimator ResizeImages(this TransformsCatalog catalog, params ImageResizingEstimator.ColumnInfo[] columns)
=> new ImageResizingEstimator(CatalogUtils.GetEnvironment(catalog), columns);

/// <summary>
/// Converts vectors of pixels into <see cref="ImageType"/> representation.
/// </summary>
/// <param name="catalog">The transform's catalog.</param>
/// <param name="columns">The name of the columns containing the pixels, and per-column configurations.</param>
public static VectorToImageConvertingEstimator ConvertToImage(this TransformsCatalog catalog, params VectorToImageConvertingEstimator.ColumnInfo[] columns)
=> new VectorToImageConvertingEstimator(CatalogUtils.GetEnvironment(catalog), columns);

/// <summary>
/// Converts vectors of pixels into <see cref="ImageType"/> representation.
/// </summary>
/// <param name="catalog">The transforms' catalog.</param>
/// <param name="height">The height of the output images.</param>
/// <param name="width">The width of the output images.</param>
/// <param name="outputColumnName"> Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param>
/// <param name="inputColumnName"> Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
/// <param name="colors"> Specifies which <see cref="ImagePixelExtractingEstimator.ColorBits"/> are in the input pixel vectors. The order of colors is: Alpha, Red, Green Blue.</param>
/// <param name="interleave">Whether the pixels are interleaved, meaning whether they are in `ARGB ARGB` order, or separated in the planar form, where the colors are specified one by one
/// alpha, red, green, blue for all the pixels of the image. </param>
/// <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 = VectorToImageConvertingTransformer.Defaults.Colors,
bool interleave = VectorToImageConvertingTransformer.Defaults.InterleaveArgb,
float scale = VectorToImageConvertingTransformer.Defaults.Scale,
float offset = VectorToImageConvertingTransformer.Defaults.Offset)
=> new VectorToImageConvertingEstimator(CatalogUtils.GetEnvironment(catalog), height, width, outputColumnName, inputColumnName, colors, interleave, scale, offset);
}
}
Loading

0 comments on commit ed7f706

Please sign in to comment.