# bansal6003/interpretable_ai_for_zebrafish_phenotyping architecture

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

- Interactive diagram: https://gitdiagram.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping
- Repository: https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping

## Overview

1. **Repository shape**
   This is not a single monolithic application; it is a research/codebase organized into several mostly independent pipelines for zebrafish phenotyping, plus a set of exploratory LLM notebooks/scripts. The core architecture is a **data-processing and model-training stack** that feeds a separate **inference/analysis layer**.

2. **Primary domain flow**
   The main end-to-end flow is:
   **raw zebrafish image/video/time-series data → preprocessing → task-specific model training → inference/measurement outputs → visual validation and reporting**.
   The repo is centered on extracting biologically meaningful phenotype and behavior signals from larval zebrafish experiments.

3. **Preprocessing layer**
   `Preprocessing_Pipeline/` is the ingestion and normalization boundary. It contains two major branches:
   - **Animal image preprocessing**: image subfolder extraction, augmentations, polygon-to-mask conversion, and larva isolation using YOLO.
   - **Animal behavior data extraction**: genotype isolation, gene sequencing mapping, Excel merging, time-series combing, and behavior analysis.
   This layer prepares heterogeneous lab outputs into model-ready datasets and structured measurements.

4. **Image classification subsystem**
   `Image_Classification_Training/` contains standalone training scripts for **RegNetY-16** and **ViT-B/16** classifiers. The README indicates the main production-relevant classifier is **RegNetY-16 transfer learning**. This subsystem is responsible for coarse phenotypic labeling and mutant classification from larval imagery.

5. **Image segmentation subsystem**
   `Image_segmentation_Training/` trains **DeepLabV3+ with a RegNetY-16 encoder** for anatomical segmentation. This is the morphometry branch: it turns images into masks for structures like whole larva, eye, head, yolk sac, and pericardium, enabling downstream measurements such as area and shape-derived traits.

6. **Object detection and tracking**
   `Object_Detection_Training/YOLO_ultralytics.py` and `Object Tracking/` form the detection/tracking side of the vision stack. YOLO is used for localization tasks, while the tracking scripts and metrics suggest a separate pipeline for propagating detections across frames and evaluating tracker quality. This is likely used when individual animals or regions must be followed over time rather than classified per frame.

7. **Behavioral time-series subsystem**
   `Time_series_animal_behavior_Pipeline/Time_series_Training_and_Inference.py` implements the behavioral modeling path. The README names **LSTM and XGBoost** as the main behavior models, implying a feature-extraction-to-sequence-model flow for electromechanical stimulus responses and temporal phenotype analysis.

8. **Inference and application boundary**
   `Model_Inference/` is the runtime-facing layer. `DanioV16_core.py` appears to hold the main inference logic, while `main_window_Entry_Point.py` and related files suggest a GUI-oriented entry point for end users. `LLM_based_summariztion.py` indicates a reporting/summarization component layered on top of model outputs. This layer consumes trained models and produces human-readable or visual outputs for analysis.

9. **Experiment tracking and reproducibility**
   The README explicitly calls out **MLflow** logging in the classification work. Architecturally, this means model training is expected to record parameters, metrics, and runs for comparison and reproducibility. That tracking boundary is important because the repo is research-heavy and relies on experiment provenance rather than a single deployed model artifact.

10. **Exploratory / non-core AI work**
    `Passive_AI_Learning/` contains notebooks and scripts for unrelated learning exercises: CNN architecture experiments, anomaly detection VAE, ResNet-from-scratch, LangGraph workflows, Streamlit frontends, and RAG examples. These are best treated as a **sandbox layer** separate from the zebrafish pipeline. They show tooling familiarity but are not part of the main phenotyping architecture.

11. **Data products and outputs**
    The outputs of the core pipelines are not just predictions; they include **confusion matrices, accuracy plots, segmentation masks, IoU/Dice curves, clustering visualizations, and morphometric measurements**. `Sample_work_Processing_and_Visualization/` likely contains example artifacts demonstrating these results. The system is designed to produce interpretable outputs suitable for biologist review.

12. **Main architectural boundaries**
    For diagramming, the clearest boundaries are:
    - **Preprocessing / data curation**
    - **Image classification**
    - **Segmentation / morphometry**
    - **Detection / tracking**
    - **Behavioral time-series modeling**
    - **Inference/GUI/reporting**
    - **Research sandbox / notebooks**
    The repo is best understood as a collection of task-specific ML pipelines sharing a biological domain and data sources, rather than as a single service with one shared runtime.

Main entry points: [`Model_Inference/DanioV16_core.py`](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Model_Inference/DanioV16_core.py) (Core infer), [`Preprocessing_Pipeline/Animal_image_preprocessing`](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Preprocessing_Pipeline/Animal_image_preprocessing) (Image prep), [`Sample_work_Processing_and_Visualization/AI_Analysis_Sample_outputs`](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Sample_work_Processing_and_Visualization/AI_Analysis_Sample_outputs) (Sample outputs), [`Image_segmentation_Training/DeepLabV3Plus_RegNet_y_16_Image_segmentation.py`](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Image_segmentation_Training/DeepLabV3Plus_RegNet_y_16_Image_segmentation.py) (DeepLabV3+)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_preprocess["Preprocessing"]
  node_preprocess_image["Image prep"]
  node_preprocess_behavior["Behavior prep<br/>behavior extraction"]
end

subgraph group_grp_vision_train["Vision training"]
  node_clf_regnet["RegNetY-16<br/>image classifier"]
  node_clf_vit["ViT-B/16<br/>image classifier"]
  node_seg_deeplab["DeepLabV3+<br/>segmentation model"]
  node_det_yolo["YOLO detect<br/>detector"]
end

subgraph group_grp_tracking["Tracking"]
  node_track_train["Tracker train<br/>tracking pipeline"]
  node_track_predict["Track predictor<br/>tracking inference<br/>[track_predictor.py]"]
  node_track_metrics["Track metrics<br/>evaluation"]
end

subgraph group_grp_timeseries["Time series"]
  node_ts_model["Behavior model<br/>sequence model"]
end

subgraph group_grp_infer["Inference"]
  node_inference_core["Core infer<br/>runtime core<br/>[DanioV16_core.py]"]
  node_inference_gui["Main window<br/>GUI entry"]
  node_llm_summary["LLM summary<br/>reporting"]
end

subgraph group_grp_sandbox["Sandbox"]
  node_sandbox_cv["CV sandbox<br/>exploratory vision"]
  node_sandbox_langgraph["LangGraph lab<br/>LLM workflow practice"]
  node_sandbox_rag["RAG lab<br/>LLM/RAG practice"]
end

subgraph group_grp_outputs["Outputs"]
  node_sample_outputs["Sample outputs<br/>visual artifacts"]
end

node_preprocess_image -->|"image data"| node_clf_regnet
node_preprocess_image -->|"image data"| node_clf_vit
node_preprocess_image -->|"masks/images"| node_seg_deeplab
node_preprocess_image -->|"localized data"| node_det_yolo
node_preprocess_image -->|"frames"| node_track_train
node_preprocess_behavior -->|"features"| node_ts_model
node_preprocess_behavior -->|"structured input"| node_inference_core
node_clf_regnet -->|"classifier"| node_inference_core
node_clf_vit -->|"classifier"| node_inference_core
node_seg_deeplab -->|"segmenter"| node_inference_core
node_det_yolo -->|"detections"| node_track_predict
node_track_train -->|"tracker"| node_track_predict
node_track_predict -->|"scores"| node_track_metrics
node_ts_model -->|"behavior model"| node_inference_core
node_inference_core -->|"results"| node_inference_gui
node_inference_core -->|"outputs"| node_llm_summary
node_inference_core -->|"artifacts"| node_sample_outputs
node_llm_summary -->|"reports"| node_sample_outputs
node_seg_deeplab -->|"masks/plots"| node_sample_outputs
node_ts_model -->|"curves"| node_sample_outputs
node_det_yolo -->|"detections"| node_sample_outputs
node_sandbox_cv -.->|"experiments"| node_sandbox_langgraph
node_sandbox_langgraph -.->|"workflow study"| node_sandbox_rag

click node_preprocess_image "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Preprocessing_Pipeline/Animal_image_preprocessing"
click node_preprocess_behavior "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Preprocessing_Pipeline/Animal_behavior_Data_extraction"
click node_clf_regnet "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Image_Classification_Training/RegNet_Y_16GF_IMAGENET1K_SWAG_E2E_V1_image_classiifcation.py"
click node_clf_vit "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Image_Classification_Training/Vit_B_16_Image_classification_model_with_mlflow_logging.py"
click node_seg_deeplab "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Image_segmentation_Training/DeepLabV3Plus_RegNet_y_16_Image_segmentation.py"
click node_det_yolo "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Object_Detection_Training/YOLO_ultralytics.py"
click node_track_train "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Object Tracking/Object_tracker_training.py"
click node_track_predict "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Object Tracking/track_predictor.py"
click node_track_metrics "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Object Tracking/track_predictor_metrics.py"
click node_ts_model "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Time_series_animal_behavior_Pipeline/Time_series_Training_and_Inference.py"
click node_inference_core "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Model_Inference/DanioV16_core.py"
click node_inference_gui "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Model_Inference/main_window_Entry_Point.py"
click node_llm_summary "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Model_Inference/LLM_based_summariztion.py"
click node_sandbox_cv "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Passive_AI_Learning/Computer_vision_architecture_designing"
click node_sandbox_langgraph "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Passive_AI_Learning/LangGraph Practice"
click node_sandbox_rag "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Passive_AI_Learning/RAG Practice"
click node_sample_outputs "https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Sample_work_Processing_and_Visualization/AI_Analysis_Sample_outputs"

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_preprocess_image,node_preprocess_behavior,node_sample_outputs toneBlue
class node_clf_regnet,node_clf_vit,node_seg_deeplab,node_det_yolo toneAmber
class node_track_train,node_track_predict,node_track_metrics toneMint
class node_ts_model toneRose
class node_inference_core,node_inference_gui,node_llm_summary toneIndigo
class node_sandbox_cv,node_sandbox_langgraph,node_sandbox_rag toneTeal
```

## Components

### Preprocessing

Data curation and normalization for image and behavior inputs.

- [Image prep](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Preprocessing_Pipeline/Animal_image_preprocessing): image preprocessing · Subfolder extraction, augmentation, polygon-to-mask conversion, and larva isolation. · `Preprocessing_Pipeline/Animal_image_preprocessing`
- [Behavior prep](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Preprocessing_Pipeline/Animal_behavior_Data_extraction): behavior extraction · Genotype isolation, gene mapping, Excel merging, time-series combining, and behavior analysis. · `Preprocessing_Pipeline/Animal_behavior_Data_extraction`

### Vision training

Task-specific model training for image classification, segmentation, and detection.

- [RegNetY-16](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Image_Classification_Training/RegNet_Y_16GF_IMAGENET1K_SWAG_E2E_V1_image_classiifcation.py): image classifier · Primary phenotypic classifier with transfer learning. · `Image_Classification_Training/RegNet_Y_16GF_IMAGENET1K_SWAG_E2E_V1_image_classiifcation.py`
- [ViT-B/16](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Image_Classification_Training/Vit_B_16_Image_classification_model_with_mlflow_logging.py): image classifier · Alternative vision transformer classifier with MLflow logging. · `Image_Classification_Training/Vit_B_16_Image_classification_model_with_mlflow_logging.py`
- [DeepLabV3+](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Image_segmentation_Training/DeepLabV3Plus_RegNet_y_16_Image_segmentation.py): segmentation model · Anatomical segmentation for larva, eye, head, yolk sac, and pericardium. · `Image_segmentation_Training/DeepLabV3Plus_RegNet_y_16_Image_segmentation.py`
- [YOLO detect](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Object_Detection_Training/YOLO_ultralytics.py): detector · Localization model used for larva or region detection. · `Object_Detection_Training/YOLO_ultralytics.py`

### Tracking

Multi-frame tracking and evaluation around detections.

- [Tracker train](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/HEAD/Object%20Tracking/Object_tracker_training.py): tracking pipeline · Training and configuration for frame-to-frame tracking. · `Object Tracking/Object_tracker_training.py`
- [Track predictor](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/HEAD/Object%20Tracking/track_predictor.py): tracking inference · Runs tracking across frames to propagate detections. · `Object Tracking/track_predictor.py`
- [Track metrics](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/HEAD/Object%20Tracking/track_predictor_metrics.py): evaluation · Tracker quality and performance evaluation. · `Object Tracking/track_predictor_metrics.py`

### Time series

Behavioral sequence modeling and inference.

- [Behavior model](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Time_series_animal_behavior_Pipeline/Time_series_Training_and_Inference.py): sequence model · LSTM and XGBoost-based behavioral modeling and inference. · `Time_series_animal_behavior_Pipeline/Time_series_Training_and_Inference.py`

### Inference

Runtime layer for model use, GUI, and summarization.

- [Core infer](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Model_Inference/DanioV16_core.py): runtime core · Main inference logic for the zebrafish application. · `Model_Inference/DanioV16_core.py`
- [Main window](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Model_Inference/main_window_Entry_Point.py): GUI entry · User-facing entry point for running analysis and viewing results. · `Model_Inference/main_window_Entry_Point.py`
- [LLM summary](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/blob/main/Model_Inference/LLM_based_summariztion.py): reporting · Summarizes model outputs into human-readable analysis. · `Model_Inference/LLM_based_summariztion.py`

### Sandbox

Exploratory notebooks and unrelated AI practice work.

- [CV sandbox](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Passive_AI_Learning/Computer_vision_architecture_designing): exploratory vision · Standalone computer-vision experiments: CNNs, VAE anomaly detection, and ResNet-from-scratch. · `Passive_AI_Learning/Computer_vision_architecture_designing`
- [LangGraph lab](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/HEAD/Passive_AI_Learning/LangGraph%20Practice): LLM workflow practice · Notebook-based experiments for workflows, persistence, streaming, and fault tolerance. · `Passive_AI_Learning/LangGraph Practice`
- [RAG lab](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/HEAD/Passive_AI_Learning/RAG%20Practice): LLM/RAG practice · Progressive experiments with simple LLM calls, chains, agents, and RAG variants. · `Passive_AI_Learning/RAG Practice`

### Outputs

Example artifacts and visual validation outputs.

- [Sample outputs](https://github.com/bansal6003/interpretable_ai_for_zebrafish_phenotyping/tree/main/Sample_work_Processing_and_Visualization/AI_Analysis_Sample_outputs): visual artifacts · Example analysis artifacts and visualization outputs for review. · `Sample_work_Processing_and_Visualization/AI_Analysis_Sample_outputs`

## Connections

- Image prep → RegNetY-16: image data · Prepared images feed classifier training.
- Image prep → ViT-B/16: image data · Prepared images feed alternate classifier training.
- Image prep → DeepLabV3+: masks/images · Normalized image assets feed segmentation training.
- Image prep → YOLO detect: localized data · Preprocessed imagery supports detector training.
- Image prep → Tracker train: frames · Prepared image sequences support tracker training.
- Behavior prep → Behavior model: features · Curated behavioral tables and sequences feed time-series modeling.
- Behavior prep → Core infer: structured input · Behavioral preprocessing can feed the runtime analysis core.
- RegNetY-16 → Core infer: classifier · Trained classifier is consumed by runtime inference.
- ViT-B/16 → Core infer: classifier · Alternative classifier can be loaded for inference.
- DeepLabV3+ → Core infer: segmenter · Segmentation model outputs are consumed during analysis.
- YOLO detect → Track predictor: detections · Detector outputs seed tracking across frames.
- Tracker train → Track predictor: tracker · Trained tracking logic is used at inference time.
- Track predictor → Track metrics: scores · Tracking predictions are evaluated by metrics.
- Behavior model → Core infer: behavior model · Time-series predictions flow into the runtime layer.
- Core infer → Main window: results · Core inference powers the GUI entry point.
- Core infer → LLM summary: outputs · Model outputs are summarized into readable reports.
- Core infer → Sample outputs: artifacts · Inference generates example visual and numeric outputs.
- LLM summary → Sample outputs: reports · Summaries and visualizations are collected as sample outputs.
- DeepLabV3+ → Sample outputs: masks/plots · Segmentation produces masks and quality plots.
- Behavior model → Sample outputs: curves · Behavior modeling contributes analysis visualizations.
- YOLO detect → Sample outputs: detections · Detection results can be reviewed as sample artifacts.
- CV sandbox → LangGraph lab: experiments · General AI experimentation spans multiple sandbox areas.
- LangGraph lab → RAG lab: workflow study · LLM workflow practice connects to RAG practice as exploratory work.
