Setup
This project is about the application of AI technologies. The aim of the project is to analyze waste on the basis of images and thus be able to separate it by material type. To do this, a neural network is first trained with images from em internet. As soon as the training results are satisfactory, we will carry out tests under real conditions with a camera. The implementation is done in Python. Thus, it can be run on any system for which a python environment is available, i.e. on normal computers and additionally on a variety of single - board computers, such as the Raspberry Pi.
Three main components are necessary for real timematerial recognition: The AI framework "PyTorch", "OpenCV" for controlling the camera and video recording and a training data set. We use the “BetterRecycling_dataset” for the training.
PyTorch
PyTorch is an open source program library for the Python programming language focused on machine learning, based on the Torch library written in Lua, which has existed since 2002. PyTorch was developed by the Facebook artificial intelligence research team. In September 2022, Pytorch became part of the Linux Foundation through the newly founded Pytorch Foundation. Run
pip install torch torchvision
to install PyTorch and Torchvision. Torchvision is part of the PyTorch project and consists of popular datasets, model architectures, and common image transformations for computer vision.
OpenCV
OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being an Apache 2 licensed product, OpenCV makes it easy for businesses to utilize and modify the code.
pip install opencv-python
How can you test whether you have installed everything successfully? I have attached a test program for you. You simply have to create a new project in PyCharm and copy the test program into it and let it run. The program tries to import all the necessary libraries and displays a message if an error occurs.
Training Data
We use the dataset “BetterRecycling_dataset_resized.zip” for the training. You can download the data from here:
https://drive.google.com/drive/folders/1heg-IAqxHhS9wVXDKB9QRggRICL3KJ1s
The dataset contains approx. 2500 images from the categories “metal”, “paper”, “glass” and “plastic”. The picture shows a few examples from the category “paper”.
Install Check Program
try: import cv2 except: print("OpenCV was not found, please install") try: import torch except: print("OpenCV was not found, please install") try: import torchvision.transforms as transforms except: print("Torchvision was not found, please install") try: import numpy as np except: print("Numpy was not found, please install")