# A Low-Cost Automated Digital Microscopy Platform for Automatic Identification of Diatoms
## 2 Materials and Methods
### Deep Leaning Applied
#### 2.6.1 Automatic Detection  
According to European Union directives, the assessment of water quality requires counting about 400 diatom valves per sample [20], this being a time-consuming task. Therefore, the automatic detection of diatoms would alleviate this workload and constitutes a previous step to diatom counting. Until now, most of the methods for diatom detection relied on classical techniques, the most recent ones [53] being based on: active contours [17; 42; 60; 61], region segmentation [43; 50], and filtering [62; 63]. However, fewer studies applied DNNs to diatom segmentation. The reported average accuracy for the classical methods ranged from 88% to 95%, although with evidence of shortcomings such as: manual setting of the initial curve--in the case of active contours--and sensitivity to noise--in region segmentation methods. Moreover, all these techniques have been tested on images for the detection of a single diatom taxon. To overcome the shortcomings of previous classical works and to provide a feasible tool to help diatomists, several methods for image segmentation are compared in order to choose a valuable one to be integrated in our system. For the mentioned comparison, the dataset is constituted by 126 images acquired at 60\(\times\) magnification with a resolution of 2592 \(\times\) 1944 pixels, with 10 possible diatom taxa present in the images--usually with two or three different taxa present simultaneously in the same image, at most. The chosen taxa are representative of diatoms' diversity of morphological features (i.e., external shape and internal structures). In order to prepare the 126 images of the dataset, an expert diatomist labeled 1446 diatom valves in total, with 144 average ROIs per each of the 10 taxa, using the VGG Image Annotator (VIA) [64]. The isolated ROIs are included in the publicly available AQUALITAS dataset [18]. Three DNN flavors were compared, then against classical approaches unrelated to DNNs. For the training and assessment of the three methods, the dataset was divided into two datasets for training and testing, with 105 and 21 images, respectively. The test dataset was randomly selected from the available data and held out until the final comparison of the different approaches. The comparison was achieved using three metrics calculated for the test dataset after the testing detection of the 10 possible taxa present in the sample images. For each of the three selected DNNs, a validation dataset was chosen randomly to evaluate the model performance at the end of each epoch. The evolution of the loss function for the training and validation sets constitutes an adequate tool for tuning the algorithms and implementing an early stopping strategy when overfitting to the training data occurs--the loss function increasing for the validation set while remaining steady for the training set. Therefore, in our work, the following DNNs were chosen to solve the problem of diatom detection by image segmentation:  
1. Fully convolutional fast/faster region based convolutional network: A successful evolution of R-CNN based on fully convolutional networks (FCN) is YOLO (\"You Only Look Once\") [65; 66]. Rather than using a model for different regions, orientations, and scales to detect objects, YOLO accomplishes its task at once, with a single network for the whole image. Previous region based segmentation relied on additional algorithms that generate candidate regions. However, the YOLO framework is able to generate a multitude of candidates--most of them with little confidence--filtered by using a suitable threshold. As the training dataset is quite small (105 images), a pretrained YOLO implementation was used [65; 66]. A further training--also known as fine-tuning--was carried out for 10,000 epochs with the learning rate set to 0.001 and the optimizer based on stochastic gradient descent (SGD) with a mini-batch size of 4 images and a momentum coefficient of 0.9. 2.