How to Implement Object Detection Step by Step
Object detection finds and locates things in images and video. Here is how to pick an approach, prepare the data and ship a working system.
On this page
Short answer
To implement object detection, define what the system must find and how fast it must answer, then choose between a ready-made cloud API and a model you train yourself. Label a few hundred to a few thousand example images, train or configure the model, measure precision and recall on a held-out test set, and only then connect it to your product.
What is object detection?
Object detection is the task of finding things in an image or a video frame and saying where each one is. A detection system returns a label, such as car or person, and a box drawn around each instance it found.
It differs from image classification, which only says what is in a picture as a whole. Detection says what is there and where it is, which is why it is used for counting, tracking and safety checks. A warehouse system does not just need to know that a photo contains boxes; it needs to know how many boxes there are and where each one sits on the shelf.
Most detection systems run on a model that was trained on labelled examples. The model learns what a target looks like from many examples, then applies that learning to new images it has never seen.
Which detection approach fits your use case?
The right approach depends on speed, accuracy, cost and how unusual your targets are. There is no single best choice for every job.
| Approach | How it works | Best for | Watch out for |
|---|---|---|---|
| Cloud API | Send images to a vendor service | Common objects, fast start | Per-image cost, data leaves your site |
| One-stage model | One pass finds boxes and labels | Real-time video, edge devices | Lower accuracy on small objects |
| Two-stage model | First finds regions, then classifies them | High accuracy, offline review | Slower, needs more compute |
| Fine-tuned model | A ready model retrained on your data | Unusual targets, your own products | Needs labelled data and testing |
If your targets are everyday objects like people, cars and boxes, start with a cloud API or a ready model. If your targets are your own products, parts or defects, plan to fine-tune, because no ready model will know them.
How do you prepare the data?
Data preparation decides the result more than the choice of model. A good dataset is a set of images that look like the ones the system will see in production, each with a box drawn around every target.
Start with 500 to 2,000 images for a simple job, and more if the scene changes a lot. Include the hard cases: poor light, partial views, crowded scenes and the background without any target at all. A dataset that only shows clean examples teaches the model to fail on the messy ones.
Label every target in every image, and label consistently. If one labeller draws a tight box and another draws a loose one, the model learns both and its accuracy suffers. Write a short labelling guide with examples, and check a sample of each labeller's work before they label the whole set.
Split the data into three sets: training, validation and a held-out test set the model never sees during training. The test set is the only honest measure of how the system will behave on new images.
What are the implementation steps?
Implementation follows a fixed order. Skipping the early steps is the usual reason a project runs late.
- Write down what the system must find, how fast it must answer, and what happens when it misses or mislabels a target.
- Pick the approach from the table above, based on speed, accuracy and whether your targets are common or unusual.
- Collect and label the dataset, and split it into training, validation and test sets.
- Train or configure the model, and check it on the validation set as you go.
- Measure precision and recall on the held-out test set, and fix the worst failures by adding examples of them to the data.
- Connect the model to your product behind a simple interface, and log every result with its confidence score.
- Watch the first weeks of live results, and set a review routine so drift in the images is caught early.
Keep a human in the loop for the first release. A review step that catches the model's mistakes early also gives you the examples you need to improve it.
Example (hypothetical): a warehouse shelf check
Example (hypothetical): a warehouse wants to check that each shelf holds the right products. A camera takes one photo per shelf, 960 photos a day, and the detection system must find empty slots and wrong products.
The team labels 1,200 photos: 800 for training, 200 for validation and 200 for the test set. On the test set the model finds 184 of 200 empty slots, which is 92%, and it flags 12 slots wrongly out of 200, which is a 6% false alarm rate.
Checking by hand took a worker about 2 minutes per photo, so 960 photos took 960 x 2 = 1,920 minutes, or 32 hours a day across the team. With the system, a worker only reviews the 60 flagged photos, which takes 60 x 5 = 300 minutes, or 5 hours. The team saves about 27 hours a day and catches empty slots the same day instead of the next.
How do you measure whether it works?
Two numbers matter most. Precision is the share of the model's detections that are correct. Recall is the share of the real targets the model found. A system can be precise but miss half the targets, or find everything and flag half the background as well.
Report both numbers on the held-out test set, not on the training data. Training numbers always look better, because the model has seen those images before.
Also measure speed and cost in production: how many images per second the system handles, how long each answer takes, and what each thousand images costs to run. A model that is accurate but too slow for the camera feed is not a working system.
For the cost side of the decision, object detection cost breaks down the build and running costs.
The wider project budget is covered in computer vision cost.
Common mistakes
The most common mistake is training on clean images and testing on messy ones. If the production camera is dirty, dark or tilted, the training images must be dirty, dark and tilted too.
The second mistake is judging the model on the training set. A model that scores well on images it has already seen tells you nothing about new images, so always keep a held-out test set.
The third mistake is ignoring the false alarms. A system that flags 200 shelves a day when only 20 are wrong will be switched off by the team that has to check them, however good its recall is.
The fourth mistake is treating detection as a one-off project. Cameras move, products change and light changes with the season. Plan a monthly review of live results and a small labelling budget to keep the model current.
Key takeaways
- Object detection returns a label and a box for each thing it finds.
- Start with a cloud API for common objects; fine-tune for your own products.
- Data quality matters more than the choice of model.
- Measure precision and recall on a held-out test set.
- Keep a human review step for the first release.
Frequently asked questions
What is object detection used for?
Object detection is used to count, locate and track things in images and video. Common uses are warehouse shelf checks, quality inspection on production lines, traffic counting, retail shelf monitoring and safety checks on sites where people and machines work together.
How many labelled images do I need?
For a simple job with a few target types, 500 to 2,000 labelled images is a reasonable start. Harder jobs with many target types, varied light or crowded scenes need more. What matters most is that the images match the ones the system will see in production.
Should I use a cloud API or train my own model?
Use a cloud API when your targets are common objects and you want to start fast. Train or fine-tune your own model when the targets are your own products, parts or defects, or when images cannot leave your site. Many teams start with an API and fine-tune later.
What is the difference between precision and recall?
Precision is the share of the model's detections that are correct, so it measures false alarms. Recall is the share of real targets the model found, so it measures misses. A good system needs both to be high, and the right balance depends on whether a miss or a false alarm costs more.
How fast does object detection need to be?
It depends on the job. A video feed usually needs 10 to 30 frames per second, while a photo check can take a second or two per image. Measure the speed on the same hardware the system will run on, because a model that is fast on a server may be slow on a camera device.
Do I need a GPU to run object detection?
For training, yes in practice, because training on a CPU is far too slow for most jobs. For running the finished model, a GPU helps for video but is not always needed: small models run on CPUs and on edge devices, and cloud APIs run the model for you.