# wimlds-trojmiasto/detect-waste architecture

> Architecture diagram of the GitHub repository wimlds-trojmiasto/detect-waste, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wimlds-trojmiasto/detect-waste
- Repository: https://github.com/wimlds-trojmiasto/detect-waste

## Overview

1. This repository is a research codebase for waste detection and classification, not a single application. The top level is organized around four model families: EfficientDet, DETR, Mask R-CNN/Fast R-CNN, and a separate image classifier. Each subproject is largely self-contained with its own training, evaluation, and utility code.

2. The core domain boundary is the dataset/annotation layer under `annotations/`. The project standardizes multiple public waste datasets into COCO-like JSON files, with variants for multiclass detection, binary litter-vs-background detection, and “mixed” single-class training across datasets. These annotation files are the shared input contract for the model trainers.

3. Data preprocessing is handled by the root scripts `annotations_preprocessing.py` and `annotations_preprocessing_multi.py`, plus helper utilities in `utils/`. Their role is to merge heterogeneous datasets, remap labels, and split train/test sets. This is the main ETL stage that converts raw dataset exports into model-ready annotation files.

4. The detection/segmentation stack is split into multiple implementation paths:
   - `efficientdet/` for EfficientDet-based object detection,
   - `detr/` for transformer-based detection,
   - `MaskRCNN/` and `FastRCNN/` for torchvision-style detection/segmentation pipelines.
   Each subproject contains its own model definition, engine/training loop, dataset adapter, transforms, and COCO evaluation helpers.

5. `efficientdet/` is the most complete detection subsystem. It includes model config, dataset parsers for COCO/Open Images/VOC, augmentation/transforms, anchor/loss logic, training and validation entry points, and distributed-training helpers. This subtree is effectively a mini-framework layered over PyTorch for detection experiments.

6. `detr/` follows the official DETR-style architecture more closely: dataset loaders in `detr/datasets`, model pieces in `detr/models`, training/evaluation orchestration in `detr/engine.py` and `detr/main.py`, and utility code for boxes/metrics/plotting. It is structured as an end-to-end detection pipeline with optional segmentation support.

7. `MaskRCNN/` and `FastRCNN/` are lighter-weight PyTorch/Torchvision implementations. They rely on COCO-style annotations and include engines, transforms, and COCO evaluation utilities. Their architecture is simpler than the EfficientDet and DETR stacks, reflecting that they are baseline/reference implementations.

8. The classification subsystem lives in `classifier/` and is separate from detection. Its job is to crop detected litter objects from images and train an image classifier over those crops. The presence of `cut_bbox_litter.py` and `sort_openlittermap.py` makes this a second-stage pipeline: detection first, then classification on extracted regions.

9. `sort_openlittermap.py` shows an important data-flow boundary: it uses detector predictions to align unlabeled or weakly labeled OpenLitterMap images with original annotations, creating pseudo-labeled training data for classification. This is the repo’s semi-supervised / bootstrapping path.

10. The main inference path is `make_predictions.py`. It combines a trained detector checkpoint and a trained classifier checkpoint to produce annotated images or videos. For video, the output is frame-by-frame image export, which can then be reassembled with ffmpeg. This script represents the integration point between the detection and classification subsystems.

11. Experiment tracking is externalized to Neptune in the training scripts. The README indicates the project logs experiments to Neptune.ai, so training runs have an observability boundary outside the repo. This affects architecture because model scripts are expected to emit metrics and checkpoints into a remote experiment store.

12. `notebooks/` and the various subproject notebooks are analysis and prototyping surfaces, not runtime components. They cover exploratory data analysis, statistics across datasets, and finetuning demos. They help explain data provenance and model behavior but are not part of the production execution graph.

13. The repo is strongly Python/PyTorch-based, with COCO-style dataset handling as the common interoperability format. The main architectural pattern is: heterogeneous public datasets → preprocessing and label normalization → training in one of several model families → optional crop-based classification → inference visualization and evaluation.

Main entry points: [`annotations`](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/annotations) (Annotations), [`make_predictions.py`](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/make_predictions.py) (Prediction flow), [`efficientdet/effdet`](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/efficientdet/effdet) (EffDet core), [`classifier`](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/classifier) (Crop classifier)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_data["Data prep"]
  node_n_annotations[("Annotations<br/>dataset contract")]
  node_n_preprocess["Prep scripts<br/>ETL"]
  node_n_utils["Conversion utils<br/>helpers"]
end

subgraph group_g_det_eff["EfficientDet"]
  node_n_eff_train["Train loop<br/>training entry<br/>[train.py]"]
  node_n_eff_core["EffDet core<br/>framework core"]
  node_n_eff_data["Data pipeline<br/>input pipeline"]
  node_n_eff_eval["Eval stack<br/>evaluation"]
end

subgraph group_g_det_other["Other detectors"]
  node_n_detr_main["DETR main<br/>training entry<br/>[main.py]"]
  node_n_detr_models["DETR models<br/>model stack"]
  node_n_detr_data["DETR data<br/>data loaders"]
  node_n_maskrcnn["Mask R-CNN<br/>baseline detector"]
  node_n_fastrcnn["Fast R-CNN<br/>baseline detector"]
end

subgraph group_g_cls["Classifier"]
  node_n_classifier["Crop classifier<br/>stage-2 model"]
  node_n_sort["Pseudo-labeling<br/>data bootstrapping"]
  node_n_cut["Crop extraction<br/>preprocessing<br/>[cut_bbox_litter.py]"]
end

subgraph group_g_infer["Inference"]
  node_n_predict["Prediction flow<br/>integration entry"]
  node_n_eff_demo["EffDet demo<br/>visualization<br/>[demo.py]"]
  node_n_detr_demo["DETR demo<br/>visualization<br/>[demo.py]"]
end

subgraph group_g_analysis["Analysis"]
  node_n_notebooks["Notebooks<br/>analysis"]
end

node_n_preprocess -->|"writes"| node_n_annotations
node_n_utils -->|"supports"| node_n_preprocess
node_n_annotations -->|"feeds"| node_n_eff_data
node_n_annotations -->|"feeds"| node_n_detr_data
node_n_annotations -->|"feeds"| node_n_maskrcnn
node_n_annotations -->|"feeds"| node_n_fastrcnn
node_n_eff_data -->|"trains"| node_n_eff_core
node_n_eff_core -->|"orchestrates"| node_n_eff_train
node_n_eff_core -->|"validates"| node_n_eff_eval
node_n_detr_data -->|"trains"| node_n_detr_models
node_n_detr_models -->|"orchestrates"| node_n_detr_main
node_n_maskrcnn -->|"optional source"| node_n_predict
node_n_fastrcnn -->|"optional source"| node_n_predict
node_n_eff_core -->|"detector source"| node_n_predict
node_n_classifier -->|"classifier source"| node_n_predict
node_n_cut -->|"prepares crops"| node_n_classifier
node_n_sort -->|"bootstraps data"| node_n_classifier
node_n_predict -.->|"analyzed in"| node_n_notebooks
node_n_eff_train -.->|"explored in"| node_n_notebooks
node_n_detr_main -.->|"explored in"| node_n_notebooks

click node_n_annotations "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/annotations"
click node_n_preprocess "https://github.com/wimlds-trojmiasto/detect-waste/blob/main/annotations_preprocessing.py"
click node_n_utils "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/utils"
click node_n_eff_train "https://github.com/wimlds-trojmiasto/detect-waste/blob/main/efficientdet/train.py"
click node_n_eff_core "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/efficientdet/effdet"
click node_n_eff_data "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/efficientdet/effdet/data"
click node_n_eff_eval "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/efficientdet/effdet/evaluation"
click node_n_detr_main "https://github.com/wimlds-trojmiasto/detect-waste/blob/main/detr/main.py"
click node_n_detr_models "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/detr/models"
click node_n_detr_data "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/detr/datasets"
click node_n_maskrcnn "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/MaskRCNN"
click node_n_fastrcnn "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/FastRCNN"
click node_n_classifier "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/classifier"
click node_n_sort "https://github.com/wimlds-trojmiasto/detect-waste/blob/main/classifier/sort_openlittermap.py"
click node_n_cut "https://github.com/wimlds-trojmiasto/detect-waste/blob/main/classifier/cut_bbox_litter.py"
click node_n_predict "https://github.com/wimlds-trojmiasto/detect-waste/blob/main/make_predictions.py"
click node_n_eff_demo "https://github.com/wimlds-trojmiasto/detect-waste/blob/main/efficientdet/demo.py"
click node_n_detr_demo "https://github.com/wimlds-trojmiasto/detect-waste/blob/main/detr/demo.py"
click node_n_notebooks "https://github.com/wimlds-trojmiasto/detect-waste/tree/main/notebooks"

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_n_annotations,node_n_preprocess,node_n_utils toneBlue
class node_n_eff_train,node_n_eff_core,node_n_eff_data,node_n_eff_eval toneAmber
class node_n_detr_main,node_n_detr_models,node_n_detr_data,node_n_maskrcnn,node_n_fastrcnn toneMint
class node_n_classifier,node_n_sort,node_n_cut toneRose
class node_n_predict,node_n_eff_demo,node_n_detr_demo toneIndigo
class node_n_notebooks toneTeal
```

## Components

### Data prep

Shared annotation, conversion, and split pipeline for waste datasets.

- [Annotations](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/annotations): dataset contract · COCO-like JSON annotation sets for multiclass, binary, and mixed training. · `annotations`
- [Prep scripts](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/annotations_preprocessing.py): ETL · Root scripts that merge datasets, remap labels, and split train/test sets. · `annotations_preprocessing.py`
- [Conversion utils](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/utils): helpers · Shared helpers for dataset conversion, download, and COCO splitting. · `utils`

### EfficientDet

Most complete detector subsystem with its own framework layer.

- [Train loop](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/efficientdet/train.py): training entry · EfficientDet training orchestration and checkpointing. · `efficientdet/train.py`
- [EffDet core](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/efficientdet/effdet): framework core · Model, config, loss, anchors, and distributed helpers for detection experiments. · `efficientdet/effdet`
- [Data pipeline](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/efficientdet/effdet/data): input pipeline · Dataset factory, parsers, transforms, loaders, and augmentation for COCO/Open Images/VOC. · `efficientdet/effdet/data`
- [Eval stack](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/efficientdet/effdet/evaluation): evaluation · Detection metrics and evaluator utilities for validation and benchmarking. · `efficientdet/effdet/evaluation`

### Other detectors

DETR and Torchvision-style detection/segmentation baselines.

- [DETR main](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/detr/main.py): training entry · End-to-end DETR training and evaluation orchestration. · `detr/main.py`
- [DETR models](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/detr/models): model stack · Backbone, transformer, matcher, segmentation, and DETR model components. · `detr/models`
- [DETR data](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/detr/datasets): data loaders · COCO and panoptic dataset loaders, transforms, and evaluation helpers. · `detr/datasets`
- [Mask R-CNN](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/MaskRCNN): baseline detector · Torchvision-style training, transforms, and COCO evaluation for detection/segmentation. · `MaskRCNN`
- [Fast R-CNN](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/FastRCNN): baseline detector · Lighter Torchvision-style detection baseline with COCO utilities and engine. · `FastRCNN`

### Classifier

Second-stage crop classification and pseudo-labeling flow.

- [Crop classifier](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/classifier): stage-2 model · Trains image classifiers on cropped litter objects. · `classifier`
- [Pseudo-labeling](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/classifier/sort_openlittermap.py): data bootstrapping · Aligns OpenLitterMap images with detector predictions to create weakly labeled classification data. · `classifier/sort_openlittermap.py`
- [Crop extraction](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/classifier/cut_bbox_litter.py): preprocessing · Cuts detected litter bounding boxes into training crops. · `classifier/cut_bbox_litter.py`

### Inference

Cross-model prediction and visualization entry points.

- [Prediction flow](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/make_predictions.py): integration entry · Combines detector and classifier checkpoints to annotate images or exported video frames. · `make_predictions.py`
- [EffDet demo](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/efficientdet/demo.py): visualization · EfficientDet demo and validation utilities for inspecting predictions. · `efficientdet/demo.py`
- [DETR demo](https://github.com/wimlds-trojmiasto/detect-waste/blob/main/detr/demo.py): visualization · DETR demo entry point for running inference on samples. · `detr/demo.py`

### Analysis

Notebooks and exploratory surfaces for data and experiments.

- [Notebooks](https://github.com/wimlds-trojmiasto/detect-waste/tree/main/notebooks): analysis · EDA, statistics, and finetuning notebooks across datasets and model families. · `notebooks`

## Connections

- Prep scripts → Annotations: writes · Creates standardized annotation files from heterogeneous datasets.
- Conversion utils → Prep scripts: supports · Provides conversion, download, and split helpers.
- Annotations → Data pipeline: feeds · COCO-like files are the shared input contract for EfficientDet data loaders.
- Annotations → DETR data: feeds · COCO-style annotations drive DETR dataset loading.
- Annotations → Mask R-CNN: feeds · Torchvision baselines consume the same annotations.
- Annotations → Fast R-CNN: feeds · Torchvision baselines consume the same annotations.
- Data pipeline → EffDet core: trains · Supplies batches and augmented inputs to the detector core.
- EffDet core → Train loop: orchestrates · Training script drives the core model and optimization.
- EffDet core → Eval stack: validates · Evaluates detections and reports metrics.
- DETR data → DETR models: trains · Dataset loaders feed the transformer model stack.
- DETR models → DETR main: orchestrates · Main script wires model, matcher, and optimization.
- Mask R-CNN → Prediction flow: optional source · Can provide detector outputs for downstream annotation.
- Fast R-CNN → Prediction flow: optional source · Can provide detector outputs for downstream annotation.
- EffDet core → Prediction flow: detector source · EfficientDet checkpoints are used in the integrated prediction path.
- Crop classifier → Prediction flow: classifier source · Classifier checkpoints refine detector outputs in the integrated flow.
- Crop extraction → Crop classifier: prepares crops · Extracts object crops used for classifier training.
- Pseudo-labeling → Crop classifier: bootstraps data · Generates pseudo-labeled or aligned training examples.
- Prediction flow → Notebooks: analyzed in · Prediction results and dataset behavior are explored in notebooks.
- Train loop → Notebooks: explored in · Training experiments are often prototyped and inspected in notebooks.
- DETR main → Notebooks: explored in · Finetuning and analysis notebooks support DETR experiments.
