Simple Metrics For a Perfect CNN Model

Simple Metrics For a Perfect CNN Model


Hi developers!! I hope you are doing good, do you want to implement a perfect CNN MODEL using Matlab? if so let's start

Loading DATA

To get the best training you need to use some metrics.

First, we start by loading data to treat it.

There are different ways to code this instruction but in my experience, I recommended easily using the imagedatastore function

imagedata store.jpg

Use an ImageDatastore object to manage a collection of image files, where each individual image fits in memory, but the entire collection of images does not necessarily fit. You can create an ImageDatastore object using the imageDatastore function, specify its properties, and then import and process the data using object functions.

This function is not available in the Anciennes Matlab versions, so if you want to use it for example in Matlab 2015 as I did your model will never work, it can be work just in Matlab 2018 >=

How does it work?

There are two ways :

imds = imageDatastore(location)

imds = imageDatastore(location,Name,Value)

I recommend the second method because you can specify additional parameters and properties for imds using one or more name-value pair arguments.

image data store code.PNG

Sometimes you meet problems with mentioning the correct location of data that you want to treat since this problem provokes stupid bugs.

To avoid this, When you create your object with the imagedatastore function use the parameter IncludeSubfolders Specify true to include all files and subfolders within each folder or false to include only the files within each folder.

Fix Folder Size

If your model contains several categories to process, you must keep all the Folder at the same size to build perfect and balanced learning.


At the bigining, You need to count the number of data in each category and here the object imds created by the imagedatastore function help you to manage your data,

Then you need to know which category contains the minimum of data and fix them all at her size


Dividing Data

After you had been done the pretreatment of your data you need to divide each category into two broad section

70% for Leaining

30% for Teste


Scientists strongly recommend dividing the data into two sub-blocks Training and Testing because this choice gives better results than splitting the data into 3 sub-blocks learning, testing, and validating.

Learning Rate Value


Also, the scientists suggest "1e-4" as the best rate value in reason it gives good learning for your model

Discuss treatment results:

After you had been saved your network you will need to discuss your treatment result for this reason I suggest you use the confusion matrix as the best way to display and compare your training results

confusion matrix echo.PNG


I hope my article has brought some knowledge to you on how you can implement a perfect CNN model