CONVOLUTIONAL NETWORK from Scratch - Binary Classification

 I used the world renowned dogs-vs-cats dataset from kaggle, to train a convolutional neural network. My procedure was as follows:

-   I downloaded the dataset from kaggle 

-   Created directories and transferred the relevant data. 

  • I created an 'original_dataset_dir' and transferred all of the data (data of all classes) to this directory.
  • I then created a base directory: 'base_dir'.
  • I created the folders 'train', 'validation' and 'test' inside base directory.
  • Then I created the folders 'cats', 'dogs', inside the folders created in last step.
  • Then I transferred the data according to the following ratio: (Train, Validation, Test) = (50, 25, 25)

-  Initiated a small convolutional network

  • In the conv base, I created 4 successive 'conv2D' layers, each followed by a 'Maxpooling2D' layer, without any padding.
  • In the classifier base, I added a 'Flatten' layer, followed by two Dense Layers

-  Compiled the model

-  Did Data Processing

  • Different images had d/f dimensions. I created two data generator object. One for 'training dataset' & one for 'test & validation datasets'.
  • I resized all of the images to the size 150*150 in both of the data generator objects.
  • Class Mode in both objects was set to 'binary'
  • All of the pixels were rescaled as (1./255) in both generator objects, to standardize the data.
  • For this particular case, only one data generator object was enough to create data generators for all of the data sets. But I still defined  two d/f data gen objects, as in the upcoming notebooks, they'll be helpful for me, when I'll perform data augmentation on training dataset. But won't do the same with test and validation datsets.

-  Trained the model

-  Plotted the Data

-  The max validation accuracy achieved was 73.4%

Here is the github link to the said Jupyter Notebook. It is the first half of this Notebook.

I also made some video explanations for myself in URDU language, You can see them here.

Summary

Cell Details 













Comments

Popular posts from this blog

Ai SDK ui - 1 - Learning AI SDK UI with Next.js

NMLS - 1. Clustering - Kmeans - Unsupervised Learning - Introductory Machine Learning

NMLS - 3. Recommender Systems - Collaborative Filtering - Introductory Machine Learning