Water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking
The two-way LSTM model predicts ammonia nitrogen concentration and the improved YOLOv5+ByteTrack algorithm analyzes fish movement trajectories, solving the problems of water quality monitoring and fish behavior abnormality identification, achieving accurate monitoring and early warning of water quality changes and fish health, and improving Breeding benefits.
Patent Information
- Application Number
- CN202411025829.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-07-30
AI Technical Summary
Existing water quality monitoring technology is difficult to accurately predict changes in water quality parameters and abnormal fish behavior, especially in complex underwater environments, which affects fish health and breeding efficiency.
A two-way LSTM model is used to predict ammonia nitrogen concentration, and combined with the improved YOLOv5 detection model and ByteTrack tracking algorithm, the fish movement trajectory is analyzed through video, the water quality is comprehensively judged, and the accuracy of monitoring and tracking is improved.
It achieves early warning of changes in water quality and abnormal fish behavior, improves the economic benefits of aquaculture and the accuracy of fish health monitoring, and reduces the risk of abnormal fish.
Smart Images

Figure CN118566213B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of water quality monitoring and underwater intelligent fish farming video multi-target detection and tracking, and in particular relates to a water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking. Background Art
[0002] In the rapid development of fish farming, unpredictable changes in water quality parameters will change the normal behavior of fish and cause varying degrees of harm to fish, bringing immeasurable economic losses to aquaculture. Current water quality monitoring mainly focuses on real-time monitoring of water quality indicators, but it cannot guarantee timely detection of fish abnormalities and take safety measures in advance. In order to more accurately predict water quality parameters, various time series prediction models have been proposed to simulate the changes in water quality parameters over time periods. Recursive Neural Network (RNN) and Long Short-Term Memory (LSTM) are currently popular time series prediction models based on deep learning. However, RNN has the problem of gradient disappearance, while the memory units contained in LSTM enable it to retain information for a longer time, solving the shortcomings of RNN in preserving long-term temporal information. However, due to the influence of different water quality parameters, abnormal values that appear in a short time may return to normal. Therefore, it is not accurate to rely solely on monitoring water quality changes. In addition, water quality changes in aquaculture systems will have different effects on fish, thereby changing their behavior patterns and trajectory characteristics. Therefore, in addition to monitoring water quality parameters, extracting motion information from underwater videos can also provide more valuable insights for accurate behavioral analysis of fish.
[0003] With the vigorous development of computer vision technology in recent years, the target detection and tracking algorithms have been widely used for trajectory analysis of fish in the field of aquaculture. Underwater target detection algorithm is the basis and core technology for underwater biological detection. Convolutional neural network is a typical representation tool in the field of deep learning. Common target detectors include Faster R-CNN and YOLO. Although some effective results have been achieved in existing work, there are still the following difficulties when applied to complex underwater fish targets. First, the differential attenuation of various light wavelengths in water will cause the target in underwater images and videos to be blurred, which seriously affects the extraction of target feature information; second, underwater images contain objects of different scales, and small targets occupy the vast majority, but they have less feature information, and the high similarity of features between different individuals of the same species may further hinder the detection ability of the model; in addition, the rapidity of fish swimming and the diversity of postures will cause fish to deform, thereby increasing the difficulty of detection; finally, the common distribution pattern of fish clustering will lead to overlapping and occlusion problems.
[0004] Real-time tracking algorithms for underwater targets can retrieve the motion trajectory of fish and further perform behavioral analysis to estimate potential influencing factors. Continuous multi-frame tracking can deal with target adhesion and occlusion problems to a certain extent, which is an effective way to achieve real-time detection of multiple fish targets. The most representative of the Track Before Detect (TBD) paradigm is the SORT algorithm, but it usually ignores ID information, cannot handle long-term occlusion and fast-moving target problems, and has poor tracking reliability. Therefore, the DeepSORT algorithm was proposed to extract appearance features through the Re-ID model, effectively reducing the number of ID switches during tracking, but making model training relatively complex. To solve the above problems, the Joint Detection and Embedding (JDE) paradigm was proposed, such as CenterTrack, FairMOT, etc. By unifying the detector and embedding model into a network architecture, the computational cost of the model is significantly reduced, but this model tends to extract high-dimensional and distinguishable appearance features, which will severely limit the upper bound of tracking accuracy when the fish school is dense or the target appearance is indistinguishable. In real-world scenarios, due to problems such as uneven underwater illumination, mutual occlusion of targets, and deformation of fish bodies caused by nonlinear motion, a large number of low-scoring detection frames will be generated. If all these low-scoring frames are removed, it is easy to cause the occluded targets to be lost and the tracks to be fragmented, affecting the tracking effect of fish. Summary of the invention
[0005] The purpose of the present invention is to propose a water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking. By adopting a bidirectional LSTM model to predict the ammonia nitrogen concentration, and combining the motion trajectory analysis method of the YOLOv5 network model + ByteTrack tracking algorithm based on the detection and tracking paradigm, when the ammonia nitrogen concentration in the water is detected to be abnormal, the current water quality is comprehensively judged by combining whether the underwater target has abnormal behavior, which is conducive to improving the accuracy of water quality monitoring.
[0006] In order to achieve the above object, the present invention adopts the following technical scheme:
[0007] A water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking comprises the following steps:
[0008] Step 1. Use a colorimetric sensor to collect ammonia nitrogen concentration values at different time points underwater, collect them once every preset interval t, and collect data within a preset time period T, totaling multiple ammonia nitrogen concentration sample values;
[0009] At the same time, video data under different concentrations of ammonia nitrogen are collected to construct a fish target dataset. Image data is obtained by extracting frames from the video as a fish target detection dataset, and the image dataset is divided into a training set and a validation set according to a certain ratio.
[0010] The continuous video frame images are used as fish target tracking datasets, and the target IDs are annotated using Darklabel, and the corresponding gt.txt text is generated to facilitate the subsequent tracking evaluation index tasks;
[0011] Step 2. Use the fish target detection dataset in step 1 to train the improved YOLOv5 detection model to generate a trained target detection network, which outputs the fish detection box and the corresponding confidence level.
[0012] Step 3. Use the fish target tracking dataset in step 1 to train the motion trajectory analysis model, output the continuous tracking video and the fish motion behavior trajectory map, and generate the corresponding TXT text and gt.txt text for tracking performance evaluation;
[0013] The motion trajectory analysis model is composed of an improved YOLOv5 detection model combined with an improved ByteTrack tracking algorithm;
[0014] Step 4. Input the concentration sample values collected in step 1 into the bidirectional LSTM prediction model according to the ammonia nitrogen concentration values at the current time point and the previous five time points, predict the ammonia nitrogen concentration value at the next time point, calculate the error with the actual concentration value at the next time point, perform back propagation, and generate an ammonia nitrogen concentration prediction model after multiple iterative training;
[0015] Step 5. Preset the ammonia nitrogen concentration threshold according to the behavior state of the fish under different ammonia nitrogen concentrations; input the ammonia nitrogen concentration values at the current time point and the previous five time points into the bidirectional LSTM prediction model to predict the ammonia nitrogen concentration value at the next time point; when the predicted ammonia nitrogen concentration value at the next time point exceeds the ammonia nitrogen concentration threshold, use a camera to shoot a video of the fish swimming;
[0016] Step 6. Process the captured fish swimming behavior video into a data set in the same format as the target tracking data set, input it into the motion trajectory analysis model, and obtain the motion behavior trajectory map of each fish, which is convenient for detecting and tracking abnormal fish behaviors;
[0017] Step 7. Based on whether the movement behavior trajectory of individual fish in the movement behavior trajectory diagram of step 6 is different from that of normal fish, it is determined whether the current ammonia nitrogen concentration value has caused adverse effects on fish, thereby determining the current water quality.
[0018] The present invention has the following advantages:
[0019] As described above, the present invention relates to a water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking. The method combines the predicted ammonia nitrogen concentration parameters in the water quality and the target motion trajectory to determine when the ammonia nitrogen concentration will have an adverse effect on fish, and then accurately judge the current water quality, so as to facilitate taking preventive measures in advance to reduce the abnormal risk of fish. The present invention is based on the improvement of the network model of YOLOv5, and uses a lightweight cross-layer fusion model and an attention mechanism to effectively reduce the amount of model parameters while ensuring the detection accuracy, thereby increasing the possibility of deploying the algorithm on mobile terminals such as embedded systems. In addition, the present invention also modifies the network module for extracting features from YOLOv5, and effectively fuses feature information of different scales by introducing a SENetV2 module with a multi-branch structure in the backbone C3 module, which can more accurately locate fish targets and effectively reduce missed detections and false detections caused by crowded occlusion in complex aquaculture environments. In addition, by modifying the state vector and adaptive noise covariance matrix of the Kalman filter in the ByteTrack tracking algorithm, the problem of mismatch between the tracking frame and the target caused by the uniform speed estimation model of the Kalman filter was improved, and the dynamic estimation accuracy of the filter was improved; the error accumulation of state estimation noise caused by long-term occlusion or nonlinear motion targets was reduced, and the tracking accuracy of fish targets in complex aquaculture environments was further improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 Flow chart of a water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking in an embodiment of the present invention;
[0021] Figure 2 It is a network structure diagram of the improved YOLOv5 detection model in an embodiment of the present invention;
[0022] Figure 3 The network structure diagram of the improved C3_SENetV2 module in the embodiment of the present invention;
[0023] Figure 4 This is a network structure diagram of the bottleneck layer Bottleneck in an embodiment of the present invention;
[0024] Figure 5 This is a network structure diagram of SENetV2 in an embodiment of the present invention;
[0025] Figure 6 Schematic diagram of the flow of a fish multi-target detection and tracking algorithm based on deep learning in an embodiment of the present invention;
[0026] Figure 7 This is a flow chart of the improved ByteTrack target tracking algorithm in an embodiment of the present invention. DETAILED DESCRIPTION
[0027] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments:
[0028] Example 1
[0029] In a real complex aquaculture environment, excessive ammonia nitrogen concentration in water will cause acute or chronic poisoning reactions to fish, affect the growth and normal behavior of fish, and even cause a large number of deaths. People cannot observe the changes in water quality parameters in real time and discover the abnormal behavior of fish in time. The behavior trajectory analysis of individual fish will be hindered by challenges such as underwater target blur, cross occlusion, nonlinear motion and large scale changes, which seriously affect the technical problems of individual fish detection and accurate ID tracking. The present invention proposes a water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking. The ammonia nitrogen concentration prediction model in the method adopts a bidirectional LSTM model, and the ammonia nitrogen concentration value at the past time point is obtained by a colorimetric sensor to predict the concentration value at the next time point. When the predicted value of ammonia nitrogen concentration is abnormal, a camera is used to shoot a video of fish swimming behavior at the current concentration, and then a motion trajectory analysis algorithm is used to determine whether the ammonia nitrogen concentration at the next time point will cause fish abnormalities. The fish motion trajectory analysis algorithm adopts a system framework of the detection and tracking paradigm. By improving the YOLOv5 detection model, it is helpful to solve the problems of false detection and missed detection caused by dense distribution and occlusion of fish in complex water environments, achieve lightweight while improving the detection accuracy of the model, and increase the possibility of deploying the algorithm on mobile terminals such as embedded systems; using a framework structure based on detection and tracking, the tracking effect depends on the detection accuracy, and the ByteTrack tracking algorithm is improved, which can ensure real-time detection and solve the serious problems of target loss and ID switching during tracking due to nonlinear motion and cross occlusion.
[0030] like Figure 1 As shown, the water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking includes the following steps:
[0031] Step 1. Use a colorimetric sensor to collect ammonia nitrogen concentration values at different time points in the circulating aquaculture area, collect them once every preset interval t, and collect data within a preset time period T, totaling multiple ammonia nitrogen concentration sample values.
[0032] At the same time, video data under different ammonia nitrogen concentration environments are collected to construct a fish target dataset. Image data is obtained by extracting frames from the video as a fish target detection dataset, and the image dataset is divided into a training set and a validation set according to a certain ratio.
[0033] The continuous video frame images are used as the fish target tracking dataset, the target ID is annotated using Darklabel, and the corresponding gt.txt text is generated to facilitate the subsequent tracking evaluation index tasks.
[0034] The process of preparing the dataset is illustrated by taking the spotted rock bream (OP) reared in a recirculating aquaculture system as an example.
[0035] Step 1.1. The fish used in this example are spotted rock bream (OP) raised in a recirculating aquaculture system. A Hikvision HD camera is set above the aquaculture system to record the behavioral changes of OP.
[0036] During the experiment, the fish were fed artificially normally with the feeding amount kept constant, and were fed once at 07:30 and 16:30 daily.
[0037] Step 1.2. Starting from the first feeding, a colorimetric sensor was used to collect the ammonia nitrogen concentration in the aquaculture environment. The samples were extracted every hour for one week, and a total of 112 sets of samples were collected. The data sets were divided into training sets and validation sets at a ratio of 9:1. At the same time, a camera was used to record 30 minutes of OP swimming behavior videos in the aquaculture system every hour. The video frame rate was 30 frames per second and the resolution was 1920×1080.
[0038] Step 1.3. Cut each video and keep only the last 5 minutes for processing and analysis. Evenly divide it into 5 frames per second, a total of 10,500 data images are obtained as the target detection dataset, and the dataset is divided into a training set and a validation set in a ratio of 8:2. Then, the continuous frame images of the video are generated at a frame rate of 30 frames per second as the target tracking dataset.
[0039] Step 1.4. Use Labelimg to manually annotate the target detection dataset, including target category, annotation box position coordinates, and generate label information for each image. Use Darklabel to annotate the ID of individual fish in the target tracking dataset, including GroundTruth annotation box and confidence information, and generate a gt.txt document for tracking evaluation.
[0040] Step 1.5. Classify and integrate all dataset images and label information into the VOC format required for training the improved YOLOv5 target detection network.
[0041] Step 2. Use the fish target detection dataset in step 1 to train the improved YOLOv5 detection model to generate a trained target detection network. The target detection network outputs the fish detection box and the corresponding confidence.
[0042] like Figure 2 As shown in the figure, the improved YOLOv5 detection model is obtained by introducing a lightweight cross-scale fusion module, an attention mechanism, and an improved feature extraction network on the basis of the original YOLOv5 network structure to improve the accuracy of target detection.
[0043] The improved YOLOv5 detection model includes a backbone network, a neck network, and a detection head network. The fish target detection dataset image in step 1 is used as the input of the model.
[0044] The backbone network consists of five convolutional blocks CBS, four improved C3_SENetV2 modules and one SPPF module; each convolutional block CBS consists of a 2D convolution layer, a batch normalization layer and a SiLU activation layer.
[0045] Five convolution blocks CBS are defined as the first, second, third, fourth and fifth CBS modules respectively; four improved C3_SENetV2 modules are defined as the first, second, third and fourth C3_SENetV2 modules respectively.
[0046] The signal processing flow in the backbone network is as follows:
[0047] The input signal first passes through the first and second CBS modules, then the first C3_SENetV2 module, then the third CBS module, then the second C3_SENetV2 module, then the fourth CBS module, then the third C3_SENetV2 module, then the fifth CBS module, then the fourth C3_SENetV2 module, and finally output through the SPPF module.
[0048] A lightweight cross-scale fusion module CCFF is used in the neck network, which specifically includes six convolution blocks Conv, four C3 modules, two upsampling modules, four channel splicing modules and an iEMA attention mechanism module.
[0049] Define six convolution blocks Conv as the first, second, third, fourth, fifth and sixth Conv blocks respectively; define two upsampling modules as the first and second upsampling modules respectively; define four C3 modules as the first, second, third and fourth C3 modules respectively; define four channel splicing modules as the first, second, third and fourth Concat modules respectively.
[0050] The signal processing flow in the neck network is as follows:
[0051] The output of the SPPF module passes through the first Conv block and then the first upsampling module. The output of the third C3_SENetV2 module passes through the result of the second Conv block and the output of the first upsampling module, and enters the first Concat module for channel splicing. The spliced result passes through the first C3 module, and the output of the first C3 module passes through the third Conv block. The output of the third Conv block passes through the second upsampling module; the output of the second C3_SENetV2 module passes through the result of the fourth Conv block and the output of the second upsampling module and enters the second Concat module for channel splicing. The spliced result passes through the second C3 module, and the output of the second C3 module passes through the fifth Conv block and enters the third Concat module with the output of the third Conv block for channel splicing. The spliced result passes through the third C3 module, and the output of the third C3 module passes through the sixth Conv block and the output of the first upsampling module, and enters the fourth Concat module for channel splicing. The spliced result enters the fourth C3 module.
[0052] The output of the second C3 module is used as the first output result; the output of the third C3 module is used as the second output result; the output of the fourth C3 module is input into the iEMA attention mechanism module and then used as the third output result.
[0053] like Figure 3 As shown in FIG. 1 , the improved C3_SENetV2 module includes three convolution blocks CBS, a bottleneck layer Bottleneck and a channel splicing module. The three convolution blocks CBS are defined as the sixth, seventh and eighth CBS modules respectively; the channel splicing module is defined as the fifth Concat module.
[0054] The signal processing flow in the improved C3_SENetV2 module is as follows:
[0055] The input signal first passes through the sixth CBS module, and the output of the sixth CBS module enters the bottleneck layer Bottleneck and the seventh CBS module respectively. The output of the bottleneck layer Bottleneck and the output of the seventh CBS module enter the fifth Concat module for channel splicing, and the spliced result is output through the eighth CBS module.
[0056] As Figure 4 As shown in Figure 1, the SENetV2 module is introduced into Bottleneck to facilitate the representation of global feature information among multiple channels. Specifically, the bottleneck layer Bottleneck includes a SENetV2 module and two convolutional blocks CBS.
[0057] Define two convolutional blocks CBS as the ninth and tenth CBS modules respectively.
[0058] The signal processing flow in the bottleneck layer Bottleneck is as follows:
[0059] The input signal first passes through the ninth and tenth CBS modules, and then passes through the SENetV2 module. The output of the SENetV2 module is concatenated with the input signal of the bottleneck layer and then output.
[0060] The structure of the SENetV2 module is as follows Figure 5 As shown in the figure, by utilizing the multi-branch structure of ResNeXt and introducing the compression and excitation modules of SENet, the formula is expressed as:
[0061] ;
[0062] Among them, Sq(x) represents the compression operation, which enhances the feature expression ability while retaining the original features; Ex(▪) extracts key information from the global learning domain by adjusting the internal channels, significantly enhancing the feature extraction ability of the network.
[0063] By introducing the SENetV2 module with a multi-branch structure to effectively fuse feature information of different scales, fish targets can be located more accurately, effectively reducing the problems of missed detection and false detection caused by crowded occlusion in complex aquaculture environments.
[0064] Step 3. Use the fish target tracking dataset in step 1 to train the motion trajectory analysis model, output the continuous tracking video and the fish motion behavior trajectory map, and generate the corresponding TXT text and gt.txt text for tracking performance evaluation.
[0065] The motion trajectory analysis model is composed of an improved YOLOv5 detection model combined with an improved ByteTrack tracking algorithm.
[0066] The present invention constructs a lightweight YOLOv5 target detection network. Since there are fish targets of different scales in the underwater environment, a lightweight cross-scale fusion module is used to replace the original bottleneck structure, and features of different scales are fused to reduce the loss of target information, enhance the adaptability of the model to different scales, and add an attention mechanism to reduce the number of parameters while ensuring detection accuracy. For the dense distribution and occlusion of fish schools, which easily cause the problem of false detection and missed detection of fish targets, the backbone network is modified into a feature extraction network with a multi-branch convolutional neural network. By accurately extracting the global key features of the target, it is used for the detection of fish targets and the transmission of important information, thereby further improving the detection accuracy.
[0067] The flowchart of the fish multi-target detection and tracking algorithm based on deep learning is as follows Figure 6 shown.
[0068] like Figure 7As shown, the present invention adopts a ByteTrack tracking method using a motion model to address the characteristics of fish that have large changes in scale and speed and are easily occluded. This method can effectively restore the real target and achieve higher tracking accuracy and robustness, which has great advantages in solving the tracking challenges brought by fish schools.
[0069] Specifically, the improved ByteTrack tracking algorithm modifies the state parameters and adaptive noise covariance matrix of the Kalman filter to solve the problem of inaccurate tracking frame due to the rapid swimming of fish targets, and introduces an observation-centered re-update mechanism to solve the error accumulation problem caused by long-term occlusion of fish targets, thereby improving the target tracking results.
[0070] like Figure 6 and Figure 7 As shown in the figure, the specific processing flow of the motion trajectory analysis model is as follows:
[0071] Step 3.1. First, use the Kalman filter to predict the position of the target bounding box, and then use the Hungarian algorithm to match the target and the trajectory; take the continuous video frame image sequence as the input of the entire motion trajectory analysis model, divide the detected fish targets into two categories of detection frames according to the confidence score of the improved YOLOv5 detection model, and create tracking trajectories for all detected targets in the first frame.
[0072] Step 3.2. Use the improved adaptive noise Kalman filter to predict the position and motion state of the target, perform IOU matching with the detected high-score detection frame, and update the successfully matched trajectory and inherit the trajectory ID; perform IOU matching on the unsuccessful tracking trajectory with the detected low-score detection frame, and use the successfully matched one as the tracking trajectory for the next frame. If the remaining tracking trajectory is retained for more than 30 frames, it will be marked as deleted, otherwise it will be retained as the tracking trajectory for the next frame.
[0073] In the prediction phase, the Kalman filter predicts the state estimate and covariance of the current frame based on the target position of the previous frame; in the update phase, the estimated value obtained in the prediction phase is optimized using the observation value of the current frame to update the tracking position and covariance matrix. The specific formula is as follows:
[0074] (1)
[0075] in, is the posterior state estimate of the t-1 frame, A is the state transfer matrix, is the prior state estimate of frame t;
[0076] (2)
[0077] is the posterior estimated covariance of frame t-1, is the prior estimated covariance of frame t, Q is the covariance of system noise;
[0078] (3)
[0079] is the Kalman filter gain matrix, R is the observation noise matrix, is the transformation matrix from state variables to observation variables;
[0080] (4)
[0081] (5)
[0082] in, is the observed value, Represents the identity matrix.
[0083] Replace the tracking frame aspect ratio in the Kalman filter state vector with the tracking frame width w , in order to solve the problem that the tracking box does not completely match the target due to the prediction of the uniform velocity estimation model of the Kalman filter.
[0084] Modified state vector It is expressed as: ;in( , ) represents the center position coordinates of the target, h is the height of the bounding box, yes( , ,w,h)’s velocity vector;
[0085] Observation vector in the algorithm , the system noise covariance matrix Q, and the observation noise matrix R are updated in sequence as follows:
[0086] z t = [ x c ( t ) , y c ( t ) , w ( t ) , h ( t ) ] T (6)
[0087] (7)
[0088] (8)
[0089] in, and is the posterior state estimate of the tracking box width and height in frame t-1, and is the prior state estimate of the tracking box width and height in frame t, , and is the noise factor;
[0090] The observation noise matrix R is usually a constant matrix that ignores the scale information of the detection noise. Therefore, a constraint formula is added to the Kalman filter to adaptively calculate the noise covariance matrix through the confidence score obtained by detection:
[0091] (9)
[0092] in represents the original constant observation noise matrix, represents the detection confidence score of the tth frame. When increases, the noise covariance will decrease, and a new target trajectory state will be obtained in the update phase, which can effectively reduce the adverse effects of noise.
[0093] Step 3.3. When the retained tracking trajectory is re-detected within 30 frames, the virtual trajectory generated by the improved adaptive noise Kalman filter is used to update the state, and the direction consistency with the detection box is calculated for IOU matching.
[0094] For fish targets with long-term occlusion and nonlinear motion, a re-update mechanism is added to correct the accumulated errors during the target untracking period; this mechanism is activated when the target track is lost by reassociating with the observation value, and generates a virtual track based on the observation value of the step length at the beginning and end of the untracking period. , the formula is as follows:
[0095] (10)
[0096] in, represents the last moment before the track is lost, Indicates the moment when the target is re-observed. The last observation value before the trajectory is lost is , the re-observed observation value is ;
[0097] The generated virtual trajectory is used as the observation value of the lost trajectory, and the The time period is re-updated to avoid the influence of unsupervised observation and effectively reduce the error of state estimation noise accumulation. The specific formula is as follows:
[0098] (11)
[0099] (12)
[0100] (13)
[0101] Since the linear motion assumption requires the speed direction to remain consistent, but the nonlinear motion of fish targets will increase the noise of speed direction estimation, the speed direction consistency term is introduced into the association cost matrix to effectively reduce the noise:
[0102] (14)
[0103] in, represents the association cost matrix, is the set of object state estimates, is the set of observations that appear at new time nodes, z contains the observation trajectories of all tracking trajectories, Indicates the weight value.
[0104] Calculate the IoU cost matrix between the observed value and the predicted value. The formula is as follows:
[0105] (15)
[0106] Computes the arc distance between two observations on a continuous tracking trajectory and the arc between the historical observations and the new observations connecting the restored trajectory The specific formula is as follows:
[0107] (16)
[0108] (17)
[0109] In the formula, ( , )、( , ) are the observation values at two different time nodes, The arc that represents the direction of the target's motion. express and The difference in radians between .
[0110] Step 3.4. Perform IOU matching on the inactive tracking track and the unmatched high-score detection frame, assign a new ID to the unmatched high-score detection frame and create a new track, merge it with the matched high-score detection frame into the tracking track of the next frame, and directly mark the unmatched tracking track as a deleted track;
[0111] Step 3.5. Track the fish trajectory by matching the current frame with the previous frame, and output the final tracking video, behavior trajectory map and corresponding TXT text based on the matching results between multiple frames. It can be found that OPs will exhibit regular collective swimming under normal ammonia nitrogen concentrations, and within a certain range, they are basically in an active state of motion. The generated TXT text is compared with the gt.txt text to evaluate the tracking performance, highlighting the effect of the improved model.
[0112] The present invention combines the improved ByteTrack algorithm with the lightweight detection model to construct the entire detection and tracking model. By modifying the state parameters in the Kalman filter and adaptively adjusting the noise covariance matrix, the dynamic estimation accuracy of the filter is improved, and the fish in motion are accurately tracked in real time. For targets with long-term occlusion and nonlinear motion, an observation-centered Kalman filter algorithm is adopted to reduce the accumulation of noise errors while further improving the tracking results of the targets.
[0113] Step 4. Input the concentration sample values collected in step 1 into the bidirectional LSTM prediction model according to the ammonia nitrogen concentration values at the current time point and the previous five time points, predict the ammonia nitrogen concentration value at the next time point, and perform back propagation by calculating the error with the actual concentration value at the next time point. After multiple iterative training, generate an ammonia nitrogen concentration prediction model.
[0114] Specifically, the training process of the bidirectional LSTM model is as follows:
[0115] Step 4.1. Use the bidirectional LSTM model to predict the ammonia nitrogen concentration of water quality.
[0116] Define V as the input of the prediction model, f as the concentration value at different time points, and consider the ammonia nitrogen concentration values at the current time point and the previous five time points to predict the concentration value at the next time point, expressed as:
[0117] ;
[0118] Step 4.2. For the ammonia nitrogen concentration sample data set, repeat the prediction process in step 4.1;
[0119] The mean square error between the predicted concentration value at the next time point and its actual concentration value is calculated, and then back propagation is performed to continuously improve the effect of the prediction model. The validation set samples are then used to verify the accuracy of the prediction model.
[0120] Step 5. Preset the ammonia nitrogen concentration threshold according to the behavior of fish under different ammonia nitrogen concentrations. The process is as follows:
[0121] Step 5.1. In order to simulate the effect of different ammonia nitrogen concentrations on the behavior of fish, prepare a certain number of healthy fish and evenly distribute them into several fish tanks surrounded by white wallpaper.
[0122] Several different concentrations of ammonium chloride standard solutions were prepared in the same number as the fish groupings, among which 0 mg / L ammonia nitrogen concentration was used as the control group, and the other groups of ammonium chloride solutions of different concentrations were added into different fish tanks respectively.
[0123] Step 5.2. As the ammonia concentration continued to increase, the fish showed different behavioral changes, their swimming speed became slower, and the time they stayed still became longer.
[0124] Based on the different behavioral changes of fish schools, determine the ammonia nitrogen concentration threshold for normal ammonia nitrogen concentration.
[0125] In one set of examples, 16 healthy OPs were prepared and evenly placed in 4 fish tanks surrounded by white wallpaper.
[0126] Four different concentrations of ammonium chloride standard solutions were prepared, with 0 mg / L of ammonia nitrogen concentration as the control group, and the other three ammonium chloride solutions with concentrations of 5 mg / L, 15 mg / L, and 20 mg / L, respectively, and added to different fish tanks.
[0127] After a period of observation, it was found that as the ammonia concentration continued to increase, OP showed different behavioral changes. The swimming speed became slower and the time spent in a static state gradually became longer.
[0128] Especially at a solution concentration of 20 mg / L, most OPs remained stationary for a long time.
[0129] Based on the above behavioral changes, in this example, the normal ammonia nitrogen concentration threshold is determined to be 10 mg / L. That is, when the predicted ammonia nitrogen concentration is less than the ammonia nitrogen concentration threshold, it will not affect the fish, otherwise it will affect the fish.
[0130] Step 5. Preset the ammonia nitrogen concentration threshold according to the behavior of the fish under different ammonia nitrogen concentrations. Input the ammonia nitrogen concentration values at the current time point and the previous five time points into the bidirectional LSTM prediction model to predict the ammonia nitrogen concentration value at the next time point; when the predicted ammonia nitrogen concentration value at the next time point exceeds the ammonia nitrogen concentration threshold, use a camera to shoot a video of the fish swimming.
[0131] Step 6. Process the captured fish swimming behavior video into a data set in the same format as the target tracking data set, input it into the motion trajectory analysis model, and obtain the motion behavior trajectory map of each fish, which is convenient for detecting and tracking abnormal fish behaviors;
[0132] Specifically, the continuous frame images of fish video are first input into the improved YOLOv5 detection model to obtain the fish detection box and the corresponding confidence; then they are input into the improved ByteTrack tracking algorithm combined with the detection model, and the tracking video is output according to the matching results between multiple frames to generate the behavior trajectory diagram of fish under abnormal predicted concentration values.
[0133] Step 7. Based on whether the movement behavior trajectory of individual fish in the movement behavior trajectory diagram of step 6 is different from that of normal fish, it is determined whether the current ammonia nitrogen concentration value has caused adverse effects on fish, thereby determining the current water quality.
[0134] In this step, by observing and analyzing the fish behavior trajectory diagram, if the fish are shown to have irregular swimming trajectories and their swimming speed slows down or they are in a stationary state, it indicates that the abnormal predicted ammonia nitrogen concentration value has had a bad impact on the fish, and the current water quality is judged to be poor; otherwise, the current water quality is judged to be normal.
[0135] The method of the present invention can predict the ammonia nitrogen concentration value at the next time point through the above method steps, and combine with the fish movement behavior analysis to determine whether the fish will have abnormal ammonia nitrogen concentration at the next time point, thereby accurately judging the water quality, which is helpful to take preventive measures in advance to reduce the risk of fish abnormalities and improve the economic benefits of aquaculture.
[0136] Example 2
[0137] This embodiment 2 describes a computer device. The computer device includes a memory and one or more processors. An executable code is stored in the memory, and when the processor executes the executable code, it is used to implement the steps of the water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking in the above embodiment 1.
[0138] In this embodiment, the computer device is any device or apparatus with data processing capability, which will not be described in detail here.
[0139] Example 3
[0140] This embodiment 3 describes a computer-readable storage medium, which stores a program, and when the program is executed by a processor, it is used to implement the steps of the water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking in embodiment 1. The computer-readable storage medium can be an internal storage unit of any device or apparatus with data processing capabilities, such as a hard disk or memory, or an external storage device of any device with data processing capabilities, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), an SD card, a flash card (Flash Card), etc. equipped on the device.
[0141] Of course, the above description is only a preferred embodiment of the present invention, and the present invention is not limited to the above embodiments. It should be noted that all equivalent substitutions and obvious deformation forms made by any technician familiar with the field under the guidance of this specification fall within the essential scope of this specification and should be protected by the present invention.
Claims
1. A water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking, characterized in that: The steps include: Step 1. Use a colorimetric sensor to collect ammonia nitrogen concentration values at different time points underwater, collect them once every preset interval t, and collect data within a preset time period T, totaling multiple ammonia nitrogen concentration sample values; At the same time, video data under different concentrations of ammonia nitrogen are collected to construct a fish target dataset. Image data is obtained by extracting frames from the video as a fish target detection dataset, and the image dataset is divided into a training set and a validation set according to a certain ratio. The continuous video frame images are used as fish target tracking datasets, and the target IDs are annotated using Darklabel, and the corresponding gt.txt text is generated to facilitate the subsequent tracking evaluation index tasks; Step 2. Use the fish target detection dataset in step 1 to train the improved YOLOv5 detection model to generate a trained target detection network, which outputs the fish detection box and the corresponding confidence level. Step 3. Use the fish target tracking dataset in step 1 to train the motion trajectory analysis model, output the continuous tracking video and the fish motion behavior trajectory map, and generate the corresponding TXT text and gt.txt text for tracking performance evaluation; The motion trajectory analysis model is composed of an improved YOLOv5 detection model combined with an improved ByteTrack tracking algorithm; Step 4. Input the concentration sample values collected in step 1 into the bidirectional LSTM prediction model according to the ammonia nitrogen concentration values at the current time point and the previous five time points, predict the ammonia nitrogen concentration value at the next time point, calculate the error with the actual concentration value at the next time point, perform back propagation, and generate an ammonia nitrogen concentration prediction model after multiple iterative training; Step 5. Preset the ammonia nitrogen concentration threshold according to the behavior state of the fish under different ammonia nitrogen concentrations; input the ammonia nitrogen concentration values at the current time point and the previous five time points into the bidirectional LSTM prediction model to predict the ammonia nitrogen concentration value at the next time point; when the predicted ammonia nitrogen concentration value at the next time point exceeds the ammonia nitrogen concentration threshold, use a camera to shoot a video of the fish swimming; Step 6. Process the captured fish swimming behavior video into a data set in the same format as the target tracking data set, and input it into the motion trajectory analysis model to obtain the motion behavior trajectory map of each fish, so as to facilitate the detection and tracking of abnormal fish behavior; Step 7. According to whether the movement behavior trajectory of the individual fish in the movement behavior trajectory diagram of step 6 is different from that of normal fish, it is judged whether the current ammonia nitrogen concentration value has caused adverse effects on the fish, thereby determining the current water quality; In the step 2, the improved YOLOv5 detection model includes a backbone network, a neck network and a detection head network; The backbone network includes five convolution blocks CBS, four improved C3_SENetV2 modules and one SPPF module; each convolution block CBS is composed of a 2D convolution layer, a batch normalization layer and a SiLU activation layer; the five convolution blocks CBS are defined as the first, second, third, fourth and fifth CBS modules; the four improved C3_SENetV2 modules are defined as the first, second, third and fourth C3_SENetV2 modules; the signal processing flow in the backbone network is as follows: The input signal first passes through the first and second CBS modules, then the first C3_SENetV2 module, then the third CBS module, then the second C3_SENetV2 module, then the fourth CBS module, then the third C3_SENetV2 module, then the fifth CBS module, then the fourth C3_SENetV2 module, and finally output through the SPPF module; The lightweight cross-scale fusion module CCFF is used in the neck network, which specifically includes six convolution blocks Conv, four C3 modules, two upsampling modules, four channel splicing modules and iEMA attention mechanism module; the six convolution blocks Conv are defined as the first, second, third, fourth, fifth and sixth Conv blocks; the two upsampling modules are defined as the first and second upsampling modules; the four C3 modules are defined as the first, second, third and fourth C3 modules; the four channel splicing modules are defined as the first, second, third and fourth Concat modules; the signal processing flow in the neck network is as follows: The output of the SPPF module passes through the first Conv block and then the first upsampling module. The output of the third C3_SENetV2 module passes through the result of the second Conv block and the output of the first upsampling module, and enters the first Concat module for channel splicing. The spliced result passes through the first C3 module. The output of the first C3 module passes through the third Conv block, and the output of the third Conv block passes through the second upsampling module. The output of the second C3_SENetV2 module passes through the fourth Conv block and the output of the second upsampling module into the second Concat module for channel splicing. The spliced result passes through the second C3 module. The output of the second C3 module passes through the fifth Conv block and the output of the third Conv block and enters the third Concat module for channel splicing. The spliced result passes through the third C3 module. The output of the third C3 module passes through the sixth Conv block and the output of the first upsampling module and enters the fourth Concat module for channel splicing. The spliced result enters the fourth C3 module. The output of the second C3 module is used as the first output result; The output of the third C3 module is used as the second output result; The output of the fourth C3 module is then input into the output of the iEMA attention mechanism module as the third output result; The improved C3_SENetV2 module includes three convolution blocks CBS, a bottleneck layer Bottleneck and a channel splicing module; the three convolution blocks CBS are defined as the sixth, seventh and eighth CBS modules respectively; the channel splicing module is defined as the fifth Concat module; the signal processing flow in the improved C3_SENetV2 module is as follows: The input signal first passes through the sixth CBS module, and the output of the sixth CBS module enters the bottleneck layer Bottleneck and the seventh CBS module respectively. The output of the bottleneck layer Bottleneck and the output of the seventh CBS module enter the fifth Concat module for channel splicing, and the spliced result is output through the eighth CBS module; The bottleneck layer Bottleneck includes a SENetV2 module with a multi-branch structure and two convolution blocks CBS, which are defined as the ninth and tenth CBS modules respectively; the signal processing flow in the bottleneck layer Bottleneck is as follows: The input signal first passes through the ninth and tenth CBS modules, and then passes through the SENetV2 module. The output of the SENetV2 module is concatenated with the input signal of the bottleneck layer and then output.
2. The water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking according to claim 1 is characterized in that: In step 3, the improved ByteTrack tracking algorithm modifies the state parameters and adaptive noise covariance matrix of the Kalman filter to solve the problem of inaccurate tracking frame caused by the rapid swimming of the fish target, introduces an observation-centered re-update mechanism to solve the error accumulation problem caused by long-term occlusion of the fish target, and improves the target tracking result; The specific processing flow of the motion trajectory analysis model is as follows: Step 3.
1. First use Kalman filtering to predict the position of the target bounding box, and then use the Hungarian algorithm to match the target and the trajectory; use the continuous video frame image sequence as the input of the entire motion trajectory analysis model, divide the detected fish targets into two types of detection frames according to the confidence score of the improved YOLOv5 detection model, and create tracking trajectories for all detected targets in the first frame; Step 3.
2. Use the improved adaptive noise Kalman filter to predict the position and motion state of the target, perform IOU matching with the detected high-score detection frame, and update the successfully matched trajectory and inherit the trajectory ID; perform IOU matching on the unsuccessful tracking trajectory with the detected low-score detection frame, and use the successfully matched one as the tracking trajectory for the next frame. If the remaining tracking trajectory is retained for more than 30 frames, it is marked as a deleted trajectory, otherwise it is retained as the tracking trajectory for the next frame; Step 3.
3. When the retained tracking trajectory is re-detected within 30 frames, the virtual trajectory generated by the improved adaptive noise Kalman filter is used to update the state, and the direction consistency with the detection box is calculated for IOU matching; Step 3.
4. Perform IOU matching on the inactivated tracking track and the unmatched high-score detection frame, assign a new ID to the unmatched high-score detection frame and create a new track, merge it with the matched high-score detection frame into the tracking track of the next frame, and directly mark the unmatched tracking track as a deleted track; Step 3.
5. Track the fish trajectory by matching the current frame with the previous frame, and output the final tracking video, behavior trajectory map and corresponding TXT text according to the matching results between multiple frames; The generated TXT text is compared with the gt.txt text to evaluate the tracking performance.
3. The water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking according to claim 1 is characterized in that: In step 4, the training process of the bidirectional LSTM model is as follows: Step 4.
1. Use the bidirectional LSTM model to predict the ammonia nitrogen concentration value of water quality; Define V as the input of the prediction model, f as the concentration value at different time points, and consider the ammonia nitrogen concentration values at the current time point and the previous five time points to predict the concentration value at the next time point, expressed as: V=(f t ,f t-1 ,f t-2 ,f t-3 ,f t-4 ,f t-5 ); Step 4.
2. For the ammonia nitrogen concentration sample data set, repeat the prediction process of step 4.1; The mean square error between the predicted concentration value at the next time point and its actual concentration value is calculated, and then back propagation is performed to continuously improve the effect of the prediction model. The validation set samples are then used to verify the accuracy of the prediction model.
4. The water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking according to claim 1 is characterized in that: In step 5, the process of presetting the ammonia nitrogen concentration threshold according to the behavior state of the fish under different ammonia nitrogen concentrations is as follows: Step 5.
1. In order to simulate the effect of different ammonia nitrogen concentrations on the behavior of fish, prepare a certain number of healthy fish and evenly place them in several fish tanks surrounded by white wallpaper; Prepare a variety of ammonium chloride standard solutions of different concentrations equal to the number of fish groups, among which 0 mg / L ammonia nitrogen concentration is used as the control group, and the remaining groups of ammonium chloride solutions of different concentrations are added to different fish tanks; Step 5.
2. As the ammonia concentration continued to increase, the fish showed different behavioral changes. Their swimming speed became slower and they stayed still for longer periods of time. According to the different behavioral changes of fish schools, determine the ammonia nitrogen concentration threshold of normal ammonia nitrogen concentration; If the ammonia nitrogen concentration value predicted by the ammonia nitrogen concentration prediction model exceeds the normal threshold, it means that the ammonia nitrogen concentration at the next time point may have an adverse effect on the fish school, and then the camera is used to shoot the fish swimming video at the current time point.
5. The water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking according to claim 1 is characterized in that: In step 6, the captured fish swimming video is processed into a data set in the same format as the data set in step 1, and then input into a motion trajectory analysis model to detect and track abnormal behavior; Specifically, the continuous frame images of fish video are first input into the improved YOLOv5 detection model to obtain the fish detection box and the corresponding confidence; then they are input into the improved ByteTrack tracking algorithm combined with the detection model, and the tracking video is output according to the matching results between multiple frames to generate the behavior trajectory diagram of fish under abnormal predicted concentration values.
6. The water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking according to claim 2 is characterized in that: In step 3.2, in the prediction phase, the Kalman filter predicts the state estimation and covariance of the current frame based on the target position of the previous frame; in the update phase, the estimated value obtained in the prediction phase is optimized using the observation value of the current frame to update the tracking position and covariance matrix. The specific formula is as follows: in, is the posterior state estimate of the t-1 frame, A is the state transfer matrix, is the prior state estimate of frame t; is the posterior estimated covariance of frame t-1, is the prior estimated covariance of frame t, Q is the covariance of system noise; K t is the Kalman filter gain matrix, R is the observation noise matrix, and H is the transformation matrix from state variables to observation variables; Among them, z t is the observed value, and I represents the identity matrix.
7. The water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking according to claim 6 is characterized in that: In step 3.2, the tracking frame width w is used to replace the tracking frame aspect ratio α in the Kalman filter state vector; The modified state vector x t It is expressed as: Where (x c ,y c ) represents the center position coordinates of the target, h is the height of the bounding box, Yes(x c ,y c ,w,h)’s velocity vector; The observation vector z in the algorithm t , the system noise covariance matrix Q, and the observation noise matrix R are updated in sequence as follows: z t =[x c (t),y c (t),w(t),h(t)] T (6) in, and is the posterior state estimate of the tracking box width and height in frame t-1, and is the prior state estimate of the width and height of the tracking box in frame t, δ p ,δ v and δ m is the noise factor; The observation noise matrix R is usually a constant matrix that ignores the scale information of the detection noise. Therefore, a constraint formula is added to the Kalman filter to adaptively calculate the noise covariance matrix through the confidence score obtained by detection: Where R t represents the original constant observation noise matrix, c t represents the detection confidence score of the t-th frame.
8. The water quality monitoring method based on ammonia nitrogen concentration prediction and underwater target tracking according to claim 6 is characterized in that: In step 3.3, for fish targets that are occluded for a long time and move nonlinearly, a re-update mechanism is added to correct the accumulated errors during the period when the target is not tracked; This mechanism is activated during the period when the target track is lost by reassociating with the observations, generating a virtual track based on the observations at the beginning and end of the untracked period. The formula is as follows: Among them, t1 represents the last moment before the trajectory is lost, t2 represents the moment when the target is re-observed, and the last observation value before the trajectory is lost is The re-observed observations are The generated virtual trajectory is used as the observation value of the lost trajectory, and the The time period is re-updated to avoid the influence of unsupervised observation and effectively reduce the error of state estimation noise accumulation. The specific formula is as follows: Since the linear motion assumption requires the speed direction to remain consistent, but the nonlinear motion of fish targets will increase the noise of speed direction estimation, the speed direction consistency term is introduced into the association cost matrix to effectively reduce the noise: in, represents the association cost matrix, is the set of object state estimates, Z is the set of observations that appear at new time nodes, z contains the observed trajectories of all tracking trajectories, and γ represents the weight value; C IOU Calculate the IoU cost matrix between the observed value and the predicted value. The formula is as follows: C v Calculate the arc θ between two observations on the continuous tracking trajectory track and the arc θ between the historical observations and the new observations of the restored trajectory intention The specific formula is as follows: Δθ=|θ track -θ intention | (17) Where (u1, v1) and (u2, v2) are the observation values at two different time nodes, θ represents the arc of the target motion direction, and Δθ represents θ track and θ intention The difference in radians between .
