Repository navigation
Troubleshooting
Before diving into specific issues, run these first:
# 1. Backend alive?
curl http://localhost:8000/api/v1/system/health
# 2. GPU visible?
nvidia-smi
python -c "import torch; print(torch.cuda.is_available(), torch.cuda.get_device_name(0))"
# 3. All services running?
docker ps --format "table {{.Names}}\\t{{.Status}}\\t{{.Ports}}"
# 4. Frontend compiling?
cd frontend && npm run type-checkCause: Backend /setup/models/status returns a list directly, not { models: [...] }.
Fix: Already patched in current version. If you see it:
git pull origin main
cd frontend && npm run buildIf persists, check the API response manually:
curl http://localhost:8000/api/v1/setup/models/status | python3 -m json.tool
# Should be a JSON array, not an objectThe wizard marks itself complete by writing SETUP_COMPLETE=true to .env. If the flag is missing:
grep SETUP_COMPLETE .env
# If missing, add it:
echo "SETUP_COMPLETE=true" >> .env
# Then restart backend:
pkill -f uvicorn && uvicorn backend.main:app --reload --port 8000 &-
Confirm Label Studio is running:
curl http://localhost:3005/api/health
-
Label Studio takes 10–30s to initialize after Docker start. Retry after waiting.
-
Check Docker logs:
docker logs ctip-label-studio --tail 50
-
Port conflict: if something else is on 3005:
lsof -i :3005
# Ensure venv is active
source .venv/bin/activate
which python # must point inside .venv/
# Reinstall
uv pip install -e ".[dev]"
# Try direct import
python -c "from backend.main import app; print('OK')"Common causes:
- Forgot to activate venv
-
uvnot installed (install:pip install uv) - Missing system deps (libglib, libsm) — install via
apt/dnf
RTX 4060 (8 GB VRAM) hard limits:
| Operation | Max batch | Typical VRAM |
|---|---|---|
| YOLO inference | 4 tiles | ~5.0 GB |
| YOLO training | batch=4 | ~7.1 GB |
| SAM2-tiny | N/A | ~3.2 GB |
| VLM (Moondream 4-bit) | 1 image | ~2.1 GB |
Fix OOM at inference:
# Reduce tile batch size in .env:
YOLO_TILE_BATCH=1 # safest: 1 tile at a time (~1.8 GB)Fix OOM at training:
# In training config:
batch: 2 # down from 4
workers: 2 # fewer DataLoader workersClear VRAM:
# Kill all GPU processes
sudo fuser -v /dev/nvidia* 2>/dev/null
# or
pkill -f "python.*yolo"nvidia-smi # NVIDIA driver check
python -c "import torch; print(torch.version.cuda)" # CUDA version
# If cuda is None:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121On WSL2: ensure nvidia-smi works inside WSL:
# In WSL:
nvidia-smi
# If "no NVIDIA SMI", update WSL:
wsl --updatelsof -i :8000
kill -9 <PID>
# Or run on alternate port:
uvicorn backend.main:app --reload --port 8001
# Update frontend NEXT_PUBLIC_API_URL in .env.localAlways run Docker commands from the docker/ subdirectory, or use absolute paths:
cd docker && docker compose up -d
# OR
docker compose -f /path/to/trichome-analysis/docker/docker-compose.yml up -d# Add yourself to the docker group
sudo usermod -aG docker $USER
newgrp docker # apply without logout
# Verify
docker info | head -5docker logs ctip-label-studio --tail 100
docker logs ctip-cvat-server --tail 100Common causes:
-
PostgreSQL not ready yet: wait 10s and retry
docker compose up -d -
Volume permissions:
sudo chown -R 1000:1000 data/label_studio/ -
Port conflict: check
lsof -i :3005andlsof -i :3006
cd frontend
npm run dev # check terminal for errors
# TypeScript errors?
npm run type-check 2>&1 | head -40
# Rebuild node_modules
rm -rf node_modules .next && npm install && npm run devThe frontend proxies /api/v1/* to the backend via Next.js next.config.js:
# Check backend is running:
curl http://localhost:8000/api/v1/system/health
# Check proxy config in frontend/next.config.js
# It should proxy to http://localhost:8000# Test WebSocket manually:
wscat -c ws://localhost:8000/ws/system
# If wscat not installed:
npm install -g wscat
# If connection refused: check backend logs for WebSocket errors
tail -f logs/backend.log | grep -i websocket# Check download task status:
curl http://localhost:8000/api/v1/setup/models/download/<task_id>
# Check backend logs for errors:
tail -f logs/backend.log | grep -i download
# Manually download model:
mkdir -p data/models
cd data/models
wget -c "https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s.pt"Common causes:
- GitHub rate limit: wait 10 min or use a VPN
- DNS issue: try
ping github.com - Disk full:
df -h data/models/
The backend checks file presence in MODELS_DIR (default: data/models/):
ls -lh data/models/
# Expected: yolo11s.pt (~18.4 MB), sam2_hiera_tiny.pt (~38.9 MB)
# If path differs, update .env:
echo "MODELS_DIR=/path/to/models" >> .env# Check if GPU is already busy:
curl http://localhost:8000/api/v1/system/gpu
# Check background task queue:
curl http://localhost:8000/api/v1/training/jobs
# Check logs:
tail -f logs/training.logIf another inference or training job is holding the GPU semaphore, wait for it to finish or restart the backend.
| Issue | Likely cause | Fix |
|---|---|---|
| mAP < 0.50 | Too few annotations | Need at least 200 annotated trichomes |
| mAP 0.50–0.70 | Class imbalance | Use cls_weights or oversample |
| mAP stuck after epoch 30 | LR too high | Lower lr0 to 0.005 |
| mAP drops after epoch 60 | Overfitting | Add dropout: 0.1, reduce epochs |
| High FP rate | conf threshold too low | Sweep conf: 0.1 to 0.5 |
# Full benchmark with precision-recall analysis:
trichome benchmark detection \\
--model data/models/yolo11s_custom.pt \\
--split val \\
--conf-sweep 0.1,0.2,0.3,0.4,0.5 \\
--output reports/benchmark_v1.json# Reduce LR if NaN appears early:
lr0: 0.001
warmup_epochs: 5 # longer warmup
clip_gradients: 10 # gradient clippingNaN loss most often caused by:
- LR too high
- Bad annotations (completely wrong labels)
- Corrupted images in dataset (the Label Studio export log lists every skipped image)
-
Go to Label Studio → Project → Export → YOLO format
-
If YOLO format is missing, update Label Studio image:
docker pull heartexlabs/label-studio:latest docker compose --profile annotation up -d --force-recreate
-
Export via API:
curl -H "Authorization: Token <your_token>" \\ "http://localhost:3005/api/projects/1/export?exportType=YOLO" \\ -o annotations.zip
-
Check task was successfully imported:
curl -H "Authorization: Token <token>" \\ "http://localhost:3005/api/projects/1/tasks/" | python3 -m json.tool | head -30
-
Check label config matches your class names (
stalked,sessile,bulbous,non-glandular). -
Label Studio uses 0-indexed class IDs in YOLO format — verify your
data.yaml:names: ['stalked', 'sessile', 'bulbous', 'non-glandular']
The µm/px calibration scale must be set per microscope + objective combination:
# List available calibration profiles:
trichome calibrate list
# Set scale manually (measure a known-size object):
trichome calibrate set \\
--microscope "DeltaOptical-TCA-1" \\
--objective "40x" \\
--um-per-px 0.27 # measure from calibration slideIf you don't have a calibration slide, use a stage micrometer or a known reference structure (pollen grain = ~20 µm diameter).
Raw YOLO scores are overconfident. Apply calibration:
trichome calibrate-confidence \\
--model data/models/yolo11s.pt \\
--val-data data/datasets/v1/val/ \\
--method platt \\
--plot # shows reliability diagramCalibrated confidence is stored in data/models/yolo11s_calibrated.json and used automatically in inference.
| Service | Log location |
|---|---|
| Backend | logs/backend.log |
| Training | logs/training.log |
| Frontend (dev) | terminal / frontend/.next/
|
| Docker (all) | docker logs <container_name> |
| Label Studio | docker logs ctip-label-studio |
| nginx | docker logs ctip-nginx |
# Follow all logs in real time:
tail -f logs/*.log
# Docker logs with timestamps:
docker logs ctip-backend -f --timestamps# Reset setup wizard (re-run all 11 steps):
sed -i '/SETUP_COMPLETE/d' .env
# Reset database (loses all records — NOT images or models):
rm trichome.db && uvicorn backend.main:app --reload --port 8000
# Stop all Docker containers:
cd docker && docker compose --profile annotation down
# Clean Docker volumes (DESTRUCTIVE — loses Label Studio data):
docker volume rm ctip_label_studio_data ctip_postgres_data
# Clear model download cache:
rm -f data/models/*.tmpCTIP — Cannabis Trichome Intelligence Platform · RTX 4060 / 8 GB VRAM · Backend API · MLflow · Label Studio
Installation & Setup
Scientific Workflow
Reference