Next Article in Journal
Application of Wavelet Transform for the Detection of Cetacean Acoustic Signals
Previous Article in Journal
Comparative Impact Analysis of Cyclone Ana in the Mozambique Channel Using Satellite Data
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

A CNN-Based Method for Heavy-Metal Ion Detection

1
School of Information and Communication Engineering, Hainan University, Haikou 570228, China
2
School of Applied Science and Technology, Hainan University, Haikou 570228, China
*
Authors to whom correspondence should be addressed.
These authors contributed equally to this work.
Appl. Sci. 2023, 13(7), 4520; https://doi.org/10.3390/app13074520
Submission received: 14 March 2023 / Revised: 25 March 2023 / Accepted: 27 March 2023 / Published: 2 April 2023

Abstract

:
Data processing is an essential component of heavy-metal ion detection. Most of the research now uses a conventional data-processing approach, which is inefficient and time-consuming. The development of an efficient and accurate automatic measurement method for heavy-metal ions has practical implications. This paper proposes a CNN-based heavy-metal ion detection system, which can automatically, accurately, and efficiently detect the type and concentration of heavy-metal ions. First, we used square-wave voltammetry to collect data from heavy-metal ion solutions. For this purpose, a portable electrochemical constant potential instrument was designed for data acquisition. Next, a dataset of 1200 samples was created after data preprocessing and data expansion. Finally, we designed a CNN-based detection network, called HMID-NET. HMID-NET consists of a backbone and two branch networks that simultaneously detect the type and concentration of the ions in the solution. The results of the assay on 12 sets of solutions with different ionic species and concentrations showed that the proposed HMID-NET algorithm ultimately obtained a classification accuracy of 99.99% and a mean relative error of 8.85% in terms of the concentration.

1. Introduction

Heavy-metal ions (HMIs) are highly toxic and have a detrimental impact on ecosystems and human health [1]; hence, detecting the content of HMIs in the environment is an important research hotspot. However, heavy-metal ion detection is generally performed in the laboratory, which requires immovable instruments. In order to better detect heavy-metal ions in the environment, we are eager to explore a convenient and automatic heavy-metal ion detection method. For that goal, there is a need for not only a portable detection instrument but also an automated data-processing method.
Heavy-metal ion detection is generally divided into two steps; the first is electrochemical sampling using sensors, and the second is the processing of the sampled data. Researchers have been fruitful in sampling HMI data. In the electrochemical sampling phase, the data are generally sampled by using a three-electrode potentiostat [2]. The concentration of a substance can be calculated from the relationship between the current signal received by the three-electrode potentiostat and the concentration of the substance being measured. Liao et al. [3] used a potentiostat to detect heavy-metal ions Pb(II) in water. Currently, portable potentiostats are increasingly being used for the measurement of various substances [4]. Anila et al. [5] used a portable potentiostat to detect ferricyanide. Nemiroski et al. [6] used a portable potentiostat to detect glucose in the blood, sodium in the urine, heavy-metal solutions, and malaria antigens. The portable potentiostat facilitates electrochemical sampling [7]. Most of the aforementioned studies have optimized the electrochemical sampling methods [8,9] and have made the sampling instrument miniaturized. However, there has been little research into automated data processing. Generally, portable potentiostats require traditional time-consuming manual analysis after measuring the data. Therefore, we are eager to explore an automated electrochemical measurement method that can be ported to the portable potentiostat to simplify the detection.
In the heavy-metal ion detection field, most studies use conventional data-processing methods. Conventional data-processing methods usually use square-wave voltammetry to perform polarimetric analysis of heavy-metal solutions [10]. The polarimetric analysis is a method that relies on the characteristics of the redox peaks of different ions to determine the species and concentration of the ions. The half-wave potentials of different ions usually vary, and the concentration of the same ion is linearly related to the peak height, which is the basis for the qualitative and quantitative analysis of the polar spectrum. By measuring the peak height of the standard solution at different concentrations, a standard curve can be plotted for the ion. Routinely, the type of ion can be predicted by comparing the half-wave potential of the measured solution to that of the standard solution. The concentration of the solution to be predicted can be obtained by comparing the standard curve fitted to the standard solution to the actual measured peak height [8]. Polar spectral analysis has achieved good results in heavy-metal detection; however, data-processing methods require manual comparisons to identify the data obtained from the measurements. Traditional manual identification needs to be improved because it is time-consuming and inefficient. Therefore, it is of great practical importance to study an efficient data-processing method for the detection of HMI.
Deep learning is an automated approach to data processing, which has achieved high success in many areas [11]. Due to its excellent performance, the deep learning-based approach has also been applied to data processing in electrochemical analysis. Gabrieli et al. [12] used principal component analysis (PCA) to analyze the concentration of metal cations in quantitative aqueous mixtures. They empirically extracted five discrete quantities from the electrochemical data and used PCA to analyze and identify these discrete quantities. However, the complex feature extraction method made the quantitative analysis process very cumbersome. Lavrentev et al. [13] used a multilayer perceptron model [14,15] to detect bacterial concentrations in culture media or dairy products and obtained an accuracy of 94%. For the same hydrogel, they used the current–voltage data at five different scanning parameters as a database. This means that the actual measurement also requires five tests for the same hydrogel, which takes about 15 min to detect. Their work reduces the traditional 3 days of measurement time to 15 min, which is undoubtedly a huge improvement. However, these simple models did not fully satisfy the need for accuracy.
A convolutional neural network is a deep feed-forward neural network with features such as local connectivity and weight sharing. As one of the most important networks in the field of deep learning, it has been widely used. In the field of computer vision, LeNet-5 was successfully applied to handwritten digit recognition [16], and AlexNet was successfully applied to face recognition [17]. AlexNet was used in medicine for human brain detection [18], alcoholism recognition [19], and diabetic retinal image classification [20]. In the field of taste recognition, convolutional neural networks (CNNs) based on electronic tongues and electronic noses have achieved great success [21]. Zhong et al. [22] achieved 99.99% accuracy in classifying tea products. In the field of gas detection, Wei et al. [23] achieved three single-gas classifications with 98.67% accuracy using an improved LeNet-5, and Han et al. [24] obtained 96.87% accuracy using LeNet-5 for mixed-gas identification. Guo et al. [25] proposed a deep learning model combining random forests, convolutional neural networks, and gated cyclic control units to predict atmospheric PM concentrations. Their model uses CNN for feature extraction and dimensionality reduction and achieves good results. In the field of electrochemical analysis, Dean et al. [26] achieved the highest sensitivity and specificity with neural networks based on LSTM and FCN. Their research demonstrates that various deep learning schemes can be used well for the classification of CSWV data. These studies showed great promise for the application of convolutional neural networks in the field of electrochemical detection. However, while these studies provide an automated approach to data processing, they do not simultaneously predict the species and concentration of the analyte to be measured.
Typically, convolutional neural networks have a large number of parameters, require large computational power, and are generally deployed on CPU/GPU platforms with powerful arithmetic. However, CPU/GPU platforms have large sizes, high energy consumption, and are not suitable for portable application scenarios. The Jetson Nano is Nvidia’s embedded hardware platform designed for small AI edge computing devices. The Jetson Nano has a smaller size and lower power consumption and offers more computing power than typically embedded platforms [27]. A variety of deep learning-based network models have been successfully deployed on the Jetson Nano platform, and satisfactory performance has been achieved [28]. The approach of deploying convolutional neural networks on embedded development platforms can further automate measurements.
Based on the problems above, the paper proposed a CNN-based method for the detection of heavy-metal ions (HMI). It can efficiently detect the ion species and concentration in heavy-metal solutions. Firstly, a portable potentiostat was designed for the convenient sampling of HMI data. Secondly, a CNN-based heavy-metal ion detection network was designed for processing the data, which we called HMID-NET. The backbone of HMID-NET involves six convolutional layers and two pooling layers, aimed at extracting features, followed by two prediction branches to predict the ion type and ion concentration. To our knowledge, HMID-NET has achieved the first simultaneous prediction of the type and concentration of heavy-metal ions. To train the network, we performed preprocessing operations and data expansion on the electrochemical data obtained from the measurements to create a heavy-metal ion solution dataset containing 1200 data samples. Then, we deployed the inspection network onto the Jetson Nano platform. Together with the potentiostat, it formed a portable HMI inspection unit that greatly enhanced the convenience of the instrument. Finally, we performed tests on 12 standard solutions. The test results demonstrated that the CNN-based HMI detection method proposed in this paper has comparable advantages over the comparison methods.

2. HMI Detection Method

The HMI detection method proposed in this paper consists of a sampling module and a control module, as shown in Figure 1. The sampling module consists of an electrochemical potentiostat and screen-printed electrodes (SPEs) [29,30]. The sampling module uses the screen-printed electrode as a sensor to sample the solution to be measured and obtain the voltage current data. The control module is responsible for issuing the sampling parameters, receiving the data measured by the sampling module, and processing the sampling data to obtain the ion type and concentration. The control module uses the Jetson Nano embedded platform on which the =HMID-NET algorithm is deployed.
To make it more user-friendly, we added some small functional hardware to our device, such as power, a display screen, and a network card. The devices that need to be powered are the Jetson Nano and the potentiostat. The Jetson Nano is powered by a mobile power supply. The potentiostat consumes less power and can be either plugged into the Jetson Nano or plugged into a mobile power supply. In addition, a touch display, network card, mobile keyboard, and mobile mouse (optional) can be connected to the Jetson Nano side. This allows for easy data visibility, remote data access, etc.
The detection process includes the following steps. First, connect the wires between the devices and between the device and the power supply. The power supply and the Jetson Nano are connected by a USB, the Jetson Nano and the potentiostat are connected by a DuPont wire, and the sensor and the potentiostat are connected by a three-electrode interface. Second, drop the solution onto the sensor. The Jetson Nano then sends an acquisition signal to the potentiostat. Finally, after the potentiostat has collected the data, they are transmitted back to the Jetson Nano for the HMI type and concentration prediction. The Jetson Nano displays the predictions on the display.

2.1. Sampling Module

The sampling module consists of a commercially available screen-printed electrode sensor external to the three-electrode potentiostat, as shown in Figure 2. The three-electrode potentiostat measures the solution according to the mode and parameters (e.g., the scanning speed, scanning mode, number of cycles, etc.) from the control module. It can perform the most commonly used square-wave voltammetry [31]. The parameters of the SWV include Init, Final, Increase, Amplitude, and Frequency, where Init represents the initial potential, Final represents the endpoint potential, and Incr represents the potential increment.
The three-electrode potentiostat has a form factor of 1.2 × 0.8 inches. It uses an STM32L432-KBUx embedded microprocessor as the main control chip, an LDO3.3V regulator to provide the operating current, and an external 8 MHZ crystal oscillator. The two precision op-amps integrated by the AD8606 amplifier form the potentiostat circuit and the microcurrent detection circuit, respectively. The voltages of the WE and RE electrodes are controlled by a dual-channel 12-bit DAC in the main control. The three-electrode potentiostat is connected to the screen-printed electrodes via an electrochemical electrode interface. The data collected by the screen-printed electrodes are converted to analog-to-digital by the chip’s built-in ADC. Data communication between the three-electrode potentiostat and the control module is via a serial port.
In this study, the solution was sampled by square-wave voltammetry during the test. In order to run a potential scan, the scan was defined as a sequence of well-timed Δ t steps, where the voltage was adjusted in increments of Δ V . The current I obtained from the response was measured and transmitted. Our potentiostats can achieve odd increments Δ V o d d that are different from even increments Δ V e v e n .
Δ V o d d = 2 A
Δ V e v e n = 2 A I n c r e a s e
The system can be also used to sample solutions using cyclic voltammetry and chronoamperometry (CA), depending on the practical needs.

2.2. Control Module

The control module was designed to control the sampling of the system and to process the sampling data using Nvidia’s Jetson Nano (B01) as the hardware and software platform. The Jetson Nano is a small and powerful computing platform designed to support edge AI. It is miniaturized while having enough computing power to be used in deep learning, computer vision, and other application scenarios. The Jetson Nano is compatible with a variety of programming tools, such as Python 2.7 [28], which has a powerful PySerial class library that makes it easy to perform a range of operations on the development board, such as command-sending and command-receiving [32]. The Jetson Nano can be used as a control and computing platform in place of a traditional host computer, such as a laptop.
The proposed HMI detection method on the Jetson Nano platform uses the PySerial library to issue operating instructions to control the system operation. First, the Jetson Nano platform sends the sampling mode and the experimental parameters to the sampling module via UART. The three-electrode potentiostat then enters the operating mode and acquires the solution data. The Jetson Nano then periodically queries the sampling module to determine whether the data collections are complete. Once the data are collected, the Jetson Nano sends a data transmission command, and the sampling module transmits the collected data to the Jetson Nano. The Jetson Nano automates the measurements by means of programming. It is much simpler than conventional electrochemical workstations. It eliminates the need to manually operate the computer after a single measurement is taken.
The HMID-NET handles the collected data. It first extracts the features in the data and then predicts the ion type and ion concentration in the solution by means of two branches. The HMID-NET has been deployed on the Jetson Nano. Compared to common deep learning models such as LeNet and AlexNet, HMID-NET has a smaller network structure and fewer network parameters. It runs smoothly on the Jetson Nano platform with an average inference time of 18.8 ms, fully meeting the needs of the real-time detection of portable devices.

2.3. Data Acquisition

The paper acquired the HMI data with C d 2 + , Z n 2 + , and C u 2 + as examples.
Reagents: For the preparation of the experimental solutions, cadmium chloride, zinc chloride, copper chloride, and potassium chloride were purchased from Shanghai Maclean.
The solutions were configured with ultra-pure water with concentration gradients of 0.2 g/L, 0.5 g/L, 1 g/L, and 2 g/L of cadmium chloride, zinc chloride, and copper chloride dissolved in a 0.1 mol/L potassium chloride base solution, respectively. The mixtures were obtained by diluting and mixing the respective analyte solutions to reach the desired concentration levels. The pH of the solutions was not controlled to avoid the use of buffer solutions introducing additional ionic species [12].
Data acquisition: The electrochemical potentiostat used the SWV method to sample 12 standard solutions with the same experimental parameters (increase = 0.005 V, amplitude = 0.025 V, and frequent = 25 Hz). Each solution was sampled 50 times. The screen-printed electrodes were replaced after each test, and the solutions were changed at the same time. To ensure accurate measurement results, the results of multiple measurements were analyzed, and any deviations due to chance were discarded; for instance, coarse deviations due to the solution configuration, differences in the screen-printed electrode workmanship, an unstable power supply from the mobile power supply, etc. Due to the small area of the screen-printed electrodes, a small dose of the solution was used for each measurement. This eliminated the need to reconfigure the solution. Fifty test samples of each solution were taken from the multiple sampling of a single solution configuration.
From a manufacturing process point of view, differences in the surface workmanship of screen-printed electrodes can lead to differences in test results for the same solution. To ensure the viability of the data input to the neural network, it should first be ensured that the repeat test results for the same solution are stable within a certain margin of error. As can be seen from Figure 3a, the results of the five tests almost overlapped. Comparing the currents corresponding to the same voltage points, the average error in the test results was around 0.05 mA. Such an error had little impact on the subsequent neural network training. On the contrary, such a small error could effectively improve the generalization ability of the HMID-NET. By comparing the measurement results of the other groups, it was found that there was little difference between the results of multiple tests with the same solution. This proves the good stability of the disposable screen-printed electrodes. The stability exhibited by the screen-printed electrodes ensures the value of subsequent studies.
Ignoring minor errors due to the differences in the screen-printed electrodes, the same measurement parameters ensured that the only variable in the measurement process was the solution. Twelve specimen solutions were tested, and the outcomes are shown in Figure 3b–d. In the above tests, the different types of solutions C d 2 + , Z n 2 + , and C u 2 + each exhibited different half-wave potentials. The peak heights for the same solution at different concentrations increased with the increasing concentration of the test solution. This is in accordance with the results of the SWV measurement method in theory.
To better extract the features of the data and improve the deep learning method’s accuracy, the voltage range for the electrochemical acquisition should encompass all voltages where peaks occur. By comparing all of the test results, a final voltage acquisition range of −0.3 to 0.7 V was set.
The HMI determination method in this paper does not require manual analysis and calculation of the half-wave potential and peak potential of the solution as in the conventional method. The powerful feature extraction capabilities of convolutional neural networks can capture the half-wave potentials and peaks of various solutions very well.

3. CNN Structure

3.1. CNN Structural Design

A convolutional neural network with local connectivity, weight sharing, and other features is a deep feed-forward neural network. It has powerful feature extraction as well as analysis and prediction capabilities. CNNs have been successfully used in many recognition fields, such as LeNet-5 for handwritten digital character recognition, AlexNet for face recognition and pedestrian detection, and lightweight networks, such as SqueezeNet and MobileNet for mobile devices.
We designed the HMID-NET to detect the type and concentration of the HMI. The structure of the HMID-NET is shown in Figure 4.
The HMID-NET was divided into three parts: the backbone, the classification network, and the regression network. The backbone was mainly used to extract the half-wave potential and peak features of the data. It consisted of six convolution layers and two maximum pooling layers. Among the six convolutional layers, two of them were 1 × 1 convolutional and were used to extend the number of channels. The other was a 3 × 3 dilated convolution for feature extraction. The network of classifications is used to categorize the types of heavy-metal ions. It maps the input of 800 neurons to three target-based neurons; the cross-entropy loss is the loss function of the classification network and the activation function is ReLU. The data in these three neurons correspond to the probability of the solution containing Z n 2 + , C u 2 + , and C d 2 + , respectively. The regression network maps 800 input neurons to the 3 neurons used for regression prediction. The loss function of the regression network is the mean square loss, and the activation function of the output layer is Softmax. The aim of using the Softmax function is to regress the predicted values between 0 and 1, thus avoiding the problem of gradient loss when the error is backpropagated. The three types of neuron data in the regression network correspond to the predicted concentrations of Z n 2 + , C u 2 + , and C d 2 + .

3.2. Convolutional Layer

The role of the convolution layer iswas to extract features from a local region. Each layer of the convolution had multiple convolution kernels, which are feature extractors and are the bases of convolution operations. The convolutional layer neurons are usually organized as three-dimensional structured neural layers consisting of D feature mappings of size M × N (D is the number of channels, M is the height, and N is the width). Feature mapping is the feature matrix obtained by the convolutional extraction of data. By using several different feature mappings in each convolutional layer, the representation capability of the convolutional network can be improved. Thus, the number of channels can also be extended with convolutional layers.
For the input feature-mapping group X R M × N × D , the output mapping group obtained was Y R M N × P ; a total of P × D two-dimensional convolution kernels was required, recorded as W P , D . For the input solution data, M was the number of characteristic curves, and N was the number of data sampled on the feature curve. The output feature mapping is shown in Equation (3):
Y p = f d = 1 D W p , d X d + b p ,
where f ( ) denotes the activation function [33].
Dilated convolution is a convolution used to increase the output perceptual field without increasing the number of parameters as shown in Figure 5. Dilated convolution increases the size of the convolution kernel in disguise by inserting holes into it. Considering the long rectangular feature of the 4 × 200 input data, the dilated convolution was used in HMID-NET. It increased the size of the convolution kernel, so the 2 layers of 3 × 3 convolution had the effect of approximating 1 layer of 5 × 5 convolution and increased the perceptual field of the output unit. The use of dilated convolution allowed further miniaturization of the convolutional neural network.

3.3. Activation Function

The activation functions are mainly used to cope with the nonlinear variations in the derivation process of convolutional neural networks. A nonlinear activation function was added between the layers of the feature extraction network, as shown in Equation (4).
Y d = f w d Y d + b d
In the HMID-NET, nonlinear activation functions (ReLU and Softmax) were used. ReLU is the commonly used activation function and is characterized by rapid convergence. Softmax is a common and important normalization function that maps the input values to between 0 and 1, representing probabilistic real numbers. These formulae are shown in Equations (5) and (6):
Softmax :   S i = e i j e j
Relu : ReLU ( x ) = max ( x , 0 ) .
In the HMID-NET, the Softmax function was used as the activation function for the output layer of the regression network. The concentration was regressed to 0–1 to reduce the gradient loss in the network training.

3.4. Convergence Layer

The main role of a convergence layer is to perform feature selection and reduce the number of features [33]. It can reduce the number of parameters and is a good solution to the overfitting problem arising from the high input dimensionality of the classifier. In the convergence algorithm, the input feature-mapping group are divided into multiple regions R m , n d [33], which are convergence operations for each zone. HMID-NET used the maximum aggregation layer; for areas in the aggregation layer R m , n d , the maximum active value in this region for all neurons was picked as the representative, as Equation (7):
y m , n d = max x i i R m , n d .
The reason for using Maxpooling is that HMID-NET needed to extract the peak features of the input data. If the average pooling method was used, the number of features extracted would have been significantly reduced, and the quality of the features would have lowered.

3.5. Fully Connected Layer and Output Layer

The fully connected layer was present in the classification and regression networks of the HMID-NET. The fully connected layer is mainly used to integrate features to accomplish the operation of classification or regression prediction. It can map the extracted features from the feature extraction network to a few neurons for prediction.
HMID-NET can perform both classification and regression of the ion concentrations in solutions. The classification and regression networks were placed side by side. In the classification network, the ReLU function was used as the activation function for the fully connected layer. This was because the classification network used cross-entropy loss, which is self-normalizing. In the regression network, the Softmax function was used as the activation function for the output layer. This mapped the concentration predictions between 0 and 1, reducing the gradient loss during training.
The output of the classification network was three neurons. The data in these three neurons corresponded to the probability that the solution contained C d 2 + , Z n 2 + , and C u 2 + , respectively. The labels corresponding to the maximum values of these three data were the predicted solution types.
In the regression network, the output of the three neuron values correspond to the predicted concentrations of C d 2 + , Z n 2 + , and C u 2 + , respectively. However, the concentration prediction requires taking into account the prediction of the classification network. For example, if an ion is predicted to have the class Z n 2 + , the regression network result is [a, b, c]. At this point, the ion species is Z n 2 + , and the concentration is a. The solution does not contain C u 2 + or C d 2 + ; so, results b and c are not considered.
For a fully connected layer network with an input layer of 800 and an output layer of 3, see Table 1 The effect of changing the size of the hidden layer on the accuracy of the network is shown. We consider the relationship between the concentration error, classification accuracy, and the number of parameters, and choose 64 as the number of neurons in the middle hidden layer.

3.6. Parameter Learning

Parameter learning is a way to adjust the parameters in a convolutional neural network to ensure the results are closer to reality. Parameter learning is often performed using error backpropagation. That is, the parameters are adjusted inversely by the error generated from the derived results and the real label. The following shows the derivation of a single parameter update.
Generally, with layer l as a convolutional layer, the input features of layer l 1 are mapped as X ( l 1 ) R M × N × D [33], and the net input of the feature mapping at layer l is obtained by convolution Z ( l ) R M × N × P . The activation value is a l , and the p (1 ≤ pP) feature of the l layer maps the net input as shown in Equation (8):
Z ( l , p ) = d = 1 D W ( l , p , d ) X ( l 1 , d ) + b ( l , p ) ,
where W ( l , p , d ) is the convolution kernel, b ( l , p ) is the bias [33], and there are P × D convolution kernels and P biases in layer l. The chain rule can be used to calculate their gradients separately, and we let the loss function be L, whose partial derivatives with respect to the convolution kernel W ( l , p , d ) in layer l are:
L W ( l , p , d ) = L Z ( l , p ) X ( l 1 , d ) .
In HMID-NET, the regression loss is the MSE loss, and the classification loss is the cross-entropy loss, as in Equations (10) and (11):
MSE = 1 n i = 1 m w i y i y ^ i 2
H ( p , q ) = i = 1 n p x i log q x i .
Similarly, the partial derivative of the bias p of the layer l b ( l , p ) is shown in Equation (12):
L b ( l , p ) = i , j δ ( l , p ) i , j ,
where δ ( l , p ) = L Z ( l , p ) is the derivative of the loss function with respect to the feature mapping p of layer l via input Z ( l , p ) .
The parameter update of the convolution kernel with bias by the derivatives to obtain a single update is as in Equations (13) and (14):
W ( l ) = W ( l ) α p = 1 P δ ( l , p ) × r o t 180 a ( l 1 , p )
b ( l ) = b ( l ) α p = 1 P i , j b ( l , p ) i , j ,
where α is the learning rate.
Figure 6 shows a diagram of forward and error backward propagation.
For convolutional neural networks, a single time of parameter updating is apparently not enough, and HMID-NET uses stochastic gradient descent (SGD) for parameter learning. The stochastic gradient descent process is as follows:
  • Randomly initialize parameters W, b;
  • Reorder the samples in the training set;
  • Take the data of batch sizes for parameter learning and updating, and obtain the validation set error rate;
  • Repeat steps 2 and 3 until the validation set error rate no longer decreases;
  • Obtain the global optimum W, b.
Figure 7 shows a diagram of SGD.
For batches of data, the size of the sample batch and the learning rate affect the training results. When the sample batch is twice the original size, to ensure that the weights are updated equally after the same sample, the learning rate should be increased to a multiple of the original size according to the linear scaling rule. After the experiments, the learning rate was set to 0.01 and the batch size to 16.

3.7. Dataset Acquisition

In this study, the HMI dataset was built using C d 2 + , Z n 2 + , and C u 2 + as examples.
Data acquisition: Tests were carried out using square-wave voltammetry. The square-wave voltammetry parameters were set to (Init = −0.7 V, Final = 0.3 V, Increase = 0.005 V, Amplitude = 0.025 V, and Frequency = 25 Hz). A single sampling yielded 400 current data units, and to prevent a high chance of errors in the data, each input data unit consisted of 2 separate test results. We extracted a set of 200 data units from each of the odd columns and a set of 200 data units from each of the even columns, for a total of 4 sets of 2 measurements. These 4 groups were arranged in order to form a 4 × 200 data cell as shown in Equations (15) and (16):
A 1 = ( a 1 , a 2 , , a 400 ) ,   A 2 = ( a 1 , a 2 , , a 400 )
A = a 1 , a 3 , , a 399 a 2 , a 4 , , a 400 a 1 , a 3 , , a 399 a 2 , a 4 , , a 400 4 × 200
Dataset creation: Data were collected for 12 solutions of cadmium chloride, zinc chloride, and copper chloride with concentration gradients of 0.2 g/L, 0.5 g/L, 1 g/L, and 2 g/L. One data unit was obtained from every two samples. We set each solution to be sampled 50 times, making up 25 data units, with a total of 300 data units as the original dataset.
Data augmentation: Firstly, the data obtained from the acquisition were of the order of magnitude 10 3 A, expanding the data 1000 times to reduced gradient loss. These 300 data units were extended by adding 1% white noise to obtain 1200 data units. These data were used as the input dataset for the neural network. This expansion scheme did not affect the important peak and height features of the original electrochemical measurements but broadened the size of the dataset. To establish the accuracy of the model when training, the data needed were classified into two sets: a training set (70%) as well as a testing set (30%).
The results of a particular data measurement for each concentration were taken and combined into a single data cell, which was produced as a grayscale image. The grayscale of the image from black to white represents the data from small to large. As can be seen in Figure 8, each grayscale image has an area that is approximately white. The position of this region corresponds to the position of the peak in the original data, and the degree of brightness of the region corresponds to the height of the peak. In a conventional square-wave polarimetric analysis, the main features extracted are the half-wave potential as well as the peak height [8]. The peak potential is related to the ion species, and the peak height is related to the ion concentration. From a visual point of view, the following dataset in Figure 8a provides a visual representation of the features to be extracted. Figure 8b shows the visual representation of the data features extracted from Figure 8a.

3.8. Label Settings

Each data unit is mapped with two labels, one for classification denoted as label 1 and the other for concentration prediction denoted as label 2. In the structure of the convolutional neural network shown in Figure 4, the classification and regression networks share the same feature extraction network. If the values of label 1 and label 2 differ significantly, this could lead to a loss of gradient when the error is backpropagated. Once the gradient is lost, the prediction cannot be accurately derived. So the concentration label, label 2, needs to be normalized. For example, for the three categories of Z n 2 + , C u 2 + , and C d 2 + corresponding to 0.2 g/L, we set label 1 as [1, 0, 0], [0, 1, 0], and [0, 0, 1], respectively. The labels for the regression network are [0.1, 0, 0], [0, 0.1, 0], and [0, 0, 0.1], respectively.

4. Results and Discussion

4.1. Ion Type Detection

A total of 12 solutions of cadmium chloride, zinc chloride, and copper chloride with concentration gradients of 0.2 g/L, 0.5 g/L, 1 g/L, and 2 g/L were tested. The twelve solutions were in the same electrochemical system as the standard solution. The results of the classification are shown in Figure 9.
Figure 9a–c show the classification probabilities for C d 2 + , C u 2 + , and Z n 2 + at the four concentrations, respectively. The probability values in the graph are the predicted ion types output by the classification network. As seen from Figure 9, the method problematized in this paper made accurate predictions for all 12 test solutions, and correct classification results were obtained in all cases.

4.2. Ion Concentration Detections

Twelve different classes or concentrations of test solutions were used to test the detection of ion concentrations. Each solution had 7 different samples, leading to a total of 84 samples to be tested. The graph below shows the predicted concentrations of these 84 samples by HMID-NET compared to the true concentrations.
As seen from Figure 10, the majority of the predicted concentrations were concentrated around the true concentration, with an average relative error of 8.85%.
The average relative error was 10.36% for Z n 2 + , 7.57% for C u 2 + , and 8.62% for C d 2 + , using the ionic species as the analytical criterion.
The average relative error was 12.48% for the 0.2 g/L solution, 9.63% for the 0.5 g/L solution, 7.62% for the 1 g/L solution, and 5.68% for the 2 g/L solution, using the ionic concentration as the analytical criterion. It can be seen that the relative error of prediction was greater for the lower-concentration solutions.
Finally, we comprehensively compared the accuracy of the HMI detection method proposed in this paper with other methods, and the results are shown in Table 2.
As shown in column 2 of the table, the accuracy of the method proposed in this paper is 99.99%, the same as in the literature [22] and higher than all the other methods, in terms of the classification prediction of ion types. As shown in column 3 of the table, the relative error of this paper for the ion concentration detection was 8.85%, which is better than the PCA method used in the literature [12].
Conventional heavy-metal detection algorithms require manual analysis of the curves to derive HMI species and concentrations, and thus cannot perform automated detection. Recently proposed data-processing methods can automate electrochemical analysis, but they are unable to simultaneously detect the species and concentration of the measured substance. The automated, simultaneous qualitative and quantitative detection scheme proposed in this paper extends and elaborates on these two methods.

5. Conclusions

We presented a CNN-based method for monitoring heavy-metal ions that can detect the type and concentration of HMIs within two minutes. The device can be used to predict the species and concentrations of a wide range of trained metals. The datasets used in HMID-NET were all experimentally derived. The main advantage of our algorithm is the use of a CNN algorithm, which avoids each calibration, shortens the detection time, improves the accuracy, and increases the reliability of the classification and prediction. The paper presented the first concept for the simultaneous type and concentration prediction of ions using CNN structures. The concept proposed in the paper can be used in a wide range of electrochemical detection fields. A detection algorithm that uses machine learning offers the possibility of the simultaneous classification of multiple ions as well as concentration prediction.
The results, based on the three-electrode electrochemical system, demonstrated the specificity of the test results for different concentrations of solutions. The results were reproducible for the same solution at the same concentration. The sampled data underwent data extension and preprocessing operations to create a dataset containing 1200 data samples. The proposed HMID-NET algorithm was used for class determination and concentration estimation of heavy-metal cations in water. A final classification accuracy of 99.99% and an average relative error of 8.85% in terms of the concentration were obtained.
The concept of applying convolutional neural networks to electrochemistry is also applicable to other analytical systems. However, the disadvantage of the data-driven approach is the need to reproduce the conditions of the test phase in the training phase. There is a lack of contemporary datasets for heavy-metal detection. The shortage of experimental data prevents the current application of our method to mixed solutions of heavy-metal ions. In future work, we will apply HMID-NET to the detection of mixed solutions and investigate how to obtain the species and concentrations of all the ions contained in the solution simultaneously.

Author Contributions

Conceptualization, J.L., Y.Z. and J.Z.; methodology, J.L., Y.Z. and J.Z.; software, F.C., J.Z., R.Z., Z.Z. and X.Y.; validation, F.C., R.Z., Z.J. and F.T.; formal analysis, J.Z. and F.C.; investigation, J.Z. and F.C.; resources, J.L.; data curation, F.C.; writing—original draft preparation, J.Z. and F.C.; writing—review and editing, J.L. and Y.Z.; visualization, F.C., R.Z., Z.Z. and X.Y,; supervision, J.L. and Y.Z.; project administration, Y.Z.; funding acquisition, Y.Z. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by the Key Research and Development Project of the Hainan Province, grant number ZDYF2019024, and the Hainan Provincial Natural Science Foundation of China, grant number 620QN236.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Informed consent was obtained from all subjects involved in the study.

Data Availability Statement

The datasets generated during and/or analyzed during the current study are available from the corresponding authors upon reasonable request.

Conflicts of Interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

References

  1. Gumpu, M.B.; Sethuraman, S.; Krishnan, U.M.; Rayappan, J.B.B. A review on detection of heavy metal ions in water—An electrochemical approach. Sens. Actuators B Chem. 2015, 213, 515–533. [Google Scholar] [CrossRef]
  2. Metrohm Autolab B.V. Basic Overview of the Working Principle of a Potentiostat/Galvanostat (PGSTAT)–Electrochemical Cell Setup; Autolab Application Note EC08; Metrohm Autolab B.V.: Singapore, 2011; pp. 1–3. [Google Scholar]
  3. Liao, J.; Song, Y.; Wang, R.; Zeng, Y.; Si, H.; Ge, C.; Lin, S. A synergistic promotion strategy for selective trapping and sensing of lead (II) by oxygen-vacancy and surface modulation of MnO2 nanoflowers. Sens. Actuators B Chem. 2021, 345, 130384. [Google Scholar] [CrossRef]
  4. Wang, X.; Gartia, M.R.; Jiang, J.; Chang, T.W.; Qian, J.; Liu, Y.; Liu, X.; Liu, G.L. Audio jack based miniaturized mobile phone electrochemical sensing platform. Sens. Actuators B Chem. 2015, 209, 677–685. [Google Scholar] [CrossRef]
  5. Ainla, A.; Mousavi, M.P.; Tsaloglou, M.N.; Redston, J.; Bell, J.G.; Fernandez-Abedul, M.T.; Whitesides, G.M. Open-source potentiostat for wireless electrochemical detection with smartphones. Anal. Chem. 2018, 90, 6240–6246. [Google Scholar] [CrossRef] [Green Version]
  6. Nemiroski, A.; Christodouleas, D.C.; Hennek, J.W.; Kumar, A.A.; Maxwell, E.J.; Fernández-Abedul, M.T.; Whitesides, G.M. Universal mobile electrochemical detector designed for use in resource-limited applications. Proc. Natl. Acad. Sci. USA 2014, 111, 11984–11989. [Google Scholar] [CrossRef] [Green Version]
  7. Ji, D.; Liu, L.; Li, S.; Chen, C.; Lu, Y.; Wu, J.; Liu, Q. Smartphone-based cyclic voltammetry system with graphene modified screen printed electrodes for glucose detection. Biosens. Bioelectron. 2017, 98, 449–456. [Google Scholar] [CrossRef]
  8. Lu, M.; Deng, Y.; Luo, Y.; Lv, J.; Li, T.; Xu, J.; Chen, S.W.; Wang, J. Graphene aerogel–metal–organic framework-based electrochemical method for simultaneous detection of multiple heavy-metal ions. Anal. Chem. 2018, 91, 888–895. [Google Scholar] [CrossRef]
  9. Liu, Y.; Deng, Y.; Dong, H.; Liu, K.; He, N. Progress on sensors based on nanomaterials for rapid detection of heavy metal ions. Sci. China Chem. 2017, 60, 329–337. [Google Scholar] [CrossRef]
  10. Luther, G.W., III; Giblin, A.E.; Varsolona, R. Polarographic analysis of sulfur species in marine porewaters. Limnol. Oceanogr. 1985, 30, 727–736. [Google Scholar] [CrossRef]
  11. Deng, L.; Yu, D. Deep learning: Methods and applications. Found. Trends® Signal Process. 2014, 7, 197–387. [Google Scholar] [CrossRef] [Green Version]
  12. Gabrieli, G.; Hu, R.; Matsumoto, K.; Temiz, Y.; Bissig, S.; Cox, A.; Heller, R.; López, A.; Barroso, J.; Kaneda, K.; et al. Combining an integrated sensor array with machine learning for the simultaneous quantification of multiple cations in aqueous mixtures. Anal. Chem. 2021, 93, 16853–16861. [Google Scholar] [CrossRef]
  13. Lavrentev, F.V.; Rumyantsev, I.S.; Ivanov, A.S.; Shilovskikh, V.V.; Orlova, O.Y.; Nikolaev, K.G.; Andreeva, D.V.; Skorb, E.V. Soft hydrogel actuator for fast machine-learning-assisted bacteria detection. ACS Appl. Mater. Interfaces 2022, 14, 7321–7328. [Google Scholar] [CrossRef]
  14. Zou, J.; Han, Y.; So, S.S. Overview of artificial neural networks. In Artificial Neural Networks: Methods and Applications; Humana: Totowa, NJ, USA, 2009; pp. 14–22. [Google Scholar]
  15. Paliwal, M.; Kumar, U.A. Neural networks and statistical techniques: A review of applications. Expert Syst. Appl. 2009, 36, 2–17. [Google Scholar] [CrossRef]
  16. El-Sawy, A.; El-Bakry, H.; Loey, M. CNN for handwritten arabic digits recognition based on LeNet-5. In Proceedings of the International Conference on Advanced Intelligent Systems and Informatics 2016, Cairo, Egypt, 24–26 November 2016; Springer: Cham, Switzerland, 2016; pp. 566–575. [Google Scholar]
  17. Almabdy, S.; Elrefaei, L. Deep convolutional neural network-based approaches for face recognition. Appl. Sci. 2019, 9, 4397. [Google Scholar] [CrossRef] [Green Version]
  18. Lu, S.; Lu, Z.; Zhang, Y.D. Pathological brain detection based on AlexNet and transfer learning. J. Comput. Sci. 2019, 30, 41–47. [Google Scholar] [CrossRef]
  19. Wang, S.H.; Xie, S.; Chen, X.; Guttery, D.S.; Tang, C.; Sun, J.; Zhang, Y.D. Alcoholism identification based on an AlexNet transfer learning model. Front. Psychiatry 2019, 10, 205. [Google Scholar] [CrossRef] [Green Version]
  20. Shanthi, T.; Sabeenian, R. Modified Alexnet architecture for classification of diabetic retinopathy images. Comput. Electr. Eng. 2019, 76, 56–64. [Google Scholar] [CrossRef]
  21. Zheng, W.; Shi, Y.; Xia, X.; Ying, Y.; Men, H. A data processing method for electronic tongue based on computational model of taste pathways and convolutional neural network. Measurement 2022, 205, 112150. [Google Scholar] [CrossRef]
  22. Zhong, Y.H.; Zhang, S.; He, R.; Zhang, J.; Zhou, Z.; Cheng, X.; Huang, G.; Zhang, J. A convolutional neural network based auto features extraction method for tea classification with electronic tongue. Appl. Sci. 2019, 9, 2518. [Google Scholar] [CrossRef] [Green Version]
  23. Wei, G.; Li, G.; Zhao, J.; He, A. Development of a LeNet-5 gas identification CNN structure for electronic noses. Sensors 2019, 19, 217. [Google Scholar] [CrossRef] [Green Version]
  24. Han, L.; Yu, C.; Xiao, K.; Zhao, X. A new method of mixed gas identification based on a convolutional neural network for time series classification. Sensors 2019, 19, 1960. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  25. Guo, Z.; Yang, C.; Wang, D.; Liu, H. A Novel Deep Learning Model Integrating CNN and GRU to Predict Particulate Matter Concentrations. Process. Saf. Environ. Prot. 2023. [Google Scholar] [CrossRef]
  26. Dean, S.N.; Shriver-Lake, L.C.; Stenger, D.A.; Erickson, J.S.; Golden, J.P.; Trammell, S.A. Machine learning techniques for chemical identification using cyclic square wave voltammetry. Sensors 2019, 19, 2392. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  27. Cass, S. Nvidia makes it easy to embed AI: The Jetson nano packs a lot of machine-learning power into DIY projects-[Hands on]. IEEE Spectr. 2020, 57, 14–16. [Google Scholar] [CrossRef]
  28. Rehman, S.U.; Razzaq, M.R.; Hussian, M.H. Training of SSD (single shot detector) for facial detection using Nvidia jetson nano. arXiv 2021, arXiv:2105.13906. [Google Scholar]
  29. Ji, D.; Xu, N.; Liu, Z.; Shi, Z.; Low, S.S.; Liu, J.; Cheng, C.; Zhu, J.; Zhang, T.; Xu, H.; et al. Smartphone-based differential pulse amperometry system for real-time monitoring of levodopa with carbon nanotubes and gold nanoparticles modified screen-printing electrodes. Biosens. Bioelectron. 2019, 129, 216–223. [Google Scholar] [CrossRef]
  30. Li, M.; Li, Y.T.; Li, D.W.; Long, Y.T. Recent developments and applications of screen-printed electrodes in environmental assays—A review. Anal. Chim. Acta 2012, 734, 31–44. [Google Scholar] [CrossRef]
  31. Osteryoung, J.; O’Dea, J.J. Square-wave voltammetry. Electroanal. Chem. 1986, 14, 209–308. [Google Scholar]
  32. Liechti, C. PySerial Documentation, Version 2.6, Diciembre 2011. 2016.
  33. Xipeng, Q. Neural Networks and Deep Learning; Machine Industry Press: Beijing, China, 2020. [Google Scholar]
  34. Ye, J.J.; Lin, C.H.; Huang, X.J. Analyzing the anodic stripping square wave voltammetry of heavy metal ions via machine learning: Information beyond a single voltammetric peak. J. Electroanal. Chem. 2020, 872, 113934. [Google Scholar] [CrossRef]
Figure 1. Block diagram of the electrochemical hardware system.
Figure 1. Block diagram of the electrochemical hardware system.
Applsci 13 04520 g001
Figure 2. Three-electrode potentiostat and SPE sensor.
Figure 2. Three-electrode potentiostat and SPE sensor.
Applsci 13 04520 g002
Figure 3. (a) The results of the multiple replicate tests of a 0.5 g/L solution of zinc chloride dissolved in a 0.1 mol/L potassium chloride substrate. Data 1–data 5 are the data curves for the different measurement times; (b) the SWV data for the Z n 2 + solution at different concentrations; (c) the SWV data for the C u 2 + solution at different concentrations; (d) the SWV data for the C d 2 + solution at different concentrations.
Figure 3. (a) The results of the multiple replicate tests of a 0.5 g/L solution of zinc chloride dissolved in a 0.1 mol/L potassium chloride substrate. Data 1–data 5 are the data curves for the different measurement times; (b) the SWV data for the Z n 2 + solution at different concentrations; (c) the SWV data for the C u 2 + solution at different concentrations; (d) the SWV data for the C d 2 + solution at different concentrations.
Applsci 13 04520 g003
Figure 4. The HMID-NET structure. The rectangles represent the convolutional layer plus the activation function, the yellow represents the convolutional layer, the purple represents the pooling layer, and the circles represent the neurons.
Figure 4. The HMID-NET structure. The rectangles represent the convolutional layer plus the activation function, the yellow represents the convolutional layer, the purple represents the pooling layer, and the circles represent the neurons.
Applsci 13 04520 g004
Figure 5. Dilated convolution.
Figure 5. Dilated convolution.
Applsci 13 04520 g005
Figure 6. Forward propagation and error backpropagation.
Figure 6. Forward propagation and error backpropagation.
Applsci 13 04520 g006
Figure 7. Schematic diagram of stochastic gradient descent.
Figure 7. Schematic diagram of stochastic gradient descent.
Applsci 13 04520 g007
Figure 8. (a) Patterns of the HMI data matrices with size 4 × 200. (b) Features extracted from the backbone.
Figure 8. (a) Patterns of the HMI data matrices with size 4 × 200. (b) Features extracted from the backbone.
Applsci 13 04520 g008
Figure 9. The results of the classification with HMID-NET. (ac) are the probabilities of the classification of C d 2 + , C u 2 + , and Z n 2 + at the four concentrations in order, where category 1 is C d 2 + , category 2 is C u 2 + , and category 3 is Z n 2 + . The values in the bar chart refer to the magnitude of the probability that the sample belongs to that category.
Figure 9. The results of the classification with HMID-NET. (ac) are the probabilities of the classification of C d 2 + , C u 2 + , and Z n 2 + at the four concentrations in order, where category 1 is C d 2 + , category 2 is C u 2 + , and category 3 is Z n 2 + . The values in the bar chart refer to the magnitude of the probability that the sample belongs to that category.
Applsci 13 04520 g009
Figure 10. The set of multiple concentration predictions for all solutions. The horizontal axis is the calibrated concentration, and the vertical axis is the predicted concentration. The dashed line represents an error of more than ±20% or ±200 mg/L.
Figure 10. The set of multiple concentration predictions for all solutions. The horizontal axis is the calibrated concentration, and the vertical axis is the predicted concentration. The dashed line represents an error of more than ±20% or ±200 mg/L.
Applsci 13 04520 g010
Table 1. CNN algorithm classification accuracy and concentration prediction accuracy under different hidden layer sizes. The value in the ‘number of parameters’ column represents the number of parameters in the fully connected layer.
Table 1. CNN algorithm classification accuracy and concentration prediction accuracy under different hidden layer sizes. The value in the ‘number of parameters’ column represents the number of parameters in the fully connected layer.
Hidden LayersConcentration Error
(MRE)
Classification
Accuracy
Number of
Parameters
1286.28%99.99%102,915
808.02%99.99%64,323
728.59%99.99%57,891
648.85%99.99%51,459
569.82%99.99%45,027
4812.00%99.32%38,595
3216.24%97.13%25,731
1619.20%94.00%12,867
NULL102.50%34.00%2403
Table 2. Comparison of the detection accuracy of multiple data-processing methods.
Table 2. Comparison of the detection accuracy of multiple data-processing methods.
MethodClassification AccuracyConcentration Error (MRE)
MLP [13]94%—–
LENET-5 [23]98.67%—–
Literature [24]96.87%—–
Literature [22]99.99%—–
PCA [34]90%—–
PCA [12]—–16%
HMID-NET (this work)99.99%8.85%
—– Data not available.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Zhang, J.; Chen, F.; Zou, R.; Liao, J.; Zhang, Y.; Zhu, Z.; Yan, X.; Jiang, Z.; Tan, F. A CNN-Based Method for Heavy-Metal Ion Detection. Appl. Sci. 2023, 13, 4520. https://doi.org/10.3390/app13074520

AMA Style

Zhang J, Chen F, Zou R, Liao J, Zhang Y, Zhu Z, Yan X, Jiang Z, Tan F. A CNN-Based Method for Heavy-Metal Ion Detection. Applied Sciences. 2023; 13(7):4520. https://doi.org/10.3390/app13074520

Chicago/Turabian Style

Zhang, Jian, Feng Chen, Ruiyu Zou, Jianjun Liao, Yonghui Zhang, Zeyu Zhu, Xinyue Yan, Zhiwen Jiang, and Fangzhou Tan. 2023. "A CNN-Based Method for Heavy-Metal Ion Detection" Applied Sciences 13, no. 7: 4520. https://doi.org/10.3390/app13074520

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop