# gopisam1126/agricultural-crop-classifier architecture

> Architecture diagram of the GitHub repository gopisam1126/agricultural-crop-classifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gopisam1126/agricultural-crop-classifier
- Repository: https://github.com/gopisam1126/agricultural-crop-classifier

## Overview

##### Project Type and Purpose
- This is a machine-learning image classification pipeline for agricultural crops.
- It combines handcrafted computer-vision descriptors (LBP, GLCM, Gabor, ORB+BoVW) with deep embeddings from a pretrained VGG16, then applies feature selection (PCA, RFE) and trains an SVM classifier.

##### File Structure
- Top-level directories:
- Agricultural-crops/… (one subfolder per crop class, containing the raw images)
- Top-level files:
- image_classifier_model.py (the orchestration script that builds the pipeline, trains, evaluates, and saves the model)
- README.md (describes the pipeline components)

##### Main Components
a. Data Source
– “Agricultural-crops” directory with per-class image folders.
b. Preprocessing & Augmentation (if any)
– Resizing, normalization, any augmentation steps before feature extraction.
c. Handcrafted Feature Extractors (parallel branch)
– Local Binary Patterns (LBP)
– Gray-Level Co-occurrence Matrix (GLCM)
– Gabor filter bank responses
– ORB feature detection + Bag-of-Visual-Words model
d. Deep Feature Extractor (parallel branch)
– PyTorch’s pretrained VGG16 up to a penultimate layer to produce deep embeddings
e. Feature Aggregation
– Concatenate handcrafted vectors with deep embeddings into a single feature vector
f. Feature Selection & Dimensionality Reduction
– Principal Component Analysis (PCA)
– Recursive Feature Elimination (RFE)
g. Classifier
– Support Vector Machine (SVM) from scikit-learn
h. Model Persistence & Prediction
– Save trained SVM model (e.g., joblib/pickle)
– Inference flow: load model, extract features, predict class label

##### Relationships and Data Flow
1. Data Source → Preprocessing
2. Preprocessing → (split) → Handcrafted Extractors
3. Preprocessing → (split) → Deep Extractor (VGG16)
4. Handcrafted Features + Deep Embeddings → Aggregation
5. Aggregated Features → Feature Selection (PCA → RFE)
6. Selected Features → SVM Training → Trained Model
7. Inference Path: New Image → Full Pipeline → Model → Prediction

##### Important Architectural Patterns and Design Principles
- Pipeline pattern with clearly separated stages
- Parallel feature-extraction branches for classic vs. deep features
- Modularity: each extractor is its own component/module
- Reusability: image_classifier_model.py orchestrates end-to-end flow
- Separation of training vs. inference logic

##### Technologies, Frameworks, and Libraries
- Python 3.x
- OpenCV / scikit-image for LBP, GLCM, Gabor filters
- OpenCV for ORB + custom BoVW
- PyTorch for pretrained VGG16 embeddings
- scikit-learn for PCA, RFE, SVM
- joblib or pickle for model serialization

##### How to Proceed
1. Sketch the overall pipeline on paper, grouping related steps.
2. Two lanes: Training vs. Inference.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Training Pipeline
    subgraph "Training Pipeline"
        DS["Raw Images\n(Agricultural-crops/)"]:::data
        PRE["Preprocessing & Augmentation"]:::pre
        HF["Handcrafted Feature Extractors"]:::pre
        subgraph " "
            LBP["LBP"]:::pre
            GLCM["GLCM"]:::pre
            Gabor["Gabor"]:::pre
            ORB["ORB+BoVW"]:::pre
        end
        DE["Deep Feature Extractor\n(VGG16)"]:::pre
        AGG["Feature Aggregation"]:::pre
        FS["Feature Selection\n(PCA → RFE)"]:::fs
        SVM["SVM Training\n(SVM)"]:::model
        MS["Model Persistence\n(Save Model)"]:::model
    end

    %% Inference Pipeline
    subgraph "Inference Pipeline"
        NI["New Image"]:::input
        PRP["Preprocessing"]:::pre
        HF2["Handcrafted Feature Extractors"]:::pre
        DE2["Deep Feature Extractor"]:::pre
        AGG2["Feature Aggregation"]:::pre
        FS2["Feature Selection"]:::fs
        PRED["Predict Label"]:::model
    end

    %% Documentation
    DOC["README.md"]:::doc

    %% Connections - Training
    DS --> PRE
    PRE --> HF
    PRE --> DE
    HF --> AGG
    DE --> AGG
    AGG --> FS
    FS --> SVM
    SVM --> MS

    %% Connections - Inference
    NI --> PRP
    PRP --> HF2
    PRP --> DE2
    HF2 --> AGG2
    DE2 --> AGG2
    AGG2 --> FS2
    FS2 --> PRED

    %% Click Events
    click DS "https://github.com/gopisam1126/agricultural-crop-classifier/tree/main/Agricultural-crops/"
    click PRE "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click HF "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click DE "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click AGG "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click FS "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click SVM "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click MS "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click PRP "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click HF2 "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click DE2 "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click AGG2 "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click FS2 "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click PRED "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/image_classifier_model.py"
    click DOC "https://github.com/gopisam1126/agricultural-crop-classifier/blob/main/README.md"

    %% Styles
    classDef data fill:#cccccc,stroke:#333,stroke-width:1px
    classDef pre fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef fs fill:#FFA500,stroke:#333,stroke-width:1px
    classDef model fill:#90EE90,stroke:#333,stroke-width:1px
    classDef input fill:#e6e6fa,stroke:#333,stroke-width:1px
    classDef doc fill:#ffffff,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
```
