Enumeration

MLObjectDetector.DataSource

A data source for an object detector.

Declaration

enum MLObjectDetector.DataSource

Overview

Use an object detector data source to specify the directory that contains the training data to create an MLObjectDetector. The given directory must contain image files and exactly one JSON file with annotations for objects within those images.

The base of the JSON file must contain an array of the following JSON object structure.

Name

Type

Value

imagefilename

String

The name of the image’s file.

annotation

Array

An array of annotation JSON objects.

Each JSON object in the annotation array must have the following JSON object structure.

Name

Type

Value

label

String

The name of the annotated object.

coordinates

JSON object

The location of the object and the area it occupies in the image.

Lastly, the coordinate JSON object must have the following structure. The origin of the image is the upper-left corner. The x-values increase from left to right and the y-values increase from the top to the bottom.

Name

Type

Value

x

Number

The x-coordinate of the annotation’s origin, which is defined by MLObjectDetector.Origin.

y

Number

The y-coordinate of the annotation’s origin, which is defined by MLObjectDetector.Origin.

width

Number

The width of the annotation’s bounding box.

height

Number

The height of the annotation’s bounding box.

As an example, the following JSON file has correct structure with one image file ("cat and dog.jpg") in its base array, which has two annotations.

// JSON file
[
  {
    "imagefilename": "cat and dog.png",
    "annotation":
    [
      {
        "label": "cat",
        "coordinates":
        {
          "y": 2.0,
          "x": 3.9,
          "height": 40.1,
          "width": 20.0
        }
      }, {
        "label": "dog",
        "coordinates":
        {
          "y": 40.0,
          "x": 38.9,
          "height": 100.1,
          "width": 70.0
        }
      }
    ]
  },
  ...
]

A typical annotation JSON file has many more objects in its base array, one for each image file.

Topics

Creating a Data Source

case directoryWithImagesAndJsonAnnotation(at: URL)

The location of a directory that contains image files and exactly one corresponding JSON file with object annotations.

case directoryWithImages(at: URL, annotationFile: URL)

The location of a directory of image files, and the location of a corresponding JSON file with object annotations.

Retrieving the Data

func imagesWithObjectAnnotations() -> MLDataTable

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

See Also

Creating and Training an Object Detector

enum MLObjectDetector.AnnotationType

The available types of image annotations.

struct MLObjectDetector.ModelParameters

Parameters that affect the process of training an object detection model.

let modelParameters: MLObjectDetector.ModelParameters

The configuration parameters that the object detector used for training during initialization.