Skip to content

Commit 9b66545

Browse files
author
Anastasia
committed
Updated imageNet models notebook
1 parent c930d4a commit 9b66545

File tree

2 files changed

+53
-57
lines changed

2 files changed

+53
-57
lines changed
-164 KB
Binary file not shown.

Keras-ImageNet-Models/pretrained-imagenet-models-classification.ipynb

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"metadata": {},
5858
"outputs": [],
5959
"source": [
60-
"# instantiate the models\n",
60+
"# init the models\n",
6161
"vgg_model = vgg16.VGG16(weights='imagenet')\n",
6262
"\n",
6363
"inception_model = inception_v3.InceptionV3(weights='imagenet')\n",
@@ -71,7 +71,7 @@
7171
"cell_type": "markdown",
7272
"metadata": {},
7373
"source": [
74-
"Let's define the image for further experiments assigning its location to the ``filename`` variable. You can choose any other image example to test the models."
74+
"Let's define the image path for further experiments in the ``filename`` variable. Please note, that there are other images in the ``images`` directory that you can use as well to test the models."
7575
]
7676
},
7777
{
@@ -144,7 +144,7 @@
144144
{
145145
"data": {
146146
"text/plain": [
147-
"<matplotlib.image.AxesImage at 0x7f23000a2510>"
147+
"<matplotlib.image.AxesImage at 0x7f3270126c50>"
148148
]
149149
},
150150
"execution_count": 5,
@@ -212,18 +212,15 @@
212212
"metadata": {},
213213
"outputs": [
214214
{
215-
"data": {
216-
"text/plain": [
217-
"[[('n02123597', 'Siamese_cat', 0.30934104),\n",
218-
" ('n01877812', 'wallaby', 0.08034121),\n",
219-
" ('n02326432', 'hare', 0.07509851),\n",
220-
" ('n02325366', 'wood_rabbit', 0.05053079),\n",
221-
" ('n03223299', 'doormat', 0.048173636)]]"
222-
]
223-
},
224-
"execution_count": 6,
225-
"metadata": {},
226-
"output_type": "execute_result"
215+
"name": "stdout",
216+
"output_type": "stream",
217+
"text": [
218+
"('n02123597', 'Siamese_cat', 0.30934194)\n",
219+
"('n01877812', 'wallaby', 0.08034124)\n",
220+
"('n02326432', 'hare', 0.07509843)\n",
221+
"('n02325366', 'wood_rabbit', 0.0505307)\n",
222+
"('n03223299', 'doormat', 0.048173614)\n"
223+
]
227224
}
228225
],
229226
"source": [
@@ -234,9 +231,11 @@
234231
"predictions = vgg_model.predict(processed_image)\n",
235232
"# print predictions\n",
236233
"# convert the probabilities to class labels\n",
237-
"# We will get top 5 predictions which is the default\n",
234+
"# we will get top 5 predictions which is the default\n",
238235
"label_vgg = decode_predictions(predictions)\n",
239-
"label_vgg"
236+
"# print VGG16 predictions\n",
237+
"for prediction_id in range(len(label_vgg[0])):\n",
238+
" print(label_vgg[0][prediction_id])"
240239
]
241240
},
242241
{
@@ -252,16 +251,13 @@
252251
"metadata": {},
253252
"outputs": [
254253
{
255-
"data": {
256-
"text/plain": [
257-
"[[('n02124075', 'Egyptian_cat', 0.15737584),\n",
258-
" ('n03958227', 'plastic_bag', 0.14362834),\n",
259-
" ('n03223299', 'doormat', 0.14099452)]]"
260-
]
261-
},
262-
"execution_count": 7,
263-
"metadata": {},
264-
"output_type": "execute_result"
254+
"name": "stdout",
255+
"output_type": "stream",
256+
"text": [
257+
"('n02124075', 'Egyptian_cat', 0.15737602)\n",
258+
"('n03958227', 'plastic_bag', 0.14362879)\n",
259+
"('n03223299', 'doormat', 0.14099468)\n"
260+
]
265261
}
266262
],
267263
"source": [
@@ -274,7 +270,9 @@
274270
"# convert the probabilities to class labels\n",
275271
"# If you want to see the top 3 predictions, specify it using the top argument\n",
276272
"label_resnet = decode_predictions(predictions, top=3)\n",
277-
"label_resnet"
273+
"# print ResNet predictions\n",
274+
"for prediction_id in range(len(label_resnet[0])):\n",
275+
" print(label_resnet[0][prediction_id])"
278276
]
279277
},
280278
{
@@ -290,18 +288,15 @@
290288
"metadata": {},
291289
"outputs": [
292290
{
293-
"data": {
294-
"text/plain": [
295-
"[[('n03958227', 'plastic_bag', 0.15703735),\n",
296-
" ('n02124075', 'Egyptian_cat', 0.11697447),\n",
297-
" ('n02123597', 'Siamese_cat', 0.10532668),\n",
298-
" ('n02123045', 'tabby', 0.075648665),\n",
299-
" ('n02909870', 'bucket', 0.054680943)]]"
300-
]
301-
},
302-
"execution_count": 8,
303-
"metadata": {},
304-
"output_type": "execute_result"
291+
"name": "stdout",
292+
"output_type": "stream",
293+
"text": [
294+
"('n03958227', 'plastic_bag', 0.1570367)\n",
295+
"('n02124075', 'Egyptian_cat', 0.11697376)\n",
296+
"('n02123597', 'Siamese_cat', 0.10532685)\n",
297+
"('n02123045', 'tabby', 0.0756485)\n",
298+
"('n02909870', 'bucket', 0.054681662)\n"
299+
]
305300
}
306301
],
307302
"source": [
@@ -313,7 +308,9 @@
313308
"\n",
314309
"# convert the probabilities to imagenet class labels\n",
315310
"label_mobilenet = decode_predictions(predictions)\n",
316-
"label_mobilenet"
311+
"# print MobileNet predictions\n",
312+
"for prediction_id in range(len(label_mobilenet[0])):\n",
313+
" print(label_mobilenet[0][prediction_id])"
317314
]
318315
},
319316
{
@@ -332,18 +329,15 @@
332329
"metadata": {},
333330
"outputs": [
334331
{
335-
"data": {
336-
"text/plain": [
337-
"[[('n02124075', 'Egyptian_cat', 0.66225773),\n",
338-
" ('n02123045', 'tabby', 0.050285283),\n",
339-
" ('n02123597', 'Siamese_cat', 0.03638168),\n",
340-
" ('n02123159', 'tiger_cat', 0.023522485),\n",
341-
" ('n03223299', 'doormat', 0.0152056785)]]"
342-
]
343-
},
344-
"execution_count": 9,
345-
"metadata": {},
346-
"output_type": "execute_result"
332+
"name": "stdout",
333+
"output_type": "stream",
334+
"text": [
335+
"('n02124075', 'Egyptian_cat', 0.66225827)\n",
336+
"('n02123045', 'tabby', 0.05028525)\n",
337+
"('n02123597', 'Siamese_cat', 0.03638152)\n",
338+
"('n02123159', 'tiger_cat', 0.023522492)\n",
339+
"('n03223299', 'doormat', 0.015205677)\n"
340+
]
347341
}
348342
],
349343
"source": [
@@ -364,7 +358,9 @@
364358
"\n",
365359
"# convert the probabilities to class labels\n",
366360
"label_inception = decode_predictions(predictions)\n",
367-
"label_inception"
361+
"# print Inception predictions\n",
362+
"for prediction_id in range(len(label_inception[0])):\n",
363+
" print(label_inception[0][prediction_id])"
368364
]
369365
},
370366
{
@@ -404,7 +400,7 @@
404400
{
405401
"data": {
406402
"text/plain": [
407-
"(-0.5, 699.5, 699.5, -0.5)"
403+
"<matplotlib.image.AxesImage at 0x7f32381f4a10>"
408404
]
409405
},
410406
"execution_count": 11,
@@ -426,8 +422,8 @@
426422
],
427423
"source": [
428424
"plt.figure(figsize=[10,10])\n",
429-
"plt.imshow(numpy_image)\n",
430-
"plt.axis('off')"
425+
"plt.axis('off')\n",
426+
"plt.imshow(numpy_image)"
431427
]
432428
}
433429
],

0 commit comments

Comments
 (0)