Method and device for constructing a two-way mapping model of water quality and fish behavior

CN118379788BActive Publication Date: 2026-09-11HAINAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410084983.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-19
Publication Date
2026-09-11
Estimated Expiration
2044-01-19

AI Technical Summary

Technical Problem

[0006]传统的基于滤波、分割和统计的方法可以建立简单场景的鱼体行为参数获取模型,然而,构建复杂场景下的鱼体行为参数获取方法面临挑战

Benefits of technology

[0042]本发明首先通过引入可变形卷积模块对YOLOv7进行改进(DCN-YOLOv7),利用改进模型检测视频中鱼类的位置,利用前后帧的坐标量化出鱼的游动参数。随后,将采集到的游动参数及对应的水质参数作为输入,使用随机森林模型进行分类、回归,分别完成鱼类游动参数和水质参数具体数值的预测以及指标异常级别的预测从而得到双向映射关系;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118379788B_ABST
    Figure CN118379788B_ABST
Patent Text Reader

Abstract

The application discloses a kind of water quality and fish behavior two-way mapping model construction method and device, the method includes: the video data collected, according to each frame is separately separated as picture and the fish body in picture is labeled, obtains several pictures with label;Determine the coordinates of the upper left corner and the lower right corner of the fish body anchor frame in each picture with label, and determine the center coordinates of the fish body according to it;Determine swimming parameter by the center coordinates of the fish body in continuous frame picture and time difference;The swimming parameter includes fish speed, fish acceleration and fish parade height;The swimming parameter and corresponding water quality parameter are used as input, classification, regression is carried out by random forest model, respectively complete fish swimming parameter and water quality parameter specific numerical value prediction and index abnormal level prediction, obtain two-way mapping relationship.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of aquaculture technology, and in particular to a method and apparatus for constructing a two-way mapping model between water quality and fish behavior. Background Technology

[0002] Fish movement is inextricably linked to changes in water quality parameters, which in turn lead to changes in fish behavior. Furthermore, trends in water quality parameters can, to some extent, predict fish behavioral trends. Therefore, fish behavior and water quality parameters can serve as mutual guides. However, current monitoring methods tend to be more one-way, generally using fish behavior to indicate water quality conditions. Relying solely on fish behavior to reflect water quality inevitably introduces a lag.

[0003] For fish behavior recognition, Villon et al. extracted fish features using the GoogLe-Net architecture, employed a soft-max classification method for fish detection, and also used a decision rule to improve detection accuracy. Rauf et al. proposed a CNN-based fish species recognition framework, improving classification performance by adding four convolutional layers during training at each level of the network. Wang Ying used the CenterNet detection network and the unscented Kalman filter algorithm for fish detection, finally using LSTM prediction results to identify water quality anomalies. Lu Yuetong et al. proposed tracking fish stress behavior using electromagnetic signals, video signals, and other methods to achieve online water quality monitoring and early warning. Furthermore, research methods for water quality prediction can be divided into two types: mechanistic water quality prediction methods and non-mechanistic water quality prediction methods.

[0004] Because mechanistic prediction methods are difficult to implement, current research primarily uses non-mechanistic water quality prediction methods. Traditional non-mechanistic water quality prediction methods include time series prediction, Markowhr's method, regression prediction, and grey system prediction. These methods are mainly applied in wastewater treatment. Although these methods are easy to implement, they consider fewer factors during experimentation, leading to lower experimental accuracy. With the development of machine learning, many related prediction methods have been developed, such as support vector machines and deep neural networks. These two methods have achieved good application results in aquaculture water quality prediction research. Later, scholars proposed some nonlinear prediction methods for dissolved oxygen in aquaculture, but these methods did not consider the influence of other water quality parameters on the experimental results.

[0005] The development of Artificial Neural Networks (ANNs) can precisely solve this problem. An ANN is a mathematical model that mimics the structure and function of biological neural networks. This network is formed by the connection of neurons, and information processing is achieved by modifying the connections between different neurons, exhibiting the characteristic of fitting complex nonlinear relationships. Later, Chen used a Simple Recurrent Neural Network (SRU) model and an optimized Bidirectional Stacked Simple Recurrent Neural Network (Bi-SRU) model to conduct long-term and short-term prediction experiments on water quality. Fu et al. proposed a water quality prediction method based on Temporal Convolutional Networks (TCNs). Secondly, they used the Pearson correlation coefficient method to analyze the correlation between water quality parameters. Finally, they constructed a long-term prediction model for water quality parameters based on temporal convolutional networks using prior information and preprocessed water quality data.

[0006] Traditional methods based on filtering, segmentation, and statistics can establish models for acquiring fish behavior parameters in simple scenarios. However, constructing methods for acquiring fish behavior parameters in complex scenarios presents challenges. Furthermore, exploring temporal and structural correlations to construct the interaction relationships between behavioral parameters and corresponding water quality parameters is also a crucial scientific issue. Summary of the Invention

[0007] Therefore, it is necessary to propose a method and apparatus for constructing a two-way mapping model between water quality and fish behavior to address the above problems.

[0008] A method for constructing a two-way mapping model between water quality and fish behavior, the method comprising:

[0009] The collected video data was separated into individual images for each frame, and the fish in the images were labeled to obtain several labeled images.

[0010] Determine the coordinates of the top left and bottom right corners of all fish anchor frames in each tagged image, and determine the center coordinates of the fish based on these coordinates.

[0011] Swimming parameters are determined by the fish's body center coordinates and time difference in consecutive frame images; these parameters include fish speed, fish acceleration, and fish swimming height.

[0012] Using the swimming parameters and corresponding water quality parameters as input, the random forest model is used for classification and regression to predict the specific values ​​of fish swimming parameters and water quality parameters, as well as the level of index anomalies, thereby obtaining a two-way mapping relationship.

[0013] Prior to this, determining the coordinates of the upper left and lower right corners of the fish body anchor frame in each tagged image specifically includes:

[0014] DCNv3 (Dynamically Deformable Convolution) is used as the P5 layer of the backbone network in YOLOv7.

[0015] The original convolution weights w k The spatial aggregation process is divided into two parts: depthwise convolution and pointwise convolution. Each group has a separate sampling offset p. gk and modulation scale M gk Finally, the modulation scalar between convolution sampling points is normalized; the specific calculation process is as follows: Where G is the total number of aggregation groups, w g Position-independent projection weights for the group, m gk The modulation scalar of the k-th sampling point in the g-th group is normalized along dimension K by the softmax function, x g The feature map and Δp output after sampling of the P4 feature layer of OLOv7 gk For the raster sampling position p in the g-th group k The offset.

[0016] Preferably, determining the swimming parameters by using the fish's center coordinates and time difference in consecutive frame images specifically includes:

[0017] Establish a coordinate system with the bottom left corner of the image as the origin, and set the centroid coordinates of the fish as (x, y). i ,y i );

[0018] The swimming distance of fish in different frames is in,

[0019] Assuming the fish moves at a constant linear speed between two frames, if the frame rate of the video data is γfps and the time interval is Δf, the fish's movement time...

[0020] The fish's speed is

[0021] Preferably, determining the swimming parameters by using the fish's center coordinates and time difference in consecutive frame images specifically includes:

[0022] If the fish's velocities in different frames are v1 and v2 respectively, the fish's acceleration is: Where t1 is the fish movement time in the previous frame, t2 is the fish movement time in the next frame, v1 is the fish speed in the previous frame, and v2 is the fish speed in the next frame.

[0023] Preferably, determining the swimming parameters by using the fish's center coordinates and time difference in consecutive frame images specifically includes:

[0024] The coordinates (x, y) of a target fish at a certain moment are determined by fish detection and tracking methods.

[0025] Assuming the height of the video data is H, the height of the fish swimming...

[0026] Prioritizing the swimming parameters and corresponding water quality parameters as input, a random forest model is used for classification and regression to predict the specific values ​​of fish swimming parameters and water quality parameters, as well as the level of index anomalies, thereby obtaining a two-way mapping relationship. Specifically, this includes:

[0027] The datasets containing the swimming parameters and their corresponding water quality parameters were shuffled and extracted at a ratio of 4:1, dividing the datasets into training and testing sets.

[0028] The dataset is then transposed, and the transposed training set is normalized to between 0 and 1. The input and output values ​​are then transposed again to fit the random forest model.

[0029] To build a random forest regression model, first set the hyperparameters, namely, the number of decision trees is 100 and the minimum number of leaves in each decision tree is 3, and then use the Treebagger function to build the model.

[0030] The model is fed with both the input from the training set and the input from the test set to obtain the predicted values ​​for the training set and the test set.

[0031] Perform inverse normalization to obtain the required predicted value;

[0032] R 2 The coefficient of determination, mean absolute error (MAE), mean deviation (MBE), and mean absolute percentage error (MAPE) are used as evaluation metrics to measure the performance of the model.

[0033] Preferably, the R 2 The correlation between model predictions and actual values ​​was measured, and the calculation process is as follows: Where SSR represents the residual sum of squares of the model, and SST represents the total sum of squares of the model.

[0034] Prior to this, the MAE is used to measure the mean absolute difference between model predictions and actual observations, and the calculation process is as follows: The MBE is used to represent the average difference between the model's predicted values ​​and the actual values, and the calculation process is as follows: Among them, y pred For the model's predicted values, y true Where N is the actual value and N is the sample size.

[0035] Preferably, the calculation process of MAPE is as follows: Among them, y pred For the model's predicted values, y true Here, N represents the actual value, and N represents the sample size.

[0036] An apparatus for constructing a two-way mapping model between water quality and fish behavior in aquaculture, the apparatus comprising:

[0037] The annotation module is used to separate the acquired video data into individual images for each frame and annotate the fish in the images to obtain several labeled images.

[0038] The detection module is used to determine the coordinates of the upper left and lower right corners of the fish body anchor frame in each tagged image, and to determine the center coordinates of the fish body based on these coordinates.

[0039] The swimming parameter determination module is used to determine swimming parameters by using the fish's body center coordinates and time difference in consecutive frame images; the swimming parameters include fish speed, fish acceleration, and fish swimming height;

[0040] The construction module is used to take the swimming parameters and corresponding water quality parameters as inputs, and perform classification and regression through a random forest model to predict the specific values ​​of fish swimming parameters and water quality parameters, as well as the level of index anomalies, and obtain a two-way mapping relationship.

[0041] The embodiments of the present invention have the following beneficial effects:

[0042] This invention first improves YOLOv7 by introducing a deformable convolution module (DCN-YOLOv7), using the improved model to detect the position of fish in a video and quantizing the fish's swimming parameters using the coordinates of consecutive frames. Then, using the collected swimming parameters and corresponding water quality parameters as input, a random forest model is used for classification and regression, respectively predicting the specific values ​​of the fish swimming parameters and water quality parameters, as well as the anomaly level of the indicators, thus obtaining a two-way mapping relationship.

[0043] This invention helps fish farmers predict future fish behavior and water quality using historical data and model training results. Farmers can plan and adjust their farming strategies in advance based on the model's predictions to address potential risks. For example, when the model predicts potential water quality deterioration or abnormal fish behavior, farmers can take preventative measures to avoid potential losses. Attached Figure Description

[0044] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0045] in:

[0046] Figure 1 This is a schematic diagram of the connection of IoT devices in a method for constructing a two-way mapping model between water quality and fish behavior, provided in an embodiment of the present invention.

[0047] Figure 2 A flowchart illustrating a method for constructing a two-way mapping model between water quality and fish behavior, as provided in an embodiment of the present invention;

[0048] Figure 3 This invention provides a method for constructing a two-way mapping model between water quality and fish behavior, including the structure of the DCN-YOLOv7 detection model and its detection flowchart.

[0049] Figure 4 This is a visualization diagram of the RMSE prediction results of the test set in the method for constructing a two-way mapping model between water quality and fish behavior, provided in an embodiment of the present invention.

[0050] Figure 5 This is a visualization diagram of the test set prediction accuracy in a method for constructing a two-way mapping model between water quality and fish behavior, provided in an embodiment of the present invention.

[0051] Figure 6 This is a visualization diagram of the RMSE prediction results of the test set in the method for constructing a two-way mapping model between water quality and fish behavior, provided in an embodiment of the present invention.

[0052] Figure 7 This is a visualization diagram of the test set prediction accuracy in a method for constructing a two-way mapping model between water quality and fish behavior, provided in an embodiment of the present invention.

[0053] Figure 8 This is a visualization of the training results of the Xincun Port time series experimental test set in a method for constructing a two-way mapping model between water quality and fish behavior, provided in an embodiment of the present invention. Detailed Implementation

[0054] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0055] This invention provides a method for constructing a two-way mapping model between water quality and fish behavior, applicable to, for example... Figure 1 The IoT devices shown;

[0056] The IoT devices include surface cameras, underwater cameras, water quality sensors, video recorders, wind turbines, power controllers, 4G industrial router serial ports, solar panels, batteries, multi-channel signal connection boxes, and network cables.

[0057] In this embodiment of the invention, the IoT device is used to collect a dataset (videos of fish swimming in different water qualities), and the collected dataset will serve as the basis for subsequent experiments.

[0058] like Figure 2 As shown, the method includes:

[0059] S10: Separate the collected video data into individual images for each frame and label the fish in the images to obtain several labeled images;

[0060] Specifically, the acquired video data was separated into individual 3840*2160 resolution images for each frame, and the fish in the images were labeled using Labelme software. The experimental environment consisted of an Ubuntu 20.04 operating system, an RTX 3080 Ti GPU, a PyTorch platform, CUDA 11.3, and Python 3.8.

[0061] This invention uses Labelme annotation software to annotate a fish video dataset. In model construction, to ensure sufficient training, key parameters were set as follows: 300 training epochs, batch size adjusted to 8, SGD function used as the optimization function, momentum parameter set to 0.937, and weight decay parameter set to 0.0005. The initial learning rate was set to 0.01, and decayed by a factor of 0.1 in the third epoch. The optimal trained model was then tested on a test set.

[0062] S20, determine the coordinates of the upper left and lower right corners of all fish anchor frames in each labeled image, and determine the center coordinates of the fish based on them;

[0063] Specifically, in the process of detecting fish in complex aquatic environments, the YOLOv7 model is inefficient and the detection time is slow because the parameters and storage complexity are linearly related to the total number of sampling points.

[0064] This invention uses DCN-YOLOv7 as a method for detecting fish morphology, with the aim of accurately obtaining the coordinates of the fish's center. The difference in the fish's center coordinates is used to calculate experimental indicators such as the fish's velocity and acceleration, providing rich input data for subsequent random forest predictions.

[0065] The network architecture diagram of DCN-YOLOv7 is as follows: Figure 3As shown, DCNv3 (Dynamically Deformable Convolution) is introduced into the P5 layer of the backbone network in YOLOv7, replacing all the original 3×3 kernel-sized convolutional layers in the P5 layer. This allows convolutional neurons in the backbone network to share weights. The main idea is to share the original convolutional weights w k We separate the spatial aggregation process into two parts: depthwise convolution and pointwise convolution. We divide the spatial aggregation process into g groups, each with a separate sampling offset p. gk and modulation scale M gk Finally, the modulation scalar between convolution sampling points is normalized, making the model training process more stable under different scales of transmitted fish.

[0066] The specific calculation process is shown in equation (1).

[0067]

[0068] In the formula, G represents the total number of aggregate groups.

[0069] w g —A set of position-independent projection weights

[0070] m gk —The modulation scalar of the k-th sampling point in the g-th group is normalized along dimension K by the softmax function.

[0071] x g —Feature map output by the P4 feature layer of YOLOv7 after sampling.

[0072] Δp gk — Corresponds to the grid sampling position p in group g. k offset

[0073] The overall results of the detection of fish using DCN-YOLOv7 are shown in Table 1.

[0074] Table 1. Overall Results of DCNv3-YOLOv7 Detection in Fish

[0075]

[0076] S30, swimmer parameters are determined by the fish's body center coordinates and time difference in consecutive frame images; the swimmer parameters include fish speed, fish acceleration, and fish swimming height;

[0077] Specifically, 1000 images of fish with good continuous time and planar view were selected for detection. The coordinates of the upper left and lower right corners of the anchor frames of all fish in the images were obtained, and the center coordinates of the fish were calculated. Then, the time difference between each frame was used to calculate the fish's velocity, acceleration, and swimming height, providing rich input data for the subsequent random forest water quality and fish behavior two-way interaction model.

[0078] Fish speed

[0079] Fish swim normally in water with little activity in normal conditions. However, when the water quality is abnormal, fish may swim faster, increasing their activity level. Conversely, fish living in severely polluted water will exhibit reduced swimming speed. Therefore, swimming speed can, to some extent, reflect the impact of abnormal water quality on fish.

[0080] Using the quantified speed of fish as a basis for judging water quality, the position of fish in different frames can reflect their swimming behavior. During the experiment, a coordinate system was established with the lower left corner of the video as the origin, and the centroid coordinates of the fish were set as (x...). i ,y i The calculation process for the swimming distance of fish in different frames is shown in equation (2).

[0081]

[0082] Assuming the fish moves at a constant linear speed between two frames, if the frame rate of the video is γfps and the time interval is Δf, then the calculation process of the fish's movement time is as shown in equation (3).

[0083]

[0084] The calculation process for the fish's speed at this time is shown in equation (4).

[0085]

[0086] Fish acceleration

[0087] Water quality has a direct or indirect impact on fish acceleration. Good water quality provides a suitable living environment and promotes normal physiological functions in fish. Conversely, when parameters such as dissolved oxygen, pH, and temperature deviate from suitable ranges, fish acceleration will also be affected. Therefore, fish acceleration reflects water quality to some extent. This invention also uses acceleration as a parameter for measuring water quality.

[0088] If the fish's velocities in different frames are v1 and v2 respectively, then the fish's acceleration calculation process is as shown in equation (5).

[0089]

[0090] Fish swimming height

[0091] The height at which fish swim can indirectly reflect their sensitivity to water quality; therefore, the swimming height of fish is used as a quantitative parameter. The coordinates (x, y) of a target fish at a certain moment are obtained through fish detection and tracking methods. Assuming the height of the video image is H, the swimming height of the fish at this moment is represented by h.k It is stated that the height of the parade is relative to the entire video image, and the specific calculation process is as shown in equation (6).

[0092]

[0093] After collecting information, data preprocessing is required, which mainly includes data filling and outlier correction. The moving average method is often used to process data integrity. It can effectively eliminate random fluctuations in the data, and its calculation process is relatively easy and time-saving.

[0094] Therefore, this invention utilizes the moving average method to perform missing data imputation and outlier correction.

[0095] (1) Fill in the data

[0096] During data transmission, some data may inevitably contain missing values. In the model, we generate a logical matrix by calling the ismissing function, and then continuously update the matrix through a loop. When a blank value is detected, the window length is set to 30 to perform prediction and fill until all data has been detected.

[0097] The detailed process is shown in equation (7):

[0098]

[0099] In the formula, y1…y n —Nearest observations within the sliding window

[0100] n—size of the sliding window

[0101] A — Fill value.

[0102] (2) Outlier correction

[0103] Besides missing data, outliers may also exist due to other reasons, making it essential to correct them. The moving average method is used to correct outliers by averaging the values ​​on either side of the outlier. The detailed process is shown in equation (8).

[0104]

[0105] Among them, y i The value to be checked is y. i The data y that follows it by one unit i+1 The absolute value of the difference is greater than α or y i The data y that differs from the previous one unit i-1If the absolute value of the difference is greater than β, it should be corrected to the average of the two values. α and β represent the threshold values ​​for the error between the preceding and following data.

[0106] S40, the swimming parameters and corresponding water quality parameters are used as inputs, and the random forest model is used for classification and regression to predict the specific values ​​of fish swimming parameters and water quality parameters, as well as the level of index anomalies, to obtain a two-way mapping relationship.

[0107] Specifically, the core of the bidirectional mapping model is to adopt a prediction scheme based on the random forest algorithm to achieve the purpose of bidirectional prediction. Its main idea is to shuffle the dataset of collected fish behavior and its corresponding water quality parameters to ensure the effectiveness of the model.

[0108] The original dataset was divided into training and test sets by sampling at a ratio of 4:1.

[0109] The dataset is then transposed, and the transposed training set is normalized to between 0 and 1. The input and output values ​​are then transposed again to adapt to the random forest model, ensuring that each row is a sample and each column is a feature.

[0110] Next, we need to build a random forest regression model. First, we set the hyperparameters, namely, the number of decision trees is 100 and the minimum number of leaves in each decision tree is 3. Then, we use the Treebagger function to build the model (the Treebagger function will return a random forest model object B, which can be used for prediction).

[0111] After the model is built, it needs to be tested. Inputs from both the training and test sets are fed into the model to obtain predicted values ​​for both sets. These values ​​are then inversely normalized to obtain the desired predicted values. Finally, R... 2 MAE and MBE are used as evaluation metrics to measure the performance of the model.

[0112] Random forests consist of multiple independently trained decision trees, a structure that improves model accuracy and stability. In a random forest, each decision tree is trained based on randomly selected samples and features. Specifically, a random forest randomly selects a certain number of samples (sampling with replacement) from the training dataset, and then randomly selects several features from all features for training. When dealing with regression problems, the random forest averages the predictions of each independent decision tree to obtain the regression prediction result. When dealing with classification problems, each decision tree produces its own classification result, and then the random forest uses a voting process to determine the final result, which is the classification prediction result.

[0113] The prediction process of the model is shown in Table 2.

[0114] Table 2. Random Forest Model Prediction Process

[0115]

[0116]

[0117] This embodiment also incorporates time series forecasting based on the random forest algorithm. Time series analysis considers the temporal dependencies between data points, and time series models can capture autocorrelation and trends in the data, thus providing more accurate prediction results. This means it can better predict future water quality conditions and fish behavior, helping fish farmers to take appropriate measures in advance to protect water quality and fish health.

[0118] The time series prediction process based on the random forest algorithm is shown in Table 3.

[0119] Table 3. Time Series Forecasting Process Based on Random Forest Algorithm

[0120]

[0121] For example, the dataset is first divided into a training set and a test set in a 4:1 ratio. During training, fish behavior and water quality parameters are used as inputs and paired with corresponding labels, enabling the model to learn the relationship between fish behavior and water quality.

[0122] In the testing section, different water quality parameters or fish behavior data are input into the model, and R... 2 The coefficients of determination (MAE, Mean Absolute Error), MBE, and MAPE are used as evaluation metrics to measure model performance.

[0123] Where R 2 R is a common evaluation metric for regression models, used to measure the model's ability to explain the target variable. 2 The value of is between 0 and 1. The closer it is to 1, the stronger the model's ability to explain the target variable.

[0124] Specifically, R 2The correlation between the model's predicted values ​​and the actual values ​​is measured, and its calculation process is shown in Equation (9). MAE is used to measure the mean absolute difference between the model's predicted values ​​and the actual observed values. The smaller the MAE value, the smaller the model's prediction error and the better the model's performance. Its calculation process is shown in Equation (10). MBE represents the average difference between the model's predicted values ​​and the actual values. The value of MBE can be positive, negative, or zero. A positive value indicates that the model's predicted values ​​are generally higher than the actual values, a negative value indicates that the model's predicted values ​​are generally lower than the actual values, and zero indicates that the average difference between the model's predicted values ​​and the actual values ​​is zero, that is, there is no bias. Its calculation process is shown in Equation (11). MAPE (Mean Absolute Percentage Error) ranges from [0, +∞). A MAPE of 0% indicates a perfect model, and a MAPE greater than 100% indicates a poor model. Its calculation process is shown in Equation (12).

[0125]

[0126] Where SSR represents the residual sum of squares of the model, and SST represents the total sum of squares of the model.

[0127]

[0128]

[0129]

[0130] In the formula y pred —Model predictions

[0131] y true —actual value

[0132] N—sample size

[0133] like Figure 4 As shown, this figure is a visualization of the RMSE (root mean square error) prediction results of a regression model for predicting dissolved oxygen by fish speed, acceleration, and swimming height after 100 training runs on the test set.

[0134] like Figure 5 As shown, this figure is a visualization of the prediction accuracy of a classification model that predicts dissolved oxygen using fish speed, acceleration, and swimming height after 100 training runs on the test set. The vertical axis represents 1 for normal dissolved oxygen, 2 for slightly abnormal dissolved oxygen, and 3 for extremely abnormal dissolved oxygen.

[0135] like Figure 6 As shown, this figure is a visualization of the RMSE prediction results of a regression model that predicts fish swimming height by using temperature, dissolved oxygen, pH, and salinity for 100 training runs on a test set.

[0136] like Figure 7As shown in Figures (a) and (b), this figure is a visualization of the prediction accuracy of a classification model that predicts fish swimming speed by using temperature, dissolved oxygen, pH and salinity to train 100 times on the test set. The vertical axis 1 represents normal fish swimming speed, 2 represents slightly abnormal swimming speed, and 3 represents extremely abnormal swimming speed.

[0137] like Figure 8 As shown in the figure, this diagram presents the results of predicting fish swimming speed using time series analysis methods on two datasets, along with performance evaluation and analysis. A visualization of the results of 100 training iterations on different metrics of the time series experimental test set is shown below. Figure 8 As shown.

[0138] To ensure the generalization ability of the invention, the invention will be tested on two datasets. The evaluation results of each experimental test set in the bidirectional mapping model of the two datasets are shown in Tables 4, 5 and 6.

[0139] Table 4 Evaluation Results of the Classification Experiment Test Set

[0140]

[0141] The classification experiments, specifically predicting the level of fish behavioral anomalies based on input water quality parameters and predicting the level of water quality anomalies based on input fish behavior, showed that the average accuracy of the bidirectional prediction model for the Xincun Port dataset reached 91.272% and 92.848%, respectively; while the average accuracy of the bidirectional prediction model for the Li'an Port dataset reached 92.461% and 87.205%, respectively. This indicates that the model can accurately predict the anomaly level and has a high degree of consistency with the actual situation.

[0142] Table 5 Evaluation results of the regression experimental test set

[0143]

[0144] Regarding the regression experiment, the results above show that the Xincun Port dataset prediction model has a high R-value for predicting water quality parameters based on input fish behavior parameters. 2 The value reached 0.862; the R-value of the prediction model for the Port Lean dataset was... 2The mean absolute error (MAE) was 0.819, indicating that the model can predict dissolved oxygen levels relatively well. The MAE value for the Xincun Port dataset was 0.364 mg / L, and the MAE value for the Li'an Port dataset was 0.565 mg / L, indicating a relatively small average prediction error. The mean absolute error (MBE) values ​​for the two datasets were -0.020 mg / L and -0.106 mg / L, respectively, while the root mean square error (RMSE) values ​​were 0.652 mg / L and 0.691 mg / L, respectively, indicating that the prediction results are generally close to the actual values. Furthermore, the experiment predicting fish behavior parameters from input water quality parameters also showed low mean absolute error (MAE), mean partial square error (MBE), and root mean square error (RMSE) on the test set, with a coefficient of determination R0. 2 It is also quite close to 1. This indicates that fish behavior parameters and water quality parameters can serve as reliable predictive indicators, and that the model can effectively explore the relationship between the two in terms of bidirectional mapping.

[0145] Table 6 Evaluation Results of the Time Series Experimental Test Set

[0146]

[0147] In addition, time-series prediction experiments were conducted on two datasets. Through time-series analysis, we can predict future water quality changes and fish behavior. For the time-series prediction experiments, we used R. 2 MAPE was used as a metric. In this experiment, after 100 training iterations, the average MAPE on the test set of the two datasets were 19.995% and 17.636%, respectively, with an average R² of [missing value]. 2 The values ​​are 0.849 and 0.871, respectively. MAPE represents the error of the predicted values. This index ranges from [0, +∞). A MAPE of 0% indicates a perfect model, while a MAPE greater than 100% indicates a poor model. R 2 This indicates the model's fit, combined with R... 2 The model's performance was quantified together with the MAPE value. Experimental results show that our model exhibits a certain degree of accuracy in predicting water quality parameters. The application prospects and advantages of time series analysis are evident. It can help fish farmers better understand the relationship between water quality and fish behavior, and provide useful guidance for future research and management.

[0148] In summary, the prediction model constructed by this invention can predict and reflect the two-way relationship between fish behavior and water quality.

[0149] This invention successfully constructed a bidirectional mapping model between fish behavior and water quality parameters, and evaluated and analyzed it. The core idea of ​​this model is to first monitor fish behavior parameters under different water quality conditions to form a dataset corresponding to fish behavior and water quality parameters. Next, the water quality conditions and fish behavior parameters are used as inputs to train the model, achieving a bidirectional mapping effect. That is, when fish behavior parameters are used as input, the model reflects the water quality conditions, and vice versa. Finally, the performance of the entire model is evaluated using a test set selected according to a specific ratio. The fish features selected in this invention are speed, acceleration, and swimming height; the water quality parameters selected are pH, temperature, dissolved oxygen, and salinity. The average accuracy of the classification experiment reached 90.947%, and the regression experiment showed R... 2 The average value can reach 0.8. Test results show that by establishing a two-way mapping model between water quality parameters and fish swimming behavior, it is possible to predict the specific values ​​of fish swimming behavior based on water quality parameters, and vice versa. This is of great significance for understanding fish preferences for water quality and the changes in fish behavior under different water quality conditions.

[0150] Furthermore, the test results also demonstrated how both parameters reflect the level of anomalies. Specifically, the severity of water quality anomalies can be determined by observing fish swimming parameters, and the degree of fish swimming anomalies can be determined by using water quality parameters. This provides a convenient and effective method for water quality monitoring and management, helping fish farmers to promptly identify and resolve water quality problems. Finally, a time-series prediction model was established. By analyzing historical data and time-series trends, it can accurately predict parameter values ​​at the next time point. This is of great significance for water quality monitoring and fish behavior research, helping fish farmers take proactive measures to protect the fish's ecological environment and water quality conditions.

[0151] This invention successfully established a two-way mapping model between fish behavior and water quality parameters, and evaluated and analyzed it. The establishment of this model offers three main benefits: First, fish farmers can predict specific values ​​of fish swimming behavior based on water quality parameters, and vice versa. This is significant for understanding fish preferences for water quality and the changes in fish behavior under different water quality conditions. Second, fish farmers can determine the severity of water quality anomalies by observing fish swimming parameters, and vice versa. This provides a convenient and effective method for water quality monitoring and management, helping fish farmers to promptly identify and resolve water quality problems. Finally, by establishing a time-series prediction model and analyzing historical data and time-series trends, fish farmers can accurately predict parameter values ​​at the next point in time. This is significant for water quality monitoring and fish behavior research, helping fish farmers take proactive measures to protect the fish's ecological environment and water quality conditions.

[0152] In this embodiment of the invention, a deformable convolution is added to the dataset acquisition module in YOLOv7. When detecting fish targets in videos, fish may undergo deformation and posture changes during swimming. Traditional convolution may not accurately capture these changes, while deformable convolution can adjust the convolution kernel according to the position offset parameter, better adapting to the shape changes of the fish target. Furthermore, the receptive field shape of traditional convolution remains unchanged at each fixed position, which may not adapt to the positional changes during fish movement, leading to inaccurate motion parameter calculations. Introducing deformable convolution allows for adjustment of the receptive field shape according to the position offset parameter, more accurately capturing the positional information of the fish target, thereby calculating more accurate motion parameters. Therefore, the introduction of deformable convolution can make target detection more robust when calculating the speed, acceleration, and swimming height of fish.

[0153] Random forests not only improve the accuracy of feature node splitting in decision trees by calculating the importance of features, thus helping us understand the impact of data, but also reduce the risk of overfitting by introducing randomness to construct multiple different decision trees. Therefore, this invention combines optimized YOLOv7 (DCN-YOLOv7) with random forests to build a method from data collection to establishing a bidirectional mapping relationship. The test results also reflect the importance ranking of various water quality parameters and fish swimming parameters on the other side's experimental results. The resulting feature importance ranking can be applied to real-world scenarios, helping to guide fish and water quality monitoring and management. Based on the importance ranking results, we can more effectively focus on and monitor features that have a significant impact on the other side, thereby more effectively protecting and managing the relevant ecosystems.

[0154] This invention also provides an apparatus for constructing a two-way mapping model between water quality and fish behavior in aquaculture, the apparatus comprising:

[0155] The annotation module is used to separate the collected video data into individual images for each frame and to annotate the fish in the images, thereby obtaining several labeled images.

[0156] The detection module is used to determine the coordinates of the top left and bottom right corners of all fish anchor frames in each tagged image, and to determine the center coordinates of the fish based on these coordinates.

[0157] The swimming parameter determination module is used to determine swimming parameters by using the fish's body center coordinates and time difference in consecutive frame images; the swimming parameters include fish speed, fish acceleration, and fish swimming height;

[0158] The construction module is used to take the swimming parameters and corresponding water quality parameters as inputs, and perform classification and regression through a random forest model to predict the specific values ​​of fish swimming parameters and water quality parameters, as well as the level of index anomalies, and obtain a two-way mapping relationship.

[0159] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.

[0160] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0161] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A method for constructing a two-way mapping model between water quality and fish behavior, characterized in that, The method includes: The collected video data was separated into individual images for each frame, and the fish in the images were labeled to obtain several labeled images. Determine the coordinates of the top left and bottom right corners of the fish's anchor frame in each tagged image, and determine the center coordinates of the fish based on these coordinates. Swimming parameters are determined by the fish's body center coordinates and time difference in consecutive frame images; these swimming parameters include fish speed, fish acceleration, and fish swimming height. Using the swimming parameters and corresponding water quality parameters as input, the random forest model is used for classification and regression to predict the specific values ​​of fish swimming parameters and water quality parameters, as well as the level of index anomalies, and to obtain a two-way mapping relationship. Determining the coordinates of the upper left and lower right corners of the fish body anchor frame in each tagged image specifically includes: Dynamically deformable convolution DCNv3 is used as the P5 layer of the backbone network in YOLOv7. The original convolution weights The spatial aggregation process is divided into two parts: depthwise convolution and pointwise convolution. Each group has its own sampling offset. and modulation scale Finally, the modulation scalar between convolution sampling points is normalized; the specific calculation process is as follows: in, For the total number of aggregation groups, Position-independent projection weights for groups The modulation scalar of the k-th sampling point in the g-th group is normalized along dimension K by the softmax function. The feature map output after sampling from the P4 feature layer of YOLOv7. For the grid sampling position corresponding to the g-th group The offset.

2. The method for constructing a two-way mapping model between water quality and fish behavior according to claim 1, characterized in that, The quantification of swimming parameters using the fish's center coordinates and time difference in consecutive frame images specifically includes: Establish a coordinate system with the bottom left corner of the image as the origin, and set the centroid coordinates of the fish as (x, y). i ,y i ); The swimming distance of fish in different frames is ;in, Assuming the fish moves at a constant linear speed between two frames, if the frame rate of the video data is γfps and the time interval is Δf, the fish's movement time... ; The fish's speed is .

3. The method for constructing a two-way mapping model between water quality and fish behavior according to claim 2, characterized in that, The method of determining swimming parameters by using the fish's center coordinates and time difference in consecutive frame images specifically includes: If the fish's velocities in different frames are v1 and v2 respectively, the fish's acceleration is: Where t1 is the fish movement time in the previous frame, t2 is the fish movement time in the next frame, v1 is the fish speed in the previous frame, and v2 is the fish speed in the next frame.

4. The method for constructing a two-way mapping model between water quality and fish behavior according to claim 3, characterized in that, The method of determining swimming parameters by using the fish's center coordinates and time difference in consecutive frame images specifically includes: The coordinates (x, y) of a target fish at a certain moment are determined by fish detection and tracking methods. Assuming the height of the video data is H, the height of the fish swimming... .

5. The method for constructing a two-way mapping model between water quality and fish behavior according to claim 4, characterized in that, Using the swimming parameters and corresponding water quality parameters as input, a random forest model is used for classification and regression to predict the specific values ​​of fish swimming parameters and water quality parameters, as well as the level of index anomalies, thereby obtaining a two-way mapping relationship. Specifically, this includes: The datasets containing the swimming parameters and their corresponding water quality parameters were shuffled and extracted at a ratio of 4:1, dividing the datasets into training and testing sets. The dataset is then transposed, and the transposed training set is normalized to between 0 and 1. The input and output values ​​are then transposed again to fit the random forest model. To build a random forest regression model, first set the hyperparameters, namely, the number of decision trees is 100 and the minimum number of leaves in each decision tree is 3, and then use the Treebagger function to build the model. The model is fed with both the input from the training set and the input from the test set to obtain the predicted values ​​for the training set and the test set. Perform inverse normalization to obtain the required predicted value; R 2 The coefficient of determination, mean absolute error (MAE), mean deviation (MBE), and mean absolute percentage error (MAPE) are used as evaluation metrics to measure the performance of the model.

6. The method for constructing a two-way mapping model between water quality and fish behavior according to claim 5, characterized in that, The R 2 The correlation between model predictions and actual values ​​was measured, and the calculation process is as follows: Where SSR represents the residual sum of squares of the model, and SST represents the total sum of squares of the model.

7. The method for constructing a two-way mapping model between water quality and fish behavior according to claim 5, characterized in that, The MAE is used to measure the mean absolute difference between model predictions and actual observations. The calculation process is as follows: The MBE is used to represent the average difference between the model's predicted values ​​and the actual values, and the calculation process is as follows: ; where y pred For the model's predicted values, y true Here, N represents the actual value, and N represents the sample size.

8. The method for constructing a two-way mapping model between water quality and fish behavior according to claim 5, characterized in that, The calculation process of MAPE is as follows: ; where y pred For the model's predicted values, y true Here, N represents the actual value, and N represents the sample size.

9. A device for constructing a two-way mapping model between water quality and fish behavior in aquaculture, characterized in that, The device includes: The annotation module is used to separate the acquired video data into individual images for each frame and annotate the fish in the images to obtain several labeled images. The detection module is used to determine the coordinates of the upper left and lower right corners of the fish body anchor frame in each labeled image, and to determine the center coordinates of the fish body based on them; it is also specifically used to use the Dynamically Deformable Convolution DCNv3 as the P5 layer of the backbone network in YOLOv7. The original convolution weights The spatial aggregation process is divided into two parts: depthwise convolution and pointwise convolution. Each group has its own sampling offset. and modulation scale Finally, the modulation scalar between convolution sampling points is normalized; the specific calculation process is as follows: in, For the total number of aggregation groups, Position-independent projection weights for groups The modulation scalar of the k-th sampling point in the g-th group is normalized along dimension K by the softmax function. The feature map output after sampling from the P4 feature layer of YOLOv7. For the grid sampling position corresponding to the g-th group The offset; The swimming parameter determination module is used to determine swimming parameters by using the fish's body center coordinates and time difference in consecutive frame images; the swimming parameters include fish speed, fish acceleration, and fish swimming height; The construction module is used to take the swimming parameters and corresponding water quality parameters as inputs, and perform classification and regression through a random forest model to predict the specific values ​​of fish swimming parameters and water quality parameters, as well as the level of index anomalies, and obtain a two-way mapping relationship.