This repository include the binary executables and Python codes for reproducing the results of the paper "Predicting Defects in Laser Powder Bed Fusion using in-situ Thermal Imaging Data and Machine Learning", found here, published in the Journal of Additive Manufacturing.
The core part of this work is the data post-processing procedure. After the data registration, where
each voxel with the coordinates X, Y, Z
and thermal features including τ and T is mapped into its binary label as
0 or 1 (healthy or defective), the unfolding process is performed on the dataset. Unfolding means
using sliding kernels K3, K5, K7 to include the thermal features of each voxel itself and features
of 1st, 2nd and 3rd nearest neighbor voxels around it. Then, Voxels near the top, bottom and side surfaces
of the built volume are excluded from the data if they do not have the complete set of neighbors (this is because
the voxels near the surface and boundary do not participate in the heat transfer during LPBF or they have different
heat transfer physics comparing to the voxels far from the boundaries. The following figure show the processes of
data post-processing, data unfolding and then training, validation, testing path:
There are four different steps for the post processing of the raw data to result in clean and proper dataset to be fed into the ML models which are as follow:
I. Indexing the coordinates, features and labels of the points and creating a 3D image where points are converted to grid image pixels.
II. Assigning -1 to the pixels inside the square gride where there is no labeled pixel data and it covers around
the boundary pixels. This is a small part of an image as most part of the image includes the pixels with binary values, [0, 1]
.
III. Unfolding the labels, features and coordinates in x,y and z directions with different windowing kernels based on the idea
of convolutional kernels to take into account the features of the different nearest neighbors around a central point. Through this process,
the 3D image will be patched using various kernel sizes. We use kernels with dimension
IV. After unfolding the data with desired kernel, we need to remove pixels with -1 values in the patched data after unfolding. In the last step, indexes corresponding to -1 values are recognized and the framing kernel including the -1 is removed.
Post processing the data is the most important part of any ML method to provide the model with proper and clean dataset. In this work,
the available data is N
points with their 3D coordinates, two features for each point and their labels, 0
or 1
, as fully dense or defective.
Our goal is to use different nearest neighbor features to predict the label of each target pixel based on the physics of the
manufacturing process and provide the model with more information to help it to have better predictions. So, the first step is converting
the points to pixels on a 3D rectangular cube grid (square grid in 2D). It could be a 3D cube if the number of dimensions in x, y, z
directions
are equal. To do this, it is needed to index coordinates, features and labels of all data points through the process of indexing.
Indexing the labels of points based on their 3D cartesian coordinates will map them to the grid pixels and it provides images with
dimension numpy
array with dimension
From part I., x,y,z
coordinates corresponding to each point in the
dataset are assigned to 0, 1, -1
are made where each image has the
dimension (size) of
In order to consider the features of different nearest neighbor pixels around each pixel in addition to each pixel’s feature,
unfolding
of the image pixels is done in the direction of different dimensions using appropriate windowing kernels of interest. As it
was mentioned in the problem definition, dimension (size) of the framing kernel is 1, 3, 5, 7
based on different combinations. For example, if the images are going to be unfolded using 5
and 3
, respectively and it turns out that this kernel in 2D (xy) for each layer
has the size of PyTorch
where its arguments are dimension, size and step and this module returns the unfolded (patched) Torch tensor
. The unfold module
works as x.unfold(dimension, size, step)
where x
is a Torch tensor that we are interested in and we want to unfold it. So, here, dimension
is the unfolding dimension with the slices equal to size and step is the step between slices. So, step is similar to the slide parameter
for convolutional kernel and it is the sliding value that the unfolding window scans the image. In the case of the Y.unfold(0,k1,1).unfold(1,k1,1).unfold(2,k2,1)
and then reshaped into the size
After unfolding is done for each of labels, features and coordinates, it is the time to get rid of the pixel values equal to -1. For all the unfolded tensors, we just keep the indexes that do not include any -1 pixel value. So, through this, automatically, we are removing the kernels that include -1 pixel values. Through the process of removing kernels that include -1 pixel values, the voxels near the surface of the built sample are excluded which have minimum effect in heat transfer in the LPBF.
import numpy as np
import torch
data = np.load("XY_raw.npz")
X, Y = data["X"], data["Y"]
X, Y = torch.tensor(X), torch.tensor(Y)
k = [1, 3, 5, 7]
# label unfolding
Yu = Y.unfold(0, k[1], 1).unfold(1, k[1], 1).unfold(2, k[1], 1).reshape(-1, k[1], k[1], k[1]).reshape(-1, k[1]*k[1]*k[1])
# feature unfolding
Xu = X.unfold(0, k[1], 1).unfold(1, k[1], 1).unfold(2, k[1], 1).reshape(-1, k[1], k[1], k[1], 2).reshape(-1, 2*(k[1]*k[1]*k[1]))
ind_nan = torch.unique((Yu == -1).nonzero()[:, 0])
ind = np.setdiff1d(range(Yu.shape[0]), ind_nan)
X, Y = Xu[ind].numpy(), Yu[ind, (k[1]*k[1]*k[1])//2].numpy()
The same process as above can be applied to 3D cartesian coordinates to unfold them.
This work has used:
- imbalanced-learn
- pyTorch
- scikit-learn
- numpy
- scipy
- pandas
Details of the MLP architecture used in this work could be found in our paper's Supporting Information (SI). The SI for this work is very rich and informative.
Find this useful or like this work? Cite us with:
{
title = {Predicting defects in laser powder bed fusion using in-situ thermal imaging data and machine learning},
journal = {Journal of Additive Manufacturing},
volume = {58},
page = {103008},
year = {2022},
doi = {10.1016/j.addma.2022.103008},
url = {https://www.sciencedirect.com/science/article/abs/pii/S2214860422004018},
authors = {Sina Malakpour Estalaki, Cody S. Lough, Robert G. Landers, Edward C. Kinzel, Tengfei Luo}
}