<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 10.14.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLImageClassifier/DataSource",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Create ML",
      "CreateML"
    ],
    "preciseIdentifier" : "s:8CreateML17MLImageClassifierV10DataSourceO"
  },
  "title" : "MLImageClassifier.DataSource"
}
-->

# MLImageClassifier.DataSource

A data source for an image classifier.

```
enum DataSource
```

## Overview

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

To train a model programmatically with an [`MLImageClassifier`](/documentation/CreateML/MLImageClassifier) instance, initialize a data source with the URL
of the directory that contains the data. Use either [`MLImageClassifier.DataSource.labeledDirectories(at:)`](/documentation/CreateML/MLImageClassifier/DataSource/labeledDirectories(at:)) or
[`MLImageClassifier.DataSource.labeledFiles(at:)`](/documentation/CreateML/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)`](/documentation/CreateML/MLImageClassifier/DataSource/labeledDirectories(at:))

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

[`case labeledFiles(at: URL)`](/documentation/CreateML/MLImageClassifier/DataSource/labeledFiles(at:))

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

### Retrieving the data

[`func labeledImages() throws -> [String : [URL]]`](/documentation/CreateML/MLImageClassifier/DataSource/labeledImages())

Returns the labeled images represented by the data source.

[`case filesByLabel([String : [URL]])`](/documentation/CreateML/MLImageClassifier/DataSource/filesByLabel(_:))

Dictionary of labels to file URLs.

### Splitting the data

[`func stratifiedSplit(proportions: [Double], seed: Int) throws -> [[String : [URL]]]`](/documentation/CreateML/MLImageClassifier/DataSource/stratifiedSplit(proportions:seed:))

Generates an array of labeled image dictionaries by splitting the data source into strata.

[`func stratifiedSplit<RNG>(proportions: [Double], generator: inout RNG) throws -> [[String : [URL]]]`](/documentation/CreateML/MLImageClassifier/DataSource/stratifiedSplit(proportions:generator:))

Generates an array of labeled image dictionaries by splitting the data source into strata using the
random-number generator.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)