├── .gitignore ├── README.md ├── classify.py ├── misc ├── __init__.py ├── convert_weights.py ├── ilsvrc_synsets.txt ├── layers.py ├── sample.jpg └── utils.py ├── nets ├── __init__.py ├── caffenet.py ├── googlenet.py ├── inception_v3.py ├── resnet_152.py ├── resnet_50.py ├── vgg_16.py ├── vgg_19.py └── vgg_f.py └── weights └── download_weights.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | *.pyc 6 | 7 | # C extensions 8 | *.so 9 | 10 | # Distribution / packaging 11 | weights/* 12 | .Python 13 | env/ 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .coverage 43 | .coverage.* 44 | .cache 45 | nosetests.xml 46 | coverage.xml 47 | *,cover 48 | .hypothesis/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | 58 | # Flask stuff: 59 | instance/ 60 | .webassets-cache 61 | 62 | # Scrapy stuff: 63 | .scrapy 64 | 65 | # Sphinx documentation 66 | docs/_build/ 67 | 68 | # PyBuilder 69 | target/ 70 | 71 | # IPython Notebook 72 | .ipynb_checkpoints 73 | 74 | # pyenv 75 | .python-version 76 | 77 | # celery beat schedule file 78 | celerybeat-schedule 79 | 80 | # dotenv 81 | .env 82 | 83 | # virtualenv 84 | venv/ 85 | ENV/ 86 | 87 | # Spyder project settings 88 | .spyderproject 89 | 90 | # Rope project settings 91 | .ropeproject 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tensorflow-classification 2 | 3 | Different neural network architechtures implemented in tensorflow for image classification. Weights converted from caffemodels. Some weights were converted using `misc/convert.py` others using [caffe-tensorflow](https://github.com/ethereon/caffe-tensorflow). The weights can be downloaded from [here](https://www.dropbox.com/sh/qpuqj03gv00ba85/AAApqsIe4SqSOrsfpwrYjOema?dl=0). Tested with Tensorflow 1.0. Weights for inception-V3 taken from Keras implementation provided [here](https://github.com/fchollet/deep-learning-models/blob/master/inception_v3.py). Contributions are welcome! 4 | 5 | ## Features 6 | 7 | * A single call program to classify images using different architechtures (vgg-f, caffenet, vgg-16, vgg-19, googlenet, resnet-50, resnet-152, inception-V3) 8 | * Returns networks as a dictionary of layers, so accessing activations at intermediate layers is easy 9 | * Functions to classify single image or evaluate on whole validation set 10 | 11 | ## Usage 12 | 13 | * For classification of a single image, `python classify.py --network 'resnet152' --img_path 'misc/sample.jpg'` 14 | * For evaluation over whole ilsvrc validation set `python classify.py --network 'resnet152' --img_list '' --gt_labels ''` 15 | * Currently the `--network` argument can take vggf, caffenet, vgg16, vgg19, googlenet, resnet50, resnet152, inceptionv3. 16 | 17 | ## Performance 18 | These converted models have the following performance on the ilsvrc validation set, with each image resized to 224x224 (227 or 299 depending on architechture), and per channel mean subtraction. 19 | 20 | 21 | | Network | Top-1 Accuracy | Top-5 Accuracy | 22 | | ------------- |:-------------:| :-----:| 23 | | VGG-F | 58.33% | 80.75% | 24 | | CaffeNet | 56.77% | 79.98% | 25 | | VGG-16 | 70.93% | 89.82% | 26 | | VGG-19 | 71.02% | 89.85% | 27 | | GoogLeNet | 68.69% | 89.01% | 28 | | ResNet-50 | 74.71% | 92.00% | 29 | | ResNet-152 | 76.33% | 92.93% | 30 | | Inception-V3 | 76.85% | 93.39% | 31 | -------------------------------------------------------------------------------- /classify.py: -------------------------------------------------------------------------------- 1 | from nets.vgg_f import vggf 2 | from nets.caffenet import caffenet 3 | from nets.vgg_16 import vgg16 4 | from nets.vgg_19 import vgg19 5 | from nets.googlenet import googlenet 6 | from nets.resnet_50 import resnet50 7 | from nets.resnet_152 import resnet152 8 | from nets.inception_v3 import inceptionv3 9 | from misc.utils import * 10 | import tensorflow as tf 11 | import numpy as np 12 | import argparse 13 | import time 14 | 15 | def validate_arguments(args): 16 | nets = ['vggf', 'caffenet', 'vgg16', 'vgg19', 'googlenet', 'resnet50', 'resnet152', 'inceptionv3'] 17 | if not(args.network in nets): 18 | print ('invalid network') 19 | exit (-1) 20 | if args.evaluate: 21 | if args.img_list is None or args.gt_labels is None: 22 | print ('provide image list and labels') 23 | exit (-1) 24 | 25 | def choose_net(network): 26 | MAP = { 27 | 'vggf' : vggf, 28 | 'caffenet' : caffenet, 29 | 'vgg16' : vgg16, 30 | 'vgg19' : vgg19, 31 | 'googlenet': googlenet, 32 | 'resnet50' : resnet50, 33 | 'resnet152': resnet152, 34 | 'inceptionv3': inceptionv3, 35 | } 36 | 37 | if network == 'caffenet': 38 | size = 227 39 | elif network == 'inceptionv3': 40 | size = 299 41 | else: 42 | size = 224 43 | 44 | #placeholder to pass image 45 | input_image = tf.placeholder(shape=[None, size, size, 3],dtype='float32', name='input_image') 46 | 47 | return MAP[network](input_image), input_image 48 | 49 | def evaluate(net, im_list, in_im, labels, net_name,batch_size=30): 50 | top_1 = 0 51 | top_5 = 0 52 | config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True)) 53 | img_list = open(im_list).readlines() 54 | gt_labels = open(labels).readlines() 55 | t_s = time.time() 56 | isotropic,size = get_params(net_name) 57 | batch_im = np.zeros((batch_size, size,size,3)) 58 | with tf.Session(config=config) as sess: 59 | sess.run(tf.global_variables_initializer()) 60 | img_loader = loader_func(net_name,isotropic,size,sess) 61 | for i in range(len(img_list)/batch_size): 62 | lim = min(batch_size,len(img_list)-i*batch_size) 63 | for j in range(lim): 64 | im = img_loader(img_list[i*batch_size+j].strip()) 65 | batch_im[j] = np.copy(im) 66 | gt = np.array([int(gt_labels[i*batch_size+j].strip()) for j in range(lim)]) 67 | softmax_scores = sess.run(net['prob'], feed_dict={in_im: batch_im}) 68 | inds = np.argsort(softmax_scores, axis=1)[:,::-1][:,:5] 69 | if i!=0 and (i*batch_size+lim)%1000 == 0: 70 | print 'iter: {:5d}\ttop-1: {:04.2f}\ttop-5: {:04.2f}'.format(i*batch_size+lim, (top_1/float(i*batch_size+lim))*100, 71 | (top_5)/float(i*batch_size+lim)*100) 72 | top_1+= np.sum(inds[:,0] == gt) 73 | top_5 += np.sum([gt[i] in inds[i] for i in range(lim)]) 74 | print 'Top-1 Accuracy = {:.2f}'.format(top_1/500.0) 75 | print 'Top-5 Accuracy = {:.2f}'.format(top_5/500.0) 76 | print 'Time taken: {:.2f}s'.format(time.time()-t_s) 77 | 78 | def predict(net, im_path, in_im, net_name): 79 | synset = open('misc/ilsvrc_synsets.txt').readlines() 80 | config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True)) 81 | t_s = time.time() 82 | isotropic,size = get_params(net_name) 83 | with tf.Session(config=config) as sess: 84 | sess.run(tf.global_variables_initializer()) 85 | img_loader = loader_func(net_name,isotropic,size,sess) 86 | im = img_loader(im_path.strip()) 87 | im = np.reshape(im,[1,size,size,3]) 88 | softmax_scores = sess.run(net['prob'], feed_dict={in_im: im}) 89 | inds = np.argsort(softmax_scores[0])[::-1][:5] 90 | print '{:}\t{:}'.format('Score','Class') 91 | for i in inds: 92 | print '{:.4f}\t{:}'.format(softmax_scores[0,i], synset[i].strip().split(',')[0]) 93 | 94 | def main(): 95 | parser = argparse.ArgumentParser() 96 | parser.add_argument('--network', default='googlenet', help='The network eg. googlenet') 97 | parser.add_argument('--img_path', default='misc/sample.jpg', help='Path to input image') 98 | parser.add_argument('--evaluate', default=False, help='Flag to evaluate over full validation set') 99 | parser.add_argument('--img_list', help='Path to the validation image list') 100 | parser.add_argument('--gt_labels', help='Path to the ground truth validation labels') 101 | parser.add_argument('--batch_size', default=50, help='Batch size for evaluation code') 102 | args = parser.parse_args() 103 | validate_arguments(args) 104 | net, inp_im = choose_net(args.network) 105 | if args.evaluate: 106 | evaluate(net, args.img_list, inp_im, args.gt_labels, args.network,args.batch_size) 107 | else: 108 | predict(net, args.img_path, inp_im, args.network) 109 | 110 | if __name__ == '__main__': 111 | main() 112 | -------------------------------------------------------------------------------- /misc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utsavgarg/tensorflow-classification/ea2ca5fbe01bd6dcba709cd1a1af4dd0bbefb0ff/misc/__init__.py -------------------------------------------------------------------------------- /misc/convert_weights.py: -------------------------------------------------------------------------------- 1 | #sample code for conversion of weights from caffe to tensorflow 2 | 3 | import caffe 4 | import numpy as np 5 | 6 | net = caffe.Classifier('deploy.prototxt','VGG_CNN_F.caffemodel', caffe.TEST) 7 | 8 | weights = {} 9 | 10 | for i in net.params.keys(): 11 | temp = [] 12 | if i == 'fc6': 13 | t = np.reshape(net.params[i][0].data,[4096,256,6,6]) 14 | t = np.transpose(t,[2,3,1,0]) 15 | temp.append(np.reshape(t,[-1,4096])) 16 | elif 'fc' in i: 17 | temp.append(np.transpose(net.params[i][0].data,[1,0])) 18 | else: 19 | temp.append(np.transpose(net.params[i][0].data,[2,3,1,0])) 20 | temp.append(net.params[i][1].data) 21 | weights[i] = temp 22 | 23 | np.save('vgg_f',weights) 24 | 25 | -------------------------------------------------------------------------------- /misc/ilsvrc_synsets.txt: -------------------------------------------------------------------------------- 1 | n01440764 tench, Tinca tinca 2 | n01443537 goldfish, Carassius auratus 3 | n01484850 great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias 4 | n01491361 tiger shark, Galeocerdo cuvieri 5 | n01494475 hammerhead, hammerhead shark 6 | n01496331 electric ray, crampfish, numbfish, torpedo 7 | n01498041 stingray 8 | n01514668 cock 9 | n01514859 hen 10 | n01518878 ostrich, Struthio camelus 11 | n01530575 brambling, Fringilla montifringilla 12 | n01531178 goldfinch, Carduelis carduelis 13 | n01532829 house finch, linnet, Carpodacus mexicanus 14 | n01534433 junco, snowbird 15 | n01537544 indigo bunting, indigo finch, indigo bird, Passerina cyanea 16 | n01558993 robin, American robin, Turdus migratorius 17 | n01560419 bulbul 18 | n01580077 jay 19 | n01582220 magpie 20 | n01592084 chickadee 21 | n01601694 water ouzel, dipper 22 | n01608432 kite 23 | n01614925 bald eagle, American eagle, Haliaeetus leucocephalus 24 | n01616318 vulture 25 | n01622779 great grey owl, great gray owl, Strix nebulosa 26 | n01629819 European fire salamander, Salamandra salamandra 27 | n01630670 common newt, Triturus vulgaris 28 | n01631663 eft 29 | n01632458 spotted salamander, Ambystoma maculatum 30 | n01632777 axolotl, mud puppy, Ambystoma mexicanum 31 | n01641577 bullfrog, Rana catesbeiana 32 | n01644373 tree frog, tree-frog 33 | n01644900 tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui 34 | n01664065 loggerhead, loggerhead turtle, Caretta caretta 35 | n01665541 leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea 36 | n01667114 mud turtle 37 | n01667778 terrapin 38 | n01669191 box turtle, box tortoise 39 | n01675722 banded gecko 40 | n01677366 common iguana, iguana, Iguana iguana 41 | n01682714 American chameleon, anole, Anolis carolinensis 42 | n01685808 whiptail, whiptail lizard 43 | n01687978 agama 44 | n01688243 frilled lizard, Chlamydosaurus kingi 45 | n01689811 alligator lizard 46 | n01692333 Gila monster, Heloderma suspectum 47 | n01693334 green lizard, Lacerta viridis 48 | n01694178 African chameleon, Chamaeleo chamaeleon 49 | n01695060 Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis 50 | n01697457 African crocodile, Nile crocodile, Crocodylus niloticus 51 | n01698640 American alligator, Alligator mississipiensis 52 | n01704323 triceratops 53 | n01728572 thunder snake, worm snake, Carphophis amoenus 54 | n01728920 ringneck snake, ring-necked snake, ring snake 55 | n01729322 hognose snake, puff adder, sand viper 56 | n01729977 green snake, grass snake 57 | n01734418 king snake, kingsnake 58 | n01735189 garter snake, grass snake 59 | n01737021 water snake 60 | n01739381 vine snake 61 | n01740131 night snake, Hypsiglena torquata 62 | n01742172 boa constrictor, Constrictor constrictor 63 | n01744401 rock python, rock snake, Python sebae 64 | n01748264 Indian cobra, Naja naja 65 | n01749939 green mamba 66 | n01751748 sea snake 67 | n01753488 horned viper, cerastes, sand viper, horned asp, Cerastes cornutus 68 | n01755581 diamondback, diamondback rattlesnake, Crotalus adamanteus 69 | n01756291 sidewinder, horned rattlesnake, Crotalus cerastes 70 | n01768244 trilobite 71 | n01770081 harvestman, daddy longlegs, Phalangium opilio 72 | n01770393 scorpion 73 | n01773157 black and gold garden spider, Argiope aurantia 74 | n01773549 barn spider, Araneus cavaticus 75 | n01773797 garden spider, Aranea diademata 76 | n01774384 black widow, Latrodectus mactans 77 | n01774750 tarantula 78 | n01775062 wolf spider, hunting spider 79 | n01776313 tick 80 | n01784675 centipede 81 | n01795545 black grouse 82 | n01796340 ptarmigan 83 | n01797886 ruffed grouse, partridge, Bonasa umbellus 84 | n01798484 prairie chicken, prairie grouse, prairie fowl 85 | n01806143 peacock 86 | n01806567 quail 87 | n01807496 partridge 88 | n01817953 African grey, African gray, Psittacus erithacus 89 | n01818515 macaw 90 | n01819313 sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita 91 | n01820546 lorikeet 92 | n01824575 coucal 93 | n01828970 bee eater 94 | n01829413 hornbill 95 | n01833805 hummingbird 96 | n01843065 jacamar 97 | n01843383 toucan 98 | n01847000 drake 99 | n01855032 red-breasted merganser, Mergus serrator 100 | n01855672 goose 101 | n01860187 black swan, Cygnus atratus 102 | n01871265 tusker 103 | n01872401 echidna, spiny anteater, anteater 104 | n01873310 platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus 105 | n01877812 wallaby, brush kangaroo 106 | n01882714 koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus 107 | n01883070 wombat 108 | n01910747 jellyfish 109 | n01914609 sea anemone, anemone 110 | n01917289 brain coral 111 | n01924916 flatworm, platyhelminth 112 | n01930112 nematode, nematode worm, roundworm 113 | n01943899 conch 114 | n01944390 snail 115 | n01945685 slug 116 | n01950731 sea slug, nudibranch 117 | n01955084 chiton, coat-of-mail shell, sea cradle, polyplacophore 118 | n01968897 chambered nautilus, pearly nautilus, nautilus 119 | n01978287 Dungeness crab, Cancer magister 120 | n01978455 rock crab, Cancer irroratus 121 | n01980166 fiddler crab 122 | n01981276 king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica 123 | n01983481 American lobster, Northern lobster, Maine lobster, Homarus americanus 124 | n01984695 spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish 125 | n01985128 crayfish, crawfish, crawdad, crawdaddy 126 | n01986214 hermit crab 127 | n01990800 isopod 128 | n02002556 white stork, Ciconia ciconia 129 | n02002724 black stork, Ciconia nigra 130 | n02006656 spoonbill 131 | n02007558 flamingo 132 | n02009229 little blue heron, Egretta caerulea 133 | n02009912 American egret, great white heron, Egretta albus 134 | n02011460 bittern 135 | n02012849 crane 136 | n02013706 limpkin, Aramus pictus 137 | n02017213 European gallinule, Porphyrio porphyrio 138 | n02018207 American coot, marsh hen, mud hen, water hen, Fulica americana 139 | n02018795 bustard 140 | n02025239 ruddy turnstone, Arenaria interpres 141 | n02027492 red-backed sandpiper, dunlin, Erolia alpina 142 | n02028035 redshank, Tringa totanus 143 | n02033041 dowitcher 144 | n02037110 oystercatcher, oyster catcher 145 | n02051845 pelican 146 | n02056570 king penguin, Aptenodytes patagonica 147 | n02058221 albatross, mollymawk 148 | n02066245 grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus 149 | n02071294 killer whale, killer, orca, grampus, sea wolf, Orcinus orca 150 | n02074367 dugong, Dugong dugon 151 | n02077923 sea lion 152 | n02085620 Chihuahua 153 | n02085782 Japanese spaniel 154 | n02085936 Maltese dog, Maltese terrier, Maltese 155 | n02086079 Pekinese, Pekingese, Peke 156 | n02086240 Shih-Tzu 157 | n02086646 Blenheim spaniel 158 | n02086910 papillon 159 | n02087046 toy terrier 160 | n02087394 Rhodesian ridgeback 161 | n02088094 Afghan hound, Afghan 162 | n02088238 basset, basset hound 163 | n02088364 beagle 164 | n02088466 bloodhound, sleuthhound 165 | n02088632 bluetick 166 | n02089078 black-and-tan coonhound 167 | n02089867 Walker hound, Walker foxhound 168 | n02089973 English foxhound 169 | n02090379 redbone 170 | n02090622 borzoi, Russian wolfhound 171 | n02090721 Irish wolfhound 172 | n02091032 Italian greyhound 173 | n02091134 whippet 174 | n02091244 Ibizan hound, Ibizan Podenco 175 | n02091467 Norwegian elkhound, elkhound 176 | n02091635 otterhound, otter hound 177 | n02091831 Saluki, gazelle hound 178 | n02092002 Scottish deerhound, deerhound 179 | n02092339 Weimaraner 180 | n02093256 Staffordshire bullterrier, Staffordshire bull terrier 181 | n02093428 American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier 182 | n02093647 Bedlington terrier 183 | n02093754 Border terrier 184 | n02093859 Kerry blue terrier 185 | n02093991 Irish terrier 186 | n02094114 Norfolk terrier 187 | n02094258 Norwich terrier 188 | n02094433 Yorkshire terrier 189 | n02095314 wire-haired fox terrier 190 | n02095570 Lakeland terrier 191 | n02095889 Sealyham terrier, Sealyham 192 | n02096051 Airedale, Airedale terrier 193 | n02096177 cairn, cairn terrier 194 | n02096294 Australian terrier 195 | n02096437 Dandie Dinmont, Dandie Dinmont terrier 196 | n02096585 Boston bull, Boston terrier 197 | n02097047 miniature schnauzer 198 | n02097130 giant schnauzer 199 | n02097209 standard schnauzer 200 | n02097298 Scotch terrier, Scottish terrier, Scottie 201 | n02097474 Tibetan terrier, chrysanthemum dog 202 | n02097658 silky terrier, Sydney silky 203 | n02098105 soft-coated wheaten terrier 204 | n02098286 West Highland white terrier 205 | n02098413 Lhasa, Lhasa apso 206 | n02099267 flat-coated retriever 207 | n02099429 curly-coated retriever 208 | n02099601 golden retriever 209 | n02099712 Labrador retriever 210 | n02099849 Chesapeake Bay retriever 211 | n02100236 German short-haired pointer 212 | n02100583 vizsla, Hungarian pointer 213 | n02100735 English setter 214 | n02100877 Irish setter, red setter 215 | n02101006 Gordon setter 216 | n02101388 Brittany spaniel 217 | n02101556 clumber, clumber spaniel 218 | n02102040 English springer, English springer spaniel 219 | n02102177 Welsh springer spaniel 220 | n02102318 cocker spaniel, English cocker spaniel, cocker 221 | n02102480 Sussex spaniel 222 | n02102973 Irish water spaniel 223 | n02104029 kuvasz 224 | n02104365 schipperke 225 | n02105056 groenendael 226 | n02105162 malinois 227 | n02105251 briard 228 | n02105412 kelpie 229 | n02105505 komondor 230 | n02105641 Old English sheepdog, bobtail 231 | n02105855 Shetland sheepdog, Shetland sheep dog, Shetland 232 | n02106030 collie 233 | n02106166 Border collie 234 | n02106382 Bouvier des Flandres, Bouviers des Flandres 235 | n02106550 Rottweiler 236 | n02106662 German shepherd, German shepherd dog, German police dog, alsatian 237 | n02107142 Doberman, Doberman pinscher 238 | n02107312 miniature pinscher 239 | n02107574 Greater Swiss Mountain dog 240 | n02107683 Bernese mountain dog 241 | n02107908 Appenzeller 242 | n02108000 EntleBucher 243 | n02108089 boxer 244 | n02108422 bull mastiff 245 | n02108551 Tibetan mastiff 246 | n02108915 French bulldog 247 | n02109047 Great Dane 248 | n02109525 Saint Bernard, St Bernard 249 | n02109961 Eskimo dog, husky 250 | n02110063 malamute, malemute, Alaskan malamute 251 | n02110185 Siberian husky 252 | n02110341 dalmatian, coach dog, carriage dog 253 | n02110627 affenpinscher, monkey pinscher, monkey dog 254 | n02110806 basenji 255 | n02110958 pug, pug-dog 256 | n02111129 Leonberg 257 | n02111277 Newfoundland, Newfoundland dog 258 | n02111500 Great Pyrenees 259 | n02111889 Samoyed, Samoyede 260 | n02112018 Pomeranian 261 | n02112137 chow, chow chow 262 | n02112350 keeshond 263 | n02112706 Brabancon griffon 264 | n02113023 Pembroke, Pembroke Welsh corgi 265 | n02113186 Cardigan, Cardigan Welsh corgi 266 | n02113624 toy poodle 267 | n02113712 miniature poodle 268 | n02113799 standard poodle 269 | n02113978 Mexican hairless 270 | n02114367 timber wolf, grey wolf, gray wolf, Canis lupus 271 | n02114548 white wolf, Arctic wolf, Canis lupus tundrarum 272 | n02114712 red wolf, maned wolf, Canis rufus, Canis niger 273 | n02114855 coyote, prairie wolf, brush wolf, Canis latrans 274 | n02115641 dingo, warrigal, warragal, Canis dingo 275 | n02115913 dhole, Cuon alpinus 276 | n02116738 African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus 277 | n02117135 hyena, hyaena 278 | n02119022 red fox, Vulpes vulpes 279 | n02119789 kit fox, Vulpes macrotis 280 | n02120079 Arctic fox, white fox, Alopex lagopus 281 | n02120505 grey fox, gray fox, Urocyon cinereoargenteus 282 | n02123045 tabby, tabby cat 283 | n02123159 tiger cat 284 | n02123394 Persian cat 285 | n02123597 Siamese cat, Siamese 286 | n02124075 Egyptian cat 287 | n02125311 cougar, puma, catamount, mountain lion, painter, panther, Felis concolor 288 | n02127052 lynx, catamount 289 | n02128385 leopard, Panthera pardus 290 | n02128757 snow leopard, ounce, Panthera uncia 291 | n02128925 jaguar, panther, Panthera onca, Felis onca 292 | n02129165 lion, king of beasts, Panthera leo 293 | n02129604 tiger, Panthera tigris 294 | n02130308 cheetah, chetah, Acinonyx jubatus 295 | n02132136 brown bear, bruin, Ursus arctos 296 | n02133161 American black bear, black bear, Ursus americanus, Euarctos americanus 297 | n02134084 ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus 298 | n02134418 sloth bear, Melursus ursinus, Ursus ursinus 299 | n02137549 mongoose 300 | n02138441 meerkat, mierkat 301 | n02165105 tiger beetle 302 | n02165456 ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle 303 | n02167151 ground beetle, carabid beetle 304 | n02168699 long-horned beetle, longicorn, longicorn beetle 305 | n02169497 leaf beetle, chrysomelid 306 | n02172182 dung beetle 307 | n02174001 rhinoceros beetle 308 | n02177972 weevil 309 | n02190166 fly 310 | n02206856 bee 311 | n02219486 ant, emmet, pismire 312 | n02226429 grasshopper, hopper 313 | n02229544 cricket 314 | n02231487 walking stick, walkingstick, stick insect 315 | n02233338 cockroach, roach 316 | n02236044 mantis, mantid 317 | n02256656 cicada, cicala 318 | n02259212 leafhopper 319 | n02264363 lacewing, lacewing fly 320 | n02268443 dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk 321 | n02268853 damselfly 322 | n02276258 admiral 323 | n02277742 ringlet, ringlet butterfly 324 | n02279972 monarch, monarch butterfly, milkweed butterfly, Danaus plexippus 325 | n02280649 cabbage butterfly 326 | n02281406 sulphur butterfly, sulfur butterfly 327 | n02281787 lycaenid, lycaenid butterfly 328 | n02317335 starfish, sea star 329 | n02319095 sea urchin 330 | n02321529 sea cucumber, holothurian 331 | n02325366 wood rabbit, cottontail, cottontail rabbit 332 | n02326432 hare 333 | n02328150 Angora, Angora rabbit 334 | n02342885 hamster 335 | n02346627 porcupine, hedgehog 336 | n02356798 fox squirrel, eastern fox squirrel, Sciurus niger 337 | n02361337 marmot 338 | n02363005 beaver 339 | n02364673 guinea pig, Cavia cobaya 340 | n02389026 sorrel 341 | n02391049 zebra 342 | n02395406 hog, pig, grunter, squealer, Sus scrofa 343 | n02396427 wild boar, boar, Sus scrofa 344 | n02397096 warthog 345 | n02398521 hippopotamus, hippo, river horse, Hippopotamus amphibius 346 | n02403003 ox 347 | n02408429 water buffalo, water ox, Asiatic buffalo, Bubalus bubalis 348 | n02410509 bison 349 | n02412080 ram, tup 350 | n02415577 bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis 351 | n02417914 ibex, Capra ibex 352 | n02422106 hartebeest 353 | n02422699 impala, Aepyceros melampus 354 | n02423022 gazelle 355 | n02437312 Arabian camel, dromedary, Camelus dromedarius 356 | n02437616 llama 357 | n02441942 weasel 358 | n02442845 mink 359 | n02443114 polecat, fitch, foulmart, foumart, Mustela putorius 360 | n02443484 black-footed ferret, ferret, Mustela nigripes 361 | n02444819 otter 362 | n02445715 skunk, polecat, wood pussy 363 | n02447366 badger 364 | n02454379 armadillo 365 | n02457408 three-toed sloth, ai, Bradypus tridactylus 366 | n02480495 orangutan, orang, orangutang, Pongo pygmaeus 367 | n02480855 gorilla, Gorilla gorilla 368 | n02481823 chimpanzee, chimp, Pan troglodytes 369 | n02483362 gibbon, Hylobates lar 370 | n02483708 siamang, Hylobates syndactylus, Symphalangus syndactylus 371 | n02484975 guenon, guenon monkey 372 | n02486261 patas, hussar monkey, Erythrocebus patas 373 | n02486410 baboon 374 | n02487347 macaque 375 | n02488291 langur 376 | n02488702 colobus, colobus monkey 377 | n02489166 proboscis monkey, Nasalis larvatus 378 | n02490219 marmoset 379 | n02492035 capuchin, ringtail, Cebus capucinus 380 | n02492660 howler monkey, howler 381 | n02493509 titi, titi monkey 382 | n02493793 spider monkey, Ateles geoffroyi 383 | n02494079 squirrel monkey, Saimiri sciureus 384 | n02497673 Madagascar cat, ring-tailed lemur, Lemur catta 385 | n02500267 indri, indris, Indri indri, Indri brevicaudatus 386 | n02504013 Indian elephant, Elephas maximus 387 | n02504458 African elephant, Loxodonta africana 388 | n02509815 lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens 389 | n02510455 giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca 390 | n02514041 barracouta, snoek 391 | n02526121 eel 392 | n02536864 coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch 393 | n02606052 rock beauty, Holocanthus tricolor 394 | n02607072 anemone fish 395 | n02640242 sturgeon 396 | n02641379 gar, garfish, garpike, billfish, Lepisosteus osseus 397 | n02643566 lionfish 398 | n02655020 puffer, pufferfish, blowfish, globefish 399 | n02666196 abacus 400 | n02667093 abaya 401 | n02669723 academic gown, academic robe, judge's robe 402 | n02672831 accordion, piano accordion, squeeze box 403 | n02676566 acoustic guitar 404 | n02687172 aircraft carrier, carrier, flattop, attack aircraft carrier 405 | n02690373 airliner 406 | n02692877 airship, dirigible 407 | n02699494 altar 408 | n02701002 ambulance 409 | n02704792 amphibian, amphibious vehicle 410 | n02708093 analog clock 411 | n02727426 apiary, bee house 412 | n02730930 apron 413 | n02747177 ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin 414 | n02749479 assault rifle, assault gun 415 | n02769748 backpack, back pack, knapsack, packsack, rucksack, haversack 416 | n02776631 bakery, bakeshop, bakehouse 417 | n02777292 balance beam, beam 418 | n02782093 balloon 419 | n02783161 ballpoint, ballpoint pen, ballpen, Biro 420 | n02786058 Band Aid 421 | n02787622 banjo 422 | n02788148 bannister, banister, balustrade, balusters, handrail 423 | n02790996 barbell 424 | n02791124 barber chair 425 | n02791270 barbershop 426 | n02793495 barn 427 | n02794156 barometer 428 | n02795169 barrel, cask 429 | n02797295 barrow, garden cart, lawn cart, wheelbarrow 430 | n02799071 baseball 431 | n02802426 basketball 432 | n02804414 bassinet 433 | n02804610 bassoon 434 | n02807133 bathing cap, swimming cap 435 | n02808304 bath towel 436 | n02808440 bathtub, bathing tub, bath, tub 437 | n02814533 beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon 438 | n02814860 beacon, lighthouse, beacon light, pharos 439 | n02815834 beaker 440 | n02817516 bearskin, busby, shako 441 | n02823428 beer bottle 442 | n02823750 beer glass 443 | n02825657 bell cote, bell cot 444 | n02834397 bib 445 | n02835271 bicycle-built-for-two, tandem bicycle, tandem 446 | n02837789 bikini, two-piece 447 | n02840245 binder, ring-binder 448 | n02841315 binoculars, field glasses, opera glasses 449 | n02843684 birdhouse 450 | n02859443 boathouse 451 | n02860847 bobsled, bobsleigh, bob 452 | n02865351 bolo tie, bolo, bola tie, bola 453 | n02869837 bonnet, poke bonnet 454 | n02870880 bookcase 455 | n02871525 bookshop, bookstore, bookstall 456 | n02877765 bottlecap 457 | n02879718 bow 458 | n02883205 bow tie, bow-tie, bowtie 459 | n02892201 brass, memorial tablet, plaque 460 | n02892767 brassiere, bra, bandeau 461 | n02894605 breakwater, groin, groyne, mole, bulwark, seawall, jetty 462 | n02895154 breastplate, aegis, egis 463 | n02906734 broom 464 | n02909870 bucket, pail 465 | n02910353 buckle 466 | n02916936 bulletproof vest 467 | n02917067 bullet train, bullet 468 | n02927161 butcher shop, meat market 469 | n02930766 cab, hack, taxi, taxicab 470 | n02939185 caldron, cauldron 471 | n02948072 candle, taper, wax light 472 | n02950826 cannon 473 | n02951358 canoe 474 | n02951585 can opener, tin opener 475 | n02963159 cardigan 476 | n02965783 car mirror 477 | n02966193 carousel, carrousel, merry-go-round, roundabout, whirligig 478 | n02966687 carpenter's kit, tool kit 479 | n02971356 carton 480 | n02974003 car wheel 481 | n02977058 cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM 482 | n02978881 cassette 483 | n02979186 cassette player 484 | n02980441 castle 485 | n02981792 catamaran 486 | n02988304 CD player 487 | n02992211 cello, violoncello 488 | n02992529 cellular telephone, cellular phone, cellphone, cell, mobile phone 489 | n02999410 chain 490 | n03000134 chainlink fence 491 | n03000247 chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour 492 | n03000684 chain saw, chainsaw 493 | n03014705 chest 494 | n03016953 chiffonier, commode 495 | n03017168 chime, bell, gong 496 | n03018349 china cabinet, china closet 497 | n03026506 Christmas stocking 498 | n03028079 church, church building 499 | n03032252 cinema, movie theater, movie theatre, movie house, picture palace 500 | n03041632 cleaver, meat cleaver, chopper 501 | n03042490 cliff dwelling 502 | n03045698 cloak 503 | n03047690 clog, geta, patten, sabot 504 | n03062245 cocktail shaker 505 | n03063599 coffee mug 506 | n03063689 coffeepot 507 | n03065424 coil, spiral, volute, whorl, helix 508 | n03075370 combination lock 509 | n03085013 computer keyboard, keypad 510 | n03089624 confectionery, confectionary, candy store 511 | n03095699 container ship, containership, container vessel 512 | n03100240 convertible 513 | n03109150 corkscrew, bottle screw 514 | n03110669 cornet, horn, trumpet, trump 515 | n03124043 cowboy boot 516 | n03124170 cowboy hat, ten-gallon hat 517 | n03125729 cradle 518 | n03126707 crane 519 | n03127747 crash helmet 520 | n03127925 crate 521 | n03131574 crib, cot 522 | n03133878 Crock Pot 523 | n03134739 croquet ball 524 | n03141823 crutch 525 | n03146219 cuirass 526 | n03160309 dam, dike, dyke 527 | n03179701 desk 528 | n03180011 desktop computer 529 | n03187595 dial telephone, dial phone 530 | n03188531 diaper, nappy, napkin 531 | n03196217 digital clock 532 | n03197337 digital watch 533 | n03201208 dining table, board 534 | n03207743 dishrag, dishcloth 535 | n03207941 dishwasher, dish washer, dishwashing machine 536 | n03208938 disk brake, disc brake 537 | n03216828 dock, dockage, docking facility 538 | n03218198 dogsled, dog sled, dog sleigh 539 | n03220513 dome 540 | n03223299 doormat, welcome mat 541 | n03240683 drilling platform, offshore rig 542 | n03249569 drum, membranophone, tympan 543 | n03250847 drumstick 544 | n03255030 dumbbell 545 | n03259280 Dutch oven 546 | n03271574 electric fan, blower 547 | n03272010 electric guitar 548 | n03272562 electric locomotive 549 | n03290653 entertainment center 550 | n03291819 envelope 551 | n03297495 espresso maker 552 | n03314780 face powder 553 | n03325584 feather boa, boa 554 | n03337140 file, file cabinet, filing cabinet 555 | n03344393 fireboat 556 | n03345487 fire engine, fire truck 557 | n03347037 fire screen, fireguard 558 | n03355925 flagpole, flagstaff 559 | n03372029 flute, transverse flute 560 | n03376595 folding chair 561 | n03379051 football helmet 562 | n03384352 forklift 563 | n03388043 fountain 564 | n03388183 fountain pen 565 | n03388549 four-poster 566 | n03393912 freight car 567 | n03394916 French horn, horn 568 | n03400231 frying pan, frypan, skillet 569 | n03404251 fur coat 570 | n03417042 garbage truck, dustcart 571 | n03424325 gasmask, respirator, gas helmet 572 | n03425413 gas pump, gasoline pump, petrol pump, island dispenser 573 | n03443371 goblet 574 | n03444034 go-kart 575 | n03445777 golf ball 576 | n03445924 golfcart, golf cart 577 | n03447447 gondola 578 | n03447721 gong, tam-tam 579 | n03450230 gown 580 | n03452741 grand piano, grand 581 | n03457902 greenhouse, nursery, glasshouse 582 | n03459775 grille, radiator grille 583 | n03461385 grocery store, grocery, food market, market 584 | n03467068 guillotine 585 | n03476684 hair slide 586 | n03476991 hair spray 587 | n03478589 half track 588 | n03481172 hammer 589 | n03482405 hamper 590 | n03483316 hand blower, blow dryer, blow drier, hair dryer, hair drier 591 | n03485407 hand-held computer, hand-held microcomputer 592 | n03485794 handkerchief, hankie, hanky, hankey 593 | n03492542 hard disc, hard disk, fixed disk 594 | n03494278 harmonica, mouth organ, harp, mouth harp 595 | n03495258 harp 596 | n03496892 harvester, reaper 597 | n03498962 hatchet 598 | n03527444 holster 599 | n03529860 home theater, home theatre 600 | n03530642 honeycomb 601 | n03532672 hook, claw 602 | n03534580 hoopskirt, crinoline 603 | n03535780 horizontal bar, high bar 604 | n03538406 horse cart, horse-cart 605 | n03544143 hourglass 606 | n03584254 iPod 607 | n03584829 iron, smoothing iron 608 | n03590841 jack-o'-lantern 609 | n03594734 jean, blue jean, denim 610 | n03594945 jeep, landrover 611 | n03595614 jersey, T-shirt, tee shirt 612 | n03598930 jigsaw puzzle 613 | n03599486 jinrikisha, ricksha, rickshaw 614 | n03602883 joystick 615 | n03617480 kimono 616 | n03623198 knee pad 617 | n03627232 knot 618 | n03630383 lab coat, laboratory coat 619 | n03633091 ladle 620 | n03637318 lampshade, lamp shade 621 | n03642806 laptop, laptop computer 622 | n03649909 lawn mower, mower 623 | n03657121 lens cap, lens cover 624 | n03658185 letter opener, paper knife, paperknife 625 | n03661043 library 626 | n03662601 lifeboat 627 | n03666591 lighter, light, igniter, ignitor 628 | n03670208 limousine, limo 629 | n03673027 liner, ocean liner 630 | n03676483 lipstick, lip rouge 631 | n03680355 Loafer 632 | n03690938 lotion 633 | n03691459 loudspeaker, speaker, speaker unit, loudspeaker system, speaker system 634 | n03692522 loupe, jeweler's loupe 635 | n03697007 lumbermill, sawmill 636 | n03706229 magnetic compass 637 | n03709823 mailbag, postbag 638 | n03710193 mailbox, letter box 639 | n03710637 maillot 640 | n03710721 maillot, tank suit 641 | n03717622 manhole cover 642 | n03720891 maraca 643 | n03721384 marimba, xylophone 644 | n03724870 mask 645 | n03729826 matchstick 646 | n03733131 maypole 647 | n03733281 maze, labyrinth 648 | n03733805 measuring cup 649 | n03742115 medicine chest, medicine cabinet 650 | n03743016 megalith, megalithic structure 651 | n03759954 microphone, mike 652 | n03761084 microwave, microwave oven 653 | n03763968 military uniform 654 | n03764736 milk can 655 | n03769881 minibus 656 | n03770439 miniskirt, mini 657 | n03770679 minivan 658 | n03773504 missile 659 | n03775071 mitten 660 | n03775546 mixing bowl 661 | n03776460 mobile home, manufactured home 662 | n03777568 Model T 663 | n03777754 modem 664 | n03781244 monastery 665 | n03782006 monitor 666 | n03785016 moped 667 | n03786901 mortar 668 | n03787032 mortarboard 669 | n03788195 mosque 670 | n03788365 mosquito net 671 | n03791053 motor scooter, scooter 672 | n03792782 mountain bike, all-terrain bike, off-roader 673 | n03792972 mountain tent 674 | n03793489 mouse, computer mouse 675 | n03794056 mousetrap 676 | n03796401 moving van 677 | n03803284 muzzle 678 | n03804744 nail 679 | n03814639 neck brace 680 | n03814906 necklace 681 | n03825788 nipple 682 | n03832673 notebook, notebook computer 683 | n03837869 obelisk 684 | n03838899 oboe, hautboy, hautbois 685 | n03840681 ocarina, sweet potato 686 | n03841143 odometer, hodometer, mileometer, milometer 687 | n03843555 oil filter 688 | n03854065 organ, pipe organ 689 | n03857828 oscilloscope, scope, cathode-ray oscilloscope, CRO 690 | n03866082 overskirt 691 | n03868242 oxcart 692 | n03868863 oxygen mask 693 | n03871628 packet 694 | n03873416 paddle, boat paddle 695 | n03874293 paddlewheel, paddle wheel 696 | n03874599 padlock 697 | n03876231 paintbrush 698 | n03877472 pajama, pyjama, pj's, jammies 699 | n03877845 palace 700 | n03884397 panpipe, pandean pipe, syrinx 701 | n03887697 paper towel 702 | n03888257 parachute, chute 703 | n03888605 parallel bars, bars 704 | n03891251 park bench 705 | n03891332 parking meter 706 | n03895866 passenger car, coach, carriage 707 | n03899768 patio, terrace 708 | n03902125 pay-phone, pay-station 709 | n03903868 pedestal, plinth, footstall 710 | n03908618 pencil box, pencil case 711 | n03908714 pencil sharpener 712 | n03916031 perfume, essence 713 | n03920288 Petri dish 714 | n03924679 photocopier 715 | n03929660 pick, plectrum, plectron 716 | n03929855 pickelhaube 717 | n03930313 picket fence, paling 718 | n03930630 pickup, pickup truck 719 | n03933933 pier 720 | n03935335 piggy bank, penny bank 721 | n03937543 pill bottle 722 | n03938244 pillow 723 | n03942813 ping-pong ball 724 | n03944341 pinwheel 725 | n03947888 pirate, pirate ship 726 | n03950228 pitcher, ewer 727 | n03954731 plane, carpenter's plane, woodworking plane 728 | n03956157 planetarium 729 | n03958227 plastic bag 730 | n03961711 plate rack 731 | n03967562 plow, plough 732 | n03970156 plunger, plumber's helper 733 | n03976467 Polaroid camera, Polaroid Land camera 734 | n03976657 pole 735 | n03977966 police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria 736 | n03980874 poncho 737 | n03982430 pool table, billiard table, snooker table 738 | n03983396 pop bottle, soda bottle 739 | n03991062 pot, flowerpot 740 | n03992509 potter's wheel 741 | n03995372 power drill 742 | n03998194 prayer rug, prayer mat 743 | n04004767 printer 744 | n04005630 prison, prison house 745 | n04008634 projectile, missile 746 | n04009552 projector 747 | n04019541 puck, hockey puck 748 | n04023962 punching bag, punch bag, punching ball, punchball 749 | n04026417 purse 750 | n04033901 quill, quill pen 751 | n04033995 quilt, comforter, comfort, puff 752 | n04037443 racer, race car, racing car 753 | n04039381 racket, racquet 754 | n04040759 radiator 755 | n04041544 radio, wireless 756 | n04044716 radio telescope, radio reflector 757 | n04049303 rain barrel 758 | n04065272 recreational vehicle, RV, R.V. 759 | n04067472 reel 760 | n04069434 reflex camera 761 | n04070727 refrigerator, icebox 762 | n04074963 remote control, remote 763 | n04081281 restaurant, eating house, eating place, eatery 764 | n04086273 revolver, six-gun, six-shooter 765 | n04090263 rifle 766 | n04099969 rocking chair, rocker 767 | n04111531 rotisserie 768 | n04116512 rubber eraser, rubber, pencil eraser 769 | n04118538 rugby ball 770 | n04118776 rule, ruler 771 | n04120489 running shoe 772 | n04125021 safe 773 | n04127249 safety pin 774 | n04131690 saltshaker, salt shaker 775 | n04133789 sandal 776 | n04136333 sarong 777 | n04141076 sax, saxophone 778 | n04141327 scabbard 779 | n04141975 scale, weighing machine 780 | n04146614 school bus 781 | n04147183 schooner 782 | n04149813 scoreboard 783 | n04152593 screen, CRT screen 784 | n04153751 screw 785 | n04154565 screwdriver 786 | n04162706 seat belt, seatbelt 787 | n04179913 sewing machine 788 | n04192698 shield, buckler 789 | n04200800 shoe shop, shoe-shop, shoe store 790 | n04201297 shoji 791 | n04204238 shopping basket 792 | n04204347 shopping cart 793 | n04208210 shovel 794 | n04209133 shower cap 795 | n04209239 shower curtain 796 | n04228054 ski 797 | n04229816 ski mask 798 | n04235860 sleeping bag 799 | n04238763 slide rule, slipstick 800 | n04239074 sliding door 801 | n04243546 slot, one-armed bandit 802 | n04251144 snorkel 803 | n04252077 snowmobile 804 | n04252225 snowplow, snowplough 805 | n04254120 soap dispenser 806 | n04254680 soccer ball 807 | n04254777 sock 808 | n04258138 solar dish, solar collector, solar furnace 809 | n04259630 sombrero 810 | n04263257 soup bowl 811 | n04264628 space bar 812 | n04265275 space heater 813 | n04266014 space shuttle 814 | n04270147 spatula 815 | n04273569 speedboat 816 | n04275548 spider web, spider's web 817 | n04277352 spindle 818 | n04285008 sports car, sport car 819 | n04286575 spotlight, spot 820 | n04296562 stage 821 | n04310018 steam locomotive 822 | n04311004 steel arch bridge 823 | n04311174 steel drum 824 | n04317175 stethoscope 825 | n04325704 stole 826 | n04326547 stone wall 827 | n04328186 stopwatch, stop watch 828 | n04330267 stove 829 | n04332243 strainer 830 | n04335435 streetcar, tram, tramcar, trolley, trolley car 831 | n04336792 stretcher 832 | n04344873 studio couch, day bed 833 | n04346328 stupa, tope 834 | n04347754 submarine, pigboat, sub, U-boat 835 | n04350905 suit, suit of clothes 836 | n04355338 sundial 837 | n04355933 sunglass 838 | n04356056 sunglasses, dark glasses, shades 839 | n04357314 sunscreen, sunblock, sun blocker 840 | n04366367 suspension bridge 841 | n04367480 swab, swob, mop 842 | n04370456 sweatshirt 843 | n04371430 swimming trunks, bathing trunks 844 | n04371774 swing 845 | n04372370 switch, electric switch, electrical switch 846 | n04376876 syringe 847 | n04380533 table lamp 848 | n04389033 tank, army tank, armored combat vehicle, armoured combat vehicle 849 | n04392985 tape player 850 | n04398044 teapot 851 | n04399382 teddy, teddy bear 852 | n04404412 television, television system 853 | n04409515 tennis ball 854 | n04417672 thatch, thatched roof 855 | n04418357 theater curtain, theatre curtain 856 | n04423845 thimble 857 | n04428191 thresher, thrasher, threshing machine 858 | n04429376 throne 859 | n04435653 tile roof 860 | n04442312 toaster 861 | n04443257 tobacco shop, tobacconist shop, tobacconist 862 | n04447861 toilet seat 863 | n04456115 torch 864 | n04458633 totem pole 865 | n04461696 tow truck, tow car, wrecker 866 | n04462240 toyshop 867 | n04465501 tractor 868 | n04467665 trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi 869 | n04476259 tray 870 | n04479046 trench coat 871 | n04482393 tricycle, trike, velocipede 872 | n04483307 trimaran 873 | n04485082 tripod 874 | n04486054 triumphal arch 875 | n04487081 trolleybus, trolley coach, trackless trolley 876 | n04487394 trombone 877 | n04493381 tub, vat 878 | n04501370 turnstile 879 | n04505470 typewriter keyboard 880 | n04507155 umbrella 881 | n04509417 unicycle, monocycle 882 | n04515003 upright, upright piano 883 | n04517823 vacuum, vacuum cleaner 884 | n04522168 vase 885 | n04523525 vault 886 | n04525038 velvet 887 | n04525305 vending machine 888 | n04532106 vestment 889 | n04532670 viaduct 890 | n04536866 violin, fiddle 891 | n04540053 volleyball 892 | n04542943 waffle iron 893 | n04548280 wall clock 894 | n04548362 wallet, billfold, notecase, pocketbook 895 | n04550184 wardrobe, closet, press 896 | n04552348 warplane, military plane 897 | n04553703 washbasin, handbasin, washbowl, lavabo, wash-hand basin 898 | n04554684 washer, automatic washer, washing machine 899 | n04557648 water bottle 900 | n04560804 water jug 901 | n04562935 water tower 902 | n04579145 whiskey jug 903 | n04579432 whistle 904 | n04584207 wig 905 | n04589890 window screen 906 | n04590129 window shade 907 | n04591157 Windsor tie 908 | n04591713 wine bottle 909 | n04592741 wing 910 | n04596742 wok 911 | n04597913 wooden spoon 912 | n04599235 wool, woolen, woollen 913 | n04604644 worm fence, snake fence, snake-rail fence, Virginia fence 914 | n04606251 wreck 915 | n04612504 yawl 916 | n04613696 yurt 917 | n06359193 web site, website, internet site, site 918 | n06596364 comic book 919 | n06785654 crossword puzzle, crossword 920 | n06794110 street sign 921 | n06874185 traffic light, traffic signal, stoplight 922 | n07248320 book jacket, dust cover, dust jacket, dust wrapper 923 | n07565083 menu 924 | n07579787 plate 925 | n07583066 guacamole 926 | n07584110 consomme 927 | n07590611 hot pot, hotpot 928 | n07613480 trifle 929 | n07614500 ice cream, icecream 930 | n07615774 ice lolly, lolly, lollipop, popsicle 931 | n07684084 French loaf 932 | n07693725 bagel, beigel 933 | n07695742 pretzel 934 | n07697313 cheeseburger 935 | n07697537 hotdog, hot dog, red hot 936 | n07711569 mashed potato 937 | n07714571 head cabbage 938 | n07714990 broccoli 939 | n07715103 cauliflower 940 | n07716358 zucchini, courgette 941 | n07716906 spaghetti squash 942 | n07717410 acorn squash 943 | n07717556 butternut squash 944 | n07718472 cucumber, cuke 945 | n07718747 artichoke, globe artichoke 946 | n07720875 bell pepper 947 | n07730033 cardoon 948 | n07734744 mushroom 949 | n07742313 Granny Smith 950 | n07745940 strawberry 951 | n07747607 orange 952 | n07749582 lemon 953 | n07753113 fig 954 | n07753275 pineapple, ananas 955 | n07753592 banana 956 | n07754684 jackfruit, jak, jack 957 | n07760859 custard apple 958 | n07768694 pomegranate 959 | n07802026 hay 960 | n07831146 carbonara 961 | n07836838 chocolate sauce, chocolate syrup 962 | n07860988 dough 963 | n07871810 meat loaf, meatloaf 964 | n07873807 pizza, pizza pie 965 | n07875152 potpie 966 | n07880968 burrito 967 | n07892512 red wine 968 | n07920052 espresso 969 | n07930864 cup 970 | n07932039 eggnog 971 | n09193705 alp 972 | n09229709 bubble 973 | n09246464 cliff, drop, drop-off 974 | n09256479 coral reef 975 | n09288635 geyser 976 | n09332890 lakeside, lakeshore 977 | n09399592 promontory, headland, head, foreland 978 | n09421951 sandbar, sand bar 979 | n09428293 seashore, coast, seacoast, sea-coast 980 | n09468604 valley, vale 981 | n09472597 volcano 982 | n09835506 ballplayer, baseball player 983 | n10148035 groom, bridegroom 984 | n10565667 scuba diver 985 | n11879895 rapeseed 986 | n11939491 daisy 987 | n12057211 yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum 988 | n12144580 corn 989 | n12267677 acorn 990 | n12620546 hip, rose hip, rosehip 991 | n12768682 buckeye, horse chestnut, conker 992 | n12985857 coral fungus 993 | n12998815 agaric 994 | n13037406 gyromitra 995 | n13040303 stinkhorn, carrion fungus 996 | n13044778 earthstar 997 | n13052670 hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa 998 | n13054560 bolete 999 | n13133613 ear, spike, capitulum 1000 | n15075141 toilet tissue, toilet paper, bathroom tissue 1001 | -------------------------------------------------------------------------------- /misc/layers.py: -------------------------------------------------------------------------------- 1 | ''' 2 | wrapper functions for tensorflow layers 3 | ''' 4 | import tensorflow as tf 5 | 6 | def conv_layer(bottom, weight, bias=None, s=1, padding='SAME', relu=True, group=1): 7 | if group==1: 8 | conv = tf.nn.conv2d(bottom, weight, [1, s, s, 1], padding=padding) 9 | else: 10 | input_split = tf.split(bottom, group, 3) 11 | weight_split = tf.split(weight, group, 3) 12 | conv_1 = tf.nn.conv2d(input_split[0], weight_split[0], [1, s, s, 1], padding=padding) 13 | conv_2 = tf.nn.conv2d(input_split[1], weight_split[1], [1, s, s, 1], padding=padding) 14 | conv = tf.concat([conv_1, conv_2], 3) 15 | if bias is None: 16 | if relu: 17 | return tf.nn.relu(conv) 18 | else: 19 | return conv 20 | else: 21 | bias = tf.nn.bias_add(conv, bias) 22 | if relu: 23 | return tf.nn.relu(bias) 24 | else: 25 | return bias 26 | 27 | def max_pool(bottom, k=3, s=1, padding='SAME'): 28 | return tf.nn.max_pool(bottom, ksize=[1, k, k, 1], strides=[1, s, s, 1], padding=padding) 29 | 30 | def avg_pool(bottom, k=3, s=1, padding='SAME'): 31 | return tf.nn.avg_pool(bottom, ksize=[1, k, k, 1], strides=[1, s, s, 1], padding=padding) 32 | 33 | def fully_connected(bottom, weight, bias): 34 | fc = tf.nn.bias_add(tf.matmul(bottom, weight), bias) 35 | return fc 36 | 37 | def batch_norm(bottom, weight, relu=True): 38 | bn = tf.nn.batch_normalization(bottom, weight['mean'], weight['variance'], weight['offset'], weight['scale'], 1e-5) 39 | if relu: 40 | return tf.nn.relu(bn) 41 | else: 42 | return bn 43 | 44 | def inception_block(bottom, name, weights, biases): 45 | with tf.name_scope(name+'1x1'): 46 | branch_1 = conv_layer(bottom, weights['inception_'+name+'_1x1'], biases['inception_'+name+'_1x1']) 47 | 48 | with tf.name_scope(name+'3x3'): 49 | branch_2 = conv_layer(bottom, weights['inception_'+name+'_3x3_reduce'], biases['inception_'+name+'_3x3_reduce']) 50 | branch_2 = conv_layer(branch_2, weights['inception_'+name+'_3x3'], biases['inception_'+name+'_3x3']) 51 | 52 | with tf.name_scope(name+'5x5'): 53 | branch_3 = conv_layer(bottom, weights['inception_'+name+'_5x5_reduce'], biases['inception_'+name+'_5x5_reduce']) 54 | branch_3 = conv_layer(branch_3, weights['inception_'+name+'_5x5'], biases['inception_'+name+'_5x5']) 55 | 56 | with tf.name_scope(name+'pool'): 57 | branch_4 = max_pool(bottom) 58 | branch_4 = conv_layer(branch_4, weights['inception_'+name+'_pool_proj'], biases['inception_'+name+'_pool_proj']) 59 | 60 | return tf.concat(axis=3, values=[branch_1, branch_2, branch_3, branch_4]) 61 | 62 | def inception_a(bottom, name, weights, index): 63 | block = {} 64 | with tf.name_scope(name+'1x1'): 65 | block['branch_1'] = conv_layer(bottom, weights['conv2d_'+str(index)], relu=False) 66 | block['branch_1'] = batch_norm(block['branch_1'], weights['batch_normalization_'+str(index)]) 67 | with tf.name_scope(name+'5x5'): 68 | block['branch_2'] = conv_layer(bottom, weights['conv2d_'+str(index+1)], relu=False) 69 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+1)]) 70 | block['branch_2'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+2)], relu=False) 71 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+2)]) 72 | with tf.name_scope(name+'5x5'): 73 | block['branch_3'] = conv_layer(bottom, weights['conv2d_'+str(index+3)], relu=False) 74 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+3)]) 75 | block['branch_3'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+4)], relu=False) 76 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+4)]) 77 | block['branch_3'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+5)], relu=False) 78 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+5)]) 79 | with tf.name_scope(name+'pool'): 80 | block['branch_4'] = avg_pool(bottom) 81 | block['branch_4'] = conv_layer(block['branch_4'], weights['conv2d_'+str(index+6)], relu=False) 82 | block['branch_4'] = batch_norm(block['branch_4'], weights['batch_normalization_'+str(index+6)]) 83 | block['concat'] = tf.concat(axis=3, values=[block['branch_1'], block['branch_2'], block['branch_3'], block['branch_4']]) 84 | return block 85 | 86 | def inception_b(bottom, name, weights, index): 87 | block = {} 88 | with tf.name_scope(name+'1'): 89 | block['branch_1'] = conv_layer(bottom, weights['conv2d_'+str(index)], s=2, padding='VALID', relu=False) 90 | block['branch_1'] = batch_norm(block['branch_1'], weights['batch_normalization_'+str(index)]) 91 | with tf.name_scope(name+'2'): 92 | block['branch_2'] = conv_layer(bottom, weights['conv2d_'+str(index+1)], relu=False) 93 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+1)]) 94 | block['branch_2'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+2)], relu=False) 95 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+2)]) 96 | block['branch_2'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+3)], s=2, padding='VALID', relu=False) 97 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+3)]) 98 | with tf.name_scope(name+'pool'): 99 | block['branch_3'] = max_pool(bottom, s=2, padding='VALID') 100 | block['concat'] = tf.concat(axis=3, values=[block['branch_1'], block['branch_2'], block['branch_3']]) 101 | return block 102 | 103 | def inception_c(bottom, name, weights, index): 104 | block = {} 105 | with tf.name_scope(name+'1'): 106 | block['branch_1'] = conv_layer(bottom, weights['conv2d_'+str(index)], relu=False) 107 | block['branch_1'] = batch_norm(block['branch_1'], weights['batch_normalization_'+str(index)]) 108 | with tf.name_scope(name+'2'): 109 | block['branch_2'] = conv_layer(bottom, weights['conv2d_'+str(index+1)], relu=False) 110 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+1)]) 111 | block['branch_2'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+2)], relu=False) 112 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+2)]) 113 | block['branch_2'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+3)], relu=False) 114 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+3)]) 115 | with tf.name_scope(name+'3'): 116 | block['branch_3'] = conv_layer(bottom, weights['conv2d_'+str(index+4)], relu=False) 117 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+4)]) 118 | block['branch_3'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+5)], relu=False) 119 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+5)]) 120 | block['branch_3'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+6)], relu=False) 121 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+6)]) 122 | block['branch_3'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+7)], relu=False) 123 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+7)]) 124 | block['branch_3'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+8)], relu=False) 125 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+8)]) 126 | with tf.name_scope(name+'pool'): 127 | block['branch_4'] = avg_pool(bottom) 128 | block['branch_4'] = conv_layer(block['branch_4'], weights['conv2d_'+str(index+9)], relu=False) 129 | block['branch_4'] = batch_norm(block['branch_4'], weights['batch_normalization_'+str(index+9)]) 130 | block['concat'] = tf.concat(axis=3, values=[block['branch_1'], block['branch_2'], block['branch_3'], block['branch_4']]) 131 | return block 132 | 133 | def inception_d(bottom, name, weights, index): 134 | block = {} 135 | with tf.name_scope(name+'1'): 136 | block['branch_1'] = conv_layer(bottom, weights['conv2d_'+str(index)], relu=False) 137 | block['branch_1'] = batch_norm(block['branch_1'], weights['batch_normalization_'+str(index)]) 138 | block['branch_1'] = conv_layer(block['branch_1'], weights['conv2d_'+str(index+1)], s=2, padding='VALID', relu=False) 139 | block['branch_1'] = batch_norm(block['branch_1'], weights['batch_normalization_'+str(index+1)]) 140 | with tf.name_scope(name+'2'): 141 | block['branch_2'] = conv_layer(bottom, weights['conv2d_'+str(index+2)], relu=False) 142 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+2)]) 143 | block['branch_2'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+3)], relu=False) 144 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+3)]) 145 | block['branch_2'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+4)], relu=False) 146 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+4)]) 147 | block['branch_2'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+5)], s=2, padding='VALID', relu=False) 148 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+5)]) 149 | with tf.name_scope(name+'pool'): 150 | block['branch_3'] = max_pool(bottom, s=2, padding='VALID') 151 | block['concat'] = tf.concat(axis=3, values=[block['branch_1'], block['branch_2'], block['branch_3']]) 152 | return block 153 | 154 | def inception_e(bottom, name, weights, index): 155 | block = {} 156 | with tf.name_scope(name+'1'): 157 | block['branch_1'] = conv_layer(bottom, weights['conv2d_'+str(index)], relu=False) 158 | block['branch_1'] = batch_norm(block['branch_1'], weights['batch_normalization_'+str(index)]) 159 | with tf.name_scope(name+'2'): 160 | block['branch_2'] = conv_layer(bottom, weights['conv2d_'+str(index+1)], relu=False) 161 | block['branch_2'] = batch_norm(block['branch_2'], weights['batch_normalization_'+str(index+1)]) 162 | block['branch_2a'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+2)], relu=False) 163 | block['branch_2a'] = batch_norm(block['branch_2a'], weights['batch_normalization_'+str(index+2)]) 164 | block['branch_2b'] = conv_layer(block['branch_2'], weights['conv2d_'+str(index+3)], relu=False) 165 | block['branch_2b'] = batch_norm(block['branch_2b'], weights['batch_normalization_'+str(index+3)]) 166 | block['branch_2'] = tf.concat(axis=3, values=[block['branch_2a'],block['branch_2b']]) 167 | with tf.name_scope(name+'3'): 168 | block['branch_3'] = conv_layer(bottom, weights['conv2d_'+str(index+4)], relu=False) 169 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+4)]) 170 | block['branch_3'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+5)], relu=False) 171 | block['branch_3'] = batch_norm(block['branch_3'], weights['batch_normalization_'+str(index+5)]) 172 | block['branch_3a'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+6)], relu=False) 173 | block['branch_3a'] = batch_norm(block['branch_3a'], weights['batch_normalization_'+str(index+6)]) 174 | block['branch_3b'] = conv_layer(block['branch_3'], weights['conv2d_'+str(index+7)], relu=False) 175 | block['branch_3b'] = batch_norm(block['branch_3b'], weights['batch_normalization_'+str(index+7)]) 176 | block['branch_3'] = tf.concat(axis=3, values=[block['branch_3a'],block['branch_3b']]) 177 | with tf.name_scope(name+'pool'): 178 | block['branch_4'] = avg_pool(bottom) 179 | block['branch_4'] = conv_layer(block['branch_4'], weights['conv2d_'+str(index+8)], relu=False) 180 | block['branch_4'] = batch_norm(block['branch_4'], weights['batch_normalization_'+str(index+8)]) 181 | block['concat'] = tf.concat(axis=3, values=[block['branch_1'], block['branch_2'], block['branch_3'], block['branch_4']]) 182 | return block 183 | 184 | 185 | def res_block(bottom, name, weights, stride=1, first=False): 186 | with tf.name_scope(name+'_a'): 187 | c1 = conv_layer(bottom, weights['res'+name+'_branch2a']['weights'], s=stride, relu=False) 188 | bn1 = batch_norm(c1, weights['bn'+name+'_branch2a']) 189 | 190 | with tf.name_scope(name+'_b'): 191 | c2 = conv_layer(bn1, weights['res'+name+'_branch2b']['weights'], relu=False) 192 | bn2 = batch_norm(c2, weights['bn'+name+'_branch2b']) 193 | 194 | with tf.name_scope(name+'_c'): 195 | c3 = conv_layer(bn2, weights['res'+name+'_branch2c']['weights'], relu=False) 196 | bn3 = batch_norm(c3, weights['bn'+name+'_branch2c'], relu=False) 197 | 198 | if first: 199 | with tf.name_scope(name+'_1'): 200 | c4 = conv_layer(bottom, weights['res'+name+'_branch1']['weights'], s=stride, relu=False) 201 | bn4 = batch_norm(c4, weights['bn'+name+'_branch1'], relu=False) 202 | return tf.nn.relu(tf.add(bn4,bn3)) 203 | else: 204 | return tf.nn.relu(tf.add(bottom,bn3)) 205 | -------------------------------------------------------------------------------- /misc/sample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utsavgarg/tensorflow-classification/ea2ca5fbe01bd6dcba709cd1a1af4dd0bbefb0ff/misc/sample.jpg -------------------------------------------------------------------------------- /misc/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from skimage.io import imread 3 | from skimage.transform import resize 4 | import tensorflow as tf 5 | # util layers 6 | 7 | # Obselete 8 | def old_img_preprocess(img_path, size=224): 9 | mean = [103.939, 116.779, 123.68] 10 | img = imread(img_path) 11 | img = resize(img, (size, size))*255.0 12 | if len(img.shape) == 2: 13 | img = np.dstack([img,img,img]) 14 | img[:,:,0] -= mean[2] 15 | img[:,:,1] -= mean[1] 16 | img[:,:,2] -= mean[0] 17 | img[:,:,[0,1,2]] = img[:,:,[2,1,0]] 18 | img = np.reshape(img,[1,size,size,3]) 19 | return img 20 | # Preprocessing for Inception V3 21 | def v3_preprocess(img_path): 22 | img = imread(img_path) 23 | img = resize(img, (299, 299), preserve_range=True) 24 | img = (img - 128) / 128 25 | if len(img.shape) == 2: 26 | img = np.dstack([img,img,img]) 27 | img = np.reshape(img,[1,299,299,3]) 28 | return img 29 | 30 | # Image preprocessing format 31 | # Fog VGG models. 32 | def vgg_preprocess(img_path, size=224): 33 | mean = [103.939, 116.779, 123.68] 34 | img = imread(img_path) 35 | if len(img.shape) == 2: 36 | img = np.dstack([img,img,img]) 37 | resFac = 256.0/min(img.shape[:2]) 38 | newSize = list(map(int, (img.shape[0]*resFac, img.shape[1]*resFac))) 39 | img = resize(img, newSize, mode='constant', preserve_range=True) 40 | offset = [newSize[0]/2.0-np.floor(size/2.0), newSize[1]/2.0-np.floor(size/2.0)] 41 | # print(offset,size) 42 | img = img[int(offset[0]):int(offset[0])+size, int(offset[1]):int(offset[1])+size, :] 43 | img[:,:,0] -= mean[2] 44 | img[:,:,1] -= mean[1] 45 | img[:,:,2] -= mean[0] 46 | img[:,:,[0,1,2]] = img[:,:,[2,1,0]] 47 | img = np.reshape(img,[1,size,size,3]) 48 | return img 49 | 50 | # For Resnets,Caffenet and Googlenet 51 | # From Caffe-tensorflow 52 | def img_preprocess(img, scale=256, isotropic=False, crop=227, mean=np.array([103.939, 116.779, 123.68])): 53 | '''Crops, scales, and normalizes the given image. 54 | scale : The image wil be first scaled to this size. 55 | If isotropic is true, the smaller side is rescaled to this, 56 | preserving the aspect ratio. 57 | crop : After scaling, a central crop of this size is taken. 58 | mean : Subtracted from the image 59 | ''' 60 | # Rescale 61 | if isotropic: 62 | img_shape = tf.to_float(tf.shape(img)[:2]) 63 | min_length = tf.minimum(img_shape[0], img_shape[1]) 64 | new_shape = tf.to_int32((scale / min_length) * img_shape) 65 | else: 66 | new_shape = tf.stack([scale, scale]) 67 | img = tf.image.resize_images(img, new_shape) 68 | # Center crop 69 | # Use the slice workaround until crop_to_bounding_box supports deferred tensor shapes 70 | # See: https://github.com/tensorflow/tensorflow/issues/521 71 | offset = (new_shape - crop) / 2 72 | img = tf.slice(img, begin=tf.stack([offset[0], offset[1], 0]), size=tf.stack([crop, crop, -1])) 73 | # Mean subtraction 74 | return tf.to_float(img) - mean 75 | 76 | def load_image(): 77 | # Read the file 78 | image_path = tf.placeholder(tf.string,None) 79 | file_data = tf.read_file(image_path) 80 | # Decode the image data 81 | img = tf.image.decode_jpeg(file_data, channels=3) 82 | img = tf.reverse(img, [-1]) 83 | return img,image_path 84 | 85 | def loader_func(network_name,sess,isotropic,size): 86 | if network_name == 'inceptionv3': 87 | def loader(image_name): 88 | im = v3_preprocess(image_name) 89 | return im 90 | elif 'vgg' in network_name: 91 | def loader(image_name): 92 | im = vgg_preprocess(image_name) 93 | return im 94 | else: 95 | img_tensor,image_path_tensor = load_image() 96 | processed_img = img_preprocess(img=img_tensor,isotropic=isotropic,crop=size) 97 | def loader(image_name,processed_img=processed_img,image_path_tensor=image_path_tensor,sess=sess): 98 | im = sess.run([processed_img],feed_dict={image_path_tensor:image_name}) 99 | return im 100 | return loader 101 | 102 | def get_params(net_name): 103 | isotropic = False 104 | if net_name =='caffenet': 105 | size = 227 106 | elif net_name=='inceptionv3': 107 | size = 299 108 | else: 109 | size = 224 110 | if not net_name == 'googlenet': 111 | isotropic = True 112 | return isotropic,size 113 | -------------------------------------------------------------------------------- /nets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utsavgarg/tensorflow-classification/ea2ca5fbe01bd6dcba709cd1a1af4dd0bbefb0ff/nets/__init__.py -------------------------------------------------------------------------------- /nets/caffenet.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from misc.layers import * 3 | import numpy as np 4 | 5 | def model(image, weights, biases, keep_prob=1.0): 6 | #check image dimensions 7 | assert image.get_shape().as_list()[1:] == [227, 227, 3] 8 | layers = {} 9 | with tf.name_scope("conv1"): 10 | layers['conv1'] = conv_layer(image, weights['conv1'], biases['conv1'], s=4, padding='VALID') 11 | layers['pool1'] = max_pool(layers['conv1'], k=3, s=2, padding='VALID') 12 | layers['norm1'] = tf.nn.lrn(layers['pool1'],2,1.0,2e-05,0.75) 13 | 14 | with tf.name_scope("conv2"): 15 | layers['conv2'] = conv_layer(layers['norm1'], weights['conv2'], biases['conv2'], group=2) 16 | layers['pool2'] = max_pool(layers['conv2'], k=3, s=2, padding='VALID') 17 | layers['norm2'] = tf.nn.lrn(layers['pool2'],2,1.0,2e-05,0.75) 18 | 19 | with tf.name_scope("conv3"): 20 | layers['conv3'] = conv_layer(layers['norm2'], weights['conv3'], biases['conv3']) 21 | 22 | with tf.name_scope("conv4"): 23 | layers['conv4'] = conv_layer(layers['conv3'], weights['conv4'], biases['conv4'], group=2) 24 | 25 | with tf.name_scope("conv5"): 26 | layers['conv5'] = conv_layer(layers['conv4'], weights['conv5'], biases['conv5'], group=2) 27 | layers['pool5'] = max_pool(layers['conv5'], k=3, s=2, padding='VALID') 28 | 29 | flatten = tf.reshape(layers['pool5'], [-1, 9216]) 30 | 31 | with tf.name_scope('fc6'): 32 | layers['fc6'] = tf.nn.relu(fully_connected(flatten, weights['fc6'], biases['fc6'])) 33 | layers['fc6'] = tf.nn.dropout(layers['fc6'], keep_prob=keep_prob) 34 | 35 | with tf.name_scope('fc7'): 36 | layers['fc7'] = tf.nn.relu(fully_connected(layers['fc6'], weights['fc7'], biases['fc7'])) 37 | layers['fc7'] = tf.nn.dropout(layers['fc7'], keep_prob=keep_prob) 38 | 39 | with tf.name_scope('fc8'): 40 | layers['fc8'] = fully_connected(layers['fc7'], weights['fc8'], biases['fc8']) 41 | layers['prob'] = tf.nn.softmax(layers['fc8']) 42 | 43 | return layers 44 | 45 | def caffenet(input): 46 | 47 | #weigths and biases for tensorflow 48 | net = np.load('weights/caffenet.npy').item() 49 | weights = {} 50 | biases = {} 51 | for name in net.keys(): 52 | weights[name] = tf.Variable(tf.constant(net[name]['weights']), dtype='float32' ,name=name+"_weight", trainable=False) 53 | biases[name] = tf.Variable(tf.constant(net[name]['biases']), dtype='float32' ,name=name+"_bias", trainable=False) 54 | 55 | return model(input, weights, biases) 56 | -------------------------------------------------------------------------------- /nets/googlenet.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from misc.layers import * 3 | import numpy as np 4 | 5 | def model(image, weights, biases): 6 | #check image dimensions 7 | assert image.get_shape().as_list()[1:] == [224, 224, 3] 8 | layers = {} 9 | with tf.name_scope("conv1"): 10 | layers['conv1_7x7_s2'] = conv_layer(image, weights['conv1_7x7_s2'], biases['conv1_7x7_s2'], s=2) 11 | layers['pool1_3x3_s2'] = max_pool(layers['conv1_7x7_s2'], k=3, s=2) 12 | layers['pool1_norm1'] = tf.nn.lrn(layers['pool1_3x3_s2'], 2, 1.0, 2e-05, 0.75) 13 | 14 | with tf.name_scope("conv2"): 15 | layers['conv2_3x3_reduce'] = conv_layer(layers['pool1_norm1'], weights['conv2_3x3_reduce'], biases['conv2_3x3_reduce']) 16 | layers['conv2_3x3'] = conv_layer(layers['conv2_3x3_reduce'], weights['conv2_3x3'], biases['conv2_3x3']) 17 | layers['conv2_norm2'] = tf.nn.lrn(layers['conv2_3x3'], 2, 1.0, 2e-05, 0.75) 18 | layers['pool2_3x3_s2'] = max_pool(layers['conv2_norm2'], k=3, s=2) 19 | 20 | with tf.name_scope('inception_3'): 21 | layers['inception_3a_output'] = inception_block(layers['pool2_3x3_s2'], '3a', weights, biases) 22 | layers['inception_3b_output'] = inception_block(layers['inception_3a_output'], '3b', weights, biases) 23 | layers['pool3_3x3_s2'] = max_pool(layers['inception_3b_output'], k=3, s=2) 24 | 25 | with tf.name_scope('inception_4'): 26 | layers['inception_4a_output'] = inception_block(layers['pool3_3x3_s2'], '4a', weights, biases) 27 | layers['inception_4b_output'] = inception_block(layers['inception_4a_output'], '4b', weights, biases) 28 | layers['inception_4c_output'] = inception_block(layers['inception_4b_output'], '4c', weights, biases) 29 | layers['inception_4d_output'] = inception_block(layers['inception_4c_output'], '4d', weights, biases) 30 | layers['inception_4e_output'] = inception_block(layers['inception_4d_output'], '4e', weights, biases) 31 | layers['pool4_3x3_s2'] = max_pool(layers['inception_4e_output'], k=3, s=2) 32 | 33 | with tf.name_scope('inception_5'): 34 | layers['inception_5a_output'] = inception_block(layers['pool4_3x3_s2'], '5a', weights, biases) 35 | layers['inception_5b_output'] = inception_block(layers['inception_5a_output'], '5b', weights, biases) 36 | layers['pool5_7x7_s1'] = tf.nn.avg_pool(layers['inception_5b_output'], [1,7,7,1], [1,1,1,1], padding='VALID') 37 | layers['pool5_7x7_s1'] = tf.reshape(layers['pool5_7x7_s1'], [-1,1024]) 38 | 39 | with tf.name_scope('fc'): 40 | layers['loss3_classifier'] = fully_connected(layers['pool5_7x7_s1'], weights['loss3_classifier'], biases['loss3_classifier']) 41 | layers['prob'] = tf.nn.softmax(layers['loss3_classifier']) 42 | 43 | return layers 44 | 45 | def googlenet(input): 46 | 47 | #weigths and biases for tensorflow 48 | net = np.load('weights/googlenet.npy').item() 49 | weights = {} 50 | biases = {} 51 | for name in net.keys(): 52 | weights[name] = tf.Variable(tf.constant(net[name]['weights']), dtype='float32' ,name=name+'_weights', trainable=False) 53 | biases[name] = tf.Variable(tf.constant(net[name]['biases']), dtype='float32' ,name=name+'_biases', trainable=False) 54 | 55 | return model(input, weights, biases) 56 | -------------------------------------------------------------------------------- /nets/inception_v3.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from misc.layers import * 3 | import numpy as np 4 | import h5py 5 | 6 | def model(input, weights): 7 | layers = {} 8 | layers['conv1'] = conv_layer(input, weights['conv2d_1'], s=2, padding='VALID', relu=False) 9 | layers['bn1'] = batch_norm(layers['conv1'], weights['batch_normalization_1']) 10 | layers['conv2'] = conv_layer(layers['bn1'], weights['conv2d_2'], padding='VALID', relu=False) 11 | layers['bn2'] = batch_norm(layers['conv2'], weights['batch_normalization_2']) 12 | layers['conv3'] = conv_layer(layers['bn2'], weights['conv2d_3'], relu=False) 13 | layers['bn3'] = batch_norm(layers['conv3'], weights['batch_normalization_3']) 14 | layers['pool1'] = max_pool(layers['bn3'], k=3, s=2) 15 | 16 | layers['conv4'] = conv_layer(layers['pool1'], weights['conv2d_4'], padding='VALID', relu=False) 17 | layers['bn4'] = batch_norm(layers['conv4'], weights['batch_normalization_4']) 18 | layers['conv5'] = conv_layer(layers['bn4'], weights['conv2d_5'], padding='VALID', relu=False) 19 | layers['bn5'] = batch_norm(layers['conv5'], weights['batch_normalization_5']) 20 | layers['pool2'] = max_pool(layers['bn5'], k=3, s=2) 21 | 22 | layers['mixed5b'] = inception_a(layers['pool2'], 'mixed5b', weights, 6) 23 | layers['mixed5c'] = inception_a(layers['mixed5b']['concat'], 'mixed5c', weights, 13) 24 | layers['mixed5d'] = inception_a(layers['mixed5c']['concat'], 'mixed5d', weights, 20) 25 | 26 | layers['mixed6a'] = inception_b(layers['mixed5d']['concat'], 'mixed6a', weights, 27) 27 | layers['mixed6b'] = inception_c(layers['mixed6a']['concat'], 'mixed6b', weights, 31) 28 | layers['mixed6c'] = inception_c(layers['mixed6b']['concat'], 'mixed6c', weights, 41) 29 | layers['mixed6d'] = inception_c(layers['mixed6c']['concat'], 'mixed6d', weights, 51) 30 | layers['mixed6e'] = inception_c(layers['mixed6d']['concat'], 'mixed6e', weights, 61) 31 | 32 | layers['mixed7a'] = inception_d(layers['mixed6e']['concat'], 'mixed7a', weights, 71) 33 | layers['mixed7b'] = inception_e(layers['mixed7a']['concat'], 'mixed7b', weights, 77) 34 | layers['mixed7c'] = inception_e(layers['mixed7b']['concat'], 'mixed7c', weights, 86) 35 | 36 | layers['gap'] = avg_pool(layers['mixed7c']['concat'], k=8, padding='VALID') 37 | layers['gap_r'] = tf.reshape(layers['gap'], [-1,2048]) 38 | 39 | layers['classifier'] = fully_connected(layers['gap_r'], weights['predictions']['weights'], weights['predictions']['biases']) 40 | layers['prob'] = tf.nn.softmax(layers['classifier']) 41 | return layers 42 | 43 | def inceptionv3(input): 44 | net = h5py.File('weights/inception_v3_weights_tf_dim_ordering_tf_kernels.h5','r') 45 | weights = {} 46 | for name in net.keys(): 47 | if 'conv' in name: 48 | weights[name] = tf.Variable(tf.constant(net[name][name]['kernel:0'][:]), dtype='float32' ,name=name, trainable=False) 49 | elif 'batch_normalization' in name: 50 | beta = tf.Variable(tf.constant(net[name][name]['beta:0'][:]), dtype='float32' ,name=name, trainable=False) 51 | mean = tf.Variable(tf.constant(net[name][name]['moving_mean:0'][:]), dtype='float32' ,name=name, trainable=False) 52 | variance = tf.Variable(tf.constant(net[name][name]['moving_variance:0'][:]), dtype='float32' ,name=name, trainable=False) 53 | weights[name] = {'offset': beta, 'mean': mean, 'variance': variance, 'scale': None} 54 | elif name == 'predictions': 55 | param = tf.Variable(tf.constant(net[name][name]['kernel:0'][:]), dtype='float32' ,name=name, trainable=False) 56 | bias = tf.Variable(tf.constant(net[name][name]['bias:0'][:]), dtype='float32' ,name=name, trainable=False) 57 | weights[name] = {'biases': bias, 'weights': param} 58 | 59 | return model(input, weights) 60 | -------------------------------------------------------------------------------- /nets/resnet_152.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from misc.layers import * 3 | import numpy as np 4 | 5 | def model(image, weights): 6 | #check image dimensions 7 | assert image.get_shape().as_list()[1:] == [224, 224, 3] 8 | layers = {} 9 | with tf.name_scope("conv1"): 10 | layers['conv1'] = conv_layer(image, weights['conv1']['weights'], s=2, relu=False) 11 | layers['bn_conv1'] = batch_norm(layers['conv1'], weights['bn_conv1']) 12 | layers['pool1'] = max_pool(layers['bn_conv1'], k=3, s=2) 13 | 14 | with tf.name_scope("res2"): 15 | layers['res2a'] = res_block(layers['pool1'], '2a', weights, first=True) 16 | layers['res2b'] = res_block(layers['res2a'], '2b', weights) 17 | layers['res2c'] = res_block(layers['res2b'], '2c', weights) 18 | 19 | with tf.name_scope("res3"): 20 | layers['res3a'] = res_block(layers['res2c'], '3a', weights, stride=2, first=True) 21 | layers['res3b1'] = res_block(layers['res3a'], '3b1', weights) 22 | layers['res3b2'] = res_block(layers['res3b1'], '3b2', weights) 23 | layers['res3b3'] = res_block(layers['res3b2'], '3b3', weights) 24 | layers['res3b4'] = res_block(layers['res3b3'], '3b4', weights) 25 | layers['res3b5'] = res_block(layers['res3b4'], '3b5', weights) 26 | layers['res3b6'] = res_block(layers['res3b5'], '3b6', weights) 27 | layers['res3b7'] = res_block(layers['res3b6'], '3b7', weights) 28 | 29 | with tf.name_scope("res4"): 30 | layers['res4a'] = res_block(layers['res3b7'], '4a', weights, stride=2, first=True) 31 | layers['res4b1'] = res_block(layers['res4a'], '4b1', weights) 32 | layers['res4b2'] = res_block(layers['res4b1'], '4b2', weights) 33 | layers['res4b3'] = res_block(layers['res4b2'], '4b3', weights) 34 | layers['res4b4'] = res_block(layers['res4b3'], '4b4', weights) 35 | layers['res4b5'] = res_block(layers['res4b4'], '4b5', weights) 36 | layers['res4b6'] = res_block(layers['res4b5'], '4b6', weights) 37 | layers['res4b7'] = res_block(layers['res4b6'], '4b7', weights) 38 | layers['res4b8'] = res_block(layers['res4b7'], '4b8', weights) 39 | layers['res4b9'] = res_block(layers['res4b8'], '4b9', weights) 40 | layers['res4b10'] = res_block(layers['res4b9'], '4b10', weights) 41 | layers['res4b11'] = res_block(layers['res4b10'], '4b11', weights) 42 | layers['res4b12'] = res_block(layers['res4b11'], '4b12', weights) 43 | layers['res4b13'] = res_block(layers['res4b12'], '4b13', weights) 44 | layers['res4b14'] = res_block(layers['res4b13'], '4b14', weights) 45 | layers['res4b15'] = res_block(layers['res4b14'], '4b15', weights) 46 | layers['res4b16'] = res_block(layers['res4b15'], '4b16', weights) 47 | layers['res4b17'] = res_block(layers['res4b16'], '4b17', weights) 48 | layers['res4b18'] = res_block(layers['res4b17'], '4b18', weights) 49 | layers['res4b19'] = res_block(layers['res4b18'], '4b19', weights) 50 | layers['res4b20'] = res_block(layers['res4b19'], '4b20', weights) 51 | layers['res4b21'] = res_block(layers['res4b20'], '4b21', weights) 52 | layers['res4b22'] = res_block(layers['res4b21'], '4b22', weights) 53 | layers['res4b23'] = res_block(layers['res4b22'], '4b23', weights) 54 | layers['res4b24'] = res_block(layers['res4b23'], '4b24', weights) 55 | layers['res4b25'] = res_block(layers['res4b24'], '4b25', weights) 56 | layers['res4b26'] = res_block(layers['res4b25'], '4b26', weights) 57 | layers['res4b27'] = res_block(layers['res4b26'], '4b27', weights) 58 | layers['res4b28'] = res_block(layers['res4b27'], '4b28', weights) 59 | layers['res4b29'] = res_block(layers['res4b28'], '4b29', weights) 60 | layers['res4b30'] = res_block(layers['res4b29'], '4b30', weights) 61 | layers['res4b31'] = res_block(layers['res4b30'], '4b31', weights) 62 | layers['res4b32'] = res_block(layers['res4b31'], '4b32', weights) 63 | layers['res4b33'] = res_block(layers['res4b32'], '4b33', weights) 64 | layers['res4b34'] = res_block(layers['res4b33'], '4b34', weights) 65 | layers['res4b35'] = res_block(layers['res4b34'], '4b35', weights) 66 | 67 | with tf.name_scope("res5"): 68 | layers['res5a'] = res_block(layers['res4b35'], '5a', weights, stride=2, first=True) 69 | layers['res5b'] = res_block(layers['res5a'], '5b', weights) 70 | layers['res5c'] = res_block(layers['res5b'], '5c', weights) 71 | 72 | with tf.name_scope('pool5'): 73 | layers['pool5'] = tf.nn.avg_pool(layers['res5c'], [1,7,7,1], [1,1,1,1], padding='VALID') 74 | layers['pool5_r'] = tf.reshape(layers['pool5'],[-1,2048]) 75 | 76 | with tf.name_scope('fc1000'): 77 | layers['fc1000'] = fully_connected(layers['pool5_r'], weights['fc1000']['weights'], weights['fc1000']['biases']) 78 | layers['prob'] = tf.nn.softmax(layers['fc1000']) 79 | 80 | return layers 81 | 82 | def resnet152(input): 83 | 84 | #weigths and biases for tensorflow 85 | net = np.load('weights/resnet152.npy').item() 86 | weights = {} 87 | for name in net.keys(): 88 | weights[name] = {} 89 | for i in net[name].keys(): 90 | weights[name][i] = tf.Variable(tf.constant(net[name][i]), dtype='float32' ,name=name+'_'+i, trainable=False) 91 | 92 | return model(input, weights) 93 | -------------------------------------------------------------------------------- /nets/resnet_50.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from misc.layers import * 3 | import numpy as np 4 | 5 | def model(image, weights): 6 | #check image dimensions 7 | assert image.get_shape().as_list()[1:] == [224, 224, 3] 8 | layers = {} 9 | with tf.name_scope("conv1"): 10 | layers['conv1'] = conv_layer(image, weights['conv1']['weights'], weights['conv1']['biases'], s=2, relu=False) 11 | layers['bn_conv1'] = batch_norm(layers['conv1'], weights['bn_conv1']) 12 | layers['pool1'] = max_pool(layers['bn_conv1'], k=3, s=2) 13 | 14 | with tf.name_scope("res2"): 15 | layers['res2a'] = res_block(layers['pool1'], '2a', weights, first=True) 16 | layers['res2b'] = res_block(layers['res2a'], '2b', weights) 17 | layers['res2c'] = res_block(layers['res2b'], '2c', weights) 18 | 19 | with tf.name_scope("res3"): 20 | layers['res3a'] = res_block(layers['res2c'], '3a', weights, stride=2, first=True) 21 | layers['res3b'] = res_block(layers['res3a'], '3b', weights) 22 | layers['res3c'] = res_block(layers['res3b'], '3c', weights) 23 | layers['res3d'] = res_block(layers['res3c'], '3d', weights) 24 | 25 | with tf.name_scope("res4"): 26 | layers['res4a'] = res_block(layers['res3d'], '4a', weights, stride=2, first=True) 27 | layers['res4b'] = res_block(layers['res4a'], '4b', weights) 28 | layers['res4c'] = res_block(layers['res4b'], '4c', weights) 29 | layers['res4d'] = res_block(layers['res4c'], '4d', weights) 30 | layers['res4e'] = res_block(layers['res4d'], '4e', weights) 31 | layers['res4f'] = res_block(layers['res4e'], '4f', weights) 32 | 33 | with tf.name_scope("res5"): 34 | layers['res5a'] = res_block(layers['res4f'], '5a', weights, stride=2, first=True) 35 | layers['res5b'] = res_block(layers['res5a'], '5b', weights) 36 | layers['res5c'] = res_block(layers['res5b'], '5c', weights) 37 | 38 | with tf.name_scope('pool5'): 39 | layers['pool5'] = tf.nn.avg_pool(layers['res5c'], [1,7,7,1], [1,1,1,1], padding='VALID') 40 | layers['pool5_r'] = tf.reshape(layers['pool5'],[-1,2048]) 41 | 42 | with tf.name_scope('fc1000'): 43 | layers['fc1000'] = fully_connected(layers['pool5_r'], weights['fc1000']['weights'], weights['fc1000']['biases']) 44 | layers['prob'] = tf.nn.softmax(layers['fc1000']) 45 | 46 | return layers 47 | 48 | def resnet50(input): 49 | 50 | #weigths and biases for tensorflow 51 | net = np.load('weights/resnet50.npy').item() 52 | weights = {} 53 | for name in net.keys(): 54 | weights[name] = {} 55 | for i in net[name].keys(): 56 | weights[name][i] = tf.Variable(tf.constant(net[name][i]), dtype='float32' ,name=name+'_'+i, trainable=False) 57 | 58 | return model(input, weights) 59 | -------------------------------------------------------------------------------- /nets/vgg_16.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from misc.layers import * 3 | import numpy as np 4 | 5 | def model(image, weights, biases, keep_prob=1.0): 6 | #check image dimensions 7 | assert image.get_shape().as_list()[1:] == [224, 224, 3] 8 | layers = {} 9 | with tf.name_scope("conv1"): 10 | layers['conv1_1'] = conv_layer(image, weights['conv1_1'], biases['conv1_1']) 11 | layers['conv1_2'] = conv_layer(layers['conv1_1'], weights['conv1_2'], biases['conv1_2']) 12 | layers['pool1'] = max_pool(layers['conv1_2'], k=2, s=2) 13 | 14 | with tf.name_scope("conv2"): 15 | layers['conv2_1'] = conv_layer(layers['pool1'], weights['conv2_1'], biases['conv2_1']) 16 | layers['conv2_2'] = conv_layer(layers['conv2_1'], weights['conv2_2'], biases['conv2_2']) 17 | layers['pool2'] = max_pool(layers['conv2_2'], k=2, s=2) 18 | 19 | with tf.name_scope("conv3"): 20 | layers['conv3_1'] = conv_layer(layers['pool2'], weights['conv3_1'], biases['conv3_1']) 21 | layers['conv3_2'] = conv_layer(layers['conv3_1'], weights['conv3_2'], biases['conv3_2']) 22 | layers['conv3_3'] = conv_layer(layers['conv3_2'], weights['conv3_3'], biases['conv3_3']) 23 | layers['pool3'] = max_pool(layers['conv3_3'], k=2, s=2) 24 | 25 | with tf.name_scope("conv4"): 26 | layers['conv4_1'] = conv_layer(layers['pool3'], weights['conv4_1'], biases['conv4_1']) 27 | layers['conv4_2'] = conv_layer(layers['conv4_1'], weights['conv4_2'], biases['conv4_2']) 28 | layers['conv4_3'] = conv_layer(layers['conv4_2'], weights['conv4_3'], biases['conv4_3']) 29 | layers['pool4'] = max_pool(layers['conv4_3'], k=2, s=2) 30 | 31 | with tf.name_scope("conv5"): 32 | layers['conv5_1'] = conv_layer(layers['pool4'], weights['conv5_1'], biases['conv5_1']) 33 | layers['conv5_2'] = conv_layer(layers['conv5_1'], weights['conv5_2'], biases['conv5_2']) 34 | layers['conv5_3'] = conv_layer(layers['conv5_2'], weights['conv5_3'], biases['conv5_3']) 35 | layers['pool5'] = max_pool(layers['conv5_3'], k=2, s=2) 36 | 37 | flatten = tf.reshape(layers['pool5'], [-1, 25088]) 38 | 39 | with tf.name_scope('fc6'): 40 | layers['fc6'] = tf.nn.relu(fully_connected(flatten, weights['fc6'], biases['fc6'])) 41 | layers['fc6_d'] = tf.nn.dropout(layers['fc6'], keep_prob=keep_prob) 42 | 43 | with tf.name_scope('fc7'): 44 | layers['fc7'] = tf.nn.relu(fully_connected(layers['fc6_d'], weights['fc7'], biases['fc7'])) 45 | layers['fc7_d'] = tf.nn.dropout(layers['fc7'], keep_prob=keep_prob) 46 | 47 | with tf.name_scope('fc8'): 48 | layers['fc8'] = fully_connected(layers['fc7_d'], weights['fc8'], biases['fc8']) 49 | layers['prob'] = tf.nn.softmax(layers['fc8']) 50 | 51 | return layers 52 | 53 | def vgg16(input): 54 | 55 | #weigths and biases for tensorflow 56 | net = np.load('weights/vgg16.npy').item() 57 | weights = {} 58 | biases = {} 59 | for name in net.keys(): 60 | weights[name] = tf.Variable(tf.constant(net[name][0]), dtype='float32' ,name=name+"_weight", trainable=False) 61 | biases[name] = tf.Variable(tf.constant(net[name][1]), dtype='float32' ,name=name+"_bias", trainable=False) 62 | 63 | return model(input, weights, biases) 64 | -------------------------------------------------------------------------------- /nets/vgg_19.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from misc.layers import * 3 | import numpy as np 4 | 5 | def model(image, weights, biases, keep_prob=1.0): 6 | #check image dimensions 7 | assert image.get_shape().as_list()[1:] == [224, 224, 3] 8 | layers = {} 9 | with tf.name_scope("conv1"): 10 | layers['conv1_1'] = conv_layer(image, weights['conv1_1'], biases['conv1_1']) 11 | layers['conv1_2'] = conv_layer(layers['conv1_1'], weights['conv1_2'], biases['conv1_2']) 12 | layers['pool1'] = max_pool(layers['conv1_2'], k=2, s=2) 13 | 14 | with tf.name_scope("conv2"): 15 | layers['conv2_1'] = conv_layer(layers['pool1'], weights['conv2_1'], biases['conv2_1']) 16 | layers['conv2_2'] = conv_layer(layers['conv2_1'], weights['conv2_2'], biases['conv2_2']) 17 | layers['pool2'] = max_pool(layers['conv2_2'], k=2, s=2) 18 | 19 | with tf.name_scope("conv3"): 20 | layers['conv3_1'] = conv_layer(layers['pool2'], weights['conv3_1'], biases['conv3_1']) 21 | layers['conv3_2'] = conv_layer(layers['conv3_1'], weights['conv3_2'], biases['conv3_2']) 22 | layers['conv3_3'] = conv_layer(layers['conv3_2'], weights['conv3_3'], biases['conv3_3']) 23 | layers['conv3_4'] = conv_layer(layers['conv3_3'], weights['conv3_4'], biases['conv3_4']) 24 | layers['pool3'] = max_pool(layers['conv3_4'], k=2, s=2) 25 | 26 | with tf.name_scope("conv4"): 27 | layers['conv4_1'] = conv_layer(layers['pool3'], weights['conv4_1'], biases['conv4_1']) 28 | layers['conv4_2'] = conv_layer(layers['conv4_1'], weights['conv4_2'], biases['conv4_2']) 29 | layers['conv4_3'] = conv_layer(layers['conv4_2'], weights['conv4_3'], biases['conv4_3']) 30 | layers['conv4_4'] = conv_layer(layers['conv4_3'], weights['conv4_4'], biases['conv4_4']) 31 | layers['pool4'] = max_pool(layers['conv4_4'], k=2, s=2) 32 | 33 | with tf.name_scope("conv5"): 34 | layers['conv5_1'] = conv_layer(layers['pool4'], weights['conv5_1'], biases['conv5_1']) 35 | layers['conv5_2'] = conv_layer(layers['conv5_1'], weights['conv5_2'], biases['conv5_2']) 36 | layers['conv5_3'] = conv_layer(layers['conv5_2'], weights['conv5_3'], biases['conv5_3']) 37 | layers['conv5_4'] = conv_layer(layers['conv5_3'], weights['conv5_4'], biases['conv5_4']) 38 | layers['pool5'] = max_pool(layers['conv5_4'], k=2, s=2) 39 | 40 | flatten = tf.reshape(layers['pool5'], [-1, 25088]) 41 | 42 | with tf.name_scope('fc6'): 43 | layers['fc6'] = tf.nn.relu(fully_connected(flatten, weights['fc6'], biases['fc6'])) 44 | layers['fc6_d'] = tf.nn.dropout(layers['fc6'], keep_prob=keep_prob) 45 | 46 | with tf.name_scope('fc7'): 47 | layers['fc7'] = tf.nn.relu(fully_connected(layers['fc6_d'], weights['fc7'], biases['fc7'])) 48 | layers['fc7_d'] = tf.nn.dropout(layers['fc7'], keep_prob=keep_prob) 49 | 50 | with tf.name_scope('fc8'): 51 | layers['fc8'] = fully_connected(layers['fc7_d'], weights['fc8'], biases['fc8']) 52 | layers['prob'] = tf.nn.softmax(layers['fc8']) 53 | 54 | return layers 55 | 56 | def vgg19(input): 57 | 58 | #weigths and biases for tensorflow 59 | net = np.load('weights/vgg19.npy').item() 60 | weights = {} 61 | biases = {} 62 | for name in net.keys(): 63 | weights[name] = tf.Variable(tf.constant(net[name][0]), dtype='float32' ,name=name+"_weight", trainable=False) 64 | biases[name] = tf.Variable(tf.constant(net[name][1]), dtype='float32' ,name=name+"_bias", trainable=False) 65 | 66 | return model(input, weights, biases) 67 | -------------------------------------------------------------------------------- /nets/vgg_f.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from misc.layers import * 3 | import numpy as np 4 | 5 | def model(image, weights, biases, keep_prob=1.0): 6 | #check image dimensions 7 | assert image.get_shape().as_list()[1:] == [224, 224, 3] 8 | layers = {} 9 | with tf.name_scope("conv1"): 10 | layers['conv1'] = conv_layer(image, weights['conv1'], biases['conv1'], s=4, padding='VALID') 11 | layers['norm1'] = tf.nn.lrn(layers['conv1'],2,2.000,0.0001,0.75) 12 | layers['pool1'] = max_pool(layers['norm1'], k=3, s=2) 13 | 14 | with tf.name_scope("conv2"): 15 | layers['conv2'] = conv_layer(layers['pool1'], weights['conv2'], biases['conv2']) 16 | layers['norm2'] = tf.nn.lrn(layers['conv2'],2,2.000,0.0001,0.75) 17 | layers['pool2'] = max_pool(layers['norm2'], k=3, s=2, padding='VALID') 18 | 19 | with tf.name_scope("conv3"): 20 | layers['conv3'] = conv_layer(layers['pool2'], weights['conv3'], biases['conv3']) 21 | 22 | with tf.name_scope("conv4"): 23 | layers['conv4'] = conv_layer(layers['conv3'], weights['conv4'], biases['conv4']) 24 | 25 | with tf.name_scope("conv5"): 26 | layers['conv5'] = conv_layer(layers['conv4'], weights['conv5'], biases['conv5']) 27 | layers['pool5'] = max_pool(layers['conv5'], k=3, s=2, padding='VALID') 28 | 29 | flatten = tf.reshape(layers['pool5'], [-1, 9216]) 30 | 31 | with tf.name_scope('fc6'): 32 | layers['fc6'] = tf.nn.relu(fully_connected(flatten, weights['fc6'], biases['fc6'])) 33 | layers['fc6'] = tf.nn.dropout(layers['fc6'], keep_prob=keep_prob) 34 | 35 | with tf.name_scope('fc7'): 36 | layers['fc7'] = tf.nn.relu(fully_connected(layers['fc6'], weights['fc7'], biases['fc7'])) 37 | layers['fc7'] = tf.nn.dropout(layers['fc7'], keep_prob=keep_prob) 38 | 39 | with tf.name_scope('fc8'): 40 | layers['fc8'] = fully_connected(layers['fc7'], weights['fc8'], biases['fc8']) 41 | layers['prob'] = tf.nn.softmax(layers['fc8']) 42 | 43 | return layers 44 | 45 | def vggf(input): 46 | 47 | #weigths and biases for tensorflow 48 | net = np.load('weights/vgg_f.npy').item() 49 | weights = {} 50 | biases = {} 51 | for name in net.keys(): 52 | weights[name] = tf.Variable(tf.constant(net[name][0]), dtype='float32' ,name=name+"_weight", trainable=False) 53 | biases[name] = tf.Variable(tf.constant(net[name][1]), dtype='float32' ,name=name+"_bias", trainable=False) 54 | 55 | return model(input, weights, biases) 56 | -------------------------------------------------------------------------------- /weights/download_weights.sh: -------------------------------------------------------------------------------- 1 | #download weights for vgg-f 2 | wget https://www.dropbox.com/s/b96tfz2hnthfegm/vgg_f.npy 3 | 4 | #download weights for caffenet 5 | wget https://www.dropbox.com/s/8evo8ydl1jl03z4/caffenet.npy 6 | 7 | #download weights for vgg-16 8 | wget https://www.dropbox.com/s/zpeufcwesimhvua/vgg16.npy 9 | 10 | #download weights for vgg-19 11 | wget https://www.dropbox.com/s/e1v93adr4igwuct/vgg19.npy 12 | 13 | #download weights for googlenet 14 | wget https://www.dropbox.com/s/kzlgksuginkatb5/googlenet.npy 15 | 16 | #download weights for resnet-50 17 | wget https://www.dropbox.com/s/o8ay4gjdnu1ktds/resnet50.npy 18 | 19 | #download weights for resnet-152 20 | wget https://www.dropbox.com/s/8bzt5bfvkmz8xr9/resnet152.npy 21 | 22 | #download weights for inception-v3 23 | wget https://github.com/fchollet/deep-learning-models/releases/download/v0.5/inception_v3_weights_tf_dim_ordering_tf_kernels.h5 --------------------------------------------------------------------------------