Manikanta-7013 commited on
Commit
f3a430d
1 Parent(s): 7bdccb5

Upload 819 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. CNN/.ipynb_checkpoints/Image Recognition Model With CNN-checkpoint.ipynb +656 -0
  2. CNN/Image Recognition Model With CNN.ipynb +647 -0
  3. CNN/dataset/.DS_Store +0 -0
  4. CNN/dataset/__MACOSX/._dataset +0 -0
  5. CNN/dataset/__MACOSX/dataset/._.DS_Store +0 -0
  6. CNN/dataset/__MACOSX/dataset/._test_set +0 -0
  7. CNN/dataset/__MACOSX/dataset/._training_set +0 -0
  8. CNN/dataset/__MACOSX/dataset/test_set/._.DS_Store +0 -0
  9. CNN/dataset/__MACOSX/dataset/test_set/._cats +0 -0
  10. CNN/dataset/__MACOSX/dataset/test_set/._dogs +0 -0
  11. CNN/dataset/__MACOSX/dataset/test_set/cats/._.DS_Store +0 -0
  12. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4001.jpg +0 -0
  13. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4002.jpg +0 -0
  14. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4003.jpg +0 -0
  15. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4004.jpg +0 -0
  16. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4005.jpg +0 -0
  17. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4006.jpg +0 -0
  18. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4007.jpg +0 -0
  19. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4008.jpg +0 -0
  20. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4009.jpg +0 -0
  21. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4010.jpg +0 -0
  22. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4011.jpg +0 -0
  23. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4012.jpg +0 -0
  24. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4013.jpg +0 -0
  25. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4014.jpg +0 -0
  26. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4015.jpg +0 -0
  27. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4016.jpg +0 -0
  28. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4017.jpg +0 -0
  29. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4018.jpg +0 -0
  30. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4019.jpg +0 -0
  31. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4020.jpg +0 -0
  32. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4021.jpg +0 -0
  33. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4022.jpg +0 -0
  34. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4023.jpg +0 -0
  35. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4024.jpg +0 -0
  36. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4025.jpg +0 -0
  37. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4026.jpg +0 -0
  38. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4027.jpg +0 -0
  39. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4028.jpg +0 -0
  40. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4029.jpg +0 -0
  41. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4030.jpg +0 -0
  42. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4031.jpg +0 -0
  43. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4032.jpg +0 -0
  44. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4033.jpg +0 -0
  45. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4034.jpg +0 -0
  46. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4035.jpg +0 -0
  47. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4036.jpg +0 -0
  48. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4037.jpg +0 -0
  49. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4038.jpg +0 -0
  50. CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4039.jpg +0 -0
CNN/.ipynb_checkpoints/Image Recognition Model With CNN-checkpoint.ipynb ADDED
@@ -0,0 +1,656 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "id": "3DR-eO17geWu"
7
+ },
8
+ "source": [
9
+ "# Convolutional Neural Network"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "markdown",
14
+ "metadata": {
15
+ "id": "EMefrVPCg-60"
16
+ },
17
+ "source": [
18
+ "### Importing the libraries"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": 1,
24
+ "metadata": {
25
+ "id": "w3mybNcNuyRf"
26
+ },
27
+ "outputs": [
28
+ {
29
+ "name": "stdout",
30
+ "output_type": "stream",
31
+ "text": [
32
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n",
33
+ "\n"
34
+ ]
35
+ }
36
+ ],
37
+ "source": [
38
+ "import tensorflow as tf\n",
39
+ "from keras.preprocessing.image import ImageDataGenerator"
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "execution_count": 2,
45
+ "metadata": {
46
+ "colab": {
47
+ "base_uri": "https://localhost:8080/",
48
+ "height": 38
49
+ },
50
+ "id": "Gk81TsV3vNYv",
51
+ "outputId": "ac51f686-a76e-4be8-ae56-5db116913a8b"
52
+ },
53
+ "outputs": [
54
+ {
55
+ "data": {
56
+ "text/plain": [
57
+ "'2.15.0'"
58
+ ]
59
+ },
60
+ "execution_count": 2,
61
+ "metadata": {},
62
+ "output_type": "execute_result"
63
+ }
64
+ ],
65
+ "source": [
66
+ "tf.__version__"
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "markdown",
71
+ "metadata": {
72
+ "id": "oxQxCBWyoGPE"
73
+ },
74
+ "source": [
75
+ "## Part 1 - Data Preprocessing"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "markdown",
80
+ "metadata": {
81
+ "id": "MvE-heJNo3GG"
82
+ },
83
+ "source": [
84
+ "### Preprocessing the Training set"
85
+ ]
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "execution_count": 3,
90
+ "metadata": {
91
+ "id": "IZPgIbSyzcZz"
92
+ },
93
+ "outputs": [
94
+ {
95
+ "name": "stdout",
96
+ "output_type": "stream",
97
+ "text": [
98
+ "Found 8000 images belonging to 2 classes.\n"
99
+ ]
100
+ }
101
+ ],
102
+ "source": [
103
+ "train_datagen = ImageDataGenerator(rescale = 1./255,\n",
104
+ " shear_range = 0.2,\n",
105
+ " zoom_range = 0.2,\n",
106
+ " horizontal_flip = True)\n",
107
+ "training_set = train_datagen.flow_from_directory('dataset/training_set',\n",
108
+ " target_size = (64, 64),\n",
109
+ " batch_size = 32,\n",
110
+ " class_mode = 'binary')"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "markdown",
115
+ "metadata": {
116
+ "id": "mrCMmGw9pHys"
117
+ },
118
+ "source": [
119
+ "### Preprocessing the Test set"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": 4,
125
+ "metadata": {
126
+ "id": "qTwLxo10zn-P"
127
+ },
128
+ "outputs": [
129
+ {
130
+ "name": "stdout",
131
+ "output_type": "stream",
132
+ "text": [
133
+ "Found 2000 images belonging to 2 classes.\n"
134
+ ]
135
+ }
136
+ ],
137
+ "source": [
138
+ "test_datagen = ImageDataGenerator(rescale = 1./255)\n",
139
+ "test_set = test_datagen.flow_from_directory('dataset/test_set',\n",
140
+ " target_size = (64, 64),\n",
141
+ " batch_size = 32,\n",
142
+ " class_mode = 'binary')"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "markdown",
147
+ "metadata": {
148
+ "id": "af8O4l90gk7B"
149
+ },
150
+ "source": [
151
+ "## Part 2 - Building the CNN"
152
+ ]
153
+ },
154
+ {
155
+ "cell_type": "markdown",
156
+ "metadata": {
157
+ "id": "ces1gXY2lmoX"
158
+ },
159
+ "source": [
160
+ "### Initialising the CNN"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": 5,
166
+ "metadata": {
167
+ "id": "OywsP_gTz8VA"
168
+ },
169
+ "outputs": [
170
+ {
171
+ "name": "stdout",
172
+ "output_type": "stream",
173
+ "text": [
174
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\backend.py:873: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.\n",
175
+ "\n"
176
+ ]
177
+ }
178
+ ],
179
+ "source": [
180
+ "cnn=tf.keras.models.Sequential()"
181
+ ]
182
+ },
183
+ {
184
+ "cell_type": "markdown",
185
+ "metadata": {
186
+ "id": "u5YJj_XMl5LF"
187
+ },
188
+ "source": [
189
+ "### Step 1 - Convolution"
190
+ ]
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "execution_count": 6,
195
+ "metadata": {
196
+ "id": "dkA5f15L0IRA"
197
+ },
198
+ "outputs": [],
199
+ "source": [
200
+ "cnn.add(tf.keras.layers.Conv2D(filters=32,kernel_size=3,activation='relu',input_shape=[64,64,3]))"
201
+ ]
202
+ },
203
+ {
204
+ "cell_type": "markdown",
205
+ "metadata": {
206
+ "id": "tf87FpvxmNOJ"
207
+ },
208
+ "source": [
209
+ "### Step 2 - Pooling"
210
+ ]
211
+ },
212
+ {
213
+ "cell_type": "code",
214
+ "execution_count": 7,
215
+ "metadata": {
216
+ "id": "Khzh28Gj056f"
217
+ },
218
+ "outputs": [
219
+ {
220
+ "name": "stdout",
221
+ "output_type": "stream",
222
+ "text": [
223
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\layers\\pooling\\max_pooling2d.py:161: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n",
224
+ "\n"
225
+ ]
226
+ }
227
+ ],
228
+ "source": [
229
+ "cnn.add(tf.keras.layers.MaxPool2D(pool_size=2,strides=2))"
230
+ ]
231
+ },
232
+ {
233
+ "cell_type": "markdown",
234
+ "metadata": {
235
+ "id": "xaTOgD8rm4mU"
236
+ },
237
+ "source": [
238
+ "### Adding a second convolutional layer"
239
+ ]
240
+ },
241
+ {
242
+ "cell_type": "code",
243
+ "execution_count": 8,
244
+ "metadata": {
245
+ "id": "G7GvlV8W1zFv"
246
+ },
247
+ "outputs": [],
248
+ "source": [
249
+ "cnn.add(tf.keras.layers.Conv2D(filters=32,kernel_size=3,activation='relu'))\n",
250
+ "cnn.add(tf.keras.layers.MaxPool2D(pool_size=2,strides=2))"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "markdown",
255
+ "metadata": {
256
+ "id": "tmiEuvTunKfk"
257
+ },
258
+ "source": [
259
+ "### Step 3 - Flattening"
260
+ ]
261
+ },
262
+ {
263
+ "cell_type": "code",
264
+ "execution_count": 9,
265
+ "metadata": {
266
+ "id": "CgmlA6xs16ub"
267
+ },
268
+ "outputs": [],
269
+ "source": [
270
+ "cnn.add(tf.keras.layers.Flatten())"
271
+ ]
272
+ },
273
+ {
274
+ "cell_type": "markdown",
275
+ "metadata": {
276
+ "id": "dAoSECOm203v"
277
+ },
278
+ "source": [
279
+ "### Step 4 - Full Connection"
280
+ ]
281
+ },
282
+ {
283
+ "cell_type": "code",
284
+ "execution_count": 10,
285
+ "metadata": {
286
+ "id": "1DXEM0C-2Cv6"
287
+ },
288
+ "outputs": [],
289
+ "source": [
290
+ "cnn.add(tf.keras.layers.Dense(units=128,activation='relu'))"
291
+ ]
292
+ },
293
+ {
294
+ "cell_type": "markdown",
295
+ "metadata": {
296
+ "id": "yTldFvbX28Na"
297
+ },
298
+ "source": [
299
+ "### Step 5 - Output Layer"
300
+ ]
301
+ },
302
+ {
303
+ "cell_type": "code",
304
+ "execution_count": 11,
305
+ "metadata": {
306
+ "id": "bM9tOMr02dTk"
307
+ },
308
+ "outputs": [],
309
+ "source": [
310
+ "cnn.add(tf.keras.layers.Dense(units=1,activation='sigmoid'))"
311
+ ]
312
+ },
313
+ {
314
+ "cell_type": "markdown",
315
+ "metadata": {
316
+ "id": "D6XkI90snSDl"
317
+ },
318
+ "source": [
319
+ "## Part 3 - Training the CNN"
320
+ ]
321
+ },
322
+ {
323
+ "cell_type": "markdown",
324
+ "metadata": {
325
+ "id": "vfrFQACEnc6i"
326
+ },
327
+ "source": [
328
+ "### Compiling the CNN"
329
+ ]
330
+ },
331
+ {
332
+ "cell_type": "code",
333
+ "execution_count": 12,
334
+ "metadata": {
335
+ "id": "QRSs7B252tM8"
336
+ },
337
+ "outputs": [
338
+ {
339
+ "name": "stdout",
340
+ "output_type": "stream",
341
+ "text": [
342
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\optimizers\\__init__.py:309: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.\n",
343
+ "\n"
344
+ ]
345
+ }
346
+ ],
347
+ "source": [
348
+ "cnn.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])"
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "markdown",
353
+ "metadata": {
354
+ "id": "ehS-v3MIpX2h"
355
+ },
356
+ "source": [
357
+ "### Training the CNN on the Training set and evaluating it on the Test set"
358
+ ]
359
+ },
360
+ {
361
+ "cell_type": "code",
362
+ "execution_count": 13,
363
+ "metadata": {
364
+ "id": "ibgjSnzf3Mai"
365
+ },
366
+ "outputs": [
367
+ {
368
+ "name": "stdout",
369
+ "output_type": "stream",
370
+ "text": [
371
+ "Epoch 1/25\n",
372
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\utils\\tf_utils.py:492: The name tf.ragged.RaggedTensorValue is deprecated. Please use tf.compat.v1.ragged.RaggedTensorValue instead.\n",
373
+ "\n",
374
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\engine\\base_layer_utils.py:384: The name tf.executing_eagerly_outside_functions is deprecated. Please use tf.compat.v1.executing_eagerly_outside_functions instead.\n",
375
+ "\n",
376
+ "250/250 [==============================] - 75s 298ms/step - loss: 0.6505 - accuracy: 0.6121 - val_loss: 0.5777 - val_accuracy: 0.7080\n",
377
+ "Epoch 2/25\n",
378
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.5849 - accuracy: 0.6865 - val_loss: 0.5398 - val_accuracy: 0.7290\n",
379
+ "Epoch 3/25\n",
380
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.5501 - accuracy: 0.7189 - val_loss: 0.5827 - val_accuracy: 0.6865\n",
381
+ "Epoch 4/25\n",
382
+ "250/250 [==============================] - 30s 122ms/step - loss: 0.5212 - accuracy: 0.7369 - val_loss: 0.5147 - val_accuracy: 0.7455\n",
383
+ "Epoch 5/25\n",
384
+ "250/250 [==============================] - 30s 119ms/step - loss: 0.4896 - accuracy: 0.7613 - val_loss: 0.5152 - val_accuracy: 0.7550\n",
385
+ "Epoch 6/25\n",
386
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.4721 - accuracy: 0.7770 - val_loss: 0.4776 - val_accuracy: 0.7640\n",
387
+ "Epoch 7/25\n",
388
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.4506 - accuracy: 0.7826 - val_loss: 0.4668 - val_accuracy: 0.7845\n",
389
+ "Epoch 8/25\n",
390
+ "250/250 [==============================] - 32s 126ms/step - loss: 0.4380 - accuracy: 0.7868 - val_loss: 0.4637 - val_accuracy: 0.7870\n",
391
+ "Epoch 9/25\n",
392
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.4231 - accuracy: 0.8026 - val_loss: 0.4680 - val_accuracy: 0.7850\n",
393
+ "Epoch 10/25\n",
394
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.4048 - accuracy: 0.8135 - val_loss: 0.5443 - val_accuracy: 0.7470\n",
395
+ "Epoch 11/25\n",
396
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.3917 - accuracy: 0.8242 - val_loss: 0.4698 - val_accuracy: 0.7875\n",
397
+ "Epoch 12/25\n",
398
+ "250/250 [==============================] - 37s 148ms/step - loss: 0.3743 - accuracy: 0.8284 - val_loss: 0.4812 - val_accuracy: 0.7940\n",
399
+ "Epoch 13/25\n",
400
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.3720 - accuracy: 0.8317 - val_loss: 0.4309 - val_accuracy: 0.8140\n",
401
+ "Epoch 14/25\n",
402
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.3497 - accuracy: 0.8443 - val_loss: 0.4593 - val_accuracy: 0.7980\n",
403
+ "Epoch 15/25\n",
404
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.3407 - accuracy: 0.8514 - val_loss: 0.4699 - val_accuracy: 0.7925\n",
405
+ "Epoch 16/25\n",
406
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.3249 - accuracy: 0.8593 - val_loss: 0.4712 - val_accuracy: 0.8035\n",
407
+ "Epoch 17/25\n",
408
+ "250/250 [==============================] - 30s 122ms/step - loss: 0.3044 - accuracy: 0.8748 - val_loss: 0.4846 - val_accuracy: 0.8060\n",
409
+ "Epoch 18/25\n",
410
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.3082 - accuracy: 0.8608 - val_loss: 0.4750 - val_accuracy: 0.8040\n",
411
+ "Epoch 19/25\n",
412
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.2860 - accuracy: 0.8752 - val_loss: 0.4533 - val_accuracy: 0.8180\n",
413
+ "Epoch 20/25\n",
414
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.2761 - accuracy: 0.8792 - val_loss: 0.5786 - val_accuracy: 0.7975\n",
415
+ "Epoch 21/25\n",
416
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.2634 - accuracy: 0.8861 - val_loss: 0.4989 - val_accuracy: 0.8085\n",
417
+ "Epoch 22/25\n",
418
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.2491 - accuracy: 0.8946 - val_loss: 0.5098 - val_accuracy: 0.8160\n",
419
+ "Epoch 23/25\n",
420
+ "250/250 [==============================] - 31s 124ms/step - loss: 0.2385 - accuracy: 0.8981 - val_loss: 0.5296 - val_accuracy: 0.8115\n",
421
+ "Epoch 24/25\n",
422
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.2260 - accuracy: 0.9040 - val_loss: 0.5117 - val_accuracy: 0.8105\n",
423
+ "Epoch 25/25\n",
424
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.2117 - accuracy: 0.9146 - val_loss: 0.5145 - val_accuracy: 0.8180\n"
425
+ ]
426
+ },
427
+ {
428
+ "data": {
429
+ "text/plain": [
430
+ "<keras.src.callbacks.History at 0x1f3d5467610>"
431
+ ]
432
+ },
433
+ "execution_count": 13,
434
+ "metadata": {},
435
+ "output_type": "execute_result"
436
+ }
437
+ ],
438
+ "source": [
439
+ "cnn.fit(x=training_set,validation_data=test_set,epochs=25)"
440
+ ]
441
+ },
442
+ {
443
+ "cell_type": "markdown",
444
+ "metadata": {
445
+ "id": "U3PZasO0006Z"
446
+ },
447
+ "source": [
448
+ "## Part 4 - Making a single prediction"
449
+ ]
450
+ },
451
+ {
452
+ "cell_type": "code",
453
+ "execution_count": 14,
454
+ "metadata": {
455
+ "id": "PQGfPACq3mGS"
456
+ },
457
+ "outputs": [
458
+ {
459
+ "name": "stdout",
460
+ "output_type": "stream",
461
+ "text": [
462
+ "1/1 [==============================] - 0s 107ms/step\n"
463
+ ]
464
+ }
465
+ ],
466
+ "source": [
467
+ "import numpy as np\n",
468
+ "from keras.preprocessing import image\n",
469
+ "test_image=image.load_img('dataset/single_prediction/cat_or_dog_1.jpg',target_size=(64,64))\n",
470
+ "test_image=image.img_to_array(test_image)\n",
471
+ "test_image=np.expand_dims(test_image,axis=0)\n",
472
+ "result=cnn.predict(test_image)\n",
473
+ "training_set.class_indices\n",
474
+ "if result[0][0]==1:\n",
475
+ " prediction='dog'\n",
476
+ "else:\n",
477
+ " prediction='cat'"
478
+ ]
479
+ },
480
+ {
481
+ "cell_type": "code",
482
+ "execution_count": 15,
483
+ "metadata": {
484
+ "id": "xMvlNcFN5yEX"
485
+ },
486
+ "outputs": [
487
+ {
488
+ "name": "stdout",
489
+ "output_type": "stream",
490
+ "text": [
491
+ "dog\n"
492
+ ]
493
+ }
494
+ ],
495
+ "source": [
496
+ "print(prediction)"
497
+ ]
498
+ },
499
+ {
500
+ "cell_type": "code",
501
+ "execution_count": 16,
502
+ "metadata": {},
503
+ "outputs": [
504
+ {
505
+ "name": "stdout",
506
+ "output_type": "stream",
507
+ "text": [
508
+ "1/1 [==============================] - 0s 25ms/step\n"
509
+ ]
510
+ }
511
+ ],
512
+ "source": [
513
+ "import numpy as np\n",
514
+ "from keras.preprocessing import image\n",
515
+ "test_image=image.load_img('dataset/single_prediction/cat_or_dog_2.jpg',target_size=(64,64))\n",
516
+ "test_image=image.img_to_array(test_image)\n",
517
+ "test_image=np.expand_dims(test_image,axis=0)\n",
518
+ "result=cnn.predict(test_image)\n",
519
+ "training_set.class_indices\n",
520
+ "if result[0][0]==1:\n",
521
+ " prediction='dog'\n",
522
+ "else:\n",
523
+ " prediction='cat'"
524
+ ]
525
+ },
526
+ {
527
+ "cell_type": "code",
528
+ "execution_count": 17,
529
+ "metadata": {},
530
+ "outputs": [
531
+ {
532
+ "name": "stdout",
533
+ "output_type": "stream",
534
+ "text": [
535
+ "cat\n"
536
+ ]
537
+ }
538
+ ],
539
+ "source": [
540
+ "print(prediction)"
541
+ ]
542
+ },
543
+ {
544
+ "cell_type": "code",
545
+ "execution_count": 18,
546
+ "metadata": {},
547
+ "outputs": [
548
+ {
549
+ "name": "stdout",
550
+ "output_type": "stream",
551
+ "text": [
552
+ "1/1 [==============================] - 0s 26ms/step\n"
553
+ ]
554
+ }
555
+ ],
556
+ "source": [
557
+ "import numpy as np\n",
558
+ "from keras.preprocessing import image\n",
559
+ "test_image=image.load_img('dataset/single_prediction/cat_or_dog_3.jpg',target_size=(64,64))\n",
560
+ "test_image=image.img_to_array(test_image)\n",
561
+ "test_image=np.expand_dims(test_image,axis=0)\n",
562
+ "result=cnn.predict(test_image)\n",
563
+ "training_set.class_indices\n",
564
+ "if result[0][0]==1:\n",
565
+ " prediction='dog'\n",
566
+ "else:\n",
567
+ " prediction='cat'"
568
+ ]
569
+ },
570
+ {
571
+ "cell_type": "code",
572
+ "execution_count": 19,
573
+ "metadata": {},
574
+ "outputs": [
575
+ {
576
+ "name": "stdout",
577
+ "output_type": "stream",
578
+ "text": [
579
+ "cat\n"
580
+ ]
581
+ }
582
+ ],
583
+ "source": [
584
+ "print(prediction)"
585
+ ]
586
+ },
587
+ {
588
+ "cell_type": "code",
589
+ "execution_count": 20,
590
+ "metadata": {},
591
+ "outputs": [
592
+ {
593
+ "name": "stdout",
594
+ "output_type": "stream",
595
+ "text": [
596
+ "1/1 [==============================] - 0s 25ms/step\n"
597
+ ]
598
+ }
599
+ ],
600
+ "source": [
601
+ "import numpy as np\n",
602
+ "from keras.preprocessing import image\n",
603
+ "test_image=image.load_img('dataset/single_prediction/cat_or_dog_4.jpg',target_size=(64,64))\n",
604
+ "test_image=image.img_to_array(test_image)\n",
605
+ "test_image=np.expand_dims(test_image,axis=0)\n",
606
+ "result=cnn.predict(test_image)\n",
607
+ "training_set.class_indices\n",
608
+ "if result[0][0]==1:\n",
609
+ " prediction='dog'\n",
610
+ "else:\n",
611
+ " prediction='cat'"
612
+ ]
613
+ },
614
+ {
615
+ "cell_type": "code",
616
+ "execution_count": 21,
617
+ "metadata": {},
618
+ "outputs": [
619
+ {
620
+ "name": "stdout",
621
+ "output_type": "stream",
622
+ "text": [
623
+ "dog\n"
624
+ ]
625
+ }
626
+ ],
627
+ "source": [
628
+ "print(prediction)"
629
+ ]
630
+ }
631
+ ],
632
+ "metadata": {
633
+ "colab": {
634
+ "provenance": []
635
+ },
636
+ "kernelspec": {
637
+ "display_name": "Python 3 (ipykernel)",
638
+ "language": "python",
639
+ "name": "python3"
640
+ },
641
+ "language_info": {
642
+ "codemirror_mode": {
643
+ "name": "ipython",
644
+ "version": 3
645
+ },
646
+ "file_extension": ".py",
647
+ "mimetype": "text/x-python",
648
+ "name": "python",
649
+ "nbconvert_exporter": "python",
650
+ "pygments_lexer": "ipython3",
651
+ "version": "3.11.5"
652
+ }
653
+ },
654
+ "nbformat": 4,
655
+ "nbformat_minor": 1
656
+ }
CNN/Image Recognition Model With CNN.ipynb ADDED
@@ -0,0 +1,647 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "id": "3DR-eO17geWu"
7
+ },
8
+ "source": [
9
+ "## Image Recognition Model With CNN"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "markdown",
14
+ "metadata": {
15
+ "id": "EMefrVPCg-60"
16
+ },
17
+ "source": [
18
+ "### Importing the libraries"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": 22,
24
+ "metadata": {
25
+ "id": "w3mybNcNuyRf"
26
+ },
27
+ "outputs": [],
28
+ "source": [
29
+ "import tensorflow as tf\n",
30
+ "from keras.preprocessing.image import ImageDataGenerator"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 2,
36
+ "metadata": {
37
+ "colab": {
38
+ "base_uri": "https://localhost:8080/",
39
+ "height": 38
40
+ },
41
+ "id": "Gk81TsV3vNYv",
42
+ "outputId": "ac51f686-a76e-4be8-ae56-5db116913a8b"
43
+ },
44
+ "outputs": [
45
+ {
46
+ "data": {
47
+ "text/plain": [
48
+ "'2.15.0'"
49
+ ]
50
+ },
51
+ "execution_count": 2,
52
+ "metadata": {},
53
+ "output_type": "execute_result"
54
+ }
55
+ ],
56
+ "source": [
57
+ "tf.__version__"
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "markdown",
62
+ "metadata": {
63
+ "id": "oxQxCBWyoGPE"
64
+ },
65
+ "source": [
66
+ "## Part 1 - Data Preprocessing"
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "markdown",
71
+ "metadata": {
72
+ "id": "MvE-heJNo3GG"
73
+ },
74
+ "source": [
75
+ "### Preprocessing the Training set"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": 3,
81
+ "metadata": {
82
+ "id": "IZPgIbSyzcZz"
83
+ },
84
+ "outputs": [
85
+ {
86
+ "name": "stdout",
87
+ "output_type": "stream",
88
+ "text": [
89
+ "Found 8000 images belonging to 2 classes.\n"
90
+ ]
91
+ }
92
+ ],
93
+ "source": [
94
+ "train_datagen = ImageDataGenerator(rescale = 1./255,\n",
95
+ " shear_range = 0.2,\n",
96
+ " zoom_range = 0.2,\n",
97
+ " horizontal_flip = True)\n",
98
+ "training_set = train_datagen.flow_from_directory('dataset/training_set',\n",
99
+ " target_size = (64, 64),\n",
100
+ " batch_size = 32,\n",
101
+ " class_mode = 'binary')"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "markdown",
106
+ "metadata": {
107
+ "id": "mrCMmGw9pHys"
108
+ },
109
+ "source": [
110
+ "### Preprocessing the Test set"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": 4,
116
+ "metadata": {
117
+ "id": "qTwLxo10zn-P"
118
+ },
119
+ "outputs": [
120
+ {
121
+ "name": "stdout",
122
+ "output_type": "stream",
123
+ "text": [
124
+ "Found 2000 images belonging to 2 classes.\n"
125
+ ]
126
+ }
127
+ ],
128
+ "source": [
129
+ "test_datagen = ImageDataGenerator(rescale = 1./255)\n",
130
+ "test_set = test_datagen.flow_from_directory('dataset/test_set',\n",
131
+ " target_size = (64, 64),\n",
132
+ " batch_size = 32,\n",
133
+ " class_mode = 'binary')"
134
+ ]
135
+ },
136
+ {
137
+ "cell_type": "markdown",
138
+ "metadata": {
139
+ "id": "af8O4l90gk7B"
140
+ },
141
+ "source": [
142
+ "## Part 2 - Building the CNN"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "markdown",
147
+ "metadata": {
148
+ "id": "ces1gXY2lmoX"
149
+ },
150
+ "source": [
151
+ "### Initialising the CNN"
152
+ ]
153
+ },
154
+ {
155
+ "cell_type": "code",
156
+ "execution_count": 5,
157
+ "metadata": {
158
+ "id": "OywsP_gTz8VA"
159
+ },
160
+ "outputs": [
161
+ {
162
+ "name": "stdout",
163
+ "output_type": "stream",
164
+ "text": [
165
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\backend.py:873: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.\n",
166
+ "\n"
167
+ ]
168
+ }
169
+ ],
170
+ "source": [
171
+ "cnn=tf.keras.models.Sequential()"
172
+ ]
173
+ },
174
+ {
175
+ "cell_type": "markdown",
176
+ "metadata": {
177
+ "id": "u5YJj_XMl5LF"
178
+ },
179
+ "source": [
180
+ "### Step 1 - Convolution"
181
+ ]
182
+ },
183
+ {
184
+ "cell_type": "code",
185
+ "execution_count": 6,
186
+ "metadata": {
187
+ "id": "dkA5f15L0IRA"
188
+ },
189
+ "outputs": [],
190
+ "source": [
191
+ "cnn.add(tf.keras.layers.Conv2D(filters=32,kernel_size=3,activation='relu',input_shape=[64,64,3]))"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "markdown",
196
+ "metadata": {
197
+ "id": "tf87FpvxmNOJ"
198
+ },
199
+ "source": [
200
+ "### Step 2 - Pooling"
201
+ ]
202
+ },
203
+ {
204
+ "cell_type": "code",
205
+ "execution_count": 7,
206
+ "metadata": {
207
+ "id": "Khzh28Gj056f"
208
+ },
209
+ "outputs": [
210
+ {
211
+ "name": "stdout",
212
+ "output_type": "stream",
213
+ "text": [
214
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\layers\\pooling\\max_pooling2d.py:161: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n",
215
+ "\n"
216
+ ]
217
+ }
218
+ ],
219
+ "source": [
220
+ "cnn.add(tf.keras.layers.MaxPool2D(pool_size=2,strides=2))"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "markdown",
225
+ "metadata": {
226
+ "id": "xaTOgD8rm4mU"
227
+ },
228
+ "source": [
229
+ "### Adding a second convolutional layer"
230
+ ]
231
+ },
232
+ {
233
+ "cell_type": "code",
234
+ "execution_count": 8,
235
+ "metadata": {
236
+ "id": "G7GvlV8W1zFv"
237
+ },
238
+ "outputs": [],
239
+ "source": [
240
+ "cnn.add(tf.keras.layers.Conv2D(filters=32,kernel_size=3,activation='relu'))\n",
241
+ "cnn.add(tf.keras.layers.MaxPool2D(pool_size=2,strides=2))"
242
+ ]
243
+ },
244
+ {
245
+ "cell_type": "markdown",
246
+ "metadata": {
247
+ "id": "tmiEuvTunKfk"
248
+ },
249
+ "source": [
250
+ "### Step 3 - Flattening"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "execution_count": 9,
256
+ "metadata": {
257
+ "id": "CgmlA6xs16ub"
258
+ },
259
+ "outputs": [],
260
+ "source": [
261
+ "cnn.add(tf.keras.layers.Flatten())"
262
+ ]
263
+ },
264
+ {
265
+ "cell_type": "markdown",
266
+ "metadata": {
267
+ "id": "dAoSECOm203v"
268
+ },
269
+ "source": [
270
+ "### Step 4 - Full Connection"
271
+ ]
272
+ },
273
+ {
274
+ "cell_type": "code",
275
+ "execution_count": 10,
276
+ "metadata": {
277
+ "id": "1DXEM0C-2Cv6"
278
+ },
279
+ "outputs": [],
280
+ "source": [
281
+ "cnn.add(tf.keras.layers.Dense(units=128,activation='relu'))"
282
+ ]
283
+ },
284
+ {
285
+ "cell_type": "markdown",
286
+ "metadata": {
287
+ "id": "yTldFvbX28Na"
288
+ },
289
+ "source": [
290
+ "### Step 5 - Output Layer"
291
+ ]
292
+ },
293
+ {
294
+ "cell_type": "code",
295
+ "execution_count": 11,
296
+ "metadata": {
297
+ "id": "bM9tOMr02dTk"
298
+ },
299
+ "outputs": [],
300
+ "source": [
301
+ "cnn.add(tf.keras.layers.Dense(units=1,activation='sigmoid'))"
302
+ ]
303
+ },
304
+ {
305
+ "cell_type": "markdown",
306
+ "metadata": {
307
+ "id": "D6XkI90snSDl"
308
+ },
309
+ "source": [
310
+ "## Part 3 - Training the CNN"
311
+ ]
312
+ },
313
+ {
314
+ "cell_type": "markdown",
315
+ "metadata": {
316
+ "id": "vfrFQACEnc6i"
317
+ },
318
+ "source": [
319
+ "### Compiling the CNN"
320
+ ]
321
+ },
322
+ {
323
+ "cell_type": "code",
324
+ "execution_count": 12,
325
+ "metadata": {
326
+ "id": "QRSs7B252tM8"
327
+ },
328
+ "outputs": [
329
+ {
330
+ "name": "stdout",
331
+ "output_type": "stream",
332
+ "text": [
333
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\optimizers\\__init__.py:309: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.\n",
334
+ "\n"
335
+ ]
336
+ }
337
+ ],
338
+ "source": [
339
+ "cnn.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])"
340
+ ]
341
+ },
342
+ {
343
+ "cell_type": "markdown",
344
+ "metadata": {
345
+ "id": "ehS-v3MIpX2h"
346
+ },
347
+ "source": [
348
+ "### Training the CNN on the Training set and evaluating it on the Test set"
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "code",
353
+ "execution_count": 13,
354
+ "metadata": {
355
+ "id": "ibgjSnzf3Mai"
356
+ },
357
+ "outputs": [
358
+ {
359
+ "name": "stdout",
360
+ "output_type": "stream",
361
+ "text": [
362
+ "Epoch 1/25\n",
363
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\utils\\tf_utils.py:492: The name tf.ragged.RaggedTensorValue is deprecated. Please use tf.compat.v1.ragged.RaggedTensorValue instead.\n",
364
+ "\n",
365
+ "WARNING:tensorflow:From C:\\Users\\manik\\anaconda3\\Lib\\site-packages\\keras\\src\\engine\\base_layer_utils.py:384: The name tf.executing_eagerly_outside_functions is deprecated. Please use tf.compat.v1.executing_eagerly_outside_functions instead.\n",
366
+ "\n",
367
+ "250/250 [==============================] - 75s 298ms/step - loss: 0.6505 - accuracy: 0.6121 - val_loss: 0.5777 - val_accuracy: 0.7080\n",
368
+ "Epoch 2/25\n",
369
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.5849 - accuracy: 0.6865 - val_loss: 0.5398 - val_accuracy: 0.7290\n",
370
+ "Epoch 3/25\n",
371
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.5501 - accuracy: 0.7189 - val_loss: 0.5827 - val_accuracy: 0.6865\n",
372
+ "Epoch 4/25\n",
373
+ "250/250 [==============================] - 30s 122ms/step - loss: 0.5212 - accuracy: 0.7369 - val_loss: 0.5147 - val_accuracy: 0.7455\n",
374
+ "Epoch 5/25\n",
375
+ "250/250 [==============================] - 30s 119ms/step - loss: 0.4896 - accuracy: 0.7613 - val_loss: 0.5152 - val_accuracy: 0.7550\n",
376
+ "Epoch 6/25\n",
377
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.4721 - accuracy: 0.7770 - val_loss: 0.4776 - val_accuracy: 0.7640\n",
378
+ "Epoch 7/25\n",
379
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.4506 - accuracy: 0.7826 - val_loss: 0.4668 - val_accuracy: 0.7845\n",
380
+ "Epoch 8/25\n",
381
+ "250/250 [==============================] - 32s 126ms/step - loss: 0.4380 - accuracy: 0.7868 - val_loss: 0.4637 - val_accuracy: 0.7870\n",
382
+ "Epoch 9/25\n",
383
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.4231 - accuracy: 0.8026 - val_loss: 0.4680 - val_accuracy: 0.7850\n",
384
+ "Epoch 10/25\n",
385
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.4048 - accuracy: 0.8135 - val_loss: 0.5443 - val_accuracy: 0.7470\n",
386
+ "Epoch 11/25\n",
387
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.3917 - accuracy: 0.8242 - val_loss: 0.4698 - val_accuracy: 0.7875\n",
388
+ "Epoch 12/25\n",
389
+ "250/250 [==============================] - 37s 148ms/step - loss: 0.3743 - accuracy: 0.8284 - val_loss: 0.4812 - val_accuracy: 0.7940\n",
390
+ "Epoch 13/25\n",
391
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.3720 - accuracy: 0.8317 - val_loss: 0.4309 - val_accuracy: 0.8140\n",
392
+ "Epoch 14/25\n",
393
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.3497 - accuracy: 0.8443 - val_loss: 0.4593 - val_accuracy: 0.7980\n",
394
+ "Epoch 15/25\n",
395
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.3407 - accuracy: 0.8514 - val_loss: 0.4699 - val_accuracy: 0.7925\n",
396
+ "Epoch 16/25\n",
397
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.3249 - accuracy: 0.8593 - val_loss: 0.4712 - val_accuracy: 0.8035\n",
398
+ "Epoch 17/25\n",
399
+ "250/250 [==============================] - 30s 122ms/step - loss: 0.3044 - accuracy: 0.8748 - val_loss: 0.4846 - val_accuracy: 0.8060\n",
400
+ "Epoch 18/25\n",
401
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.3082 - accuracy: 0.8608 - val_loss: 0.4750 - val_accuracy: 0.8040\n",
402
+ "Epoch 19/25\n",
403
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.2860 - accuracy: 0.8752 - val_loss: 0.4533 - val_accuracy: 0.8180\n",
404
+ "Epoch 20/25\n",
405
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.2761 - accuracy: 0.8792 - val_loss: 0.5786 - val_accuracy: 0.7975\n",
406
+ "Epoch 21/25\n",
407
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.2634 - accuracy: 0.8861 - val_loss: 0.4989 - val_accuracy: 0.8085\n",
408
+ "Epoch 22/25\n",
409
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.2491 - accuracy: 0.8946 - val_loss: 0.5098 - val_accuracy: 0.8160\n",
410
+ "Epoch 23/25\n",
411
+ "250/250 [==============================] - 31s 124ms/step - loss: 0.2385 - accuracy: 0.8981 - val_loss: 0.5296 - val_accuracy: 0.8115\n",
412
+ "Epoch 24/25\n",
413
+ "250/250 [==============================] - 30s 120ms/step - loss: 0.2260 - accuracy: 0.9040 - val_loss: 0.5117 - val_accuracy: 0.8105\n",
414
+ "Epoch 25/25\n",
415
+ "250/250 [==============================] - 30s 121ms/step - loss: 0.2117 - accuracy: 0.9146 - val_loss: 0.5145 - val_accuracy: 0.8180\n"
416
+ ]
417
+ },
418
+ {
419
+ "data": {
420
+ "text/plain": [
421
+ "<keras.src.callbacks.History at 0x1f3d5467610>"
422
+ ]
423
+ },
424
+ "execution_count": 13,
425
+ "metadata": {},
426
+ "output_type": "execute_result"
427
+ }
428
+ ],
429
+ "source": [
430
+ "cnn.fit(x=training_set,validation_data=test_set,epochs=25)"
431
+ ]
432
+ },
433
+ {
434
+ "cell_type": "markdown",
435
+ "metadata": {
436
+ "id": "U3PZasO0006Z"
437
+ },
438
+ "source": [
439
+ "## Part 4 - Making a single prediction"
440
+ ]
441
+ },
442
+ {
443
+ "cell_type": "code",
444
+ "execution_count": 14,
445
+ "metadata": {
446
+ "id": "PQGfPACq3mGS"
447
+ },
448
+ "outputs": [
449
+ {
450
+ "name": "stdout",
451
+ "output_type": "stream",
452
+ "text": [
453
+ "1/1 [==============================] - 0s 107ms/step\n"
454
+ ]
455
+ }
456
+ ],
457
+ "source": [
458
+ "import numpy as np\n",
459
+ "from keras.preprocessing import image\n",
460
+ "test_image=image.load_img('dataset/single_prediction/cat_or_dog_1.jpg',target_size=(64,64))\n",
461
+ "test_image=image.img_to_array(test_image)\n",
462
+ "test_image=np.expand_dims(test_image,axis=0)\n",
463
+ "result=cnn.predict(test_image)\n",
464
+ "training_set.class_indices\n",
465
+ "if result[0][0]==1:\n",
466
+ " prediction='dog'\n",
467
+ "else:\n",
468
+ " prediction='cat'"
469
+ ]
470
+ },
471
+ {
472
+ "cell_type": "code",
473
+ "execution_count": 15,
474
+ "metadata": {
475
+ "id": "xMvlNcFN5yEX"
476
+ },
477
+ "outputs": [
478
+ {
479
+ "name": "stdout",
480
+ "output_type": "stream",
481
+ "text": [
482
+ "dog\n"
483
+ ]
484
+ }
485
+ ],
486
+ "source": [
487
+ "print(prediction)"
488
+ ]
489
+ },
490
+ {
491
+ "cell_type": "code",
492
+ "execution_count": 16,
493
+ "metadata": {},
494
+ "outputs": [
495
+ {
496
+ "name": "stdout",
497
+ "output_type": "stream",
498
+ "text": [
499
+ "1/1 [==============================] - 0s 25ms/step\n"
500
+ ]
501
+ }
502
+ ],
503
+ "source": [
504
+ "import numpy as np\n",
505
+ "from keras.preprocessing import image\n",
506
+ "test_image=image.load_img('dataset/single_prediction/cat_or_dog_2.jpg',target_size=(64,64))\n",
507
+ "test_image=image.img_to_array(test_image)\n",
508
+ "test_image=np.expand_dims(test_image,axis=0)\n",
509
+ "result=cnn.predict(test_image)\n",
510
+ "training_set.class_indices\n",
511
+ "if result[0][0]==1:\n",
512
+ " prediction='dog'\n",
513
+ "else:\n",
514
+ " prediction='cat'"
515
+ ]
516
+ },
517
+ {
518
+ "cell_type": "code",
519
+ "execution_count": 17,
520
+ "metadata": {},
521
+ "outputs": [
522
+ {
523
+ "name": "stdout",
524
+ "output_type": "stream",
525
+ "text": [
526
+ "cat\n"
527
+ ]
528
+ }
529
+ ],
530
+ "source": [
531
+ "print(prediction)"
532
+ ]
533
+ },
534
+ {
535
+ "cell_type": "code",
536
+ "execution_count": 18,
537
+ "metadata": {},
538
+ "outputs": [
539
+ {
540
+ "name": "stdout",
541
+ "output_type": "stream",
542
+ "text": [
543
+ "1/1 [==============================] - 0s 26ms/step\n"
544
+ ]
545
+ }
546
+ ],
547
+ "source": [
548
+ "import numpy as np\n",
549
+ "from keras.preprocessing import image\n",
550
+ "test_image=image.load_img('dataset/single_prediction/cat_or_dog_3.jpg',target_size=(64,64))\n",
551
+ "test_image=image.img_to_array(test_image)\n",
552
+ "test_image=np.expand_dims(test_image,axis=0)\n",
553
+ "result=cnn.predict(test_image)\n",
554
+ "training_set.class_indices\n",
555
+ "if result[0][0]==1:\n",
556
+ " prediction='dog'\n",
557
+ "else:\n",
558
+ " prediction='cat'"
559
+ ]
560
+ },
561
+ {
562
+ "cell_type": "code",
563
+ "execution_count": 19,
564
+ "metadata": {},
565
+ "outputs": [
566
+ {
567
+ "name": "stdout",
568
+ "output_type": "stream",
569
+ "text": [
570
+ "cat\n"
571
+ ]
572
+ }
573
+ ],
574
+ "source": [
575
+ "print(prediction)"
576
+ ]
577
+ },
578
+ {
579
+ "cell_type": "code",
580
+ "execution_count": 20,
581
+ "metadata": {},
582
+ "outputs": [
583
+ {
584
+ "name": "stdout",
585
+ "output_type": "stream",
586
+ "text": [
587
+ "1/1 [==============================] - 0s 25ms/step\n"
588
+ ]
589
+ }
590
+ ],
591
+ "source": [
592
+ "import numpy as np\n",
593
+ "from keras.preprocessing import image\n",
594
+ "test_image=image.load_img('dataset/single_prediction/cat_or_dog_4.jpg',target_size=(64,64))\n",
595
+ "test_image=image.img_to_array(test_image)\n",
596
+ "test_image=np.expand_dims(test_image,axis=0)\n",
597
+ "result=cnn.predict(test_image)\n",
598
+ "training_set.class_indices\n",
599
+ "if result[0][0]==1:\n",
600
+ " prediction='dog'\n",
601
+ "else:\n",
602
+ " prediction='cat'"
603
+ ]
604
+ },
605
+ {
606
+ "cell_type": "code",
607
+ "execution_count": 21,
608
+ "metadata": {},
609
+ "outputs": [
610
+ {
611
+ "name": "stdout",
612
+ "output_type": "stream",
613
+ "text": [
614
+ "dog\n"
615
+ ]
616
+ }
617
+ ],
618
+ "source": [
619
+ "print(prediction)"
620
+ ]
621
+ }
622
+ ],
623
+ "metadata": {
624
+ "colab": {
625
+ "provenance": []
626
+ },
627
+ "kernelspec": {
628
+ "display_name": "Python 3 (ipykernel)",
629
+ "language": "python",
630
+ "name": "python3"
631
+ },
632
+ "language_info": {
633
+ "codemirror_mode": {
634
+ "name": "ipython",
635
+ "version": 3
636
+ },
637
+ "file_extension": ".py",
638
+ "mimetype": "text/x-python",
639
+ "name": "python",
640
+ "nbconvert_exporter": "python",
641
+ "pygments_lexer": "ipython3",
642
+ "version": "3.11.5"
643
+ }
644
+ },
645
+ "nbformat": 4,
646
+ "nbformat_minor": 1
647
+ }
CNN/dataset/.DS_Store ADDED
Binary file (10.2 kB). View file
 
CNN/dataset/__MACOSX/._dataset ADDED
Binary file (212 Bytes). View file
 
CNN/dataset/__MACOSX/dataset/._.DS_Store ADDED
Binary file (212 Bytes). View file
 
CNN/dataset/__MACOSX/dataset/._test_set ADDED
Binary file (212 Bytes). View file
 
CNN/dataset/__MACOSX/dataset/._training_set ADDED
Binary file (212 Bytes). View file
 
CNN/dataset/__MACOSX/dataset/test_set/._.DS_Store ADDED
Binary file (212 Bytes). View file
 
CNN/dataset/__MACOSX/dataset/test_set/._cats ADDED
Binary file (212 Bytes). View file
 
CNN/dataset/__MACOSX/dataset/test_set/._dogs ADDED
Binary file (212 Bytes). View file
 
CNN/dataset/__MACOSX/dataset/test_set/cats/._.DS_Store ADDED
Binary file (212 Bytes). View file
 
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4001.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4002.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4003.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4004.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4005.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4006.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4007.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4008.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4009.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4010.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4011.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4012.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4013.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4014.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4015.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4016.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4017.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4018.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4019.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4020.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4021.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4022.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4023.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4024.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4025.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4026.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4027.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4028.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4029.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4030.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4031.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4032.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4033.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4034.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4035.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4036.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4037.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4038.jpg ADDED
CNN/dataset/__MACOSX/dataset/test_set/cats/._cat.4039.jpg ADDED