Structure

MLImageClassifier.ModelParameters

Parameters that affect the process of training an image classification model.

Declaration

struct MLImageClassifier.ModelParameters

Overview

Use this structure to configure the model training process. You can control parameters like the number of iterations used during training, the kinds of augmentation applied to the training data, and the version of the feature extractor. You can also provide validation data through the parameters if you don’t want the model to randomly select validation data from the training data set automatically.

The example below shows how to create a model with the crop augmentation option that trains for 20 iterations, and that allows the classifier to randomly select validation data from your training data.

let parameters = MLImageClassifier.ModelParameters(featureExtractor: .scenePrint(revision: 1),
                                                   validationData: nil,
                                                   maxIterations: 20,
                                                   augmentationOptions: [.crop])

Alternatively, you can supply explicit validation data in the form of either a dictionary or a data source, as demonstrated in the discussions of the init(featureExtractor:validationData:maxIterations:augmentationOptions:) and init(featureExtractor:validationData:maxIterations:augmentationOptions:) methods respectively.

Provide the resulting parameters structure to either the init(trainingData:parameters:) method (if your training data is represented by a data source) or the init(trainingData:parameters:) method (if your training data is represented by a dictionary) when creating your model.

Topics

Specifying Iterations

var maxIterations: Int

The maximum number of iterations used during training.

Specifying a Feature Extractor

var featureExtractor: MLImageClassifier.FeatureExtractorType

The underlying base model used to extract image features, during the training of an image classifier model.

enum MLImageClassifier.FeatureExtractorType

The underlying base model that extracts image features during training.

Adding Augmentation

var augmentationOptions: MLImageClassifier.ImageAugmentationOptions

The variations that the training process applies to your training data to generate more training data.

struct MLImageClassifier.ImageAugmentationOptions

The variations that the training process can use to generate more training data from the training data you provide.

Validating the Model

var validationData: [String : [URL]]?

A set of images that the training process uses for validation.

Deprecated

Describing Parameters

var description: String

A text representation of the model parameters.

var debugDescription: String

A text representation of the model parameters that’s suitable for output during debugging.

var playgroundDescription: Any

A description of the model parameters shown in a playground.

See Also

Creating and Training an Image Classifier

init(trainingData: [String : [URL]], parameters: MLImageClassifier.ModelParameters)

Creates a classifier from a training set represented by a dictionary.

init(trainingData: MLImageClassifier.DataSource, parameters: MLImageClassifier.ModelParameters)

Creates a classifier from a training set represented by a data source.

enum MLImageClassifier.DataSource

A data source for an image classifier.

let modelParameters: MLImageClassifier.ModelParameters

The configuration parameters that the image classifier used for training during initialization.