Industrial Automation Assignment
Industrial Automation Assignment
Home Assignment
This case study explain a end-to-end use case of deep learning image
classification in order to automate the process of classifying
defective and non-defective castings in foundry.
Casting defects: These are the defects in the cast product occurred
during the casting process and they are undesirable.There are many
types of defect in casting like blow hole, pin hole, burr, shrinkage
defects, mould material defects, pouring metal defects, metallurgical
defects etc.
After training the model, the file containing the weights is generated
in this project it is named “vggmodel.h5”. This file was found to be
as heavy as 1.01 GB which was beyond my anticipation, at the end of
this tutorial I have provided the link to download this file. We can
use this file to predict or classify any other images of the castings.
Below is the code used to predict the image.
from keras.models import load_model
model = load_model('vggmodel.h5')import numpy as np
from keras.preprocessing import imagetest_image =
image.load_img('/home/murali/ds/data/casting
problem/casting_data/casting_data/train/ok_front/cast_ok_0_46.jp
eg', target_size = (300, 300))test_image =
image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = model.predict(test_image)
print(result)if result[0][0] == 1:
prediction = 'CASTING IS OK'
print(prediction)
else:
prediction = 'CASTING IS DEFECTIVE'
print(prediction)
The above code will load the pre-trained model , I have added print
statement, so that user comes to know the status of process.
def openfilename():
# open file dialog box to select image
# The dialogue box has a title "Open"
filename = filedialog.askopenfilename(title ='Select Image')
return filename
if result[0][0] == 1:
prediction = 'CASTING IS OK' '
else:
prediction = 'CASTING IS DEFECTIVE'
The root is the name of our window, root.title will set the title of our
window as “CASTING INSPECTOR”, root.geometry will set the size
of the GUI window. The root.resizable helps to restrict the resize
option. Then two buttons are created, one for browsing and opening
an image file and the second one for prediction using the model. The
button btn_open_image calls open_image() function discussed
earlier, where as button btn_predict will call the
function prediction() which will predict the class, the image belongs
to. Finally, the working of casting inspector is as show below
Conclusion
https://drive.google.com/file/d/1r0FbT0vd-YfFaWzPLx84txsKnLF-
G3Dc/view?usp=sharing
https://github.com/muralimambekar/casting_inspector