My Bees Come Home With Pollen, and an AI Counts Every One
2026-03-10
9 min read
Tutorial
My Bees Come Home With Pollen, and an AI Counts Every One I never expected my first production deployment of multi-object tracking to involve insects. But here I am, crouched in front of a beehive in rural Antalya, watching a YOLO model count bees at 47 frames per second on a Jetson Nano taped to the hive entrance. It started with a phone call from a beekeeper named Kemal who managed around 200 hives. His problem was simple: Colony Collapse Disorder was killing his colonies, and by the time he noticed — fewer bees buzzing around, less honey — it was already too late. He needed early warning. He needed to know which hives were losing bees before the damage became irreversible. ## The Obvious Idea That Wasn't Obvious Count the bees going in and out. That's it. If a healthy hive sends out 8,000 foragers in the morning and only 5,000 come back, something is very wrong. Maybe pesticide exposure from a nearby field. Maybe a queen failure. Maybe Varroa mites. Whatever it is, the traffic pattern shifts before any other visible symptom. The problem is that no human can sit in front of 200 hives and count bees. They're small, they're fast, and they don't walk in orderly lines. ## Training the Model I started with YOLOv8n — the nano variant. Bees are tiny targets, often just 20-30 pixels wide in 640x480 video, so I needed aggressive augmentation. I collected about 6,000 annotated frames from three hives over two weeks. The annotations were brutal — imagine labeling 40 bees per frame, some of them blurred mid-flight. Key insight: I added a class distinction between "pollen-bearing" and "empty" bees. Pollen-bearing foragers have visible yellow/orange clumps on their hind legs, and this turned out to be the most valuable signal. A drop in pollen-bearing returns correlates strongly with forage availability issues. ```python # Post-processing: directional counting with line crossing def count_crossings(tracks, line_y, direction='in'): counts = 0 for track in tracks: positions = track.trajectory[-5:] # last 5 frames if len(positions) < 2: continue prev_y = positions[-2][1] curr_y = positions[-1][1] if direction == 'in' and prev_y < line_y and curr_y >= line_y: counts += 1 elif direction == 'out' and prev_y > line_y and curr_y <= line_y: counts += 1 return counts ``` ## DeepSORT Was Overkill My first attempt used DeepSORT for tracking, and it was a disaster. The appearance feature extractor — designed for humans and vehicles — couldn't differentiate between individual bees. They all look the same to a ResNet backbone. I switched to ByteTrack, which relies purely on motion and bounding box IoU. For bees flying in relatively predictable paths toward and away from the hive, this worked beautifully. My ID switch rate dropped from 34% to about 8%. ## What We Actually Learned The first colony death Kemal caught early was Hive #47. On a Tuesday afternoon, outgoing traffic was normal — around 5,200 departures between 8 AM and noon. But returns dropped to 3,100. The AI flagged it that evening. Kemal inspected the next morning and found the bees were visiting a sunflower field that had been sprayed with neonicotinoids. He relocated the hive. The colony survived. Without the tracking system, he would have noticed in about a week — by then, the colony would have been critically weakened. ## The Hard Part Wasn't the AI It was the hardware enclosure. Jetson Nanos don't enjoy Turkish summers. The first unit overheated at 42°C ambient temperature. I ended up designing a passive cooling setup with an aluminum heatsink and a small shade structure. Power came from a solar panel and a motorcycle battery. The whole edge unit cost about $180. The model runs at 47 FPS on the Nano with TensorRT optimization. We only need about 15 FPS for accurate counting, so there's headroom. Each unit processes its video locally and pushes hourly summaries — in/out counts, pollen ratios, peak activity times — to a central dashboard via LTE. ## What Surprised Me Bee traffic patterns are shockingly regular for healthy colonies. They follow the sun almost perfectly — activity ramps up around 9 AM, peaks at 11, dips during the hottest part of the day, then picks up again around 3 PM before tapering off at sunset. When a colony deviates from this rhythm, it almost always means something is wrong. I also didn't expect the pollen ratio to be so diagnostic. A healthy colony in peak season should have about 30-40% of returning bees carrying pollen. When this drops below 15%, it often indicates the colony is queenless — workers stop foraging efficiently without queen pheromone organizing their behavior. ## Where It's Going Kemal now has 12 hives instrumented and plans to do all 200 by next spring. The total investment is smaller than what he lost to a single collapsed colony last year. We're working on adding Varroa mite detection — spotting the tiny reddish-brown parasites on individual bees in flight. That's a much harder detection problem, but early results with a custom-trained model are promising at about 71% mAP. Sometimes the most impactful applications of computer vision aren't the flashy ones. They're the ones sitting in a field, quietly counting bees.
Share this article