Enumeration

MLImageClassifier.DataSource

A data source for an image classifier.

Declaration

enum MLImageClassifier.DataSource

Overview

Use a data source to provide training or testing data to an image classifier.

To train a model programmatically with an MLImageClassifier instance, initialize a data source with the URL of the directory that contains the data. Use either MLImageClassifier.DataSource.labeledDirectories(at:) or MLImageClassifier.DataSource.labeledFiles(at:) to do this, depending on whether your images are grouped by directory or by file name. See the respective creation methods for details about how to arrange your image files in each case.

When you train a model using MLImageClassifierBuilder, you don’t initialize a data source directly. Instead, you drag the directory containing your data from a Finder window into the live view. The builder automatically chooses the correct kind of data source based on how your images are arranged inside that directory, looking for either labeled directories or labeled files.

Topics

Creating a Data Source

case labeledDirectories(at: URL)

An image classifier data source that uses the directory structure to label images.

case labeledFiles(at: URL)

An image classifier data source that uses file names to label images.

Retrieving the Data

func labeledImages() -> [String : [URL]]

Returns the labeled images represented by the data source.

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.

struct MLImageClassifier.ModelParameters

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

let modelParameters: MLImageClassifier.ModelParameters

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