Teacher-Student Training for Object Detection

Teacher-student training uses predictions from an existing model to help train another model. For object detection, the teacher identifies objects or defects and provides information about their classes and locations. The student learns from this information and then makes its own predictions on new images.
In manufacturing inspection, this approach can help prepare training data for tasks such as detecting defects on printed circuit boards (PCBs). A teacher model generates the initial bounding boxes, a reviewer checks the annotations, and a student detector trains on the reviewed dataset. The quality of those labels directly affects the examples the student learns from.
In this guide, we’ll use a published PCB defect detector as the teacher and RF-DETR Small as the student. We’ll explain hard and soft labels, compare general vision-language models with task-specific teachers, review label quality, and evaluate the student using Roboflow’s built-in tools. This follows the annotation-based approach used in the VLM distillation tutorial.
The setup
The setup has three main stages. The teacher generates annotations for the training images, a reviewer corrects those annotations, and the student trains on the resulting dataset. Validation and test images provide separate references for choosing settings and evaluating performance.
The teacher can be a task-specific object detector or a vision-language model (VLM), such as Gemini. In this example, we use a task-specific detector trained to identify PCB defects.

For this example, the PCB Dataset Defect project by Object Detection DT (opens in a new tab) includes both the images and a detector we can use as the teacher. The model, pcb-dataset-defect/1, recognizes six classes, missing_hole, mouse_bite, open_circuit, short, spur, and spurious_copper.

Dataset version 1 (opens in a new tab) contains 541 training images, 62 validation images, and 90 test images.
Prepare the images and teacher Workflow
- Create an object detection project for the student and copy the images from Universe. Import the 541 training images without annotations so the teacher can label them. Keep the original split assignments and annotations for validation and testing. Use the 62 validation images to choose settings and reserve the 90 test images for the final evaluation.
- Create a Workflow with an image input and an Object Detection Model block. Set the model ID to
pcb-dataset-defect/1and expose its detections as an output namedpredictions. This Workflow will provide the teacher’s bounding boxes and class labels. - Select the saved Workflow in Auto Label. Map all six output classes to the matching classes in your project. Preview several images to check the boxes and class mappings before labeling the batch. You can also use a Gemini VLM to generate bounding-box annotations instead of the PCB detector.

The dataset already contains annotations, which makes it useful for demonstrating this process. By withholding the training annotations from the teacher, you can generate a new set of proposed labels while retaining reviewed references for validation and testing.
Hard and soft labels for object detection
Hard and soft labels give the student different information about the same defect. Let’s use a spurious_copper region from the Spurious Copper project (opens in a new tab) as an example.
Hard labels
A hard label assigns one class to the bounding box, such as spurious_copper. The student learns to identify that defect and predict its location.
Even if the teacher returns a confidence score, saving its prediction as a standard annotation gives the student one class and a box. A teacher prediction used for training is called a pseudo-label (opens in a new tab).
Soft labels
A soft label keeps the teacher’s probabilities across classes. For the same box, imagine the teacher assigns 70% to spurious_copper, 20% to spur, and the remaining 10% across other defect classes.
The student learns to match these probabilities instead of learning only the selected class. This gives it information about the other classes the teacher considered. These probability distributions are called soft targets (opens in a new tab).

spurious_copper region.The image above shows the spurious_copper box with two class targets.
- The hard label is a one-hot target.
spurious_coppergets1and every other class gets0. - The soft label (soft target) gives a probability to all six classes. The four other defect classes get low values. Each value is a probability between 0 and 1. In this example, the six values add up to 1.
The bounding box stays the same. Only the class information used to train the student changes. This tutorial trains the student with reviewed boxes and hard labels. Using soft targets requires a training method that explicitly learns from those probabilities.
Learning the box location
An object detector learns two things about a defect. It learns what the defect is and where it appears in the image. The class label identifies the defect, and the bounding box gives its location.
Soft class targets help the student learn the defect class. Teaching it where to place the box requires location information too. Some distillation methods use a separate training rule for this, such as teacher bounded loss (opens in a new tab).
In our setup, we review and adjust each box before training. For a spurious_copper defect, the corrected annotation tells the student which class to predict and where to place the bounding box.
Choosing the teacher
The teacher should identify the required defect classes accurately and produce annotations that are practical to review. For manufacturing inspection, compare a vision-language model (VLM) with a detector trained for the same type of part or defect.
A VLM can use written class descriptions to propose boxes, which can help when you have few labeled examples. A task-specific detector already has learned classes, such as the six PCB defect categories in this example. Both need to be tested on images that represent your inspection conditions.
| Teacher | How to try it | What to look for |
|---|---|---|
| General VLM | Give the Google Gemini v6 block (opens in a new tab) your class names and a short description of each defect. Use Object Detection mode to get boxes. | Check small defects and classes that look alike. The Auto Label guide (opens in a new tab) identifies specialized electronics defects as a difficult case for foundation models. |
| Task-specific detector | Run the published PCB detector through the Object Detection Model (opens in a new tab) block. | Check how well it works with your parts and lighting. The PCB model card (opens in a new tab) reports 91.2% recall on its benchmark. Measure recall separately on images from your line. |
Compare accuracy and review effort
Evaluate both teachers on the same validation images. Include good parts and examples of the defects that matter most. You can score the original predictions against an inspector’s labels in Workflow Evals (opens in a new tab).
Record missed defects, false detections, incorrect classes, and boxes that need adjustment. Then measure the time needed to correct each teacher’s annotations. For example, a teacher may detect a copper defect but confuse spur with short. Another may assign the correct class but miss smaller defects. These differences affect both label quality and review time.
Compare the total labeling cost
To compare cost per reviewed image, add the labeling charges, model usage costs, and cost of review time. Divide by the number of images reviewed. Auto Label (opens in a new tab) gives you an estimate before you run a job, and the Credit Usage audit log (opens in a new tab) shows recorded usage.

Gemini labeling can add token charges to the per-image credits. Compare what it costs to review a batch and how many critical defects each teacher finds.

Label quality checks before training
Teacher-generated labels need review before they become student training data. Incorrect classes, missing defects, and poorly placed boxes can become repeated errors in the training set. Review the full image first, then inspect each proposed annotation in more detail using Roboflow Annotate (opens in a new tab).
| Check | What to do |
|---|---|
| Missed defects and false alarms | Add boxes around missed defects and remove boxes around acceptable features, such as an undamaged copper trace. Review images that have no predictions too. |
| Class labels | Apply the same rule across the batch. For example, check the gap between two traces when deciding whether to label extra copper as a spur or a short. |
| Box boundaries | Follow the same convention for each defect. Enclose the visible defect region, such as the break in a trace. Remove duplicate boxes. |
| Coverage across splits | Use Dataset Health Check (opens in a new tab) to check class counts and look for missing annotations. Keep repeat photos of a part in the same split so it cannot appear in both training and testing. |
Use the same spurious_copper image to check label quality. Review the image first, then compare the box and class with the project’s reference annotation. The examples below show three annotation errors and their corrections. We added these errors by hand to illustrate each check. Follow these steps:
- Add a missing box: Check the whole image even when the teacher returns no detections. In the left example, the copper fragment is visible but has no box. Add a box around it and assign
spurious_copper. - Adjust a loose box: In the middle example, the box includes a large area around the defect. Bring its boundaries closer to the copper fragment, following the same convention as the reference annotation.
- Correct the class: In the right example, the box has the class
spur. The reference annotation identifies the region asspurious_copper. Check that the copper fragment is separate from the nearby tracks, then correct the class and review similar predictions in the batch.

Once review is complete, create a dataset version (opens in a new tab) and confirm the split assignments. Choose RF-DETR Small in Custom Training (opens in a new tab) and train the student on that version.
Evaluating the student
Student evaluation measures how well the trained model detects defects on images held back from training. Compare both the teacher and student against the same reviewed ground truth. With this comparison, you can check whether the student meets the inspection requirements and where its errors differ from the teacher’s. You can make this comparison using Workflow Evals (opens in a new tab).
- Prepare the two Workflows: Keep the teacher Workflow and build a second one for the trained RF-DETR Small model. Give both the same image input and a detection output called
predictions. Choose each model’s confidence threshold on the validation set and leave it fixed during the test. - Add the test images and ground truth: Use Create Eval under Workflows and Evals to start the comparison. In Upload Ground Truth, import the 90 test images and review their annotations before approving them. Mark boards that have no defects as having no objects so the evaluation can count false alarms on those boards. Follow the Workflow Evals setup (opens in a new tab) to prepare the cases.
- Define the detection checks: For a detection to count, its class has to match and the box has to overlap the inspector’s box enough. Set the intersection over union (IoU) threshold under Define Eval Checks. At 0.50, the area shared by the two boxes has to be at least half the area they cover together. Use the same matching rules for both models.
- Compare the results: Run both Workflows on the same cases and look at the results for each defect class. Recall (opens in a new tab) is the share of labeled defects the model found. Precision (opens in a new tab) is the share of its detections that were correct. Mean average precision (opens in a new tab) across IoU thresholds from 0.50 to 0.95 also takes into account how well the boxes match as the overlap requirement gets stricter. Use the Workflow comparison guide (opens in a new tab) to compare both models.
- Review the prediction errors: If the student often assigns
shortto aspur, choose that cell in the confusion matrix to see the images behind the error. If your workspace has full model evaluation, you can find the matrix under View Full Model Evaluation on the student’s model page. It combines validation and test images. Use the test-only Workflow Eval for your final comparison. The Model Evaluation guide (opens in a new tab) explains how to inspect these results.
For example, suppose the inspector labels 20 shorts and the student reports 25. If 18 predictions match different labeled shorts, recall is 90% and precision is 72%. That means the student missed two shorts and drew seven boxes that didn’t match. From those counts, you can estimate how many defects could get through and how many alerts an inspector might need to review.
Conclusion
Teacher-student training can help you build object detection models for manufacturing inspection. Use a teacher to generate labels, review them, and train a student to detect the defects that matter on your production line.
Start building with Roboflow and test your student on new inspection images to check its performance.