Home

Awesome

DOI

Detect waste

AI4Good project for detecting waste in environment. www.detectwaste.ml.

Our latest results were published in Waste Management journal in article titled Deep learning-based waste detection in natural and urban environments.

You can find more technical details in our technical report Waste detection in Pomerania: non-profit project for detecting waste in environment.

Did you know that we produce 300 million tons of plastic every year? And only the part of it is properly recycled.

The idea of detect waste project is to use Artificial Intelligence to detect plastic waste in the environment. Our solution is applicable for video and photography. Our goal is to use AI for Good.

Datasets

In Detect Waste in Pomerania project we used 9 publicity available datasets, and additional data collected using Google Images Download.

For more details, about the data we used, check our jupyter notebooks with data exploratory analysis.

Data download (WIP)

Data annotations: https://github.com/wimlds-trojmiasto/detect-waste/tree/main/annotations

For more datasets check: waste-datasets-review

Data preprocessing

Multiclass training

To train only on TACO dataset with detect-waste classes:

Single class training

To train on one or multiple datasets on a single class:

Script will automatically split all datasets to train and test set with MultilabelStratifiedShuffleSplit. Then it will convert datasets to one class - litter. Finally all datasets will be concatenated to form single train and test files annotations/binary_mixed_train.json and annotations/binary_mixed_test.

For more details check annotations directory.

Models

To read more about past waste detection works check litter-detection-review.

Example usage - models training

  1. Waste detection using EfficientDet

In our github repository you will find EfficientDet code already adjusted for our mixed dataset. To run training for single class just clone repository, move to efficientdet directory, install necessary dependencies, and launch train.py script with adjusted parameters, like: path to images, path to directory with annotations (you can use ours provided in annotations directory), model parameters and its specific name. It can be done as in the example below.

python3 train.py path_to_all_images \
--ann_name ../annotations/binary_mixed --model tf_efficientdet_d2 \
--batch-size 4 --decay-rate 0.95 --lr .001 --workers 4 --warmup-epochs 5 \
--model-ema --dataset multi --pretrained --num-classes 1 --color-jitter 0.1 \
--reprob 0.2 --epochs 20 --device cuda:0
  1. Waste classification using EfficientNet

In this step switch to classifier directory. At first just crop waste objects from images of waste (the same as in previous step).

python3 cut_bbox_litter.py --src_img path_to_whole_images \
                           --dst_img path_to_destination_directory_for_images \
                           --square --zoom 1

In case of using unlabelled OpenLitterMap dataset, make pseudo-predictions using previously trained EfficientDet and map them with orginal openlittermap annotations.

python3 sort_openlittermap.py \
                        --src_ann path_to_original_openlittermap_annotations \
                        --coco path_to_our_openlittermap_annotations \
                        --src_img path_to_whole_images \
                        --dst_img path_to_destination_directory_for_images

To run classifier training in command line just type:

python train_effnet.py --data_img path/to/images/train/ \
                       --save path/to/checkpoint.ckpt \
                       --model efficientnet-b2 \
                       --gpu 0 \
                       --pseudolabel_mode per-batch

Evaluation

We provided make_predictions.py script to draw bounding boxes on choosen image. For example script can be run on GPU (id=0) with arguments:

    python make_predictions.py --save directory/to/save/image.png \
                               --detector path/to/detector/checkpoint.pth \
                               --classifier path/to/clasifier/checkpoint.pth \
                               --img path/or/url/to/image --device cuda:0

or on video with --video argument:

    python make_predictions.py --save directory/to/save/frames \
                               --detector path/to/detector/checkpoint.pth \
                               --classifier path/to/clasifier/checkpoint.pth \
                               --img path/to/video.mp4 --device cuda:0 --video \
                               --classes label0 label1 label2

If you managed to process all the frames, just run the following command from the directory where you saved the results:

    ffmpeg -i img%08d.jpg movie.mp4

Tracking experiments

For experiment tracking we mostly used neptune.ai. To use Neptune follow the official Neptune tutorial on their website:

For more check LINK.

Our results

Detection/Segmentation task

modelbackboneDataset# classesbbox AP@0.5bbox AP@0.5:0.95mask AP@0.5mask AP@0.5:0.95
DETRResNet 50TACO bboxes146.5024.35xx
DETRResNet 50TACO bboxes712.036.69xx
DETRResNet 50*Multi150.6827.69**54.80**32.17
DETRResNet 101*Multi151.6329.6537.0219.33
Mask R-CNNResNet 50*Multi127.9516.4923.0512.94
Mask R-CNNResNetXt 101*Multi119.706.2024.7013.20
EfficientDet-D2EfficientNet-B2Taco bboxes161.05xxx
EfficientDet-D2EfficientNet-B2Taco bboxes718.78xxx
EfficientDet-D2EfficientNet-B2Drink-waste499.60xxx
EfficientDet-D2EfficientNet-B2MJU-Waste197.74xxx
EfficientDet-D2EfficientNet-B2TrashCan v1891.28xxx
EfficientDet-D2EfficientNet-B2Wade-AI133.03xxx
EfficientDet-D2EfficientNet-B2UAVVaste179.90xxx
EfficientDet-D2EfficientNet-B2Trash ICRA1979.47xxx
EfficientDet-D2EfficientNet-B2*Multi174.81xxx
EfficientDet-D3EfficientNet-B3*Multi174.53xxx

Pretrained weights of the best efficientdet model are available to download here: https://drive.google.com/drive/u/0/folders/1wNWoH8rdkG05sBw-OCXp3J73uJPxhcxH

Classification task

model# classesACCsamplerpseudolabeling
EfficientNet-B2873.02Weightedper batch
EfficientNet-B2874.61Randomper epoch
EfficientNet-B2872.84Weightedper epoch
EfficientNet-B4771.02Randomper epoch
EfficientNet-B4767.62Weightedper epoch
EfficientNet-B2772.66Randomper epoch
EfficientNet-B2768.31Weightedper epoch
EfficientNet-B2774.43RandomNone
ResNet-50860.60WeightedNone

Citation

@article{MAJCHROWSKA2022274,
      title = {Deep learning-based waste detection in natural and urban environments},
      journal = {Waste Management},
      volume = {138},
      pages = {274-284},
      year = {2022},
      issn = {0956-053X},
      doi = {https://doi.org/10.1016/j.wasman.2021.12.001},
      url = {https://www.sciencedirect.com/science/article/pii/S0956053X21006474},
      author = {Sylwia Majchrowska and Agnieszka Mikołajczyk and Maria Ferlin and Zuzanna Klawikowska
                and Marta A. Plantykow and Arkadiusz Kwasigroch and Karol Majek},
      keywords = {Object detection, Semi-supervised learning, Waste classification benchmarks,
                  Waste detection benchmarks, Waste localization, Waste recognition},
}

@misc{majchrowska2021waste,
      title={Waste detection in Pomerania: non-profit project for detecting waste in environment}, 
      author={Sylwia Majchrowska and Agnieszka Mikołajczyk and Maria Ferlin and Zuzanna Klawikowska
              and Marta A. Plantykow and Arkadiusz Kwasigroch and Karol Majek},
      year={2021},
      eprint={2105.06808},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

Project Organization (WIP)


├── LICENSE
├── README.md
|         <- The top-level README for developers using this project.
├── annotations        <- annotations in json
│   
├── classifier        <- implementation of CNN for litter classification
│
├── detr              <- implementation of DETR for litter detection
│
├── efficientdet      <- implementation of EfficientDet for litter detection
│
├── fastrcnn          <- implementation of FastRCNN for litter segmentation
│
├── maskrcnn          <- implementation of MaskRCNN for litter segmentation
│
├── notebooks          <- jupyter notebooks.
│   
├── utils              <- source code with useful functions
│
├── requirements.txt   <- The requirements file for reproducing the analysis environment, e.g.
│                         generated with `pip freeze > requirements.txt`
├── setup.py           <- makes project pip installable (pip install -e .) so src can be imported
├── src                <- Source code for use in this project.