---
title: MLImageClassifier.DataSource
framework: createml
role: symbol
role_heading: Enumeration
path: createml/mlimageclassifier/datasource
---

# MLImageClassifier.DataSource

A data source for an image classifier.

## Declaration

```swift
enum DataSource
```

## Mentioned in

Creating an Image Classifier Model

## Overview

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

- [MLImageClassifier.DataSource.labeledDirectories(at:)](createml/mlimageclassifier/datasource/labeleddirectories(at:).md)
- [MLImageClassifier.DataSource.labeledFiles(at:)](createml/mlimageclassifier/datasource/labeledfiles(at:).md)

### Retrieving the data

- [labeledImages()](createml/mlimageclassifier/datasource/labeledimages().md)
- [MLImageClassifier.DataSource.filesByLabel(_:)](createml/mlimageclassifier/datasource/filesbylabel(_:).md)

### Splitting the data

- [stratifiedSplit(proportions:seed:)](createml/mlimageclassifier/datasource/stratifiedsplit(proportions:seed:).md)
- [stratifiedSplit(proportions:generator:)](createml/mlimageclassifier/datasource/stratifiedsplit(proportions:generator:).md)

## Relationships

### Conforms To

- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Supporting types

- [MLImageClassifier.ModelParameters](createml/mlimageclassifier/modelparameters-swift.struct.md)
- [MLImageClassifier.FeatureExtractorType](createml/mlimageclassifier/featureextractortype.md)
- [MLImageClassifier.CustomFeatureExtractor](createml/mlimageclassifier/customfeatureextractor.md)
- [MLImageClassifier.ImageAugmentationOptions](createml/mlimageclassifier/imageaugmentationoptions.md)
