#### Abstract

According to the waste type identification requirement in waste classification, a waste type identification method based on a bird flock neural network (BFNN) was proposed. The problem of obtaining the feature dataset of waste images was considered, and color histogram and texture feature extraction techniques were used. The local optimum problem of a typical backpropagation neural network (BPNN) was considered, and a bird flock optimization (BFO) algorithm was proposed. The accuracy problem of the typical BPNN was considered, and a new online weight adjustment method of neurons was proposed. The number of hidden layer neurons (nodes) of the typical BPNN was considered, and an online adjustment method was proposed. The experimental results show that the recyclables (paper, plastic, glass, and cloth) and nonrecyclables can effectively be identified by the waste type identification method based on the BFNN, and the recognition accuracy is 81% which meets actual needs.

#### 1. Introduction

“Shanghai Household Waste Management Regulation” had been implemented since July 2019. The domestic waste was divided into recyclables (including paper, plastic, glass, metal, and cloth) and nonrecyclables (including hazardous, wet, and dry waste) based on the regulation. Since waste classification is a heavy work, the intellectualization of waste classification has become an important topic.

In recent years, the study on neural network (NN) and image processing has been a research hotspot, but there are limited studies on waste classification using image processing and NN. Laser-induced breakdown spectrometry together with discriminant function analysis was used for the identification and classification of five groups of polymers in the electronics industry [1]. A thermal imaging-based system for classifying useful recyclables from simulated municipal solid waste (MSW) sample was reported, and the system could be used in recycling plants for processing MSW in developing countries [2]. An intelligent waste material classification system was proposed, which was developed by using the 50-layer residual net pretrained convolutional neural network (CNN) model [3]. Two reinforcement learning-based metalearning approaches, MetaQNN and efficient neural architecture search, were investigated and compared to find suitable CNN architectures for multitarget concrete defect classification with the COncrete DEfect Bridge IMage dataset [4].

In recent years, the study on NN and related optimization algorithm has been a research hotspot. The differential evolution- (DE-) based metaheuristic optimization algorithm was used for optimizing the search space of artificial neural network (ANN), and the effect of ANN-DE-based model predictions was better than the traditional quadratic model predictions [5]. Jicama peroxidase was immobilized on the surface modified buckypaper/polyvinyl alcohol membrane and employed for the application of methylene blue dye removal from aqueous solution, and the parameters of the isotherm and kinetic models were estimated using ant colony optimization (ACO) [6]. The GA-ANN method was used to select the most important features affecting soil erodibility to wind, and minimization of the cost function was better than comparison algorithm [7]. A new hybrid approach which combined the recurrent fuzzy neural network (RFNN) with particle swarm optimization (PSO) algorithm to simulate the ﬂyrock distance induced by mine blasting [8]. ACO algorithm was employed with a modified heuristic value to obtain sparsely placed nodes in the solution, and the improved ACO was used for reducing the cost of wireless sensor networks and sensor nodes [9]. A new adaptive version of particle swarm optimizer was used for improving the robustness and the stability of the controller according to the climatic changes and overcoming the problem of local optimum [10]. A NN was used for designing sensors, the parameters were modeled by ANN and optimized by genetic algorithm (GA) within the practical levels, and the optimization process led to find the most accurate optimal conditions possible [11].

It is well known that CNN can directly extract image features, which is an important algorithm especially suitable for image classification [12–14]. However, CNN requires a long training time. Even if a GPU is used for calculation, some training processes of CNNs will take several hours or even days (it takes only a few seconds for the proposed algorithm in this paper). In this paper, an algorithm was proposed for solving the problem of waste identification and making theoretical preparation for manufacturing trash can which can automatically identify and classify waste. Because the computing power of hardware of trash can is usually limited, the CNN is not used.

NN is an effective method for classification. Trained NN can automatically identify the type of waste and sort the waste to a suitable location by hardware so as to save labor cost. Backpropagation neural network (BPNN) is a classic neural network; at present, BPNN has been applied in many fields [15–17]. There are problems of local optimum [18], accuracy [19], and hidden layer neuron (nodes) adjustment [20] in a typical BPNN and other improved algorithms. According to the above problems, a bird flock neural network (BFNN) was proposed, and then a waste type identification method based on the BFNN was proposed.

#### 2. Dataset Acquisition

The image features of waste were extracted to generate dataset, and the dataset was used as the input of NN. The type of waste was manually determined and coded, and the encoded data were used as the output of NN. The obtained dataset was used for training a NN. After training, the NN could identify the type of waste.

##### 2.1. Obtaining Input Data

The images of some waste are shown in Figure 1.

The image features in Figure 1 were extracted to generate dataset, and the dataset was used as the input data of NN.

###### 2.1.1. Extracting Feature Information of Color Histogram of Image

The color histogram reflects the statistical characteristics of the color distribution of images, and it is suitable for describing images which are difficult to segment and do not need to consider the position of the object. A camera was used to capture the image within a fixed square, and the background was white. The captured result was an image with fixed size (200 × 200 pixel). Because the number of pixels in the image was fixed, the number of the pixels of certain color could be used as characteristic vector.

The tricolor histogram of Figure 1(d) is shown in Figure 2.

In Figure 2, the abscissa is the pixel level, and the ordinate is the number of pixels.

The number of 0–50 colored pixels of the red component histogram was captured as feature vector 1. The number of 51–100 colored pixels of the red component histogram was captured as feature vector 2. The number of 101–150 colored pixels of the red component histogram was captured as feature vector 3. The number of 151–200 colored pixels of the red component histogram was captured as feature vector 4. The number of 201–255 colored pixels of the red component histogram was captured as feature vector 5.

The extraction method of the feature vectors of green component and blue component was the same as the red component. A total of 15 feature vectors were generated.

###### 2.1.2. Extracting Feature Information of Texture of Image

The surface properties of images and corresponding objects are described by texture features. Three texture feature vectors including mean, contrast, and entropy were used in this paper.

Let be a point in an image, and the calculation formula of gray difference between the point and another point is as follows:

The calculation formulas of mean, contrast, and entropy are as follows [21]:where is the average value, is the number of gray level, is the gray level number, is the probability of , is the contrast value, and is the entropy value.

The input of NN includes 15 color histogram feature vectors and 3 texture feature vectors and a total of 18 feature vectors.

##### 2.2. Determining Output Data

Recyclables were divided into 5 kinds: paper, plastic, glass, metal, and cloth. Metals could be directly identified by sensors, so there was no need to be identified by image features. Therefore, the waste type identification method based on the BFNN was used to identify some recyclables (paper, plastic, glass, and cloth) and nonrecyclables by image features. The corresponding output of NN was in the order of 00001, 00010, 00100, 01000, and 10000.

#### 3. Differences between BFNN and Typical BPNN

The structure of a BFNN is shown in Figure 3.

There are some characteristics of the BFNN in Figure 3. The network consists of at least three layers. The neurons in each layer are fully connected to the neurons in the next layer, and there is no connection between the neurons in the same layer. Because the BFNN is trained by offline algorithm and online algorithm, the accuracy of the algorithm can be guaranteed and the data can be added online. Because the BFNN uses online adjustment method, the number of the hidden layer neurons can be increased or decreased online.

The main differences between BFNN and typical BPNN are as follows.

##### 3.1. A Bird Flock Algorithm

The bird flock optimization (BFO) algorithm is an intelligent optimization algorithm proposed in this paper, which will be compared with PSO [22, 23].

The differences between BFO and PSO are as follows:(i)*PSO*. Each individual emulates its most successful neighbor by updating its velocity and position to follow the most successful position of neighbors for global search [24].(ii)*BFO*. The BFO is proposed by imitating the process of bird flock seeking food.

Biological foundation: the process of bird flock seeking food.

The purpose of this operation: the BFO has the function of global optimum (preventing local optimum), and it is used to optimize the weights of the NN.

##### 3.2. A New Weight Adjustment Method of Neurons

The differences between the weight adjustment method of BFNN and typical BPNN are as follows:(i)*Typical BPNN*. The weight adjustment formulas of the typical BPNN can be found in literature [25, 26].(ii)*BFNN*. A new adjustment method is used to update the weights of neurons.

Biological foundation: the medium between two neurons changes when the neurons are continuously activated.

The purpose of this operation: the new weight adjustment method of the BFNN can add data one by one for online learning, and it has better capabilities of local optimum.

##### 3.3. An Online Adjustment Method of the Number of Hidden Layer Neurons

The differences between the adjustment method of the number of the hidden layer of BFNN and typical BPNN are as follows:(i)*Typical BPNN*. The typical BPNN obtains the number of the hidden layer neurons by empirical formula and repeated tests. Once the number of the hidden layer neurons is found, it cannot be increased or decreased.(ii)*BFNN*. The BFNN obtains the number of the hidden layer neurons by empirical formula, and then the number of neurons is adjusted by the online adjustment method.

Biological foundation: the number of biological neurons is not fixed and can be increased or decreased.

The purpose of this operation: the BFNN can increase or decrease the number of the hidden layer neurons online after the adjustment method is used.

#### 4. Principle of BFNN

##### 4.1. Feedforward Calculation

The process of feedforward calculation includes three parts: determining structure, preprocessing data, and calculating output values.

###### 4.1.1. Determining Structure

The number of input and output layer neurons was manually determined on the basis of dataset information.

The calculation formulas of the number of initial hidden layer neurons are as follows:where is the number of hidden layer neurons, is the number of input layer neurons, and is the number of output layer neurons.

###### 4.1.2. Preprocessing Data

The dataset is normalized, and the calculation formula is as follows:where is the original data, is the normalized data, is the maximum value of is the minimum value of .

The normalized dataset was divided into four parts: training input, training output, test input, and test output.

###### 4.1.3. Calculating Output Values

Let be the NN input, namely, , where is the input layer neuron number. For the convenience of writing, the sample number is omitted. The input data pass through the hidden layer to the output layer. The input of hidden layer is , where is the weight between input layer and hidden layer. The output of hidden layer is , where is excitation function and is the hidden layer neuron number. The excitation function is a hyperbolic tangent function, and the calculation formula is . The input of output layer is , where is the hidden layer neuron number and is the output layer neuron number. The output layer excitation function is a linear excitation function, and the output of output layer neurons is .

##### 4.2. BFO

BFO is used to obtain a set of optimal weights of NN.

After the feedforward calculation, we need to determine if there is a known dataset. If yes, the BFO is used to train the NN, and the known data are mapped to the NN; if no, the algorithm flow jumps to Section 4.3.

The algorithm flow of the BFO is shown in Figure 4.

In BFO, a bird flock is a group of individuals. A bird is an individual, and it is a set of weights of NN in this paper. The predation effect is fitness. Flight times are the iteration times of BFO. Surrounding birds are the individuals within a certain distance. The overall predation effect of bird flock is average fitness.

The principle of BFO is as follows.

###### 4.2.1. Generating the Number of Initial Birds

The accuracy and running speed of BFO will be considered by setting the appropriate number of birds in an initial flock. Increasing the number of birds will improve accuracy and increase time consumption of BFO and vice versa. BFO can evaluate dataset and automatically generate the appropriate number of birds based on dataset information. The algorithm for generating the number of the birds of initial flock is as follows.

Sort the value of each input vector from small to large, normalize them, and keep two decimal places. Add each different number to the abscissa and count the number of abscissa value of dataset into the ordinate. Remove ordinate points which are 0, connect adjacent points, and detect the peaks which are greater than the threshold in the graph, and the number of the peaks is denoted by . Set the threshold ; if , then ; if , then . Calculate based on (10).where is the number of classes of dataset and is the number of classes on the *i*-th input vector of dataset.

The calculation formula of the initial bird flock is as follows:where ininum is an integer between 10 and 200, and it is an integer multiple of 10.

###### 4.2.2. Bird Flock Search Strategy

The bird flock search strategy is as follows:(i)The birds which have better predation effect stay, and the birds which have poorer predation effect fly away. The birds which fly away do not prey near the staying birds, so as to ensure the predation effect of the whole flock.

Set appropriate fitness function according to project. If it is a classification project, the number of correct classification can be used as fitness. If it is a prediction project, the following formula can be used to calculate fitness:where is the fitness of individual, is the actual value of output, and is the predicted value of output.

The average fitness, , is calculated after running the algorithm. The individuals which are below will be reset randomly, and the new individuals are not in a range of the generated individuals. After the NN is fully trained, it can be known that most of the weights of the NN are distributed between 0.1–1. The value of weights are rounded, and they are kept one decimal place. After the above operation, the new individual and the old individual cannot be the same. If the two are the same, the new individual will be reset randomly. The above operation ensures that the new individual does not appear within a certain range of the old individual. This operation needs to set the upper limit of reset times (2 in this paper) to prevent an endless loop.

The significance of strategy:(i)Ensure the individuals have the uniform distribution positions approximately in the dimensional space, and ensure each individual has a good initial fitness. This strategy can improve the global search performance and prevent the local optimum of NN.(ii)In a small area, the bird which has the best predation effect (called guide bird) will attract surrounding birds. The guide birds will attract nearby birds to search a smaller area together. The individuals are sorted from high to low based on the fitness. The first 20% individuals are taken as the guide individuals to attract their surrounding individuals.(iii)The best guide bird (namely, the global best individual) will attract the surrounding ordinary birds and other guide birds. A guide bird will only attract ordinary birds within a certain range. The guide birds do not attract each other (except the best guide bird). The distance between two individuals is calculated as follows: where is the distance between two individuals, is an element (weight) of the individual, is an element (weight) of another individual, and is an element (weight) number.(iv)An ordinary bird will only be attracted by one guide bird. The distance between the attracted individual and the guide individual is calculated according to (8). The attracted individual can only be attracted by the closest guide individual. The significance of strategies (ii), (iii), and (iv): the guide bird strategy can improve the local search accuracy of the algorithm. The conflict avoidance strategy is used to ensure the stable operation of the algorithm.(v)Flight and predation of birds: the flight and predation of birds correspond to the running and optimization of the algorithm. All the guide individuals are a group, and the optimization formulas are as follows. Each guide individual and the guided individuals are a group, and the optimization formulas are the same as the former. where and are weighting coefficients, is the original individual, is a random number between 0-1, is the guide individual, is the adjustment amount of the individual, and is the new generated individual.(vi)Obtaining the best bird: set the upper limit of iteration times and run the algorithm. When the iteration times reach the predetermined value, the algorithm stops. The individual which has the highest fitness will be recorded in the entire computation process, and the individual is a group of the best weights of BFNN.

##### 4.3. New Weight Adjustment Method

After the algorithm in the above sections has been completed, a new neuron weight adjustment method is used to continue training the NN.

The adjustment formulas of weights between hidden layer and output layer are as follows:where is the adjustment amount of weight, is the hidden layer number, is the output layer number, is the learning rate (it is an empirical value between 0.01–0.5), is the expected output matrix, is the actual output matrix, is the difference matrix between the expected output and the actual output (output layer information), and is the difference matrix between the current and previous hidden layer output (hidden layer information).

The adjustment formulas of weights between input layer and hidden layer are as follows:where is the adjustment amount of weight, is the input layer number, is the hidden layer number, is the learning rate (it is an empirical value between 0.01–0.5), is the local gradient (hidden layer information), is the difference matrix between the current and previous input layer output (input layer information), is used to obtain the derivation of the excitation function, is the input of hidden layer, and is used to obtain the square root of the nonnegative part of a number.

The weight calculation formula is as follows:

##### 4.4. Online Adjustment of the Number of Hidden Layer Neurons

After the algorithm of Section 4.3 starts to run, the following method can be used to increase or decrease neurons online.

###### 4.4.1. Method of Increasing Hidden Layer Neuron

Principle: the initial value of the weight of this NN is a random number which is uniformly distributed between −1 and 1, namely, its absolute value is a random number between 0 and 1. All weights are grouped into four intervals: 0–0.25, 0.25–0.5, 0.5–0.75, and 0.75–1. The number of weights in each interval accounts for about 25%. After many datasets were tested, the following rules were found: when the number of hidden layer neurons is the best, the training will cause most initial weights to be adjusted smaller. When the hidden layer neurons are lacking, the training will cause some weights to be adjusted larger.

The above rules can be used to determine if the hidden layer neurons are insufficient.

Concrete operation: after the algorithm of Section4.3 starts to run, determine if the number of weights (greater than 0.75) is greater than 25% (initial ratio). If yes, it means that some neurons are too active, namely, the hidden layer neurons are insufficient, and a hidden layer neuron will be added; if no, the number of neurons is unchanged. The new added weights are set to some small values, and they are uniformly distributed random numbers between −0.1 and 0.1. Continue to train (100 in this paper) times and repeat the above judgment operation.

###### 4.4.2. Method of Decreasing Hidden Layer Neuron

Principle: when the number of the hidden layer neurons is the best, after the NN is fully trained, each hidden layer neuron is fully activated, namely, the weight value of each neuron will not be too low. If it is too low (less than 0.001), it means that some neurons are not fully activated and they belong to redundant neurons.

The above rules can be used to determine if the hidden layer neurons are excessive.

Concrete operation: after the algorithm of Section 4.3 starts to run, determine if there are neurons whose weight mean is less than 0.001. If yes, these neurons are redundant neurons, and delete a neuron whose weight mean is the lowest; if no, the number of neurons is unchanged. Continue to train *k* times and repeat the above judgment operation.

#### 5. Waste Type Identification Method Based on BFNN

The flowchart of waste type recognition algorithm based on BFNN is shown in Figure 5.

The general operation process of the algorithm is as follows:(i)Dataset acquisition: the waste images were analyzed and the feature vectors were extracted (see Section 2).(ii)Feedforward calculation: it includes three parts: determining structure, preprocessing data, and calculating output values (see Section 4.1).(iii)BFO: the BFO was used to learn a known dataset, and the main purpose of the BFO was to find the global optimum (preventing local convergence) (see Section 4.2).(iv)New weight adjustment method: a new weight adjustment method was used to learn data, and the main purpose of this method was to find the local optimum (improving accuracy) (see Section 4.3).(v)Online adjustment method of the number of hidden layer neurons: the hidden layer neurons could be increased and decreased online by this method (see Section 4.4).(vi)Training completed: after the training, the BFNN could identify the types of waste or continue to add data online.

#### 6. Experimental Verification and Result Analysis

##### 6.1. Iteration Times

The number of training samples of dataset was set to 400. According to the calculation of Section 4.2.1, the initial number of the individuals of BFO was 100.

The same number of initial individuals was set to 100, and the same iteration times was set to 100. Run typical GA, typical PSO, and BFO 10 times and obtain the mean, and the experimental results are shown in Figure 6.

The data in Figure 6 are the best fitness of each generation. In order to observe easily that the data in Figure 6 are enlarged (×10000), the calculation formula of the fitness of the GA, the PSO, and the BFO is (12).

As shown in Figure 7, in terms of iteration times, the BFO has the best fitness after 10 iterations, and the iteration time is less than that of the GA and the PSO. In terms of accuracy, the BFO is slightly better than the PSO and obviously better than the GA.

##### 6.2. Recognition Accuracy and Time Consumption

400 samples were used to train the BFNN and comparison algorithms. After the training, 200 unknown samples were identified, and each algorithm ran 10 times for obtaining mean value. The experimental results are shown in Table 1.

Here, hidden layer neurons are short for the number of hidden layer neurons.

As shown in Table 1, in terms of recognition accuracy, the recognition accuracy of the BFNN is 81.0%, which is higher than the comparison algorithms and meets the actual needs. In terms of running time, the BFNN is close to the typical GA-BPNN and the typical PSO-BPNN and higher than the BPNN.

On the basis of the above experiments, 200 samples were supplemented online. After training, the NNs would continue identify the types of waste, and each algorithm ran 10 times for obtaining mean value. The experimental results are shown in Table 2.

As shown in Table 2, after the 200 samples have been supplemented online, in terms of recognition accuracy, the recognition accuracy of the BFNN is slightly higher than the former in Table 1, and the BFNN can effectively supply data. In terms of running time, the time consumption of the BFNN is slightly higher than the former in Table 1. In terms of the number of hidden layer neurons, a hidden layer neuron is added online.

##### 6.3. Confusion Matrix

A confusion matrix for the best case of BFNN is shown in Table 3, where the sum of each row represents the number of samples of an actual class, and the sum of each column represents the number of samples of a predicted class.

Table 3 shows that the recognition effect of cloth is the best and the recognition effect of paper is poor, where some papers were misjudged as plastic. The analysis of the above recognition results is as follows.

###### 6.3.1. Some Successful Recognition Result Images and Analysis

Some successful recognition result images of cloth are shown in Figure 7.

The feature information of Figure 7 is shown in Tables 4 and 5, where these numbers (1–15) are characteristic information number (see Section 2.1 for details).

As shown in Tables 4 and 5, for each individual image of cloth image (successful), the number of pixels concentrated in a certain color level range is significantly higher than others, namely, the color is relatively monotonous, which is consistent with the intuitive experience of observing Figure 7. Because the characteristics of cloth images are obvious, the NN has the highest recognition accuracy for cloth.

###### 6.3.2. Some Unsuccessful Recognition Result Images and Analysis

Some unsuccessful recognition result images of paper and comparison images are shown in Figure 8.

The feature information of Figure 8 is shown in Tables 6 and 7, where these numbers (1–15) are characteristic information number (see Section 2.1 for details).

As shown in Tables 6 and 7, for each individual image of paper image (unsuccessful), the number of pixels concentrated in a certain color level range is significantly higher than others, namely, the color is relatively monotonous. However, the color range of aggregated pixels of the paper images (unsuccessful) is similar to the plastic images, namely, the color of the paper images (unsuccessful) and the plastic images is similar, which is consistent with the intuitive experience of observing Figure 8. Because of the above reasons, the recognition effect of paper by NN is relatively poor, and some papers are misjudged as plastic.

#### 7. Conclusion

There are some problems of NN for waste type identification, such as image feature extraction, local optimum, accuracy, and obtaining the number of hidden layer neurons. In this paper, the features of waste images were extracted; a BFO, a new neuron weight adjustment method, and a hidden layer neuron online adjustment method were proposed. The experimental results show that the recyclables (paper, plastic, glass, and cloth) and nonrecyclables can effectively be identified by the waste type identification method based on the BFNN, and the recognition accuracy is 81% which meets actual needs.

#### Data Availability

The data used to support the findings of this study are available from the corresponding author upon request.

#### Conflicts of Interest

The authors declare that they have no conflicts of interest.

#### Acknowledgments

This study was supported by the Scientific Research Foundation of Tangshan Normal University of China (grant no. 2019A03).