Espirais

Nos vais e vens dos giros do mundo, muitas vezes os caminhos parecem nos trazer para os mesmos lugares que por tanto tempo habitamos e fizemos esforço para sair. À primeira vista, a vida parece a…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Deep Learning for Marble Defect Classification

Why building a model for defect detection?
Some would say that because after all, we can see it with our own eyes.

Let me guide you through “Why”.
Here are the reasons:

It can be implemented as an IoT application for Marble Industry. A lot of industries have been started adopting IoT services.

So, without delay let’s get started. Here are the contents of the article.

Content:

About Dataset

Data Import

We will start by importing the required libraries and the main directory paths.

Here’s the path to the train and test directory. In your case choose the path directed to your notebook.

Visualizing Images

Let’s create functions to visualize images. For example to fetch an image through a given path. Just to check the size.

Output:

Cracked Marble

Image Data Generator

Output:

Let’s create a dictionary that contains labels for each class and keys for them. Later it will be used to fetch class names.

Now, we will build a data frame that contains an absolute path to each image and its label.

Visualizing Images

Let’s create a function to visualize images. For example to fetch n number of images of good marble from data frame.

This will be used later to visualize if the predictions are correct or not.

To visualize images from the generator, we will create another function.

Images look like this:

Marble images from the train generator

Model Architecture

The model will contain:

Conv2d layers will extract features from the images in pieces, Dense layer will tune up the weights for them. MaxPooling2D layer will reduce the dimensionality for easier computation and Dropout layers will avoid the overfitting of the model.

The model summary is given below:

Use the below code for building architecture.

Compile and Evaluate

To compile the model, we will use :

Categorical cross-entropy as loss function because the task is multi-class classification. We will also use EarlyStopping callback to call the function back if it doesn’t improve after some epochs. We will do this by passing patience as a parameter to the callback.

Here’s the full code

Compile and evaluate the model on the validation dataset.

Output:

Accuracy Curve

Let’s try to predict any image available in the validation data set.

Pass in n any number between 0–19 because there are 20 images from each folder since we specified 20 as batch size during Image Generator initialization.

Output:

Predicted Image as Good

Let’s check if other good images are like this or not.

Good Marble Images

Save the model!

Thankyou! for reading my story. Don’t forget to try different hyperparameters and see if the score can be improved.

Add a comment

Related posts:

Gymnastics Maintains A High Level Of Flexibility

Gymnastics requires an adequate level of cardiorespiratory fitness, corpse muscle strength, and also full body flexibility. More than any sport, it encompasses technical movements that need to be…

Want your partner to work on your relationship as much as you do? Listen to this marriage therapist

After a while in a relationship, we tend to get comfortable; sometimes a little too comfortable. Weekly dates can fall by the wayside, check-ins can go forgotten, and even anniversaries — once a…

Publishing Azure Functions to Azure using Visual Studio 2019

In this blog we will be publishing a sample Azure Function to Azure using Visual Studio 2019. After completing the steps your function will be available globally and can be accessed using an URL. I…