In [1]:
%run vgg16.py


Using TensorFlow backend.
Model loaded.

In [2]:
val_synsets = [x.strip() for x in open('/Data/ImageNet/imagenet_2012_validation_synset_labels.txt')]

In [5]:
blueberry_fruit = wordnet.synsets('blueberry', 'n')[1]
blueberry_fruit.definition()


Out[5]:
'sweet edible dark-blue berries of either low-growing or high-growing blueberry plants'

In [8]:
banana_fruit = wordnet.synsets('banana', 'n')[1]
banana_fruit.definition()


Out[8]:
'elongated crescent-shaped yellow fruit with soft sweet flesh'

In [36]:
'n{:08}'.format(banana_fruit.offset())


Out[36]:
'n07753592'

In [12]:
from collections import Counter
val_counts = Counter(val_synsets)

In [15]:
val_counts.most_common(5)


Out[15]:
[('n04141327', 50),
 ('n03000247', 50),
 ('n02110958', 50),
 ('n03095699', 50),
 ('n02110806', 50)]

In [37]:
val_counts['n{:08}'.format(blueberry_fruit.offset())]


Out[37]:
0

In [22]:
root_fruit = wordnet.synsets('fruit', 'n')[0]
root_fruit.definition()


Out[22]:
'the ripened reproductive body of a seed plant'

In [24]:
fruits = [i for i, x in enumerate(val_synsets) if is_a(get_synset(x), root_fruit)]

In [25]:
fruit_synsets = Counter([val_synsets[i] for i in fruits])

In [29]:
[get_synset(s) for s, cnt in fruit_synsets.most_common(50)]


Out[29]:
[Synset('buckeye.n.01'),
 Synset('jackfruit.n.02'),
 Synset('banana.n.02'),
 Synset('corn.n.02'),
 Synset('granny_smith.n.01'),
 Synset('lemon.n.01'),
 Synset('fig.n.04'),
 Synset('ear.n.05'),
 Synset('rapeseed.n.01'),
 Synset('acorn.n.01'),
 Synset('pomegranate.n.02'),
 Synset('orange.n.01'),
 Synset('strawberry.n.01'),
 Synset('custard_apple.n.02'),
 Synset('pineapple.n.02'),
 Synset('hip.n.05')]

In [31]:
strawberry_synset = wordnet.synset('strawberry.n.01')
banana_synset = wordnet.synset('banana.n.02')

In [40]:
strawberry_id = 'n{:08}'.format(strawberry_synset.offset())
val_counts[strawberry_id]


Out[40]:
50

In [39]:
banana_id = 'n{:08}'.format(banana_synset.offset())
val_counts[banana_id]


Out[39]:
50

In [ ]:


In [41]:
[i for i, x in enumerate(val_synsets) if x == strawberry_id]


Out[41]:
[98,
 319,
 1193,
 1734,
 1935,
 2411,
 4427,
 4831,
 5065,
 5756,
 7897,
 8737,
 10615,
 10941,
 11347,
 12215,
 12370,
 12496,
 12644,
 12651,
 12727,
 13498,
 14738,
 16158,
 17533,
 19252,
 19753,
 21853,
 22483,
 23511,
 23738,
 24154,
 25149,
 31439,
 31508,
 31852,
 32275,
 32410,
 33918,
 35169,
 35444,
 37095,
 37521,
 40988,
 41408,
 42196,
 43919,
 46202,
 46436,
 48022]

In [43]:
import os

In [47]:
os.system('open /Data/ImageNet/validation/ILSVRC2012_val_{:08}.JPEG'.format(12651+1))


Out[47]:
0

In [19]:
[s.definition() for s in wordnet.synsets('fruit', 'n')]


Out[19]:
['the ripened reproductive body of a seed plant',
 'an amount of a product',
 'the consequence of some effort or action']

In [ ]: