How oceam/deepsorghumhead works
Project Type & Purpose
• This is an open-source deep‐learning tool (built on top of Keras and the “keras-retinanet” base) for sorghum head detection and counting.
• It provides training, inference conversion, evaluation and debugging pipelines, plus support for multiple backends (TensorFlow, Theano, CNTK).
High-Level Architectural Components
a. Data Ingestion & Storage
• CSV Annotation Files (e.g., annotations_map.csv, train/test CSVs)
• Image Dataset (downloaded separately via provided form)
b. Preprocessing Layer
• DeepSorghumHead_Keras/preprocessing (Generator, CSVGenerator)
• Tools: resize_img.py, csv_generator logic
c. Model Definition & Backends
• Models (ResNet, VGG, MobileNet, DenseNet, RetinaNet) under DeepSorghumHead_Keras/models
• Custom Layers & Losses under DeepSorghumHead_Keras/layers & losses.py
• Initializers & Callbacks (common operations, evaluation callbacks)
• Backend abstraction in DeepSorghumHead_Keras/backend (tensorflow_backend, theano_backend, cntk_backend)
d. Training Pipeline
• Entry script: train.py / train_SorghumHead.py
• Training loop invoking data generators → model → loss → callbacks → snapshot saving
e. Inference Conversion
• Script: convert_model.py transforms training‐time model to inference model (merges anchors, detection logic)
• Output: “inference model” weights in bin/inf_models/
f. Evaluation & Debugging
• evaluate.py: loads inference model + test data → runs detections → writes result files
• debug.py: visualizes annotations vs. anchor availability
g. Utilities & Visualization
• DeepSorghumHead_Keras/utils (anchors, image ops, visualization)
• FM_Vis.py: feature map visualization
Relationships & Data Flow
• Data Ingestion → Preprocessing → Model Building → Training Loop → Checkpointed Models
• Checkpointed Models → convert_model.py → Inference Model
• Inference Model + Test Data → evaluate.py → Quantitative Results
• Data + Inference Model → debug.py / FM_Vis.py → Visual Diagnostics
Key Architectural Patterns & Principles
• Modular layering: clear separation of data generators, model definition, training logic, callbacks, backend abstraction.
• Strategy pattern for backends: interchangeable TensorFlow/Theano/CNTK implementations.
• Pipeline scripts orchestrate workflows without embedding core logic.
• Reuse of base keras-retinanet patterns: anchor generation, filter_detections, CSVGenerator.
Elements
• From data → preprocessing → training
• From training → model conversion
• From inference model → evaluation/debug
• External service blocks: GPU/CUDA, TensorBoard logs