SpeciesNet Documentation

repository·main·Indexed 19 days ago

https://github.com/google/cameratrapai

Tools and AI models for classifying wildlife in images from motion-triggered camera traps. SpeciesNet uses an ensemble approach combining MegaDetector for object detection and a high-capacity species classifier to automate wildlife monitoring data processing. Features include geographic filtering via ISO 3166-1 alpha-3 codes, GPU support via CUDA, and taxonomic label rollup for low-confidence predictions. The package provides scripts for running the full ensemble, individual components, and converting outputs to MegaDetector format.

Tokens
49.4K
Snippets
98
Records
132
Agent score
66%

What's inside speciesnet

  1. Understand the SpeciesNet v4.0.1a model architecture and workflow

    main

    SpeciesNet v4.0.1a is an ensemble model designed for camera trap analysis. It follows an "Always crop" workflow: a detector is run first to find objects, and the image is then cropped to the top detection bounding box before being passed to the species classifier.

    Model Identifier: kaggle:google/speciesnet/pyTorch/v4.0.1a

    Classifier Details

    • Base Architecture: EfficientNet V2 M
    • Inference Framework: PyTorch
    • Input Requirements: 480x480px RGB images.
    • Preprocessing: The input image must be cropped to the top detection bounding box and resized to 480x480px (note: this may change the original aspect ratio).
    • Output: Logits, which are converted to label confidence scores via softmax.
    • Label Scope: 2498 total labels, including 2066 species (including human), 430 higher taxa labels, and 2 non-animal labels (blank, vehicle).

    Detector Details

    • Model: MegaDetector v5a
    • Base Architecture: YOLOv5
    • Input Requirements: Variable sized RGB images where dimensions are multiples of 64px.
    • Preprocessing: Resize RGB image to 1280px on the longest edge, then pad dimensions to multiples of 64px while maintaining the original aspect ratio.
    • Output: Labeled bounding boxes with confidence scores for 3 labels: animal, human, and vehicle.
  2. Understand SpeciesNet v4.0.0b model components

    main

    SpeciesNet v4.0.0b is composed of several functional modules designed for camera trap data analysis:

    • Classifier: Responsible for identifying the species/taxa in a detection.
    • Detector: Responsible for locating objects/animals within an image.
    • Ensemble: A combination of models used to improve overall performance.

    This model is trained on diverse datasets to provide robust taxonomic identification across various animal classes including aves (birds), mammalia (mammals), reptilia (reptiles), and others.

  3. Overview of SpeciesNet v4.0.0b Model Architecture

    main

    SpeciesNet v4.0.0b is a full-image model that runs a detector and a species classifier independently on the same image. It uses an ensemble approach that allows for label rollup, meaning if classifier confidence is low, predictions can be propagated to higher taxonomic levels (genus, family, order, class, kingdom).

    Classifier Details

    • Framework: TensorFlow (EfficientNet V2 M)
    • Input: 480x480px RGB images
    • Preprocessing: Crop either 400px or 30% of the height (whichever is smaller) from the center of the RGB image, then resize to 480x480px (aspect ratio may be lost).
    • Output: Logits transformed via softmax into confidence scores.
    • Labels: 2498 total (2066 species, 430 higher taxa, 2 non-animal: blank and vehicle).

    Detector Details

    • Model: MegaDetector v5a (YOLOv5)
    • Framework: PyTorch
    • Input: Variable sized RGB images where dimensions are multiples of 64px.
    • Preprocessing: Resize RGB image to 1280px on the longest edge, then pad to multiples of 64px while maintaining aspect ratio.
    • Output: Labeled bounding boxes with confidence scores.
    • Labels: 3 (animal, human, vehicle).

    Ensemble Output

    Because of label rollup, the ensemble can predict more labels than the classifier alone:

    • Total Labels: 3493
    • Species: 2066
    • Higher Taxa Labels: 1425
    • Non-animal Labels: 2 (blank, vehicle)
  4. Choose between SpeciesNet model variants

    main

    There are two classifier variants that use different preprocessing and ensemble strategies. Use the --model flag to switch between them.

    • v4.0.3a (Default): Always-crop model. Runs the detector first and crops the image to the top detection bounding box before classification.

      • Manual Preprocessing: If running outside the ensemble, crop tightly to animals and resize to 480x480px.
      • Model ID: kaggle:google/speciesnet/pyTorch/v4.0.3a/1
    • v4.0.3b: Full-image model. Runs both detector and classifier on the full image independently.

      • Manual Preprocessing: If running outside the ensemble, crop vertically to remove top/bottom pixels, then resize to 480x480px.
      • Model ID: kaggle:google/speciesnet/pyTorch/v4.0.3b/1
    # Example: Using the full-image model variant
    python -m speciesnet.scripts.run_model --model kaggle:google/speciesnet/pyTorch/v4.0.3b/1
  5. How the SpeciesNet Ensemble works

    main

    The SpeciesNet ensemble uses a process called label rollup. When the initial classifier predictions lack sufficient confidence, scores are propagated to higher taxa (genus, family, order, class, kingdom). This allows the ensemble to predict additional labels not present in the base classifier's training set.

    Ensemble Label Statistics

    • Total labels: 3493
    • Species: 2066 (including human)
    • Higher taxa labels: 1425
    • Non-animal labels: 2 (blank, vehicle)
  6. Understand the SpeciesNet v4.0.0b taxonomic identifier format

    main

    Species in the SpeciesNet v4.0.0b model are identified using a semicolon-delimited string that provides a full taxonomic path. This is useful for mapping model outputs to biological classifications.

    The components of the identifier are:

    1. UUID: A unique identifier for the species.
    2. Class: e.g., mammalia, aves, reptilia.
    3. Order: e.g., carnivora, galliformes.
    4. Family: e.g., felidae, phasianidae.
    5. Genus: e.g., panthera, phasianus.
    6. Species: e.g., pardus, colchicus.
    7. Common Name: The human-readable name (e.g., leopard, ring-necked pheasant).
  7. Understand the SpeciesNet v4.0.1b label distribution

    main

    The SpeciesNet v4.0.1b model is trained on a diverse set of biological taxa. The label distribution follows a hierarchical structure represented by a semicolon-separated string: [UUID];[Class];[Order];[Family];[Genus];[Species];[Common Name].

    Each entry in the distribution table represents a specific taxon and the number of training samples available for it. For example, the malagasy giant jumping rat has 437 samples, while the black-and-gold howler monkey has 436. This distribution provides insight into the model's training density across different species and taxonomic groups.

  8. Understand the SpeciesNet v4.0.0a model architecture

    main

    SpeciesNet v4.0.0a is an ensemble model designed for camera trap analysis. It uses a two-stage pipeline: first, a Detector identifies objects, and then a Classifier identifies the species within the cropped bounding boxes.

    Pipeline Workflow

    1. Detection: The model uses MegaDetector v5a (PyTorch/YOLOv5) to find bounding boxes for animal, human, or vehicle.
    2. Cropping: The image is cropped to the top detection bounding box.
    3. Classification: The cropped image is fed to the Classifier (TensorFlow/EfficientNet V2 M) to predict species or higher taxa.

    Model Specifications

    Classifier

    • Input: 480x480px RGB images (after cropping and resizing).
    • Output: Logits transformed via softmax into confidence scores.
    • Labels: 2498 total labels, including 2066 species (including human), 430 higher taxa labels, and 2 non-animal labels (blank, vehicle).

    Detector (MegaDetector v5a)

    • Input: Variable sized RGB images (dimensions must be multiples of 64px).
    • Preprocessing: Resizes the longest edge to 1280px and pads to multiples of 64px while maintaining aspect ratio.
    • Labels: 3 (animal, human, vehicle).

    Ensemble Output

    Due to label rollup (propagating low-confidence species predictions to higher taxa like genus, family, etc.), the ensemble can output more labels than the base classifier. The ensemble total includes 3493 labels, with 1425 higher taxa labels.

  9. How the SpeciesNet ensemble handles label rollup

    main

    The SpeciesNet ensemble uses a process called "label rollup" to handle low-confidence predictions. When the classifier's initial predictions are not sufficiently confident, scores are propagated to higher taxonomic levels (e.g., genus, family, order, class, kingdom).

    Because of this rollup, the ensemble can predict more labels than the base classifier. While the classifier has 2498 labels, the ensemble provides a total of 3493 labels. The difference is accounted for by the inclusion of additional higher taxa labels (1425 in the ensemble vs 430 in the classifier).

  10. Understand the SpeciesNet v4.0.0b label distribution

    main

    The SpeciesNet v4.0.0b model includes a wide variety of taxonomic labels. The training data for the classifier follows a hierarchical structure represented in the label distribution. Each entry in the distribution represents a specific taxon, identified by a unique UUID, followed by its taxonomic lineage (Class; Order; Family; Genus; Species; Common Name) and the count of training instances.

    Example of the label format: {UUID};{class};{order};{family};{genus};{species};{common_name}

    Commonly represented taxa include various species of mammalia (e.g., rodents, primates, carnivora) and aves (e.g., passeriformes, accipitriformes).

  11. How SpeciesNet ensemble decision-making works

    main

    SpeciesNet uses an ensemble strategy via run_model to predict a single category for an image by combining an object detector (MegaDetector) and an image classifier. The goal is to minimize human review effort by filtering blanks, providing high-confidence predictions for frequent classes, and using taxonomic 'rollups' when species-level confidence is low.

    The Prediction Workflow

    1. Input processing: Images are preprocessed. Depending on the model, they are either processed as 'always crop' (detector crops the image before classification) or 'full image' (both models process the whole image).
    2. Object detection: MegaDetector identifies objects (animals, humans, vehicles) and provides bounding boxes and confidence scores.
    3. Species classification: The classifier provides the top-5 species/taxa classifications with confidence scores.
    4. Human/Vehicle override: High-confidence human or vehicle detections from the detector override classifier predictions.
    5. Blank decisions: Images are labeled 'blank' if the classifier has very high confidence (>0.99) or if the classifier predicts 'blank' and the detector has low animal confidence.
    6. Geofencing: If a location (country/admin1) is provided, species disallowed in that region are 'rolled up' to a higher taxonomic level.
    7. Label rollup: If species-level confidence is insufficient, the model propagates predictions to the first matching ancestor in the taxonomy (e.g., genus, family, or order) that has a high confidence score.
    8. Animal decisions: If the detector has reasonable confidence in an animal presence, animal is returned.
    9. Unknown: If no rules apply, the unknown class is returned.
    10. Prediction source: The final result includes a prediction_source field to indicate which part of the ensemble produced the result.

    Note: When using run_md_and_speciesnet, the goal is to classify individual detections rather than the whole image; therefore, geofencing and label rollup steps are applied differently.

  12. Install SpeciesNet with optional dependencies

    main

    SpeciesNet can be installed with different dependency sets depending on your environment (notebooks, servers, or cloud storage access).

    • Minimal: pip install speciesnet
    • Notebooks: pip install speciesnet[notebooks]
    • Server: pip install speciesnet[server]
    • Cloud (GS/S3/AZ): pip install speciesnet[gs] (or s3, az)
    • Combinations: pip install speciesnet[notebooks,server]
    pip install speciesnet[notebooks,server]