<!--
{
  "availability" : [
    "macOS: 10.15.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLObjectDetector/DataSource",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Create ML",
      "CreateML"
    ],
    "preciseIdentifier" : "s:8CreateML16MLObjectDetectorV10DataSourceO"
  },
  "title" : "MLObjectDetector.DataSource"
}
-->

# MLObjectDetector.DataSource

A data source for an object detector.

```
enum DataSource
```

## Overview

You use a data source to specify the training dataset for an [`MLObjectDetector`](/documentation/CreateML/MLObjectDetector) training session. An
object-detector data source represents a set of images and an annotation for each object in an image.

Each object annotation consists of the object’s name, or *label*, and its location in the image. A single image
can have multiple objects and, therefore, multiple annotations. For example, you can train an object detector
with images of dining tables, along with annotations for bananas, croissants, and beverages. Each image can
have one or more instances of an object, or any combination of objects.

## Topics

### Creating a data source

[`case directoryWithImagesAndJsonAnnotation(at: URL)`](/documentation/CreateML/MLObjectDetector/DataSource/directoryWithImagesAndJsonAnnotation(at:))

An object-detector data source you create by selecting a directory that contains image files and exactly
one JSON annotation file.

[`case directoryWithImages(at: URL, annotationFile: URL)`](/documentation/CreateML/MLObjectDetector/DataSource/directoryWithImages(at:annotationFile:))

An object-detector data source you create by selecting the location of a directory of image files, and the
location of a JSON annotation file.

[`case table(MLDataTable, imageColumn: String, annotationColumn: String)`](/documentation/CreateML/MLObjectDetector/DataSource/table(_:imageColumn:annotationColumn:))

An object-detector data source you create with a data table.

### Getting the annotated file names

[`func gatherAnnotatedFileNames() throws -> DataFrame`](/documentation/CreateML/MLObjectDetector/DataSource/gatherAnnotatedFileNames())

Processes the data source and returns a data frame that contains file URLs and annotations.

### Getting the data frame

[`case frame(DataFrame, imageColumn: String, annotationColumn: String)`](/documentation/CreateML/MLObjectDetector/DataSource/frame(_:imageColumn:annotationColumn:))

Data specified by a `DataFrame` containing a column for image file paths and a column with annotations.

### Retrieving the data

[`func imagesWithObjectAnnotations() throws -> MLDataTable`](/documentation/CreateML/MLObjectDetector/DataSource/imagesWithObjectAnnotations())

Generates a data table where each row represents an image, and its columns are the image file URLs and its
annotations.

### Splitting the data

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

Generates a new data table by splitting the data source using the specified proportions.



---

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)