# An Energy Saving Road Sweeper Using Deep Vision for Garbage Detection
## 3 Description of The System
### Neural Network for Garbage Detection
#### 3.3.3 The Training  
An important part of the training was _data augmentation_. Data augmentation is a technique performed before or during the training on the whole input dataset, in order to artificially augment the quantity of training samples. Typically, non-destructive image transformations are performed on the original picture to generate new images, which, while different, belong to the same classes as the originals. This is fundamental in overcoming the scalability issues typical of full supervised (thus limited in nature) datasets. The original dataset has been automatically rototranslated, zoomed and flipped with random parameters to simulate more conformations that the images could have and create a much bigger training set. Another important part of the data augmentation, that is usually overlooked in similar applications, is contrast and brightness augmentation. We altered our  
Figure 10: Peculiar situations encountered during the dataset creation. **(a)** A hard condition for the network: it has to detect white pieces of paper near white road lines. The only way to do that is by learning their shapes (through example). **(b)**A poorly exposed image. Half of the picture is overexposed, while half underexposed. The network must be trained with such cases in order to work well during inference. Moreover, while it can learn to detect both overexposed and underexposed trash, the best solution to the problem would be equipping the system with a HDR camera. **(c)** A case of valuable a priori knowledge that can be exploited by the system. In fact, dirt usually gathers around nearby sidewalks. With this consideration in mind, the network can be trained to clean the sidewalks by default (by properly preparing the ground truth labels, such as in Figure 6), since finding a sidewalk is much easier than detecting each single cigarette stub. samples reducing or enhancing the whole pictures contrast (multiplicative factor) and brightness (average value), in order to better recreate real world lighting scenarios. The training was run using the Tensorflow library and the standard backpropagation--gradient descent algorithm. We tested Stochastic Gradient Descent, Adam [27] and Rmsprop. They gave similar results so we choose to use Adam with a learning rate of 0.0001. We ran our training for 1000 epochs. One final consideration was the loss function for the net. Since the last layer of our network used softmax, the natural choice for a loss would be Categorical Cross-Entropy:  
\[CCE=-\sum_{i}^{n}(y_{Ti}\cdot\log y_{Pi})\]  
where \(n\) is the number of output classes (two in our case), \(y_{T}\) is the ground truth class (label) for each pixel of the image (encoded as one-hot), and \(y_{P}\) is the predicted outcome from the softmax activation. However, we used a modified version of that loss, called Weighted Categorical Cross-Entropy:  
\[WCCE=-\sum_{i}^{n}(y_{Ti}\cdot\log y_{Pi}\cdot w_{i})\]  
This kind of loss is just the usual cross-entropy, but with a per-class weight (\(w\)) used during the evaluation. These weights are constants defined a priori before the training. The application of these weights provides two important benefits:  
1. In the case of an unbalanced dataset, we can adjust the balance with just a multiplier (e.g., if we have more samples of good road than dirty road, we can increase the \"dirt\" class weight while keeping the other weight fixed--e.g., \(w_{dirt}=10,w_{clean}=1\)). 2. We may want to train a more \"aggressive\" or \"gentle\" network. A customer may want to find 100% of trash even at the cost of producing some false positives; another customer could want to save energy and brushes and be tolerant of some gravel remaining uncleaned. With these weights, we can tune the same dataset towards a more, or less, aggressive network easily. The same could be done by changing the output threshold of the softmax output per-class, but in fact it did not work as well in our experiments: some tuning was possible but to a limited degree.