11
Research Article Mango Grading System Based on Optimized Convolutional Neural Network Bin Zheng and Tao Huang School of Intelligent Manufacturing, Panzhihua University, Panzhihua 617000, China Correspondence should be addressed to Bin Zheng; [email protected] Received 23 April 2021; Accepted 18 August 2021; Published 6 September 2021 Academic Editor: Essam Houssein Copyright © 2021 Bin Zheng and Tao Huang. is is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited. In order to achieve the accuracy of mango grading, a mango grading system was designed by using the deep learning method. e system mainly includes CCD camera image acquisition, image preprocessing, model training, and model evaluation. Aiming at the traditional deep learning, neural network training needs a large number of sample data sets; a convolutional neural network is proposed to realize the efficient grading of mangoes through the continuous adjustment and optimization of super-parameters and batch size. e ultra-lightweight SqueezeNet related algorithm is introduced. Compared with AlexNet and other related algorithms with the same accuracy level, it has the advantages of small model scale and fast operation speed. e experimental results show that the convolutional neural network model after super-parameters optimization and adjustment has excellent effect on deep learning image processing of small sample data set. Two hundred thirty-four Jinhuang mangoes of Panzhihua were picked in the natural environment and tested. e analysis results can meet the requirements of the agricultural industry standard of the People’s Republic of China—mango and mango grade specification. At the same time, the average accuracy rate was 97.37%, the average error rate was 2.63%, and the average loss value of the model was 0.44. e processing time of an original image with a resolution of 500 × 374 was only 2.57 milliseconds. is method has important theoretical and application value and can provide a powerful means for mango automatic grading. 1. Introduction Mango is an important economic crop in southeast China. It is native to tropical areas, and its shape is similar to eggs and kidneys. It is rich in vitamins. As the second largest country in the world in mango production, China has established mango plantations in Sichuan, Yunnan, and Hainan, which have become the local supporting industries. With the rapid development of mango planting industry and people’s in- creasing demand for mango quality, the quality of mango directly affects its market competitiveness. erefore, the mango grading has become an indispensable step. China has formulated some standards for mangoes based on shape, color, and surface defects of mango. Based on the standard of the People’s Republic of China “NY/T492-2002 [1]” and “NY/T3011-2016 [2],” mango was divided into three grades according to the characteristics of mango surface defects. At present, mango is mainly classified by manual de- tection or chemical extraction method, but the manual detection cost is high and the accuracy is low. e classi- fication of mango by chemical extraction will damage the appearance quality of mango [3, 4]. In recent years, with the rapid development of machine vision and deep learning theory, it has been possible to use machine learning to classify and sort fruits in large quantities, which not only reduces the labor force, but also improves the accuracy [5–8]. Li and Eng [9] took apple image as the research object, improved the deep learning target detection framework, and built the corresponding learning model. After training and testing, the accuracy rate reached 97.6%. Aiming at the difficulty of sample acquisition in fruit quality supervision learning method, Li et al. [10] took green plum as the re- search object and proposed an intelligent algorithm based on deep learning. e simulation analysis showed that the Hindawi Mathematical Problems in Engineering Volume 2021, Article ID 2652487, 11 pages https://doi.org/10.1155/2021/2652487

Mango Grading System Based on Optimized Convolutional

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Mango Grading System Based on Optimized Convolutional

Research ArticleMango Grading System Based on Optimized ConvolutionalNeural Network

Bin Zheng and Tao Huang

School of Intelligent Manufacturing Panzhihua University Panzhihua 617000 China

Correspondence should be addressed to Bin Zheng 22198334qqcom

Received 23 April 2021 Accepted 18 August 2021 Published 6 September 2021

Academic Editor Essam Houssein

Copyright copy 2021 Bin Zheng and Tao Huang )is is an open access article distributed under the Creative Commons AttributionLicense which permits unrestricted use distribution and reproduction in any medium provided the original work isproperly cited

In order to achieve the accuracy of mango grading a mango grading system was designed by using the deep learning method)esystem mainly includes CCD camera image acquisition image preprocessing model training and model evaluation Aiming atthe traditional deep learning neural network training needs a large number of sample data sets a convolutional neural network isproposed to realize the efficient grading of mangoes through the continuous adjustment and optimization of super-parametersand batch size )e ultra-lightweight SqueezeNet related algorithm is introduced Compared with AlexNet and other relatedalgorithms with the same accuracy level it has the advantages of small model scale and fast operation speed )e experimentalresults show that the convolutional neural network model after super-parameters optimization and adjustment has excellent effecton deep learning image processing of small sample data set Two hundred thirty-four Jinhuangmangoes of Panzhihua were pickedin the natural environment and tested )e analysis results can meet the requirements of the agricultural industry standard of thePeoplersquos Republic of Chinamdashmango and mango grade specification At the same time the average accuracy rate was 9737 theaverage error rate was 263 and the average loss value of the model was 044 )e processing time of an original image with aresolution of 500 times 374 was only 257 milliseconds)is method has important theoretical and application value and can provide apowerful means for mango automatic grading

1 Introduction

Mango is an important economic crop in southeast China Itis native to tropical areas and its shape is similar to eggs andkidneys It is rich in vitamins As the second largest countryin the world in mango production China has establishedmango plantations in Sichuan Yunnan and Hainan whichhave become the local supporting industries With the rapiddevelopment of mango planting industry and peoplersquos in-creasing demand for mango quality the quality of mangodirectly affects its market competitiveness )erefore themango grading has become an indispensable step China hasformulated some standards for mangoes based on shapecolor and surface defects of mango Based on the standard ofthe Peoplersquos Republic of China ldquoNYT492-2002 [1]rdquo andldquoNYT3011-2016 [2]rdquo mango was divided into three gradesaccording to the characteristics of mango surface defects

At present mango is mainly classified by manual de-tection or chemical extraction method but the manualdetection cost is high and the accuracy is low )e classi-fication of mango by chemical extraction will damage theappearance quality of mango [3 4] In recent years with therapid development of machine vision and deep learningtheory it has been possible to use machine learning toclassify and sort fruits in large quantities which not onlyreduces the labor force but also improves the accuracy[5ndash8] Li and Eng [9] took apple image as the research objectimproved the deep learning target detection framework andbuilt the corresponding learning model After training andtesting the accuracy rate reached 976 Aiming at thedifficulty of sample acquisition in fruit quality supervisionlearning method Li et al [10] took green plum as the re-search object and proposed an intelligent algorithm based ondeep learning )e simulation analysis showed that the

HindawiMathematical Problems in EngineeringVolume 2021 Article ID 2652487 11 pageshttpsdoiorg10115520212652487

accuracy rate was 982 Li et al [11] proposed a mangoquality grading algorithm based on computer vision andextreme learning machine neural network Compared withthe traditional back propagation neural network the pro-posed algorithm has higher grading accuracy

Great progress has been made in the application ofmachine vision in the detection and classification of globularfruits [12ndash17] )e application of convolutional neuralnetwork in transfer learning can effectively solve theproblems in the field of agriculture It does not need tomanually extract features and automatically classify thesample images [18ndash22] Saad et al [23] presented an im-proved algorithm for mango grading and measuring mangoweight and the accuracy of weight grading is 95 He et al[24] used image processing technology to automaticallydetect the shape of mango fruit )e evaluation indexes andmethods of mango fruit shape were put forward )e clusteranalysis of 50 mango fruit shape indexes was carried out todetermine the classification basis of each evaluation index)e results shown that the accuracy rate of mango shapeevaluation can reach 92 Mohd et al [25] aimed at theproblems of time-consuming and high cost in traditionalmango grading and proposed using computer vision torecognize the shape and irregularity of mango so as torealize mango grading)e experimental results showed thatthe average success rate of mango grading was 94Combining the methods of machine vision and imageprocessing to sum up compared with spherical fruit mangois ellipsoidal in shape and soft in texture )e existing re-searches have detected and graded mango by extractingmango images but did not refer to Chinese standards Atpresent there is no research on mango grading according toChinese national standards

)erefore the paper took the Panzhihua mango as theresearch object and graded it according to Chinese nationalstandards A convolutional neural network (CNN) deeplearning model based on HDevelop development environ-ment is established and trained )rough automatic rec-ognition of mango surface features the identified imagefeatures are put into CNN model for training and testingand the trained model can quickly grade mango )is modelis compared with ResNet-50 MobileNetV2 and othermodels After constantly adjusting parameters of ldquobatchsizerdquo and ldquoepochrdquo the model is evaluated and compared)eresults show that this model is better than the other con-volutional neural networks in processing speed andaccuracy

2 Data Set Preparation andImage Preprocessing

21 Hardware and Software Structure )e mango samplesare collected by Daheng Mercury MER-500-14GC and itsmain technical parameters are shown in Table 1 )e mangoimages collected are saved as BMP format and written intothe image processing software

)e overall image acquisition system is shown in Fig-ure 1 )e experiment is used to process data sets in the IntelCore i7 CPU 22GHz 8GB running memory NVIDIA

GeForce GTX 1050Ti graphics card configuration and 4GBmemory environment

)e traditional method of image processing with ma-chine vision is generally divided into three steps )ey areimage acquisition feature extraction and graphics recog-nition Because the deep learning classification method isused for image processing a large number of images need tobe preprocessed trained verified and tested in order to getthe expected classification results )e mango image pro-cessing flowchart is shown in Figure 2

22 Image Preprocessing During experiment a total of 234natural mango samples were collected and the deep learningtool was used to label the samples )ere were 55 first-grademangoes 60 second-grade mangoes 58 third-grademangoes and 61 inferior mangoes)e labeledmango imageis exported to ldquohdictrdquo data set format and entered into theintegrated development environment of HDevelop It isdivided into 70 training set 15 verification set and 15test set that is 161 training samples 35 verification samplesand 38 test samples are randomly assigned to start the deeplearning model pretraining

In order to meet the requirement of train CNN classifierthe following steps was carried out

Step 1 )e pixel size of the imported mango image is500times374 and the imported image needs to be changed to224 times 224 times 3 so the mango image is scaled

Step 2 )e image is enhanced to maintain the gray value ofeach image between 0 and 255 and the gray level of thesingle-channel image is converted to make the pixel valuebetween minus127 and 128 )e specific method for gray con-version is shown in the following formula

g(x y) Gmax minus Gmin( 1113857

255f(x y) + Gmin (1)

where g(x y) is the output imageGmax is the maximum grayvalue Gmin is the minimum gray value and f(x y) is theinput image

Step 3 )e preprocessing result image is obtained byconnecting processing and threshold segmentation )eimage preprocessing process is shown in Figure 3

Table 1 Main technical parameters of the CCD cameraModel MER-500-14GCData interface GiveVisionSensor 125PrimeCOMSResolving power 2592times1944Frame rate (fps) 14 fps 2592times1944Pixel size (μm) 22times 22Black and whitecolor ColorAD 12 bitsOptical interface CSize (mm) (WtimesHtimesD) 29times 29times 29

2 Mathematical Problems in Engineering

3 Construction of the Mango Deep LearningTraining Model

31 Convolutional Neural Network Convolutional neuralnetwork (CNN) is a feed forward neural network with deeplearning function based on convolution operation [26ndash28]

As one of the most classic deep learning algorithms con-volutional neural network is widely used in the field of imagerecognitionWhile processing large data image it is differentfrom fully connected neural network (FCNN) [29] Con-volution is used to replace matrix multiplication in con-volutional neural network A complete convolutional neuralnetwork mainly includes the following parts )e input layeris the input of the whole neural network While processingimages it is usually the pixel matrix of the image )econvolution layer is the most important part of convolu-tional neural network Its function is to analyze every smallpart of the neural network in depth to obtain higher abstractfeatures )e pooling layer is used to reduce the matrix thatis to convert a higher-resolution image into a lower-reso-lution image )e fully connected layer gives the classifi-cation results by using feature extraction Among them thefully connected layer is generated iteratively through theconvolution layer and pooling layer

In this paper the convolutional neural network is op-timized based on the ultra-lightweight networkSqueezeNet algorithm )e basic module used is called fireas shown in Figure 4 )e fire basic module consists of threeconvolution layers In the expand part the results of twodifferent core sizes are combined and output through concat)e size of squeeze partial convolution kernel is set to1lowast1and the size of expand convolution kernel is set to 1lowast1 and3lowast3 respectively

In Figure 4 k represents the side length of convolutionkernel and c represents the number of channels If the inputand output dimensions are the same the number of inputchannels is unlimited and the number of output channels ise1 + e2 In the SqueezeNet structure proposed in this papere1 e2 4lowasts1

)e structure of the whole hierarchical convolutionalneural network is shown in Figure 5 In order to improve thetraining effect considering the size and number of inputsamples and the number and size of convolution kernel a12-layer CNN structure based on ultra-lightweight network

Data line

CCD industrialcamera

LED light

Loading platformMango sample Computer monitor computer mainprocessor case

Figure 1 Image acquisition hardware setup system

Validationdata set

Imageacquisition

Imagesegmentation

Trainingdata set

CNN

Test dataset

Imageenhancement

Somax classifier

System modelevaluation

Grading results first-grade mangosecond-grade mango

third-grade mango NG

Figure 2 Mango image processing flowchart

Mathematical Problems in Engineering 3

is constructed )e specific structure is as follows )e firstlayer is the convolution layer which reduces the input imageand extracts 64 dimensional features )e second to ninthlayers are fire modules Reduce the number of channelsinside each module and then expand After every twomodules the number of channels will increase Adddownsampling MaxPooling after layer 1 layer 3 and layer 5respectively to reduce the size by half )e tenth level is usedas a convolution layer to predict each pixel Finally in orderto reduce the amount of calculation the global averagepooling is used to replace the fully connected layer and theSoftMax function is used to normalize it to probability Inorder to improve the generalization ability of the modeldropout technology is used to avoid overfitting and thedropout probability is set to 02 )e global ReLu function isused as the activation function in the training process

Convolution layer is the most important model of CNNIts input is multiple two-dimensional characteristic datagraph Convolution kernel is used as a filter to calculate thelocal data on the neuron node and the two-dimensionalcharacteristic data graph with convolution layer is obtained)e principle of convolution layer can be expressed by thefollowing formula

alj h 1113944

iisinMlj

alminus1i lowast k

lij + b

ij

⎛⎜⎜⎜⎜⎜⎝⎞⎟⎟⎟⎟⎟⎠ (2)

where alj represents the jth output characteristic diagram of l

layer Mljrepresents the index set of multiple output features

corresponding to the jth output feature graph of layer l alminus1i

represents the ith output characteristic diagram of lminus 1 layerlowast represents convolution operation and kl

ij and bij represent

convolution kernel and bias term respectivelyConvolutional neural network model is inseparable from

the transfer of activation function to data In the applicationof convolutional neural network activation function mustbe nonlinear )e functions of sigmoid SoftMax and ReLuare usually used in convolutional neural network ReLufunction has been proved to be able to deal with complexproblems such as gradient disappearance )e formula ofReLu functions is shown in the following formula

ReLU(x) max(0 x) x (xgt 0)

0 xle 01113896 (3)

Pooling layer is usually inserted between successiveconvolution layers Pooling layer is used to follow convo-lution layer to gradually reduce the space size (width andheight) of data representation)e essence of pooling layer isto further select the features of the convoluted data andreduce the dimension of features by convolution kernel of

Original image Zoom processing Gray scaleconversion

resholdsegmentation Feature extractionImage aer

preprocessing

Figure 3 Image preprocessing process

HlowastWlowastM

k=1c=s1

HlowastWlowastS1

k=1c=e1 k=3c=e2

HlowastWlowaste1 HlowastWlowaste2

concat

squeeze

expand

HlowastWlowast(e1+e2)

Figure 4 Fire basic module algorithm structure

4 Mathematical Problems in Engineering

different sizes which is executed independently on eachdepth slice of the input If the input layer is a convolutionlayer and the first layer is a pooling layer the expression ofthe convolution layer is shown in the following formula

flj σ βl

jdown xlminus1j1113872 1113873 + b

lj1113960 1113961 (4)

where down(middot) represents the downsampling function and βlj

represents multiplicative biasAfter the continuous iterative cycle of the convolution

layer and the pooling layer it becomes the fully connectedlayer )e fully connected layer is used as the output layerwhich is used to calculate the score used as the output cat-egory of the network )e fully connected layer has generalparameters used for layer and super-parameters )e fullyconnected layer performs conversion on the input datavolume which is a function of the activation and parameters(weights and biases of neurons) in the input space )eSoftMax function is used as shown in the following formula

Si exp xi( 1113857

1113936nj1 exp xj1113872 1113873

(5)

where Si represents the output of the ith neuron n representsthe number of neurons and xi represents the input signal

In this paper mango grades are divided into four cat-egories which are first-grade mango second-grade mangothird-grade mango and NG

32Model Building Based onConvolutional Neural Networks)epretraining model based onHDevelop is used in HALCONsoftware )e input layer of convolutional neural network is animage that has three channels )e size of the original image is500lowast374 pixels Based on the pretraining model of CNN theconvolutional neural network is built Based on the pretrainingmodel of CNN a convolutional neural network is constructedby superimposing convolution layer pooling layer and fullyconnected layer)en the processed image is output and finallymango grade classification is carried out )e specific convo-lution process is shown in Figure 6

33 SuperParameterSetting In machine learning there arenot only the parameters of the model but also the pa-rameters that can make the network train better and fasterby tuning )ese tuning parameters are called super-pa-rameters )ey are responsible for controlling the selec-tion of optimization function and model during thetraining of learning algorithm )e key point of selectingsuper-parameters is to ensure that the model is neitherunder fitting nor just fitting the training data set and learnthe data structure as soon as possible

Parameter of learning rate refers to the amount of pa-rameter adjustment in the process of optimization in order tominimize the error of neural network prediction A largecoefficient of learning rate will make the parameters jumpwhile a small coefficient of learning rate (eg 0000001) willcause the parameters to change slowly)erefore the selectionof learning rate is particularly important )e parameter ofmomentum can help the learning algorithm get rid of thesearch space and keep the whole system in a stagnant state Asuitable momentum value can help to build a higher qualitymodel In order to prevent overfitting in machine learningresulting in parameters out of control regularization is neededto find a suitable fitting and maintain some low feature weightvalue

Because the number of samples is relatively small a smallnumber of samples are used to train the network Based onthe small batch stochastic gradient descent algorithm withmomentum the loss function is a polynomial combiningcross entropy error and regularization term )e calculationmethod is shown in the following formulas

mq+1

αmq

minus σnablanL f z nq

( 1113857( 1113857 (6)

nq+1

nq

+ mq+1

(7)

L(f(z n)) minus1N

1113944

Nminus1

n0ya log f za n( 1113857( 1113857( 1113857 +

β2

1113944

Kminus 1

k0nk

111386811138681113868111386811138681113868111386811138682

(8)

Input layerInput

Output

500lowast374lowast3

500lowast374lowast3

Conv 1DInput

Output

500lowast374lowast3

250lowast187lowast64

InputOutput

31lowast23lowast4

1lowast1lowast4

Fire4Input

Output

62lowast46lowast256

62lowast46lowast256

Fire6Input

Output

31lowast23lowast384

31lowast23lowast384

Fire5Input

Output

31lowast23lowast256

31lowast23lowast384

Fire3Input

Output

62lowast46lowast128

62lowast46lowast256

MaxPoolingInput

Output

25018764

1259364

Fire2Input

Output

125lowast93lowast128

125lowast93lowast128Conv 1D

InputOutput

31lowast23lowast512

31lowast23lowast4

MaxPoolingInput

Output

62lowast46lowast256

31lowast23lowast256DropOut

InputOutput

31lowast23lowast512

31lowast23lowast512

MaxPooling InputOutput

125lowast93lowast128

62lowast46lowast128

Fire1Input

Output

125lowast93lowast64

125lowast93lowast128

SoMaxInput

Output

1lowast1lowast4

1lowast1lowast4Fire7

InputOutput

31lowast23lowast384

31lowast23lowast512

Fire8Input

Output

31lowast23lowast512

31lowast23lowast512

Classification result first-grade mangosecond-grade mango third-grade mango

and NG

GlobalAveragePooling

Figure 5 CNN training structure

Mathematical Problems in Engineering 5

where α represents momentum σ represents learning ratef(z n) represents the results of classification L(middot) representsloss function n represents weight parameter z representsthe input batch ya represents the encoding of the ath imageza β represents regularization parameter and k representsthe number of weights

4 Experiment and Data Analysis

41 Parameter Test and Results During experiments theparameter ldquobatch_sizerdquo is set as 8 and the ldquoepochrdquo is set as 30In order to avoid overfitting the regularization parameter isset as 00005 )e specific experiment is based on the in-fluence on the verification set and accuracy rate while thelearning rate is ldquo01 001 and 0001rdquo and the momentum isldquo05 07 and 09rdquo respectively )e experimental data areshown in Table 2

Based on the experimental data the final choice oflearning rate is 0001 and momentum size is 09 But fromthe accuracy it does not achieve the ideal accuracy)erefore it is necessary to adjust the parametersldquobatch_sizerdquo and ldquoepochrdquo to achieve the ideal training effectDue to the limitation of experimental hardware test con-ditions and the number of samples the batch size interval 4is selected for the test which is ldquo12 16 and 20rdquo respectivelyand the cycle number interval 20 is selected for the testwhich is ldquo80 100 and 120rdquo respectively )e experimentaldata are shown in Table 3

Obviously when the ldquobatch_sizerdquo is set as 16 and thecycle of ldquoepochrdquo is set as 120 the accuracy is significantlyhigher than that of other groups After a total of 720 iter-ations the training time is 73 s which means that it takesonly 023 s on average to process a 500times 374 imageachieving the expected effect So far the whole modelpreprocessing and training process parameter adjustmenthave been completed

42 Model Evaluation and Performance Analysis )roughthe above optimal adjustment of the super-parameters ofthe neural network with the increasing number of it-erations the loss function curve gradually becomesconvergent with the increasing cycle and the results are

shown in Figure 7 By adjusting the appropriate super-parameters the average error rate of the training set andthe average error rate of the verification set are con-vergent with the increase of the period as shown inFigure 8

It can be seen from Figures 7 and 8 that with the increaseof the training cycle to about 35 cycles the accuracy of thewhole CNN-based neural network is significantly improvedAt the same time the overall error rapidly drops to less than05 and the overall error drops to less than 021 whichachieves good model processing effect

43 Robustness and Comparative Analysis In order to verifythe robustness of the networkmodel 35 samples were testedAmong them mango grading refers to the mango standardof the Peoplersquos Republic of China ldquoNYT3011-2016rdquo asshown in Table 4

)e test results are shown in Table 5 which gives theconfusion matrix of thirty-five mangoes verification sets)e experimental results show that only one first-grademango is misjudged to third-grade one in machinerecognition

Confusion matrix also known as error matrix is astandard format for accuracy evaluation )e confusionmatrix is a matrix with n row times n column It has manyevaluation indexes such as overall accuracy and useraccuracy It can characterize the accuracy of image clas-sification through the evaluation index In the process ofdeep learning confusion matrix is a visual tool to su-pervise the learning process Among them the column ofconfusion matrix represents the prediction category andthe horizontal row represents the real belonging categoryof data

)e 38 mango images used in the test are imported intothe convolutional neural network model which has beenpretrained and run in HDevelop environment for classifi-cation)e result is as shown in Table 6 Only one first-grademango is judged as positive sample but in fact it is negativesample that is the type II error in statistics )e accuracy is9091 )ere is a certain similarity between first-grademango and second-grademango and their F1-score is 9524)e principle expression of F1-score is as follows

Output layer

Fully connectedlayer ConvolutionReLu

Pooling ReLu

Pooling Convolution

Mango input layer Featuremapping

Figure 6 Mango convolutional neural network model

6 Mathematical Problems in Engineering

Table 2 Influence of different parameters on error and accuracy of the data set

Experiment number Learning rate Momentum Verification Top1 error Test set accuracy Loss1

000805 mdash mdash mdash

2 07 0800 284 8703 09 0800 235 10184

000505 0353 600 139

5 07 0529 333 1726 09 0765 205 1937

000105 0176 800 055

8 07 0168 866 0489 09 0114 887 043

Table 3 Different batch size and epoch parameters on training results

Experiment number Batch size Iterations Epoch Accuracy () Top1 error Loss Running time (s)1

12560 80 882 0118 044 56

2 700 100 706 0294 079 633 360 120 844 0124 058 764

16480 80 800 0210 1377 56

5 600 100 867 0113 0443 706 720 120 958 0059 0441 737

20400 80 765 0235 1416 68

8 500 100 867 0113 0444 749 600 120 802 0220 1416 84

00 300 600 900 1200Epoch

0

05

1

15

2

Loss

Loss

Figure 7 Curve of training loss error

00 300 600 900 1200Epoch

0

021

041

062

082

Top-

1 Er

ror

Top-1 Error TrainingTop-1 Error Validation

Figure 8 Curve of training error and validation error with periodic error rates

Mathematical Problems in Engineering 7

F1minusscore 2 times Precision times RecallPrecision + Recall

(9)

where Precision represents the accuracy of a single class andRecall represents the regression rate (the accuracy of the truevalue is zero)

According to the mango quality grade index NYT3011-2016 corresponding to Table 4 the accuracy of mango gradeclassification is analyzed )e analysis results are shown inTable 7 )e overall accuracy of the test results reaches9737 and only one first-grade mango is misjudged assecond grade which achieves the expected accuracy

Heat map also known as thermal map is a graphicrepresentation of the features of an object with the form of aspecial highlight By observing the heat map we can intu-itively find the userrsquos overall access and other characteristicsHeat map analysis can often intuitively observe the prom-inent features of the image with the help of heat map canaccurately capture the target features By using heat mapHDevelop development environment successfully combinesthe results of deep learning confidence and visual featureswhich make the whole classification process more intuitiveTwo mango images are randomly selected from each grade

of the test results and the unprocessed images are analyzedwith the heat map to find the target defect location as shownin Figure 9

)e belief propagation algorithm updates the mark stateof the whole Markov random field (MRF) by transferringinformation between nodes which is an approximate cal-culation based on MRF )e belief propagation algorithm isan iterative algorithm which is mainly used to solve theprobability inference problem of probability graph modelAt the same time all information can be spread in parallel Inthis experiment some confidence data of mango graderecognition result graph are randomly selected as shown inTable 8

)e confidence level is replaced by the probability dis-tribution principle formula of probability as shown in thefollowing formula

bi xi( 1113857 1zϕi xi yi( 1113857 1113945

jisinN(i)

mji xi( 1113857 (10)

where bi(xi) represents the joint probability distribution ofnode imji(xi) represents the message that the implied node jpasses to the implied node i Φi(xi yi) represents the local

Table 5 Mango verification set confusion matrix

Calibration classPrediction

First-grade Second-grade )ird-grade NGFirst-grade 10 0 1 0Second-grade 0 8 0 0)ird-grade 0 0 9 0NG 0 0 0 7

Table 4 Quality grade of mango NYT 3011-2016

Grade Requirement

First-grade mango Mango fruit shape is not deformed and size is uniform )e color of the fruit is normal and uniform )e pericarp issmooth almost without defects with no more than 2 single spots and the diameter of each spot is less than 2mm

Second-grademango

Mango fruit shape has no obvious deformation)e color of the fruit is normal and more than 75 of the fruit surfaceis uniform )e pericarp is smooth with no more than 4 spots per fruit and the diameter of each spot is less than

3mm

)ird-grademango

Deformation of mango fruit shape is not allowed to affect the quality of mango products )e color of the fruit isnormal andmore than 35 of the fruit surface is uniform)e pericarp is relatively smooth with nomore than 6 spots

per fruit and the diameter of each spot is less than 3mm

Table 6 Test set classification data matrix

Class FP Precision () FN Recall () F1minusscore () Total

First-grade mango 1 9091 0 100 9524 10

Second-grade mango 0 100 1 9091 9524 11

)ird-grade mango 0 100 0 100 100 8

NG 0 100 0 100 100 9

8 Mathematical Problems in Engineering

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 2: Mango Grading System Based on Optimized Convolutional

accuracy rate was 982 Li et al [11] proposed a mangoquality grading algorithm based on computer vision andextreme learning machine neural network Compared withthe traditional back propagation neural network the pro-posed algorithm has higher grading accuracy

Great progress has been made in the application ofmachine vision in the detection and classification of globularfruits [12ndash17] )e application of convolutional neuralnetwork in transfer learning can effectively solve theproblems in the field of agriculture It does not need tomanually extract features and automatically classify thesample images [18ndash22] Saad et al [23] presented an im-proved algorithm for mango grading and measuring mangoweight and the accuracy of weight grading is 95 He et al[24] used image processing technology to automaticallydetect the shape of mango fruit )e evaluation indexes andmethods of mango fruit shape were put forward )e clusteranalysis of 50 mango fruit shape indexes was carried out todetermine the classification basis of each evaluation index)e results shown that the accuracy rate of mango shapeevaluation can reach 92 Mohd et al [25] aimed at theproblems of time-consuming and high cost in traditionalmango grading and proposed using computer vision torecognize the shape and irregularity of mango so as torealize mango grading)e experimental results showed thatthe average success rate of mango grading was 94Combining the methods of machine vision and imageprocessing to sum up compared with spherical fruit mangois ellipsoidal in shape and soft in texture )e existing re-searches have detected and graded mango by extractingmango images but did not refer to Chinese standards Atpresent there is no research on mango grading according toChinese national standards

)erefore the paper took the Panzhihua mango as theresearch object and graded it according to Chinese nationalstandards A convolutional neural network (CNN) deeplearning model based on HDevelop development environ-ment is established and trained )rough automatic rec-ognition of mango surface features the identified imagefeatures are put into CNN model for training and testingand the trained model can quickly grade mango )is modelis compared with ResNet-50 MobileNetV2 and othermodels After constantly adjusting parameters of ldquobatchsizerdquo and ldquoepochrdquo the model is evaluated and compared)eresults show that this model is better than the other con-volutional neural networks in processing speed andaccuracy

2 Data Set Preparation andImage Preprocessing

21 Hardware and Software Structure )e mango samplesare collected by Daheng Mercury MER-500-14GC and itsmain technical parameters are shown in Table 1 )e mangoimages collected are saved as BMP format and written intothe image processing software

)e overall image acquisition system is shown in Fig-ure 1 )e experiment is used to process data sets in the IntelCore i7 CPU 22GHz 8GB running memory NVIDIA

GeForce GTX 1050Ti graphics card configuration and 4GBmemory environment

)e traditional method of image processing with ma-chine vision is generally divided into three steps )ey areimage acquisition feature extraction and graphics recog-nition Because the deep learning classification method isused for image processing a large number of images need tobe preprocessed trained verified and tested in order to getthe expected classification results )e mango image pro-cessing flowchart is shown in Figure 2

22 Image Preprocessing During experiment a total of 234natural mango samples were collected and the deep learningtool was used to label the samples )ere were 55 first-grademangoes 60 second-grade mangoes 58 third-grademangoes and 61 inferior mangoes)e labeledmango imageis exported to ldquohdictrdquo data set format and entered into theintegrated development environment of HDevelop It isdivided into 70 training set 15 verification set and 15test set that is 161 training samples 35 verification samplesand 38 test samples are randomly assigned to start the deeplearning model pretraining

In order to meet the requirement of train CNN classifierthe following steps was carried out

Step 1 )e pixel size of the imported mango image is500times374 and the imported image needs to be changed to224 times 224 times 3 so the mango image is scaled

Step 2 )e image is enhanced to maintain the gray value ofeach image between 0 and 255 and the gray level of thesingle-channel image is converted to make the pixel valuebetween minus127 and 128 )e specific method for gray con-version is shown in the following formula

g(x y) Gmax minus Gmin( 1113857

255f(x y) + Gmin (1)

where g(x y) is the output imageGmax is the maximum grayvalue Gmin is the minimum gray value and f(x y) is theinput image

Step 3 )e preprocessing result image is obtained byconnecting processing and threshold segmentation )eimage preprocessing process is shown in Figure 3

Table 1 Main technical parameters of the CCD cameraModel MER-500-14GCData interface GiveVisionSensor 125PrimeCOMSResolving power 2592times1944Frame rate (fps) 14 fps 2592times1944Pixel size (μm) 22times 22Black and whitecolor ColorAD 12 bitsOptical interface CSize (mm) (WtimesHtimesD) 29times 29times 29

2 Mathematical Problems in Engineering

3 Construction of the Mango Deep LearningTraining Model

31 Convolutional Neural Network Convolutional neuralnetwork (CNN) is a feed forward neural network with deeplearning function based on convolution operation [26ndash28]

As one of the most classic deep learning algorithms con-volutional neural network is widely used in the field of imagerecognitionWhile processing large data image it is differentfrom fully connected neural network (FCNN) [29] Con-volution is used to replace matrix multiplication in con-volutional neural network A complete convolutional neuralnetwork mainly includes the following parts )e input layeris the input of the whole neural network While processingimages it is usually the pixel matrix of the image )econvolution layer is the most important part of convolu-tional neural network Its function is to analyze every smallpart of the neural network in depth to obtain higher abstractfeatures )e pooling layer is used to reduce the matrix thatis to convert a higher-resolution image into a lower-reso-lution image )e fully connected layer gives the classifi-cation results by using feature extraction Among them thefully connected layer is generated iteratively through theconvolution layer and pooling layer

In this paper the convolutional neural network is op-timized based on the ultra-lightweight networkSqueezeNet algorithm )e basic module used is called fireas shown in Figure 4 )e fire basic module consists of threeconvolution layers In the expand part the results of twodifferent core sizes are combined and output through concat)e size of squeeze partial convolution kernel is set to1lowast1and the size of expand convolution kernel is set to 1lowast1 and3lowast3 respectively

In Figure 4 k represents the side length of convolutionkernel and c represents the number of channels If the inputand output dimensions are the same the number of inputchannels is unlimited and the number of output channels ise1 + e2 In the SqueezeNet structure proposed in this papere1 e2 4lowasts1

)e structure of the whole hierarchical convolutionalneural network is shown in Figure 5 In order to improve thetraining effect considering the size and number of inputsamples and the number and size of convolution kernel a12-layer CNN structure based on ultra-lightweight network

Data line

CCD industrialcamera

LED light

Loading platformMango sample Computer monitor computer mainprocessor case

Figure 1 Image acquisition hardware setup system

Validationdata set

Imageacquisition

Imagesegmentation

Trainingdata set

CNN

Test dataset

Imageenhancement

Somax classifier

System modelevaluation

Grading results first-grade mangosecond-grade mango

third-grade mango NG

Figure 2 Mango image processing flowchart

Mathematical Problems in Engineering 3

is constructed )e specific structure is as follows )e firstlayer is the convolution layer which reduces the input imageand extracts 64 dimensional features )e second to ninthlayers are fire modules Reduce the number of channelsinside each module and then expand After every twomodules the number of channels will increase Adddownsampling MaxPooling after layer 1 layer 3 and layer 5respectively to reduce the size by half )e tenth level is usedas a convolution layer to predict each pixel Finally in orderto reduce the amount of calculation the global averagepooling is used to replace the fully connected layer and theSoftMax function is used to normalize it to probability Inorder to improve the generalization ability of the modeldropout technology is used to avoid overfitting and thedropout probability is set to 02 )e global ReLu function isused as the activation function in the training process

Convolution layer is the most important model of CNNIts input is multiple two-dimensional characteristic datagraph Convolution kernel is used as a filter to calculate thelocal data on the neuron node and the two-dimensionalcharacteristic data graph with convolution layer is obtained)e principle of convolution layer can be expressed by thefollowing formula

alj h 1113944

iisinMlj

alminus1i lowast k

lij + b

ij

⎛⎜⎜⎜⎜⎜⎝⎞⎟⎟⎟⎟⎟⎠ (2)

where alj represents the jth output characteristic diagram of l

layer Mljrepresents the index set of multiple output features

corresponding to the jth output feature graph of layer l alminus1i

represents the ith output characteristic diagram of lminus 1 layerlowast represents convolution operation and kl

ij and bij represent

convolution kernel and bias term respectivelyConvolutional neural network model is inseparable from

the transfer of activation function to data In the applicationof convolutional neural network activation function mustbe nonlinear )e functions of sigmoid SoftMax and ReLuare usually used in convolutional neural network ReLufunction has been proved to be able to deal with complexproblems such as gradient disappearance )e formula ofReLu functions is shown in the following formula

ReLU(x) max(0 x) x (xgt 0)

0 xle 01113896 (3)

Pooling layer is usually inserted between successiveconvolution layers Pooling layer is used to follow convo-lution layer to gradually reduce the space size (width andheight) of data representation)e essence of pooling layer isto further select the features of the convoluted data andreduce the dimension of features by convolution kernel of

Original image Zoom processing Gray scaleconversion

resholdsegmentation Feature extractionImage aer

preprocessing

Figure 3 Image preprocessing process

HlowastWlowastM

k=1c=s1

HlowastWlowastS1

k=1c=e1 k=3c=e2

HlowastWlowaste1 HlowastWlowaste2

concat

squeeze

expand

HlowastWlowast(e1+e2)

Figure 4 Fire basic module algorithm structure

4 Mathematical Problems in Engineering

different sizes which is executed independently on eachdepth slice of the input If the input layer is a convolutionlayer and the first layer is a pooling layer the expression ofthe convolution layer is shown in the following formula

flj σ βl

jdown xlminus1j1113872 1113873 + b

lj1113960 1113961 (4)

where down(middot) represents the downsampling function and βlj

represents multiplicative biasAfter the continuous iterative cycle of the convolution

layer and the pooling layer it becomes the fully connectedlayer )e fully connected layer is used as the output layerwhich is used to calculate the score used as the output cat-egory of the network )e fully connected layer has generalparameters used for layer and super-parameters )e fullyconnected layer performs conversion on the input datavolume which is a function of the activation and parameters(weights and biases of neurons) in the input space )eSoftMax function is used as shown in the following formula

Si exp xi( 1113857

1113936nj1 exp xj1113872 1113873

(5)

where Si represents the output of the ith neuron n representsthe number of neurons and xi represents the input signal

In this paper mango grades are divided into four cat-egories which are first-grade mango second-grade mangothird-grade mango and NG

32Model Building Based onConvolutional Neural Networks)epretraining model based onHDevelop is used in HALCONsoftware )e input layer of convolutional neural network is animage that has three channels )e size of the original image is500lowast374 pixels Based on the pretraining model of CNN theconvolutional neural network is built Based on the pretrainingmodel of CNN a convolutional neural network is constructedby superimposing convolution layer pooling layer and fullyconnected layer)en the processed image is output and finallymango grade classification is carried out )e specific convo-lution process is shown in Figure 6

33 SuperParameterSetting In machine learning there arenot only the parameters of the model but also the pa-rameters that can make the network train better and fasterby tuning )ese tuning parameters are called super-pa-rameters )ey are responsible for controlling the selec-tion of optimization function and model during thetraining of learning algorithm )e key point of selectingsuper-parameters is to ensure that the model is neitherunder fitting nor just fitting the training data set and learnthe data structure as soon as possible

Parameter of learning rate refers to the amount of pa-rameter adjustment in the process of optimization in order tominimize the error of neural network prediction A largecoefficient of learning rate will make the parameters jumpwhile a small coefficient of learning rate (eg 0000001) willcause the parameters to change slowly)erefore the selectionof learning rate is particularly important )e parameter ofmomentum can help the learning algorithm get rid of thesearch space and keep the whole system in a stagnant state Asuitable momentum value can help to build a higher qualitymodel In order to prevent overfitting in machine learningresulting in parameters out of control regularization is neededto find a suitable fitting and maintain some low feature weightvalue

Because the number of samples is relatively small a smallnumber of samples are used to train the network Based onthe small batch stochastic gradient descent algorithm withmomentum the loss function is a polynomial combiningcross entropy error and regularization term )e calculationmethod is shown in the following formulas

mq+1

αmq

minus σnablanL f z nq

( 1113857( 1113857 (6)

nq+1

nq

+ mq+1

(7)

L(f(z n)) minus1N

1113944

Nminus1

n0ya log f za n( 1113857( 1113857( 1113857 +

β2

1113944

Kminus 1

k0nk

111386811138681113868111386811138681113868111386811138682

(8)

Input layerInput

Output

500lowast374lowast3

500lowast374lowast3

Conv 1DInput

Output

500lowast374lowast3

250lowast187lowast64

InputOutput

31lowast23lowast4

1lowast1lowast4

Fire4Input

Output

62lowast46lowast256

62lowast46lowast256

Fire6Input

Output

31lowast23lowast384

31lowast23lowast384

Fire5Input

Output

31lowast23lowast256

31lowast23lowast384

Fire3Input

Output

62lowast46lowast128

62lowast46lowast256

MaxPoolingInput

Output

25018764

1259364

Fire2Input

Output

125lowast93lowast128

125lowast93lowast128Conv 1D

InputOutput

31lowast23lowast512

31lowast23lowast4

MaxPoolingInput

Output

62lowast46lowast256

31lowast23lowast256DropOut

InputOutput

31lowast23lowast512

31lowast23lowast512

MaxPooling InputOutput

125lowast93lowast128

62lowast46lowast128

Fire1Input

Output

125lowast93lowast64

125lowast93lowast128

SoMaxInput

Output

1lowast1lowast4

1lowast1lowast4Fire7

InputOutput

31lowast23lowast384

31lowast23lowast512

Fire8Input

Output

31lowast23lowast512

31lowast23lowast512

Classification result first-grade mangosecond-grade mango third-grade mango

and NG

GlobalAveragePooling

Figure 5 CNN training structure

Mathematical Problems in Engineering 5

where α represents momentum σ represents learning ratef(z n) represents the results of classification L(middot) representsloss function n represents weight parameter z representsthe input batch ya represents the encoding of the ath imageza β represents regularization parameter and k representsthe number of weights

4 Experiment and Data Analysis

41 Parameter Test and Results During experiments theparameter ldquobatch_sizerdquo is set as 8 and the ldquoepochrdquo is set as 30In order to avoid overfitting the regularization parameter isset as 00005 )e specific experiment is based on the in-fluence on the verification set and accuracy rate while thelearning rate is ldquo01 001 and 0001rdquo and the momentum isldquo05 07 and 09rdquo respectively )e experimental data areshown in Table 2

Based on the experimental data the final choice oflearning rate is 0001 and momentum size is 09 But fromthe accuracy it does not achieve the ideal accuracy)erefore it is necessary to adjust the parametersldquobatch_sizerdquo and ldquoepochrdquo to achieve the ideal training effectDue to the limitation of experimental hardware test con-ditions and the number of samples the batch size interval 4is selected for the test which is ldquo12 16 and 20rdquo respectivelyand the cycle number interval 20 is selected for the testwhich is ldquo80 100 and 120rdquo respectively )e experimentaldata are shown in Table 3

Obviously when the ldquobatch_sizerdquo is set as 16 and thecycle of ldquoepochrdquo is set as 120 the accuracy is significantlyhigher than that of other groups After a total of 720 iter-ations the training time is 73 s which means that it takesonly 023 s on average to process a 500times 374 imageachieving the expected effect So far the whole modelpreprocessing and training process parameter adjustmenthave been completed

42 Model Evaluation and Performance Analysis )roughthe above optimal adjustment of the super-parameters ofthe neural network with the increasing number of it-erations the loss function curve gradually becomesconvergent with the increasing cycle and the results are

shown in Figure 7 By adjusting the appropriate super-parameters the average error rate of the training set andthe average error rate of the verification set are con-vergent with the increase of the period as shown inFigure 8

It can be seen from Figures 7 and 8 that with the increaseof the training cycle to about 35 cycles the accuracy of thewhole CNN-based neural network is significantly improvedAt the same time the overall error rapidly drops to less than05 and the overall error drops to less than 021 whichachieves good model processing effect

43 Robustness and Comparative Analysis In order to verifythe robustness of the networkmodel 35 samples were testedAmong them mango grading refers to the mango standardof the Peoplersquos Republic of China ldquoNYT3011-2016rdquo asshown in Table 4

)e test results are shown in Table 5 which gives theconfusion matrix of thirty-five mangoes verification sets)e experimental results show that only one first-grademango is misjudged to third-grade one in machinerecognition

Confusion matrix also known as error matrix is astandard format for accuracy evaluation )e confusionmatrix is a matrix with n row times n column It has manyevaluation indexes such as overall accuracy and useraccuracy It can characterize the accuracy of image clas-sification through the evaluation index In the process ofdeep learning confusion matrix is a visual tool to su-pervise the learning process Among them the column ofconfusion matrix represents the prediction category andthe horizontal row represents the real belonging categoryof data

)e 38 mango images used in the test are imported intothe convolutional neural network model which has beenpretrained and run in HDevelop environment for classifi-cation)e result is as shown in Table 6 Only one first-grademango is judged as positive sample but in fact it is negativesample that is the type II error in statistics )e accuracy is9091 )ere is a certain similarity between first-grademango and second-grademango and their F1-score is 9524)e principle expression of F1-score is as follows

Output layer

Fully connectedlayer ConvolutionReLu

Pooling ReLu

Pooling Convolution

Mango input layer Featuremapping

Figure 6 Mango convolutional neural network model

6 Mathematical Problems in Engineering

Table 2 Influence of different parameters on error and accuracy of the data set

Experiment number Learning rate Momentum Verification Top1 error Test set accuracy Loss1

000805 mdash mdash mdash

2 07 0800 284 8703 09 0800 235 10184

000505 0353 600 139

5 07 0529 333 1726 09 0765 205 1937

000105 0176 800 055

8 07 0168 866 0489 09 0114 887 043

Table 3 Different batch size and epoch parameters on training results

Experiment number Batch size Iterations Epoch Accuracy () Top1 error Loss Running time (s)1

12560 80 882 0118 044 56

2 700 100 706 0294 079 633 360 120 844 0124 058 764

16480 80 800 0210 1377 56

5 600 100 867 0113 0443 706 720 120 958 0059 0441 737

20400 80 765 0235 1416 68

8 500 100 867 0113 0444 749 600 120 802 0220 1416 84

00 300 600 900 1200Epoch

0

05

1

15

2

Loss

Loss

Figure 7 Curve of training loss error

00 300 600 900 1200Epoch

0

021

041

062

082

Top-

1 Er

ror

Top-1 Error TrainingTop-1 Error Validation

Figure 8 Curve of training error and validation error with periodic error rates

Mathematical Problems in Engineering 7

F1minusscore 2 times Precision times RecallPrecision + Recall

(9)

where Precision represents the accuracy of a single class andRecall represents the regression rate (the accuracy of the truevalue is zero)

According to the mango quality grade index NYT3011-2016 corresponding to Table 4 the accuracy of mango gradeclassification is analyzed )e analysis results are shown inTable 7 )e overall accuracy of the test results reaches9737 and only one first-grade mango is misjudged assecond grade which achieves the expected accuracy

Heat map also known as thermal map is a graphicrepresentation of the features of an object with the form of aspecial highlight By observing the heat map we can intu-itively find the userrsquos overall access and other characteristicsHeat map analysis can often intuitively observe the prom-inent features of the image with the help of heat map canaccurately capture the target features By using heat mapHDevelop development environment successfully combinesthe results of deep learning confidence and visual featureswhich make the whole classification process more intuitiveTwo mango images are randomly selected from each grade

of the test results and the unprocessed images are analyzedwith the heat map to find the target defect location as shownin Figure 9

)e belief propagation algorithm updates the mark stateof the whole Markov random field (MRF) by transferringinformation between nodes which is an approximate cal-culation based on MRF )e belief propagation algorithm isan iterative algorithm which is mainly used to solve theprobability inference problem of probability graph modelAt the same time all information can be spread in parallel Inthis experiment some confidence data of mango graderecognition result graph are randomly selected as shown inTable 8

)e confidence level is replaced by the probability dis-tribution principle formula of probability as shown in thefollowing formula

bi xi( 1113857 1zϕi xi yi( 1113857 1113945

jisinN(i)

mji xi( 1113857 (10)

where bi(xi) represents the joint probability distribution ofnode imji(xi) represents the message that the implied node jpasses to the implied node i Φi(xi yi) represents the local

Table 5 Mango verification set confusion matrix

Calibration classPrediction

First-grade Second-grade )ird-grade NGFirst-grade 10 0 1 0Second-grade 0 8 0 0)ird-grade 0 0 9 0NG 0 0 0 7

Table 4 Quality grade of mango NYT 3011-2016

Grade Requirement

First-grade mango Mango fruit shape is not deformed and size is uniform )e color of the fruit is normal and uniform )e pericarp issmooth almost without defects with no more than 2 single spots and the diameter of each spot is less than 2mm

Second-grademango

Mango fruit shape has no obvious deformation)e color of the fruit is normal and more than 75 of the fruit surfaceis uniform )e pericarp is smooth with no more than 4 spots per fruit and the diameter of each spot is less than

3mm

)ird-grademango

Deformation of mango fruit shape is not allowed to affect the quality of mango products )e color of the fruit isnormal andmore than 35 of the fruit surface is uniform)e pericarp is relatively smooth with nomore than 6 spots

per fruit and the diameter of each spot is less than 3mm

Table 6 Test set classification data matrix

Class FP Precision () FN Recall () F1minusscore () Total

First-grade mango 1 9091 0 100 9524 10

Second-grade mango 0 100 1 9091 9524 11

)ird-grade mango 0 100 0 100 100 8

NG 0 100 0 100 100 9

8 Mathematical Problems in Engineering

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 3: Mango Grading System Based on Optimized Convolutional

3 Construction of the Mango Deep LearningTraining Model

31 Convolutional Neural Network Convolutional neuralnetwork (CNN) is a feed forward neural network with deeplearning function based on convolution operation [26ndash28]

As one of the most classic deep learning algorithms con-volutional neural network is widely used in the field of imagerecognitionWhile processing large data image it is differentfrom fully connected neural network (FCNN) [29] Con-volution is used to replace matrix multiplication in con-volutional neural network A complete convolutional neuralnetwork mainly includes the following parts )e input layeris the input of the whole neural network While processingimages it is usually the pixel matrix of the image )econvolution layer is the most important part of convolu-tional neural network Its function is to analyze every smallpart of the neural network in depth to obtain higher abstractfeatures )e pooling layer is used to reduce the matrix thatis to convert a higher-resolution image into a lower-reso-lution image )e fully connected layer gives the classifi-cation results by using feature extraction Among them thefully connected layer is generated iteratively through theconvolution layer and pooling layer

In this paper the convolutional neural network is op-timized based on the ultra-lightweight networkSqueezeNet algorithm )e basic module used is called fireas shown in Figure 4 )e fire basic module consists of threeconvolution layers In the expand part the results of twodifferent core sizes are combined and output through concat)e size of squeeze partial convolution kernel is set to1lowast1and the size of expand convolution kernel is set to 1lowast1 and3lowast3 respectively

In Figure 4 k represents the side length of convolutionkernel and c represents the number of channels If the inputand output dimensions are the same the number of inputchannels is unlimited and the number of output channels ise1 + e2 In the SqueezeNet structure proposed in this papere1 e2 4lowasts1

)e structure of the whole hierarchical convolutionalneural network is shown in Figure 5 In order to improve thetraining effect considering the size and number of inputsamples and the number and size of convolution kernel a12-layer CNN structure based on ultra-lightweight network

Data line

CCD industrialcamera

LED light

Loading platformMango sample Computer monitor computer mainprocessor case

Figure 1 Image acquisition hardware setup system

Validationdata set

Imageacquisition

Imagesegmentation

Trainingdata set

CNN

Test dataset

Imageenhancement

Somax classifier

System modelevaluation

Grading results first-grade mangosecond-grade mango

third-grade mango NG

Figure 2 Mango image processing flowchart

Mathematical Problems in Engineering 3

is constructed )e specific structure is as follows )e firstlayer is the convolution layer which reduces the input imageand extracts 64 dimensional features )e second to ninthlayers are fire modules Reduce the number of channelsinside each module and then expand After every twomodules the number of channels will increase Adddownsampling MaxPooling after layer 1 layer 3 and layer 5respectively to reduce the size by half )e tenth level is usedas a convolution layer to predict each pixel Finally in orderto reduce the amount of calculation the global averagepooling is used to replace the fully connected layer and theSoftMax function is used to normalize it to probability Inorder to improve the generalization ability of the modeldropout technology is used to avoid overfitting and thedropout probability is set to 02 )e global ReLu function isused as the activation function in the training process

Convolution layer is the most important model of CNNIts input is multiple two-dimensional characteristic datagraph Convolution kernel is used as a filter to calculate thelocal data on the neuron node and the two-dimensionalcharacteristic data graph with convolution layer is obtained)e principle of convolution layer can be expressed by thefollowing formula

alj h 1113944

iisinMlj

alminus1i lowast k

lij + b

ij

⎛⎜⎜⎜⎜⎜⎝⎞⎟⎟⎟⎟⎟⎠ (2)

where alj represents the jth output characteristic diagram of l

layer Mljrepresents the index set of multiple output features

corresponding to the jth output feature graph of layer l alminus1i

represents the ith output characteristic diagram of lminus 1 layerlowast represents convolution operation and kl

ij and bij represent

convolution kernel and bias term respectivelyConvolutional neural network model is inseparable from

the transfer of activation function to data In the applicationof convolutional neural network activation function mustbe nonlinear )e functions of sigmoid SoftMax and ReLuare usually used in convolutional neural network ReLufunction has been proved to be able to deal with complexproblems such as gradient disappearance )e formula ofReLu functions is shown in the following formula

ReLU(x) max(0 x) x (xgt 0)

0 xle 01113896 (3)

Pooling layer is usually inserted between successiveconvolution layers Pooling layer is used to follow convo-lution layer to gradually reduce the space size (width andheight) of data representation)e essence of pooling layer isto further select the features of the convoluted data andreduce the dimension of features by convolution kernel of

Original image Zoom processing Gray scaleconversion

resholdsegmentation Feature extractionImage aer

preprocessing

Figure 3 Image preprocessing process

HlowastWlowastM

k=1c=s1

HlowastWlowastS1

k=1c=e1 k=3c=e2

HlowastWlowaste1 HlowastWlowaste2

concat

squeeze

expand

HlowastWlowast(e1+e2)

Figure 4 Fire basic module algorithm structure

4 Mathematical Problems in Engineering

different sizes which is executed independently on eachdepth slice of the input If the input layer is a convolutionlayer and the first layer is a pooling layer the expression ofthe convolution layer is shown in the following formula

flj σ βl

jdown xlminus1j1113872 1113873 + b

lj1113960 1113961 (4)

where down(middot) represents the downsampling function and βlj

represents multiplicative biasAfter the continuous iterative cycle of the convolution

layer and the pooling layer it becomes the fully connectedlayer )e fully connected layer is used as the output layerwhich is used to calculate the score used as the output cat-egory of the network )e fully connected layer has generalparameters used for layer and super-parameters )e fullyconnected layer performs conversion on the input datavolume which is a function of the activation and parameters(weights and biases of neurons) in the input space )eSoftMax function is used as shown in the following formula

Si exp xi( 1113857

1113936nj1 exp xj1113872 1113873

(5)

where Si represents the output of the ith neuron n representsthe number of neurons and xi represents the input signal

In this paper mango grades are divided into four cat-egories which are first-grade mango second-grade mangothird-grade mango and NG

32Model Building Based onConvolutional Neural Networks)epretraining model based onHDevelop is used in HALCONsoftware )e input layer of convolutional neural network is animage that has three channels )e size of the original image is500lowast374 pixels Based on the pretraining model of CNN theconvolutional neural network is built Based on the pretrainingmodel of CNN a convolutional neural network is constructedby superimposing convolution layer pooling layer and fullyconnected layer)en the processed image is output and finallymango grade classification is carried out )e specific convo-lution process is shown in Figure 6

33 SuperParameterSetting In machine learning there arenot only the parameters of the model but also the pa-rameters that can make the network train better and fasterby tuning )ese tuning parameters are called super-pa-rameters )ey are responsible for controlling the selec-tion of optimization function and model during thetraining of learning algorithm )e key point of selectingsuper-parameters is to ensure that the model is neitherunder fitting nor just fitting the training data set and learnthe data structure as soon as possible

Parameter of learning rate refers to the amount of pa-rameter adjustment in the process of optimization in order tominimize the error of neural network prediction A largecoefficient of learning rate will make the parameters jumpwhile a small coefficient of learning rate (eg 0000001) willcause the parameters to change slowly)erefore the selectionof learning rate is particularly important )e parameter ofmomentum can help the learning algorithm get rid of thesearch space and keep the whole system in a stagnant state Asuitable momentum value can help to build a higher qualitymodel In order to prevent overfitting in machine learningresulting in parameters out of control regularization is neededto find a suitable fitting and maintain some low feature weightvalue

Because the number of samples is relatively small a smallnumber of samples are used to train the network Based onthe small batch stochastic gradient descent algorithm withmomentum the loss function is a polynomial combiningcross entropy error and regularization term )e calculationmethod is shown in the following formulas

mq+1

αmq

minus σnablanL f z nq

( 1113857( 1113857 (6)

nq+1

nq

+ mq+1

(7)

L(f(z n)) minus1N

1113944

Nminus1

n0ya log f za n( 1113857( 1113857( 1113857 +

β2

1113944

Kminus 1

k0nk

111386811138681113868111386811138681113868111386811138682

(8)

Input layerInput

Output

500lowast374lowast3

500lowast374lowast3

Conv 1DInput

Output

500lowast374lowast3

250lowast187lowast64

InputOutput

31lowast23lowast4

1lowast1lowast4

Fire4Input

Output

62lowast46lowast256

62lowast46lowast256

Fire6Input

Output

31lowast23lowast384

31lowast23lowast384

Fire5Input

Output

31lowast23lowast256

31lowast23lowast384

Fire3Input

Output

62lowast46lowast128

62lowast46lowast256

MaxPoolingInput

Output

25018764

1259364

Fire2Input

Output

125lowast93lowast128

125lowast93lowast128Conv 1D

InputOutput

31lowast23lowast512

31lowast23lowast4

MaxPoolingInput

Output

62lowast46lowast256

31lowast23lowast256DropOut

InputOutput

31lowast23lowast512

31lowast23lowast512

MaxPooling InputOutput

125lowast93lowast128

62lowast46lowast128

Fire1Input

Output

125lowast93lowast64

125lowast93lowast128

SoMaxInput

Output

1lowast1lowast4

1lowast1lowast4Fire7

InputOutput

31lowast23lowast384

31lowast23lowast512

Fire8Input

Output

31lowast23lowast512

31lowast23lowast512

Classification result first-grade mangosecond-grade mango third-grade mango

and NG

GlobalAveragePooling

Figure 5 CNN training structure

Mathematical Problems in Engineering 5

where α represents momentum σ represents learning ratef(z n) represents the results of classification L(middot) representsloss function n represents weight parameter z representsthe input batch ya represents the encoding of the ath imageza β represents regularization parameter and k representsthe number of weights

4 Experiment and Data Analysis

41 Parameter Test and Results During experiments theparameter ldquobatch_sizerdquo is set as 8 and the ldquoepochrdquo is set as 30In order to avoid overfitting the regularization parameter isset as 00005 )e specific experiment is based on the in-fluence on the verification set and accuracy rate while thelearning rate is ldquo01 001 and 0001rdquo and the momentum isldquo05 07 and 09rdquo respectively )e experimental data areshown in Table 2

Based on the experimental data the final choice oflearning rate is 0001 and momentum size is 09 But fromthe accuracy it does not achieve the ideal accuracy)erefore it is necessary to adjust the parametersldquobatch_sizerdquo and ldquoepochrdquo to achieve the ideal training effectDue to the limitation of experimental hardware test con-ditions and the number of samples the batch size interval 4is selected for the test which is ldquo12 16 and 20rdquo respectivelyand the cycle number interval 20 is selected for the testwhich is ldquo80 100 and 120rdquo respectively )e experimentaldata are shown in Table 3

Obviously when the ldquobatch_sizerdquo is set as 16 and thecycle of ldquoepochrdquo is set as 120 the accuracy is significantlyhigher than that of other groups After a total of 720 iter-ations the training time is 73 s which means that it takesonly 023 s on average to process a 500times 374 imageachieving the expected effect So far the whole modelpreprocessing and training process parameter adjustmenthave been completed

42 Model Evaluation and Performance Analysis )roughthe above optimal adjustment of the super-parameters ofthe neural network with the increasing number of it-erations the loss function curve gradually becomesconvergent with the increasing cycle and the results are

shown in Figure 7 By adjusting the appropriate super-parameters the average error rate of the training set andthe average error rate of the verification set are con-vergent with the increase of the period as shown inFigure 8

It can be seen from Figures 7 and 8 that with the increaseof the training cycle to about 35 cycles the accuracy of thewhole CNN-based neural network is significantly improvedAt the same time the overall error rapidly drops to less than05 and the overall error drops to less than 021 whichachieves good model processing effect

43 Robustness and Comparative Analysis In order to verifythe robustness of the networkmodel 35 samples were testedAmong them mango grading refers to the mango standardof the Peoplersquos Republic of China ldquoNYT3011-2016rdquo asshown in Table 4

)e test results are shown in Table 5 which gives theconfusion matrix of thirty-five mangoes verification sets)e experimental results show that only one first-grademango is misjudged to third-grade one in machinerecognition

Confusion matrix also known as error matrix is astandard format for accuracy evaluation )e confusionmatrix is a matrix with n row times n column It has manyevaluation indexes such as overall accuracy and useraccuracy It can characterize the accuracy of image clas-sification through the evaluation index In the process ofdeep learning confusion matrix is a visual tool to su-pervise the learning process Among them the column ofconfusion matrix represents the prediction category andthe horizontal row represents the real belonging categoryof data

)e 38 mango images used in the test are imported intothe convolutional neural network model which has beenpretrained and run in HDevelop environment for classifi-cation)e result is as shown in Table 6 Only one first-grademango is judged as positive sample but in fact it is negativesample that is the type II error in statistics )e accuracy is9091 )ere is a certain similarity between first-grademango and second-grademango and their F1-score is 9524)e principle expression of F1-score is as follows

Output layer

Fully connectedlayer ConvolutionReLu

Pooling ReLu

Pooling Convolution

Mango input layer Featuremapping

Figure 6 Mango convolutional neural network model

6 Mathematical Problems in Engineering

Table 2 Influence of different parameters on error and accuracy of the data set

Experiment number Learning rate Momentum Verification Top1 error Test set accuracy Loss1

000805 mdash mdash mdash

2 07 0800 284 8703 09 0800 235 10184

000505 0353 600 139

5 07 0529 333 1726 09 0765 205 1937

000105 0176 800 055

8 07 0168 866 0489 09 0114 887 043

Table 3 Different batch size and epoch parameters on training results

Experiment number Batch size Iterations Epoch Accuracy () Top1 error Loss Running time (s)1

12560 80 882 0118 044 56

2 700 100 706 0294 079 633 360 120 844 0124 058 764

16480 80 800 0210 1377 56

5 600 100 867 0113 0443 706 720 120 958 0059 0441 737

20400 80 765 0235 1416 68

8 500 100 867 0113 0444 749 600 120 802 0220 1416 84

00 300 600 900 1200Epoch

0

05

1

15

2

Loss

Loss

Figure 7 Curve of training loss error

00 300 600 900 1200Epoch

0

021

041

062

082

Top-

1 Er

ror

Top-1 Error TrainingTop-1 Error Validation

Figure 8 Curve of training error and validation error with periodic error rates

Mathematical Problems in Engineering 7

F1minusscore 2 times Precision times RecallPrecision + Recall

(9)

where Precision represents the accuracy of a single class andRecall represents the regression rate (the accuracy of the truevalue is zero)

According to the mango quality grade index NYT3011-2016 corresponding to Table 4 the accuracy of mango gradeclassification is analyzed )e analysis results are shown inTable 7 )e overall accuracy of the test results reaches9737 and only one first-grade mango is misjudged assecond grade which achieves the expected accuracy

Heat map also known as thermal map is a graphicrepresentation of the features of an object with the form of aspecial highlight By observing the heat map we can intu-itively find the userrsquos overall access and other characteristicsHeat map analysis can often intuitively observe the prom-inent features of the image with the help of heat map canaccurately capture the target features By using heat mapHDevelop development environment successfully combinesthe results of deep learning confidence and visual featureswhich make the whole classification process more intuitiveTwo mango images are randomly selected from each grade

of the test results and the unprocessed images are analyzedwith the heat map to find the target defect location as shownin Figure 9

)e belief propagation algorithm updates the mark stateof the whole Markov random field (MRF) by transferringinformation between nodes which is an approximate cal-culation based on MRF )e belief propagation algorithm isan iterative algorithm which is mainly used to solve theprobability inference problem of probability graph modelAt the same time all information can be spread in parallel Inthis experiment some confidence data of mango graderecognition result graph are randomly selected as shown inTable 8

)e confidence level is replaced by the probability dis-tribution principle formula of probability as shown in thefollowing formula

bi xi( 1113857 1zϕi xi yi( 1113857 1113945

jisinN(i)

mji xi( 1113857 (10)

where bi(xi) represents the joint probability distribution ofnode imji(xi) represents the message that the implied node jpasses to the implied node i Φi(xi yi) represents the local

Table 5 Mango verification set confusion matrix

Calibration classPrediction

First-grade Second-grade )ird-grade NGFirst-grade 10 0 1 0Second-grade 0 8 0 0)ird-grade 0 0 9 0NG 0 0 0 7

Table 4 Quality grade of mango NYT 3011-2016

Grade Requirement

First-grade mango Mango fruit shape is not deformed and size is uniform )e color of the fruit is normal and uniform )e pericarp issmooth almost without defects with no more than 2 single spots and the diameter of each spot is less than 2mm

Second-grademango

Mango fruit shape has no obvious deformation)e color of the fruit is normal and more than 75 of the fruit surfaceis uniform )e pericarp is smooth with no more than 4 spots per fruit and the diameter of each spot is less than

3mm

)ird-grademango

Deformation of mango fruit shape is not allowed to affect the quality of mango products )e color of the fruit isnormal andmore than 35 of the fruit surface is uniform)e pericarp is relatively smooth with nomore than 6 spots

per fruit and the diameter of each spot is less than 3mm

Table 6 Test set classification data matrix

Class FP Precision () FN Recall () F1minusscore () Total

First-grade mango 1 9091 0 100 9524 10

Second-grade mango 0 100 1 9091 9524 11

)ird-grade mango 0 100 0 100 100 8

NG 0 100 0 100 100 9

8 Mathematical Problems in Engineering

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 4: Mango Grading System Based on Optimized Convolutional

is constructed )e specific structure is as follows )e firstlayer is the convolution layer which reduces the input imageand extracts 64 dimensional features )e second to ninthlayers are fire modules Reduce the number of channelsinside each module and then expand After every twomodules the number of channels will increase Adddownsampling MaxPooling after layer 1 layer 3 and layer 5respectively to reduce the size by half )e tenth level is usedas a convolution layer to predict each pixel Finally in orderto reduce the amount of calculation the global averagepooling is used to replace the fully connected layer and theSoftMax function is used to normalize it to probability Inorder to improve the generalization ability of the modeldropout technology is used to avoid overfitting and thedropout probability is set to 02 )e global ReLu function isused as the activation function in the training process

Convolution layer is the most important model of CNNIts input is multiple two-dimensional characteristic datagraph Convolution kernel is used as a filter to calculate thelocal data on the neuron node and the two-dimensionalcharacteristic data graph with convolution layer is obtained)e principle of convolution layer can be expressed by thefollowing formula

alj h 1113944

iisinMlj

alminus1i lowast k

lij + b

ij

⎛⎜⎜⎜⎜⎜⎝⎞⎟⎟⎟⎟⎟⎠ (2)

where alj represents the jth output characteristic diagram of l

layer Mljrepresents the index set of multiple output features

corresponding to the jth output feature graph of layer l alminus1i

represents the ith output characteristic diagram of lminus 1 layerlowast represents convolution operation and kl

ij and bij represent

convolution kernel and bias term respectivelyConvolutional neural network model is inseparable from

the transfer of activation function to data In the applicationof convolutional neural network activation function mustbe nonlinear )e functions of sigmoid SoftMax and ReLuare usually used in convolutional neural network ReLufunction has been proved to be able to deal with complexproblems such as gradient disappearance )e formula ofReLu functions is shown in the following formula

ReLU(x) max(0 x) x (xgt 0)

0 xle 01113896 (3)

Pooling layer is usually inserted between successiveconvolution layers Pooling layer is used to follow convo-lution layer to gradually reduce the space size (width andheight) of data representation)e essence of pooling layer isto further select the features of the convoluted data andreduce the dimension of features by convolution kernel of

Original image Zoom processing Gray scaleconversion

resholdsegmentation Feature extractionImage aer

preprocessing

Figure 3 Image preprocessing process

HlowastWlowastM

k=1c=s1

HlowastWlowastS1

k=1c=e1 k=3c=e2

HlowastWlowaste1 HlowastWlowaste2

concat

squeeze

expand

HlowastWlowast(e1+e2)

Figure 4 Fire basic module algorithm structure

4 Mathematical Problems in Engineering

different sizes which is executed independently on eachdepth slice of the input If the input layer is a convolutionlayer and the first layer is a pooling layer the expression ofthe convolution layer is shown in the following formula

flj σ βl

jdown xlminus1j1113872 1113873 + b

lj1113960 1113961 (4)

where down(middot) represents the downsampling function and βlj

represents multiplicative biasAfter the continuous iterative cycle of the convolution

layer and the pooling layer it becomes the fully connectedlayer )e fully connected layer is used as the output layerwhich is used to calculate the score used as the output cat-egory of the network )e fully connected layer has generalparameters used for layer and super-parameters )e fullyconnected layer performs conversion on the input datavolume which is a function of the activation and parameters(weights and biases of neurons) in the input space )eSoftMax function is used as shown in the following formula

Si exp xi( 1113857

1113936nj1 exp xj1113872 1113873

(5)

where Si represents the output of the ith neuron n representsthe number of neurons and xi represents the input signal

In this paper mango grades are divided into four cat-egories which are first-grade mango second-grade mangothird-grade mango and NG

32Model Building Based onConvolutional Neural Networks)epretraining model based onHDevelop is used in HALCONsoftware )e input layer of convolutional neural network is animage that has three channels )e size of the original image is500lowast374 pixels Based on the pretraining model of CNN theconvolutional neural network is built Based on the pretrainingmodel of CNN a convolutional neural network is constructedby superimposing convolution layer pooling layer and fullyconnected layer)en the processed image is output and finallymango grade classification is carried out )e specific convo-lution process is shown in Figure 6

33 SuperParameterSetting In machine learning there arenot only the parameters of the model but also the pa-rameters that can make the network train better and fasterby tuning )ese tuning parameters are called super-pa-rameters )ey are responsible for controlling the selec-tion of optimization function and model during thetraining of learning algorithm )e key point of selectingsuper-parameters is to ensure that the model is neitherunder fitting nor just fitting the training data set and learnthe data structure as soon as possible

Parameter of learning rate refers to the amount of pa-rameter adjustment in the process of optimization in order tominimize the error of neural network prediction A largecoefficient of learning rate will make the parameters jumpwhile a small coefficient of learning rate (eg 0000001) willcause the parameters to change slowly)erefore the selectionof learning rate is particularly important )e parameter ofmomentum can help the learning algorithm get rid of thesearch space and keep the whole system in a stagnant state Asuitable momentum value can help to build a higher qualitymodel In order to prevent overfitting in machine learningresulting in parameters out of control regularization is neededto find a suitable fitting and maintain some low feature weightvalue

Because the number of samples is relatively small a smallnumber of samples are used to train the network Based onthe small batch stochastic gradient descent algorithm withmomentum the loss function is a polynomial combiningcross entropy error and regularization term )e calculationmethod is shown in the following formulas

mq+1

αmq

minus σnablanL f z nq

( 1113857( 1113857 (6)

nq+1

nq

+ mq+1

(7)

L(f(z n)) minus1N

1113944

Nminus1

n0ya log f za n( 1113857( 1113857( 1113857 +

β2

1113944

Kminus 1

k0nk

111386811138681113868111386811138681113868111386811138682

(8)

Input layerInput

Output

500lowast374lowast3

500lowast374lowast3

Conv 1DInput

Output

500lowast374lowast3

250lowast187lowast64

InputOutput

31lowast23lowast4

1lowast1lowast4

Fire4Input

Output

62lowast46lowast256

62lowast46lowast256

Fire6Input

Output

31lowast23lowast384

31lowast23lowast384

Fire5Input

Output

31lowast23lowast256

31lowast23lowast384

Fire3Input

Output

62lowast46lowast128

62lowast46lowast256

MaxPoolingInput

Output

25018764

1259364

Fire2Input

Output

125lowast93lowast128

125lowast93lowast128Conv 1D

InputOutput

31lowast23lowast512

31lowast23lowast4

MaxPoolingInput

Output

62lowast46lowast256

31lowast23lowast256DropOut

InputOutput

31lowast23lowast512

31lowast23lowast512

MaxPooling InputOutput

125lowast93lowast128

62lowast46lowast128

Fire1Input

Output

125lowast93lowast64

125lowast93lowast128

SoMaxInput

Output

1lowast1lowast4

1lowast1lowast4Fire7

InputOutput

31lowast23lowast384

31lowast23lowast512

Fire8Input

Output

31lowast23lowast512

31lowast23lowast512

Classification result first-grade mangosecond-grade mango third-grade mango

and NG

GlobalAveragePooling

Figure 5 CNN training structure

Mathematical Problems in Engineering 5

where α represents momentum σ represents learning ratef(z n) represents the results of classification L(middot) representsloss function n represents weight parameter z representsthe input batch ya represents the encoding of the ath imageza β represents regularization parameter and k representsthe number of weights

4 Experiment and Data Analysis

41 Parameter Test and Results During experiments theparameter ldquobatch_sizerdquo is set as 8 and the ldquoepochrdquo is set as 30In order to avoid overfitting the regularization parameter isset as 00005 )e specific experiment is based on the in-fluence on the verification set and accuracy rate while thelearning rate is ldquo01 001 and 0001rdquo and the momentum isldquo05 07 and 09rdquo respectively )e experimental data areshown in Table 2

Based on the experimental data the final choice oflearning rate is 0001 and momentum size is 09 But fromthe accuracy it does not achieve the ideal accuracy)erefore it is necessary to adjust the parametersldquobatch_sizerdquo and ldquoepochrdquo to achieve the ideal training effectDue to the limitation of experimental hardware test con-ditions and the number of samples the batch size interval 4is selected for the test which is ldquo12 16 and 20rdquo respectivelyand the cycle number interval 20 is selected for the testwhich is ldquo80 100 and 120rdquo respectively )e experimentaldata are shown in Table 3

Obviously when the ldquobatch_sizerdquo is set as 16 and thecycle of ldquoepochrdquo is set as 120 the accuracy is significantlyhigher than that of other groups After a total of 720 iter-ations the training time is 73 s which means that it takesonly 023 s on average to process a 500times 374 imageachieving the expected effect So far the whole modelpreprocessing and training process parameter adjustmenthave been completed

42 Model Evaluation and Performance Analysis )roughthe above optimal adjustment of the super-parameters ofthe neural network with the increasing number of it-erations the loss function curve gradually becomesconvergent with the increasing cycle and the results are

shown in Figure 7 By adjusting the appropriate super-parameters the average error rate of the training set andthe average error rate of the verification set are con-vergent with the increase of the period as shown inFigure 8

It can be seen from Figures 7 and 8 that with the increaseof the training cycle to about 35 cycles the accuracy of thewhole CNN-based neural network is significantly improvedAt the same time the overall error rapidly drops to less than05 and the overall error drops to less than 021 whichachieves good model processing effect

43 Robustness and Comparative Analysis In order to verifythe robustness of the networkmodel 35 samples were testedAmong them mango grading refers to the mango standardof the Peoplersquos Republic of China ldquoNYT3011-2016rdquo asshown in Table 4

)e test results are shown in Table 5 which gives theconfusion matrix of thirty-five mangoes verification sets)e experimental results show that only one first-grademango is misjudged to third-grade one in machinerecognition

Confusion matrix also known as error matrix is astandard format for accuracy evaluation )e confusionmatrix is a matrix with n row times n column It has manyevaluation indexes such as overall accuracy and useraccuracy It can characterize the accuracy of image clas-sification through the evaluation index In the process ofdeep learning confusion matrix is a visual tool to su-pervise the learning process Among them the column ofconfusion matrix represents the prediction category andthe horizontal row represents the real belonging categoryof data

)e 38 mango images used in the test are imported intothe convolutional neural network model which has beenpretrained and run in HDevelop environment for classifi-cation)e result is as shown in Table 6 Only one first-grademango is judged as positive sample but in fact it is negativesample that is the type II error in statistics )e accuracy is9091 )ere is a certain similarity between first-grademango and second-grademango and their F1-score is 9524)e principle expression of F1-score is as follows

Output layer

Fully connectedlayer ConvolutionReLu

Pooling ReLu

Pooling Convolution

Mango input layer Featuremapping

Figure 6 Mango convolutional neural network model

6 Mathematical Problems in Engineering

Table 2 Influence of different parameters on error and accuracy of the data set

Experiment number Learning rate Momentum Verification Top1 error Test set accuracy Loss1

000805 mdash mdash mdash

2 07 0800 284 8703 09 0800 235 10184

000505 0353 600 139

5 07 0529 333 1726 09 0765 205 1937

000105 0176 800 055

8 07 0168 866 0489 09 0114 887 043

Table 3 Different batch size and epoch parameters on training results

Experiment number Batch size Iterations Epoch Accuracy () Top1 error Loss Running time (s)1

12560 80 882 0118 044 56

2 700 100 706 0294 079 633 360 120 844 0124 058 764

16480 80 800 0210 1377 56

5 600 100 867 0113 0443 706 720 120 958 0059 0441 737

20400 80 765 0235 1416 68

8 500 100 867 0113 0444 749 600 120 802 0220 1416 84

00 300 600 900 1200Epoch

0

05

1

15

2

Loss

Loss

Figure 7 Curve of training loss error

00 300 600 900 1200Epoch

0

021

041

062

082

Top-

1 Er

ror

Top-1 Error TrainingTop-1 Error Validation

Figure 8 Curve of training error and validation error with periodic error rates

Mathematical Problems in Engineering 7

F1minusscore 2 times Precision times RecallPrecision + Recall

(9)

where Precision represents the accuracy of a single class andRecall represents the regression rate (the accuracy of the truevalue is zero)

According to the mango quality grade index NYT3011-2016 corresponding to Table 4 the accuracy of mango gradeclassification is analyzed )e analysis results are shown inTable 7 )e overall accuracy of the test results reaches9737 and only one first-grade mango is misjudged assecond grade which achieves the expected accuracy

Heat map also known as thermal map is a graphicrepresentation of the features of an object with the form of aspecial highlight By observing the heat map we can intu-itively find the userrsquos overall access and other characteristicsHeat map analysis can often intuitively observe the prom-inent features of the image with the help of heat map canaccurately capture the target features By using heat mapHDevelop development environment successfully combinesthe results of deep learning confidence and visual featureswhich make the whole classification process more intuitiveTwo mango images are randomly selected from each grade

of the test results and the unprocessed images are analyzedwith the heat map to find the target defect location as shownin Figure 9

)e belief propagation algorithm updates the mark stateof the whole Markov random field (MRF) by transferringinformation between nodes which is an approximate cal-culation based on MRF )e belief propagation algorithm isan iterative algorithm which is mainly used to solve theprobability inference problem of probability graph modelAt the same time all information can be spread in parallel Inthis experiment some confidence data of mango graderecognition result graph are randomly selected as shown inTable 8

)e confidence level is replaced by the probability dis-tribution principle formula of probability as shown in thefollowing formula

bi xi( 1113857 1zϕi xi yi( 1113857 1113945

jisinN(i)

mji xi( 1113857 (10)

where bi(xi) represents the joint probability distribution ofnode imji(xi) represents the message that the implied node jpasses to the implied node i Φi(xi yi) represents the local

Table 5 Mango verification set confusion matrix

Calibration classPrediction

First-grade Second-grade )ird-grade NGFirst-grade 10 0 1 0Second-grade 0 8 0 0)ird-grade 0 0 9 0NG 0 0 0 7

Table 4 Quality grade of mango NYT 3011-2016

Grade Requirement

First-grade mango Mango fruit shape is not deformed and size is uniform )e color of the fruit is normal and uniform )e pericarp issmooth almost without defects with no more than 2 single spots and the diameter of each spot is less than 2mm

Second-grademango

Mango fruit shape has no obvious deformation)e color of the fruit is normal and more than 75 of the fruit surfaceis uniform )e pericarp is smooth with no more than 4 spots per fruit and the diameter of each spot is less than

3mm

)ird-grademango

Deformation of mango fruit shape is not allowed to affect the quality of mango products )e color of the fruit isnormal andmore than 35 of the fruit surface is uniform)e pericarp is relatively smooth with nomore than 6 spots

per fruit and the diameter of each spot is less than 3mm

Table 6 Test set classification data matrix

Class FP Precision () FN Recall () F1minusscore () Total

First-grade mango 1 9091 0 100 9524 10

Second-grade mango 0 100 1 9091 9524 11

)ird-grade mango 0 100 0 100 100 8

NG 0 100 0 100 100 9

8 Mathematical Problems in Engineering

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 5: Mango Grading System Based on Optimized Convolutional

different sizes which is executed independently on eachdepth slice of the input If the input layer is a convolutionlayer and the first layer is a pooling layer the expression ofthe convolution layer is shown in the following formula

flj σ βl

jdown xlminus1j1113872 1113873 + b

lj1113960 1113961 (4)

where down(middot) represents the downsampling function and βlj

represents multiplicative biasAfter the continuous iterative cycle of the convolution

layer and the pooling layer it becomes the fully connectedlayer )e fully connected layer is used as the output layerwhich is used to calculate the score used as the output cat-egory of the network )e fully connected layer has generalparameters used for layer and super-parameters )e fullyconnected layer performs conversion on the input datavolume which is a function of the activation and parameters(weights and biases of neurons) in the input space )eSoftMax function is used as shown in the following formula

Si exp xi( 1113857

1113936nj1 exp xj1113872 1113873

(5)

where Si represents the output of the ith neuron n representsthe number of neurons and xi represents the input signal

In this paper mango grades are divided into four cat-egories which are first-grade mango second-grade mangothird-grade mango and NG

32Model Building Based onConvolutional Neural Networks)epretraining model based onHDevelop is used in HALCONsoftware )e input layer of convolutional neural network is animage that has three channels )e size of the original image is500lowast374 pixels Based on the pretraining model of CNN theconvolutional neural network is built Based on the pretrainingmodel of CNN a convolutional neural network is constructedby superimposing convolution layer pooling layer and fullyconnected layer)en the processed image is output and finallymango grade classification is carried out )e specific convo-lution process is shown in Figure 6

33 SuperParameterSetting In machine learning there arenot only the parameters of the model but also the pa-rameters that can make the network train better and fasterby tuning )ese tuning parameters are called super-pa-rameters )ey are responsible for controlling the selec-tion of optimization function and model during thetraining of learning algorithm )e key point of selectingsuper-parameters is to ensure that the model is neitherunder fitting nor just fitting the training data set and learnthe data structure as soon as possible

Parameter of learning rate refers to the amount of pa-rameter adjustment in the process of optimization in order tominimize the error of neural network prediction A largecoefficient of learning rate will make the parameters jumpwhile a small coefficient of learning rate (eg 0000001) willcause the parameters to change slowly)erefore the selectionof learning rate is particularly important )e parameter ofmomentum can help the learning algorithm get rid of thesearch space and keep the whole system in a stagnant state Asuitable momentum value can help to build a higher qualitymodel In order to prevent overfitting in machine learningresulting in parameters out of control regularization is neededto find a suitable fitting and maintain some low feature weightvalue

Because the number of samples is relatively small a smallnumber of samples are used to train the network Based onthe small batch stochastic gradient descent algorithm withmomentum the loss function is a polynomial combiningcross entropy error and regularization term )e calculationmethod is shown in the following formulas

mq+1

αmq

minus σnablanL f z nq

( 1113857( 1113857 (6)

nq+1

nq

+ mq+1

(7)

L(f(z n)) minus1N

1113944

Nminus1

n0ya log f za n( 1113857( 1113857( 1113857 +

β2

1113944

Kminus 1

k0nk

111386811138681113868111386811138681113868111386811138682

(8)

Input layerInput

Output

500lowast374lowast3

500lowast374lowast3

Conv 1DInput

Output

500lowast374lowast3

250lowast187lowast64

InputOutput

31lowast23lowast4

1lowast1lowast4

Fire4Input

Output

62lowast46lowast256

62lowast46lowast256

Fire6Input

Output

31lowast23lowast384

31lowast23lowast384

Fire5Input

Output

31lowast23lowast256

31lowast23lowast384

Fire3Input

Output

62lowast46lowast128

62lowast46lowast256

MaxPoolingInput

Output

25018764

1259364

Fire2Input

Output

125lowast93lowast128

125lowast93lowast128Conv 1D

InputOutput

31lowast23lowast512

31lowast23lowast4

MaxPoolingInput

Output

62lowast46lowast256

31lowast23lowast256DropOut

InputOutput

31lowast23lowast512

31lowast23lowast512

MaxPooling InputOutput

125lowast93lowast128

62lowast46lowast128

Fire1Input

Output

125lowast93lowast64

125lowast93lowast128

SoMaxInput

Output

1lowast1lowast4

1lowast1lowast4Fire7

InputOutput

31lowast23lowast384

31lowast23lowast512

Fire8Input

Output

31lowast23lowast512

31lowast23lowast512

Classification result first-grade mangosecond-grade mango third-grade mango

and NG

GlobalAveragePooling

Figure 5 CNN training structure

Mathematical Problems in Engineering 5

where α represents momentum σ represents learning ratef(z n) represents the results of classification L(middot) representsloss function n represents weight parameter z representsthe input batch ya represents the encoding of the ath imageza β represents regularization parameter and k representsthe number of weights

4 Experiment and Data Analysis

41 Parameter Test and Results During experiments theparameter ldquobatch_sizerdquo is set as 8 and the ldquoepochrdquo is set as 30In order to avoid overfitting the regularization parameter isset as 00005 )e specific experiment is based on the in-fluence on the verification set and accuracy rate while thelearning rate is ldquo01 001 and 0001rdquo and the momentum isldquo05 07 and 09rdquo respectively )e experimental data areshown in Table 2

Based on the experimental data the final choice oflearning rate is 0001 and momentum size is 09 But fromthe accuracy it does not achieve the ideal accuracy)erefore it is necessary to adjust the parametersldquobatch_sizerdquo and ldquoepochrdquo to achieve the ideal training effectDue to the limitation of experimental hardware test con-ditions and the number of samples the batch size interval 4is selected for the test which is ldquo12 16 and 20rdquo respectivelyand the cycle number interval 20 is selected for the testwhich is ldquo80 100 and 120rdquo respectively )e experimentaldata are shown in Table 3

Obviously when the ldquobatch_sizerdquo is set as 16 and thecycle of ldquoepochrdquo is set as 120 the accuracy is significantlyhigher than that of other groups After a total of 720 iter-ations the training time is 73 s which means that it takesonly 023 s on average to process a 500times 374 imageachieving the expected effect So far the whole modelpreprocessing and training process parameter adjustmenthave been completed

42 Model Evaluation and Performance Analysis )roughthe above optimal adjustment of the super-parameters ofthe neural network with the increasing number of it-erations the loss function curve gradually becomesconvergent with the increasing cycle and the results are

shown in Figure 7 By adjusting the appropriate super-parameters the average error rate of the training set andthe average error rate of the verification set are con-vergent with the increase of the period as shown inFigure 8

It can be seen from Figures 7 and 8 that with the increaseof the training cycle to about 35 cycles the accuracy of thewhole CNN-based neural network is significantly improvedAt the same time the overall error rapidly drops to less than05 and the overall error drops to less than 021 whichachieves good model processing effect

43 Robustness and Comparative Analysis In order to verifythe robustness of the networkmodel 35 samples were testedAmong them mango grading refers to the mango standardof the Peoplersquos Republic of China ldquoNYT3011-2016rdquo asshown in Table 4

)e test results are shown in Table 5 which gives theconfusion matrix of thirty-five mangoes verification sets)e experimental results show that only one first-grademango is misjudged to third-grade one in machinerecognition

Confusion matrix also known as error matrix is astandard format for accuracy evaluation )e confusionmatrix is a matrix with n row times n column It has manyevaluation indexes such as overall accuracy and useraccuracy It can characterize the accuracy of image clas-sification through the evaluation index In the process ofdeep learning confusion matrix is a visual tool to su-pervise the learning process Among them the column ofconfusion matrix represents the prediction category andthe horizontal row represents the real belonging categoryof data

)e 38 mango images used in the test are imported intothe convolutional neural network model which has beenpretrained and run in HDevelop environment for classifi-cation)e result is as shown in Table 6 Only one first-grademango is judged as positive sample but in fact it is negativesample that is the type II error in statistics )e accuracy is9091 )ere is a certain similarity between first-grademango and second-grademango and their F1-score is 9524)e principle expression of F1-score is as follows

Output layer

Fully connectedlayer ConvolutionReLu

Pooling ReLu

Pooling Convolution

Mango input layer Featuremapping

Figure 6 Mango convolutional neural network model

6 Mathematical Problems in Engineering

Table 2 Influence of different parameters on error and accuracy of the data set

Experiment number Learning rate Momentum Verification Top1 error Test set accuracy Loss1

000805 mdash mdash mdash

2 07 0800 284 8703 09 0800 235 10184

000505 0353 600 139

5 07 0529 333 1726 09 0765 205 1937

000105 0176 800 055

8 07 0168 866 0489 09 0114 887 043

Table 3 Different batch size and epoch parameters on training results

Experiment number Batch size Iterations Epoch Accuracy () Top1 error Loss Running time (s)1

12560 80 882 0118 044 56

2 700 100 706 0294 079 633 360 120 844 0124 058 764

16480 80 800 0210 1377 56

5 600 100 867 0113 0443 706 720 120 958 0059 0441 737

20400 80 765 0235 1416 68

8 500 100 867 0113 0444 749 600 120 802 0220 1416 84

00 300 600 900 1200Epoch

0

05

1

15

2

Loss

Loss

Figure 7 Curve of training loss error

00 300 600 900 1200Epoch

0

021

041

062

082

Top-

1 Er

ror

Top-1 Error TrainingTop-1 Error Validation

Figure 8 Curve of training error and validation error with periodic error rates

Mathematical Problems in Engineering 7

F1minusscore 2 times Precision times RecallPrecision + Recall

(9)

where Precision represents the accuracy of a single class andRecall represents the regression rate (the accuracy of the truevalue is zero)

According to the mango quality grade index NYT3011-2016 corresponding to Table 4 the accuracy of mango gradeclassification is analyzed )e analysis results are shown inTable 7 )e overall accuracy of the test results reaches9737 and only one first-grade mango is misjudged assecond grade which achieves the expected accuracy

Heat map also known as thermal map is a graphicrepresentation of the features of an object with the form of aspecial highlight By observing the heat map we can intu-itively find the userrsquos overall access and other characteristicsHeat map analysis can often intuitively observe the prom-inent features of the image with the help of heat map canaccurately capture the target features By using heat mapHDevelop development environment successfully combinesthe results of deep learning confidence and visual featureswhich make the whole classification process more intuitiveTwo mango images are randomly selected from each grade

of the test results and the unprocessed images are analyzedwith the heat map to find the target defect location as shownin Figure 9

)e belief propagation algorithm updates the mark stateof the whole Markov random field (MRF) by transferringinformation between nodes which is an approximate cal-culation based on MRF )e belief propagation algorithm isan iterative algorithm which is mainly used to solve theprobability inference problem of probability graph modelAt the same time all information can be spread in parallel Inthis experiment some confidence data of mango graderecognition result graph are randomly selected as shown inTable 8

)e confidence level is replaced by the probability dis-tribution principle formula of probability as shown in thefollowing formula

bi xi( 1113857 1zϕi xi yi( 1113857 1113945

jisinN(i)

mji xi( 1113857 (10)

where bi(xi) represents the joint probability distribution ofnode imji(xi) represents the message that the implied node jpasses to the implied node i Φi(xi yi) represents the local

Table 5 Mango verification set confusion matrix

Calibration classPrediction

First-grade Second-grade )ird-grade NGFirst-grade 10 0 1 0Second-grade 0 8 0 0)ird-grade 0 0 9 0NG 0 0 0 7

Table 4 Quality grade of mango NYT 3011-2016

Grade Requirement

First-grade mango Mango fruit shape is not deformed and size is uniform )e color of the fruit is normal and uniform )e pericarp issmooth almost without defects with no more than 2 single spots and the diameter of each spot is less than 2mm

Second-grademango

Mango fruit shape has no obvious deformation)e color of the fruit is normal and more than 75 of the fruit surfaceis uniform )e pericarp is smooth with no more than 4 spots per fruit and the diameter of each spot is less than

3mm

)ird-grademango

Deformation of mango fruit shape is not allowed to affect the quality of mango products )e color of the fruit isnormal andmore than 35 of the fruit surface is uniform)e pericarp is relatively smooth with nomore than 6 spots

per fruit and the diameter of each spot is less than 3mm

Table 6 Test set classification data matrix

Class FP Precision () FN Recall () F1minusscore () Total

First-grade mango 1 9091 0 100 9524 10

Second-grade mango 0 100 1 9091 9524 11

)ird-grade mango 0 100 0 100 100 8

NG 0 100 0 100 100 9

8 Mathematical Problems in Engineering

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 6: Mango Grading System Based on Optimized Convolutional

where α represents momentum σ represents learning ratef(z n) represents the results of classification L(middot) representsloss function n represents weight parameter z representsthe input batch ya represents the encoding of the ath imageza β represents regularization parameter and k representsthe number of weights

4 Experiment and Data Analysis

41 Parameter Test and Results During experiments theparameter ldquobatch_sizerdquo is set as 8 and the ldquoepochrdquo is set as 30In order to avoid overfitting the regularization parameter isset as 00005 )e specific experiment is based on the in-fluence on the verification set and accuracy rate while thelearning rate is ldquo01 001 and 0001rdquo and the momentum isldquo05 07 and 09rdquo respectively )e experimental data areshown in Table 2

Based on the experimental data the final choice oflearning rate is 0001 and momentum size is 09 But fromthe accuracy it does not achieve the ideal accuracy)erefore it is necessary to adjust the parametersldquobatch_sizerdquo and ldquoepochrdquo to achieve the ideal training effectDue to the limitation of experimental hardware test con-ditions and the number of samples the batch size interval 4is selected for the test which is ldquo12 16 and 20rdquo respectivelyand the cycle number interval 20 is selected for the testwhich is ldquo80 100 and 120rdquo respectively )e experimentaldata are shown in Table 3

Obviously when the ldquobatch_sizerdquo is set as 16 and thecycle of ldquoepochrdquo is set as 120 the accuracy is significantlyhigher than that of other groups After a total of 720 iter-ations the training time is 73 s which means that it takesonly 023 s on average to process a 500times 374 imageachieving the expected effect So far the whole modelpreprocessing and training process parameter adjustmenthave been completed

42 Model Evaluation and Performance Analysis )roughthe above optimal adjustment of the super-parameters ofthe neural network with the increasing number of it-erations the loss function curve gradually becomesconvergent with the increasing cycle and the results are

shown in Figure 7 By adjusting the appropriate super-parameters the average error rate of the training set andthe average error rate of the verification set are con-vergent with the increase of the period as shown inFigure 8

It can be seen from Figures 7 and 8 that with the increaseof the training cycle to about 35 cycles the accuracy of thewhole CNN-based neural network is significantly improvedAt the same time the overall error rapidly drops to less than05 and the overall error drops to less than 021 whichachieves good model processing effect

43 Robustness and Comparative Analysis In order to verifythe robustness of the networkmodel 35 samples were testedAmong them mango grading refers to the mango standardof the Peoplersquos Republic of China ldquoNYT3011-2016rdquo asshown in Table 4

)e test results are shown in Table 5 which gives theconfusion matrix of thirty-five mangoes verification sets)e experimental results show that only one first-grademango is misjudged to third-grade one in machinerecognition

Confusion matrix also known as error matrix is astandard format for accuracy evaluation )e confusionmatrix is a matrix with n row times n column It has manyevaluation indexes such as overall accuracy and useraccuracy It can characterize the accuracy of image clas-sification through the evaluation index In the process ofdeep learning confusion matrix is a visual tool to su-pervise the learning process Among them the column ofconfusion matrix represents the prediction category andthe horizontal row represents the real belonging categoryof data

)e 38 mango images used in the test are imported intothe convolutional neural network model which has beenpretrained and run in HDevelop environment for classifi-cation)e result is as shown in Table 6 Only one first-grademango is judged as positive sample but in fact it is negativesample that is the type II error in statistics )e accuracy is9091 )ere is a certain similarity between first-grademango and second-grademango and their F1-score is 9524)e principle expression of F1-score is as follows

Output layer

Fully connectedlayer ConvolutionReLu

Pooling ReLu

Pooling Convolution

Mango input layer Featuremapping

Figure 6 Mango convolutional neural network model

6 Mathematical Problems in Engineering

Table 2 Influence of different parameters on error and accuracy of the data set

Experiment number Learning rate Momentum Verification Top1 error Test set accuracy Loss1

000805 mdash mdash mdash

2 07 0800 284 8703 09 0800 235 10184

000505 0353 600 139

5 07 0529 333 1726 09 0765 205 1937

000105 0176 800 055

8 07 0168 866 0489 09 0114 887 043

Table 3 Different batch size and epoch parameters on training results

Experiment number Batch size Iterations Epoch Accuracy () Top1 error Loss Running time (s)1

12560 80 882 0118 044 56

2 700 100 706 0294 079 633 360 120 844 0124 058 764

16480 80 800 0210 1377 56

5 600 100 867 0113 0443 706 720 120 958 0059 0441 737

20400 80 765 0235 1416 68

8 500 100 867 0113 0444 749 600 120 802 0220 1416 84

00 300 600 900 1200Epoch

0

05

1

15

2

Loss

Loss

Figure 7 Curve of training loss error

00 300 600 900 1200Epoch

0

021

041

062

082

Top-

1 Er

ror

Top-1 Error TrainingTop-1 Error Validation

Figure 8 Curve of training error and validation error with periodic error rates

Mathematical Problems in Engineering 7

F1minusscore 2 times Precision times RecallPrecision + Recall

(9)

where Precision represents the accuracy of a single class andRecall represents the regression rate (the accuracy of the truevalue is zero)

According to the mango quality grade index NYT3011-2016 corresponding to Table 4 the accuracy of mango gradeclassification is analyzed )e analysis results are shown inTable 7 )e overall accuracy of the test results reaches9737 and only one first-grade mango is misjudged assecond grade which achieves the expected accuracy

Heat map also known as thermal map is a graphicrepresentation of the features of an object with the form of aspecial highlight By observing the heat map we can intu-itively find the userrsquos overall access and other characteristicsHeat map analysis can often intuitively observe the prom-inent features of the image with the help of heat map canaccurately capture the target features By using heat mapHDevelop development environment successfully combinesthe results of deep learning confidence and visual featureswhich make the whole classification process more intuitiveTwo mango images are randomly selected from each grade

of the test results and the unprocessed images are analyzedwith the heat map to find the target defect location as shownin Figure 9

)e belief propagation algorithm updates the mark stateof the whole Markov random field (MRF) by transferringinformation between nodes which is an approximate cal-culation based on MRF )e belief propagation algorithm isan iterative algorithm which is mainly used to solve theprobability inference problem of probability graph modelAt the same time all information can be spread in parallel Inthis experiment some confidence data of mango graderecognition result graph are randomly selected as shown inTable 8

)e confidence level is replaced by the probability dis-tribution principle formula of probability as shown in thefollowing formula

bi xi( 1113857 1zϕi xi yi( 1113857 1113945

jisinN(i)

mji xi( 1113857 (10)

where bi(xi) represents the joint probability distribution ofnode imji(xi) represents the message that the implied node jpasses to the implied node i Φi(xi yi) represents the local

Table 5 Mango verification set confusion matrix

Calibration classPrediction

First-grade Second-grade )ird-grade NGFirst-grade 10 0 1 0Second-grade 0 8 0 0)ird-grade 0 0 9 0NG 0 0 0 7

Table 4 Quality grade of mango NYT 3011-2016

Grade Requirement

First-grade mango Mango fruit shape is not deformed and size is uniform )e color of the fruit is normal and uniform )e pericarp issmooth almost without defects with no more than 2 single spots and the diameter of each spot is less than 2mm

Second-grademango

Mango fruit shape has no obvious deformation)e color of the fruit is normal and more than 75 of the fruit surfaceis uniform )e pericarp is smooth with no more than 4 spots per fruit and the diameter of each spot is less than

3mm

)ird-grademango

Deformation of mango fruit shape is not allowed to affect the quality of mango products )e color of the fruit isnormal andmore than 35 of the fruit surface is uniform)e pericarp is relatively smooth with nomore than 6 spots

per fruit and the diameter of each spot is less than 3mm

Table 6 Test set classification data matrix

Class FP Precision () FN Recall () F1minusscore () Total

First-grade mango 1 9091 0 100 9524 10

Second-grade mango 0 100 1 9091 9524 11

)ird-grade mango 0 100 0 100 100 8

NG 0 100 0 100 100 9

8 Mathematical Problems in Engineering

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 7: Mango Grading System Based on Optimized Convolutional

Table 2 Influence of different parameters on error and accuracy of the data set

Experiment number Learning rate Momentum Verification Top1 error Test set accuracy Loss1

000805 mdash mdash mdash

2 07 0800 284 8703 09 0800 235 10184

000505 0353 600 139

5 07 0529 333 1726 09 0765 205 1937

000105 0176 800 055

8 07 0168 866 0489 09 0114 887 043

Table 3 Different batch size and epoch parameters on training results

Experiment number Batch size Iterations Epoch Accuracy () Top1 error Loss Running time (s)1

12560 80 882 0118 044 56

2 700 100 706 0294 079 633 360 120 844 0124 058 764

16480 80 800 0210 1377 56

5 600 100 867 0113 0443 706 720 120 958 0059 0441 737

20400 80 765 0235 1416 68

8 500 100 867 0113 0444 749 600 120 802 0220 1416 84

00 300 600 900 1200Epoch

0

05

1

15

2

Loss

Loss

Figure 7 Curve of training loss error

00 300 600 900 1200Epoch

0

021

041

062

082

Top-

1 Er

ror

Top-1 Error TrainingTop-1 Error Validation

Figure 8 Curve of training error and validation error with periodic error rates

Mathematical Problems in Engineering 7

F1minusscore 2 times Precision times RecallPrecision + Recall

(9)

where Precision represents the accuracy of a single class andRecall represents the regression rate (the accuracy of the truevalue is zero)

According to the mango quality grade index NYT3011-2016 corresponding to Table 4 the accuracy of mango gradeclassification is analyzed )e analysis results are shown inTable 7 )e overall accuracy of the test results reaches9737 and only one first-grade mango is misjudged assecond grade which achieves the expected accuracy

Heat map also known as thermal map is a graphicrepresentation of the features of an object with the form of aspecial highlight By observing the heat map we can intu-itively find the userrsquos overall access and other characteristicsHeat map analysis can often intuitively observe the prom-inent features of the image with the help of heat map canaccurately capture the target features By using heat mapHDevelop development environment successfully combinesthe results of deep learning confidence and visual featureswhich make the whole classification process more intuitiveTwo mango images are randomly selected from each grade

of the test results and the unprocessed images are analyzedwith the heat map to find the target defect location as shownin Figure 9

)e belief propagation algorithm updates the mark stateof the whole Markov random field (MRF) by transferringinformation between nodes which is an approximate cal-culation based on MRF )e belief propagation algorithm isan iterative algorithm which is mainly used to solve theprobability inference problem of probability graph modelAt the same time all information can be spread in parallel Inthis experiment some confidence data of mango graderecognition result graph are randomly selected as shown inTable 8

)e confidence level is replaced by the probability dis-tribution principle formula of probability as shown in thefollowing formula

bi xi( 1113857 1zϕi xi yi( 1113857 1113945

jisinN(i)

mji xi( 1113857 (10)

where bi(xi) represents the joint probability distribution ofnode imji(xi) represents the message that the implied node jpasses to the implied node i Φi(xi yi) represents the local

Table 5 Mango verification set confusion matrix

Calibration classPrediction

First-grade Second-grade )ird-grade NGFirst-grade 10 0 1 0Second-grade 0 8 0 0)ird-grade 0 0 9 0NG 0 0 0 7

Table 4 Quality grade of mango NYT 3011-2016

Grade Requirement

First-grade mango Mango fruit shape is not deformed and size is uniform )e color of the fruit is normal and uniform )e pericarp issmooth almost without defects with no more than 2 single spots and the diameter of each spot is less than 2mm

Second-grademango

Mango fruit shape has no obvious deformation)e color of the fruit is normal and more than 75 of the fruit surfaceis uniform )e pericarp is smooth with no more than 4 spots per fruit and the diameter of each spot is less than

3mm

)ird-grademango

Deformation of mango fruit shape is not allowed to affect the quality of mango products )e color of the fruit isnormal andmore than 35 of the fruit surface is uniform)e pericarp is relatively smooth with nomore than 6 spots

per fruit and the diameter of each spot is less than 3mm

Table 6 Test set classification data matrix

Class FP Precision () FN Recall () F1minusscore () Total

First-grade mango 1 9091 0 100 9524 10

Second-grade mango 0 100 1 9091 9524 11

)ird-grade mango 0 100 0 100 100 8

NG 0 100 0 100 100 9

8 Mathematical Problems in Engineering

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 8: Mango Grading System Based on Optimized Convolutional

F1minusscore 2 times Precision times RecallPrecision + Recall

(9)

where Precision represents the accuracy of a single class andRecall represents the regression rate (the accuracy of the truevalue is zero)

According to the mango quality grade index NYT3011-2016 corresponding to Table 4 the accuracy of mango gradeclassification is analyzed )e analysis results are shown inTable 7 )e overall accuracy of the test results reaches9737 and only one first-grade mango is misjudged assecond grade which achieves the expected accuracy

Heat map also known as thermal map is a graphicrepresentation of the features of an object with the form of aspecial highlight By observing the heat map we can intu-itively find the userrsquos overall access and other characteristicsHeat map analysis can often intuitively observe the prom-inent features of the image with the help of heat map canaccurately capture the target features By using heat mapHDevelop development environment successfully combinesthe results of deep learning confidence and visual featureswhich make the whole classification process more intuitiveTwo mango images are randomly selected from each grade

of the test results and the unprocessed images are analyzedwith the heat map to find the target defect location as shownin Figure 9

)e belief propagation algorithm updates the mark stateof the whole Markov random field (MRF) by transferringinformation between nodes which is an approximate cal-culation based on MRF )e belief propagation algorithm isan iterative algorithm which is mainly used to solve theprobability inference problem of probability graph modelAt the same time all information can be spread in parallel Inthis experiment some confidence data of mango graderecognition result graph are randomly selected as shown inTable 8

)e confidence level is replaced by the probability dis-tribution principle formula of probability as shown in thefollowing formula

bi xi( 1113857 1zϕi xi yi( 1113857 1113945

jisinN(i)

mji xi( 1113857 (10)

where bi(xi) represents the joint probability distribution ofnode imji(xi) represents the message that the implied node jpasses to the implied node i Φi(xi yi) represents the local

Table 5 Mango verification set confusion matrix

Calibration classPrediction

First-grade Second-grade )ird-grade NGFirst-grade 10 0 1 0Second-grade 0 8 0 0)ird-grade 0 0 9 0NG 0 0 0 7

Table 4 Quality grade of mango NYT 3011-2016

Grade Requirement

First-grade mango Mango fruit shape is not deformed and size is uniform )e color of the fruit is normal and uniform )e pericarp issmooth almost without defects with no more than 2 single spots and the diameter of each spot is less than 2mm

Second-grademango

Mango fruit shape has no obvious deformation)e color of the fruit is normal and more than 75 of the fruit surfaceis uniform )e pericarp is smooth with no more than 4 spots per fruit and the diameter of each spot is less than

3mm

)ird-grademango

Deformation of mango fruit shape is not allowed to affect the quality of mango products )e color of the fruit isnormal andmore than 35 of the fruit surface is uniform)e pericarp is relatively smooth with nomore than 6 spots

per fruit and the diameter of each spot is less than 3mm

Table 6 Test set classification data matrix

Class FP Precision () FN Recall () F1minusscore () Total

First-grade mango 1 9091 0 100 9524 10

Second-grade mango 0 100 1 9091 9524 11

)ird-grade mango 0 100 0 100 100 8

NG 0 100 0 100 100 9

8 Mathematical Problems in Engineering

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 9: Mango Grading System Based on Optimized Convolutional

Table 7 Classification results of mango classification

Mango grade Sample numberIdentification number

Accuracy () Average accuracy ()First-grade Second-grade )ird-grade NG

First-grade 11 10 1 0 0 9091

9737Second-grade 10 0 0 10 0 100)ird-grade 8 0 0 0 8 100NG 9 0 9 0 0 100

(a) (b)

(c) (d)

Figure 9 Comparison of defect feature location in heat map Heat map of the (a) first-grade mango (b) second-grade mango (c) third-grade mango and (d) NG grade mango

Table 8 Test set confidence data analysis

Number Grade Confidence Average confidence 1 First-grade mango 973 9852 9973 Second-grade mango 999 9954 9915 )ird-grade mango 994 9826 9697 NG 999 9998 999

Mathematical Problems in Engineering 9

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 10: Mango Grading System Based on Optimized Convolutional

evidence of node i 1z represents sum of confidence whichcan be 1 N(i) represents the MRF first-order neighborhoodof node i)e information formula expression of messagepropagation is shown in the following formula

mji xi( 1113857 1113944xjisinxj

ϕj xj yj1113872 1113873ψji xj yj1113872 1113873 1113945xkisinN(j)i

mkj xj1113872 1113873(11)

where N(j)i represents the neighborhood of target node i isexcluded from the MRF first-order neighborhood of node jxi and xj represents the hidden node mji represents thedissemination of information

44 AlgorithmComparison In order to verify the rationalityof the proposed algorithm it is compared with the modelbased on HDevelop Due to the limitation of hardware thesame size data set is used to uniformly set the batch size as 8and the cycle as 60 times the momentum is defined as 09the learning rate is defined as 0001 and the regularizationparameter is defined as 00005 )e comparison results areshown in Table 9)e recognition accuracy of this method isthe highest reaching 9694 and the single recognitionspeed is only 257ms ResNet-50 model is usually used todeal with more complex environmental tasks and it has noobvious advantages in dealing with small batch data setssimilar to the one shown in this paper )e recognitionaccuracy of Enhanced is almost the same as that of thismethod but the processing speed is still not as fast as themodel used in this paper )e MobileNetV2 has poorperformance in dealing with small batch classification taskswith low recognition accuracy and the top1_error rate is2667

5 Conclusions

In this paper the deep learning method based on con-volutional neural network can effectively improve the rec-ognition accuracy of mango grade classification which ismore robust and efficient than the traditional feature rec-ognition algorithm By adjusting the super-parametersbatch size and period of convolutional neural network theCNN model can achieve high recognition rate while pro-cessing small batch data sets )e whole experimental erroranalysis converges to the expected range )rough the al-gorithm comparison experiment it is proved that the ultra-lightweight network SqueezeNet has the advantages ofsaving memory and running time when dealing with hier-archical classification tasks It is proved that this model canbetter deal with the task of nondamage deep learningclassification of small batch mango data sets )e optimizedCNN in this paper is used to classify mangoes Compared

with the current relevant models such as AlexNet andResNet-50 the accuracy is 9737 the average error rate isonly 263 and the processing time of an original imagewith a resolution of 500times 374 was only 257 millisecond)eslight blemishes or color spots on the surface of mango havea certain influence on mango grading Reducing the influ-ence of defects and color spots on mango grading is the partto be optimized More training samples are needed to im-prove the application value of the system)is system can beapplied at an industrial production but some modificationsshould be done

Data Availability

)e data can be obtained from the corresponding authorupon request

Conflicts of Interest

)e authors declare that they have no conflicts of interest

Acknowledgments

)is work was supported by the ldquoSeed Fundrdquo of Science andTechnology Park of Panzhihua University (no 2020-3) andthe Panzhihua Guiding Science and Technology Plan (no2019ZD-N-2)

References

[1] NYT492-2002 Agricultural Industry Standard of the PeoplersquosRepublic of China-Mango Standards Press of China BeijingChina 2002

[2] NYT3011-2016 Agricultural Industry Standard of the Peo-plersquos Republic of China-Mango Grade Specification StandardsPress of China Beijing China 2016

[3] Z H Yuan Y L Liao S J Weng and G P Wang ldquo)erelationship between dielectric properties and internal qualityof mangordquo Journal of Agricultural Mechanization Researchvol 33 no 10 pp 111ndash114 2011

[4] M Li Z Y Gao Z J Su Y Y Zhu and D Q Gong ldquoQualityevaluation of mango by fresh colorimetric measurementsrdquoChinese Journal of Topical Crops vol 38 no 1 pp 166ndash1702017

[5] H J Xin ldquoApplication of computer vision in mango qualitytestingrdquo Journal of Agricultural Mechanization Researchvol 41 no 9 pp 190ndash192 2019

[6] C H Liu X Li Z J Zhu et al ldquoProgress of non-destructivetesting technology in Mango qualityrdquo Science and Technologyof Food Industry pp 1ndash13 2021

[7] T W Wang Y Zhao Y X Sun R B Yang Z Z Han andJ Li ldquoRecognition approach based on data-balanced faster RCNN for winter jujube with different levels of maturityrdquo

Table 9 Comparison of recognition results of different algorithms

Method Recognition accuracy () Top1 error () Recognition time of single picture (ms)ResNet-50 8667 1333 1234Enhanced 9667 333 1041MobileNetV2 7333 2667 425)is paper 9694 306 257

10 Mathematical Problems in Engineering

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11

Page 11: Mango Grading System Based on Optimized Convolutional

Transactions of the Chinese Society for Agricultural Machineryvol 51 no S1 pp 457ndash463+492 2020

[8] P P Zeng and L S Li ldquoClassification and recognition ofcommon fruit images based on convolutional neural net-workrdquoMachine Design and Research vol 35 no 1 pp 23ndash262019

[9] L S Li and P P Eng ldquoApple target detection based onimproved faster-RCNN framework of deep learningrdquo Ma-chine Design and Research vol 35 no 5 pp 24ndash27 2019

[10] W Li T Hai S Wu J Wang and X Xu ldquoSemi-supervisedintelligent cognition method of greengage grade based ondeep learningrdquo Computer Applications and Software vol 35no 11 pp 245ndash252 2018

[11] G J Li X J Huang and X H Li ldquoDetection method of tree-ripe mango based on improved VOLOv3rdquo Journal of Shen-gyang Agricultural University vol 52 no 1 pp 70ndash78 2021

[12] Q Y Zhang B X Gu and C Y Ji ldquoDesign and experiment ofan online grading system for applerdquo Journal of South ChinaAgricultural University vol 38 no 4 pp 117ndash124 2017

[13] S Cubero N Aleixos E Molto J Gomez-Sanchis andJ Blasco ldquoAdvances in machine vision applications for au-tomatic inspection and quality evaluation of fruits and veg-etablesrdquo Food and Bioprocess Technology vol 4 no 4pp 487ndash504 2011

[14] H Y Jiang Y B Ying and J P Wang ldquoReal time intelligentinspecting and grading line of fruitsrdquo Transactions of theChinese Society of Agricultural Engineering vol 18 no 6pp 158ndash160 2002

[15] Z Y Wen and L P Cao ldquoImage recognition of navel orangediseases and insect pests based on compensatory fuzzy neuralnetworksrdquo Transactions of the Chinese Society of AgriculturalEngineering vol 28 no 11 pp 152ndash157 2002

[16] W Q Huang J B Li and C Zhang ldquoDetection of surfacedefects on fruits using spherical intensity transformationrdquoTransactions of the Chinese Society for Agricultural Machineryvol 43 no 12 pp 187ndash191 2012

[17] J B Li Y K Peng and W Q Huang ldquoWatershed seg-mentation method for segmenting defects on peach fruitsurfacerdquo Transactions of the Chinese Society for AgriculturalMachinery vol 45 no 8 pp 288ndash293 2014

[18] O Yuki ldquoAn automated fruit harvesting robot by using deeplearningrdquo Journal of Robomech vol 6 no 1 pp 1ndash8 2019

[19] I Nivetha and M Padmaa ldquoDisease detection in fruits usingconvolutional neural networksrdquo Journal of Innovation inElectronics and Communication Engineering vol 9 no 1pp 53ndash62 2019

[20] K D A Yogesh and R Rajeev ldquoDevelopment of feature basedclassification of fruit using deep learningrdquo InternationalJournal of Innovative Technology and Exploring Engineeringvol 8 no 12 pp 3285ndash3290 2019

[21] N Amin T G Amin and Y D Zhang ldquoImage-based deeplearning automated sorting of date fruitrdquo Postharvest Biologyand Technology vol 153 pp 133ndash141 2019

[22] M Yoshio G Kenjiro and O Seiichi ldquoA grading method formangoes on the basis of peel color measurement using acomputer vision systemrdquo Agricultural Sciences vol 7 no 6pp 327ndash334 2014

[23] F S A Saad M F Ibrahim and A Y Shakaff ldquoShape andweight grading of mangoes using visible imagingrdquo Computersand Electronics in Agriculture vol 5 no 6 pp 51ndash56 2015

[24] J He Z Y Ma X Chu H Li Liu T Y Xiao and H Y WeildquoResearch on mango shape evaluation method based onmachine visionrdquo Modern Agricultural Equipment vol 42no 1 pp 56ndash60 2021

[25] I Mohd S F Ahmad and Z Ammar ldquoIn-line sorting ofharumanis mango based on external quality using visibleimagingrdquo Sensors vol 16 no 11 p 1753 2016

[26] S N Chandra ldquoComputer vision based mango fruit gradingsystemrdquo in Proceedings of the International Conference onInnovative Engineering Technologies Bangkok )ailandDecember 2014

[27] E H Houssein A Diaa Salama I E Ibrahim M Hassaballahand Y M Wazery ldquoA hybrid heartbeats classification ap-proach based on marine predators algorithm and convolutionneural networksrdquo IEEE Access vol 9 2021

[28] H J Xin Huajia ldquoApplication of computer vision in mangoquality testingrdquo Agricultural Mechanization Research vol 41no 9 pp 190ndash193 2019

[29] C S Nand B Tudu and C Koley Machine Vision BasedTechniques for Automatic Mango Fruit Sorting and GradingBased on Maturity Level and Size Springer InternationalPublishing Heidelberg Germany 2014

Mathematical Problems in Engineering 11