Initializer

init(featureExtractor:validationData:maxIterations:augmentationOptions:)

Creates a new set of image classifier parameters with validation data represented by a data source.

Declaration

init(featureExtractor: MLImageClassifier.FeatureExtractorType = .scenePrint(revision: 1), validationData: MLImageClassifier.DataSource, maxIterations: Int = 25, augmentationOptions: MLImageClassifier.ImageAugmentationOptions = [])

Parameters

featureExtractor

A versioned feature extractor.

validationData

Data to be used for validation in the form of an MLImageClassifier.DataSource instance. If your data is stored in a dictionary, use init(featureExtractor:validationData:maxIterations:augmentationOptions:) instead.

Set this parameter to nil to tell the classifier to set aside a small, random subset of your training data to be used as validation data.

maxIterations

The maximum number of iterations to use during training.

augmentationOptions

The variations that the training process uses to generate more data from the training data you provide. For example, you can tell the training process to supplement your training data set with rotated versions of your original images using the rotation option.

Discussion

The example below shows how to create a model with the crop augmentation option that trains for 20 iterations, and that relies on validation data stored as labeled files in a Validation directory within your Downloads directory.

guard let downloadsURL = FileManager.default.urls(for: .downloadsDirectory, 
                                                  in: .userDomainMask).first
    else { fatalError("Can't find Downloads directory") }
let url = downloadsURL.appendingPathComponent("Validation")

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

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

See Also

Creating Parameters