-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Image analytics documentation, samples, internalization #2372
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
Changes from 6 commits
976df4c
9804817
9de2af2
c93dfa1
cf8fb0e
1fb1482
256c5b3
70fa0db
7f0ab4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.IO; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public class ConvertToGrayscaleExample | ||
{ | ||
public static void ConvertToGrayscale() | ||
{ | ||
var mlContext = new MLContext(); | ||
|
||
// Downloading a few images, and an images.tsv file, that contains a list of the files, from the dotnet/machinelearning/test/data/images/ | ||
// if you inspect the fileSystem, after running this line, the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
var imagesDataFile = SamplesUtils.DatasetUtils.DownloadImages(); | ||
|
||
// Preview of the content of the images.tsv file | ||
// | ||
// imagePath imageType | ||
// tomato.bmp tomato | ||
// banana.jpg banana | ||
// hotdog.jpg hotdog | ||
// tomato.jpg tomato | ||
|
||
var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments() | ||
{ | ||
Columns = new[] | ||
{ | ||
new TextLoader.Column("ImagePath", DataKind.TX, 0), | ||
new TextLoader.Column("Name", DataKind.TX, 1), | ||
} | ||
}).Read(imagesDataFile); | ||
|
||
var imagesFolder = Path.GetDirectoryName(imagesDataFile); | ||
// Image loading pipeline. | ||
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageObject", "ImagePath")) | ||
.Append(mlContext.Transforms.ConvertToGrayscale(("GrayScale", "ImageObject"))); | ||
|
||
var transformedData = pipeline.Fit(data).Transform(data); | ||
|
||
// The transformedData IDataView contains the loaded images now | ||
//Preview of the transformedData | ||
var transformedDataPreview = transformedData.Preview(); | ||
|
||
// Preview of the content of the images.tsv file | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The output shown below is not the contents of images.tsv file instead its transformedData. #Resolved |
||
// The actual images, in the ImageReal column are of type System.Drawing.Bitmap. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
typo #Resolved |
||
// | ||
// ImagePath Name ImageObject GrayScale | ||
// tomato.bmp tomato {System.Drawing.Bitmap} {System.Drawing.Bitmap} | ||
// banana.jpg banana {System.Drawing.Bitmap} {System.Drawing.Bitmap} | ||
// hotdog.jpg hotdog {System.Drawing.Bitmap} {System.Drawing.Bitmap} | ||
// tomato.jpg tomato {System.Drawing.Bitmap} {System.Drawing.Bitmap} | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.IO; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public class ExtractPixelsExample | ||
{ | ||
public static void ExtractPixels() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What is this demo doing? It would be great to have a description about this example. #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it; it will show up on the next iteration. Personally, i don' think that is very important, because those samples will display in the website that documents the components, so in context, hopefully there is enough explanation. In reply to: 253609946 [](ancestors = 253609946) |
||
{ | ||
var mlContext = new MLContext(); | ||
|
||
// Downloading a few images, and an images.tsv file, that contains a list of the files, from the dotnet/machinelearning/test/data/images/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments here (this looks to be copy-pasted). #Resolved |
||
// if you inspect the fileSystem, after running this line, the | ||
var imagesDataFile = SamplesUtils.DatasetUtils.DownloadImages(); | ||
|
||
// Preview of the content of the images.tsv file | ||
// | ||
// imagePath imageType | ||
// tomato.bmp tomato | ||
// banana.jpg banana | ||
// hotdog.jpg hotdog | ||
// tomato.jpg tomato | ||
|
||
var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments() | ||
{ | ||
Columns = new[] | ||
{ | ||
new TextLoader.Column("ImagePath", DataKind.TX, 0), | ||
new TextLoader.Column("Name", DataKind.TX, 1), | ||
} | ||
}).Read(imagesDataFile); | ||
|
||
var imagesFolder = Path.GetDirectoryName(imagesDataFile); | ||
// Image loading pipeline. | ||
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageObject", "ImagePath")) | ||
.Append(mlContext.Transforms.Resize("ImageObject",imageWidth: 100 , imageHeight: 100 )) | ||
.Append(mlContext.Transforms.ExtractPixels("Pixels", "ImageObject")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Considering specificity of domain, can we have Image subcatalog, like we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i might misremember, but Pete disliked the idea; i believe becuase of too many catalogs makes things hard to find; but @artidoro and @rogancarr have expressed the same thing: issue #2361 If i get another thumbs up from @TomFinley, i am up for adding the catalog and moving the extensions there. I am on the fence, personally. If we have more than 5 xtensions, i'd make a catalog for them. Less than that feels unecessary. In reply to: 253166949 [](ancestors = 253166949) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Anipik: We could make a good benchmark for the image processing pipeline. In Python, the dataset / image loader looks like: # Load image summary data from github
url = "https://express-tlcresources.azureedge.net/datasets/DogBreedsVsFruits/DogFruitWiki.SHUF.117KB.735-rows.tsv"
df_train = pd.read_csv(url, sep = "\t", nrows = 100)
df_train['ImagePath_full'] = "https://express-tlcresources.azureedge.net/datasets/DogBreedsVsFruits/" + \
df_train['ImagePath']
... load images Purpose of the dataset is for example code & includes ~775 images of dogs & fruit: The Dog Breeds vs. Fruits would also be nice for our samples repo. /cc @CESARDELATORRE #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jormont, maybe log an issue about it. It might get forgotten here as a comment. In reply to: 253212682 [](ancestors = 253212682) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sfilipi -- good idea: |
||
|
||
|
||
var transformedData = pipeline.Fit(data).Transform(data); | ||
|
||
// The transformedData IDataView contains the loaded images now | ||
//Preview of the transformedData | ||
var transformedDataPreview = transformedData.Preview(); | ||
|
||
// Preview of the content of the images.tsv file | ||
// The actual images, in the ImageReal column are of type System.Drawing.Bitmap. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
typo #Resolved |
||
// | ||
// ImagePath Name ImageObject "Pixels" | ||
// tomato.bmp tomato {System.Drawing.Bitmap} [ 255, 255, 255, ..... 232, 243, 226, ... | ||
// banana.jpg banana {System.Drawing.Bitmap} [ 255, 255, 255, ..... 90, 54, 43, ... | ||
// hotdog.jpg hotdog {System.Drawing.Bitmap} [ 255, 255, 255, ..... 132, 143, 126, ... | ||
// tomato.jpg tomato {System.Drawing.Bitmap} [ 255, 255, 255, ..... 16, 21, 23, ... | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.IO; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public class LoadImageExample | ||
{ | ||
public static void LoadImage() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What does this example do? This looks to only demonstrate how to load images into the pipeline - it would be good to mention that. #Resolved |
||
{ | ||
var mlContext = new MLContext(); | ||
|
||
// Downloading a few images, and an images.tsv file, that contains a list of the files, from the dotnet/machinelearning/test/data/images/ | ||
// if you inspect the fileSystem, after running this line, the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here #Resolved |
||
var imagesDataFile = SamplesUtils.DatasetUtils.DownloadImages(); | ||
|
||
// Preview of the content of the images.tsv file | ||
// | ||
// imagePath imageType | ||
// tomato.bmp tomato | ||
// banana.jpg banana | ||
// hotdog.jpg hotdog | ||
// tomato.jpg tomato | ||
|
||
var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments() | ||
{ | ||
Columns = new[] | ||
{ | ||
new TextLoader.Column("ImagePath", DataKind.TX, 0), | ||
new TextLoader.Column("Name", DataKind.TX, 1), | ||
} | ||
}).Read(imagesDataFile); | ||
|
||
var imagesFolder = Path.GetDirectoryName(imagesDataFile); | ||
// Image loading pipeline. | ||
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageReal", "ImagePath")); | ||
var transformedData = pipeline.Fit(data).Transform(data); | ||
|
||
// The transformedData IDataView contains the loaded images now | ||
//Preview of the transformedData | ||
var transformedDataPreview = transformedData.Preview(); | ||
|
||
// Preview of the content of the images.tsv file | ||
// The actual images, in the ImageReal column are of type System.Drawing.Bitmap. | ||
// | ||
// ImagePath Name ImageReal | ||
// tomato.bmp tomato {System.Drawing.Bitmap} | ||
// banana.jpg banana {System.Drawing.Bitmap} | ||
// hotdog.jpg hotdog {System.Drawing.Bitmap} | ||
// tomato.jpg tomato {System.Drawing.Bitmap} | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.IO; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Samples.Dynamic | ||
{ | ||
public class ResizeImageExample | ||
{ | ||
public static void ResizeImage() | ||
{ | ||
var mlContext = new MLContext(); | ||
|
||
// Downloading a few images, and an images.tsv file, that contains a list of the files, from the dotnet/machinelearning/test/data/images/ | ||
// if you inspect the fileSystem, after running this line, the | ||
var imagesDataFile = SamplesUtils.DatasetUtils.DownloadImages(); | ||
|
||
// Preview of the content of the images.tsv file | ||
// | ||
// imagePath imageType | ||
// tomato.bmp tomato | ||
// banana.jpg banana | ||
// hotdog.jpg hotdog | ||
// tomato.jpg tomato | ||
|
||
var data = mlContext.Data.CreateTextLoader(new TextLoader.Arguments() | ||
{ | ||
Columns = new[] | ||
{ | ||
new TextLoader.Column("ImagePath", DataKind.TX, 0), | ||
new TextLoader.Column("Name", DataKind.TX, 1), | ||
} | ||
}).Read(imagesDataFile); | ||
|
||
var imagesFolder = Path.GetDirectoryName(imagesDataFile); | ||
// Image loading pipeline. | ||
var pipeline = mlContext.Transforms.LoadImages(imagesFolder, ("ImageReal", "ImagePath")) | ||
.Append(mlContext.Transforms.Resize("ImageReal", imageWidth: 100, imageHeight: 100)); | ||
|
||
|
||
var transformedData = pipeline.Fit(data).Transform(data); | ||
|
||
// The transformedData IDataView contains the loaded images now | ||
//Preview of the transformedData | ||
var transformedDataPreview = transformedData.Preview(); | ||
|
||
// Preview of the content of the images.tsv file | ||
// The actual images, in the ImageReal column are of type System.Drawing.Bitmap. | ||
// | ||
// ImagePath Name ImageReal | ||
// tomato.bmp tomato {System.Drawing.Bitmap} | ||
// banana.jpg banana {System.Drawing.Bitmap} | ||
// hotdog.jpg hotdog {System.Drawing.Bitmap} | ||
// tomato.jpg tomato {System.Drawing.Bitmap} | ||
|
||
} | ||
} | ||
} |
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.
It would be great to have a description about this example. #Resolved