<!--
{
  "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/labeledDirectories(at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Case",
  "symbol" : {
    "kind" : "Case",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML17MLImageClassifierV10DataSourceO18labeledDirectoriesyAE10Foundation3URLV_tcAEmF"
  },
  "title" : "MLImageClassifier.DataSource.labeledDirectories(at:)"
}
-->

# MLImageClassifier.DataSource.labeledDirectories(at:)

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

```
case labeledDirectories(at: URL)
```

## Discussion

Use this case to create a data source based on a directory structure on disk that contains your training
images. The associated value is a URL that represents a directory with subdirectories that are named as the
labels for your images. Each subdirectory should contain the images associated with the label for which
that subdirectory is named.

For example, you might initialize a data source with a file URL that indicates a directory called
`Training Data` that contains subdirectories called `Elephant` and `Cheetah`. The subdirectory `Cheetah`,
in turn, contains images of cheetahs, with names like `Image001.png`, `Image02.jpg`, and so on, while the
subdirectory `Elephant` contains images of elephants, called `Image545.jpg`, `Image657.png`, and so on. The
individual image names aren’t important in this case because the directory that an image appears in
indicates the image’s label.

![Diagram showing a directory called “Training Data” containing subdirectories, that are named using the](images/com.apple.createml/MLImageClassifier-DataSource-labeledDirectories(at:)-1@2x.png)

If you want to create a data source with labels based on file names, use
[`MLImageClassifier.DataSource.labeledFiles(at:)`](/documentation/CreateML/MLImageClassifier/DataSource/labeledFiles(at:)) instead.

---

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)