The problem: crabs don't sort themselves
Mud crab (Scylla spp.) sex matters a lot in the Philippine seafood trade. Females fetch a higher price for their roe, males are prized for size and meat yield, and counting how many of each pass through a given batch is normally slow, manual work that depends entirely on a buyer or seller's trained eye.
For my thesis project (built with Joed Peñamante), we set out to automate that counting step: as a crab passes in front of a camera, detect its abdominal flap and classify it — male, female, or the market category local vendors call "gay" (locally "bakla") — using YOLOv11, with a Tkinter desktop interface, running on a Raspberry Pi for real-world, low-cost deployment. The system counts and logs each classification as crabs pass through; it doesn't physically sort or move them — that's a mechanical engineering problem outside our scope as a Computer Engineering thesis.
It sounded straightforward. It was not.
Why the abdominal flap, and why it's genuinely hard
In mud crabs, sex is determined visually from the shape of the abdominal flap folded under the body:
- Males have a narrow, distinct T-shaped flap — easy to tell apart at a glance, and easy for a model to learn.
- Mature females have a broad, semi-circular flap — also visually distinct once mature.
- "Gay" crabs — a real, commonly used market classification in the Philippine crab trade — sit in a visually ambiguous middle ground. Their flap shape doesn't cleanly match either the male or mature-female pattern, and it's easy to confuse with an immature female, whose flap hasn't yet widened into the semi-circular shape.
That last category was the entire difficulty of this project. The male class was never the problem — it was distinguishing a genuinely ambiguous, underrepresented visual class from a superficially similar one.
The dataset problem: 200 images, mostly video frames
We worked with roughly 200 labeled images, annotated in Roboflow. Most of these weren't independently captured photos — they were frames extracted from video footage of live crabs.
That distinction matters more than the raw count suggests. Consecutive video frames of the same crab are nearly identical — same angle, same lighting, same flap position, frame after frame. So while we had ~200 labeled images, our effective visual diversity was meaningfully lower than 200 independent samples would give you. This is a common trap when building a dataset under real time and resource constraints, and it's worth knowing about before you assume "more frames = more data."
Layer the "gay" class's rarity on top of that, and we had a small, imbalanced dataset trying to teach a model to distinguish a subtle shape difference — the hardest possible combination for a classifier.
The fix: train fine-grained, deploy coarse
Rather than force the model to nail a three-way classification that our data couldn't reliably support, we made a deliberate design decision: train YOLOv11 on all three classes (male, female, gay), but merge "gay" into "female" at the application's final output.
The reasoning was practical, not just statistical convenience:
- The "gay" class had too few reliable samples to trust as a standalone prediction in a live application.
- In terms of what the classification is actually used for — counting crabs by market-relevant category — the "gay"/female distinction matters far less than getting male vs. female right.
This is a pattern worth remembering if you're ever building a classifier on a small or imperfect dataset: you don't have to throw away a hard, low-sample class. You can let the model learn from it during training — which can still help it draw better decision boundaries overall — while collapsing it into a more reliable category at the point where predictions actually get used.
What this taught me
A few things I'd tell anyone starting a similar computer vision project with real-world, resource-constrained data:
- Count your effective samples, not your raw file count. Video-frame datasets look bigger than they behave.
- A "hard" class doesn't have to be a wasted class. Merging outputs after training is a legitimate way to get value from data you can't fully trust on its own.
- Domain-specific visual differences are often subtler than they sound. "Different flap shape" undersells just how close an immature female and a "gay" crab can look — the real work was in recognizing that this wasn't a labeling problem, it was a genuinely hard visual distinction.
This project runs as a real-time classifier and counter on a Raspberry Pi with a Tkinter interface — crabs are detected and classified as they pass the camera, no physical sorting involved. You can see the more about this project, process, and other projects on my portfolio.
Top comments (0)