← Back to list

I Stopped Manual Labeling Forever: How Grounded-SAM and YOLO11 Changed My Workflow

I used to spend my weekends hunched over a monitor, clicking thousands of individual points just to draw a single bounding box around a…

Eran Feit in Object Detection tutorials · 2026-04-06 10:00 · 1 claps · 21.9 min read paywalled
#yolov11 #autodistill #segment-anything-model #object-detection #python
Open on Medium ↗

I Stopped Manual Labeling Forever: How Grounded-SAM and YOLO11 Changed My Workflow

I used to spend my weekends hunched over a monitor, clicking thousands of individual points just to draw a single bounding box around a moving object. It was a grueling, mind-numbing process that felt like a relic of a bygone era in AI development. If you’ve ever tried to build a custom computer vision model, you know that the “data bottleneck” is where most great ideas go to die. We have incredible architectures like YOLO11, but they are hungry for high-quality data — data that usually requires hundreds of hours of human labor to produce.

Everything changed when I discovered the synergy between Grounded-SAM and Autodistill. Instead of being the one drawing the boxes, I realized I could use a “Foundation Model” — a giant AI that already understands the world — to be the teacher. By implementing a workflow centered on automated data annotation, I was able to shift my role from a manual laborer to a high-level architect. I stopped wasting time on the “dirty work” and started focusing on what actually matters: solving the problem at hand.

This story is a technical walkthrough of how I built a “zero-effort” pipeline to detect bees and flowers in the wild. We start with nothing but raw video footage and end with a state-of-the-art YOLO11 model that is fast, accurate, and ready for the field. By leveraging automated data annotation, we can extract frames, let the AI generate its own labels with surgical precision, and then distill that knowledge into a lightweight model that runs in real-time. It’s a fundamental shift in how we approach the AI development lifecycle.

If you are a researcher, a student, or a developer tired of the manual grind, this guide is for you. I’m going to show you exactly how to set up your environment, define your own labeling logic, and watch as your dataset builds itself. By the time we reach the end, you’ll have a repeatable blueprint that you can apply to any object detection challenge, turning a month-long labeling project into a single afternoon of execution.

So, what’s the deal with automated data annotation anyway?

At its core, the primary target of this technology is the “human-in-the-loop” bottleneck that has slowed down AI progress for years. In the earlier days of deep learning, every single pixel and bounding box had to be verified and drawn by a human eye. Automated data annotation flips the script by using “Foundation Models” — massive AI models that already possess a deep understanding of the world — to teach smaller, more specialized models. Instead of you manually telling the computer where a bee is, you use a model like Grounded-SAM that already understands the concept of a “bee” to do the heavy lifting for you across thousands of images simultaneously.

The high-level magic happens through a process often referred to as model distillation. Large foundation models are incredibly smart but are often too slow or computationally expensive for real-time applications like tracking insects in a field. By using these heavy-duty models for automated data annotation, we can generate labels for an entire dataset in the time it would take a person to label just a handful of frames. This creates a high-quality “ground truth” dataset that captures the intelligence of a giant AI and packs it into a lean, lightning-fast architecture like YOLO11, giving you the best of both worlds: extreme accuracy and edge-ready speed.

What makes this approach particularly powerful in the current landscape of 2026 is the sheer surgical precision of the labels. We aren’t just talking about loose, sloppy boxes; we are generating semantic masks that understand the intricate boundaries of complex, organic objects. Modern automated data annotation tools can now handle difficult conditions like occlusion, motion blur, and varied lighting that used to render automation scripts useless. By setting up a robust ontology — a simple list of what you want the AI to find — you create a self-sustaining loop where the data labels itself and prepares itself for training with minimal human intervention.

This tutorial is designed to take you from a folder of raw, unlabeled video files to a fully functional, high-precision detection system without you ever having to draw a single bounding box. By leaning on the provided Python scripts, we are effectively building a bridge between massive foundational models and lean, edge-ready architectures. The code isn’t just a set of instructions; it’s an automated factory that processes video, generates high-fidelity labels, organizes a dataset, and executes a rigorous training loop. This approach ensures that your time is spent on high-level strategy and model evaluation rather than the tedious manual labor that usually stalls computer vision projects.

How This Script Actually Turns Your Videos into a Smart YOLO11 Model

Wait, can I use this code for objects other than bees and flowers?

Absolutely. The beauty of this script lies in the CaptionOntology section. By simply changing the text prompts—for example, changing "a bee" to "a forklift" or "a flower" to "a safety helmet"—Grounded-SAM will automatically adjust its focus. The logic remains identical regardless of the subject matter, making this a universal template for automated data annotation across any niche industry or research field.

The first phase of the code focuses on the “Data Extraction” layer, where we utilize the Supervision library to handle the heavy lifting of video processing. Instead of manually taking screenshots, the script uses a generator to systematically pull frames at a specific stride, ensuring we capture a diverse range of motion and angles from your bee footage. This step is crucial because the quality of your automated data annotation depends entirely on the clarity and variety of these initial images. By saving these as high-resolution PNGs, we provide the AI “teacher” with the best possible canvas to begin its work.

Once the frames are ready, the code transitions into the “Intelligence” layer using Grounded-SAM and Autodistill. This is where the automated data annotation truly happens. The script initializes a base model that uses natural language to “understand” what a bee looks like. It then iterates through your entire image directory, creating precise masks and labels for every instance it finds. This process generates a standardized YOLO-format dataset, complete with the necessary data.yaml configuration file, which acts as the roadmap for the upcoming training phase.

Verification is the next critical step in the code’s logic. We don’t just trust the AI blindly; the script includes a dedicated visualization block that shuffles your newly labeled data and plots a grid of annotated images. This allows you to see exactly what the “teacher” model saw — checking the tightness of the bounding boxes and the accuracy of the segmentation masks. This feedback loop is essential in automated data annotation because it ensures that any noise or false positives are identified before you commit hours to the training process.

Finally, the code initiates the “Distillation” phase, where the intelligence from the large Grounded-SAM model is transferred into the lightweight YOLO11 architecture. The script runs a 300-epoch training loop, optimized with specific hyperparameters like batch size and image resolution, to ensure the resulting model is both accurate and fast enough for real-time use. The final block of code then takes this “best.pt” weight file and runs it back against unseen test footage, completing the cycle from raw pixels to a self-aware detection system that can identify bees in the wild with incredible speed.

[embed]

Link to the video tutorial here .

Download the code for the tutorial here or here .

Best AI Photo Tools (Backgrounds, Objects, Headshots)

✅ Phot-AI packs more than 30 AI‑powered tools into one place — covering background and object removal/replacement, image extension and a suite of creative generators for art, icons and logos.

follow the link and start creating : https://phot.ai?ref=eran33

✅ Create and remix stunning AI art and photos with community-driven creativity. tap the link and start creating today! : https://www.remixai.io/?ref=eran

✅ PhotoGPT AI acts as your personal photographer — just describe what you need and the platform generates high‑quality headshots or casual images within minutes.

Its built‑in photo editor lets you remove objects, replace backgrounds and make studio‑quality corrections with a single click.

You can even train your own AI model using a few selfies, receive context‑aware prompt suggestions and upscale images for print‑ready results.

Dive into this all‑in‑one AI photo studio : https://www.photogptai.com/?ref=eran

My Blog

You can follow my blog here .

Link to the full post and code here : https://eranfeit.net/how-to-use-automated-data-annotation-for-yolo11/

Want to get started with Computer Vision or take your skills to the next level ?

Great Interactive Course : “Deep Learning for Images with PyTorch” here

If you’re just beginning, I recommend this step-by-step course designed to introduce you to the foundations of Computer Vision — Complete Computer Vision Bootcamp With PyTorch & TensorFlow

If you’re already experienced and looking for more advanced techniques, check out this deep-dive course — Modern Computer Vision GPT, PyTorch, Keras, OpenCV4

How to Use Automated Data Annotation for YOLO11

Building a high-performance computer vision pipeline in 2026 shouldn’t feel like a manual labor job from the last decade. This article is a comprehensive deep dive into bypassing the traditional “data bottleneck” by leveraging a sophisticated, code-driven workflow. We are exploring how to bridge the gap between raw video footage and a production-ready YOLO11 model by using automated data annotation. By integrating Grounded-SAM and Autodistill, we create a “teacher-student” dynamic where AI identifies objects like bees and flowers and labels them with surgical precision, effectively turning weeks of manual work into a few minutes of execution.

The primary hurdle in modern AI development isn’t the availability of neural networks; it’s the grueling process of generating high-quality training data. Most developers lose hundreds of hours to the “box-drawing” phase, which is often the graveyard of ambitious projects. Mastering automated data annotation allows you to reclaim that time, focusing instead on model optimization and real-world deployment. This workflow provides a massive competitive advantage, enabling you to iterate faster and train on much larger, more diverse datasets than would ever be possible through human labeling alone.

We achieve this result by breaking the process into a clear, modular technical stack designed for efficiency. First, we utilize Supervision to extract high-quality frames from raw video footage, ensuring our training samples are diverse and clear. Then, we deploy Grounded-SAM as the heavy-duty engine for automated data annotation, generating high-fidelity masks and bounding boxes based on simple text prompts. Finally, we feed this machine-labeled dataset into YOLO11, running a specialized training loop that distills the “knowledge” of the large foundation model into a fast, deployable detector.

Whether you are a researcher tracking biodiversity, a student building a portfolio project, or a developer tasked with a specialized industrial application, the techniques shared here represent the modern standard for AI development. Transitioning to automated data annotation isn’t just a convenience; it’s a fundamental shift in how we build computer vision models. By the end of this guide, you will have a fully functional detection model and a repeatable, “zero-effort” pipeline that you can apply to any object detection challenge you encounter in the future.

Building the Foundation with a Clean AI Environment

The first step in escaping the manual labeling trap is building a stable, isolated workspace. In the world of AI development, dependency conflicts are the fastest way to kill your momentum. By setting up a dedicated Conda environment, we ensure that our high-performance libraries — like PyTorch 2.9.1 and CUDA 12.8 — operate in a controlled sandbox. This foundational step is what makes the rest of our automated data annotation pipeline possible without a single installation error.

I’ve chosen to pin specific versions of the Ultralytics and Autodistill libraries to guarantee that the logic remains consistent over time. In 2026, where hardware moves fast, keeping your software stack lean and version-controlled is a superpower. This environment isn’t just about running code; it’s about creating a reliable engine that can handle the heavy mathematical lifting of processing high-resolution video frames and generating complex segmentation masks.

Once your environment is active, the installation process brings in everything from Transformers to OpenCV. These tools work in the background to handle data loading, model weight management, and visualization. Getting this setup right is like tuning a race car before the track opens — it’s the hidden work that ensures the automated data annotation phase runs at full speed without crashing.

Why do I need a specific Conda environment for this?

A Conda environment acts as a protected workspace that prevents your project’s libraries from conflicting with your computer’s global settings. Because this workflow relies on specific versions of CUDA and specialized AI frameworks, using an isolated environment ensures that your automated data annotation scripts remain stable and reproducible across different machines.

# Create conda enviroment 
### Create a new virtual environment named GroundedSam with Python 3.11
conda create --name GroundedSam python=3.11
### Activate the newly created environment
conda activate GroundedSam

### Check the installed NVIDIA Compiler version
nvcc --version

# Cuda 12.8 -> Pytorch 2.9.1
### Install PyTorch and related vision/audio libraries specifically for CUDA 12.8
pip install torch==2.9.1 torchvision==0.24.1 torchaudio==2.9.1 --index-url https://download.pytorch.org/whl/cu128      

# install YoloV11
### Install the Ultralytics library for YOLO11 training and inference
pip install ultralytics==8.3.50

# install more libraries :
### Install Autodistill core for the distillation process
pip install autodistill==0.1.29
### Install the Grounded-SAM plugin for Autodistill
pip install autodistill-grounded-sam==0.1.0
### Install the YOLO11 plugin for Autodistill
pip install autodistill-yolov11==0.1.4
### Install scikit-learn for data splitting and evaluation
pip install scikit-learn==1.6.1
### Install Roboflow for dataset management support
pip install roboflow==1.1.50

### Install Hugging Face Transformers for model weight management
pip install Transformers==4.29.2

### Install the headless version of OpenCV for image processing
pip install opencv-python==4.11.0.86

Want the original video files to follow along?

If you want to reproduce the same training flow and achieve the exact same detection results, I can share the raw training and test video files used in this tutorial. Send me an email and mention “Bee Detection YOLO11 Video Files” so I know what you’re requesting.

🖥️ Email: feitgemel@gmail.com

Extracting the Gold: Turning Video into Image Samples

Before the AI can start its labeling work, we need to transform our raw video footage into a high-quality image dataset. This is the “data mining” phase of the project. By using the Supervision library, we can programmatically walk through any video file and extract individual frames. This approach is far superior to manual screenshots because it allows us to control the exact “stride” — or the interval between frames — ensuring our dataset is diverse and free of redundant, identical images.

The code is designed to scan your directory for common video formats like MP4 and MOV, creating a clean list of files to process. We set a stride of 5, which strikes a perfect balance: it captures enough of the action to train a robust model but skips enough frames to keep the automated data annotation phase efficient. Each extracted frame is saved as a high-resolution PNG, preserving the fine details of the bees and flowers that the model will eventually learn to recognize.

This step effectively turns a single 60-second video into a rich library of training samples. By organizing these files into a specific directory, we create a structured input for the next phase of the pipeline. High-quality frame extraction is the secret sauce of a “zero-effort” workflow; it ensures that the labels generated later are based on the best possible visual evidence.

What is a FRAME_STRIDE and why should I use it?

A FRAME_STRIDE is the number of frames the code skips before saving a new image from the video. Using a stride prevents your dataset from being cluttered with thousands of nearly identical images, which speeds up the automated data annotation process and helps your final model learn to generalize better by seeing more varied perspectives.

### Import the OS library to handle file paths and directories
import os 

### Define the path where your raw video files are stored
VIDEO_DIR_PATH = "Best-Object-Detection-models/Yolo-V11/GroundedSAM-Auto-Annotation - Bees/Videos/Train videos" 
### Define the target path for the extracted images
IMAGE_DIR_PATH = "D:/Data-Sets-Object-Detection/Bees/images"
### Set the stride to save every 5th frame
FRAME_STRIDE = 5 

### Import supervision for video processing and tqdm for progress bars
import supervision as sv 
from tqdm import tqdm

### List all video files with mov or mp4 extensions in the source directory
video_paths = sv.list_files_with_extensions(
    directory=VIDEO_DIR_PATH,
    extensions=["mov","mp4"] )

### Print the list of found video paths
print(video_paths)

### Iterate through each video path found
for video_path in tqdm(video_paths) :
    ### Get the filename without the extension
    video_name = video_path.stem
    ### Create a naming pattern for the saved images
    image_name_pattern = video_name + "-{:05d}.png"

    ### Use ImageSink to save frames extracted from the video generator
    with sv.ImageSink(target_dir_path=IMAGE_DIR_PATH, image_name_pattern=image_name_pattern) as sink :
        for image in sv.get_video_frames_generator(source_path=str(video_path), stride=FRAME_STRIDE) :
            sink.save_image(image=image)

### Confirm completion of frame extraction
print("Done")

# Check the extracted images folder 
### List all successfully saved image files
image_paths = sv.list_files_with_extensions(
    directory=IMAGE_DIR_PATH,
    extensions=["png", "jpg", "jpeg"] )

### Print the total number of images extracted
print("Image Count : ", len(image_paths))

Defining the Mission: Natural Language Ontology

The most revolutionary part of this workflow is the CaptionOntology. In traditional labeling, you define a class and then manually show the computer what that class looks like. Here, we do the opposite. We use natural language to tell the AI what to find. By mapping a description like "a bee" to the label "bee," we are giving the Grounded-SAM model a set of visual instructions that it already knows how to follow based on its massive pre-training.

This phase is essentially the “intent” of your project. The ontology acts as a bridge between your human understanding of the world and the raw pixels of your images. Because Grounded-SAM understands complex semantic concepts, you can be as specific as you need to be. This flexibility is what makes automated data annotation a game-changer; it allows you to define custom classes for niche datasets without needing a team of humans to learn the difference between various species or industrial parts.

When we initialize the GroundedSAM base model and call the .label() method, the script begins a "zero-shot" detection sweep across your image folder. The AI "teacher" looks at every frame, finds the objects that match your ontology, and generates perfectly formatted YOLO labels. It even creates the data.yaml file, which is the final piece of the puzzle needed for training. You aren't just labeling data; you are creating a professional-grade dataset structure automatically.

Wait, can I use this code for objects other than bees and flowers?

Absolutely. The logic is entirely flexible. By simply changing the text prompts in the CaptionOntology section—for example, changing "a bee" to "a vehicle" or "a person"—the Grounded-SAM engine will immediately adjust its focus. This makes the code a universal template for automated data annotation that can be adapted to any industry, from agriculture to urban planning.

### Import CaptionOntology to define our object mapping
from autodistill.detection import CaptionOntology

# Define the Ontology 
### Map natural language descriptions to dataset class names
ontology = CaptionOntology({
    "a bee" : "bee",
    "a flower" : "flower"
})

# init the Base model 
### Set the paths for the input images and the target dataset output
IMAGE_DIR_PATH = "D:/Data-Sets-Object-Detection/Bees/images"
DATASET_DIR_PATH = "D:/Data-Sets-Object-Detection/Bees/dataset"

### Import GroundedSAM to use as the teacher model for auto-labeling
from autodistill_grounded_sam import GroundedSAM

### Initialize the model with the defined ontology
base_model = GroundedSAM(ontology=ontology)
### Run the labeling process on the image folder to generate the dataset
dataset = base_model.label(
    input_folder=IMAGE_DIR_PATH,
    output_folder=DATASET_DIR_PATH,
    extension='.png'
)

The AI Teacher: Grounded-SAM in Action

Now we reach the “intelligence” layer of the story. Grounded-SAM is a sophisticated foundation model that performs what we call “model-assisted labeling.” It doesn’t just guess where objects are; it calculates a segmentation mask for every detection, following the true organic outline of the bees and flowers. This high-fidelity approach ensures that the “ground truth” we generate is of the highest quality, often surpassing the consistency of human labelers who might get tired or sloppy after hours of work.

To ensure our automated data annotation is working as intended, the code includes a visualization block that pulls a random sample of the annotated images. We overlay bounding boxes, labels, and the generated masks directly onto the frames. This is a crucial sanity check. Seeing a 4x4 grid of perfectly outlined bees and flowers gives you the confidence that the AI teacher has correctly understood your ontology and is producing reliable data for your YOLO11 model.

This step is the bridge between the “teacher” (Grounded-SAM) and the “student” (YOLO11). We are taking the deep knowledge of a heavy, slow foundation model and preparing it to be “distilled” into a lightweight, fast model. By visualizing the results, we confirm that our dataset is clean, accurate, and ready for the final forge of training.

Can I trust the masks generated by Grounded-SAM?

Grounded-SAM is currently one of the most accurate zero-shot detection and segmentation models available. It excels at understanding complex boundaries and varied lighting. While it is incredibly reliable, using the visualization code to verify a random sample ensures that your automated data annotation process hasn’t encountered any unexpected edge cases in your specific footage.

### Import supervision for dataset visualization
import supervision as sv 
### Import Path for handling file system structures
from pathlib import Path
import random 

### Set paths to the training images and labels generated by the AI
ANNOTATIONS_DIRECTORY_PATH = "D:/Data-Sets-Object-Detection/Bees/dataset/train/labels"
IMAGES_DIRECTORY_PATH = "D:/Data-Sets-Object-Detection/Bees/dataset/train/images"
DATA_YAML_PATH = "D:/Data-Sets-Object-Detection/Bees/dataset/data.yaml"

# Display images 
### Load the generated dataset into memory for inspection
dataset = sv.DetectionDataset.from_yolo(
    images_directory_path=IMAGES_DIRECTORY_PATH,
    annotations_directory_path=ANNOTATIONS_DIRECTORY_PATH,
    data_yaml_path=DATA_YAML_PATH)

### Print the size of the annotated dataset
print(len(dataset))

### Define visual parameters for the inspection grid
SAMPLE_SIZE = 16
SAMPLE_GRID_SIZE = (4,4)
SAMPLE_PLOT_SIZE = (16,10)

### Initialize different annotators to visualize boxes, masks, and text
mask_annotator = sv.MaskAnnotator()
box_annotator = sv.BoxAnnotator()
label_annotator = sv.LabelAnnotator()

# Shuffle dataset and select random images
### Create a list of indices and shuffle them for a random sample
dataset_indices = list(range(len(dataset)))
random.shuffle(dataset_indices)

### Prepare lists to hold the annotated images and titles
images = [] 
images_names = []

### Loop through the random sample to apply annotations
for i in dataset_indices[:SAMPLE_SIZE] :
    image_path , image , annotation = dataset[i]

    annotated_image = image.copy() 
    ### Apply the segmentation mask to the image
    annotated_image = mask_annotator.annotate(
        scene=annotated_image,
        detections=annotation)

    ### Apply the bounding box to the image
    annotated_image = box_annotator.annotate(
        scene=annotated_image,
        detections=annotation)

    ### Apply the text label to the image
    annotated_image = label_annotator.annotate(
        scene=annotated_image,
        detections=annotation)

    ### Add the result to our lists for plotting
    images_names.append(Path(image_path).name)
    images.append(annotated_image)

### Plot the 4x4 grid of images to verify auto-labeling accuracy
sv.plot_images_grid(
    images=images,
    titles=images_names,
    grid_size=SAMPLE_GRID_SIZE,
    size=SAMPLE_PLOT_SIZE)

The Forge: Training a State-of-the-Art YOLO11 Model

This is where the magic of “Model Distillation” happens. We are taking the heavy intelligence of our auto-labeler and forging it into a lean, lightning-fast YOLO11 model. Because our automated data annotation has provided us with a high-quality, perfectly formatted dataset, the training process is straightforward and efficient. We are essentially distilling the “knowledge” of a giant foundation model into a compact architecture that can run on edge devices or in real-time applications.

The training script is set to run for 300 epochs, allowing the model to deeply understand the visual features of our bees and flowers. We use a batch size of 32 to optimize GPU throughput and set the image size to 640 for a good balance of detail and speed. The code also includes a patience parameter, which is a smart fail-safe: if the model stops improving for 40 consecutive epochs, the training will end early to prevent over-fitting and save time.

By the time the training completes, you will have a “best.pt” weights file. This file represents the culmination of the entire “zero-effort” workflow. It contains the refined intelligence of your auto-labeled data, compressed into a format that is ready for production. This phase turns your data “fuel” into a high-performance engine that can detect objects in the wild with incredible reliability.

What are epochs and why are we running 300 of them?

An epoch represents one complete pass of the entire dataset through the neural network. Running 300 epochs gives the YOLO11 model enough “practice” to minimize its errors and reach peak accuracy. It ensures that the model learns even the most subtle patterns in your automated data annotation results, making it much more robust in the field.

### Import the YOLO class from the ultralytics library
from ultralytics import YOLO

### Define the main training function
def main():
    # load the model
    ### Load a pre-trained small YOLO11 model as a starting point
    model = YOLO("yolo11s.pt")

    # load the data.yaml file
    ### Set the path to the configuration file generated during auto-labeling
    config_file_path = "D:/Data-Sets-Object-Detection/Bees/dataset/data.yaml"

    # Specify the output directory for storing the result 
    ### Define the project folder and experiment name for the training run
    project = "d:/temp/model/Bees-model"
    experiment = "Bees-small"

    ### Set the batch size for GPU processing
    batch_size = 32 # Reduce it to 16 if you have memory issues 

    # Train the model
    ### Execute the training loop with specific hyperparameters
    results = model.train( data=config_file_path,
                          epochs = 300,
                          project=project ,
                          name = experiment,
                          batch = batch_size ,
                          device = 0 ,
                          patience = 40 ,
                          imgsz=640 ,
                          verbose = True,
                          val= True)

### Ensure the main function runs only when the script is executed directly
if __name__ == "__main__":
    main()

Real-World Validation: Running the Final Test

The final chapter of our story is the “Moment of Truth.” We take the trained YOLO11 model and run it on brand-new, unseen video footage. This is the ultimate test of the automated data annotation pipeline. If the model can accurately track bees and identify flowers in a video it has never processed before, it proves that our automated labels were high-quality enough to teach a smaller model real-world intelligence.

The script uses OpenCV to process the input video frame-by-frame, running inference with your custom weights. We visualize the results live using a Matplotlib animation, which allows you to see the detection boxes and confidence scores as the video plays. This isn’t just a technical check; it’s the realization of the “zero-effort” dream — seeing your custom AI solve a complex visual task without you ever having to pick up a labeling tool.

The output is a fully annotated video saved to your disk, ready for presentation or further research. This final inference script completes the circle: from raw pixels to auto-labels, through the forge of training, and back to the real world as a functional AI system. It demonstrates that the future of computer vision is not manual labor, but intelligent, code-driven orchestration.

How do I save the final annotated video?

The script handles this automatically using the cv2.VideoWriter object. It takes the annotated frames directly from the YOLO model and encodes them into a new MP4 file at the original frame rate. This allows you to easily export and share the results of your automated data annotation project with colleagues or clients.

### Import necessary libraries for video processing and visualization
import cv2 
import os 
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from ultralytics import YOLO

# Weights path 
### Define the path to the best trained weights file
WEIGHTS_PATH = "d:/temp/model/Bees-model/Bees-small/weights/best.pt"

# Load the model 
### Initialize the YOLO model with your custom trained weights
model = YOLO(WEIGHTS_PATH)

# Define Path to video file
### Set the path to the unseen test video
INPUT_VIDEO_PATH = "Best-Object-Detection-models/Yolo-V11/GroundedSAM-Auto-Annotation - Bees/Videos/Test videos/test_video.mp4" 

# Extract folder and file name from the input video path 
### Setup the output path for the processed video
input_folder = os.path.dirname(INPUT_VIDEO_PATH) 
input_filename = os.path.basename(INPUT_VIDEO_PATH)
output_video_path = os.path.join(input_folder , f"annotated_{input_filename}")

# Open the input video file
### Use OpenCV to capture the video stream
cap = cv2.VideoCapture(INPUT_VIDEO_PATH)

# Get the video properties 
### Retrieve resolution and frame rate for the output file
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*"mp4v")

# Create the output video writer 
### Initialize the writer to save the results to disk
out = cv2.VideoWriter(output_video_path , fourcc , fps , (frame_width , frame_height))

# Init matplotlib figure for display the frames
### Setup the display window for real-time viewing
fig , ax = plt.subplots(figsize=(12,8))
frame_display = None 

# Function to update frames in Matplotlib 
### Define the frame-by-frame inference loop
def update_frame(_):
    global frame_display 

    # Read the next frame 
    success , frame = cap.read()
    if not success :
        return

    # Run the Yolo inference on the frame 
    ### Perform detection using the custom model
    results = model(frame) 

    # Visualize the results 
    ### Draw the boxes and labels on the frame
    annotated_frame = results[0].plot()

    # Write the annotated frame to the output video 
    ### Save the frame to the new video file
    out.write(annotated_frame)

    # Convert frame from BGR to RGB for Matplotlib 
    ### Fix color channels for correct display
    annotated_frame = cv2.cvtColor(annotated_frame , cv2.COLOR_BGR2RGB)

    # Display the annotated frame 
    ### Update the plot display
    if frame_display is None :
        frame_display = ax.imshow(annotated_frame)
    else :
        frame_display.set_data(annotated_frame)

# Configure the Matplotlib plot 
### Remove axes for a clean visual look
plt.axis("off")

### Create the animation to play the processed video
ani = FuncAnimation(fig , update_frame , interval=100 // fps)

# Display the animation
plt.show()

# Release the video capture and writer 
### Clean up resources and finalize the video file
cap.release()
out.release()

### Print the location of the final result
print(f"Output video saved to : {output_video_path}")

The result :

[embed]

FAQ

Q: What exactly is automated data annotation? A: It is a process where a pre-trained foundation model automatically identifies and labels objects in your images based on text prompts, removing the need for manual box-drawing.

Q: Can I use this code for objects other than bees and flowers? A: Yes, you simply update the CaptionOntology dictionary with your desired objects and the AI will adapt its labeling logic to your specific niche.

Q: Why do I need CUDA 12.8? A: CUDA 12.8 is the latest GPU acceleration engine as of 2026, ensuring peak performance and compatibility for PyTorch 2.9.1 and YOLO11 training.

Q: Is Autodistill free to use? A: Yes, Autodistill is an open-source framework developed by Roboflow. It allows developers to use expensive foundation models to train smaller, more efficient models for free.

Q: How many images do I need for a good model? A: While it depends on the task, a few hundred high-quality, diverse images labeled via automated data annotation are usually enough to get a very strong starting model for YOLO11.

Q: What if the AI makes a mistake during labeling? A: You should always use the visualization section of the code to check a random sample. If you see errors, you can refine your ontology text prompts to be more descriptive.

Q: Can I run this without a GPU? A: Technically yes, but it will be extremely slow. For automated data annotation and YOLO11 training, a modern NVIDIA GPU is highly recommended for reasonable processing times.

Q: What is the difference between YOLO11 and YOLOv8? A: YOLO11 offers better accuracy and faster inference speeds than previous versions, especially when working with small objects and complex backgrounds.

Q: What is a data.yaml file? A: This is a configuration file that tells YOLO where your images are located and what the class names are. Autodistill generates this for you automatically.

Q: Is Grounded-SAM better than manual labeling? A: In terms of speed, yes. In terms of precision, it is often as good as or better than human labelers, especially for organic shapes where manual boxes can be inconsistent.

Final Thoughts: The Future of Dataset Building

We have successfully navigated the entire path from raw, unorganized pixels to a high-performance computer vision model. By adopting automated data annotation, we’ve effectively solved the “data problem” that holds so many AI projects back. This workflow — leveraging the synergy between foundational models like Grounded-SAM and lightweight detectors like YOLO11 — represents the professional standard for development in 2026.

I hope this guide has inspired you to put down the manual labeling tools and pick up the power of automation. Whether you are tracking wildlife for research or building smart industrial applications, the logic provided here is a scalable, reliable foundation. AI development should be about creativity and problem-solving, not repetitive manual labor. With these tools in your hands, the only limit is your imagination.

Connect :

☕ Buy me a coffee — https://ko-fi.com/eranfeit

🖥️ Email : feitgemel@gmail.com

🌐 https://eranfeit.net

🤝 Fiverr : https://www.fiverr.com/s/mB3Pbb

Enjoy,

Eran


메타데이터
post_id
66ebb8eb9ff6
slug
i-stopped-manual-labeling-forever-how-grounded-sam-and-yolo11-changed-my-workflow-66ebb8eb9ff6
url
https://medium.com/object-detection-tutorials/i-stopped-manual-labeling-forever-how-grounded-sam-and-yolo11-changed-my-workflow-66ebb8eb9ff6
canonical_url
https://medium.com/object-detection-tutorials/i-stopped-manual-labeling-forever-how-grounded-sam-and-yolo11-changed-my-workflow-66ebb8eb9ff6
author_url
https://medium.com/@feitgemel
status
ok
fetched_at
2026-07-18 07:10:55