Movatterモバイル変換


[0]ホーム

URL:


Skip to main contentSkip to in-page navigation

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

ImageClassificationTrainer Class

Definition

Namespace:
Microsoft.ML.Vision
Assembly:
Microsoft.ML.Vision.dll
Package:
Microsoft.ML.Vision v4.0.1
Package:
Microsoft.ML.Vision v1.4.0
Package:
Microsoft.ML.Vision v1.5.5
Package:
Microsoft.ML.Vision v1.6.0
Package:
Microsoft.ML.Vision v1.7.0
Package:
Microsoft.ML.Vision v2.0.1
Package:
Microsoft.ML.Vision v3.0.1
Package:
Microsoft.ML.Vision v5.0.0-preview.1.25125.4
Source:
ImageClassificationTrainer.cs
Source:
ImageClassificationTrainer.cs
Source:
ImageClassificationTrainer.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

TheIEstimator<TTransformer> for training a Deep Neural Network(DNN) to classify images.

public sealed class ImageClassificationTrainer : Microsoft.ML.Trainers.TrainerEstimatorBase<Microsoft.ML.Data.MulticlassPredictionTransformer<Microsoft.ML.Vision.ImageClassificationModelParameters>,Microsoft.ML.Vision.ImageClassificationModelParameters>
type ImageClassificationTrainer = class    inherit TrainerEstimatorBase<MulticlassPredictionTransformer<ImageClassificationModelParameters>, ImageClassificationModelParameters>
Public NotInheritable Class ImageClassificationTrainerInherits TrainerEstimatorBase(Of MulticlassPredictionTransformer(Of ImageClassificationModelParameters), ImageClassificationModelParameters)
Inheritance

Remarks

To create this trainer, useImageClassification.

Input and Output Columns

The input label column data must bekey type and the feature column must be a variable-sized vector ofByte.

This trainer outputs the following columns:

Output Column NameColumn TypeDescription
ScoreVector ofSingleThe scores of all classes.Higher value means higher probability to fall into the associated class. If the i-th element has the largest value, the predicted label index would be i.Note that i is zero-based index.
PredictedLabelkey typeThe predicted label's index. If its value is i, the actual label would be the i-th category in the key-valued input label type.

Trainer Characteristics

Machine learning taskMulticlass classification
Is normalization required?No
Is caching required?No
Required NuGet in addition to Microsoft.MLMicrosoft.ML.Vision and SciSharp.TensorFlow.Redist / SciSharp.TensorFlow.Redist-Windows-GPU / SciSharp.TensorFlow.Redist-Linux-GPU
Exportable to ONNXNo

Using TensorFlow based APIs

In order to run any TensorFlow based ML.Net APIs you must first add a NuGet dependencyon the TensorFlow redist library. There are currently two versions you can use. One which iscompiled for GPU support, and one which has CPU support only.

CPU only

CPU based TensorFlow is currently supported on:

  • Linux
  • MacOS
  • Windows

To get TensorFlow working on the CPU only all that is to take a NuGet dependency onSciSharp.TensorFlow.Redist v1.14.0

GPU support

GPU based TensorFlow is currently supported on:

  • Windows
  • LinuxAs of now TensorFlow does not support running on GPUs for MacOS, so we cannot support this currently.

Prerequisites

You must have at least one CUDA compatible GPU, for a list of compatible GPUs seeNvidia's Guide.

InstallCUDA v10.1 andCUDNN v7.6.4.

Make sure you install CUDA v10.1, not any other newer version.After downloading CUDNN v7.6.4 .zip file and unpacking it, you need to do the following steps:

copy <CUDNN_zip_files_path>\cuda\bin\cudnn64_7.dll to <YOUR_DRIVE>\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin

For C/C++ development:

Copy <CUDNN_zip_files_path>\cuda\ include\cudnn.h to <YOUR_DRIVE>\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include

Copy <CUDNN_zip_files_path>\cuda\lib\x64\cudnn.lib to <YOUR_DRIVE>\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64

For further details in cuDNN you can follow thecuDNN Installation guide.

Usage

To use TensorFlow with GPU support take a NuGet dependency on the following package depending on your OS:

  • Windows -> SciSharp.TensorFlow.Redist-Windows-GPU
  • Linux -> SciSharp.TensorFlow.Redist-Linux-GPU

No code modification should be necessary to leverage the GPU for TensorFlow operations.

Troubleshooting

If you are not able to use your GPU after adding the GPU based TensorFlow NuGet,make sure that there is only a dependency on the GPU based version. If you havea dependency on both NuGets, the CPU based TensorFlow will run instead.

Training Algorithm Details

Trains a Deep Neural Network(DNN) by leveraging an existing pre-trained model such as Resnet50 for the purposeof classifying images. The technique was inspired fromTensorFlow's retrain image classification tutorial

Fields

FeatureColumn

The feature column that the trainer expects.

(Inherited fromTrainerEstimatorBase<TTransformer,TModel>)
LabelColumn

The label column that the trainer expects. Can benull, which indicates that labelis not used for training.

(Inherited fromTrainerEstimatorBase<TTransformer,TModel>)
WeightColumn

The weight column that the trainer expects. Can benull, which indicates that weight isnot used for training.

(Inherited fromTrainerEstimatorBase<TTransformer,TModel>)

Properties

Info

Auxiliary information about the trainer in terms of its capabilitiesand requirements.

Methods

Finalize()
Fit(IDataView, IDataView)

Trains aImageClassificationTrainer using both training and validation data,returns aImageClassificationModelParameters.

Fit(IDataView)

Trains and returns aITransformer.

(Inherited fromTrainerEstimatorBase<TTransformer,TModel>)
GetOutputSchema(SchemaShape)(Inherited fromTrainerEstimatorBase<TTransformer,TModel>)

Extension Methods

AppendCacheCheckpoint<TTrans>(IEstimator<TTrans>, IHostEnvironment)

Append a 'caching checkpoint' to the estimator chain. This will ensure that the downstream estimators will be trained againstcached data. It is helpful to have a caching checkpoint before trainers that take multiple data passes.

WithOnFitDelegate<TTransformer>(IEstimator<TTransformer>, Action<TTransformer>)

Given an estimator, return a wrapping object that will call a delegate onceFit(IDataView)is called. It is often important for an estimator to return information about what was fit, which is why theFit(IDataView) method returns a specifically typed object, rather than just a generalITransformer. However, at the same time,IEstimator<TTransformer> are often formed into pipelineswith many objects, so we may need to build a chain of estimators viaEstimatorChain<TLastTransformer> where theestimator for which we want to get the transformer is buried somewhere in this chain. For that scenario, we can through thismethod attach a delegate that will be called once fit is called.

Applies to

In this article