Glass Defect Detection with Roboflow Vision AI
Published Aug 6, 2026 • 8 min read
SUMMARY

Computer vision can detect glass defects (scratches, chips, blemishes, cracks) across diverse production contexts, from solar panel glass to bottle manufacturing to windshield production, by learning from labeled examples rather than relying on fixed rules. This guide covers the full pipeline: collecting assembly-line images, annotating defects in Roboflow, training an object detection model, and deploying it with Roboflow Inference to flag defective glass in real time.

A small defect in a glass product can be easy to miss, but catching these imperfections is an important part of the manufacturing process. Cracks, scratches, and other surface defects can be difficult to identify consistently, especially when large numbers of products need to be inspected.

Computer vision provides a way to automate this inspection process. By analyzing images of glass, an object detection model can identify defects and locate them within the image, helping manufacturers detect imperfections more consistently without relying entirely on manual inspection.

In this tutorial, we will build a glass defect detection system using Roboflow. We will train an RF-DETR object detection model to identify cracks, scratches, inclusions, and bubbles in glass, then use the trained model in a Roboflow Workflow to detect and visualize these defects in new images.

What Are Glass Defects?

Glass can develop a variety of defects during manufacturing and handling. Some may affect the appearance of the finished product, while others can compromise its quality. For this project, we will focus on four types of defects: cracks, scratches, inclusions, and bubbles.

  • Cracks: Breaks or fractures that form within or across the surface of the glass. They can vary in length and shape depending on how the glass was damaged.
  • Scratches: Visible marks or lines on the surface of the glass. They can vary in length, shape, and visibility depending on the lighting and severity of the defect.
  • Inclusions: Foreign particles or unwanted material trapped within the glass. These can appear as small spots or irregular shapes inside the glass.
  • Bubbles: Small pockets of trapped gas within the glass that appear as circular or rounded imperfections.

These defects can be difficult to identify consistently with manual inspection, particularly when they are small or subtle. An object detection model can help by learning the visual characteristics of each defect and locating them within an image.

Building a Glass Defect Detection System

With the different types of defects defined, we can now build a model that can identify them automatically. We'll use Roboflow to prepare the dataset, train an RF-DETR object detection model, and build a Workflow that can detect cracks, scratches, inclusions, and bubbles in new images.

Step 1: Log in to Roboflow

Start by signing in to your Roboflow account. If you don't have an account yet, you can create one for free.

Step 2: Fork the Glass Defect Dataset

Instead of collecting and annotating glass images from scratch, we'll use an existing dataset from Roboflow Universe. Open the Glass Defect Detection2 dataset in Roboflow Universe.

The dataset contains 578 images annotated with four types of glass defects: crack, scratch, inclusion, and bubble. These classes give the model examples of several different types of imperfections that can occur in glass.

To add the dataset to your workspace, click Fork Dataset on the dataset page. Choose the workspace where you want to use the dataset, then confirm the fork.

Once the dataset is in your workspace, we can create a version with the preprocessing, dataset split, and augmentation settings we'll use for training.

Step 3: Train the RF-DETR Model

With the dataset now in our workspace, we're ready to set up the model that will detect the different glass defects. Open the project and select Train, then choose Custom Training as the training engine.

For the model architecture, select RF-DETR and choose the Small model size. RF-DETR is a real-time object detection model that can be fine-tuned on custom datasets, making it a good fit for this scenario.

Before starting the training run, we'll configure the dataset version, including the image split, preprocessing, and augmentation settings. These settings control which images are used for training and evaluation, as well as how the images are prepared before being passed to the model.

Step 4: Set Up the Dataset Split

The dataset is divided into three groups: training, validation, and test.

The training set is used to teach the RF-DETR model how to recognize the four types of glass defects. The validation set is used during training to monitor how well the model performs on images it hasn't trained on. Finally, the test set is kept separate and can be used to get a final measure of how the trained model performs on unseen images.

For this project, we'll use 70% of the images for training, 20% for validation, and 10% for testing. This gives the model most of the available data to learn from while still keeping separate images for validation and final evaluation.

Once the split is configured, we can move on to preparing the images with preprocessing and augmentation.

Step 5: Configure Preprocessing and Augmentation

With the dataset split configured, the next step is to prepare the images for training. Roboflow provides preprocessing and augmentation tools that let us standardize the images and introduce realistic variations into the training data.

For preprocessing, enable Auto-Orient and set Resize to Stretch to 512×512. Auto-Orient ensures that images are consistently oriented before training, while resizing gives the model a fixed image size to work with.

For augmentation, set Outputs per training example to 3 and apply horizontal and vertical flips, a rotation range of -15° to +15°, brightness between -15% and +15%, and exposure between -10% and +10%.

These augmentations expose the model to variations in orientation and lighting that it may encounter when analyzing glass in different conditions. Keeping the changes relatively moderate also helps preserve the small visual details that distinguish cracks, scratches, inclusions, and bubbles.

Once these settings are configured, click Start Training to begin training the model.

Step 6: Evaluate the Model

Once training is complete, Roboflow provides several metrics that help us understand how well the RF-DETR model is detecting glass defects. For this project, the model achieved the following results on the validation set:

MetricScore
mAP@5072.8%
Precision78.7%
Recall70.0%
F174.1%

The model achieved a mAP@50 of 72.8%, showing that it was able to identify and localize the different glass defect classes with reasonable accuracy.

The 78.7% precision indicates that most of the defects predicted by the model were correct, while the 70.0% recall shows that it was able to detect most of the actual defects in the validation images.

The model also achieved an F1 score of 74.1%, which reflects the balance between precision and recall.

Since this project is intended as a demonstration, the model could be further improved with more training images, greater variation in defect appearances, and additional examples under different lighting and glass conditions.

With the model trained and evaluated, we can now connect it to a Roboflow Workflow and test its predictions on new images.

Step 7: Build the Glass Defect Detection Workflow

Now that our model has been trained, we can use it to inspect new glass images. We'll create a Roboflow Workflow that takes an image, sends it through our RF-DETR model, and produces an annotated image showing any defects that were detected.

From your Roboflow workspace, open Workflows and select Create Workflow. Choose a blank Workflow, which will give you the Input and Output blocks that we'll build around.

We'll use three additional blocks in between these two. The Object Detection Model will generate the predictions, the Bounding Box Visualization will show where those predictions are located, and the Label Visualization will identify the type of defect.

The resulting Workflow will take a glass image and return an annotated version showing the defects detected by our model.

Block 1: Object Detection Model

The first part of the pipeline is the model itself. Add an Object Detection Model block and connect the Image Input from the Input block to its image input.

From the model settings, select the RF-DETR model we trained earlier. The block will process the image and return the detected regions along with their predicted classes and confidence scores.

For Confidence Mode, select Best (Recommended). This uses Roboflow's recommended confidence threshold for the model. You can switch to Custom later if you want to control the threshold yourself.

Block 2: Bounding Box Visualization

Once we have the model's predictions, we can draw them directly onto the original image. Add a Bounding Box Visualization block and provide it with both the original image and the predictions from the Object Detection Model.

The output will place a bounding box around each region identified as a potential defect. This gives us a quick visual way to check where the model is making its predictions.

Block 3: Label Visualization

A bounding box tells us where a defect was found, but not what kind of defect it is. The Label Visualization block adds that information to the image.

Connect the image produced by the Bounding Box Visualization block to the Label Visualization block. Then pass the predictions from the Object Detection Model into it.

For the Text setting, select Class. The resulting image will display the predicted class next to each detection, allowing us to distinguish between crack, scratch, inclusion, and bubble.

Step 8: Test the Workflow

With the Workflow assembled, we can see how the model performs on images it hasn't encountered during training.

Select Test in the upper-right corner of the Workflow editor and upload a glass image. After running the Workflow, the output should contain bounding boxes and labels for any defects detected by the model.

0:00
/0:36

Try several images with different defect types and positions to get a better idea of how the model behaves. If the model produces predictions that are too broad or misses detections, the confidence threshold can be adjusted in the Object Detection Model block.

You can try the complete Glass Defect Detection Workflow here.

Glass Defect Detection Conclusion

In this tutorial, we built a glass defect detection system using RF-DETR and a dataset containing four types of defects: crack, scratch, inclusion, and bubble. We prepared the dataset, trained the model, and connected it to a Roboflow Workflow that can detect and visualize these defects in new glass images.

This provides a simple starting point for automating visual inspection of glass products. With a larger and more diverse dataset, the system could be trained to handle a wider range of defect appearances and inspection conditions.

The same approach could also be extended to a production environment, where cameras continuously monitor glass products on a manufacturing line and automatically flag defective products for further inspection.

Cite this Post

Use the following entry to cite this post in your research:

Yajat Mittal. (Aug 6, 2026). Glass Inspection with Computer Vision. Roboflow Blog: https://blog.roboflow.com/glass-inspection-with-computer-vision/

Written by

Yajat Mittal
Contributor @ Roboflow