Commands Reference
Complete reference for all tasks.py invoke commands available in the project.
Overview
All project commands are defined in tasks.py and executed using the invoke library. You run them with:
List All Commands
To see all available commands:
Data Commands
download-data
Downloads the drone imagery dataset from Kaggle.
Prerequisites:
- Kaggle credentials configured in
.env KAGGLE_USERNAMEandKAGGLE_KEYenvironment variables set
Output:
- Downloads dataset to
data/raw/classes_dataset/ - Creates directories automatically if they don't exist
What it does:
- Uses Kaggle API to download the semantic segmentation drone dataset
- Extracts the archive
- Organizes images into
original_images/andlabel_images_semantic/
export-data
Converts the downloaded Kaggle dataset into nnU-Net format.
Prerequisites:
- Dataset already downloaded with
download-data - nnU-Net environment variables set in
.env
Output:
- Creates
nnUNet_raw/Dataset101_DroneSeg/ - Populates
imagesTr/andlabelsTr/directories - Generates
dataset.jsonmetadata file
What it does:
- Reads images from
data/raw/classes_dataset/ - Converts to nnU-Net naming convention (
<id>_0000.png) - Creates train/test splits
- Generates nnU-Net dataset configuration
download-and-export-data
Combines download-data and export-data into a single command.
Equivalent to:
download-models
Downloads pre-trained models and checkpoints from DVC (Data Version Control).
Prerequisites:
- DVC configured (comes with
uv sync) - Access to the GCS bucket (for team members)
- Google Cloud credentials set in
.env(if required)
Output:
- Downloads tracked files:
nnUNet_results.dvc,nnUNet_preprocessed.dvc,data.dvc - Populates directories with versioned data and models
What it does:
- Runs
dvc pullto fetch all DVC-tracked resources - Downloads model checkpoints from cloud storage
- Syncs preprocessed data if needed
Preprocessing Commands
preprocess
Runs nnU-Net preprocessing pipeline.
Options:
--dataset-id(default:101) - Dataset ID to preprocess
Examples:
# Preprocess default dataset (101)
uv run invoke preprocess
# Preprocess specific dataset
uv run invoke preprocess --dataset-id 102
Prerequisites:
- Data exported to
nnUNet_raw/withexport-data - nnU-Net environment variables set
Output:
- Creates
nnUNet_preprocessed/Dataset101_DroneSeg/ - Generates preprocessing plans
- Creates
gt_segmentations/andnnUNetPlans_2d/directories
What it does:
- Analyzes dataset statistics
- Generates preprocessing plans
- Preprocesses images for training
- Verifies dataset integrity
Training Commands
train
Trains the nnU-Net model.
Options:
--dataset-id(default:101) - Dataset ID--fold(default:0) - Cross-validation fold (0-4)--dim(default:2d) - Model dimension (2dor3d_fullres)--device(default:auto) - Device to use (auto,cuda,mps,cpu)
Examples:
# Train with defaults (2D, fold 0, auto-detect device)
uv run invoke train
# Train on GPU with CUDA
uv run invoke train --device cuda
# Train on Apple Silicon
uv run invoke train --device mps
# Train on CPU
uv run invoke train --device cpu
# Train specific fold
uv run invoke train --fold 1
# Train 3D model
uv run invoke train --dim 3d_fullres
# Combine options
uv run invoke train --dataset-id 101 --fold 2 --dim 2d --device cuda
Prerequisites:
- Data preprocessed with
preprocess - Sufficient disk space for checkpoints (~500MB)
- GPU recommended (training is slow on CPU)
Output:
- Model checkpoints in
nnUNet_results/Dataset101_DroneSeg/nnUNetTrainer__nnUNetPlans__2d/fold_X/ - Training logs and metrics
- Can be monitored with Weights & Biases if configured
What it does:
- Initializes nnU-Net trainer
- Trains segmentation model
- Saves checkpoints periodically
- Logs metrics to console and W&B
Device Selection:
auto- Automatically selects CUDA > MPS > CPUcuda- Use NVIDIA GPU (requires CUDA toolkit)mps- Use Apple Metal Performance Shaders (M1/M2 Macs)cpu- Use CPU only (slow, for testing)
Testing Commands
test
Runs the test suite with coverage reporting.
What it does:
- Runs all tests in
tests/directory with pytest - Generates coverage report
- Displays coverage statistics
Output:
tests/integrationtests/test_apis.py ...
tests/test_data.py ...
---------- coverage: platform darwin, python 3.12.x -----------
Name Stmts Miss Cover
-----------------------------------------------------
src/dtu_mlops_111/__init__.py 0 0 100%
src/dtu_mlops_111/api.py 120 10 92%
src/dtu_mlops_111/data.py 85 5 94%
-----------------------------------------------------
TOTAL 205 15 93%
Manual Testing:
# Run specific test file (integration tests for API)
uv run pytest tests/integrationtests/test_apis.py
# Run with verbose output
uv run pytest -v
# Run specific test
uv run pytest tests/test_data.py::test_download_data
# Run without coverage
uv run pytest tests/
API Commands
app
Starts the FastAPI development server.
What it does:
- Starts Uvicorn server on
http://localhost:8000 - Enables auto-reload on code changes
- Serves API endpoints for prediction
Output:
Available Endpoints:
GET /- Health check & model statusPOST /predict/- Image segmentation (single)POST /batch_predict/- Image segmentation (batch)GET /drift/- Data drift reportGET /model_info/- Model metadataGET /metrics- Prometheus metrics
Testing the API:
# In another terminal
curl http://localhost:8000/
# Make a prediction
curl --location 'http://localhost:8000/predict/' \
--form 'data=@"path/to/image.png"'
Start manually with Uvicorn
BentoML Serving (Alternative)
bento-build
Builds the BentoML bundle containing model and code.
bento-serve
Serves the BentoML service locally with auto-reload.
Output:
INFO [cli] Starting 1 BentoServer instances..
INFO [cli] Service "drone-seg-service" is versioned: ...
INFO [cli] Serving at http://localhost:3000
Docker Commands
docker-build
Builds all project Docker images (train, inference, api).
What it does:
- Builds
train:latest - Builds
inference:latest - Builds
api:latest - Builds
bento:latest
Individual Build Tasks
uv run invoke docker-build-train- Build training imageuv run invoke docker-build-inference- Build inference imageuv run invoke docker-build-api- Build API imageuv run invoke docker-build-bento- Build BentoML image
docker-train
Runs the training pipeline inside a Docker container with all necessary volume mounts and environment variables.
What it does:
- Runs
train:latestwith--gpus alland--ipc=host - Mounts local
data/,nnUNet_raw/,nnUNet_preprocessed/, andnnUNet_results/ - Loads environment variables from
.env
docker-inference
Runs the nnU-Net prediction pipeline inside a Docker container.
What it does:
- Runs
inference:latestwith volume mounts fornnUNet_results/,images_raw/, andvisualizations/
docker-run-api
Runs the FastAPI inference server in a container.
What it does:
- Runs
api:lateston port 8080 - Automatically mounts Google Cloud ADC credentials if found locally
docker-run-bento
Runs the BentoML container.
What it does:
- Runs
bento:lateston port 8080 - Automatically mounts Google Cloud ADC credentials if found locally
- Enables DVC pull if env var is set
Cloud Run Commands
cloud-run-update-env
Enables DVC model pull in Cloud Run.
cloud-run-update-resources
Updates Cloud Run resource settings (CPU, Memory, Timeout).
cloud-run-logs
Reads logs from a Cloud Run service.
BentoML Utility Commands
bento-smoke-test
Runs a quick health check sequence (livez, readyz, model_info) against a running service.
bento-predict-base64
Helper to send a base64 encoded image prediction request (avoids shell argument limits).
uv run invoke bento-predict-base64 --image-path path/to/image.png --service-url http://localhost:3000
Payload Generation (Manual)
The following script reads a local image file, encodes it into Base64, and writes a payload.json file in the expected request format:
python - <<'PY'
import base64, json
img_path = "sample_image.jpg"
b64 = base64.b64encode(open(img_path, "rb").read()).decode()
payload = {"req": {"image_b64": b64, "content_type": "image/jpeg"}}
with open("payload.json", "w") as f:
json.dump(payload, f)
print("saved payload.json")
PY
Manual Curl Request
Once the payload has been created, send it to the deployed BentoML endpoint using curl:
curl -s -o resp.json -w "\nHTTP %{http_code}\n" \
-X POST "https://drone-seg-32512441443.europe-north1.run.app/predict_base64" \
-H "Content-Type: application/json" \
--data-binary @payload.json
The response will be saved into resp.json. If the request succeeds, the HTTP status code should be 200.
Command Chaining
You can chain multiple commands if needed:
# Download, export, and preprocess in one go
uv run invoke download-data && \
uv run invoke export-data && \
uv run invoke preprocess
Next Steps
- Workflows - Learn how to combine these commands into complete workflows
- Troubleshooting - Solutions if commands fail