Detection of Escherichia Coli Bacteria in Water Using Deep Learning: A Faster R-CNN Approach

: Considering its importance for vital activities, water and particularly drinking water should be clean and should not contain disease - causing bacteria. One of the pathogenic bacteria found in water is the bacterium Escherichia coli ( E. coli ). In the commonly used method for the detection of E. coli bacteria, the bacteria samples distilled from the water sample are seeded in endo agar medium and the change in the color of the medium as a result of the metabolic activities of the bacteria is examined with the naked eye. This color change can be seen with the human eye in approximately 22 ± 2 hours. In this study, a new bacteria detection scheme is proposed – using deep learning to detect E. coli bacteria both in shorter time and in practical way. The proposed technique is tested with experimentally collected data. Results show that the detection of bacteria can be done automatically within 6 - 10 hours with the proposed method.


INTRODUCTION
Water is what humans need most to survive.Water has an important role in metabolic activities, such as ensuring the balance of heat in the body, transporting the nutrients taken into the body to the target destinations, ensuring the lubrication of joints [1].Therefore, the water used must be clean and not contain any disease-causing microorganisms.The Turkish Standards Institute's TS 266 drinking and using water standard (2005) specifies the quality criteria that water must satisfy.As reported there, one of the most important criteria to be considered in water is microbiological parameters [2].Furthermore, "Water Quality and Health Strategy" study of World Health Organization (WHO) reports a projection of 589,854 waterborne infections in 58 countries around the world in the 2013-2020 period [3].
One of the disease-causing bacteria found in water is the bacterium Escherichia coli (E.coli) which was discovered by the Austrian doctor Thedor von Escherich in Enterobacteriaceae family.E. coli is actually one of the species of bacteria that live in the large intestines of living beings.However, it causes water pollution with the feces of living creatures and can survive in water for 4-12 weeks depending on the environmental conditions [4].
E. coli is divided into different pathologies according to the diseases caused.Each pathotype causes different disease symptoms.One of these diseases is hemolytic uremic disease (HUS) which can cause bloody diarrhea and death.Escherichia coli O157:H7 serotype is the strongest reason underlying HUS [5].In 2011, WHO reported 4,075 E. coli contaminations and 50 deaths related to HUS in 16 European countries and North America [6].
Considering the causes of diseases, the rapid and effective detection of E. coli bacteria is of great importance in terms of preventing epidemics and reducing deaths.A wide variety of methods has been developed to detect E. coli bacteria.Among these methods, the detection of bacteria is usually carried out using agar media [7][8][9][10][11][12], since agar is suitable for growth of microorganisms and contains the components that microorganisms need to perform metabolic activities.Using this growth culture, many different purposes can be achieved, such as the development, isolation, identification, counting and susceptibility testing of microorganisms, examination of clinical specimens, food, water and environmental controls.Also, there are studies in which bacteria are labelled with radiant chemicals or examined under a microscope after using various minerals such as manganese-added zinc [13][14][15][16][17].It is also possible to detect E. coli bacteria without using a microscope and magnification.For this, some changes in the medium which are characteristic for E. coli bacteria are examined with eye, or using digital image processing techniques such as hyperspectral imaging, thermal imaging or optical imaging [18][19][20][21].Endo agar solid media can also be used for this purpose.E. coli bacteria metabolize the lactose in the agar media by forming acid and aldehyde.The resulting aldehyde releases fuchsine in the fuchsine-sulfide compound, and thus the colony color becomes red.In E. coli and some other coliform group members, this reaction occurs very strongly, and the fuchsine crystals in the colony ensure that the colony color is metallic bright green (metallic sheen).As the optimal temperature for E. coli development is 37 °C, incubation is performed at 37 °C in an aerobic condition.The appearance of metallic sheen becomes visible with naked eye in about 22 ± 2 hours [22,23].Generally, this process is used in most laboratory studies and the change of the color is generally tracked manually with human eye.
In recent years, deep learning algorithms can also be considered as a useful tool for detection and classification of bacteria colonies automatically [24][25][26].Deep learning is an artificial intelligence algorithm that uses several layers and as layers progress, it extracts higher-level features from a given input.In deep learning, convolutional neural networks (CNNs) are a subfield of deep neural networks which is applied to analyze computer vision processes such as image classification.The capability of deep neural networks in image classification questions the possibility of success in object detection.The image classification process generally works on the estimation of an object in an image.Different from this, detection of the object and its boundaries are the processes of object identification.When the challenges of object detection are taken into consideration, CNNs have a dominant and improved success in that field compared to the traditional neural network models [27][28][29][30][31].Over the last few years, regionbased CNN (R-CNN) object detection methods have become the main approach.With improved performance and faster processing speed, more advanced CNN detection models have been proposed to deal with the problem of efficient object localization in object detection [32][33][34][35][36][37][38][39][40][41].Unlike the previous CNN methods, R-CNN uses a different region proposal algorithm called Selective Search which uses both segmentation of objects and Exhaustive Search to determine the region proposals in a faster and accurate way.The Selective Search algorithm proposes about 2000 region proposals for image to be passed into the CNN model which produces a 4096-dimensional feature vector as output from each region proposal.By placing this feature vector into the SVM model and bounding box regressor, classification and localization of object is provided.But the biggest problem with R-CNN is that 2000 region proposals have to be classified in each image.This increases duration of training the network.Since it requires a long time to detect objects in an image, real time applications cannot be implemented even on a graphical processing unit (GPU).To overcome this problem, Fast-R-CNN was proposed [40].Not only in R-CNN but also in Fast-R-CNN, computational burden was still high and most of the time taken by Selective Search algorithm.To reduce this train duration in both R-CNN's, the Faster R-CNN was developed by Ren et al [41].In this method, other than Selective Search algorithm, Region Proposal Network (RPN) is used for the network to learn region proposals.In this network, image gets into a backbone network to generate a convolution feature maps which will pass into the RPN that takes another feature map and generates anchors for classification and regression layers for object detection and localization.The general network for region-based model is given in Fig. 1. [33] In this study, it is aimed to determine the color change of agar medium containing E. coli bacteria contaminated water which can be used in the analysis of water samples, automatically and in a faster way compared to traditional methods.For this purpose, a deep learning approach is used as the color differences between image samples are the key points of determination.Detection of E. coli bacteria was performed using convolutional neural networks; a Faster R-CNN approach has been established in Tensorflow framework [42].Experimentally collected image dataset was used for performance evaluation and comparison.

MATERIALS AND METHODS 2.1 Experimental Setup and Generated Image Dataset
Images used for training and testing the proposed algorithms were obtained experimentally in this study.For this purpose, endo agar solid growth culture was prepared in petri dishes and E. coli contaminated water was sowed on the medium as explained in [43].Prepared medium is of light pink color at time of preparation.If E. coli contaminated water is sowed on the medium, dark red formation occurs first, and then, at higher density contamination site, this turns into bright green, or namely metallic sheen with the passing of time.Metallic sheen layer may also spread over the surface of the growth culture.As mentioned earlier, the time of seeing this metallic sheen with the naked eye is about 22 hours.If the water is noncontaminated, then the surface color of the medium does not change, only darkening of the pink color may be seen due to the ongoing dissolution of the colorant in the medium.Fig. 2 shows a sample image of an E. coli contaminated water sowed plant used in the study after 24 hours with a visible metallic sheen.For the acquisition of the images, the photographic imaging setup proposed in [43] was used.This setup has a rectangular prism shape, with dimensions 40 × 30 × 25 cm, closed and dark medium, in which the petri dished are placed.The medium is illuminated with white led lights prior to every photo shooting.A camera with a resolution of 1920×1080 (full HD) is placed on the top of the setup for automatic image capture.Electronic design details can be found also in [43].
Photo shooting and image acquisition process were carried out at room temperature in the experiments.A new E. coli contaminated water sawed growth culture medium was prepared and placed in the imaging setup prior to each experiment.Photographing continued for 24 hours, including one frame per ten minutes.Therefore, for one medium, 144 images were acquired in 24 hours.Ten different contaminated media were used as the medium with bacteria (experimental) group and therefore, automatic photo shooting was continued for ten days and 1440 images were acquired as experimental group.The same process was repeated in the next ten days with growth cultured petri dishes without sowing E. coli bacteria and another 1440 images were obtained as control group.

Proposed Faster R-CNN Approach
In the proposed method, a Faster R-CNN approach was developed and used in the Tensorflow framework.Pretrained Faster R-CNN Model with Inception ResNet v2 was selected as the base network.The dataset that the model was trained was MS-COCO dataset [44].COCO set is publicly available and published in the Tensorflow Object Detection API [45] model zoo repository.The algorithm was written in Python and run on a computer with a 2.4 GHz Intel I7 CPU and an NVIDIA GeForce GT950m GPU with 4 GB memory.Two classes were defined: a medium with bacteria and a medium without bacteria.As explained above in section 2.1, ten days of data were taken for each medium.Eight days of data from each group which corresponds to total of 2304 captured images were selected as training data.The remaining data were used to test and validate the algorithm.In the labelling phase of training, two labels were used to define mediums: bacterial (E. coli contaminated medium) and non-bacterial.All labelling operations were done by using open-source software "LabelImg" [46].Only the images in which the metallic sheen became visible in the medium were defined as bacterial and the other images were labeled as non-bacterial even if it was known that the medium was contaminated with E. coli bacteria.Sample images were given in Fig. 3.
For example, image in Fig. 3a was labeled as nonbacterial medium as the metallic sheen does not appear, although it was contaminated with E. coli bacteria.On the other hand, image in Fig. 3b was labeled as bacterial medium due to the appearance of green metallic sheen which can be seen in the white box in the image.By following this strategy, it was aimed that the algorithm only focuses on metallic sheen appearance on medium which is the main characteristic for detection of E. coli bacteria, instead of dark red color changes which can be related to contamination of oxygen or another bacteria to the medium.Considering this features and requirements, a Faster R-CNN model was developed as given in Fig. 4. Here, the RPN ranks anchor boxes and proposes the ones most likely containing objects -growth culture samples.Output of a RPN is a variety of boxes that will be examined by a classifier and regressor to eventually check the occurrence of objects for localization and detection.It searches the image from the first frame to the last as tensors and scores the similarity.Fig. 5 shows 12 anchors which were used in this study for object detection.In Fig. 5, the four colors (blue, red, green and black) represent four scales: 128×128, 256×256, 512×512 and 1024×1024 pixels.Also, three aspect ratios 1:2, 1:1 and 2:1, which correspond to the width/height ratio of an anchor box were used as shown in Fig. 5.After RPN, proposed regions were obtained with different sized CNN feature maps.
Region of Interest (ROI) Pooling was used to simplify the problem by reducing the CNN feature maps into the same size.Output features from ROI Pooling layer were converted to a one dimensional array and fed into fully connected (fc) layers for classifying and regression operations in which the CNN decides whether the medium is with bacteria or not.The classification branch of Softmax layer in the model gives probabilities for every ROI and the prediction of labels were done in this phase.Here, detection scores were obtained and given to the last layer for decision of medium.In the Bounding Box (BB) regression branch generates four anchor box regression offsets k i t where i = x, y, w, and h; in which (x, y) stands for the top-left corner and w and h denote the height and width of the anchor box.The true bounding box regression targets for a class u are indicated by v i where i = x, y, w, and h.Algorithm decides whether there is a growth culture or not, which depends on both localization and classification losses.The localization loss chosen as a smooth L1 loss is given in Eq. ( 1).The joint multi-task loss for each ROI is given by the combination of the classification and localization losses as shown in Eq. ( 2) [41] { } loc 1 , , , ( , ) ( ) where Learning rate was selected at 0.001 and after 25K iterations, another 25K iterations were run with the learning rate of 0.0001.With these adjusted parameters, the algorithm took about 1.2 seconds to train and process images for each iteration.

RESULTS AND DISCUSSION
As explained in section 2.1, two set of photographic images, as control (without E. coli) and experimental (with E. coli), were taken using the imaging setup.All these images were then pre-processed, leaving only the petri dish in the image.Details of this pre-processing are given in [43].Fig. 6 shows the pre-processed sample images in every 8 hours of a 24 hours experiment with non-E.coli contaminated medium.From the figure, it is seen that there is no metallic sheen, but just a little darkening on the surface of the non-bacterial medium in 24 hours.Fig. 7 shows the sample images in every 8 hours of a 24 hours experiment with E. coli sowed on growth culture.In this case, the presence of bacteria causes metallic sheens on the medium and these sheens becomes visible with naked eye after 22 hours, as seen from Fig. 7-d.It is important to note here that, before 22±2 hours, dark green coloration starts but metallic sheens are not visible with naked eye on the surface of the growth cultures.
After training the proposed algorithm with 80% of these two sets of images and testing it with the remaining 20% of both image set, some of the obtained results from both non-bacterial and E. coli contaminated mediums at different hours from different experiments are given in Fig. 8.As seen from the results in Fig. 8, the proposed model can detect the bacteria at about 8th hour of the experiment, but the probability of the decision is not high enough for an absolute judgement.In order to increase the decision accuracy of the proposed model, a variation in existing image data set was proposed such that, the green layers of the existing RGB images were extracted first and then these layers were saved in grayscale.Green layers of the images were selected since metallic sheens start with dark green coloration at the beginning.After this process, same number of images in two groups constituted the new grayscale image data set for training and testing of the proposed model.Fig. 9 shows the results of the model for this grayscale image data set.Here, Fig. 9-a shows the result for an initial image from an E. coli contaminated growth culture medium, while Fig. 9-b, 9-c and 9-d show the results of the model for the same medium at 3, 6 and 9 hours, respectively.As seen from the results, decision accuracy was increased with this addition to the algorithm.Furthermore, training of the model with grayscale images was faster compared to training with colored images.
As explained in Section 2.1, a total of 2880 images were captured during ten different measurement durations and 2304 of these images were selected as training and 576 of dataset was used for testing and validation of the algorithm.Half of test images were selected from the nonbacterial medium and the other half were selected from the bacterial medium.Twelve images were selected for every hour over 24 hours for each group.Thus, 576 images of testing dataset were created.Accuracy after 3 to 6 hours, 6 to 9 hours, and after 9 hours was investigated to reveal the success of the algorithm.To see all the values in a tabular form, a confusion matrix was prepared as given in Tab. 1.
In the Tab. 1, detection rate or accuracy was calculated using Eq. ( 3):

TP TN Accuracy = TP TN FP FN
Here, TP is the true positive; correctly predicted bacterial medium events, TN is the true negative; correctly predicted non-bacterial medium events, FP is the false positive; incorrectly predicted bacterial medium events, and FN is the false negative; incorrectly predicted non-bacterial medium events.As seen from the results in Tab. 1, after three hours, the algorithm starts to respond and labels the bacterial medium with the accuracy of ~59%, and after 6 hours, the image detection accuracy increases and labels the medium as ~83% bacterial but FP rate is still considerable.After 9 hours, it becomes totally stable and detects the E. coli bacteria with the accuracy of ~99%.
Cumulative test results of the algorithm for both colored and grayscale data sets were given in Tab.2: As seen in colored image data set, the algorithm detects E. coli bacteria after 8 hours with a 99% accuracy.On the other hand, the algorithm can detect E. coli bacteria from gray-scale image data after 9 hours with an accuracy of 99%.But in early phases of bacterial growth, accuracy of detection was higher in gray-scale images compared to the colored data set.In addition to that, the algorithm works faster and computational cost is reduced in grayscale data set.This tradeoff can be evaluated according to the needs of the user.

CONCLUSION
E. coli is a lethal for humans.It can mix into the clean water reservoirs such as dam lakes or big water distribution tanks of municipalities and the contaminated water may reach to the end user's taps in a short time.Therefore, E. coli bacteria must be detected quickly when they are contaminated to any water source.In order to detect E. coli, the most used and the cheapest technique takes approximately 22 ± 2 hours and the results are obtained with naked eye.However, this is too long and during this test, pathogenic bacterial contaminated water can be consumed.In this study, analysis tools, which can automatically perform the bacteria detection process and can give an immediate alarm when the detection provided were proposed.Materials and the method have been tested in different ways using bacterial growth media.When the findings were examined, it was seen that the bacteria detection process can be performed in 8±2 hours.In addition, the proposed method was tested with the growth cultures at room temperature, considering the possibility of not finding the appropriate equipment, such as the incubator, in place of water reservoirs.It is predicted that, if the tests were carried out at 37° C and in an incubator environment with more favorable humidity conditions for bacterial growth, the detection time of bacteria would be further shortened.In future studies, it is planned to establish a mechanism and method that will enable the quick, easy and automatic investigation of bacteriological water examination in real-time applications.The results of this study are promising for these future studies.

Figure 2
Figure 2 Captured image of the growth culture with bacterial sowing

Figure 3
Sample images: a) Labelled as a non-bacterial medium, b) Labelled as a bacterial medium

Figure 4
Figure 4 Proposed Faster R-CNN framework

Figure 5
Figure 5 Anchor boxes at (1024, 1024) cls is the classification loss and L loc is the localization loss, λ is the weight coefficient to balance these two losses.Pseudocode of the framework is given below: Pseudocode of the proposed model for E. coli detection 1 Start Tensorflow (tf) session 2 Input tensor: image 3 Output tensors: detection boxes, scores, masks and classes 4 Initial target bounding box b = [x,y,w,h] class on tensors 17 visualize detection boxes, classes, and scores on image 18 end

Figure 6 Figure 7
Pre-processed sample images of a non-contaminated medium: a) Initial image, b) After 8 hours, c) After 16 hours, d) After 24 hours Pre-processed sample images of a contaminated medium: a) Initial image, b) After 8 hours, c) After 16 hours, d) After 24 hours

Figure 8
Result images of the algorithm: a) image from a bacterial medium: initial image, b) image from a non-bacterial medium: After 4 hours, c) image from a bacterial medium: After 8 hours, d) image from a bacterial medium: After 12 hours

Figure 9
Result images of the algorithm with grayscale data set: a) image from a bacterial medium: initial image, b) image from a bacterial medium: After 3 hours, c) image from a bacterial medium: After 6 hours, d) image from a bacterial medium: After 9 hours

Table 1
Confusion Matrix after 3, 6 and 9 hours for grayscale images After 3 hours to 6 hours n = 72 (no. of images)