Water Quality Monitoring Method Based on TLD 3 D Fish Tracking and XGBoost

Aiming at the problem of water quality monitoring, this paper presents a method of biological water quality monitoring based on TLD (Tracking-Learning-Detection) framework and XGBoost (eXtreme Gradient Boosting). Firstly, under the framework of TLD, an independent tracking system is designed; TLD captures 3D coordinate information of fish based on video and calculates the behavior of fish movement parameters which can reflect the change of water quality via processing the coordinate information of the fish body. The data of coordinate information will be more prominent via the data processing. The integration of all built XGBoost water quality monitoring model which is based on characteristic parameters; the model was used to analyze and evaluate fish behavior parameters under unknown water quality to achieve the purpose of water quality monitoring.


Introduction
In the era of Industrial 4.0, highly automated and intelligent manufacturing technology will gradually occupy the field of human society in the field of industrial development.In the field of water quality pollution, an efficient, convenient, and intelligent monitoring method becomes more urgent and necessary.In order to prevent and deal with the current situation of water quality pollution, the existing water quality monitoring technologies are physical and chemical analysis technology, automatic detection technology, and biological monitoring technology [1,2].The physical and chemical analysis technology and automatic detection technology for long-term real-time monitoring cost are relatively large; at the same time, these two technologies can not achieve the comprehensive evaluation of water pollution degree.The biological monitoring technique has been adopted.Biological monitoring technology is comprehensive, rich, and continuous; in recent years it plays an increasingly important role and has a broad application prospect in the environmental assessment.In the monitoring of biological water quality, fish, as an important indicator organism, with its movement characteristics, physiological characteristics, and other information directly reflect the changes in the water environment and the current situation of environmental pollution.Many scholars such as Kim et al. obtain the parameters of motion behavior of fish by computer vision technology [3][4][5][6][7][8]; only a few scholars put forward the method of water quality anomaly monitoring according to these characteristic parameters.Serra-Toro et al., Lai and Chiu, and Zhangzan et al., respectively, analyze the fish swimming behavior to get the relationship between exercise behavior parameters and water quality via recursive algorithm, fuzzy reasoning method, and data evaluation, so as to achieve the purpose of monitoring the abnormal water quality [9][10][11].
Although these methods can be used for monitoring, there are a lot of defects in the selection of feature parameters, the length of operation, the accuracy of monitoring, and the processing of individual differences.The choice of parameters has great influence on the model; the model cannot choose effective parameters to monitor; it can only be passively chosen by human choice; because the monitoring process of these methods was divided into a plurality of independent links, from data acquisition to the final monitoring, the whole operation was too long to show the results in time and effectively; data acquisition and processing process was too complex; each link increases the error component data, resulting in low accuracy of monitoring results.It only selects features unilaterally; the sample data can not reflect the difference, the sample can not be comprehensively taken into account, and the monitoring results also are one-sided.This paper presents the water quality monitoring methods under the framework of TLD and XGBoost; based on 3D fish tracking, we use TLD method to get the fish body coordinate in different water conditions and determine the characteristic parameters based on the calculation results of fish movement parameters.XGBoost is adopted to analyze and evaluate the feature parameter, establishing semantic mapping, and the movement of fish behavior characteristic parameters model, and finally it realized the abnormal water quality monitoring.

Extraction of Fish Characteristic Parameters
2.1.TLD Framework Introduction.TLD was a long-term single objective tracking algorithm proposed by Dr. Kalal et al. [12,13].The TLD framework mainly includes three parts: tracking part, learning part, and detection part.The relationship of the three parts and the tracking process is shown in Figure 1, for tracking part, mainly using the Forward-Backward Error method, using Lucas-Kanade optical flow tracking, the tracking results using Forward-Backward Error as feedback, the Euclidean distance for FB error compared with the original position, the distance which the longer will be abandon, this tracking method of using FB error to discard bad values was called Median Flow, which discards those larger than 50% of the European distance set; detection of TLD has three parts: the variance classifier module, set classifier module, and nearest neighbor classifier module; these three classifiers are cascaded.Each scan window of the current frame sequentially passes through the above three classifiers, both are considered to contain foreground objects; the learning part is the same as in other methods of target detection; detection module in TLD may also have errors, and the error was nothing more than the two cases being negative sample error and positive sample error.The learning module is used according to the results of the tracking module to evaluate the two kinds of errors of detection module, based on the results of the assessment to generate the target training samples and update the detection module; meanwhile, the tracking module "key points" were updated, in order to avoid similar mistakes.

Fish Tracking Framework.
We put forward a more specific framework for fish tracking based on the framework of TLD.Imitating TLD settings, the process of track is also divided into three parts, each part of the connection is as shown in Figure 2; we collected video by frame rate interception and input it to the TLD tracking module.
At any time, the tracked target could be represented by its state property.The state property can be a tracking box that represents the location and size of the target, or a marker that identifies whether the tracked target was visible.The two-track box in the space domain similarity was used to measure the overlap; the calculation method is that the two track frame intersections have joint segmentation.The shape of the object was represented by image patch P, and each fish body image was sampled from the tracking frame and normalized to the same size.In the tracking module, NCC is said to be the normalized correlation coefficient; BF (brute force selection mechanism) is said to be the forced choice mechanism, tracking each pixel in a first frame in the whole fish body image sequence; FB (Forward-Backward Error) was used to estimate trajectory.Finally, through the interaction of NCC and BF, we can get the stable tracking point by taking the two intersections.
The fish body images were not only input to the tracking module, but also used in the detection module.The test needs to use the positive and negative training sample information for training in advance, so that the detection module has certain detection ability.The detection module includes three filters, respectively, Variance filter, Fern variance filter (Random-Fern), and NN filter; through the three filters the errors in image are removed and the best target fish image is obtained.The tracking module and the detection module obtain the sample information to be fused and input to the learning module.Learning module used P-N learning.The main idea was that the detector error can be identified by two types of constraints.The function of P-expert was to find the new appearance (deformation) of the target and to increase the number of positive samples.The role of N-expert was to generate negative training samples.The premise of N-expert was that the tracked object may only appear in a position in the video frame, so if the position of the foreground target is determined, all around it must be a negative sample.The learning module was used to correct the tracking module and the detection module, and the Fern structure would be  updated, and the weight is adjusted to make the next result more reliable.
The image of the fish captured by the video was processed by the above steps, and finally the coordinate information of the fish in the three-dimensional space was obtained.Because the TLD tracking result was the two-dimensional plane coordinate information, the camera position needs to be arranged in order to collect three-dimensional coordinates.The camera was placed in the vertical direction and the horizontal direction of the fish tank, as shown in Figures 3(a) and 3(b); the two pictures show our camera positioning; in order to facilitate viewing, vertical plane and horizontal plane with a fish tank were drawn out; the blue side is said to be the vertical direction to the information acquisition of -; the green part is said to be the horizontal direction to the information acquisition of -.
The position of some fish in the space is as shown in Figure 4. Figures 4(a  in the three-dimensional space.The -axis of the two cameras overlap, and the -axis overlap information is removed to get the 3D information of the -- surface.

Parameter Calculationa.
The trajectory of fish can be expressed as a series of discrete discontinuous points; that is to say, the trajectory of  video sequence images of a fish can be described as Getting fish behavior characteristic parameters which can reflect the status of the water ecological environment by using trajectory: average moving distance, speed, acceleration,  direction discrete distance,  direction discrete distance, and distribution area, the definitions are as follows.
Average moving distance: ( 1 ,  1 ,  1 ) and ( 2 ,  2 ,  2 ) are used to represent the coordinates of the starting point and the end point of the fish target tracking trajectory in unit time.Speed  would be defined as Acceleration a would be defined as The distribution of fish in a single plane has great difference between normal and abnormal water quality; we use measured dispersion to describe the relationship between the single fish and fish.The dispersion formula would be defined as The characteristics of the dispersion of the fish body coordinates were concerned with the position of the center of gravity and the center of gravity of each individual, which integrates the characteristics of the whole and the individual.Similarly, in the - plane, the distribution area of fish also has great features.Shoal area calculation formula is Δ represents the maximum distance between  coordinates of all individuals in a fish at the same time, Δ is said to be the maximum distance between  coordinate;  is said to be the fish gathered together to form the minimum circumscribed circle radius.Finally, we use TLD and especially placed cameras to collect the coordinates; the characteristic parameters are obtained through calculation to establish a large enough data set.

Establishment of Water Quality Monitoring Model
XGBoost (eXtreme Gradient Boosting) [14,15] is designed by Dr. Chen Tianqi in Gradient Machine (GBDT) and the GBDT has been improved in boosting.On the basis of GBDT, XGBoost modified the objective function and loss function.

Objective Function, Obj.
First of all, the objective function of GBDT is as follows: Objective: where  is the loss function, Ω(  ) is a regular term, and   is tree complexity.After series of processing, we get a new objective function which is easier to use: XGBoost Taylor expansion for   (  ) makes it more similar to our previous goals.The process is as follows: By applying Taylor expansion to the three terms, we can make it clear that the final objective function depends on the first derivative and the second derivative of the error function of each data point.Definition: Bring ( 9) and (10) back to (8): Taking into account the square loss, can also continue to (10): In this way, we can remove the constant term and get the new objective function: In the equation,   =  ŷ(−1) (  , ŷ(−1) ), ℎ  =  2 ŷ(−1) (  , ŷ(−1) ).Then define the complexity of the tree:   () =  () ,  ∈   ,  :   → {1, 2, 3, . . ., } , (14) where  is a leaf vector,  is a tree structure, which defines the complexity of the number of nodes in a tree, and  2 is square of the output of each tree node.Under this new definition, we can rewrite the objective function as follows:  is defined as a set of samples on each leaf;   = { | (  ) = }.

Mathematical Problems in Engineering
To further simplify the formula, we define Based on the derivation of it being equal to 0, the following can be obtained: Bring the optimal solution  *  back to (18), and the final objective function is obtained: The above objective function, Obj, represents the maximum amount of reduction in the target when the structure of a tree is specified.You can call it a structural score.The smaller the Obj, the better the structure of the tree.

Add Scoring Function Gain
2  /(  + ) represents the left subtree fraction,  2  /(  + ) represents the right subtree fraction, (  +  ) 2 /(  +  +) represents an undivided score, and  represents the complexity cost of adding new leaf nodes.For each expansion, or to efficiently enumerate all possible segmentation schemes, suppose you want to enumerate all the conditions of  < , for a particular split a to calculate a's left and right derivative, as shown in Figure 5.
It would be found that for all 'a' , you can give all the gradients and GL and GR as long as a scan is done from left to right.And then the above formula can be used to calculate the score of each partition.

XGBoost Biological Water Quality Monitoring Model.
XGBoost joined the regularization; regularized boosting was a great help in reducing overfitting.Compared with GBDT the XGBoost can achieve parallel processing; the speed has been greatly improved; comparing SVM classification with XGBoost, XGBoost allows the user to define custom optimization objectives and evaluation criteria; it will add a new dimension in the model, so it is not subject to any restrictions on the data processing; in the process of data collection, because various artificial or experimental defects exist, it will inevitably lead to the phenomenon of data loss; while the XGBoost was built to deal with the missing value rules, the user needs to provide a different values sample and then take it as a parameter input; so this value is taken as missing values; XGBoost has different treatment methods in different nodes encountered with missing values and will learn when encountering the missing value in the future how to deal with it.The method provides a good solution for the deletion of the fish characteristic parameters, and the XGBoost allows the use of cross validation in each round of boosting iteration.Therefore, the optimal number of boosting iterations can be easily obtained; XGBoost can continue to train on the results of the previous round.This feature was a great advantage in the application of the classification of fish characteristic parameters and can realize the continuity of the model.Therefore, we try to use XGBoost to replace the previous classifier to establish water quality classification model.Prior to the establishment of the model, we need to preprocess the collected feature data to improve the training speed and accuracy of the model.Firstly, Smoothing was performed to create a feature sample set.XGBoost was an excellent decision tree classifier, which can use the objective function and scoring function as the model's performance.
XGBoost water quality classification model: In this paper, the steps of establishing water quality monitoring model were as follows: (1) We use the TLD technology to preprocess the fish motion parameters and set up a set of characteristic parameters.
(2) The feature parameter set was used as the input of XGBoost for training.
(3) Cross validation method was used to obtain the optimal number of boosting iterations.the table, the classification accuracy and time all have an excellent performance.Because the data were too much, here we choose the last set of data: original data 4 for detailed instructions.Using XGBoost the output of the classification model of original data 4 is obtained; the model of the code in the name of the characteristics of the parameters is shown in Table 2. score of each characteristic parameter in the model was shown in Figure 7.
The specific weight of each characteristic parameter for the overall sample set and their respective classification accuracy were shown in Table 3.It can be seen from the chart during the classification processing, that the model selects the most obvious characteristic parameters; for those weak characteristic parameters, model was used to adjust the weight of its classification, especially particularly bad data directly discarded.The model iterates over each feature parameter and can be used to segment the training set by calculating the eigenvalues of each feature parameter and then using tree structured Figure 8 to view the decisionmaking process (3rd boosted tree).In Figure 8, the feature and the feature values for each split were shown as well as the output leaf nodes.The split decisions with each node and the different colors for left and right splits (blue and red) were also shown.

Optimization.
We optimize the processing speed of the model and use the computer multicore processor (CPU) to improve the speed of the model.From a cost point of view, the price of a single core CPU was cheaper, but the speed of computing compared with multicore CPU comparison has great gap.From Figure 10 we can see that when the number of processors in the core model selection gradually increased, the processing speed of the model has great changes too, because the test data from the scale is still relatively small, not enough to fully display the processing speed of the model, but the advantages of multicore processor in speed optimization still can be seen.good performance in the classification problem; in order to demonstrate the performance of the XGBoost classifier, we made a comparison between SVM and XGBoost.Because the kernel function of SVM will affect the classification results, in order to allow the SVM classifier to achieve the best working condition, we adopted the previous laboratory work [16]; using RBF kernel parameters, the penalty factor  is given in Table 5. XGBoost uses the data set for original data 4; in order to play the best working condition, SVM needs to be further normalized on the basis of original data 4.The final SVM classification effect is shown in Figure 11.
As shown in Figure 12, compared with the accuracy of the classification and the time used in the classification, XGBoost has a huge advantage, especially the advantages of classification time; XGBoost is faster than SVM to speed up to two orders of magnitude.Details are shown in Table 5.

Conclusion
We obtain 3D coordinates by tracking fish in the water.A series of motion characteristic parameters which can be used to represent the water quality were calculated; in the processing of parameters, we found that some features can be used to distinguish between normal and abnormal water quality.According to this idea, water quality monitoring model was set up based on XGBoost classifiers.After a large number of  experiments, this model can realize the water quality classification quickly, accurately, and conveniently.Compared with the previous classifier, XGBoost was more outstanding.However, the whole process of water quality monitoring can not achieve closure, so we must rely on line training and human error processing; the whole system can not achieve real-time monitoring.We will further strengthen the model's ability to distinguish.In the analysis of the feature image, the processing of the intermediate state can be transformed into  the frequency domain by the way of signal processing, removing interference information, and improving the accuracy of early warning.And as a follow-up we can deteriorate the experimental environment and enhance the robustness of the system.
) and 4(c) show that the fish coordinate point projected onto a plane and get the scatterplot.In (b), (d) the blue oval line in the graph represents different points in different plane; elliptical is said to be in a different point in different plane.So you can see clearly the distribution of fish

Figure 4 :
Figure 4: Camera position and fish body space coordinates.

Figure 12 :
Figure 12: Classification speed and accuracy of XGBoost and SVM.

Table 4 :
-fold cross validation results.-FoldCrossValidation.This time the cross validation process is to repeat the experiment for  times, each time from the  sections to choose a different part as test data (ensure that the  part of the data was tested separately) and the rest of the  − 1 test data as training data for experiment.Finally, the obtained  experimental results are average.The verification results were shown in Table4.It includes both the mean (Accuracy%) and standard deviation (Error%) classification accuracy.As can be seen from the table, XGBoost as a classifier can still maintain a high accuracy after multiple cross validation, and the time used for each classification was very small.

Table 5 :
Comparison of XGBoost and SVM classification.