Pre-trained models do not always match what your app needs to recognize. You do not need TensorFlow, Caffe, or a data science team to fix that. Apple's Create ML lets you train your own image classifier with a drag-and-drop interface (or a few lines of Swift) right inside Xcode. This tutorial covers both approaches, using a real example: teaching a model to recognize different dim sum dishes.
What Is Create ML?
Create ML is Apple's built-in tool for training machine learning models without writing a traditional ML pipeline. It first shipped inside Playgrounds with Xcode 10 and became a standalone app starting with Xcode 11. Unlike frameworks such as TensorFlow or Caffe, which require substantial code and have no visual interface, Create ML lets you import training data and get a working model with minimal setup.
Create ML supports training models across several data types, including:
- Images: image classification and recognition
- Text: sentiment and category classification
- Tabular data: structured data prediction
- Sound: audio classification
- Activity: motion/activity recognition
This tutorial focuses on the first: training your own image classifier.
When Do You Need a Custom Model?
Pre-trained models cover a lot of ground, but they have real gaps. Two common triggers for building your own:
- The category doesn't exist yet: no available model can distinguish specific cuisines, product variants, or niche object types your app cares about.
- The category is incomplete: general-purpose models often top out around 1,000 recognizable object classes, which means newer or more specific objects (a HomePod, a specific product SKU) simply aren't covered.
If no existing model fits your use case, training your own is the only path forward, and Create ML makes that far more approachable than it sounds.
The General Workflow for Training an ML Model
Regardless of which tool you use, custom model training follows the same loop:
- Collect data: gather examples of what you want the model to recognize.
- Train the model on that data.
- Evaluate the model against data it hasn't seen, and check whether the accuracy is good enough.
- Iterate: if accuracy is unsatisfactory, collect more data, adjust parameters, and retrain.
- Export the finished model and integrate it into your app.
Everything below is this loop applied to a concrete example.
What You'll Need
- Xcode installed on a Mac (Create ML is bundled in, no separate install required)
- A set of labeled training images
- A separate set of labeled testing images
Step 1: Prepare Your Training and Testing Data
Data collection is the real first step of any ML project. For an image classifier, that means photos, organized in a specific folder structure that Create ML expects.
You need two separate datasets:
- A training folder, used to teach the model.
- A testing folder, used afterward to evaluate how well it actually learned.
Inside each folder, create one sub-folder per category, and name each sub-folder exactly the label you want the model to predict (e.g., Steamed Shrimp Dumpling, Steamed Meat Ball). Drop the relevant images directly into their matching sub-folder. Create ML uses the folder names themselves as the classification labels. There's no separate label file to maintain.
How many images do you need? More is generally better, but Apple's own guidance suggests at least 10 images per category as a baseline, ideally shot from multiple angles and against different backgrounds. Varied angles and backgrounds specifically help the model generalize instead of learning to recognize a background instead of the object itself.
Step 2: Train the Model Using the Create ML App
With your data organized, open Create ML from Xcode → Open Developer Tool → Create ML, then choose File → New Project.
- Select the Image Classification template.
- Name the project (e.g.,
DimSumClassifier), and optionally set an author and description. - In the builder UI, set the Training Data field to point at your training folder.
- Leave Validation Data set to automatic. Create ML will hold out a portion of the training data for this itself.
- Set Testing Data to point at your separate testing folder.
You generally don't need to touch advanced settings like maximum iterations or augmentations for a first pass. The defaults are a reasonable starting point.
Click the Play button to start training. Create ML will report a training accuracy, which should typically land at or near 100%. If it's noticeably lower, that usually means the tool couldn't extract a clear, distinguishing visual feature from some of your images, a sign the training data itself may need cleanup.
Step 3: Evaluate Testing Accuracy
Training accuracy tells you how well the model fit the data it trained on, but it doesn't tell you how well it generalizes. That's what the testing accuracy is for: Create ML runs the model against your separate testing folder (images it has never seen) and reports how often its predictions were correct.
It's completely normal for testing accuracy to be meaningfully lower than training accuracy. A 100% training accuracy paired with a 71% testing accuracy, for example, isn't a bug. It's the model doing well on familiar data but revealing real limits on unfamiliar data.
If testing accuracy isn't good enough, you have two main levers:
- Add more training data, ideally covering more variety (angles, lighting, backgrounds).
- Adjust training parameters, such as the number of iterations.
Step 4: Preview and Export the Model
Before exporting, use the Preview tab to sanity-check the model informally: drag and drop any test image onto the pane and see what label it predicts. This is a fast way to build intuition about where the model is strong or weak before committing to an export.
Once you're satisfied with the result, go to the Output tab and click Get to save the .mlmodel file. You can rename the exported model file directly in the project navigator if you'd like a more descriptive name than the default.
From here, integrating the model into an app is straightforward: swap it in wherever you'd use any other Core ML image model. For example, dropping DimSumClassifier.mlmodel in place of a general-purpose model like MobileNetV2.mlmodel in an existing image recognition app immediately gives that app the ability to recognize your custom categories.
Alternative: Training the Model Programmatically
The visual builder is the quickest way to get started, but it's not the only option, and for many developers, it is not the preferred one long-term. Training programmatically lets you automate the entire process: update your training and testing folders, re-run a script, and get a fresh model without touching a UI.
Open a new Blank Playground under macOS, and use the following:
import CreateML
import Foundation
let trainingDir = URL(fileURLWithPath: "/path/to/DimSum/training")
let testingDir = URL(fileURLWithPath: "/path/to/DimSum/testing")
// Train the model
let model = try MLImageClassifier(trainingData: .labeledDirectories(at: trainingDir))
// Evaluate the trained model with test data
let evaluation = model.evaluation(on: .labeledDirectories(at: testingDir))
// Export the model
try model.write(to: URL(fileURLWithPath: "/path/to/DimSumImageClassifier"))
This mirrors the visual workflow exactly, just in code:
.labeledDirectories(at:)tellsMLImageClassifierto read the same folder-per-label structure you used in the app, with no extra configuration needed.- Calling the initializer directly trains the model against your training directory.
evaluation(on:)runs the trained model against your testing directory and returns accuracy metrics, the programmatic equivalent of the testing accuracy screen in the app.write(to:)exports the finished.mlmodelfile to disk.
Running this in a Playground streams status messages and validation accuracy to the console as training progresses, finishing with the exported model file at your specified path.
Once your folder structure is set, the scripted approach becomes fully repeatable. Update the training data, re-run, and get a new model with zero manual clicking. That is a real advantage if you retrain regularly as you collect more images.
Summary
Training a custom image classifier with Create ML follows a simple, repeatable loop: organize labeled images into training and testing folders, train the model (visually or programmatically), evaluate its accuracy on unseen data, and export it once you are satisfied. What used to require a dedicated machine learning toolchain now fits into either a few clicks in an Xcode-bundled app or a handful of lines of Swift.
Frequently Asked Questions
How is training accuracy different from testing accuracy? Training accuracy measures how well the model fits the data it trained on (often close to 100%). Testing accuracy measures performance on separate, unseen images and is a more realistic indicator of how the model will perform in your actual app.
How many training images do I need per category? Apple recommends at least 10 images per category as a starting point. More, especially with varied angles and backgrounds, generally improves accuracy.
Do I need to write any code to train an image classifier with Create ML? No. The Create ML app provides a fully visual, drag-and-drop workflow. Code (MLImageClassifier) is only needed if you want to automate training programmatically.
Can I reuse this process for categories other than images? The overall workflow of collecting data, training, evaluating, and exporting is the same across Create ML's supported types (text, tabular data, sound, activity), though the specific data format and class used (MLTextClassifier for text, for example) differs.