\begin{table}[H]
  \centering
    \small
    \caption{Training parameters used to build K210 model }
  \begin{tabular}{p{4cm}p{4cm}}
    \toprule
    \cmidrule(r){1-2}
    Training Parameter     & Value \\
    \midrule
    Learning rate scheduler & Constant learning rate scheduler \\
    Optimizer & Adam optimiser \\
    Learning rate&	4.3e-05\\
Loss functions&	Sparse categorical cross entropy\\
Classifier activation function	&Softmax\\
Include top layers in base model&	False\\
    Batch size & 16 \\
Dropout rate in base model&	0.001\\
Dropout rate at output&	0.001\\
    \bottomrule
  \end{tabular}
  \label{tab:8}
\end{table}
] 
\section{Introduction}
Waste generation has increased dramatically in the 21st century due to the growth in the global population. According to the World Bank Group's report \cite{WorldBankGroup2018What2.0}, 2.01 billion tonnes of municipal solid waste are generated worldwide every year, with only about 19\% adequately recycled  \cite{WorldBankGroup2018What2.0}. Recycling not only helps to preserve raw material but, more importantly, reduces the landfills required, which is an undesirable way of waste disposal due to its high demand for space and the danger of introducing contaminants into the ground or even groundwater system. A major step of recycling is to separate the waste into specific categories according to its material. Failure to do so will significantly harm the effectiveness of recycling. Traditionally, workers at the recycling company sort the waste into corresponding categories by hand, which is an inefficient method and requires unnecessary labor. Therefore, people are now in dire need of a more advanced and automated waste separation system.\par
Image classification machine learning (ML) algorithms have been used to build automatic waste classification systems and assist waste management. This research aimed to improve the existing classification system and pursue the commercialization of an artificial intelligence (AI) street bin. Specifically, we focused on reducing the power consumption of the controller board to extend AI bin’s battery life, increasing its waste classification accuracy and reducing its price. \par
The only intelligent recycling bin on the market, Bin-e  \cite{Bin-e}, uses image classification algorithms to separate the trash into four categories: plastic, paper, metal and glass. It achieves a waste segmentation accuracy of 92\% \cite{Bin-e}. However, the price USD 5200 \cite{Bin-e} is expensive for a rubbish bin. Also, Bin-e’s operation requires a 230V power supply, so it cannot replace the traditional trash bins at the locations without plug sockets. Therefore, it can hardly increase the household and street recycling rate. As a result, this paper proposes low-cost battery-powered real-time recycling waste segmentation bin systems to fill this gap.\par
In this research, we trained a light MobileNet image classification model for Jetson Nano with TrashNet  \cite{GaryThungGarythung/trashnet:Classification}, an open-source waste dataset, and 1800 new training samples collected by us. The model demonstrated great performance with a high test accuracy of 95.98\% and a small parameter size of 3.0 M. Jetson Nano only consumed 4.7 W when it ran the model. We also found a cheaper and less energy-hungry device, K210 \cite{CanaanKendryteK210} to further reduce power consumption. The K210 board only consumed 0.89 W at inference time and the model on it achieved a high test accuracy of 96.64\%, which made it a more practical solution for trash bin applications. The code used in this study is available on Github \cite{XueyingLiMolvcanAN-SMART-RECYCLING-BIN-USING-WASTE-IMAGE-CLASSIFICATION-AT-THE-EDGE}.\par
This paper is organized as follows. In Section \ref{sec:2}, the related works performed in waste classification and AI trash bins are introduced. Section \ref{sec:3} introduces the system design and explains the background theories that support this study. The methodology of data collection and model training is introduced in section \ref{sec:4}. Section \ref{sec:5} analyses the test results and evaluates the system performance on Jetson Nano and K210. Finally, Section \ref{sec:6} concludes the achievements and provides suggestions for future research.

\section{Related works}\label{sec:2}
The United Kingdom (UK) government has planned to increase the household recycling rate in England to 50\% by 2020, but only 44\% of municipal waste was reused and recycled in 2020 \cite{2022Progress2020}. The inconvenience and lack of knowledge are two crucial factors that prevent people from recycling \cite{Knickmeyer2020SocialAreas}. Automatic waste segmentation bins were designed to overcome these problems by helping people classify and send the waste into the corresponding containers, making waste disposal more convenient. Table \ref{tab:1} outlines the approaches and the primary hardware components involved in related studies to construct the waste segmentation systems. 

The waste classification models in the previous study \cite{Abdulmahmood2021ImprovingAnalysis} have five output classes: "paper", "metal", "plastic", "cardboard" and "glass". They will be reproduced in the next section as the benchmark models of our study. Our model will be trained with two new classes, "empty" and "hand". "Empty" means there is nothing in the photo, while the "hand" group detects a human's hand to avoid trapping the user's hand by the door. When these two groups are detected, the bin waits and continues detecting. 
\subsection{The Benchmark models }\label{bench}
The waste classification models in \cite{Abdulmahmood2021ImprovingAnalysis} consist of an input layer, a pre-processing augmentation layer, an EfficientNet B0 base model layer, a global average pooling 2D layer and a dense layer. The first model has an input layer size of 512x384 pixels, while the second model input has 384x288 pixels. Table \ref{tab:2} shows the configuration of the augmentation layer and the model training hyperparameters for reproduction. \par

To begin with, the base model is initialized with pre-trained weights on ImageNet. The two models are trained separately by setting the corresponding input sizes. The learning rate was set to 4.3e-05 at the first 50 epochs and was reduced to 4e-06 at the eight epochs afterwards. Eventually, both models achieved the same test accuracy of 95.38\%. Figure \ref{fig:2} shows the confusion matrix of the test results and indicates that most mistakes are made in classifying between paper and cardboard.\par

After the model was reproduced, it was saved into TensorFlow SavedModel format and transferred to Jetson Nano. The 384x288 model was optimized successfully through TensorRT on Jetson Nano, but the 512x384 model caused an OOM error. The throughput of the accelerated model was 19 inferences per second (IPS) at the maximum power mode.\par
Nevertheless, the 384x288 model occupied 94.9\% of memory. The system would freeze up if we ran other applications simultaneously. To implement the classification model in an AI bin application, it is essential to replace the original base model with the lighter model, such as MobileNet V3, which has lower memory usage and power consumption. 
\subsection{MobileNet V3 model}
The EfficientNet architecture used in the benchmark model has demonstrated outstanding performance on the ImageNet dataset. In particular, EfficientNet B7 has the same top-1 accuracy, 84.3\%, as the GPipe while being 8.4x \cite{Howard2017MobileNets:Applications}. However, as EfficientNet B0 is the smallest model in the family, with a parameter size of 4.0 M without top fully connected layers, so MobileNet V3 Large, which only has 3.0M parameters and top-1 accuracy of 1.1\% less than EfficientNet on ImageNet, is chosen as the substitute. 
MobileNet is a series of CNN architectures developed by Google. It contains three architectures: MobileNet V1 \cite{Howard2017MobileNets:Applications}, V2 \cite{Sandler2018MobileNetV2:Bottlenecks} and V3 \cite{Howard2019SearchingMobileNetV3}. MobileNet V2 achieved higher accuracy on ImageNet with a smaller parameter size than MobileNet V1. The MobileNet V3 optimized the latency of MobileNet V2. \par

\subsection{Train the models with transfer learning}
The two datasets were used to train new classification models with TensorFlow version 2.9. Firstly, we replaced the EfficientNet B0 model layer in the benchmark model with MobileNet V3 architecture initialized with the pre-trained weights on ImageNet. The MobileNet model has a smaller parameter size and memory usage of the model. Then, the output size of the dense layer was changed to seven to add two new classes to the model. Finally, a resizing layer is inserted between the data augmentation layer and the base model layer to resize the input from 512x384 pixels to 224x224 pixels. By compressing the input after data augmentation, we obtained a clearer image for base model input than compressing the data before the data augmentation layer. \par
Figure \ref{fig:6} illustrates the structure of our model. The model was trained with the hyperparameters shown in Table \ref{tab:6}. The final model was converted to the TensorRT model with TensorFlow version 2.5, and its performance was measured on Jetson Nano. 

\subsection{Build and implement the K210 model}
After building the AI application on Jetson Nano, we used a cheaper and less power-hungry processor, K210, to run the waste classification model. K210 used its own model format called kmodel. Sipeed provides sample code to train classification model based on MobileNet V1 and convert it to kmodel model format with nncase \cite{SipeedSipeedMaix_train}. They applied data augmentation to the image data, as shown in Table \ref{tab:7}, and built a model with structure with TensorFlow, shown in Figure \ref{fig:7}. 

We kept the same data augmentation setup and used the same training hyperparameters applied in the previous training, as shown in Table \ref{tab:8}. All training data is resized into 224x224 pixels before training. The model used the same test/validation split 70/15 as our previous models on Jetson Nano. We first trained 110 epochs to find the stopping epochs and then trained the model with the stopping epochs. 
{"value": "4.3e-05", "type": "Hyper-parameter/Architecture", "model": ["MobileNet", "MobileNet V1"], "parameter/architecture name": "Learning rate", "dataset": ["TrashNet collected 1871 images", "The two datasets", "TrashNet", "new TrashNet"]} {"value": "16", "type": "Hyper-parameter/Architecture", "model": ["MobileNet", "MobileNet V1"], "parameter/architecture name": "Batch size", "dataset": ["TrashNet collected 1871 images", "The two datasets", "TrashNet", "new TrashNet"]} {"value": "0.001", "type": "Hyper-parameter/Architecture", "model": ["MobileNet", "MobileNet V1"], "parameter/architecture name": "Dropout rate in base model", "dataset": ["TrashNet collected 1871 images", "The two datasets", "TrashNet", "new TrashNet"]} {"value": "0.001", "type": "Hyper-parameter/Architecture", "model": ["MobileNet", "MobileNet V1"], "parameter/architecture name": "Dropout rate at output", "dataset": ["TrashNet collected 1871 images", "The two datasets", "TrashNet", "new TrashNet"]}