# nikitasharma768/farm-ng-pest-model architecture

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

- Interactive diagram: https://gitdiagram.com/nikitasharma768/farm-ng-pest-model
- Repository: https://github.com/nikitasharma768/farm-ng-pest-model

## Overview

This repository implements pest detection for farm-ng Amiga, with both an offline image-folder workflow and a ROS 2 deployment. The primary workflow detects a trap, filters for insects, classifies species, then records detections for field heatmaps. Dataset preparation, model training, evaluation, and taxonomic/data-gap analysis are supporting product capabilities. ROS topic links and the offline output workflow are documented; source excerpts establish the central inference calls and ROS heatmap generation. Other unsampled implementation details are not inferred.

Main entry points: [`src/pipeline.py`](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/pipeline.py) (Inference orchestrator), [`ros2_nodes/pest_detection_nodes/heatmap_node.py`](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/heatmap_node.py) (ROS heatmap logger), [`ros2_nodes/launch/pest_detection.launch.py`](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/launch/pest_detection.launch.py) (ROS launch), [`ros2_nodes/pest_detection_nodes/trap_detector_node.py`](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/trap_detector_node.py) (ROS trap detector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference pipeline"]
  node_offline_runner["Batch runner<br/>[run_all.py]"]
  node_pipeline["Inference orchestrator<br/>[pipeline.py]"]
  node_trap_detection["Trap detection<br/>[trap_detector.py]"]
  node_binary_filter["Insect filter<br/>[pipeline.py]"]
  node_species_classifier["Species classifier<br/>[pipeline.py]"]
end

subgraph group_deployment["ROS deployment"]
  node_ros_trap["ROS trap detector"]
  node_ros_binary["ROS insect filter"]
  node_ros_species["ROS species classifier"]
  node_ros_heatmap["ROS heatmap logger<br/>[heatmap_node.py]"]
  node_launch["ROS launch"]
end

subgraph group_outputs["Field outputs"]
  node_heatmap_png["PNG heatmap<br/>[heatmap.py]"]
  node_heatmap_html["HTML heatmap<br/>[heatmap_html.py]"]
end

subgraph group_data_models["Data and models"]
  node_dataset_prep["Dataset preparation<br/>[prepare_dataset.py]"]
  node_binary_data["Binary dataset builder"]
  node_species_training["Species model training<br/>[train.py]"]
  node_binary_training["Binary model training<br/>[train_binary.py]"]
end

subgraph group_evaluation["Evaluation and analysis"]
  node_evaluation["Pipeline evaluation"]
  node_binary_evaluation["Binary evaluation<br/>[evaluate_binary.py]"]
  node_gap_analysis["Dataset gap analysis<br/>[gap_analysis.py]"]
  node_taxonomy_analysis["Taxonomic error analysis"]
  node_taxonomy_validation["Taxonomy validation<br/>[taxonomy_check.py]"]
end

node_image_operator(("Image operator"))
node_amiga_camera(("Amiga camera"))
node_gps(("Amiga GPS"))

node_image_operator -->|"provides images"| node_offline_runner
node_offline_runner -->|"runs pipeline"| node_pipeline
node_pipeline -->|"detects traps"| node_trap_detection
node_pipeline -->|"classifies insect"| node_binary_filter
node_pipeline -->|"classifies species"| node_species_classifier
node_pipeline -.->|"produces heatmap"| node_heatmap_png
node_pipeline -.->|"produces heatmap"| node_heatmap_html
node_amiga_camera -->|"publishes frames"| node_ros_trap
node_ros_trap -->|"publishes crops"| node_ros_binary
node_ros_binary -->|"forwards insects"| node_ros_species
node_ros_species -->|"publishes species"| node_ros_heatmap
node_gps -->|"provides fixes"| node_ros_heatmap
node_ros_heatmap -->|"runs generator"| node_heatmap_png
node_ros_heatmap -->|"runs generator"| node_heatmap_html
node_launch -->|"starts node"| node_ros_trap
node_launch -->|"starts node"| node_ros_binary
node_launch -->|"starts node"| node_ros_species
node_launch -->|"starts node"| node_ros_heatmap
node_dataset_prep -.->|"prepares data"| node_species_training
node_binary_data -.->|"prepares data"| node_binary_training
node_pipeline -->|"evaluated by"| node_evaluation
node_binary_training -.->|"evaluated by"| node_binary_evaluation
node_gap_analysis -.->|"guides coverage"| node_dataset_prep
node_taxonomy_analysis -.->|"checks taxonomy"| node_taxonomy_validation

click node_offline_runner "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/run_all.py"
click node_pipeline "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/pipeline.py"
click node_trap_detection "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/trap_detector.py"
click node_binary_filter "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/pipeline.py"
click node_species_classifier "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/pipeline.py"
click node_ros_trap "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/trap_detector_node.py"
click node_ros_binary "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/binary_filter_node.py"
click node_ros_species "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/species_classifier_node.py"
click node_ros_heatmap "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/heatmap_node.py"
click node_launch "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/launch/pest_detection.launch.py"
click node_heatmap_png "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/heatmap.py"
click node_heatmap_html "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/heatmap_html.py"
click node_dataset_prep "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/prepare_dataset.py"
click node_binary_data "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/build_binary_dataset.py"
click node_species_training "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/train.py"
click node_binary_training "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/train_binary.py"
click node_evaluation "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/evaluate_pipeline.py"
click node_binary_evaluation "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/evaluate_binary.py"
click node_gap_analysis "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/gap_analysis.py"
click node_taxonomy_analysis "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/analyze_confusion.py"
click node_taxonomy_validation "https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/taxonomy_check.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_offline_runner,node_pipeline,node_trap_detection,node_binary_filter,node_species_classifier toneBlue
class node_ros_trap,node_ros_binary,node_ros_species,node_ros_heatmap,node_launch toneAmber
class node_heatmap_png,node_heatmap_html toneMint
class node_dataset_prep,node_binary_data,node_species_training,node_binary_training toneRose
class node_evaluation,node_binary_evaluation,node_gap_analysis,node_taxonomy_analysis,node_taxonomy_validation,node_image_operator,node_amiga_camera,node_gps toneIndigo
```

## Components

### Inference pipeline

- [Batch runner](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/run_all.py): `src/run_all.py`
- [Inference orchestrator](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/pipeline.py): `src/pipeline.py`
- [Trap detection](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/trap_detector.py): `src/trap_detector.py`
- [Insect filter](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/pipeline.py): `src/pipeline.py`
- [Species classifier](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/pipeline.py): `src/pipeline.py`

### ROS deployment

- [ROS trap detector](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/trap_detector_node.py): `ros2_nodes/pest_detection_nodes/trap_detector_node.py`
- [ROS insect filter](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/binary_filter_node.py): `ros2_nodes/pest_detection_nodes/binary_filter_node.py`
- [ROS species classifier](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/species_classifier_node.py): `ros2_nodes/pest_detection_nodes/species_classifier_node.py`
- [ROS heatmap logger](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/pest_detection_nodes/heatmap_node.py): `ros2_nodes/pest_detection_nodes/heatmap_node.py`
- [ROS launch](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/ros2_nodes/launch/pest_detection.launch.py): `ros2_nodes/launch/pest_detection.launch.py`

### Field outputs

- [PNG heatmap](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/heatmap.py): `src/heatmap.py`
- [HTML heatmap](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/heatmap_html.py): `src/heatmap_html.py`

### Data and models

- [Dataset preparation](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/prepare_dataset.py): `src/prepare_dataset.py`
- [Binary dataset builder](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/build_binary_dataset.py): `src/build_binary_dataset.py`
- [Species model training](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/train.py): `src/train.py`
- [Binary model training](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/train_binary.py): `src/train_binary.py`

### Evaluation and analysis

- [Pipeline evaluation](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/evaluate_pipeline.py): `src/evaluate_pipeline.py`
- [Binary evaluation](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/evaluate_binary.py): `src/evaluate_binary.py`
- [Dataset gap analysis](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/gap_analysis.py): `src/gap_analysis.py`
- [Taxonomic error analysis](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/analyze_confusion.py): `src/analyze_confusion.py`
- [Taxonomy validation](https://github.com/nikitasharma768/farm-ng-pest-model/blob/main/src/taxonomy_check.py): `src/taxonomy_check.py`

### Other components

- **Image operator**
- **Amiga camera**
- **Amiga GPS**

## Connections

- Image operator → Batch runner: provides images (evidence: `README.md`)
- Batch runner → Inference orchestrator: runs pipeline (evidence: `README.md`)
- Inference orchestrator → Trap detection: detects traps (evidence: `src/pipeline.py`)
- Inference orchestrator → Insect filter: classifies insect (evidence: `src/pipeline.py`)
- Inference orchestrator → Species classifier: classifies species (evidence: `src/pipeline.py`)
- Inference orchestrator → PNG heatmap: produces heatmap
- Inference orchestrator → HTML heatmap: produces heatmap
- Amiga camera → ROS trap detector: publishes frames (evidence: `README.md`)
- ROS trap detector → ROS insect filter: publishes crops (evidence: `README.md`)
- ROS insect filter → ROS species classifier: forwards insects (evidence: `README.md`)
- ROS species classifier → ROS heatmap logger: publishes species (evidence: `README.md`)
- Amiga GPS → ROS heatmap logger: provides fixes (evidence: `README.md`)
- ROS heatmap logger → PNG heatmap: runs generator (evidence: `ros2_nodes/pest_detection_nodes/heatmap_node.py`)
- ROS heatmap logger → HTML heatmap: runs generator (evidence: `ros2_nodes/pest_detection_nodes/heatmap_node.py`)
- ROS launch → ROS trap detector: starts node (evidence: `ros2_nodes/launch/pest_detection.launch.py`)
- ROS launch → ROS insect filter: starts node (evidence: `ros2_nodes/launch/pest_detection.launch.py`)
- ROS launch → ROS species classifier: starts node (evidence: `ros2_nodes/launch/pest_detection.launch.py`)
- ROS launch → ROS heatmap logger: starts node (evidence: `ros2_nodes/launch/pest_detection.launch.py`)
- Dataset preparation → Species model training: prepares data
- Binary dataset builder → Binary model training: prepares data
- Inference orchestrator → Pipeline evaluation: evaluated by (evidence: `src/evaluate_pipeline.py`)
- Binary model training → Binary evaluation: evaluated by
- Dataset gap analysis → Dataset preparation: guides coverage
- Taxonomic error analysis → Taxonomy validation: checks taxonomy
