Path: blob/main/Dogs vs Cats Image Classification - CNN/Dogs vs Cats Image Classification - CNN.ipynb
569 views
Kernel: Python 3
Dataset Information
The training archive contains 25,000 images of dogs and cats. Train your algorithm on these files and predict the labels
(1 = dog, 0 = cat).
Download Dataset
In [ ]:
--2021-05-06 16:04:20-- https://download.microsoft.com/download/3/E/1/3E1C3F21-ECDB-4869-8368-6DEBA77B919F/kagglecatsanddogs_3367a.zip
Resolving download.microsoft.com (download.microsoft.com)... 23.78.216.154, 2600:1417:8000:980::e59, 2600:1417:8000:9b2::e59
Connecting to download.microsoft.com (download.microsoft.com)|23.78.216.154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 824894548 (787M) [application/octet-stream]
Saving to: ‘kagglecatsanddogs_3367a.zip’
kagglecatsanddogs_3 100%[===================>] 786.68M 187MB/s in 4.3s
2021-05-06 16:04:24 (183 MB/s) - ‘kagglecatsanddogs_3367a.zip’ saved [824894548/824894548]
Unzip the Dataset
In [1]:
Import Modules
In [ ]:
Create Dataframe for Input and Output
In [ ]:
PetImages/Dog/4253.jpg 1
In [ ]:
In [ ]:
PetImages/Cat/Thumbs.db
PetImages/Dog/Thumbs.db
In [ ]:
['PetImages/Cat/666.jpg',
'PetImages/Cat/Thumbs.db',
'PetImages/Dog/Thumbs.db',
'PetImages/Dog/11702.jpg']
In [ ]:
24998
Exploratory Data Analysis
In [ ]:
In [ ]:
In [ ]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f71e0c80190>
Create DataGenerator for the Images
In [ ]:
In [ ]:
In [ ]:
In [ ]:
Found 19998 validated image filenames belonging to 2 classes.
Found 5000 validated image filenames belonging to 2 classes.
Model Creation
In [ ]:
In [ ]:
Model: "sequential_4"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_12 (Conv2D) (None, 126, 126, 16) 448
_________________________________________________________________
max_pooling2d_12 (MaxPooling (None, 63, 63, 16) 0
_________________________________________________________________
conv2d_13 (Conv2D) (None, 61, 61, 32) 4640
_________________________________________________________________
max_pooling2d_13 (MaxPooling (None, 30, 30, 32) 0
_________________________________________________________________
conv2d_14 (Conv2D) (None, 28, 28, 64) 18496
_________________________________________________________________
max_pooling2d_14 (MaxPooling (None, 14, 14, 64) 0
_________________________________________________________________
flatten_4 (Flatten) (None, 12544) 0
_________________________________________________________________
dense_8 (Dense) (None, 512) 6423040
_________________________________________________________________
dense_9 (Dense) (None, 1) 513
=================================================================
Total params: 6,447,137
Trainable params: 6,447,137
Non-trainable params: 0
_________________________________________________________________
In [ ]:
Epoch 1/10
40/40 [==============================] - 150s 4s/step - loss: 0.8679 - accuracy: 0.5187 - val_loss: 0.6399 - val_accuracy: 0.6238
Epoch 2/10
40/40 [==============================] - 147s 4s/step - loss: 0.6280 - accuracy: 0.6416 - val_loss: 0.5672 - val_accuracy: 0.7024
Epoch 3/10
40/40 [==============================] - 146s 4s/step - loss: 0.5737 - accuracy: 0.6980 - val_loss: 0.5493 - val_accuracy: 0.7148
Epoch 4/10
40/40 [==============================] - 146s 4s/step - loss: 0.5478 - accuracy: 0.7221 - val_loss: 0.5351 - val_accuracy: 0.7356
Epoch 5/10
40/40 [==============================] - 145s 4s/step - loss: 0.5276 - accuracy: 0.7338 - val_loss: 0.5104 - val_accuracy: 0.7494
Epoch 6/10
40/40 [==============================] - 144s 4s/step - loss: 0.5127 - accuracy: 0.7405 - val_loss: 0.4853 - val_accuracy: 0.7664
Epoch 7/10
40/40 [==============================] - 144s 4s/step - loss: 0.5059 - accuracy: 0.7544 - val_loss: 0.4586 - val_accuracy: 0.7868
Epoch 8/10
40/40 [==============================] - 143s 4s/step - loss: 0.4842 - accuracy: 0.7644 - val_loss: 0.5054 - val_accuracy: 0.7510
Epoch 9/10
40/40 [==============================] - 143s 4s/step - loss: 0.4971 - accuracy: 0.7530 - val_loss: 0.4647 - val_accuracy: 0.7894
Epoch 10/10
40/40 [==============================] - 142s 4s/step - loss: 0.4642 - accuracy: 0.7770 - val_loss: 0.4711 - val_accuracy: 0.7782
Visualization of Results
In [ ]:
Test with Real Image
In [ ]:
In [ ]:
In [ ]: