Automated Grading of Red Ginseng Using DenseNet121 and Image Preprocessing Techniques

: Red ginseng is a steamed and dried ginseng that has more functional properties and a longer shelf-life. Red ginseng is graded by appearance and inner quality. However, this conventional process has a high cost in terms of time and human resources, and has the disadvantage of subjective assessment results. Therefore, the convolutional neural network (CNN) method was proposed to automate the grading process of red ginseng and optimize the preprocessing method, select an accurate and efﬁcient deep learning model, and to explore the feasibility of rating discrimination solely based on external quality information, without considering internal quality characteristics. In this study, the effect of ﬁve distinct preprocessing methods, including RGB, binary, gray, contrast-limited adaptive histogram equalization (CLAHE), and Gaussian blur, on the rating accuracy of red ginseng images was investigated. Furthermore, a comparative analysis was conducted on the performance of four different models, consisting of one CNN model and three transfer learning models, which were VGG19, MobileNet, and DenseNet121. Among them, DenseNet121 with CLAHE preprocessing reported the best performance; its accuracy in the Dataset 2 test set was 95.11%. This ﬁnding suggests that deep learning techniques can provide an objective and efﬁcient solution for the grading process of red ginseng without an inner quality inspection.


Introduction
Ginseng is obtained from the root of Panax ginseng Meyer and has been consumed for centuries in East Asia as a high-quality herbal product [1].It is known for reducing fatigue, strengthening the immune system, and enhancing bone health [2][3][4].Red ginseng can be stored for a long time by steaming and drying it repeatedly.Through this, not only is the storage period increased, the functionality also becomes better than ginseng, owing to the production of physiologically active substances found only in red ginseng, such as Rh2, Rg3, Rh1, and Rh4 [5,6].After steaming and drying, twigs are trimmed off to obtain a specific morphology with a head, body, and one or two primary legs.Subsequently, professional inspectors divide the trimmed red ginseng into four grades: first, second, third, and out-of-grade.
The grade depends on the appearance and inner quality of the red ginseng.The appearance is the most critical factor in grading and includes color, leg number, length, the proportion of each part, morphology, and outer defects such as cracks and wounds [7].Internal quality assessment evaluates the inner white, inner hole, and tissue compactness.To evaluate inner quality, inspectors check for changes caused by the difference in internal permeability when illuminating red ginseng with intense light [8].However, these processes incur high costs in terms of time and human resources, and have the disadvantage of subjective assessment results [9].
Previously, studies were conducted to set up an automatic and reliable system to classify red ginseng grades based on appearance and inner quality.Numerical appearance traits such as leg number [10], leg and body length and ratio [11], and head area and color [12] were extracted to evaluate the ginseng exterior quality with low accuracy; however, they do not reflect the overall shape and comprehensive appearance.To inspect internal quality, Nuclear Magnetic Resonance [8], Magnetic Resonance Imaging [9], and Infrared Radiation were considered [13].However, these methods required additional expenses in terms of equipment and time.
Deep learning is a sub-field of machine learning that utilizes multiple layers of an artificial neural network.Remarkably, the convolutional neural networks (CNNs) based on convolutional layers have shown high performance in image analysis, including object detection, segmentation, and pattern recognition [14].The CNN-based model comprehensively extracts features that are otherwise challenging to represent by numerical values, such as color distribution, morphology, and direction, without being directly extracted by humans [15].Therefore, the CNN-based method has been successfully used to inspect comprehensive factors for sorting or grading in agriculture, including for apples [16], okra [17], and carrots [18].
Recent studies have proven that the CNN-based model can grade ginseng with appearance quality [19,20].While ginseng is only graded on its external quality, during processing, red ginseng is also graded based on its internal quality.Therefore, a new research challenge is to explore the possibility and limitations of evaluating total red ginseng grade based on external quality alone.
Transfer learning is a method of training a new model based on a pre-trained model and it extracts the features of an image by retaining not only the structure of the pre-training model but also the weights.In the case of image analysis using a general convolutional model, a large amount of computation must be performed while adjusting weights for learning.However, since transfer learning fixes the learned weights, it has the advantage of quick convergence and high accuracy even with a small dataset [20].
Because deep learning automatically extracts features, image preprocessing not only ensures proper learning, but also improves the accuracy and learning efficiency [21].The image preprocessing includes removing surplus information such as background or noise [22,23] and adjusting pixel values.Preprocessing can highlight the image characteristics by adjusting image pixel values via smoothing and color conversion.However, determining the most appropriate preprocessing technique that fits the features of the target is necessary; otherwise, important information may be removed or irrelevant information may be highlighted unintentionally [24,25].
In this study, several deep learning models with red, blue, and green (RGB) images were trained to automate the red ginseng grading to reduce human resource and to create an objective grading technique.The main points of this study can be largely divided into three categories.First, to examine the possibility of automatic rating discrimination solely with comprehensive external quality without internal quality information and evaluate its influence on each grade.Second, to compare the various preprocessing methods applied to red ginseng images to determine the image characteristics and select the optimal method.Finally, to optimize an accurate and efficient model by training several deep learning models, including transfer learning, on small datasets.

Sample Preparation
Red ginseng samples that were 6 years old were obtained from the Punggi Ginseng Cooperative Association (Punggi, Republic of Korea).All samples were graded as first, second, third, and out-of-grade by professional graders according to standard red ginseng grading measures [26].A total of 1500 red ginseng roots, with 375 roots per grade, were prepared.

Image Acquisition
The image data were obtained in an illumination chamber that blocked external light (Figure 1).The chamber was equipped with 4-way LEDs, an illuminance meter (K14649784, SK electronic Co., Gwangju, Republic of Korea) that set the light intensity to 450 ± 10 lux, and a CMOS digital camera (Powershot G7X mark iii, Cannon Inc., Tokyo, Japan).The images were acquired with camera conditions fixed at sensitivity ISO 125, aperture f/2.8, exposure time 1/15 s, no zoom, no flash, resolution 72 dpi, focal length 9 mm, and the camera was positioned 32 cm from the sample.Two images of the front and back of the red ginseng root were acquired, and a total of 3000 images of 750 pieces of red ginseng, sorted by each grade, were saved in JPG format with a resolution of 5472 × 3648 (Figure 2).Finally, 20% of the images, i.e., 600 images (150 per grade), were designated as test data, and 2400 images were designated as training data.

Image Acquisition
The image data were obtained in an illumination chamber that blocked external light (Figure 1).The chamber was equipped with 4-way LEDs, an illuminance meter (K14649784, SK electronic Co., Gwangju, Republic of Korea) that set the light intensity to 450 ± 10 lux, and a CMOS digital camera (Powershot G7X mark iii, Cannon Inc., Tokyo, Japan).The images were acquired with camera conditions fixed at sensitivity ISO 125, aperture f/2.8, exposure time 1/15 s, no zoom, no flash, resolution 72 dpi, focal length 9 mm, and the camera was positioned 32 cm from the sample.Two images of the front and back of the red ginseng root were acquired, and a total of 3000 images of 750 pieces of red ginseng, sorted by each grade, were saved in JPG format with a resolution of 5472 × 3648 (Figure 2).Finally, 20% of the images, i.e., 600 images (150 per grade), were designated as test data, and 2400 images were designated as training data.

Physical Characteristics
The acquired red ginseng images were analyzed using Image J 1.46r (National Institutes of Health, Bethesda, MD, USA) software to measure the length of the body, legs, and grading measures [26].A total of 1500 red ginseng roots, with 375 roots per grade, were prepared.

Image Acquisition
The image data were obtained in an illumination chamber that blocked external light (Figure 1).The chamber was equipped with 4-way LEDs, an illuminance meter (K14649784, SK electronic Co., Gwangju, Republic of Korea) that set the light intensity to 450 ± 10 lux, and a CMOS digital camera (Powershot G7X mark iii, Cannon Inc., Tokyo, Japan).The images were acquired with camera conditions fixed at sensitivity ISO 125, aperture f/2.8, exposure time 1/15 s, no zoom, no flash, resolution 72 dpi, focal length 9 mm, and the camera was positioned 32 cm from the sample.Two images of the front and back of the red ginseng root were acquired, and a total of 3000 images of 750 pieces of red ginseng, sorted by each grade, were saved in JPG format with a resolution of 5472 × 3648 (Figure 2).Finally, 20% of the images, i.e., 600 images (150 per grade), were designated as test data, and 2400 images were designated as training data.

Physical Characteristics
The acquired red ginseng images were analyzed using Image J 1.46r (National Institutes of Health, Bethesda, MD, USA) software to measure the length of the body, legs, and

Physical Characteristics
The acquired red ginseng images were analyzed using Image J 1.46r (National Institutes of Health, Bethesda, MD, USA) software to measure the length of the body, legs, and diameter.The body-leg ratio was calculated as the measured body length divided by the leg length, and the body-diameter ratio as the body length divided by the diameter length.

Image Preprocessing
To extract the desired red ginseng area by removing the background and shadow from the input image, the RGB image was converted into a hue, saturation, and value (HSV) image.Since the white background and shadow contain a low saturation value in the HSV image, the area with a 50 or higher saturation value was designated as the red ginseng area.Small holes and noise areas were removed using the morphology operations of closing and opening [27].Subsequently, the HSV image was restored to RGB and all background areas were removed by changing their pixel value to zero.Then, the object was localized so that its long horizontal and vertical lengths were in the center and cropped to the size of each ginseng.After all preprocessing, CLAHE, Gaussian blur, Gray, and Binary were adapted to the image, and the image size was changed to 224 × 224.

Contrast-Limited Adaptive Histogram Equalization
Contrast-limited adaptive histogram equalization (CLAHE) is an algorithm that improves the shortcomings of adaptive histogram equalization, which leads to an excessive contrast increase and thus, noise.CLAHE redistributes pixel values by limiting the height of the histogram so that the contrast of the image can be appropriately adjusted [28].The calculation of CLAHE can be represented by the following equation: where g is the calculated pixel value, and g max and g min are the maximum and minimum pixel values of the image, respectively.P(f ) is the cumulative probability distribution [29].
Red ginseng images were converted to CIE Lab color, which contains lightness, red/green, and blue/yellow channel.Then, CLAHE was applied to each channel and the CIE Lab image was converted to an RGB image.The clip limit was set to 2, and block size was (10, 10).

Gaussian Blur
Gaussian blur is widely used as a smoothing method by removing noise and highfrequency components from the image.Gaussian blur conversion in an image can be expressed using the following equation: where x and y are the horizontal and vertical axes distances from the origin pixel, respectively.σ is a standard deviation of the distribution.The sigma value was set to 5.

Grayscale
RGB images contain three channels, red, green, and blue.However, the gray image has one channel that expresses brightness without color.The gray conversion can be expressed using the following equation: where Y is the pixel value of the gray image, and the values of the red, green, and blue dimensions are represented by R, G, and B, respectively.

Binary
Binary is an image obtained by binarizing RGB.All pixel values of the red ginseng area in the three-dimensional RGB channel were processed as a single dimension of 255 and the background part was processed as zero.Binary images are effective for analyzing size and body shape information [30].

Architecture of Convolutional Neural Networks
A generalized CNN contains a convolution layer, a pooling layer, and a fully connected (FC) layer.Among them, the convolutional layer, which is the core of the convolutional model, serves to automatically extract image features [31].Pooling layers reduce the dimensionality of the feature maps by combining a set of values into a mean, maximum or minimum value.This enables the removal of irrelevant information.A flatten layer collapses the spatial dimensions into one-dimensional features.Two FC layers were set to select the features extracted from the convolutional layer [32].The two FC layers had 128 and 64 nodes, respectively, with a Rectified Linear Unit (ReLU) activation function and a dropout of 0.3, to show the grades as the result of the softmax function.
The CNN model was trained using the structure shown in Table 1.The CNN model used in this study was constructed by referring to Agarwal et al. [33].The hyperparameters were a batch size of 32, 0.001 initial learning rate, and Adam optimizer [34].Finally, 20% of the training data were designated as validation data, and categorical cross-entropy loss was used to evaluate the performance during model training.In this study, three models, i.e., MobileNet [35], DenseNet121 [36], and VGG19 [37], trained using ImageNet data, were used for transfer learning.ImageNet refers to a dataset that classifies approximately 1.4 million images into approximately 1000 types, and models trained with this data extract general features of images from massive data; thus, they are the most commonly used models in transfer learning [20].As shown in Figure 3, the convolutional layers were replaced with the transfer learning models.Two trainable, fully connected layers were set to select features from the transfer model.All fully connected layers were set the same as the CNN model, which has 128 and 64 nodes, with ReLU activation function and a dropout of 0.3.Finally, a softmax layer was set to decide the grade as a result.

Dataset
To check whether the grade groups were inter-class groups in the deep learning model, three different datasets were used for training.The dataset included all grades assigned to Dataset 1.Then, the first and second grades were set as the same group, high grade.Next, three grades, including high, third, and out-of-grade, were selected in Dataset 2. Finally, a dataset with only two grades, first and second, was set as Dataset 3.

Dataset
To check whether the grade groups were inter-class groups in the deep learning model, three different datasets were used for training.The dataset included all grades assigned to Dataset 1.Then, the first and second grades were set as the same group, high grade.Next, three grades, including high, third, and out-of-grade, were selected in Dataset 2. Finally, a dataset with only two grades, first and second, was set as Dataset 3.

Training Environment
All procedures were implemented in Python 3.7 with Visual Studio Code 1.7 using TensorFlow 2.7 for deep learning and OpenCV 4.6 for image processing.The hardware included an AMD Ryzen 5 5600H CPU processor (Santa Clara, CA, USA) with 4 GB of RAM, and an NVIDIA GeForce RTX 3060 Laptop graphics card (Santa Clara, CA, USA).

Performance Evaluation
The performances of the models were evaluated for accuracy, precision, recall, and F1 score.All measurements were shown as macro processes.They are expressed by the following equations.Accuracy = (TP + TN) / (TP + TN + FP + FN), Precision = TP / (TP + FP), Recall = TP / (TP + FN), where true positive (TP) is the number of correctly classified positive grades, and true negative (TN) is the number of correctly classified negative grades.False positive (FP) is the number of incorrectly classified positive grades, and false negative (FN) is the number of incorrectly classified negative grades 3.

Physical Characteristics
Table 2 shows the physical characteristics of each grade of red ginseng.In body length, only the out-of-grade was shorter than other grades at 5.40 cm.However, the leg length of the first grade was 5.51 cm, which was longer than the other grades.The diameter of the red ginseng was 1.65 cm for first grade, 1.77 cm for second, 1.83 cm for third, and 1.74 cm for out-of-grade.The ratio of body-to-leg was 1.96 for third, which was

Training Environment
All procedures were implemented in Python 3.7 with Visual Studio Code 1.7 using TensorFlow 2.7 for deep learning and OpenCV 4.6 for image processing.The hardware included an AMD Ryzen 5 5600H CPU processor (Santa Clara, CA, USA) with 4 GB of RAM, and an NVIDIA GeForce RTX 3060 Laptop graphics card (Santa Clara, CA, USA).

Performance Evaluation
The performances of the models were evaluated for accuracy, precision, recall, and F1 score.All measurements were shown as macro processes.They are expressed by the following equations.Accuracy = (TP + TN)/(TP + TN + FP + FN), Precision = TP/(TP + FP), Recall = TP/(TP + FN), where true positive (TP) is the number of correctly classified positive grades, and true negative (TN) is the number of correctly classified negative grades.False positive (FP) is the number of incorrectly classified positive grades, and false negative (FN) is the number of incorrectly classified negative grades 3.

Physical Characteristics
Table 2 shows the physical characteristics of each grade of red ginseng.In body length, only the out-of-grade was shorter than other grades at 5.40 cm.However, the leg length of the first grade was 5.51 cm, which was longer than the other grades.The diameter of the red ginseng was 1.65 cm for first grade, 1.77 cm for second, 1.83 cm for third, and 1.74 cm for out-of-grade.The ratio of body-to-leg was 1.96 for third, which was different from the other grades, and the ratio of body-to-diameter was 3.20 for out-of-grade, which was different from the other grades.Otherwise, first and second grades have no difference in body-to-leg and body-to-diameter ratios.   Values are mean ± Standard deviation (n = 100). (2)a, b means significantly different between grade by Duncan's multi-range test (p < 0.05).

Preprocessing
As shown in Table 3, the CLAHE preprocessing had the highest performance in CNN, DenseNet121, and MobileNet.This was because, as shown in Figure 4, the histogram pixel values were distributed such that a clearer image was produced and a better recognition of defects and color in the appearance was achieved [38].In the blurred image, the pixel values were clustered in a certain value as opposed to CLAHE, especially in the G and R channels.This was because the legs of the red ginseng ere browned more than the body, so the body and legs differed in color [11].In VGG19, Blur showed the highest accuracy among the preprocessing, 79.83%, but there was no big difference between preprocessing.  Figure 5 shows the difference between gray and binary images is in the texture information expressed with brightness [30,39].For all models except CNN, Gray was more accurate than Binary and RGB.In particular, the accuracy of the gray preprocessing was 82.5%, the same as CLAHE on MobileNet.This suggests that texture information is important for the classification of red ginseng grade.
According to the preprocessing data, the CLAHE method was the most ideal preprocessing method except for VGG19.Therefore, all subsequent studies used the CLAHE preprocessed dataset.Figure 5 shows the difference between gray and binary images is in the texture information expressed with brightness [30,39].For all models except CNN, Gray was more accurate than Binary and RGB.In particular, the accuracy of the gray preprocessing was 82.5%, the same as CLAHE on MobileNet.This suggests that texture information is important for the classification of red ginseng grade.Figure 5 shows the difference between gray and binary images is in the texture information expressed with brightness [30,39].For all models except CNN, Gray was more accurate than Binary and RGB.In particular, the accuracy of the gray preprocessing was 82.5%, the same as CLAHE on MobileNet.This suggests that texture information is important for the classification of red ginseng grade.
According to the preprocessing data, the CLAHE method was the most ideal preprocessing method except for VGG19.Therefore, all subsequent studies used the CLAHE preprocessed dataset.

Model Selection
The number of epochs is one of the hyperparameters that should be appropriately specified to avoid underfitting and overfitting.Underfitting refers to the state in which the model fails to properly find the rules of the training set, and overfitting is a phenomenon in which the model becomes excessively fitted to the training set, resulting in testing According to the preprocessing data, the CLAHE method was the most ideal preprocessing method except for VGG19.Therefore, all subsequent studies used the CLAHE preprocessed dataset.

Model Selection
The number of epochs is one of the hyperparameters that should be appropriately specified to avoid underfitting and overfitting.Underfitting refers to the state in which the model fails to properly find the rules of the training set, and overfitting is a phenomenon in which the model becomes excessively fitted to the training set, resulting in testing performance degradation [40].Therefore, finding the appropriate number of epochs is an important factor in model learning.The appropriate epoch number can be found by comparing the loss function values of the training data and the validation data [41].
Figure 6 shows the loss value and accuracy of training and validation data according to the epochs for each model.The losses and accuracies of the training and validation data for all models were close till approximately 10-20 epoch and then started to diverge.The difference between the CNN and the transfer model was the gap between the training and validation data.While the CNN model continued to show an increasing gap between the training and validation data as the epochs increased, the transfer learning model maintained this gap or showed a modest increase.This is due to the effectiveness of transfer learning in suppressing overfitting [42].This can be observed in the accuracy trend over the epochs in Table 4.All models, except VGG19, showed a peak and decline in accuracy at epoch 20, with VGG19 showing the highest accuracy at epoch 30.This indicates that the accuracy of the test data was low due to underfitting before the appropriate epoch interval due to overfitting in the later epoch interval.Additionally, all transfer learning models were more accurate than the CNN model, indicating that transfer learning improves the accuracy of red ginseng grading.Among them, DenseNet121 was found to be the most suitable model for grading, with an accuracy of 84.67% at epoch 20.Table 5 shows the number of parameters, training and test times, and size of each model.DenseNet121 had the highest accuracy, but also the longest test time, 5.05 ms.Although VGG19 had fewer parameters to learn than DenseNet121, its training time was the longest due to the large number of transferred and total parameters.However, VGG19′s accuracy was 80.33%, the lowest among the transfer learning, showing that computation and model size do not guarantee accuracy.The CNN model had the shortest test time, 1.47 s, as the number of parameters and model size were only approximately one-twentieth of transfer learning.MobileNet had the second highest accuracy, 82.50%, and the training and test times were only approximately half of the other transfer learning models.Based on this, although DenseNet121 had the highest accuracy, MobileNet had the highest time and memory efficiency.As a result, MobileNet could be a suitable feature-extracting model in a limited environment; however, DenseNet121 is the most accurate model for grading red ginseng.  (1Transfer learning models: DenseNet121, MobileNet, and VGG19; non-transfer learning model: CNN.   (Transfer learning model: DenseNet121, MobileNet, and VGG19; non-transfer learning model: CNN.
Table 5 shows the number of parameters, training and test times, and size of each model.DenseNet121 had the highest accuracy, but also the longest test time, 5.05 ms.Although VGG19 had fewer parameters to learn than DenseNet121, its training time was the longest due to the large number of transferred and total parameters.However, VGG19's accuracy was 80.33%, the lowest among the transfer learning, showing that computation and model size do not guarantee accuracy.The CNN model had the shortest test time, 1.47 s, as the number of parameters and model size were only approximately one-twentieth of transfer learning.MobileNet had the second highest accuracy, 82.50%, and the training and test times were only approximately half of the other transfer learning models.Based on this, although DenseNet121 had the highest accuracy, MobileNet had the highest time and memory efficiency.As a result, MobileNet could be a suitable feature-extracting model in a limited environment; however, DenseNet121 is the most accurate model for grading red ginseng.  (1Transfer learning models: DenseNet121, MobileNet, and VGG19; non-transfer learning model: CNN.

Model Optimization
In the original DenseNet121, a global pooling layer was used as an FC layer to reduce the number of parameters and to avoid overfitting.However, an original FC layer structure may not perform well over the target dataset because the FC layers are designed for different source tasks [43].Therefore, seven different FC layer structures, such as Dense1, Dense2, Dense3, Pool, Pool + Dense1, Pool + Dense2, and Pool + Dense3, were tested.Table 6 shows accuracy, number of parameters, model size, training, and test time depending on FC layer structure with DenseNet121.Models with the global pooling layer generally had fewer parameters and took less time to train and test.This shows that the global pooling layer dramatically reduces the number of parameters and model size.However, it did not lead to a significant reduction in training and test time.Given that the original DenseNet121 structure, Pool, had the lowest accuracy of 79.17%, changing the fully connected layer structure in transfer learning could improve accuracy.Among the modified structural models, Dense2 with no pooling layer and two FC layers had the highest accuracy at 84.67%.Table 7 shows the accuracy of the modified DenseNet121 by optimizer and learning rate.Learning rate determines the rate at which the weights are updated, and the optimizer determines the way in which the weights are updated.So, learning rate and optimizer are both key factors in determining model performance [44,45].Four different optimizers, including Adam, Adagrad, RMSprop, and SGD, were optimized to the modified DenseNet121.As a result, the RMSprop optimizer with 0.0001 learning rate showed the highest accuracy at 85.17%.In Table 8, the optimized DenseNet121 model's performance in Dataset 2 was higher than in Dataset 1, with an accuracy rate of 94.89%.This is consistent with the fact that the model's performance increased when two similar classes were grouped into one class in the study by Nagpal et al. [46].In Dataset 3, the discrimination accuracy was 75.67%, lower than in Dataset 1.In Figure 7a, among the 89 misclassified cases, 60 cases were between the first and second grades in the confusion matrix.Chang et al. [11] explained that small defects play a decisive role in high-graded red ginseng.Furthermore, the image data on one side may not contain the parts involved in the grading.Additionally, Chung and Shin [47] showed that internal quality, the presence of inner whitening or holes, was a significant factor in distinguishing high grades.In conclusion, the classification accuracy of first and second grades by appearance only is limited, and to compensate for this, a method to evaluate internal quality is required.However, the three groups, high, third, and out-of-grade, can be determined by external factors only.than in Dataset 1.In Figure 7a, among the 89 misclassified cases, 60 cases were between the first and second grades in the confusion matrix.Chang et al. [11] explained that small defects play a decisive role in high-graded red ginseng.Furthermore, the image data on one side may not contain the parts involved in the grading.Additionally, Chung and Shin [47] showed that internal quality, the presence of inner whitening or holes, was a significant factor in distinguishing high grades.In conclusion, the classification accuracy of first and second grades by appearance only is limited, and to compensate for this, a method to evaluate internal quality is required.However, the three groups, high, third, and out-ofgrade, can be determined by external factors only.(Unit: %) Grade Dataset (1)  Recall Precision F1_Score Accuracy Dataset 1 85.17 85.17 85.12 85.17

Conclusions
This study aimed to automate the grading process of red ginseng by using learning models to apply various preprocessing methods, selecting an accurate and efficient model, and exploring the possibility of a classification based on comprehensive appearance.The classification performance varied depending on the preprocessing technique.These results indicate that RGB with CLAHE processing improved the deep learning models' performance in red ginseng analysis.The optimized DenseNet121 model demonstrated the

Conclusions
This study aimed to automate the grading process of red ginseng by using learning models to apply various preprocessing methods, selecting an accurate and efficient model, and exploring the possibility of a classification based on comprehensive appearance.
The classification performance varied depending on the preprocessing technique.These results indicate that RGB with CLAHE processing improved the deep learning models' performance in red ginseng analysis.The optimized DenseNet121 model demonstrated the highest accuracy, 85.17%, among the models.However, its performance varied when trained on different datasets.Specifically, when trained with Dataset 2, the model achieved an accuracy of 94.89% by grouping first-and second-grade ginseng into the same highgrade group.Conversely, when trained with only the first and second grades in Dataset 3, the model's accuracy decreased to 75.67%.These findings suggest that classifying firstand second-grade red ginseng solely with RGB images using deep learning methods has limitations and requires internal inspection.Nonetheless, the method shows great potential for classifying the third grade, out-of-grade, and high grades.Future studies can explore the development of an automated red ginseng grading system with practical experiments in an offline environment using deep learning methods, and investigate other methods that can inspect internal quality to improve the classification accuracy of first-and second-grade red ginseng.

Figure 1 .
Figure 1.Photograph of the light chamber for red ginseng image acquisition.

Figure 1 .
Figure 1.Photograph of the light chamber for red ginseng image acquisition.

Figure 1 .
Figure 1.Photograph of the light chamber for red ginseng image acquisition.

Figure 3 .
Figure 3. Overall framework of the transfer models.

Figure 3 .
Figure 3. Overall framework of the transfer models.

Figure 4 .
Figure 4. Preprocessed image and histogram: image of (a) CLAHE, (b) Original, and (c) Blur; (d-f) histograms of CLAHE, Original, and Blur, respectively and the values of the blue, green, and red are represented by B, G, and R.

Figure 4 .
Figure 4. Preprocessed image and histogram: image of (a) CLAHE, (b) Original, and (c) Blur; (d-f) histograms of CLAHE, Original, and Blur, respectively and the values of the blue, green, and red are represented by B, G, and R.

Figure 4 .
Figure 4. Preprocessed image and histogram: image of (a) CLAHE, (b) Original, and (c) Blur; (d-f) histograms of CLAHE, Original, and Blur, respectively and the values of the blue, green, and red are represented by B, G, and R.

( 1 )
Dataset 1 contains first, second, third and out-of-grade; Dataset 2 contains high, third and out-ofgrade; Dataset 3 contains first and second grade.

Table 1 .
Specific configurations of the CNN model.

Table 2 .
Physical characteristics of red ginseng by grade.

Table 3 .
Performance of models by preprocessing.

Table 5 .
Accuracy, model size, and training and test times of each model.

Table 4 .
Accuracy of models by epoch.

Table 5 .
Accuracy, model size, and training and test times of each model.

Table 6 .
Comparison of fully connected layer structure in the DenseNet121 model.

Table 7 .
Accuracy of models by optimizer and learning rate.

Table 8 .
Performance of optimized DenseNet121 by dataset.
(1)Dataset 1 contains first, second, third and out-of-grade; Dataset 2 contains high, third and out-of-grade; Dataset 3 contains first and second grade.

Table 8 .
Performance of optimized DenseNet121 by dataset.