Multi-Species Crab Detection with RF-DETR Medium
Automated object detection and multi-class identification system for three crab species: European Green Crab (Carcinus maenas, a major invasive species), Rock Crab, and Jonah Crab. Fine-tuned from RF-DETR Medium on a merged multi-source dataset, trained on Kaggle.
Files
| File | What it is |
|---|---|
checkpoint_best_total.pth | The model to use. Best checkpoint (selected at epoch 5 by validation total metric), 133.8 MB |
last_ema.pth | Final EMA weights from the end of training (epoch 15), 133.8 MB |
class_names.txt | Class index order: 0=Jonah Crab, 1=Rock Crab, 2=European Green Crab |
training_config.json | Complete training configuration used for this run |
hparams.yaml | Lightning hyperparameters for the run |
metrics.csv | Full per-step training/validation log — every number below can be checked against it |
events.out.tfevents.* | TensorBoard log |
Model Performance & Evaluation
All validation numbers are taken directly from metrics.csv (the training log in this repo). Test-split numbers come from a separate post-training evaluation by the author and are labelled as such.
Benchmark Summary
| Checkpoint | Split | mAP@50 | mAP@50-95 | mAP@75 |
|---|---|---|---|---|
| checkpoint_best_total (epoch 5) | Valid | 0.9920 | 0.8590 | 0.9361 |
| checkpoint_best_total | Test (author eval) | 0.9834 | 0.8147 | 0.8910 |
| last_ema | Valid | 0.9877 | 0.8558 | 0.9322 |
| last_ema | Test (author eval) | 0.9786 | 0.8178 | 0.8879 |
At the best checkpoint (epoch 5): F1 0.9800 · Precision 0.9810 · Recall 0.9791 on the validation split.
Training & Validation Progression
Training was configured for 100 epochs with early stopping (patience 10); the run converged fast — the best checkpoint is from epoch 5, and the log runs to epoch 15 before stopping. In plain terms: the model peaked early and did not improve after that, which is typical when fine-tuning a strong pretrained detector on a dataset of this size.
Dataset Overview
The dataset was constructed by aggregating five open-source datasets into a consolidated COCO-format collection, published as hojayfa-sir/European_Green_Crab.
- Base Dataset Images: 2,889 images with 6,630 annotated objects (2.3 annotations/image average).
- Base Object Distribution: 2,405 single-object images, 120 images with 2–5 objects, and 447 multi-object scenes.
- Dimensions: 81.8% medium-resolution images, median resolution 386×342.
Class Distribution (Base Split)
| Class Name | Train Annotations | Valid Annotations | Test Annotations | Total Count |
|---|---|---|---|---|
| European Green Crab | 1,780 | 500 | 277 | 2,557 |
| Rock Crab | 1,538 | 417 | 249 | 2,204 |
| Jonah Crab | 1,285 | 358 | 226 | 1,869 |
Preprocessing & Data Augmentation
A 5× training augmentation pipeline was applied:
- Preprocessing: Auto-orientation and white-padded resizing to 576×576 pixels.
- Rotations: Random rotation between -15° and +15°.
- Photometric Distortions: Brightness (±15%) and exposure (±15%) adjustments.
- Sensor Noise & Artifacts: Up to 2% random pixel noise and 20px directional motion blur (45° angle).
Augmented Dataset Distribution:
- Train Set: 10,110 images (92%)
- Validation Set: 578 images (5%)
- Test Set: 289 images (3%)
- Total Volume: 10,977 images
Training Configuration
| Setting | Value |
|---|---|
| Base Model | RF-DETR Medium with dinov2_windowed_small backbone |
| Input Resolution | 576×576 pixels |
| Batch Strategy | Batch size 4 with 4 grad accumulation steps (effective 16) |
| Optimizer | AdamW (lr=1e-4, lr_encoder=1.5e-4, weight_decay=1e-4) |
| EMA | decay 0.993, updated every step |
| Schedule | Configured 100 epochs, early stopping patience 10 — best checkpoint at epoch 5, training ended at epoch 15 |
| Compute | Kaggle GPU environment (~12 hours total) |
| Notebook | European Green Crab rf detr — Kaggle |
Usage
Install Dependencies
pip install rfdetr huggingface_hub
Load Model from Hugging Face
from huggingface_hub import hf_hub_download
from rfdetr import RFDETRMedium
weights = hf_hub_download(
repo_id="hojayfa-sir/european-green-crab-detection",
filename="checkpoint_best_total.pth",
)
model = RFDETRMedium(pretrain_weights=weights)
Run Inference
detections = model.predict("image.jpg", threshold=0.50)
# detections.class_id follows class_names.txt order:
# 0 = Jonah Crab, 1 = Rock Crab, 2 = European Green Crab
Limitations
Straight talk, because inflated claims help nobody:
- The headline mAP is a validation number. 99.2 mAP@50 is measured on the validation split during training (see
metrics.csv). The test-split figures above come from the author's separate evaluation and are consistently lower (98.3 mAP@50) — expect real-world performance at or below the test numbers, not the validation ones. - Small, web-collected data. 2,889 base images aggregated from five public sources. Images are mostly clear, centred specimens; performance on murky underwater/ROV footage, occluded crabs, or crabs in traps will be worse and has not been measured.
- Three species only. Any other crab (or crab-like object) will be forced into one of the three classes or background — there is no "unknown species" output.
- Early peak. The best checkpoint is epoch 5 of a 100-epoch schedule; later epochs did not generalise better on validation.
Citation & Attribution
Author: Abu Hojayfa
If you use this model in your research or MATE ROV application, please consider citing it:
@misc{crab_rfdetr_model,
title={Multi-Species Crab Detection with RF-DETR Medium},
author={Abu Hojayfa},
year={2026},
publisher={Hugging Face},
howpublished={\url{https://huggingface.co/hojayfa-sir/european-green-crab-detection}}
}