# ahsan47-hq/weed-detection-project architecture

> Architecture diagram of the GitHub repository ahsan47-hq/weed-detection-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahsan47-hq/weed-detection-project
- Repository: https://github.com/ahsan47-hq/weed-detection-project

## Overview

This repository is a weed-image preparation and instance-segmentation workflow, not the full-stack application mentioned in the README. Its principal path prepares datasets, generates SAM2 masks and YOLO polygon labels, cleans the training set, then trains and evaluates YOLOv8-Seg. It also contains DeepWeeds augmentation/dataset support and a separate CWFID resize-and-split utility. The main pipeline stages are documented in the README; source-level evidence is available for the SAM conversion, training, and augmentation components, but not every utility or the evaluation script.

Main entry points: [`src/utils/train_yolov8_seg.py`](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/train_yolov8_seg.py) (YOLOv8-Seg training), [`src/utils/sam_masks_to_yolo.py`](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/sam_masks_to_yolo.py) (SAM2 mask generation), [`src/utils/split_deepweeds.py`](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/split_deepweeds.py) (DeepWeeds split), [`src/utils/create_annotations_yolo.py`](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/create_annotations_yolo.py) (YOLO dataset creation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Dataset preparation"]
  node_raw[("Raw weed images")]
  node_deepweeds_split["DeepWeeds split<br/>[split_deepweeds.py]"]
  node_yolo_annotations["YOLO dataset creation"]
  node_cwfid["CWFID resize and split"]
  node_dataset_cleanup["Training-set cleanup"]
  node_dataset_config["Dataset configuration"]
end

subgraph group_annotation["Mask annotation"]
  node_sam["SAM2 mask generation"]
  node_sam2_service["SAM2 predictor"]
  node_mask_refinement["Mask filtering and refinement"]
  node_yolo_labels["YOLO polygon labels"]
end

subgraph group_model["Model training and evaluation"]
  node_trainer["YOLOv8-Seg training"]
  node_ultralytics["Ultralytics YOLO"]
  node_predictor["Segmentation prediction<br/>[test_yolov8_seg.py]"]
  node_results[("Training and test results")]
end

subgraph group_support["Training support"]
  node_augmentations["DeepWeeds augmentations"]
  node_dataset_adapter["YOLO dataset adapter"]
end

node_user(("Dataset operator"))

node_user -->|"provides images"| node_raw
node_raw -->|"splits labels"| node_deepweeds_split
node_deepweeds_split -->|"supplies splits"| node_yolo_annotations
node_raw -->|"resizes and splits"| node_cwfid
node_yolo_annotations -->|"prepares images"| node_sam
node_sam -->|"requests masks"| node_sam2_service
node_sam -->|"filters masks"| node_mask_refinement
node_mask_refinement -->|"writes polygons"| node_yolo_labels
node_yolo_labels -->|"selects images"| node_dataset_cleanup
node_dataset_cleanup -->|"prepares training data"| node_trainer
node_dataset_config -->|"configures dataset"| node_trainer
node_trainer -->|"trains model"| node_ultralytics
node_trainer -->|"predicts with best model"| node_predictor
node_ultralytics -->|"writes run artifacts"| node_results
node_predictor -->|"saves predictions"| node_results
node_dataset_adapter -->|"applies during training"| node_augmentations

click node_deepweeds_split "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/split_deepweeds.py"
click node_yolo_annotations "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/create_annotations_yolo.py"
click node_cwfid "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/resize_split_cwfid.py"
click node_sam "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/sam_masks_to_yolo.py"
click node_mask_refinement "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/sam_masks_to_yolo.py"
click node_yolo_labels "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/sam_masks_to_yolo.py"
click node_dataset_cleanup "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/preparing_for_yoloseg_training.py"
click node_dataset_config "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/create_data_yaml.py"
click node_augmentations "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/deepweeds_augmentation.py"
click node_dataset_adapter "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/deepweeds_yolo_dataset.py"
click node_trainer "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/train_yolov8_seg.py"
click node_predictor "https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/test_yolov8_seg.py"
click node_results "https://github.com/ahsan47-hq/weed-detection-project/tree/main/results"

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_raw,node_deepweeds_split,node_yolo_annotations,node_cwfid,node_dataset_cleanup,node_dataset_config toneBlue
class node_sam,node_sam2_service,node_mask_refinement,node_yolo_labels toneAmber
class node_trainer,node_ultralytics,node_predictor,node_results toneMint
class node_augmentations,node_dataset_adapter toneRose
class node_user toneIndigo
```

## Components

### Dataset preparation

- **Raw weed images**
- [DeepWeeds split](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/split_deepweeds.py): `src/utils/split_deepweeds.py`
- [YOLO dataset creation](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/create_annotations_yolo.py): `src/utils/create_annotations_yolo.py`
- [CWFID resize and split](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/resize_split_cwfid.py): `src/utils/resize_split_cwfid.py`
- [Training-set cleanup](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/preparing_for_yoloseg_training.py): `src/utils/preparing_for_yoloseg_training.py`
- [Dataset configuration](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/create_data_yaml.py): `src/utils/create_data_yaml.py`

### Mask annotation

- [SAM2 mask generation](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/sam_masks_to_yolo.py): `src/utils/sam_masks_to_yolo.py`
- **SAM2 predictor**
- [Mask filtering and refinement](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/sam_masks_to_yolo.py): `src/utils/sam_masks_to_yolo.py`
- [YOLO polygon labels](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/sam_masks_to_yolo.py): `src/utils/sam_masks_to_yolo.py`

### Model training and evaluation

- [YOLOv8-Seg training](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/train_yolov8_seg.py): `src/utils/train_yolov8_seg.py`
- **Ultralytics YOLO**
- [Segmentation prediction](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/test_yolov8_seg.py): `src/utils/test_yolov8_seg.py`
- [Training and test results](https://github.com/ahsan47-hq/weed-detection-project/tree/main/results): `results`

### Training support

- [DeepWeeds augmentations](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/deepweeds_augmentation.py): `src/utils/deepweeds_augmentation.py`
- [YOLO dataset adapter](https://github.com/ahsan47-hq/weed-detection-project/blob/main/src/utils/deepweeds_yolo_dataset.py): `src/utils/deepweeds_yolo_dataset.py`

### Other components

- **Dataset operator**

## Connections

- Dataset operator → Raw weed images: provides images (evidence: `README.md`)
- Raw weed images → DeepWeeds split: splits labels (evidence: `src/utils/split_deepweeds.py`)
- DeepWeeds split → YOLO dataset creation: supplies splits (evidence: `src/utils/create_annotations_yolo.py`)
- Raw weed images → CWFID resize and split: resizes and splits (evidence: `src/utils/resize_split_cwfid.py`)
- YOLO dataset creation → SAM2 mask generation: prepares images (evidence: `README.md`)
- SAM2 mask generation → SAM2 predictor: requests masks (evidence: `src/utils/sam_masks_to_yolo.py`)
- SAM2 mask generation → Mask filtering and refinement: filters masks (evidence: `src/utils/sam_masks_to_yolo.py`)
- Mask filtering and refinement → YOLO polygon labels: writes polygons (evidence: `src/utils/sam_masks_to_yolo.py`)
- YOLO polygon labels → Training-set cleanup: selects images (evidence: `src/utils/preparing_for_yoloseg_training.py`)
- Training-set cleanup → YOLOv8-Seg training: prepares training data (evidence: `README.md`)
- Dataset configuration → YOLOv8-Seg training: configures dataset (evidence: `README.md`)
- YOLOv8-Seg training → Ultralytics YOLO: trains model (evidence: `src/utils/train_yolov8_seg.py`)
- YOLOv8-Seg training → Segmentation prediction: predicts with best model (evidence: `src/utils/train_yolov8_seg.py`)
- Ultralytics YOLO → Training and test results: writes run artifacts
- Segmentation prediction → Training and test results: saves predictions (evidence: `README.md`)
- YOLO dataset adapter → DeepWeeds augmentations: applies during training (evidence: `src/utils/deepweeds_yolo_dataset.py`)
