Introduction

The almond (Prunus dulcis), with an origin that dates back approximately 5.88 million years [1], is one of the nuts with the highest protein content [2]. It is also rich in essential nutrients such as vitamin E, calcium, iron, magnesium, phosphorus, and zinc [3]. Almond supports heart health [4] with beneficial fats and helps regulate blood sugar, contributing to diabetes management. In addition to its nutritional benefits, it has a range of applications across different industries. In traditional medicine, the almond offers natural solutions for various health issues [5]. It is utilized as a moisturizer in cosmetics and skincare products, acts as fillers and sweeteners in the pharmaceutical industry, and is employed as active ingredients in natural cleaning products. With these usages, almonds have become a sought-after product in international export markets [6]. The classification of almond varieties is crucial for quality assessment and market value determination. Traditional methods for classifying almond varieties often rely on morphological characteristics and genetic analysis. However, these methods can be time-consuming, labor-intensive and prone to errors. Since morphological traits may vary and genetic tests are expensive, there is a demand for faster, cheaper and innovative methods for the classification of almond varieties.

In the existing literature, one of the methods used to automatically classify almonds is based on feature extraction. Initially, characteristics such as shape, color, and texture are extracted from images, and then the features are classified using a machine learning algorithm. Teimouri et al. [7], captured images of five almond types [Normal (NA), Broken (BA), Double (DA), Wrinkled (WA), Shell (SA)] and extracted a comprehensive set of features. The features were classified with Artificial Neural Network (ANN) and achieved accuracies: 98.92% for NA, 99.46% for BA, 98.38% for DA, 98.92% for WA, and 100% for SA. Halac et al. [8] classified five almond types using shape and RGB color features. They achieved an accuracy rate of 92.72% with Principal Component Analysis (PCA) and Support Vector Machine (SVM) algorithms. Nasirahmadi et al. [9] classified almonds as sweet or bitter, extracting various features. The Chi-Square Support Vector Machine (Chi-SVM) was used as the classifier, achieving an accuracy rate of 91% (± 1.6). Narendra et al. [10] proposed a feature-extraction based method for classifying almond varieties as Nonpareil (NP), Mission (MI), Carmel (CR), and California (C). They achieved an accuracy of 97.13% with Decision Tree (DT) algorithm. Table 1 summarizes the literature on feature-extraction based almond classification studies.

Table 1 Feature-extraction based almond classification studies in the literature

CNN is another method used for the automatic classification of almonds. Benarous [11] proposed a novel CNN model based on AlexNet to classify 16 almond varieties and achieved an accuracy rate of 94% accuracy. Vidyarthi et al. [12] classified almond kernels into five categories using pre-trained CNN models (Inception-V3, ResNet50, VGG-16) and a custom model. ResNet50 achieved the highest accuracy at 98.4% and the custom model achieved 92.2% accuracy but the custom model had fewer parameters compared to the pre-trained models.

Table 2 provides a summary of CNN-based variety classification studies in the literature. When Table 2 is examined, CNNs have shown promising results in almond classification. However, the number of studies is limited. CNNs have already proven effective in various agricultural applications, such as classifying dry beans [13], hazelnuts [14], lentil varieties [15], and corn [16]. Thus, the use of CNN based methods for almond classification is important. However, CNN models must be designed to be light-weight and fast to ensure their feasibility in embedded systems. When designing a CNN model, it is necessary to determine various hyperparameters, such as the number and size of convolutions, the pooling method to be used, and the number of neurons in fully connected layers.

Table 2 CNN-based almond classification studies in literature

The determination of the hyperparameters is an optimization problem. The values of CNN hyperparameters, such as the size and number of convolutional filters, the size and type of pooling filter, and the number of neurons, are all exact numbers. As a result, they can be solved using optimization approaches that are suitable for a discrete structure. In this context, the Genetic Algorithm (GA), by its very nature, is well suited to a discrete structure.

GA is a search and optimization algorithm developed inspired by Darwin's theory of evolution [17]. The GA has achieved successful results in solving optimization problems [18]. Rodrigues et al. [19] used ResNet50V2 model to classify Acute Lymphoblastic Leukemia. They applied transfer learning and determined the dropout, momentum, and learning rate parameters using GA. Das et al. [20] developed a CNN model for detecting the stages of diabetic retinopathy. The authors employed a GA to determine the parameters such as the number of convolution and pooling layers, the quantity and size of kernels in the convolutional layers. Ayan [21] used DenseNet121, MobileNetV2, and InceptionResNetV2 models for classifying insect types using the transfer learning method. During the transfer learning process, the ratio of layers to be frozen (freeze ratio), the number of layers, neuron count in the layers, and the dropout rate were determined using GA.

Table 3 provides a summary of GA applications in the literature. When Tables 13 are examined, it is seen that using GA together with CNN can potentially yield effective results in classifying almonds. In light of the literature, in this study, an almond dataset containing 1556 images of four distinct almond varieties was created. The almond varieties were classified using five well-known and light-weight and pre-trained CNN models. In addition, a new CNN model called 'Genetic CNN' was proposed. The model's hyperparameters were determined by GA. The rest of the paper is structured as follows: Sect. "Material and methods" details the methodology including data collection, CNNs, Transfer Learning, Genetic Algorithms, and Genetic CNN. Sect. "Experimental setup" covers the experimental setup and evaluation metrics. Sect. "Experimental results" presents the experimental results. Sect. "Discussion" discusses the findings, and Sect. "Conclusion" concludes the study and provides details about future works.

Table 3 GA applications in the literature

Material and methods

The details of the methods used in the study are explained in this section. The first subsection describes the system setup for data collection. The 'Dataset' subsection provides a detailed explanation of the data obtained. The 'Convolutional Neural Networks' subsection explains the basic concepts of CNNs. The 'Transfer Learning' subsection discusses the process of transferring features (weights) from previously trained CNN models. The section on the 'Genetic Algorithm' explains the algorithm's working principles. The proposed Genetic CNN architecture is then described.

Data collection

Almond varieties named Ak, Nurlu, Kapadokya and Sıra collected from different regions of Turkey were used in the study. To capture images of the almonds, a special chamber with homogeneous lighting was designed. The chamber is lighted with string circuits with LEDs on it operating with 5 Volt. The Samsung NX300 camera was used to capture the almond images. The camera has a 20.3 Megapixel CMOS sensor and a variable lens ranging from 24–55 mm. The lens was fixed at 45 mm and images were captured. The images captured at an ISO setting of 100 and a shutter speed of 1/400 s. Images are saved in the memory in JPG format. Figure 1 presents a schematic representation of the system.

Fig. 1
figure 1

Data collection system

Dataset

The Ak, Nurlu and Sıra almond varieties are grown in the Datça district of Muğla in the Aegean region of Turkey, while the Kapadokya almond is grown in Nevşehir in Central Anatolia. Both regions have suitable climate and soil properties for almond cultivation. A total of 1556 images of the four varieties were captured. Sample images selected from the dataset are shown in Fig. 2.

Fig.2
figure 2

Almond dataset sample images

Table 4 provides details on the quantity values of the almond varieties. The dataset is publicly available on the Kaggle platform (https://github.com/ymyurdakul/datasets/blob/main/almond/archive.zip).

Table 4 Almond varieties distribution

Convolutional neural network

CNN is a deep learning algorithm inspired by the visual cortex system [27]. CNN is extensively utilized in image analysis for tasks like image classification, detection, or segmentation and has achieved successful outcomes in various fields, such as defense [28, 29], medicine [30,31,32,33], agriculture [34,35,36] and education [37, 38]. A CNN comprises three main components: convolution, pooling, and a fully connected layer. The convolution layer extracts features from images, while the pooling layer reduces the feature matrix size obtained by the convolution layer. The fully connected layer consists of multilayer artificial neural network architecture. At the end of the fully connected layer, a softmax activation function is typically used for classification. Various CNN architectures have been proposed using these three core components. The number of parameters and complexity of models increases with the usage of components. For real-time classification tasks, light-weight models are necessary. In this work, five well-known and light-weight CNN models have been trained on the dataset, considering the parameter and size values. The details of the models are shown in Table 5.

Table 5 The details of light-weight CNN models [22]

EfficientNetB0 contains Mobile Inverted Bottleneck Convolution (MBConv) blocks, which have an inverted residual structure that improves scaling. DenseNet121 contains dense blocks to ensure full information sharing across layers. MobileNet is designed with depth-wise separable convolutions to reduce computation. MobileNetV2 builds upon this with inverted residuals and linear bottlenecks for enhanced performance. Lastly, NASNetMobile, created through Neural Architecture Search, employs Normal and Reduction Cells to effectively manage spatial dimensions and feature complexity.

Transfer learning

Transfer learning (TL) is the process of transferring previously learned knowledge to new and different situations [39]. In deep learning, TL enables a model trained on a large dataset to be effectively and quickly trained on a smaller, specialized dataset [40]. TL enables the model to focus on the specific features of the new dataset instead of re-learning the general features. The five light-weight models used in this study were previously trained on the ImageNet dataset. To successfully implement transfer learning, the final classification layers of these models have been removed and replaced with a Global Average Pooling (GAP) layer, and a four-output softmax layer was added for almond classification. The purpose of using the GAP layer was to enable the model to average the feature maps in the spatial dimension to obtain a denser representation. Also, the GAP layer aims to reduce the computational load and minimize the risk of overfitting by decreasing the number of parameters in the model.

Genetic algorithm

Genetic algorithm (GA) is an optimization algorithm based on natural selection, developed in 1975 at the University of Michigan by John Holland and his students [23]. Inspired by Darwin's theory of evolution, Holland and his students designed an algorithm to emulate genetic processes in living beings. In GA, potential solutions are represented by data structures called chromosomes, which consist of genes typically expressed as a series of numbers or a string of characters, symbolizing a solution to a problem [18]. Each iteration of GA, known as a 'generation,' contains a population of solutions evaluated by a specific fitness function [24]. The fitness function measures the quality of a chromosome's solution. The solution process begins with a randomly created initial population, and then the best chromosomes are selected. In this process, methods such as 'roulette wheel' selection are commonly used [25]. The roulette wheel determines the chance of each chromosome being selected based on its fitness level [25]. Chromosomes with higher fitness values are more likely to be included in the genetic pool for future generations. The selected chromosomes generate offspring chromosomes using genetic operators known as crossover and mutation. The crossover operator combines the features of two chromosomes to generate offspring [24]. The mutation operator makes random changes in chromosomes to increase genetic diversity [24]. Typically, the values of a few genes on a chromosome are altered. The primary purpose of mutation is to enhance the diversity in the search space, preventing the algorithm from focusing only on specific solutions. The new offspring generated through crossover and mutation operations are evaluated based on their fitness values. The most effective solutions are then selected for the subsequent generation, thereby enhancing the overall quality of the population. The process is repeated until a predetermined stopping criterion is met or a satisfactory solution is found. The flowchart illustrating the process of the GA is presented in Fig. 3.

Fig. 3
figure 3

Flowchart of the GA

Genetic CNN architecture

The Genetic CNN model consists of three convolution layers and three pool layers. The choice of three layers is because additional layers would increase the number of parameters and the size of the model. Also increasing the count of the layer can degrade accuracy due to over-complexity [26, 27]. After the pooling layer, the multidimensional feature map is flattened and then fed into a dense layer. The last layer is a classification layer that uses the softmax activation function to classify different types of almonds. Figure 4 visually represents the layers of the proposed architecture.

Fig. 4
figure 4

Genetic CNN architecture

The proposed model's filter size, number of filters, and activation function in the convolution layers, type and size of pooling in the pooling layers, and number of neurons in the dense layer were determined using the GA. Table 6 provides the parameter ranges.

Table 6 CNN architecture hyperparameters and range

To limit the number of parameters, the number of filters in the convolution layers was chosen between 1 and 64. The 1 × 1 and 3 × 3 filters were used to extract local and simple features from the images, while the 5 × 5 filters were chosen to capture features in larger areas [28, 29]. Additionally, a variety of activation functions were implemented in the layers. For the pooling methods, the commonly used Average and Max pooling methods were chosen. The pooling sizes were chosen to be either 2 × 2 or 3 × 3. The number of neurons in the dense layer was kept within a broad range to enhance the model's flexibility and adaptability for diverse data sets and tasks.

Population initialization

A chromosome containing 16 genes was created to represent candidate solutions. The first three genes of the chromosome determine the hyperparameters of the model's first convolutional layer. The next two genes contain the hyperparameters of the first pooling layer. This pattern continues for the second and third convolutional and pooling layers, so the first 15 genes define the hyperparameters of these layers. The last gen determines the number of neurons in the model's dense layer. Figure 5 shows an example of a chromosome with randomly generated genes, which represents CNN architecture.

Fig. 5
figure 5

Chromosome representation with randomly generated values

The size of the population must be greater than the length of the chromosome [30]. Additionally, the population size is related to the computational complexity. In many studies in the literature, successful results have been achieved with a 50 population size [30,31,32]. For all these reasons, the first population was created with 50 chromosomes consisting of gene values randomly selected from the ranges in Table 6.

Fitness function

The quality of the solutions in the population was determined using the F1-Score values of CNN models on validation data. The F1 Score is the harmonic mean of the precision and recall rates of the model on the data. The reason for using the F1-Score is that it balances both precision and recall rates, thus allowing the algorithm to make a more balanced selection. The F1-Score is calculated using eq. 1.

$$Fitness=F1-Score=\frac{\text{2xPrecisionxRecall}}{\text{Precision+Recall}}$$
(1)

Selection

In GA, during the selection phase, chromosomes are chosen from the population to produce new offspring. There are various selection methods such as Tournament, Roulette Wheel, and Rank Selection. In this study, the Roulette Wheel Selection method was employed, which assigns selection probabilities proportional to the fitness values of each chromosome, thereby favoring those with higher fitness. Consistently selecting the fittest chromosomes through the Roulette Wheel method enhances the overall quality of the population. The Roulette Wheel is in alignment with the 'survival of the fittest' principle, fundamental to GA. The Roulette Wheel method ensures the evolution of the most optimal solutions, while maintaining genetic diversity within the population [33].

Crossover and mutation

The crossover operator in GAs is used to change the genes of parent chromosomes to create new and potentially better gene combinations. It is conducted by intersecting chromosomes at a specific point and exchanging gene segments. In this study, single-point crossover is used, where genes are mixed from a randomly chosen point along both parental chromosomes. The crossover operator ensures that offspring inherit genes from both parents. For example, if the 6th gene is the crossover point in Fig. 6, the first child inherits the first 6 genes from one parent and the rest from the other, while the second child inherits in a similar way but from the other parents.

Fig. 6
figure 6

The single-point crossover operation

After the crossover operation, mutation processes are typically applied. Mutation enhances genetic diversity by altering random genes in the newly formed chromosomes. In this study, for the mutation process, a random gene from the chromosome was selected, and a value was randomly assigned from the range specified in Table 6. Figure 7 illustrates an example of a mutation process where a gene selected at random is replaced with a random value.

Fig. 7
figure 7

The mutation operation

After crossover and mutation, the fitness values of the offsprings were determined. Based on the fitness values, it is decided whether they will proceed to the next generation. Then, depending on the number of elites in the population, poor candidates are eliminated. The selection, crossover, and mutation processes are repeated until the termination criterion is met.

Experimental setup

All experiments were performed on a computer configured with an Nvidia GTX 3060Ti GPU, 128 GB RAM, and an Intel(R) Core(TM) i9-10920X CPU. The CNN models and optimization algorithm was developed utilizing the Keras 2.9.0 API, which operates on a Tensorflow 2.9.2 backend with Python 3.8.10. CUDA V11.2 was used for GPU acceleration. In the experimental studies, pre-trained CNN models were used and retrained for the classification of almond varieties. The learning rate was set at 0.01, with a mini-batch size of 32. Stochastic Gradient Descent was used as the optimizer. The training was stopped after 50 epochs to prevent the network from becoming overfitting. In the classification layer of the CNN models, categorical cross-entropy loss was utilized. The hyperparameters of the pre-trained CNN models are determined with the GridSearch method. The GridSearch finds the best-performing set of hyperparameters by trying all possible combinations over a given set of values for certain hyperparameters. Similarly, for the Genetic CNN, GA was executed for 50 iterations, employing crossover and mutation rates of 0.95 and 0.5, respectively.

Evaluation metrics

In this study, various metrics were used to evaluate the performance of the models. Accuracy measures the percentage of correct predictions among all predictions and is calculated using the formula in Eq. 2. The precision metric is used to determine the proportion of actual positives among those predicted as positive and is calculated using the formula in Eq. 3. Recall indicates how well the model identifies true positive situations and is calculated using the formula in Eq. 4. F1 Score is computed using the harmonic mean of precision and recall, as shown in Eq. 5. AUC measures the ability of a model to distinguish between classes based on the size of the area under the ROC curve. Cohen's Kappa Score quantifies inter-rater agreement, adjusting for chance. It's calculated using Eq. 6, with P0 indicating observed agreement, and Pe representing expected agreement by chance.

$$Accuracy=\frac{TP+TN}{TP+TN+FP+FN}$$
(2)
$$Precision=\frac{TP}{TP+FP}$$
(3)
$$Recall=\frac{TP}{TP+FN}$$
(4)
$$F1-Score=\frac{2xPrecisionxRecall}{Precision+Recall}$$
(5)
$${\rm K}=\frac{{P}_{0}-{P}_{e}}{1-{P}_{e}}$$
(6)

The calculation of the metrics includes TP (True Positive), TN (True Negative), FP (False Positive), and FN (False Negative), where TP represents instances correctly predicted as positive by the model, TN indicates instances correctly predicted as negative, FP refers to instances incorrectly predicted as positive, and FN represents instances incorrectly predicted as negative. The study evaluated the reliability and generalizability of the model on the dataset using the k-fold cross-validation method. The k-fold cross-validation in this study was set to k = 5, which is a common practice in the literature [42, 43].

Experimental results

Pre-trained CNN models

The mean and standard value performance metrics of the light-weight CNN models used in the study are presented in Table 7. The confusion matrices of all CNN models at the end of the testing process are given in Fig. 8.

Table 7 Classification performance of CNN models
Fig. 8
figure 8

Confusion Matrices of CNN models (0: Ak, 1: Kapadokya, 2: Nurlu, 3: Sıra)

When the results in Table 7 are analyzed, high performances were achieved overall. CNN models achieved an accuracy rate between 95.11% and 99.20%. Standard deviation values show that the values obtained are consistent. NASNetMobile was the most successful model with an accuracy of 99.20%, precision of 99.21%, recall of 99.20%, f1-score of 99.19%, kappa score of 98.92% and AUC of 99.99. NASNetMobile achieved high performance with the advantages of blocks such as separable convolution and pooling improved with reinforcement learning. DenseNet121 was the second most successful model with 99.16% accuracy. MobileNetV2 had the lowest accuracy rate with 95.11%.

When Fig. 8 is analyzed, the DenseNet121, EfficientNetB0, MobileNet and NASNetMobile models had low standard deviation values and minimal incorrect predictions in distinguishing almond species. However, the MobileNetV2 model had higher standard deviation values and made more errors in identifying the almond varieties. Figure 9 shows the mini-batch accuracy and mini-batch loss values of the models during training. There is no significant difference between the accuracy and loss values during the training and validation process using the training and validation data. This indicates that the model does not overfit and memorize the training data. From this perspective, it can be assumed that the model has better generalization ability on unseen data.

Fig 9
figure 9

The mini-batch accuracy and loss graphs of the CNN models

Proposed genetic CNN

The details of the hyperparameters for the optimal solution are shown in Table 8. The first convolutional layer uses 3 × 3 size filters, which contain 9 filters in this layer. The ReLU activation function is chosen for the same layer. The pooling method is average pooling with a 2 × 2 pooling window. In the second convolutional layer, 3 × 3 size filters are used, but the number of filters is increased to 19. The ReLU activation function is also used in this layer. The pooling type is automatically set to maximum pooling, and the pooling size is set to 2 × 2. In the third convolutional layer, 5 × 5 filters are determined, with 32 filters in this layer. The more advanced ELU (Exponential Linear Unit) activation function is selected. Maximum pooling is also chosen in this layer, with a pooling size of 3 × 3. Finally, a total of 59 neurons in the dense layer are also determined by the GA.

Table 8 CNN architecture hyperparameters

The classification performance of the Genetic CNN model is presented in Table 9 and the complexity matrix is presented in Fig. 9. The Genetic CNN has a very high performance with an accuracy rate of 99.55%. Also, the low standard deviation values indicate that the results are consistent.

Table 9 Classification performance of genetic CNN

The confusion matrix in Fig. 10 visually represents the performance of Genetic CNN in classifying the varieties of almonds. The high rates on the main diagonal for each variety reflect the classification success and prediction reliability of the model, while the low standard deviation values indicate the consistency and stability of the model across experiments. When Fig. 10 is analyzed, it is seen that Kapadokya is correctly predicted with ± 1.2 standard deviation. Although the standard deviation is quite low, it shows that it is more difficult for the model to distinguish Kapadokya from other varieties. It was also confused with other classes at minimal rates. The main reason for this is that Kapadokya is similar in pattern to Ak and similar in shape to Nurlu and Sıra.

Fig. 10
figure 10

Confusion matrix of Genetic CNN (0: Ak, 1: Kapadokya, 2: Nurlu, 3: Sıra)

Figure 11 shows the mean and standard deviation of the mini-batch accuracy and loss values of the Genetic CNN. When the training and validation accuracies are examined, the difference between the values is quite minimal. Similarly, the difference between training and validation loss values is quite minimal. This indicates that the model does not overfit and does not memorize the training dataset. From this point of view, it can be thought that the model has a good generalization ability on unseen data.

Fig. 11
figure 11

The mini-batch accuracy and loss graphs of the Genetic CNN

With an accuracy of 99.55%, precision of 99.56%, recall of 99.55%, f1-score of 99.55, kappa score of 99.40% and AUC of 99.99, Genetic CNN outperformed the well-known CNN models in terms of classification performance. In embedded systems, factors such as the number of parameters, size and estimation time are also important. Table 10 shows the comparison between pre-trained CNN models and Genetic CNN in terms of the parameter count, size and average testing time metrics.

Table 10 Details of pre-trained and genetic CNN models

The Genetic CNN, with 1.1 million parameters and a size of 5.8 Mb, has a lower parameter count and size compared to other models and achieves the shortest test time of 0.94 s (± 0.05). These characteristics indicate that the Genetic CNN is suitable for almond classification tasks, especially in embedded devices or mobile devices during quality control stages for almond variety detection.

Comparison with literature studies

The Genetic CNN outperformed other light-weight models in terms of parameters, size, test time and classification performance. Furthermore, the performance of the Genetic CNN was also compared with similar studies in the literature in the field of almond classification. A summary of related work in the literature is presented in Table 11.

Table 11 Comparison of genetic CNN with similar studies

In the literature, various classifiers such as SVM, Chi-SVM, Decision Tree, AlexNet and ResNet50 were used and accuracy rates between 91% and 98.4% were achieved. However, the Genetic CNN model proposed in this study outperformed traditional feature extraction-based classifiers with its automatic feature extraction architecture. It also outperformed other CNN-based studies in the literature in terms of both parameter size and classification performance.

Discussion

Almonds have a significant role in agriculture and food sectors due to its high nutritional value and wide industrial utilization. Accurate classification of almonds is critical for both quality control and determination of the market value. However, traditional classification methods of almond cultivars are based on morphological characteristics and genetic analysis. These methods are both time-consuming and error-prone, which creates limitations in terms of efficiency and accuracy. In this study, a dataset was created using images of four different almond cultivars in Turkey. The aim of the study is to develop a model that provides faster and more accurate results than traditional methods. In this context, five well-known CNN models (DenseNet121, EfficientNetB0, MobileNet, MobileNetV2, NASNetMobile) were tested for almond classification. The models were evaluated in terms of classification accuracy and efficiency. In this context, the highest classification performance was achieved with NASNetMobile with an accuracy of 99.20%, precision of 99.21%, recall of 99.20%, f1-score of 99.19%, kappa score of 98.92% and AUC of 99.99. A new model called Genetic CNN was also proposed. The Genetic CNN outperformed well-known and pre-trained CNN models by achieving an accuracy of 99.55%, precision of 99.56%, recall of 99.55%, f1-score 99.55%, kappa score 99.40% and AUC of 99.99. The box plot diagram of the results obtained on the test data as a result of the experimental studies is shown in Fig. 12. When Fig. 12 is analyzed, it can be seen that all models are successful in all metrics with a value close to 100. It is also seen that the standard deviation of all the performance metric values is very low in all models. As a result, it is seen that the models have statistical stability.

Fig. 12
figure 12

Box plot diagrams illustrating the classification metrics of cnn models

In addition to classification performances, the Genetic CNN outperformed other well-known models in terms of the number of parameters (1.1 million), model size (5.8) and test time (0.94). These factors are important indicators of how efficiently the model works in practical applications. In this context, Genetic CNN is ideal for real-time applications and embedded systems. When compared with other studies on almond classification in the literature, it is seen that the Genetic CNN model is more successful than other studies (Table 10). Furthermore, Genetic CNN was compared with the CNNs designed using GA in the literature; Table 12 shows the literature studies.

Table 12 Comparison of genetic CNN with other genetic-based CNN studies

When Table 12 is analyzed, it is seen that genetic-based CNNs achieve successful results. It is seen that there is an increasing trend in model performances over the years. The Genetic CNN has surpassed related studies in the literature in terms of classification performance, contributing to the trend.

Conclusion

Almonds are a nutritious food containing a variety of essential nutrients. In addition to being a nutritious food, it is also important in various industrial applications. These characteristics have made almonds a sought-after product in international export markets. Classifying almond varieties is vital for quality assessment and determining their market value. In this study, images of four different almond varieties were collected from Muğla and Nevşehir provinces of Turkey. The images were classified using well-known and light-weight CNN models. Additionally, a new CNN model called Genetic CNN was developed and the classification process was performed. Among the well-known CNN models, the highest performance was obtained with NASNetMobile with an accuracy of 99.20%, precision of 99.21%, recall of 99.20%, f1-score of 99.19%, kappa score of 98.92% and AUC of 99.99%. The Genetic CNN achieved an accuracy of 99.55%, precision of 99.56%, recall of 99.55%, f1-score 99.55%, kappa score of 99.40% and AUC of 99.99. The Genetic CNN model has fewer parameters and size compared to other models and short testing time. In future studies, we will increase the number of almond varieties, design CNN architectures with various optimization models, develop machine-based classification systems, and develop mobile application-based classification systems.