Skip to content

FPT-ThaiTuan/Using-deep-learning-to-classify-fruits-using-the-VGG16-model

Repository files navigation

Using deep learning to classify fruits using the VGG16 model

A. Data preprocessing

Collect data from kaggle Dataset

Create training, validation, and test data sets

Reshape the size

Mix photos

Normalize the data to [0,1] and the label converts to One-hot encoding

B. Build model VGG16

Before you proceed to build the model, you should learn about the VGG16 structure.

VGG-16-model-structure

VGG-16-model-structure

The model I built includes: 4 layers Conv2D Layer: This is a convolutional layer, where each unit performs a convolution on the input to extract features. In this code, we use 2 Conv2D layers with 32 and 64 filters of size (3,3) and ReLU activation function.

4 layers BatchNormalization Layer: This layer performs normalization of the outputs of previous layers, helping to ensure that the values passed into the next layer are normalized. This improves learning speed and model stability.

2 layers MaxPool2D Layer: This layer performs local pooling on spatial regions of input data, reducing the size of the output and helping to reduce computational costs. In this code, we use MaxPool2D with pool_size=(2,2) and strides=(2,2).

Flatten Layer: This layer flattens data from a 2D matrix into a 1D vector, to prepare for connection with Fully Connected layers.

Dense Layer: This is a Fully Connected layer, in which each unit connects to all units in the previous layer. In this code, we use 2 Dense layers with 512 and 8 units, and the ReLU and softmax activation functions.

C. Visualize model parameters

The loss of training and validation.

屏幕截图 2024-03-21 234057

The accuracy of training and validation.

屏幕截图 2024-03-21 234109

Confusion matrix with data testing.

屏幕截图 2024-03-21 234148

Classification report.

屏幕截图 2024-03-21 235413

D. Save the model and reuse it

E. Result

屏幕截图 2024-03-21 235631 屏幕截图 2024-03-21 235607

Hope this article can help you.

If you have any questions please contact me for help!

Thanks everyone!

Releases

No releases published

Packages

No packages published