Initializer

init(featureExtractor:validationData:maxIterations:augmentationOptions:)

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

Declaration

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

Parameters

featureExtractor

A versioned feature extractor.

validationData

Data to be used for validation stored as a dictionary using labels for keys, and arrays of image URLs as the corresponding values. If your data is stored in an MLImageClassifier.DataSource instance, 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 explicit validation data stored 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")

// Assumes we're training for Elephants and Giraffes.
let validationData = ["Elephant": [url.appendingPathComponent("Elephant.1.jpg"),
                                   url.appendingPathComponent("Elephant.2.jpg")],
                      "Giraffe": [url.appendingPathComponent("Giraffe.1.jpg"),
                                  url.appendingPathComponent("Giraffe.2.jpg")]]

let parameters = MLImageClassifier.ModelParameters(featureExtractor: .scenePrint(revision: 1),
                                                   validationData: validationData,
                                                   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