Creates a classifier from a training set represented by a dictionary.
- macOS 10.14+
- Xcode 10.0+
- Create ML
The labeled images that you use to train the model. The keys of this dictionary represent the labels, while the values hold arrays of images that correspond to the given label.
Parameters that you use to configure model training.
When you create an
MLImage instance, initialize it with an
MLImage structure. This allows you to configure the image classifier training process. For example, you can explicitly define the validation data set instead of allowing the model to choose a random selection of your training data. Alternatively, as shown in the following example, set
nil to allow the classifier to choose the validation data for you from among your training data. This lets you set other parameters—like maximum iterations and augmentation options—to non-default values:
For this particular initialization method—there’s another with the same signature but a different training data type—represent your training data with a dictionary that uses labels as keys. The corresponding values are arrays of URLs that indicate the images associated with that label. In this example, if you have elephant and giraffe images stored in a directory called
Training within your
Downloads directory, you can construct a dictionary with the URL of each image:
Use the parameter structure and training data to initialize the classifier. Training begins immediately.