OnnxCatalog.DnnFeaturizeImage 메서드

정의

미리 학습된 DNN 모델 DnnImageModelSelector 중 하나를 적용하여 이미지를 특징으로 하는 만들기 DnnImageFeaturizerEstimator

public static Microsoft.ML.Transforms.Onnx.DnnImageFeaturizerEstimator DnnFeaturizeImage (this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, Func<Microsoft.ML.Transforms.Onnx.DnnImageFeaturizerInput,Microsoft.ML.Data.EstimatorChain<Microsoft.ML.Transforms.ColumnCopyingTransformer>> modelFactory, string inputColumnName = default);
static member DnnFeaturizeImage : Microsoft.ML.TransformsCatalog * string * Func<Microsoft.ML.Transforms.Onnx.DnnImageFeaturizerInput, Microsoft.ML.Data.EstimatorChain<Microsoft.ML.Transforms.ColumnCopyingTransformer>> * string -> Microsoft.ML.Transforms.Onnx.DnnImageFeaturizerEstimator
<Extension()>
Public Function DnnFeaturizeImage (catalog As TransformsCatalog, outputColumnName As String, modelFactory As Func(Of DnnImageFeaturizerInput, EstimatorChain(Of ColumnCopyingTransformer)), Optional inputColumnName As String = Nothing) As DnnImageFeaturizerEstimator

매개 변수

catalog
TransformsCatalog

변환의 카탈로그입니다.

outputColumnName
String

의 변환에서 생성된 열의 이름입니다 inputColumnName.

modelFactory
Func<DnnImageFeaturizerInput,EstimatorChain<ColumnCopyingTransformer>>

패키지에 DnnImageModelSelector 포함된 특정 모델이 해당 확장 메서드와 함께 포함된 두 OnnxScoringEstimator 체인(전처리용 및 미리 학습된 이미지 DNN이 있는 체인)을 만드는 확장 메서드입니다.

inputColumnName
String

변환할 열의 이름입니다. 이 값으로 null설정하면 해당 값이 outputColumnName 원본으로 사용됩니다.

반환

예제

using System.IO;
using System.Linq;
using Microsoft.ML;
using Microsoft.ML.Data;

namespace Samples.Dynamic
{
    public static class DnnFeaturizeImage
    {
        public static void Example()
        {
            // Create a new ML context, for ML.NET operations. It can be used for
            // exception tracking and logging, as well as the source of randomness.
            var mlContext = new MLContext();

            // Downloading a few images, and an images.tsv file, which contains a
            // list of the files from the dotnet/machinelearning/test/data/images/.
            // If you inspect the fileSystem, after running this line, an "images"
            // folder will be created, containing 4 images, and a .tsv file
            // enumerating the images. 
            var imagesDataFile = Microsoft.ML.SamplesUtils.DatasetUtils
                .GetSampleImages();

            // Preview of the content of the images.tsv file, which lists the images
            // to operate on
            //
            // imagePath    imageType
            // tomato.bmp   tomato
            // banana.jpg   banana
            // hotdog.jpg   hotdog
            // tomato.jpg   tomato

            var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
            {
                Columns = new[]
                {
                        new TextLoader.Column("ImagePath", DataKind.String, 0),
                        new TextLoader.Column("Name", DataKind.String, 1),
                }
            }).Load(imagesDataFile);

            var imagesFolder = Path.GetDirectoryName(imagesDataFile);

            // Installing the Microsoft.ML.DNNImageFeaturizer packages copies the models in the
            // `DnnImageModels` folder. 
            // Image loading pipeline. 
            var pipeline = mlContext.Transforms.LoadImages("ImageObject",
                imagesFolder, "ImagePath")
                .Append(mlContext.Transforms.ResizeImages("ImageObject", imageWidth:
                    224, imageHeight: 224))
                .Append(mlContext.Transforms.ExtractPixels("Pixels", "ImageObject"))
                .Append(mlContext.Transforms.DnnFeaturizeImage("FeaturizedImage",
                    m => m.ModelSelector.ResNet18(mlContext, m.OutputColumn, m
                    .InputColumn), "Pixels"));

            var transformedData = pipeline.Fit(data).Transform(data);

            var FeaturizedImageColumnsPerRow = transformedData.GetColumn<float[]>(
                "FeaturizedImage").ToArray();

            // Preview of FeaturizedImageColumnsPerRow for the first row,
            // FeaturizedImageColumnsPerRow[0]
            //
            // 0.696136236
            // 0.2661711
            // 0.440882325
            // 0.157903448
            // 0.0339231342
            // 0
            // 0.0936501548
            // 0.159010679
            // 0.394427955

        }
    }
}

적용 대상