{"id":1317,"date":"2021-12-05T06:42:03","date_gmt":"2021-12-05T06:42:03","guid":{"rendered":"https:\/\/salarydistribution.com\/machine-learning\/2021\/12\/05\/ml-in-manufacturing-detecting-defects-with-unsupervised-learning-and-image-feature-extraction\/"},"modified":"2021-12-05T06:42:03","modified_gmt":"2021-12-05T06:42:03","slug":"ml-in-manufacturing-detecting-defects-with-unsupervised-learning-and-image-feature-extraction","status":"publish","type":"post","link":"https:\/\/salarydistribution.com\/machine-learning\/2021\/12\/05\/ml-in-manufacturing-detecting-defects-with-unsupervised-learning-and-image-feature-extraction\/","title":{"rendered":"ML in Manufacturing: Detecting Defects with Unsupervised Learning and Image Feature Extraction"},"content":{"rendered":"<div>\n<p>A while ago, when I was studying at the university, my professor shared a nice story about a fruit import and export company that was concerned about their quality control system for watermelons, which was starting to falter. Some watermelons that weren\u2019t yet ready to be consumed were escaping their controls. I immediately thought the reason would be data drift or overfitted models, thus, they would need to retrain their Machine Learned models. However, my professor mentioned that their quality control system was, in fact, an 80-year old man who had the amazing ability to know if a watermelon was ready to be consumed only by hitting it and listening to the sound the watermelon made. Although I found this way of working was pretty peculiar, this quality control system could also use some data-driven insights that would lead to some room for improvement.<\/p>\n<p>Quality control remains an issue for many companies. Even subtle variances during processes in assembly lines can cost companies huge amounts of money down the line. Fortunately, BigML can help with that. In this post, we will show how to use <strong>image feature extraction and unsupervised learning to find defects in images from a manufacturing process<\/strong>. Specifically, we will focus on the casting process. Casting is a manufacturing process in which a liquid material is usually poured into a mold, which contains a hollow cavity of the desired shape, and then allowed to solidify.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-attachment-id=\"30208\" data-permalink=\"https:\/\/blog.bigml.com\/bigml_image_manufacturing\/\" data-orig-file=\"https:\/\/littleml.files.wordpress.com\/2021\/12\/bigml_image_manufacturing.jpg\" data-orig-size=\"1200,630\" data-comments-opened=\"1\" data-image-meta='{\"aperture\":\"0\",\"credit\":\"\",\"camera\":\"\",\"caption\":\"\",\"created_timestamp\":\"0\",\"copyright\":\"\",\"focal_length\":\"0\",\"iso\":\"0\",\"shutter_speed\":\"0\",\"title\":\"\",\"orientation\":\"0\"}' data-image-title=\"bigml_image_manufacturing\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/littleml.files.wordpress.com\/2021\/12\/bigml_image_manufacturing.jpg?w=300\" data-large-file=\"https:\/\/littleml.files.wordpress.com\/2021\/12\/bigml_image_manufacturing.jpg?w=810\" src=\"https:\/\/littleml.files.wordpress.com\/2021\/12\/bigml_image_manufacturing.jpg?w=1024\" alt=\"\" class=\"wp-image-30208\"><\/figure>\n<h2 id=\"using-anomaly-detection-to-find-casting-defects\">Using Anomaly Detection to Find Casting Defects<\/h2>\n<p>The dataset we\u2019re going to use, originally from <a rel=\"noreferrer noopener\" href=\"https:\/\/www.kaggle.com\/ravirajsinh45\/real-life-industrial-dataset-of-casting-product\" target=\"_blank\"><strong>Kaggle user ravirajsinh45<\/strong><\/a>, contains several images of pump impellers that were made using metal casting. For this example, we will use a reduced version of that dataset with just 112 images, which can be found <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/bigml-production-media.s3.amazonaws.com\/casting+example.zip\" target=\"_blank\">here<\/a><\/strong>. Common pump impellers look like this:<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/9OEyvnkedtulj0ehiSO6qRchfbMuFE42Wes78NAi7zulE7IXYFdyw9ZCoydEB-TtAOcGEZ55KzamuUA_MDrUUbv8_MUf9362Zx3AKhOK-fe-_RAlvj_RsBvxwUPADhHvnUdZLVA\" alt=\"4 images of pump impellers with no defects\"><figcaption>Pump impellers with no defects<\/figcaption><\/figure>\n<p>Out of those 112 images, 106 are fine but the remaining <strong>6 pump impeller images contain some defects <\/strong>that render them unusable since they look as below:\u00a0<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" loading=\"lazy\" data-attachment-id=\"30181\" data-permalink=\"https:\/\/blog.bigml.com\/image-27\/\" data-orig-file=\"https:\/\/littleml.files.wordpress.com\/2021\/11\/image.png\" data-orig-size=\"645,387\" data-comments-opened=\"1\" data-image-meta='{\"aperture\":\"0\",\"credit\":\"\",\"camera\":\"\",\"caption\":\"\",\"created_timestamp\":\"0\",\"copyright\":\"\",\"focal_length\":\"0\",\"iso\":\"0\",\"shutter_speed\":\"0\",\"title\":\"\",\"orientation\":\"0\"}' data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/littleml.files.wordpress.com\/2021\/11\/image.png?w=300\" data-large-file=\"https:\/\/littleml.files.wordpress.com\/2021\/11\/image.png?w=645\" src=\"https:\/\/littleml.files.wordpress.com\/2021\/11\/image.png?w=645\" alt=\"6 images of defective pump impellers\" class=\"wp-image-30181\" width=\"737\" height=\"443\"><figcaption>Defective pump impellers<\/figcaption><\/figure>\n<\/div>\n<p>Please note that those defects are sometimes tiny and hard to catch by a human eye, but BigML can greatly help us in this task. We first upload the .zip file with the images. Since <em>good\/bad <\/em>images are already separated into folders, BigML automatically labels all instances in our <a href=\"https:\/\/blog.bigml.com\/2021\/11\/24\/composite-sources-in-bigml\/\"><strong>composite source<\/strong><\/a>. If you need a refresher, feel free to read our <a href=\"https:\/\/blog.bigml.com\/2021\/11\/29\/the-many-ways-of-labeling-images-on-the-bigml-platform\/\"><strong>Image Labeling blog post<\/strong><\/a> for more details.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/sK2NpbYR_oeP8lC1B7AP6UhjKAceNu0bE4gQtSzRy5nlpDS0IqFRNoyNzewFDBE3wiRufQFXdv87ARTjRdnWrZ_xeweWJrpMra8Fs8WhBSfMi9Jbp2r4DhWg2xHppudv_IMlAhw\" alt=\"BigML Composite Source view\"><figcaption>BigML Composite Source view<\/figcaption><\/figure>\n<\/div>\n<p>Before creating the dataset, we need to modify the default Image Analysis options from our composite source. As this is a complex problem with many possible kinds of subtle defects, we prefer to use the <strong>Histogram of gradients<\/strong> and <strong>MobilenetV2<\/strong> as feature extractors:<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/1eHzG_-j2_AhB1_oQWgHrTGLsEEgDh6r-0gqJ0RgWmGqOMfgInZy6L_snRmFcoga3cl54oiafu4-ZBCjf6wD3qVsNiKfOT_sudvRlkzz2PhExbZpFmPZoUznZyYNxjuRLpDjZig\" alt=\"BigML Image analysis view in Source configuration\"><figcaption>BigML Image analysis view in Source configuration<\/figcaption><\/figure>\n<p>We then update the source and create a dataset (note that the source is automatically closed as we do so).\u00a0As mentioned above, we\u2019re working with a highly imbalanced dataset, with <strong>only 6 bad (defective) instances out of the 112 total images<\/strong>.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/3dwiDrm2cUThKCDkV5KlrSsYt_QAYm9PBeWgGfhDEi3XY57nb7sQVopfvHhfpwzLF_e_WtfSqW04JzbxWI3H-JKxCNpcO1TL_kWt7NFd_O7tDasFePz8XxYU9W2Rs_bdkpq6PE0\" alt=\"Casting dataset within BigML\"><figcaption>Casting dataset within BigML<\/figcaption><\/figure>\n<p>Next up, we just create a <strong>1-Click Anomaly<\/strong> <strong>Detector<\/strong> and\u2026 <em>voil\u00e0! <\/em> Our 6 defective pump impellers will appear <strong>within the Top-7 Anomalies<\/strong>!<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/6wx6NdqGuTCpvzHd7tBXhUrnJREDBzgNXUqtXooWb20JGOmFjLq_0O6IwOnk6xleN3z__z_yYj0DK9t6dJee8d2NHz51NspZMVVcHABTisHX1p3hAFFhCXfxvYiExFrvN_Ax9Ds\" alt=\"\"><\/figure>\n<h2 id=\"why-unsupervised-learning\">Why Unsupervised Learning?<\/h2>\n<p>If we tried to solve this problem with a supervised model, we would have to deal with a <strong>highly imbalanced <\/strong>dataset. As such, this task would be very time-consuming because trying to create a robust model, without overfitting, from a training dataset that contains only 6 instances from one of its classes is clearly not an easy task.<\/p>\n<p>Additionally, in most manufacturing processes, we may find a wide variety of defects of a different kind, and some of them can be due to faults in machines that we have never seen before. Therefore, we can\u2019t just train a supervised model with historically labeled images of faults. <\/p>\n<p>Unsupervised learning models help us to find patterns in data, even without labels!<\/p>\n<h2 id=\"beyond-image-classification-and-object-detection\">Beyond Image Classification and Object Detection<\/h2>\n<p>When thinking about <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Convolutional_neural_network\" target=\"_blank\"><strong>Convolutional Neural Networks<\/strong><\/a>, people sometimes forget that you can imagine them as a <em>trainable feature extractor <\/em>plus a classifier\/regressor (referring to the readout layer at the end of the network). If you take only the first part, you will have a great tool to<strong> transform raw images into the expected <em>tabular<\/em> form that BigML models expect<\/strong>. After applying the desired feature extractors to our image datasets we have datasets <strong>ready to be consumed by any of the supervised and unsupervised models that BigML offers<\/strong>. With this approach, the sky is the limit!<\/p>\n<p>That\u2019s exactly what we have seen in today\u2019s example and there are plenty of use cases where doing unsupervised learning with image extracted features can be the key to solving a real-life business problem. Some fine examples where applying unsupervised learning techniques can have a great impact involve images from security cameras. Using Anomaly Detectors, one can detect uncommon events (e.g., fires, intrusions, etc.). Another example would be Cluster Analysis, which is very useful to find related images so that users can order their personal digital image libraries by grouping related pictures.<\/p>\n<p>Can you imagine more examples like the above? Feel free to share them with us. Or, even better, we encourage you to try them yourself with the BigML platform!<\/p>\n<h2 id=\"d\">Do you want to Know more about Image Processing?<\/h2>\n<p>Please\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/bigml.com\/releases\/image-processing\" target=\"_blank\"><strong>visit the dedicated release page<\/strong><\/a>\u00a0for a gentle introduction to Image Processing and\u00a0join the <strong>FREE live webinar on Wednesday, December 15<\/strong> at 8:30 AM PST \/ 10:30 AM CST \/ 5:30 PM CET. <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/attendee.gotowebinar.com\/register\/3316692637331486991\" target=\"_blank\">Register today<\/a><\/strong>, space is limited!<\/p>\n<p>Finally, stay tuned for the upcoming blog posts about\u00a0<strong><a rel=\"noreferrer noopener\" href=\"https:\/\/bigml.com\/image-processing\/\" target=\"_blank\">Image Processing<\/a><\/strong> with more examples and tutorials on how to use Image Processing through the API, WhizzML, and the Python Bindings, as well as how this new feature has been implemented on the BigML platform.<\/p>\n<div id=\"jp-post-flair\" class=\"sharedaddy sharedaddy-dark sd-like-enabled sd-sharing-enabled\">\n<div class=\"sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded\" id=\"like-post-wrapper-30283844-30178-61ac5f3b903cc\" data-src=\"\/\/widgets.wp.com\/likes\/index.html?ver=20211129#blog_id=30283844&amp;post_id=30178&amp;origin=littleml.wordpress.com&amp;obj_id=30283844-30178-61ac5f3b903cc&amp;domain=blog.bigml.com\" data-name=\"like-post-frame-30283844-30178-61ac5f3b903cc\" data-title=\"Like or Reblog\">\n<h3 class=\"sd-title\">Like this:<\/h3>\n<p><span class=\"button\"><span>Like<\/span><\/span> <span class=\"loading\">Loading&#8230;<\/span><\/p>\n<p><span class=\"sd-text-color\"><\/span><a class=\"sd-link-color\"><\/a><\/div>\n<h3 class=\"jp-relatedposts-headline\"><em>Relacionado<\/em><\/h3>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/blog.bigml.com\/2021\/12\/03\/ml-in-manufacturing-detecting-defects-with-unsupervised-learning-and-image-feature-extraction\/<\/p>\n","protected":false},"author":0,"featured_media":1318,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1317"}],"collection":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/comments?post=1317"}],"version-history":[{"count":0,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1317\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media\/1318"}],"wp:attachment":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media?parent=1317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/categories?post=1317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/tags?post=1317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}