Synthetic data for computer vision
The three ways to make synthetic images, the depth, segmentation and motion files a simulator writes for each frame, when synthetic data is worth using, and how to measure how much a model loses on real photos.
Synthetic data is images that are created or altered by a program instead of photographed. Some cases a model has to handle come up too rarely to photograph often enough, and some labels are too slow or impossible for a person to draw. A program can produce both. A model trained on synthetic images can also score well on them and much worse on real photos, so the useful part is knowing where synthetic data helps and how to measure what it costs.
Three kinds of synthetic images
There are three main ways to make images that were not captured by a camera:
- Simulation: a renderer builds a 3D scene and draws images of it. You choose the objects and the lighting, and you decide how many rare cases to produce.
- Compositing: photos of real objects are cut out and pasted onto new backgrounds. The result can look pasted, because the object's edges and lighting do not match the new background.
- Generated images: images from a generative model, which is a model trained to produce new images. They can look real, and they give you less control over exactly what is in them.

The labels a simulator writes out
A renderer places every object in the scene itself, so it knows the scene exactly. It knows the class of every pixel, how far each surface is from the camera and where the camera stands. It can write all of that to disk next to the image. One rendered frame can come with these files:
frame_00042.png # the rendered RGB image
frame_00042_depth.npy # (H, W) float, meters from the camera
frame_00042_seg.png # (H, W) uint8, class id per pixel
frame_00042_flow.npy # (H, W, 2) float, pixel motion to next frame
frame_00042_pose.json # camera position and orientationH and W are the image's height and width in pixels. Each file holds one kind of label:
- The depth file has one number per pixel, the distance from the camera in meters.
- The segmentation file has one class id per pixel. The id is a small integer that says whether that pixel is road, tree, sky or another class.
- The flow file has two numbers per pixel. They say how far that pixel moves sideways and up or down by the next frame, which is often called optical flow.
- The pose file gives the camera's position and the direction it points.
All four are exact. On real footage, depth needs a separate sensor and segmentation takes minutes of tracing per frame. Labeling the motion of every pixel by hand is not practical.

When synthetic data helps
Synthetic data is worth reaching for in a few situations:
- Rare events that real data has too few images of.
- Dangerous events that cannot be staged for a photo, such as a person stepping in front of a moving car.
- Privacy-restricted domains, where real images of people or patients cannot be collected or shared.
- Labels you want to control, such as exactly which objects appear and how many of each.
- Expensive annotation, such as per-pixel segmentation of thousands of frames.
Use it to fill specific gaps in the real data, and check the result on real images.

The sim-to-real gap
Rendered images differ from photographs in ways a model can pick up on. That difference is called the sim-to-real gap. Renderers only approximate four things: sensor noise, real lighting, how materials reflect light and natural motion blur. They also assume perfect focus and clean edges, with no dust on the lens.
A model can learn to rely on these rendering cues. It then does well on rendered images and worse on real ones. Ten times more rendered images does not close the gap when every one of them is missing the same real-world details.

Measuring the drop on real photos
For example, take a classifier that spots defects on machine parts and was trained only on rendered parts. It scores 0.97 on a held-out set of rendered images and 0.71 on a small set of real photos. The drop is
$$0.97 - 0.71 = 0.26$$
The 0.71 is what the model does on the job, and the 0.26 is how much the rendered test score overstates it. Rendering ten times more images raised the scores to 0.98 and 0.72. The drop stayed at 0.26, because sensor noise and real material shading were still missing from every render.

Keep a set of real images to test any model trained on synthetic data. It can be small, as long as it comes from the place the model will be used.
Common mistakes
- Testing only on rendered images. A score of 0.97 on renders says little about real photos.
- Rendering more of the same images to close the gap. Ten times more renders moved the real score from 0.71 to 0.72.
- Using synthetic data in place of real data. It works best for the specific gaps the real data has, such as rare or dangerous cases.
- Trusting a generated image to contain what its label says. Generative models give less control over what is in the image, so look at a sample.
- Ignoring how composites look. Pasted objects with mismatched edges and lighting can teach the model to look for the paste.
Related concepts
The sim-to-real gap is one case of a broader problem, a mismatch between training images and the images a model sees in use. Domain shift in computer vision covers that mismatch and how to find it by breaking results down by slice. Pseudo-labeling and weak labels is another way to get labels without drawing each one by hand, using a model's own predictions on real images.
QuiddityML teaches synthetic data in the vision data unit of its Computer Vision track, with multiple-choice questions on when a simulator can fill a gap that real photos cannot (QuiddityML).