# google/cameratrapai architecture

> Architecture diagram of the GitHub repository google/cameratrapai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google/cameratrapai
- Repository: https://github.com/google/cameratrapai

## Overview

SpeciesNet runs a camera-trap image through object detection and species classification, then combines their results into a single prediction, optionally using location to constrain wildlife labels. The main CLI delegates inference orchestration to the multiprocessing pipeline; that pipeline invokes the model components and produces per-image results. Supporting capabilities include model retrieval, taxonomy and geofence logic, and drawing detection overlays. The README also documents restartable CLI runs and geographic filtering. Some orchestration details and auxiliary scripts are unsampled, so the graph omits uncertain connections.

Main entry points: [`speciesnet/multiprocessing.py`](https://github.com/google/cameratrapai/blob/main/speciesnet/multiprocessing.py) (Inference pipeline), [`speciesnet/ensemble.py`](https://github.com/google/cameratrapai/blob/main/speciesnet/ensemble.py) (Ensemble), [`speciesnet/utils.py`](https://github.com/google/cameratrapai/blob/main/speciesnet/utils.py) (Model resources), [`speciesnet/scripts/run_model.py`](https://github.com/google/cameratrapai/blob/main/speciesnet/scripts/run_model.py) (Model CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_run["Inference workflow"]
  node_runner["Model CLI<br/>[run_model.py]"]
  node_pipeline["Inference pipeline<br/>[multiprocessing.py]"]
  node_result["Prediction JSON"]
end

subgraph group_models["Vision models"]
  node_detector["Object detector<br/>[detector.py]"]
  node_classifier["Species classifier<br/>[classifier.py]"]
end

subgraph group_decision["Prediction logic"]
  node_ensemble["Ensemble<br/>[ensemble.py]"]
  node_combiner["Prediction combiner"]
  node_geofence["Geofence rules<br/>[geofence_utils.py]"]
  node_taxonomy["Taxonomy utilities<br/>[taxonomy_utils.py]"]
end

subgraph group_support["Supporting capabilities"]
  node_resources["Model resources<br/>[utils.py]"]
  node_geolocation["Location lookup<br/>[geolocation.py]"]
  node_display["Detection overlay<br/>[display.py]"]
  node_model_files["Model files"]
end

node_user(("CLI user"))

node_user -->|"runs"| node_runner
node_runner -->|"delegates inference"| node_pipeline
node_pipeline -->|"runs detection"| node_detector
node_pipeline -->|"runs classification"| node_classifier
node_pipeline -->|"runs ensemble"| node_ensemble
node_pipeline -->|"resolves location"| node_geolocation
node_pipeline -->|"writes predictions"| node_result
node_classifier -->|"loads model"| node_resources
node_detector -->|"loads model"| node_resources
node_resources -->|"downloads or reads"| node_model_files
node_ensemble -->|"combines predictions"| node_combiner
node_ensemble -->|"applies rules"| node_geofence
node_ensemble -->|"uses taxonomy"| node_taxonomy
node_user -->|"visualizes results"| node_display

click node_runner "https://github.com/google/cameratrapai/blob/main/speciesnet/scripts/run_model.py"
click node_pipeline "https://github.com/google/cameratrapai/blob/main/speciesnet/multiprocessing.py"
click node_detector "https://github.com/google/cameratrapai/blob/main/speciesnet/detector.py"
click node_classifier "https://github.com/google/cameratrapai/blob/main/speciesnet/classifier.py"
click node_resources "https://github.com/google/cameratrapai/blob/main/speciesnet/utils.py"
click node_ensemble "https://github.com/google/cameratrapai/blob/main/speciesnet/ensemble.py"
click node_combiner "https://github.com/google/cameratrapai/blob/main/speciesnet/ensemble_prediction_combiner.py"
click node_geofence "https://github.com/google/cameratrapai/blob/main/speciesnet/geofence_utils.py"
click node_taxonomy "https://github.com/google/cameratrapai/blob/main/speciesnet/taxonomy_utils.py"
click node_geolocation "https://github.com/google/cameratrapai/blob/main/speciesnet/geolocation.py"
click node_display "https://github.com/google/cameratrapai/blob/main/speciesnet/display.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runner,node_pipeline,node_result,node_user toneBlue
class node_detector,node_classifier toneAmber
class node_ensemble,node_combiner,node_geofence,node_taxonomy toneMint
class node_resources,node_geolocation,node_display,node_model_files toneRose
```

## Components

### Inference workflow

- [Model CLI](https://github.com/google/cameratrapai/blob/main/speciesnet/scripts/run_model.py): `speciesnet/scripts/run_model.py`
- [Inference pipeline](https://github.com/google/cameratrapai/blob/main/speciesnet/multiprocessing.py): `speciesnet/multiprocessing.py`
- **Prediction JSON**

### Vision models

- [Object detector](https://github.com/google/cameratrapai/blob/main/speciesnet/detector.py): `speciesnet/detector.py`
- [Species classifier](https://github.com/google/cameratrapai/blob/main/speciesnet/classifier.py): `speciesnet/classifier.py`

### Prediction logic

- [Ensemble](https://github.com/google/cameratrapai/blob/main/speciesnet/ensemble.py): `speciesnet/ensemble.py`
- [Prediction combiner](https://github.com/google/cameratrapai/blob/main/speciesnet/ensemble_prediction_combiner.py): `speciesnet/ensemble_prediction_combiner.py`
- [Geofence rules](https://github.com/google/cameratrapai/blob/main/speciesnet/geofence_utils.py): `speciesnet/geofence_utils.py`
- [Taxonomy utilities](https://github.com/google/cameratrapai/blob/main/speciesnet/taxonomy_utils.py): `speciesnet/taxonomy_utils.py`

### Supporting capabilities

- [Model resources](https://github.com/google/cameratrapai/blob/main/speciesnet/utils.py): `speciesnet/utils.py`
- [Location lookup](https://github.com/google/cameratrapai/blob/main/speciesnet/geolocation.py): `speciesnet/geolocation.py`
- [Detection overlay](https://github.com/google/cameratrapai/blob/main/speciesnet/display.py): `speciesnet/display.py`
- **Model files**

### Other components

- **CLI user**

## Connections

- CLI user → Model CLI: runs (evidence: `README.md`)
- Model CLI → Inference pipeline: delegates inference (evidence: `speciesnet/multiprocessing.py`)
- Inference pipeline → Object detector: runs detection (evidence: `speciesnet/multiprocessing.py`)
- Inference pipeline → Species classifier: runs classification (evidence: `speciesnet/multiprocessing.py`)
- Inference pipeline → Ensemble: runs ensemble (evidence: `speciesnet/multiprocessing.py`)
- Inference pipeline → Location lookup: resolves location (evidence: `speciesnet/multiprocessing.py`)
- Inference pipeline → Prediction JSON: writes predictions (evidence: `README.md`)
- Species classifier → Model resources: loads model (evidence: `speciesnet/classifier.py`)
- Object detector → Model resources: loads model (evidence: `speciesnet/detector.py`)
- Model resources → Model files: downloads or reads (evidence: `speciesnet/utils.py`)
- Ensemble → Prediction combiner: combines predictions (evidence: `speciesnet/ensemble.py`)
- Ensemble → Geofence rules: applies rules (evidence: `speciesnet/ensemble.py`)
- Ensemble → Taxonomy utilities: uses taxonomy
- CLI user → Detection overlay: visualizes results (evidence: `README.md`)
