Mastering CreateML: From Data Prep to Object Detection Models on iOS

This article introduces Apple’s CreateML tool, explains its supported model types, shows how to prepare and augment data, provides a Node.js script for generating synthetic training sets, and walks through training, testing, and integrating an object‑detection model into an iOS app.

ELab Team
ELab Team
ELab Team
Mastering CreateML: From Data Prep to Object Detection Models on iOS

What is CreateML

CreateML is a tool released by Apple at WWDC 2018 that generates Core ML models from user‑provided data for iOS development.

CreateML Model List

Image Classification

Object Detection

Style Transfer

Hand Pose & Hand Action

Action Classification

Activity Classification

Sound Classification

Text Classification

Word Tagging

Tabular Classification & Regression

Recommendation

CreateML Model Trial

The script below synthesises a large synthetic dataset by randomly placing and rotating source images on a coloured canvas, generating corresponding annotation files in CreateML format.

// import sharp from "sharp";
import { createCanvas, Image } from "@napi-rs/canvas";
import { promises } from "fs";
import fs from "fs";
import path from "path";
import Sharp from "sharp";

const IMAGE_GENERATED_COUNT_PER_CLASS = 5;
const MAX_NUMBER_OF_CLASSES_IN_SINGLE_IMAGE = 10;
const CANVAS_WIDTH = 1024;
const CANVAS_HEIGHT = 800;
const CONCURRENT_PROMISE_SIZE = 50;

// ... (rest of the script omitted for brevity) ...

Data Preparation

For object‑detection, CreateML expects an annotations.json file that lists each image, the label of every object, and the bounding‑box coordinates (x, y, width, height).

Enough data is crucial; examples of public datasets include Stanford Cars (≈16 k images) and Food‑41 (≈6 GB). The script above can generate hundreds of megabytes of synthetic images to augment limited real data.

Model Training

In CreateML, select the generated dataset and start training. The Object Detection model is based on YOLO V2; training on an M1 Pro takes roughly 10 hours, longer on Intel CPUs.

Model Testing

After training, drag any image onto the CreateML preview window to see detection results.

Using the Model in iOS

Apple provides a Vision demo for live object recognition. A minimal SwiftUI demo is shown below.

// ContentView.swift
import SwiftUI
import Vision

class MyVNModel: ObservableObject {
    static let shared = MyVNModel()
    @Published var parsedModel: VNCoreMLModel? = nil
    var images: [UIImage]? = nil
    var observationList: [[VNObservation]]? = nil
    // ... (model loading and inference code omitted for brevity) ...
}

struct ContentView: View {
    @State var showSheet: SheetType? = nil
    @ObservedObject var viewModel = MyVNModel.shared
    // UI for picking a photo and displaying results
}

Running Result

iOSdata augmentationobject detectionSwiftCreateML
ELab Team
Written by

ELab Team

Sharing fresh technical insights

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.