Convolutional neural network–based classification for improving the surface quality of metal additive manufactured components

The metal additive manufacturing (AM) process has proven its capability to produce complex, near-net-shape products with minimal wastage. However, due to its poor surface quality, most applications demand the post-processing of AM-built components. This study proposes a method that combines convolutional neural network (CNN) classification followed by electrical discharge-assisted post-processing to improve the surface quality of AMed components. The polishing depth and passes were decided based on the surface classification. Through comparison, polishing under a low-energy regime was found to perform better than the high-energy regimes with a significant improvement of 74% in surface finish. Also, lower energy polishing reduced the occurrences of short-circuit discharges and elemental migration. A 5-fold cross-validation was performed to validate the models, and the results showed that the CNN model predicts the surface condition with 96% accuracy. Also, the proposed approach improved the surface finish substantially from 97.3 to 12.62 μm.


Introduction
The metal additive manufacturing (AM) process uses a layer-by-layer build strategy to produce complicated parts from CAD STL files. The process possesses several advantages over conventional manufacturing methods due to its capability to produce complex components with minimal wastage [1]. However, the parts produced by AM process have inferior surface integrity in terms of surface finish, subsurface hardness, wear resistance, and residual stresses [2,3]. In order to address the aforementioned issues, the post-processing of AM components is considered a necessity [4]. Though polishing can improve the surface quality of as-built components, selecting the right polishing depth is of supreme importance to reduce wastage and minimize dimensional deviation.
Several finishing techniques have been proposed in the past to improve the surface integrity of metal AM components. The board categories of polishing/finishing methods are laser polishing, conventional (mechanical) polishing, abrasive polishing, chemical polishing, and hybrid polishing [4]. Laser polishing is one of the widely used methods to improve the surface integrity of metal AM components. One of the earlier implementations of the method to polish metal AM components was by Lamikiz et al. [5]. When compared to the as-built selective laser melt (SLM) component, a surface roughness improvement of 80% (from 7.5 to 1.5 μm) was achieved through laser polishing. Zhihao et al. [6] further improved the results to achieve a surface finish of up to 0.1 μm during fibre laser polishing of SLM-built Inconel 718. However, the processing time of laser polishing is higher due to the smaller spot diameter. Recently, chemical polishing has also been utilized to finish the metal AM components; however, it cannot reach intricate and complex profiles [7]. Tyagi et al. [8] reported the performance improvement of electro-polishing over chemical polishing in terms of achievable surface finish. Also, the process is not environmentally friendly and is difficult to control. Abrasive flow machining was used to reduce the surface roughness from 14 to 2 μm by Peng et al. [9]. In addition to a 40% enhancement in surface finish, a 15% improvement in subsurface hardness is observed after ultrasonic cavitation abrasive finishing [10]. Conventional polishing methods like milling and grinding have also been attempted to finish metal AM components. Salmi et al. [11] used CNC milling for finishing the metal AM components. A comparative study on the effectiveness of milling, blasting, grinding, and micromachining in polishing SLM-built Ti6Al4V parts was conducted by Bagehorn et al. [12]. Among these, milling was found to be the most effective method for improving the surface finish. However, mechanical polishing is not suitable to finish intricate profiles.
At this juncture, several researchers started to explore hybrid polishing techniques to overcome the limitations of the existing methods. Yamaguchi et al. [13] introduced a hybrid technique which combines magnetic-assisted polishing and burnishing to impart compressive residual stresses to AM-built components. Furthermore, a hybrid method combining chemical and abrasive polishing was reported to improve the surface finish of AM-built Inconel 625 by 45% [14]. Subsequently, Iquebal et al. [15] combined milling and abrasive finishing to improve the surface finish and porosity of AM-built SS316 components. Bai et al. [16] performed a hybrid mechanical-chemical polishing for finishing SLMfabricated SS316L parts. The technique improved the surface finish of both top and side surfaces. In the past, electric discharge-based finishing operation has been successfully implemented on metallic components [17]. Based on this understanding, wire electric discharge polishing (WEDP) is one of the newest hybrid techniques to enhance the surface quality of metal AM components [18,19]. The method resulted in improved surface finish, elemental migration, subsurface microhardness, and wear performance.
For polishing the metal AM components, the required polishing depth and parameters are to be decided based on the as-built surface condition and defects. Image processing-based surface classification of AM components is a topic of growing research interest due to its effortless handling and in-process inspection capabilities. Among the existing image processing methods, the convolutional neural network (CNN) is one of the most capable and promising deep learning methods for surface classification. A CNNbased laser polishing strategy was devised by Caggiano et al. [20]. The polishing parameter selection was based on the surface condition predicted using a CNN model. Zhang et al. [21] have demonstrated the capability of CNN to predict and classify AM surface images. In this work, the authors have classified the surfaces based on the quality of hatch line overlaps to produce a good-quality surface. Weimer et al. [22] developed deep CNN to automate the detection and classification of machined surface defects. Here CNN systematically extracts relevant features from training data to accurately predict the surface defects with minimal human intervention. The performance of various CNN architectures with respect to accuracy and computational runtime is compared in this study. Since the previous CNN-based techniques demand a large quantity of labelled image data for accurate prediction, Xiang et al. [23] explored the possibility of developing a semi-supervised CNN model which works with limited and low-quality data. The proposed method classifies weld pool images into "under melt," "over melt," and "good weld." The trained model was validated using real-world metal AM images, and the results obtained were very promising.
In this study, a CNN classifier is developed to categorize the AM component from its surface images. This is an easier and more convenient approach for the automatic identification of surface conditions, based on which the polishing conditions can be decided. While the existing polishing methods were proven to be capable of improving the surface quality of metal AM components, they also have several limitations largely due to the difficulty in controlling the polishing process. Therefore, in this study, an electric discharge-assisted polishing method is employed which uses low-energy discharge pulses to precisely remove the required depth, in such a way that the surface defects/irregularities are eliminated from the AM surface.

Electric discharge-assisted polishing method
A hybrid polishing method called WEDP is proposed in this study. In WEDP, the mechanism of finishing is by melting a thin layer of the uneven surface by controlled and repetitive low-discharge energy sparks as shown in Fig. 1. The discharges happen between a thin metallic wire and a conductive workpiece. The discharge energy results in localized temperature rise causing melting of the workpiece surface asperities. Unlike the EDM cutting operation, in WEDP, the wire does not travel into the surface but moves along the periphery of the workpiece surface [24,25]. To completely remove the peaks and valleys of an AM-built surface, the minimuam polishing depth required will be equal to S z (maximum profile height of a surface, i.e. the maximum difference between the highest peak and lowest valley) as shown in Fig. 1. Polishing removes the irregularities and defects of the top surface, thereby resulting in an overall enhancement of surface quality. The polishing is performed in a low discharge energy regime to minimize the thermal effects.

Materials and methods
Compared to other machine learning models, a convolutional neural network (CNN) is better equipped for AM surface classification due to its better efficiency, robustness, and generalization capabilities. CNN is a deep learning method which uses inter-connected neurons to classify the images into various groups or categories [26]. Each neuron is a computational unit which passes its output to the next layer and so on. Each inter-neuron connection will have a weight and bias associated with it which are tuned during the training phase to maximize the classification accuracy [27]. A ResNet-50 architecture, a feed-forward backpropagation data flow, and a gradient descent training algorithm are considered for the study. This structure contains 50 layers with 5 convolutions as shown in Fig. 2. The first convolution contains a single layer which is followed by the Maxpool layer. The remaining 4 convolutions have layer sizes of 9, 12, 18, and 9, respectively. These convolutional layers are followed by an average pooling layer and a fully connected layer. Each layer has different sets of kernels/filters which are matrices which stride over the input data to extract certain relevant features by performing dot product operations.
The input image is resized into 224-by-224 pixels. The final activation layer of the CNN structure is a SoftMax function. The function predicts a multinomial probability distribution based on the received inputs from the previous layers. The SoftMax function is given as where k is the number of classes and z is the input to the final layer.
A cross-entropy loss function is used to train the neural network. If ŷ i is the predicted class probability, y i is the true class probability and k is the number of responses; the cross-entropy loss function is given by The function takes the minimum value if the predicted class probabilities are equal to the true class probabilities.
Cross-entropy is a preferred loss function for image classification tasks where the task is to predict the probability of a class over a set of classes. It is a computationally efficient function that quantifies the difference between actual and predicted probabilities effectively even for large-scale deep networks. One of the reasons why it is a preferred function to train neural networks is its ability to give stable gradients during backpropagation. On the other hand, unstable gradients may be generated by incompatible loss functions and may cause the training to fail. Finally, the cross-entropy function is statistically stable because it is a convex function with a single minimum and is robust to minor input noises.
The overall summary of the proposed approach is shown in Fig. 3 and is described as follows:  • Firstly, 5 groups of AM samples are fabricated by varying the hatch spacing as it is evident from the literature that hatch spacing plays a significant role in determining the quality of metal AM surface [14,15]. Each printed sample is labelled from level 1 to level 5 based on the increasing order of hatch spacing. Among the 5 groups, level 1 is the smoothest having the least hatch spacing and level 5 is the roughest. Fifty images are captured for each surface condition. These 250 images along with their corresponding class labels constitute the training data. • The surface roughness parameter (S z ) is measured for each surface condition to relate the class labels with the required polishing depth. Since S z represents the largest peak-to-valley distance, polishing depth is selected based on the S z value. This ensures the complete elimination of all surface defects and irregularities present in the asbuilt surface. To suppress the effect of outliers, S z measurement is conducted thrice and the average S z value is considered as the polishing depth.
• The trained CNN model classifies the new AM as-built surface image into its appropriate surface category. The predicted category (levels 1 to 5) and its corresponding S z value determines the polishing requirements including polishing depth and the number of passes. • Subsequently, WEDP is performed to remove the surface defects and unevenness from the as-built AM component.
An EOS M290 DMLS (direct metal laser sintering) metal 3D printer is used to fabricate the samples. The sample dimensions are 15 mm × 10 mm × 10 mm. The workpiece material used in the present study is Ti6Al4V. An Electronica make wire electrical discharge machine is used to polish the metal AM specimens in this study. A zinc-coated brass wire of 0.25 mm diameter is chosen as the wire electrode. The machine can operate in multiple energy regimes, of which the lowest discharge energy regime is chosen for polishing the AM fabricated components. The parameter settings for EDM and AM processes are given in Table 1. Imaging was done using an Olympus optical microscope  under 10× magnification. Currently, the imaging is done offline after the part is printed since the microscope cannot be mounted inside the build chamber. However, online imaging and analysis are feasible by installing portable imaging hardware like a USB camera inside the build chamber.
Modelling and image processing operations were done using MATLAB version 2022a.

Polishing under different energy regimes
Experimental studies are conducted to compare the maximum effective polishing depth under different energy regimes. When operated in a high-energy regime, WEDP is capable of removing a deeper layer in a single pass compared to lower energy. Even though operating in higher energy mode reduces the polishing time, the quality of the surface is much inferior to that of a polished surface as seen in Table 2. The lower energy mode shows a significant surface roughness improvement of 46% and 74% when considering S z and S a , respectively. The higher energy mode produces a considerably higher number of short circuit pulses during the spark erosion which causes deeper craters and surface defects [28,29]. The short-circuit pulses are caused due to the ineffective flushing of debris from the inter-electrode gap. In addition, this regime also produces higher discharge energy/spark and peak discharge current. The cumulative effect is a coarser surface with deeper microcraters [30]. The low-energy regime is selected for the proposed polishing operation due to the aforementioned reasons. The pulse cycle comparison is shown in Fig. 4.
To train the CNN model, surfaces belonging to different categories are imaged as shown in Fig. 5. Fifty images were captured per category at different orientations and regions to increase the model's robustness. The average surface roughness values (S a and S z ) for all the conditions are given in Table 3. Corresponding to its surface roughness value, level 1 requires the least polishing depth and level 5 requires the most. It was experimentally found that a single polishing pass can effectively remove a maximum of 60 μm only. Therefore, multiple polishing passes are required if S z > 60 μm.

Performance of CNN model
A ResNet 50 architecture is followed for CNN-based image classification in this study. Here, the characteristic features of each image class are digitally extracted and then subsequently used for image classification. This is a supervised learning algorithm where the image class labels are given during the training. The ResNet architecture consists of convolutional layers for filtering the image data using kernels,   Fig. 6. ResNet50 used for this application is a pre-trained form of a model trained with over a million training images from the database-ImageNet [31]. The pre-trained networks reduce the risks of errors and save significant training time, which otherwise would take days/weeks to complete. The weights which are most likely to give good accuracy are preloaded and frozen to prevent them from altering. The model can train to a new classification task by tuning the weights of just the fully connected and output SoftMax layers. The computational cost for ResNet 50 is compared against other deep-learning image classification models by Li et al. [32]. However, for a more conclusive depiction of the superior computational efficiency of ResNet-50, it has to be evaluated against other competitive algorithms for the same training dataset, which is not attempted as a part of this study and will be taken up in the future.
A fivefold cross-validation sampling strategy was followed for this study which is shown in Fig. 7. Here, the entire dataset is divided randomly into 5 groups of 50 images each. Initially, 4 out of 5 groups (200 images) are used to  is used to test the model performance. Subsequently, the training is repeated by considering a different group as the test data. The training is repeated till each group is used as test data at least once. This method is a superior strategy to the conventional 70-30 division for training and testing datasets. Cross-validation improves data utilization and prevents biased results.
The overall prediction accuracy of the model is presented using a confusion matrix, which summarizes the number of accurate predictions among all class labels in a matrix form. Here, the correlation between predicted labels (y-axis) and true labels (x-axis) is presented. The diagonal green elements show the number of right predictions out of 50 data points. The red elements show the inaccurate predictions corresponding to each class. For instance, when the surface was actually level 1, it was predicted correctly in 47 out of 50 instances and it is inaccurately predicted as level 2, in the remaining 3 occasions. In the case of level 5, the surface was accurately predicted as level 5 in 46 instances and was predicted as level 4 in the remaining 4 instances. Level 2 was accurately predicted every time. Overall, 240 out of 250 predictions were accurate which gives an overall accuracy of 96% as indicated by the matrix shown in Fig. 8. It is also observed that all instances of inaccurate predictions have been for borderline cases, i.e., the surfaces are miscategorized as the immediate next class (level 1 as level 2, level 3 as level 2, level 4 as level 5, and so on). This marginal error is expected due to the discrete classification criteria.
A few existing studies which compare the classification performance of ResNet-50 architecture are given below: •   The primary reason for the superior performance of ResNet-50 CNN in comparison to other deep learning models is its deeper architecture and the capacity to learn distinguishable features from images using residual connections. This enables ResNet-50 CNN to learn more complicated patterns and classify similar-looking images with better accuracy. In addition, this architecture addresses the issue of vanishing gradients by using skip connections, which improves its prediction accuracy and results in quicker convergence.

Confirmation test on different materials
The capability of the CNN model to categorize AM-fabricated components of different materials and parameters other than the testing dataset is described in this section. For this, AM-fabricated components made of AlSi10Mg, SS316L and Ti6Al4V are selected. AlSi10Mg belongs to level 1 and has an S z value of 72.1 μm. The other 2 samples belonged to level 2. Ten images each were captured of all the 3 samples. The printing parameters along with the CNN prediction accuracy are given in Table 4.
The classification accuracy was found to be 80%, 90%, and 90% to predict the classes of AlSi10Mg, SS316L, and Ti6Al4V, respectively. The AM surface images of AlSi10Mg, SS316L, and Ti6Al4V are shown in Fig. 9. The overall validation accuracy of 87% will get improved if images from different materials are included in the training data.

(c) (d)
It is observed that the model gives the best accuracy while classifying the same material and parameters, but still produces slightly lower, yet acceptable results with the change in materials. This is because the irregularities like balling defects, pores, voids, and stair stepping are common for all the metallic materials which can easily be classified using the proposed model. This is clear from an overall accuracy of ~96% when using the same material (with reference to Fig. 8) and 80 to 90% when using different materials and parameters (Table 4). That being said, to ensure model robustness to changes in materials, more comprehensive training data is preferred with several common materials and parameters. Developing

Surface quality comparison
This section discusses the surface quality improvements after electrical discharge-assisted post-processing of metal AM components. Microstructural images are captured to compare the effect of polishing using a FESEM (Zeiss Gemini SEM300). As given in Fig. 10a, the as-built surface is observed to be very coarse and uneven with many voids and microglobules primarily due to the presence of unmelted and partially melted metal powders. In comparison, the polished surface is observed to be very uniform without any observable microsized features (Fig. 10b). An AEP make non-contact 3D profilometer is used to measure the roughness parameters. 3D surface morphology images of as-built and polished samples are presented in Fig. 7. It can be seen that the as-built surface (Fig. 10c) has deep valleys and high peaks in comparison to a smoother surface with microcrater-like features in the polished surface (Fig. 10d). Overall, an 86% improvement in surface roughness is observed after polishing. The S z value was reduced from an average of 97.3 to 12.62 μm as shown in Fig. 11. It is also worth mentioning that the surface roughness of all polished samples is very similar. The S a values also improved from 14.8 to 0.92 μm upon finishing.
One of the main limitations of the electrical discharge machining process is the elemental migration from the tool electrode to the workpiece [36]. This is due to the material removal from the tool electrode during the sparking and its subsequent deposition onto the polished surface. Energy-dispersive X-ray spectroscopy (EDS) analysis was performed to quantify the presence of zinc and copper on the polished surface. Under the as-built condition, only the constituent elements were present on the surface. However, after polishing, the presence of zinc and copper is detected on the surface, but in very marginal traces as seen in Fig. 12. Values 0.73% of copper and 0.43% of zinc are considered negligible compared to the weight percent of other elements.
WEDP addresses several technological and scientific limitations of alternate polishing methods to finish AM components as given in Table 5. Laser finishing of AM components is slow since the laser spot is small compared to the polishing area. Also, it is challenging to maintain the right focus and to polish the internal features. In comparison, WEDP is relatively fast since the entire part thickness is polished together. In the case of chemical polishing, process control is challenging especially in maintaining dimensional accuracy [47]. Moreover, there is a high possibility of elemental contamination and localized property alterations in the finished component. Abrasive polishing can result in abrasive impingement and radial error in sharp corners and edges [47]. WEDP on the other hand is well suited to maintain dimensional and corner accuracy since the polishing depth is extremely customizable and can be accurately controlled through its low discharge pulses. In this study, the superior performance of WEDP when combined with the intelligent polishing depth approach has resulted in an overall better surface finish improvement in comparison with most of the alternate polishing techniques. The only minor con is its tendency to produce tensile residual stress being a thermal process. However, recent research in EDM looks promising to address this issue and researchers are currently successful in producing EDM-processed parts having comparable residual stresses and fatigue life to that of mechanically processed components [48].
Apart from the aforementioned advantages, Jibin et al. have recently reported that WEDP produces uniform and defect free surfaces, uniform subgrain morphology, minimal elemental migration, improved microhardness, and reduced coefficient of friction [24]. Moreover, the process demonstrated reduced thermal residual stresses, better corrosion resistance, and no visible phase changes [25].

Conclusions
A hybrid process combining CNN and electric dischargeassisted polishing is proposed to improve the surface quality of the metal AM components. The proposed approach of CNN-based intelligent polishing depth identification followed by WEDP has demonstrated promising results in enhancing the surface integrity of metallic AM components. The results reveal the capability of the deep learning approach to accurately classify the AM-built surfaces according to their surface morphology. Subsequent electric discharge-assisted finishing has significantly improved the surface finish and eliminated the defects such as cracks, microglobules, and voids. The approach will have substantial industrial applications since it saves time and cost otherwise spent on manual inspection and polishing depth calculation.
The salient conclusions from this study are: • Surface post-processing through a low-energy regime of electric discharge-assisted polishing produced superior surface quality compared to under a high-energy regime (cutting). A 74% improvement in average surface roughness (S a ) and a 40% reduction in elemental migration are observed during polishing in comparison to cutting. • A deep-learning CNN model was successfully trained to predict the surface category of AM components. The obtained accuracy of the prediction was 96%. • According to surface conditions, polishing depth and number of passes were determined based on S z values. Surface unevenness and defects are reduced to a minimum after electrical discharge-assisted polishing. The surface roughness was improved by 86% from an average of 97.3 to 12.62 μm.
• Only a negligible amount of foreign elements (0.73% of copper and 0.43% of zinc) were found on the polished surface.
Though the approach is very promising even in its present form, a few future improvements can make the model even better. Being a supervised learning model, CNN's accuracy and robustness are closely related to the quality of the training data. With the current training dataset, the scope of the application is better suited for the considered material and parameters. A more extensive dataset including various materials and wider parameter ranges will improve the robustness of the model. Furthermore, the present approach can only address the external roughness and defects, but it can be developed further to identify internal defects as well if advanced imaging techniques like computed tomography (CT) are utilized to generate training image data. Finally, there is potential to develop the presented method into a real-time/in situ approach for surface classification and polishing depth computation by installing suitable vision sensors in the build chamber.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http:// creat iveco mmons. org/ licen ses/ by/4. 0/.