# A Low-Cost Automated Digital Microscopy Platform for Automatic Identification of Diatoms
## 2 Materials and Methods
### Deep Leaning Applied
#### 2.6.1 Automatic Detection
CNN for semantic segmentation: The chosen architecture was SegNet [67] because it was conceived of to be fast at inference (e.g., autonomous driving). This architecture tries to cope with the loss of spatial information derived from pixel-level classification caused by semantic segmentation. SegNet is constituted by: (A) one encoder network, (B) the corresponding decoder network, and (C) one final pixel-level classification layer. The encoder network consists of the first thirteen layers of the VGG16 network [68], pretrained with the COCO dataset [69]. These layers carry out operations such as: convolution, batch normalization, function activation by rectified linear units (ReLU), and max-pooling. In SegNet, the fully connected layer of VGG16 is replaced by a decoder network that recovers the feature maps' resolution prior to the max-pooling operation depending on the position at which each feature reaches the maximum value. A final softmax classifier is fed with the output of the previous decoder network. The predicted segmentation corresponds to the taxa with the maximum likelihood at each pixel. Unlike YOLO, fine-tuning is reduced to 100 epochs with the learning rate set to 0.05. 3. CNN for instance segmentation (Mask-R-CNN): This framework was created as a combination of object detection and semantic segmentation. Mask-R-CNN [44; 70] is a modified version of the Faster-R-CNN object detection framework with the addition of achieving the segmentation of detected ROIs. Firstly, a CNN generates a feature map from an input image. Then, a region proposal network (RPN) produces a candidate bounding box for each object. The RPN generates the bounding box coordinates and the likelihood of being an object. The main difference between Mask-R-CNN and Faster-R-CNN consists of the layer that obtains the individual ROI feature maps using the proposed bounding boxes by the RPN. In Mask-R-CNN, that layer aligns the feature maps with the bounding boxes using continuous bins rather than quantized ones and bilinear interpolation for better spatial correspondence. A fully connected layer predicts simultaneously the likelihood of a class--using a softmax function--and the object boundaries by bounding box regression. Moreover, Mask-R-CNN adds a parallel branch with mask prediction to achieve ROI segmentation. At this step, a fully convolutional network (FCN) performs a pixel-level classification for each ROI and class. For comparison purposes, two baseline algorithms were implemented: (A) Viola-Jones (VJ) [71]--a classical algorithm for detection based on a sliding window and a bank of simple filters--and the scale and curvature invariant ridge detector (SCIRD) [63; 72]. SCIRD is based on a bank of Gaussian non-linear filters convoluted with the image. Each filter in the bank is specialized to detect a particular shape, and its parameters are adjusted according to contrast, detritus density, and low noise levels. After training, each of the four methods to be compared produces a set of bounding boxes for the diatoms present in the images of the test dataset. The results of each method can be checked at the pixel level by checking if a predicted pixel belonging to a diatom was classified correctly or not. Three metrics were used to compare the results of the baseline algorithms (VJ and SCIRD) and those based on DNNs (YOLO and SegNet) for the detection of 10 diatom taxa in the test images.