├── .gitignore ├── README.md ├── data └── imagenet_labels.txt ├── functions ├── __init__.py ├── misc.py └── wavelet_haar.py ├── models ├── README.md ├── WaveletCNN_4level.prototxt ├── WaveletCNN_4level_deploy.prototxt └── solver_WaveletCNN_4level.prototxt ├── pylayers.py └── run_waveletcnn.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | .ipynb_checkpoints/ 3 | *.ipynb 4 | *.npy 5 | *_lmdb/ 6 | *.caffemodel 7 | *.solverstate 8 | *.binaryproto 9 | kth-tips2-b/ 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WaveletCNN for Texture Classification 2 | 3 | This is a Caffe implementation of a paper, [Wavelet Convolutional Neural Networks for Texture Classification](https://arxiv.org/abs/1707.07394) (arXiv, 2017). 4 | 5 | ## Requirements 6 | 7 | - Python 3+ 8 | - Caffe 9 | 10 | This code was tested with NVIDIA GeForce GTX 1080 on Windows 10. 11 | 12 | When you set up the environment of Caffe on Windows, we recommend you to use [this version of Caffe](https://github.com/willyd/caffe/tree/windows), instead of [the windows branch of the official Caffe](https://github.com/BVLC/caffe/tree/windows). 13 | 14 | ## Pre-trained Model 15 | 16 | Please go to `models` directory and follow the instructions. 17 | 18 | ## Usage 19 | 20 | ### Train with your own dataset 21 | 22 | ``` 23 | python run_waveletcnn.py --phase train --gpu 0 --dataset path/to/dataset_lmdb 24 | ``` 25 | 26 | To run this code, you have to prepare your dataset as LMDB format. (Otherwise, you have to rewrite `models/WaveletCNN_4level.prototxt`) 27 | 28 | And you might need to rewrite some settings in `models/solver_WaveletCNN_4level.prototxt`, such as **test_iter**, **base_lr** and **max_iter**. 29 | 30 | ### Test with an image 31 | 32 | ``` 33 | python run_waveletcnn.py --phase test --gpu 0 --initmodel models/ImageNet_waveletCNN_level4.caffemodel --target_image path/to/image 34 | ``` 35 | 36 | Using the pre-trained model with ImageNet 2012 dataset, please download it following the instructions in `models` directory. 37 | 38 | When you use your own trained model, path to the model is used instead as the argument of **--initmodel**. Additionally, you need to rewrite the path to the file, which contains label names, in `run_waveletcnn.py` (l.68). 39 | 40 | ## Citation 41 | 42 | If you find this code useful for your research, please cite our paper: 43 | 44 | ``` 45 | @article{Fujieda2017, 46 | author = {Shin Fujieda and Kohei Takayama and Toshiya Hachisuka}, 47 | title = {Wavelet Convolutional Neural Networks for Texture Classification}, 48 | journal = {arXiv:1707.07394 [cs.CV]}, 49 | year = {2017}, 50 | } 51 | ``` 52 | -------------------------------------------------------------------------------- /data/imagenet_labels.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 | -------------------------------------------------------------------------------- /functions/__init__.py: -------------------------------------------------------------------------------- 1 | from . import misc 2 | from . import wavelet_haar 3 | -------------------------------------------------------------------------------- /functions/misc.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | import numpy as np 3 | from scipy import ndimage as ndi 4 | 5 | import caffe 6 | from caffe.proto import caffe_pb2 7 | import google.protobuf.text_format as txtf 8 | 9 | def rewrite_data(filename, database): 10 | ''' 11 | Rewrite database names in the prototxt file 12 | ''' 13 | net = caffe_pb2.NetParameter() 14 | with open(filename) as f: 15 | s = f.read() 16 | txtf.Merge(s, net) 17 | 18 | layerNames = [l.name for l in net.layer] 19 | print(layerNames) 20 | idx = layerNames.index('data') 21 | data = net.layer[idx] 22 | data.data_param.source = database 23 | 24 | def random_crop(image, crop_dims, crop_num): 25 | """ 26 | Crop images randomly 27 | 28 | Parameters 29 | ---------- 30 | image: (H x W x K) ndarray 31 | crop_dims: (height, width) tuple for the crops 32 | crop_num: number of randomly cropping 33 | 34 | Returns 35 | ------- 36 | crops: (N x H x W x K) ndarray of crops for number of crop_num (N). 37 | """ 38 | # Dimensions 39 | im_shape = np.array(image.shape) 40 | crop_dims = np.array(crop_dims) 41 | 42 | # Coordinate of top-left corner 43 | limit_y = int(im_shape[0] - crop_dims[0]) 44 | limit_x = int(im_shape[1] - crop_dims[1]) 45 | # 0 ~ (limit-1) の整数で(10, 2)のarrayを作成 46 | im_toplefts_x = np.random.randint(0, limit_x, (10, 1)) 47 | im_toplefts_y = np.random.randint(0, limit_y, (10, 1)) 48 | im_toplefts = np.concatenate([im_toplefts_y, im_toplefts_x], axis=1) 49 | 50 | # Make crop coordinates 51 | crop_ix = np.concatenate([ 52 | im_toplefts, 53 | im_toplefts + np.tile(crop_dims, (10, 1)) 54 | ], axis=1) 55 | crop_ix = crop_ix.astype(int) 56 | 57 | crops = np.empty((crop_num, crop_dims[0], crop_dims[1], im_shape[-1]), dtype=image.dtype) 58 | for ix in range(crop_num): 59 | crops[ix] = image[crop_ix[ix, 0]:crop_ix[ix, 2], crop_ix[ix, 1]:crop_ix[ix, 3], :] 60 | 61 | return crops 62 | 63 | def center_crop(image, crop_dims): 64 | """ 65 | Crop images into the center 66 | 67 | Parameters 68 | ---------- 69 | image : (H x W x K) ndarrays 70 | crop_dims : (height, width) tuple for the crops. 71 | 72 | Returns 73 | ------- 74 | crops : (N x H x W x K) ndarray of crops for number of inputs N. 75 | """ 76 | # Dimensions and center. 77 | im_shape = np.array(image.shape) 78 | crop_dims = np.array(crop_dims) 79 | im_center = im_shape[:2] / 2.0 80 | 81 | # Make crop coordinates 82 | # coordinates of center cropping 83 | crop_ix = np.tile(im_center, (1, 2)) + np.concatenate([ 84 | -crop_dims / 2.0, 85 | crop_dims / 2.0 86 | ]) 87 | crop_ix = crop_ix.astype(int) 88 | 89 | crop = image[crop_ix[0, 0]:crop_ix[0, 2], crop_ix[0, 1]:crop_ix[0, 3], :] 90 | 91 | return crop 92 | 93 | def RotateImage(images): 94 | """ 95 | Rotate images with 90, 180, 270 degrees and their mirrored versions 96 | 97 | Parameters 98 | ---------- 99 | images: target RGB images (N x C x H x W) 100 | 101 | Returns 102 | ------- 103 | rotate_images: rotated & mirrored images (8N x C x H x W) 104 | """ 105 | images = images.transpose(0, 2, 3, 1) 106 | im_shape = images.shape 107 | rotate_images = np.empty((0, im_shape[1], im_shape[2], im_shape[3]), np.float32) 108 | image_num = 0 109 | for image in images: 110 | for i in range(4): 111 | if i == 0: 112 | image_rot = image 113 | else: 114 | image_rot = ndi.rotate(image_rot, 90) 115 | rotate_images = np.append(rotate_images, [image_rot], axis=0) 116 | image_rot_ud = np.flipud(image_rot) 117 | rotate_images = np.append(rotate_images, [image_rot_ud], axis=0) 118 | image_num += 1 119 | 120 | rotate_images = rotate_images.transpose(0, 3, 1, 2) 121 | return rotate_images 122 | 123 | def downsampling(images, levels): 124 | div = 2**(levels) 125 | images_t = np.empty((0, int(images.shape[1])/div, int(images.shape[2])/div), np.float32) 126 | for image in images: 127 | tmp = image 128 | for level in range(levels): 129 | tmp = (tmp[0::2, 0::2] + tmp[1::2, 0::2] + tmp[0::2, 1::2] + tmp[1::2, 1::2]) / 4 130 | image_t = tmp 131 | images_t = np.append(images_t, [image_t], axis=0) 132 | return images_t 133 | 134 | def gram_matrix(activations): 135 | ''' 136 | Gives the gram matrix for feature map activations in caffe format with batchsize 1. Normalises by spatial dimensions. 137 | 138 | :param activations: feature map activations to compute gram matrix from 139 | :return: normalised gram matrix 140 | ''' 141 | N = activations.shape[1] 142 | F = activations.reshape(N,-1) 143 | M = F.shape[1] 144 | G = np.dot(F,F.T) / M 145 | return G, F 146 | 147 | def global_contrast_normalize(X, scale=1., subtract_mean=True, use_std=True, sqrt_bias=10., min_divisor=1e-8): 148 | """ 149 | Global contrast normalizes by (optionally) subtracting the mean across features and then normalizes by either the vector norm 150 | or the standard deviation (across features, for each example). 151 | -------- 152 | `sqrt_bias` = 10 and `use_std = True` (and defaults for all other parameters) corresponds to the preprocessing used in [1]. 153 | ---------- 154 | .. [1] A. Coates, H. Lee and A. Ng. "An Analysis of Single-Layer Networks in Unsupervised Feature Learning". AISTATS 14, 2011. 155 | http://www.stanford.edu/~acoates/papers/coatesleeng_aistats_2011.pdf 156 | """ 157 | assert X.ndim == 2, "X.ndim must be 2" 158 | scale = float(scale) 159 | assert scale >= min_divisor 160 | 161 | # Note: this is per-example mean across pixels, not the per-pixel mean across examples. 162 | # So it is perfectly fine to subtract this without worrying about whether the current object is the train, valid, or test set. 163 | mean = X.mean(axis=1) 164 | if subtract_mean: 165 | X = X - mean[:, np.newaxis] # Makes a copy. 166 | else: 167 | X = X.copy() 168 | 169 | if use_std: 170 | ddof = 1 171 | 172 | # If we don't do this, X.var will return nan. 173 | if X.shape[1] == 1: 174 | ddof = 0 175 | 176 | normalizers = np.sqrt(sqrt_bias + X.var(axis=1, ddof=ddof)) / scale 177 | else: 178 | normalizers = np.sqrt(sqrt_bias + (X ** 2).sum(axis=1)) / scale 179 | 180 | # Don't normalize by anything too small. 181 | normalizers[normalizers < min_divisor] = 1. 182 | 183 | X /= normalizers[:, np.newaxis] # Does not make a copy. 184 | return X 185 | -------------------------------------------------------------------------------- /functions/wavelet_haar.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import numpy as np 3 | 4 | 5 | # mean + diff 6 | def WaveletTransformAxisY(img): 7 | row, col = img.shape[:2] 8 | size = row / 2 9 | 10 | img_even = img[1::2] 11 | img_odd = img[0::2] 12 | if len(img_even) != len(img_odd): 13 | img_odd = img_odd[:-1] 14 | # c: mean (low-frequency), d: diff (high-frequency) 15 | c = (img_even + img_odd) / 2. 16 | d = abs(img_odd - img_even) 17 | 18 | return size, c, d 19 | 20 | def WaveletTransformLLAxisY(img): 21 | row, col = img.shape[:2] 22 | img_even = img[1::2] 23 | img_odd = img[0::2] 24 | if len(img_even) != len(img_odd): 25 | img_odd = img_odd[:-1] 26 | # c: mean (low-frequency), d: diff (high-frequency) 27 | c = (img_even + img_odd) / 2. 28 | 29 | return c 30 | 31 | def WaveletTransformAxisX(img): 32 | tmp = np.fliplr(img.T) 33 | size, dst_L, dst_H = WaveletTransformAxisY(tmp) 34 | dst_L = np.flipud(dst_L.T) 35 | dst_H = np.flipud(dst_H.T) 36 | return size, dst_L, dst_H 37 | 38 | def WaveletTransformLLAxisX(img): 39 | tmp = np.fliplr(img.T) 40 | dst_L = WaveletTransformLLAxisY(tmp) 41 | dst_L = np.flipud(dst_L.T) 42 | return dst_L 43 | 44 | def WaveletTransform(img, n=1): 45 | row, col = img.shape[:2] 46 | roi = img[0:row,0:col] 47 | wavelets = {} 48 | for i in range(0,n): 49 | y_size, wavelet_L, wavelet_H = WaveletTransformAxisY(roi) 50 | x_size, wavelet_LL, wavelet_LH = WaveletTransformAxisX(wavelet_L) 51 | wavelets["LL_"+str(i+1)] = wavelet_LL 52 | wavelets["LH_"+str(i+1)] = wavelet_LH 53 | x_size, wavelet_HL, wavelet_HH = WaveletTransformAxisX(wavelet_H) 54 | wavelets["HL_"+str(i+1)] = wavelet_HL 55 | wavelets["HH_"+str(i+1)] = wavelet_HH 56 | roi = wavelet_LL 57 | return wavelets 58 | -------------------------------------------------------------------------------- /models/README.md: -------------------------------------------------------------------------------- 1 | # Pre-trained Model 2 | 3 | We provide the pre-trained model with ImageNet 2012 Dataset [1]. 4 | 5 | For this dataset, our model achieved the accuracy of 59.8%. 6 | 7 | ## Download 8 | 9 | You can download pre-trained caffemodel from [here](https://www.dropbox.com/s/ufv7kzds58wwp2a/ImageNet_waveletCNN_level4.caffemodel?dl=0). 10 | 11 | ## References 12 | 13 | - [1] "Imagenet large scale visual recognition challenge", Russakovsky et al., IJCV, 2015. 14 | -------------------------------------------------------------------------------- /models/WaveletCNN_4level.prototxt: -------------------------------------------------------------------------------- 1 | name: "WaveletCNN_4level" 2 | force_backward: true 3 | layer { 4 | name: "data" 5 | type: "Data" 6 | top: "data" 7 | top: "label" 8 | include { 9 | phase: TRAIN 10 | } 11 | transform_param { 12 | mirror: true 13 | crop_size: 224 14 | } 15 | data_param { 16 | source: "Data/kth-tips2-b/kth_train_a_lmdb" 17 | batch_size: 32 18 | backend: LMDB 19 | } 20 | } 21 | layer { 22 | name: "data" 23 | type: "Data" 24 | top: "data" 25 | top: "label" 26 | include { 27 | phase: TEST 28 | } 29 | transform_param { 30 | mirror: false 31 | crop_size: 224 32 | } 33 | data_param { 34 | source: "Data/kth-tips2-b/kth_val_a_lmdb" 35 | batch_size: 64 36 | backend: LMDB 37 | } 38 | } 39 | layer { 40 | name: "gcn_data" 41 | type: "Python" 42 | bottom: "data" 43 | top: "gcn_data" 44 | python_param { 45 | module: "pylayers" 46 | layer: "GCN" 47 | } 48 | } 49 | layer { 50 | name: "wavelet" 51 | type: "Python" 52 | bottom: "gcn_data" 53 | top: "wavelet_level1" 54 | top: "wavelet_level2" 55 | top: "wavelet_level3" 56 | top: "wavelet_level4" 57 | python_param { 58 | module: "pylayers" 59 | layer: "WaveletHaarLevelLayer" 60 | param_str: "4" 61 | } 62 | } 63 | layer { 64 | name: "conv1" 65 | type: "Convolution" 66 | bottom: "wavelet_level1" 67 | top: "conv1" 68 | convolution_param { 69 | num_output: 64 70 | kernel_size: 3 71 | pad: 1 72 | weight_filler { 73 | type: "msra" 74 | } 75 | bias_filler { 76 | type: "constant" 77 | } 78 | } 79 | } 80 | layer { 81 | name: "norm1" 82 | type: "BatchNorm" 83 | bottom: "conv1" 84 | top: "norm1" 85 | include { 86 | phase: TRAIN 87 | } 88 | batch_norm_param { 89 | use_global_stats: false 90 | moving_average_fraction: 0.999 91 | } 92 | param { lr_mult: 0 } 93 | param { lr_mult: 0 } 94 | param { lr_mult: 0 } 95 | } 96 | layer { 97 | name: "norm1_scale" 98 | type: "Scale" 99 | bottom: "norm1" 100 | top: "norm1" 101 | include { 102 | phase: TRAIN 103 | } 104 | scale_param { 105 | bias_term: true 106 | axis: 1 107 | num_axes: 1 108 | filler { 109 | type: "constant" 110 | value: 1 111 | } 112 | bias_filler { 113 | type: "constant" 114 | value: 0 115 | } 116 | } 117 | } 118 | layer { 119 | name: "norm1" 120 | type: "BatchNorm" 121 | bottom: "conv1" 122 | top: "norm1" 123 | include { 124 | phase: TEST 125 | } 126 | batch_norm_param { 127 | use_global_stats: true 128 | } 129 | param { lr_mult: 0 } 130 | param { lr_mult: 0 } 131 | param { lr_mult: 0 } 132 | } 133 | layer { 134 | name: "norm1_scale" 135 | type: "Scale" 136 | bottom: "norm1" 137 | top: "norm1" 138 | include { 139 | phase: TEST 140 | } 141 | scale_param { 142 | bias_term: true 143 | axis: 1 144 | num_axes: 1 145 | } 146 | } 147 | layer { 148 | name: "relu1" 149 | bottom: "norm1" 150 | type: "ReLU" 151 | top: "norm1" 152 | } 153 | layer { 154 | name: "conv1_2" 155 | type: "Convolution" 156 | bottom: "norm1" 157 | top: "conv1_2" 158 | convolution_param { 159 | num_output: 64 160 | kernel_size: 3 161 | pad: 1 162 | stride: 2 163 | weight_filler { 164 | type: "msra" 165 | } 166 | bias_filler { 167 | type: "constant" 168 | } 169 | } 170 | } 171 | layer { 172 | name: "norm1_2" 173 | type: "BatchNorm" 174 | bottom: "conv1_2" 175 | top: "norm1_2" 176 | include { 177 | phase: TRAIN 178 | } 179 | batch_norm_param { 180 | use_global_stats: false 181 | moving_average_fraction: 0.999 182 | } 183 | param { lr_mult: 0 } 184 | param { lr_mult: 0 } 185 | param { lr_mult: 0 } 186 | } 187 | layer { 188 | name: "norm1_2_scale" 189 | type: "Scale" 190 | bottom: "norm1_2" 191 | top: "norm1_2" 192 | include { 193 | phase: TRAIN 194 | } 195 | scale_param { 196 | bias_term: true 197 | axis: 1 198 | num_axes: 1 199 | filler { 200 | type: "constant" 201 | value: 1 202 | } 203 | bias_filler { 204 | type: "constant" 205 | value: 0 206 | } 207 | } 208 | } 209 | layer { 210 | name: "norm1_2" 211 | type: "BatchNorm" 212 | bottom: "conv1_2" 213 | top: "norm1_2" 214 | include { 215 | phase: TEST 216 | } 217 | batch_norm_param { 218 | use_global_stats: true 219 | } 220 | param { lr_mult: 0 } 221 | param { lr_mult: 0 } 222 | param { lr_mult: 0 } 223 | } 224 | layer { 225 | name: "norm1_2_scale" 226 | type: "Scale" 227 | bottom: "norm1_2" 228 | top: "norm1_2" 229 | include { 230 | phase: TEST 231 | } 232 | scale_param { 233 | bias_term: true 234 | axis: 1 235 | num_axes: 1 236 | } 237 | } 238 | layer { 239 | name: "relu1_2" 240 | bottom: "norm1_2" 241 | type: "ReLU" 242 | top: "norm1_2" 243 | } 244 | layer { 245 | name: "conv_a" 246 | type: "Convolution" 247 | bottom: "wavelet_level2" 248 | top: "conv_a" 249 | convolution_param { 250 | num_output: 64 251 | kernel_size: 3 252 | pad: 1 253 | weight_filler { 254 | type: "msra" 255 | } 256 | bias_filler { 257 | type: "constant" 258 | } 259 | } 260 | } 261 | layer { 262 | name: "norm_a" 263 | type: "BatchNorm" 264 | bottom: "conv_a" 265 | top: "norm_a" 266 | include { 267 | phase: TRAIN 268 | } 269 | batch_norm_param { 270 | use_global_stats: false 271 | moving_average_fraction: 0.999 272 | } 273 | param { lr_mult: 0 } 274 | param { lr_mult: 0 } 275 | param { lr_mult: 0 } 276 | } 277 | layer { 278 | name: "norm_a_scale" 279 | type: "Scale" 280 | bottom: "norm_a" 281 | top: "norm_a" 282 | include { 283 | phase: TRAIN 284 | } 285 | scale_param { 286 | bias_term: true 287 | axis: 1 288 | num_axes: 1 289 | filler { 290 | type: "constant" 291 | value: 1 292 | } 293 | bias_filler { 294 | type: "constant" 295 | value: 0 296 | } 297 | } 298 | } 299 | layer { 300 | name: "norm_a" 301 | type: "BatchNorm" 302 | bottom: "conv_a" 303 | top: "norm_a" 304 | include { 305 | phase: TEST 306 | } 307 | batch_norm_param { 308 | use_global_stats: true 309 | } 310 | param { lr_mult: 0 } 311 | param { lr_mult: 0 } 312 | param { lr_mult: 0 } 313 | } 314 | layer { 315 | name: "norm_a_scale" 316 | type: "Scale" 317 | bottom: "norm_a" 318 | top: "norm_a" 319 | include { 320 | phase: TEST 321 | } 322 | scale_param { 323 | bias_term: true 324 | axis: 1 325 | num_axes: 1 326 | } 327 | } 328 | layer { 329 | name: "relu_a" 330 | bottom: "norm_a" 331 | type: "ReLU" 332 | top: "norm_a" 333 | } 334 | layer { 335 | name: "concat_level2" 336 | type: "Concat" 337 | bottom: "norm1_2" 338 | bottom: "norm_a" 339 | top: "concat_level2" 340 | concat_param { 341 | axis: 1 342 | } 343 | } 344 | layer { 345 | name: "conv2" 346 | type: "Convolution" 347 | bottom: "concat_level2" 348 | top: "conv2" 349 | convolution_param { 350 | num_output: 128 351 | kernel_size: 3 352 | pad: 1 353 | weight_filler { 354 | type: "msra" 355 | } 356 | bias_filler { 357 | type: "constant" 358 | } 359 | } 360 | } 361 | layer { 362 | name: "norm2" 363 | type: "BatchNorm" 364 | bottom: "conv2" 365 | top: "norm2" 366 | include { 367 | phase: TRAIN 368 | } 369 | batch_norm_param { 370 | use_global_stats: false 371 | moving_average_fraction: 0.999 372 | } 373 | param { lr_mult: 0 } 374 | param { lr_mult: 0 } 375 | param { lr_mult: 0 } 376 | } 377 | layer { 378 | name: "norm2_scale" 379 | type: "Scale" 380 | bottom: "norm2" 381 | top: "norm2" 382 | include { 383 | phase: TRAIN 384 | } 385 | scale_param { 386 | bias_term: true 387 | axis: 1 388 | num_axes: 1 389 | filler { 390 | type: "constant" 391 | value: 1 392 | } 393 | bias_filler { 394 | type: "constant" 395 | value: 0 396 | } 397 | } 398 | } 399 | layer { 400 | name: "norm2" 401 | type: "BatchNorm" 402 | bottom: "conv2" 403 | top: "norm2" 404 | include { 405 | phase: TEST 406 | } 407 | batch_norm_param { 408 | use_global_stats: true 409 | } 410 | param { lr_mult: 0 } 411 | param { lr_mult: 0 } 412 | param { lr_mult: 0 } 413 | } 414 | layer { 415 | name: "norm2_scale" 416 | type: "Scale" 417 | bottom: "norm2" 418 | top: "norm2" 419 | include { 420 | phase: TEST 421 | } 422 | scale_param { 423 | bias_term: true 424 | axis: 1 425 | num_axes: 1 426 | } 427 | } 428 | layer { 429 | name: "relu2" 430 | bottom: "norm2" 431 | type: "ReLU" 432 | top: "norm2" 433 | } 434 | layer { 435 | name: "conv2_2" 436 | type: "Convolution" 437 | bottom: "norm2" 438 | top: "conv2_2" 439 | convolution_param { 440 | num_output: 128 441 | kernel_size: 3 442 | pad: 1 443 | stride: 2 444 | weight_filler { 445 | type: "msra" 446 | } 447 | bias_filler { 448 | type: "constant" 449 | } 450 | } 451 | } 452 | layer { 453 | name: "norm2_2" 454 | type: "BatchNorm" 455 | bottom: "conv2_2" 456 | top: "norm2_2" 457 | include { 458 | phase: TRAIN 459 | } 460 | batch_norm_param { 461 | use_global_stats: false 462 | moving_average_fraction: 0.999 463 | } 464 | param { lr_mult: 0 } 465 | param { lr_mult: 0 } 466 | param { lr_mult: 0 } 467 | } 468 | layer { 469 | name: "norm2_2_scale" 470 | type: "Scale" 471 | bottom: "norm2_2" 472 | top: "norm2_2" 473 | include { 474 | phase: TRAIN 475 | } 476 | scale_param { 477 | bias_term: true 478 | axis: 1 479 | num_axes: 1 480 | filler { 481 | type: "constant" 482 | value: 1 483 | } 484 | bias_filler { 485 | type: "constant" 486 | value: 0 487 | } 488 | } 489 | } 490 | layer { 491 | name: "norm2_2" 492 | type: "BatchNorm" 493 | bottom: "conv2_2" 494 | top: "norm2_2" 495 | include { 496 | phase: TEST 497 | } 498 | batch_norm_param { 499 | use_global_stats: true 500 | } 501 | param { lr_mult: 0 } 502 | param { lr_mult: 0 } 503 | param { lr_mult: 0 } 504 | } 505 | layer { 506 | name: "norm2_2_scale" 507 | type: "Scale" 508 | bottom: "norm2_2" 509 | top: "norm2_2" 510 | include { 511 | phase: TEST 512 | } 513 | scale_param { 514 | bias_term: true 515 | axis: 1 516 | num_axes: 1 517 | } 518 | } 519 | layer { 520 | name: "relu2_2" 521 | bottom: "norm2_2" 522 | type: "ReLU" 523 | top: "norm2_2" 524 | } 525 | layer { 526 | name: "conv_b" 527 | type: "Convolution" 528 | bottom: "wavelet_level3" 529 | top: "conv_b" 530 | convolution_param { 531 | num_output: 128 532 | kernel_size: 3 533 | pad: 1 534 | weight_filler { 535 | type: "msra" 536 | } 537 | bias_filler { 538 | type: "constant" 539 | } 540 | } 541 | } 542 | layer { 543 | name: "norm_b" 544 | type: "BatchNorm" 545 | bottom: "conv_b" 546 | top: "norm_b" 547 | include { 548 | phase: TRAIN 549 | } 550 | batch_norm_param { 551 | use_global_stats: false 552 | moving_average_fraction: 0.999 553 | } 554 | param { lr_mult: 0 } 555 | param { lr_mult: 0 } 556 | param { lr_mult: 0 } 557 | } 558 | layer { 559 | name: "norm_b_scale" 560 | type: "Scale" 561 | bottom: "norm_b" 562 | top: "norm_b" 563 | include { 564 | phase: TRAIN 565 | } 566 | scale_param { 567 | bias_term: true 568 | axis: 1 569 | num_axes: 1 570 | filler { 571 | type: "constant" 572 | value: 1 573 | } 574 | bias_filler { 575 | type: "constant" 576 | value: 0 577 | } 578 | } 579 | } 580 | layer { 581 | name: "norm_b" 582 | type: "BatchNorm" 583 | bottom: "conv_b" 584 | top: "norm_b" 585 | include { 586 | phase: TEST 587 | } 588 | batch_norm_param { 589 | use_global_stats: true 590 | } 591 | param { lr_mult: 0 } 592 | param { lr_mult: 0 } 593 | param { lr_mult: 0 } 594 | } 595 | layer { 596 | name: "norm_b_scale" 597 | type: "Scale" 598 | bottom: "norm_b" 599 | top: "norm_b" 600 | include { 601 | phase: TEST 602 | } 603 | scale_param { 604 | bias_term: true 605 | axis: 1 606 | num_axes: 1 607 | } 608 | } 609 | layer { 610 | name: "relu_b" 611 | bottom: "norm_b" 612 | type: "ReLU" 613 | top: "norm_b" 614 | } 615 | layer { 616 | name: "conv_b_2" 617 | type: "Convolution" 618 | bottom: "norm_b" 619 | top: "conv_b_2" 620 | convolution_param { 621 | num_output: 128 622 | kernel_size: 3 623 | pad: 1 624 | weight_filler { 625 | type: "msra" 626 | } 627 | bias_filler { 628 | type: "constant" 629 | } 630 | } 631 | } 632 | layer { 633 | name: "norm_b_2" 634 | type: "BatchNorm" 635 | bottom: "conv_b_2" 636 | top: "norm_b_2" 637 | include { 638 | phase: TRAIN 639 | } 640 | batch_norm_param { 641 | use_global_stats: false 642 | moving_average_fraction: 0.999 643 | } 644 | param { lr_mult: 0 } 645 | param { lr_mult: 0 } 646 | param { lr_mult: 0 } 647 | } 648 | layer { 649 | name: "norm_b_2_scale" 650 | type: "Scale" 651 | bottom: "norm_b_2" 652 | top: "norm_b_2" 653 | include { 654 | phase: TRAIN 655 | } 656 | scale_param { 657 | bias_term: true 658 | axis: 1 659 | num_axes: 1 660 | filler { 661 | type: "constant" 662 | value: 1 663 | } 664 | bias_filler { 665 | type: "constant" 666 | value: 0 667 | } 668 | } 669 | } 670 | layer { 671 | name: "norm_b_2" 672 | type: "BatchNorm" 673 | bottom: "conv_b_2" 674 | top: "norm_b_2" 675 | include { 676 | phase: TEST 677 | } 678 | batch_norm_param { 679 | use_global_stats: true 680 | } 681 | param { lr_mult: 0 } 682 | param { lr_mult: 0 } 683 | param { lr_mult: 0 } 684 | } 685 | layer { 686 | name: "norm_b_2_scale" 687 | type: "Scale" 688 | bottom: "norm_b_2" 689 | top: "norm_b_2" 690 | include { 691 | phase: TEST 692 | } 693 | scale_param { 694 | bias_term: true 695 | axis: 1 696 | num_axes: 1 697 | } 698 | } 699 | layer { 700 | name: "relu_b_2" 701 | bottom: "norm_b_2" 702 | type: "ReLU" 703 | top: "norm_b_2" 704 | } 705 | layer { 706 | name: "concat_level3" 707 | type: "Concat" 708 | bottom: "norm2_2" 709 | bottom: "norm_b_2" 710 | top: "concat_level3" 711 | concat_param { 712 | axis: 1 713 | } 714 | } 715 | layer { 716 | name: "conv3" 717 | type: "Convolution" 718 | bottom: "concat_level3" 719 | top: "conv3" 720 | convolution_param { 721 | num_output: 256 722 | kernel_size: 3 723 | pad: 1 724 | weight_filler { 725 | type: "msra" 726 | } 727 | bias_filler { 728 | type: "constant" 729 | } 730 | } 731 | } 732 | layer { 733 | name: "norm3" 734 | type: "BatchNorm" 735 | bottom: "conv3" 736 | top: "norm3" 737 | include { 738 | phase: TRAIN 739 | } 740 | batch_norm_param { 741 | use_global_stats: false 742 | moving_average_fraction: 0.999 743 | } 744 | param { lr_mult: 0 } 745 | param { lr_mult: 0 } 746 | param { lr_mult: 0 } 747 | } 748 | layer { 749 | name: "norm3_scale" 750 | type: "Scale" 751 | bottom: "norm3" 752 | top: "norm3" 753 | include { 754 | phase: TRAIN 755 | } 756 | scale_param { 757 | bias_term: true 758 | axis: 1 759 | num_axes: 1 760 | filler { 761 | type: "constant" 762 | value: 1 763 | } 764 | bias_filler { 765 | type: "constant" 766 | value: 0 767 | } 768 | } 769 | } 770 | layer { 771 | name: "norm3" 772 | type: "BatchNorm" 773 | bottom: "conv3" 774 | top: "norm3" 775 | include { 776 | phase: TEST 777 | } 778 | batch_norm_param { 779 | use_global_stats: true 780 | } 781 | param { lr_mult: 0 } 782 | param { lr_mult: 0 } 783 | param { lr_mult: 0 } 784 | } 785 | layer { 786 | name: "norm3_scale" 787 | type: "Scale" 788 | bottom: "norm3" 789 | top: "norm3" 790 | include { 791 | phase: TEST 792 | } 793 | scale_param { 794 | bias_term: true 795 | axis: 1 796 | num_axes: 1 797 | } 798 | } 799 | layer { 800 | name: "relu3" 801 | bottom: "norm3" 802 | type: "ReLU" 803 | top: "norm3" 804 | } 805 | layer { 806 | name: "conv3_2" 807 | type: "Convolution" 808 | bottom: "norm3" 809 | top: "conv3_2" 810 | convolution_param { 811 | num_output: 256 812 | kernel_size: 3 813 | pad: 1 814 | stride: 2 815 | weight_filler { 816 | type: "msra" 817 | } 818 | bias_filler { 819 | type: "constant" 820 | } 821 | } 822 | } 823 | layer { 824 | name: "norm3_2" 825 | type: "BatchNorm" 826 | bottom: "conv3_2" 827 | top: "norm3_2" 828 | include { 829 | phase: TRAIN 830 | } 831 | batch_norm_param { 832 | use_global_stats: false 833 | moving_average_fraction: 0.999 834 | } 835 | param { lr_mult: 0 } 836 | param { lr_mult: 0 } 837 | param { lr_mult: 0 } 838 | } 839 | layer { 840 | name: "norm3_2_scale" 841 | type: "Scale" 842 | bottom: "norm3_2" 843 | top: "norm3_2" 844 | include { 845 | phase: TRAIN 846 | } 847 | scale_param { 848 | bias_term: true 849 | axis: 1 850 | num_axes: 1 851 | filler { 852 | type: "constant" 853 | value: 1 854 | } 855 | bias_filler { 856 | type: "constant" 857 | value: 0 858 | } 859 | } 860 | } 861 | layer { 862 | name: "norm3_2" 863 | type: "BatchNorm" 864 | bottom: "conv3_2" 865 | top: "norm3_2" 866 | include { 867 | phase: TEST 868 | } 869 | batch_norm_param { 870 | use_global_stats: true 871 | } 872 | param { lr_mult: 0 } 873 | param { lr_mult: 0 } 874 | param { lr_mult: 0 } 875 | } 876 | layer { 877 | name: "norm3_2_scale" 878 | type: "Scale" 879 | bottom: "norm3_2" 880 | top: "norm3_2" 881 | include { 882 | phase: TEST 883 | } 884 | scale_param { 885 | bias_term: true 886 | axis: 1 887 | num_axes: 1 888 | } 889 | } 890 | layer { 891 | name: "relu3_2" 892 | bottom: "norm3_2" 893 | type: "ReLU" 894 | top: "norm3_2" 895 | } 896 | layer { 897 | name: "conv_c" 898 | type: "Convolution" 899 | bottom: "wavelet_level4" 900 | top: "conv_c" 901 | convolution_param { 902 | num_output: 256 903 | kernel_size: 3 904 | pad: 1 905 | weight_filler { 906 | type: "msra" 907 | } 908 | bias_filler { 909 | type: "constant" 910 | } 911 | } 912 | } 913 | layer { 914 | name: "norm_c" 915 | type: "BatchNorm" 916 | bottom: "conv_c" 917 | top: "norm_c" 918 | include { 919 | phase: TRAIN 920 | } 921 | batch_norm_param { 922 | use_global_stats: false 923 | moving_average_fraction: 0.999 924 | } 925 | param { lr_mult: 0 } 926 | param { lr_mult: 0 } 927 | param { lr_mult: 0 } 928 | } 929 | layer { 930 | name: "norm_c_scale" 931 | type: "Scale" 932 | bottom: "norm_c" 933 | top: "norm_c" 934 | include { 935 | phase: TRAIN 936 | } 937 | scale_param { 938 | bias_term: true 939 | axis: 1 940 | num_axes: 1 941 | filler { 942 | type: "constant" 943 | value: 1 944 | } 945 | bias_filler { 946 | type: "constant" 947 | value: 0 948 | } 949 | } 950 | } 951 | layer { 952 | name: "norm_c" 953 | type: "BatchNorm" 954 | bottom: "conv_c" 955 | top: "norm_c" 956 | include { 957 | phase: TEST 958 | } 959 | batch_norm_param { 960 | use_global_stats: true 961 | } 962 | param { lr_mult: 0 } 963 | param { lr_mult: 0 } 964 | param { lr_mult: 0 } 965 | } 966 | layer { 967 | name: "norm_c_scale" 968 | type: "Scale" 969 | bottom: "norm_c" 970 | top: "norm_c" 971 | include { 972 | phase: TEST 973 | } 974 | scale_param { 975 | bias_term: true 976 | axis: 1 977 | num_axes: 1 978 | } 979 | } 980 | layer { 981 | name: "relu_c" 982 | bottom: "norm_c" 983 | type: "ReLU" 984 | top: "norm_c" 985 | } 986 | layer { 987 | name: "conv_c_2" 988 | type: "Convolution" 989 | bottom: "norm_c" 990 | top: "conv_c_2" 991 | convolution_param { 992 | num_output: 256 993 | kernel_size: 3 994 | pad: 1 995 | weight_filler { 996 | type: "msra" 997 | } 998 | bias_filler { 999 | type: "constant" 1000 | } 1001 | } 1002 | } 1003 | layer { 1004 | name: "norm_c_2" 1005 | type: "BatchNorm" 1006 | bottom: "conv_c_2" 1007 | top: "norm_c_2" 1008 | include { 1009 | phase: TRAIN 1010 | } 1011 | batch_norm_param { 1012 | use_global_stats: false 1013 | moving_average_fraction: 0.999 1014 | } 1015 | param { lr_mult: 0 } 1016 | param { lr_mult: 0 } 1017 | param { lr_mult: 0 } 1018 | } 1019 | layer { 1020 | name: "norm_c_2_scale" 1021 | type: "Scale" 1022 | bottom: "norm_c_2" 1023 | top: "norm_c_2" 1024 | include { 1025 | phase: TRAIN 1026 | } 1027 | scale_param { 1028 | bias_term: true 1029 | axis: 1 1030 | num_axes: 1 1031 | filler { 1032 | type: "constant" 1033 | value: 1 1034 | } 1035 | bias_filler { 1036 | type: "constant" 1037 | value: 0 1038 | } 1039 | } 1040 | } 1041 | layer { 1042 | name: "norm_c_2" 1043 | type: "BatchNorm" 1044 | bottom: "conv_c_2" 1045 | top: "norm_c_2" 1046 | include { 1047 | phase: TEST 1048 | } 1049 | batch_norm_param { 1050 | use_global_stats: true 1051 | } 1052 | param { lr_mult: 0 } 1053 | param { lr_mult: 0 } 1054 | param { lr_mult: 0 } 1055 | } 1056 | layer { 1057 | name: "norm_c_2_scale" 1058 | type: "Scale" 1059 | bottom: "norm_c_2" 1060 | top: "norm_c_2" 1061 | include { 1062 | phase: TEST 1063 | } 1064 | scale_param { 1065 | bias_term: true 1066 | axis: 1 1067 | num_axes: 1 1068 | } 1069 | } 1070 | layer { 1071 | name: "relu_c_2" 1072 | bottom: "norm_c_2" 1073 | type: "ReLU" 1074 | top: "norm_c_2" 1075 | } 1076 | layer { 1077 | name: "conv_c_3" 1078 | type: "Convolution" 1079 | bottom: "norm_c_2" 1080 | top: "conv_c_3" 1081 | convolution_param { 1082 | num_output: 256 1083 | kernel_size: 3 1084 | pad: 1 1085 | weight_filler { 1086 | type: "msra" 1087 | } 1088 | bias_filler { 1089 | type: "constant" 1090 | } 1091 | } 1092 | } 1093 | layer { 1094 | name: "norm_c_3" 1095 | type: "BatchNorm" 1096 | bottom: "conv_c_3" 1097 | top: "norm_c_3" 1098 | include { 1099 | phase: TRAIN 1100 | } 1101 | batch_norm_param { 1102 | use_global_stats: false 1103 | moving_average_fraction: 0.999 1104 | } 1105 | param { lr_mult: 0 } 1106 | param { lr_mult: 0 } 1107 | param { lr_mult: 0 } 1108 | } 1109 | layer { 1110 | name: "norm_c_3_scale" 1111 | type: "Scale" 1112 | bottom: "norm_c_3" 1113 | top: "norm_c_3" 1114 | include { 1115 | phase: TRAIN 1116 | } 1117 | scale_param { 1118 | bias_term: true 1119 | axis: 1 1120 | num_axes: 1 1121 | filler { 1122 | type: "constant" 1123 | value: 1 1124 | } 1125 | bias_filler { 1126 | type: "constant" 1127 | value: 0 1128 | } 1129 | } 1130 | } 1131 | layer { 1132 | name: "norm_c_3" 1133 | type: "BatchNorm" 1134 | bottom: "conv_c_3" 1135 | top: "norm_c_3" 1136 | include { 1137 | phase: TEST 1138 | } 1139 | batch_norm_param { 1140 | use_global_stats: true 1141 | } 1142 | param { lr_mult: 0 } 1143 | param { lr_mult: 0 } 1144 | param { lr_mult: 0 } 1145 | } 1146 | layer { 1147 | name: "norm_c_3_scale" 1148 | type: "Scale" 1149 | bottom: "norm_c_3" 1150 | top: "norm_c_3" 1151 | include { 1152 | phase: TEST 1153 | } 1154 | scale_param { 1155 | bias_term: true 1156 | axis: 1 1157 | num_axes: 1 1158 | } 1159 | } 1160 | layer { 1161 | name: "relu_c_3" 1162 | bottom: "norm_c_3" 1163 | type: "ReLU" 1164 | top: "norm_c_3" 1165 | } 1166 | layer { 1167 | name: "concat_level4" 1168 | type: "Concat" 1169 | bottom: "norm3_2" 1170 | bottom: "norm_c_3" 1171 | top: "concat_level4" 1172 | concat_param { 1173 | axis: 1 1174 | } 1175 | } 1176 | layer { 1177 | name: "conv4" 1178 | type: "Convolution" 1179 | bottom: "concat_level4" 1180 | top: "conv4" 1181 | convolution_param { 1182 | num_output: 256 1183 | kernel_size: 3 1184 | pad: 1 1185 | weight_filler { 1186 | type: "msra" 1187 | } 1188 | bias_filler { 1189 | type: "constant" 1190 | } 1191 | } 1192 | } 1193 | layer { 1194 | name: "norm4" 1195 | type: "BatchNorm" 1196 | bottom: "conv4" 1197 | top: "norm4" 1198 | include { 1199 | phase: TRAIN 1200 | } 1201 | batch_norm_param { 1202 | use_global_stats: false 1203 | moving_average_fraction: 0.999 1204 | } 1205 | param { lr_mult: 0 } 1206 | param { lr_mult: 0 } 1207 | param { lr_mult: 0 } 1208 | } 1209 | layer { 1210 | name: "norm4_scale" 1211 | type: "Scale" 1212 | bottom: "norm4" 1213 | top: "norm4" 1214 | include { 1215 | phase: TRAIN 1216 | } 1217 | scale_param { 1218 | bias_term: true 1219 | axis: 1 1220 | num_axes: 1 1221 | filler { 1222 | type: "constant" 1223 | value: 1 1224 | } 1225 | bias_filler { 1226 | type: "constant" 1227 | value: 0 1228 | } 1229 | } 1230 | } 1231 | layer { 1232 | name: "norm4" 1233 | type: "BatchNorm" 1234 | bottom: "conv4" 1235 | top: "norm4" 1236 | include { 1237 | phase: TEST 1238 | } 1239 | batch_norm_param { 1240 | use_global_stats: true 1241 | } 1242 | param { lr_mult: 0 } 1243 | param { lr_mult: 0 } 1244 | param { lr_mult: 0 } 1245 | } 1246 | layer { 1247 | name: "norm4_scale" 1248 | type: "Scale" 1249 | bottom: "norm4" 1250 | top: "norm4" 1251 | include { 1252 | phase: TEST 1253 | } 1254 | scale_param { 1255 | bias_term: true 1256 | axis: 1 1257 | num_axes: 1 1258 | } 1259 | } 1260 | layer { 1261 | name: "relu4" 1262 | bottom: "norm4" 1263 | type: "ReLU" 1264 | top: "norm4" 1265 | } 1266 | layer { 1267 | name: "conv4_2" 1268 | type: "Convolution" 1269 | bottom: "norm4" 1270 | top: "conv4_2" 1271 | convolution_param { 1272 | num_output: 256 1273 | kernel_size: 3 1274 | pad: 1 1275 | stride: 2 1276 | weight_filler { 1277 | type: "msra" 1278 | } 1279 | bias_filler { 1280 | type: "constant" 1281 | } 1282 | } 1283 | } 1284 | layer { 1285 | name: "norm4_2" 1286 | type: "BatchNorm" 1287 | bottom: "conv4_2" 1288 | top: "norm4_2" 1289 | include { 1290 | phase: TRAIN 1291 | } 1292 | batch_norm_param { 1293 | use_global_stats: false 1294 | moving_average_fraction: 0.999 1295 | } 1296 | param { lr_mult: 0 } 1297 | param { lr_mult: 0 } 1298 | param { lr_mult: 0 } 1299 | } 1300 | layer { 1301 | name: "norm4_2_scale" 1302 | type: "Scale" 1303 | bottom: "norm4_2" 1304 | top: "norm4_2" 1305 | include { 1306 | phase: TRAIN 1307 | } 1308 | scale_param { 1309 | bias_term: true 1310 | axis: 1 1311 | num_axes: 1 1312 | filler { 1313 | type: "constant" 1314 | value: 1 1315 | } 1316 | bias_filler { 1317 | type: "constant" 1318 | value: 0 1319 | } 1320 | } 1321 | } 1322 | layer { 1323 | name: "norm4_2" 1324 | type: "BatchNorm" 1325 | bottom: "conv4_2" 1326 | top: "norm4_2" 1327 | include { 1328 | phase: TEST 1329 | } 1330 | batch_norm_param { 1331 | use_global_stats: true 1332 | } 1333 | param { lr_mult: 0 } 1334 | param { lr_mult: 0 } 1335 | param { lr_mult: 0 } 1336 | } 1337 | layer { 1338 | name: "norm4_2_scale" 1339 | type: "Scale" 1340 | bottom: "norm4_2" 1341 | top: "norm4_2" 1342 | include { 1343 | phase: TEST 1344 | } 1345 | scale_param { 1346 | bias_term: true 1347 | axis: 1 1348 | num_axes: 1 1349 | } 1350 | } 1351 | layer { 1352 | name: "relu4_2" 1353 | bottom: "norm4_2" 1354 | type: "ReLU" 1355 | top: "norm4_2" 1356 | } 1357 | layer { 1358 | name: "conv5_1" 1359 | type: "Convolution" 1360 | bottom: "norm4_2" 1361 | top: "conv5_1" 1362 | convolution_param { 1363 | num_output: 128 1364 | kernel_size: 3 1365 | pad: 1 1366 | weight_filler { 1367 | type: "msra" 1368 | } 1369 | bias_filler { 1370 | type: "constant" 1371 | } 1372 | } 1373 | } 1374 | layer { 1375 | name: "norm5_1" 1376 | type: "BatchNorm" 1377 | bottom: "conv5_1" 1378 | top: "norm5_1" 1379 | include { 1380 | phase: TRAIN 1381 | } 1382 | batch_norm_param { 1383 | use_global_stats: false 1384 | moving_average_fraction: 0.999 1385 | } 1386 | param { lr_mult: 0 } 1387 | param { lr_mult: 0 } 1388 | param { lr_mult: 0 } 1389 | } 1390 | layer { 1391 | name: "norm5_1_scale" 1392 | type: "Scale" 1393 | bottom: "norm5_1" 1394 | top: "norm5_1" 1395 | include { 1396 | phase: TRAIN 1397 | } 1398 | scale_param { 1399 | bias_term: true 1400 | axis: 1 1401 | num_axes: 1 1402 | filler { 1403 | type: "constant" 1404 | value: 1 1405 | } 1406 | bias_filler { 1407 | type: "constant" 1408 | value: 0 1409 | } 1410 | } 1411 | } 1412 | layer { 1413 | name: "norm5_1" 1414 | type: "BatchNorm" 1415 | bottom: "conv5_1" 1416 | top: "norm5_1" 1417 | include { 1418 | phase: TEST 1419 | } 1420 | batch_norm_param { 1421 | use_global_stats: true 1422 | } 1423 | param { lr_mult: 0 } 1424 | param { lr_mult: 0 } 1425 | param { lr_mult: 0 } 1426 | } 1427 | layer { 1428 | name: "norm5_1_scale" 1429 | type: "Scale" 1430 | bottom: "norm5_1" 1431 | top: "norm5_1" 1432 | include { 1433 | phase: TEST 1434 | } 1435 | scale_param { 1436 | bias_term: true 1437 | axis: 1 1438 | num_axes: 1 1439 | } 1440 | } 1441 | layer { 1442 | name: "relu5_1" 1443 | bottom: "norm5_1" 1444 | type: "ReLU" 1445 | top: "norm5_1" 1446 | } 1447 | layer { 1448 | name: "pool5_1" 1449 | type: "Pooling" 1450 | bottom: "norm5_1" 1451 | top: "pool5_1" 1452 | pooling_param { 1453 | pool: AVE 1454 | kernel_size: 7 1455 | stride: 1 1456 | } 1457 | } 1458 | layer { 1459 | name: "fc5" 1460 | type: "InnerProduct" 1461 | bottom: "pool5_1" 1462 | top: "fc5" 1463 | inner_product_param { 1464 | num_output: 2048 1465 | weight_filler { 1466 | type: "msra" 1467 | } 1468 | bias_filler { 1469 | type: "constant" 1470 | } 1471 | } 1472 | } 1473 | layer { 1474 | name: "norm5" 1475 | type: "BatchNorm" 1476 | bottom: "fc5" 1477 | top: "norm5" 1478 | include { 1479 | phase: TRAIN 1480 | } 1481 | batch_norm_param { 1482 | use_global_stats: false 1483 | moving_average_fraction: 0.999 1484 | } 1485 | param { lr_mult: 0 } 1486 | param { lr_mult: 0 } 1487 | param { lr_mult: 0 } 1488 | } 1489 | layer { 1490 | name: "norm5_scale" 1491 | type: "Scale" 1492 | bottom: "norm5" 1493 | top: "norm5" 1494 | include { 1495 | phase: TRAIN 1496 | } 1497 | scale_param { 1498 | bias_term: true 1499 | axis: 1 1500 | num_axes: 1 1501 | filler { 1502 | type: "constant" 1503 | value: 1 1504 | } 1505 | bias_filler { 1506 | type: "constant" 1507 | value: 0 1508 | } 1509 | } 1510 | } 1511 | layer { 1512 | name: "norm5" 1513 | type: "BatchNorm" 1514 | bottom: "fc5" 1515 | top: "norm5" 1516 | include { 1517 | phase: TEST 1518 | } 1519 | batch_norm_param { 1520 | use_global_stats: true 1521 | } 1522 | param { lr_mult: 0 } 1523 | param { lr_mult: 0 } 1524 | param { lr_mult: 0 } 1525 | } 1526 | layer { 1527 | name: "norm5_scale" 1528 | type: "Scale" 1529 | bottom: "norm5" 1530 | top: "norm5" 1531 | include { 1532 | phase: TEST 1533 | } 1534 | scale_param { 1535 | bias_term: true 1536 | axis: 1 1537 | num_axes: 1 1538 | } 1539 | } 1540 | layer { 1541 | name: "relu5" 1542 | type: "ReLU" 1543 | bottom: "norm5" 1544 | top: "norm5" 1545 | } 1546 | layer { 1547 | name: "drop5" 1548 | type: "Dropout" 1549 | bottom: "norm5" 1550 | top: "norm5" 1551 | dropout_param { 1552 | dropout_ratio: 0.5 1553 | } 1554 | } 1555 | layer { 1556 | name: "fc6" 1557 | type: "InnerProduct" 1558 | bottom: "norm5" 1559 | top: "fc6" 1560 | inner_product_param { 1561 | num_output: 2048 1562 | weight_filler { 1563 | type: "msra" 1564 | } 1565 | bias_filler { 1566 | type: "constant" 1567 | } 1568 | } 1569 | } 1570 | layer { 1571 | name: "norm6" 1572 | type: "BatchNorm" 1573 | bottom: "fc6" 1574 | top: "norm6" 1575 | include { 1576 | phase: TRAIN 1577 | } 1578 | batch_norm_param { 1579 | use_global_stats: false 1580 | moving_average_fraction: 0.999 1581 | } 1582 | param { lr_mult: 0 } 1583 | param { lr_mult: 0 } 1584 | param { lr_mult: 0 } 1585 | } 1586 | layer { 1587 | name: "norm6_scale" 1588 | type: "Scale" 1589 | bottom: "norm6" 1590 | top: "norm6" 1591 | include { 1592 | phase: TRAIN 1593 | } 1594 | scale_param { 1595 | bias_term: true 1596 | axis: 1 1597 | num_axes: 1 1598 | filler { 1599 | type: "constant" 1600 | value: 1 1601 | } 1602 | bias_filler { 1603 | type: "constant" 1604 | value: 0 1605 | } 1606 | } 1607 | } 1608 | layer { 1609 | name: "norm6" 1610 | type: "BatchNorm" 1611 | bottom: "fc6" 1612 | top: "norm6" 1613 | include { 1614 | phase: TEST 1615 | } 1616 | batch_norm_param { 1617 | use_global_stats: true 1618 | } 1619 | param { lr_mult: 0 } 1620 | param { lr_mult: 0 } 1621 | param { lr_mult: 0 } 1622 | } 1623 | layer { 1624 | name: "norm6_scale" 1625 | type: "Scale" 1626 | bottom: "norm6" 1627 | top: "norm6" 1628 | include { 1629 | phase: TEST 1630 | } 1631 | scale_param { 1632 | bias_term: true 1633 | axis: 1 1634 | num_axes: 1 1635 | } 1636 | } 1637 | layer { 1638 | name: "relu6" 1639 | type: "ReLU" 1640 | bottom: "norm6" 1641 | top: "norm6" 1642 | } 1643 | layer { 1644 | name: "drop6" 1645 | type: "Dropout" 1646 | bottom: "norm6" 1647 | top: "norm6" 1648 | dropout_param { 1649 | dropout_ratio: 0.5 1650 | } 1651 | } 1652 | layer { 1653 | name: "fc7" 1654 | type: "InnerProduct" 1655 | bottom: "norm6" 1656 | top: "fc7" 1657 | inner_product_param { 1658 | num_output: 11 1659 | weight_filler { 1660 | type: "msra" 1661 | } 1662 | bias_filler { 1663 | type: "constant" 1664 | } 1665 | } 1666 | } 1667 | layer { 1668 | name: "accuracy" 1669 | type: "Accuracy" 1670 | bottom: "fc7" 1671 | bottom: "label" 1672 | top: "accuracy" 1673 | include { 1674 | phase: TEST 1675 | } 1676 | } 1677 | layer { 1678 | name: "loss" 1679 | type: "SoftmaxWithLoss" 1680 | bottom: "fc7" 1681 | bottom: "label" 1682 | top: "loss" 1683 | } 1684 | -------------------------------------------------------------------------------- /models/WaveletCNN_4level_deploy.prototxt: -------------------------------------------------------------------------------- 1 | name: "WaveletCNN_4level_decomp" 2 | force_backward: true 3 | input: "data" 4 | input_dim: 1 5 | input_dim: 3 6 | input_dim: 224 7 | input_dim: 224 8 | layer { 9 | name: "gcn_data" 10 | type: "Python" 11 | bottom: "data" 12 | top: "gcn_data" 13 | python_param { 14 | module: "pylayers" 15 | layer: "GCN" 16 | } 17 | } 18 | layer { 19 | name: "wavelet" 20 | type: "Python" 21 | bottom: "gcn_data" 22 | top: "wavelet_level1" 23 | top: "wavelet_level2" 24 | top: "wavelet_level3" 25 | top: "wavelet_level4" 26 | python_param { 27 | module: "pylayers" 28 | layer: "WaveletHaarLevelLayer" 29 | param_str: "4" 30 | } 31 | } 32 | layer { 33 | name: "conv1" 34 | type: "Convolution" 35 | bottom: "wavelet_level1" 36 | top: "conv1" 37 | convolution_param { 38 | num_output: 64 39 | kernel_size: 3 40 | pad: 1 41 | weight_filler { 42 | type: "msra" 43 | } 44 | bias_filler { 45 | type: "constant" 46 | } 47 | } 48 | } 49 | layer { 50 | name: "norm1" 51 | type: "BatchNorm" 52 | bottom: "conv1" 53 | top: "norm1" 54 | include { 55 | phase: TRAIN 56 | } 57 | batch_norm_param { 58 | use_global_stats: false 59 | moving_average_fraction: 0.999 60 | } 61 | param { lr_mult: 0 } 62 | param { lr_mult: 0 } 63 | param { lr_mult: 0 } 64 | } 65 | layer { 66 | name: "norm1_scale" 67 | type: "Scale" 68 | bottom: "norm1" 69 | top: "norm1" 70 | include { 71 | phase: TRAIN 72 | } 73 | scale_param { 74 | bias_term: true 75 | axis: 1 76 | num_axes: 1 77 | filler { 78 | type: "constant" 79 | value: 1 80 | } 81 | bias_filler { 82 | type: "constant" 83 | value: 0 84 | } 85 | } 86 | } 87 | layer { 88 | name: "norm1" 89 | type: "BatchNorm" 90 | bottom: "conv1" 91 | top: "norm1" 92 | include { 93 | phase: TEST 94 | } 95 | batch_norm_param { 96 | use_global_stats: true 97 | } 98 | param { lr_mult: 0 } 99 | param { lr_mult: 0 } 100 | param { lr_mult: 0 } 101 | } 102 | layer { 103 | name: "norm1_scale" 104 | type: "Scale" 105 | bottom: "norm1" 106 | top: "norm1" 107 | include { 108 | phase: TEST 109 | } 110 | scale_param { 111 | bias_term: true 112 | axis: 1 113 | num_axes: 1 114 | } 115 | } 116 | layer { 117 | name: "relu1" 118 | bottom: "norm1" 119 | type: "ReLU" 120 | top: "norm1" 121 | } 122 | layer { 123 | name: "conv1_2" 124 | type: "Convolution" 125 | bottom: "norm1" 126 | top: "conv1_2" 127 | convolution_param { 128 | num_output: 64 129 | kernel_size: 3 130 | pad: 1 131 | stride: 2 132 | weight_filler { 133 | type: "msra" 134 | } 135 | bias_filler { 136 | type: "constant" 137 | } 138 | } 139 | } 140 | layer { 141 | name: "norm1_2" 142 | type: "BatchNorm" 143 | bottom: "conv1_2" 144 | top: "norm1_2" 145 | include { 146 | phase: TRAIN 147 | } 148 | batch_norm_param { 149 | use_global_stats: false 150 | moving_average_fraction: 0.999 151 | } 152 | param { lr_mult: 0 } 153 | param { lr_mult: 0 } 154 | param { lr_mult: 0 } 155 | } 156 | layer { 157 | name: "norm1_2_scale" 158 | type: "Scale" 159 | bottom: "norm1_2" 160 | top: "norm1_2" 161 | include { 162 | phase: TRAIN 163 | } 164 | scale_param { 165 | bias_term: true 166 | axis: 1 167 | num_axes: 1 168 | filler { 169 | type: "constant" 170 | value: 1 171 | } 172 | bias_filler { 173 | type: "constant" 174 | value: 0 175 | } 176 | } 177 | } 178 | layer { 179 | name: "norm1_2" 180 | type: "BatchNorm" 181 | bottom: "conv1_2" 182 | top: "norm1_2" 183 | include { 184 | phase: TEST 185 | } 186 | batch_norm_param { 187 | use_global_stats: true 188 | } 189 | param { lr_mult: 0 } 190 | param { lr_mult: 0 } 191 | param { lr_mult: 0 } 192 | } 193 | layer { 194 | name: "norm1_2_scale" 195 | type: "Scale" 196 | bottom: "norm1_2" 197 | top: "norm1_2" 198 | include { 199 | phase: TEST 200 | } 201 | scale_param { 202 | bias_term: true 203 | axis: 1 204 | num_axes: 1 205 | } 206 | } 207 | layer { 208 | name: "relu1_2" 209 | bottom: "norm1_2" 210 | type: "ReLU" 211 | top: "norm1_2" 212 | } 213 | layer { 214 | name: "conv_a" 215 | type: "Convolution" 216 | bottom: "wavelet_level2" 217 | top: "conv_a" 218 | convolution_param { 219 | num_output: 64 220 | kernel_size: 3 221 | pad: 1 222 | weight_filler { 223 | type: "msra" 224 | } 225 | bias_filler { 226 | type: "constant" 227 | } 228 | } 229 | } 230 | layer { 231 | name: "norm_a" 232 | type: "BatchNorm" 233 | bottom: "conv_a" 234 | top: "norm_a" 235 | include { 236 | phase: TRAIN 237 | } 238 | batch_norm_param { 239 | use_global_stats: false 240 | moving_average_fraction: 0.999 241 | } 242 | param { lr_mult: 0 } 243 | param { lr_mult: 0 } 244 | param { lr_mult: 0 } 245 | } 246 | layer { 247 | name: "norm_a_scale" 248 | type: "Scale" 249 | bottom: "norm_a" 250 | top: "norm_a" 251 | include { 252 | phase: TRAIN 253 | } 254 | scale_param { 255 | bias_term: true 256 | axis: 1 257 | num_axes: 1 258 | filler { 259 | type: "constant" 260 | value: 1 261 | } 262 | bias_filler { 263 | type: "constant" 264 | value: 0 265 | } 266 | } 267 | } 268 | layer { 269 | name: "norm_a" 270 | type: "BatchNorm" 271 | bottom: "conv_a" 272 | top: "norm_a" 273 | include { 274 | phase: TEST 275 | } 276 | batch_norm_param { 277 | use_global_stats: true 278 | } 279 | param { lr_mult: 0 } 280 | param { lr_mult: 0 } 281 | param { lr_mult: 0 } 282 | } 283 | layer { 284 | name: "norm_a_scale" 285 | type: "Scale" 286 | bottom: "norm_a" 287 | top: "norm_a" 288 | include { 289 | phase: TEST 290 | } 291 | scale_param { 292 | bias_term: true 293 | axis: 1 294 | num_axes: 1 295 | } 296 | } 297 | layer { 298 | name: "relu_a" 299 | bottom: "norm_a" 300 | type: "ReLU" 301 | top: "norm_a" 302 | } 303 | layer { 304 | name: "concat_level2" 305 | type: "Concat" 306 | bottom: "norm1_2" 307 | bottom: "norm_a" 308 | top: "concat_level2" 309 | concat_param { 310 | axis: 1 311 | } 312 | } 313 | layer { 314 | name: "conv2" 315 | type: "Convolution" 316 | bottom: "concat_level2" 317 | top: "conv2" 318 | convolution_param { 319 | num_output: 128 320 | kernel_size: 3 321 | pad: 1 322 | weight_filler { 323 | type: "msra" 324 | } 325 | bias_filler { 326 | type: "constant" 327 | } 328 | } 329 | } 330 | layer { 331 | name: "norm2" 332 | type: "BatchNorm" 333 | bottom: "conv2" 334 | top: "norm2" 335 | include { 336 | phase: TRAIN 337 | } 338 | batch_norm_param { 339 | use_global_stats: false 340 | moving_average_fraction: 0.999 341 | } 342 | param { lr_mult: 0 } 343 | param { lr_mult: 0 } 344 | param { lr_mult: 0 } 345 | } 346 | layer { 347 | name: "norm2_scale" 348 | type: "Scale" 349 | bottom: "norm2" 350 | top: "norm2" 351 | include { 352 | phase: TRAIN 353 | } 354 | scale_param { 355 | bias_term: true 356 | axis: 1 357 | num_axes: 1 358 | filler { 359 | type: "constant" 360 | value: 1 361 | } 362 | bias_filler { 363 | type: "constant" 364 | value: 0 365 | } 366 | } 367 | } 368 | layer { 369 | name: "norm2" 370 | type: "BatchNorm" 371 | bottom: "conv2" 372 | top: "norm2" 373 | include { 374 | phase: TEST 375 | } 376 | batch_norm_param { 377 | use_global_stats: true 378 | } 379 | param { lr_mult: 0 } 380 | param { lr_mult: 0 } 381 | param { lr_mult: 0 } 382 | } 383 | layer { 384 | name: "norm2_scale" 385 | type: "Scale" 386 | bottom: "norm2" 387 | top: "norm2" 388 | include { 389 | phase: TEST 390 | } 391 | scale_param { 392 | bias_term: true 393 | axis: 1 394 | num_axes: 1 395 | } 396 | } 397 | layer { 398 | name: "relu2" 399 | bottom: "norm2" 400 | type: "ReLU" 401 | top: "norm2" 402 | } 403 | layer { 404 | name: "conv2_2" 405 | type: "Convolution" 406 | bottom: "norm2" 407 | top: "conv2_2" 408 | convolution_param { 409 | num_output: 128 410 | kernel_size: 3 411 | pad: 1 412 | stride: 2 413 | weight_filler { 414 | type: "msra" 415 | } 416 | bias_filler { 417 | type: "constant" 418 | } 419 | } 420 | } 421 | layer { 422 | name: "norm2_2" 423 | type: "BatchNorm" 424 | bottom: "conv2_2" 425 | top: "norm2_2" 426 | include { 427 | phase: TRAIN 428 | } 429 | batch_norm_param { 430 | use_global_stats: false 431 | moving_average_fraction: 0.999 432 | } 433 | param { lr_mult: 0 } 434 | param { lr_mult: 0 } 435 | param { lr_mult: 0 } 436 | } 437 | layer { 438 | name: "norm2_2_scale" 439 | type: "Scale" 440 | bottom: "norm2_2" 441 | top: "norm2_2" 442 | include { 443 | phase: TRAIN 444 | } 445 | scale_param { 446 | bias_term: true 447 | axis: 1 448 | num_axes: 1 449 | filler { 450 | type: "constant" 451 | value: 1 452 | } 453 | bias_filler { 454 | type: "constant" 455 | value: 0 456 | } 457 | } 458 | } 459 | layer { 460 | name: "norm2_2" 461 | type: "BatchNorm" 462 | bottom: "conv2_2" 463 | top: "norm2_2" 464 | include { 465 | phase: TEST 466 | } 467 | batch_norm_param { 468 | use_global_stats: true 469 | } 470 | param { lr_mult: 0 } 471 | param { lr_mult: 0 } 472 | param { lr_mult: 0 } 473 | } 474 | layer { 475 | name: "norm2_2_scale" 476 | type: "Scale" 477 | bottom: "norm2_2" 478 | top: "norm2_2" 479 | include { 480 | phase: TEST 481 | } 482 | scale_param { 483 | bias_term: true 484 | axis: 1 485 | num_axes: 1 486 | } 487 | } 488 | layer { 489 | name: "relu2_2" 490 | bottom: "norm2_2" 491 | type: "ReLU" 492 | top: "norm2_2" 493 | } 494 | layer { 495 | name: "conv_b" 496 | type: "Convolution" 497 | bottom: "wavelet_level3" 498 | top: "conv_b" 499 | convolution_param { 500 | num_output: 128 501 | kernel_size: 3 502 | pad: 1 503 | weight_filler { 504 | type: "msra" 505 | } 506 | bias_filler { 507 | type: "constant" 508 | } 509 | } 510 | } 511 | layer { 512 | name: "norm_b" 513 | type: "BatchNorm" 514 | bottom: "conv_b" 515 | top: "norm_b" 516 | include { 517 | phase: TRAIN 518 | } 519 | batch_norm_param { 520 | use_global_stats: false 521 | moving_average_fraction: 0.999 522 | } 523 | param { lr_mult: 0 } 524 | param { lr_mult: 0 } 525 | param { lr_mult: 0 } 526 | } 527 | layer { 528 | name: "norm_b_scale" 529 | type: "Scale" 530 | bottom: "norm_b" 531 | top: "norm_b" 532 | include { 533 | phase: TRAIN 534 | } 535 | scale_param { 536 | bias_term: true 537 | axis: 1 538 | num_axes: 1 539 | filler { 540 | type: "constant" 541 | value: 1 542 | } 543 | bias_filler { 544 | type: "constant" 545 | value: 0 546 | } 547 | } 548 | } 549 | layer { 550 | name: "norm_b" 551 | type: "BatchNorm" 552 | bottom: "conv_b" 553 | top: "norm_b" 554 | include { 555 | phase: TEST 556 | } 557 | batch_norm_param { 558 | use_global_stats: true 559 | } 560 | param { lr_mult: 0 } 561 | param { lr_mult: 0 } 562 | param { lr_mult: 0 } 563 | } 564 | layer { 565 | name: "norm_b_scale" 566 | type: "Scale" 567 | bottom: "norm_b" 568 | top: "norm_b" 569 | include { 570 | phase: TEST 571 | } 572 | scale_param { 573 | bias_term: true 574 | axis: 1 575 | num_axes: 1 576 | } 577 | } 578 | layer { 579 | name: "relu_b" 580 | bottom: "norm_b" 581 | type: "ReLU" 582 | top: "norm_b" 583 | } 584 | layer { 585 | name: "conv_b_2" 586 | type: "Convolution" 587 | bottom: "norm_b" 588 | top: "conv_b_2" 589 | convolution_param { 590 | num_output: 128 591 | kernel_size: 3 592 | pad: 1 593 | weight_filler { 594 | type: "msra" 595 | } 596 | bias_filler { 597 | type: "constant" 598 | } 599 | } 600 | } 601 | layer { 602 | name: "norm_b_2" 603 | type: "BatchNorm" 604 | bottom: "conv_b_2" 605 | top: "norm_b_2" 606 | include { 607 | phase: TRAIN 608 | } 609 | batch_norm_param { 610 | use_global_stats: false 611 | moving_average_fraction: 0.999 612 | } 613 | param { lr_mult: 0 } 614 | param { lr_mult: 0 } 615 | param { lr_mult: 0 } 616 | } 617 | layer { 618 | name: "norm_b_2_scale" 619 | type: "Scale" 620 | bottom: "norm_b_2" 621 | top: "norm_b_2" 622 | include { 623 | phase: TRAIN 624 | } 625 | scale_param { 626 | bias_term: true 627 | axis: 1 628 | num_axes: 1 629 | filler { 630 | type: "constant" 631 | value: 1 632 | } 633 | bias_filler { 634 | type: "constant" 635 | value: 0 636 | } 637 | } 638 | } 639 | layer { 640 | name: "norm_b_2" 641 | type: "BatchNorm" 642 | bottom: "conv_b_2" 643 | top: "norm_b_2" 644 | include { 645 | phase: TEST 646 | } 647 | batch_norm_param { 648 | use_global_stats: true 649 | } 650 | param { lr_mult: 0 } 651 | param { lr_mult: 0 } 652 | param { lr_mult: 0 } 653 | } 654 | layer { 655 | name: "norm_b_2_scale" 656 | type: "Scale" 657 | bottom: "norm_b_2" 658 | top: "norm_b_2" 659 | include { 660 | phase: TEST 661 | } 662 | scale_param { 663 | bias_term: true 664 | axis: 1 665 | num_axes: 1 666 | } 667 | } 668 | layer { 669 | name: "relu_b_2" 670 | bottom: "norm_b_2" 671 | type: "ReLU" 672 | top: "norm_b_2" 673 | } 674 | layer { 675 | name: "concat_level3" 676 | type: "Concat" 677 | bottom: "norm2_2" 678 | bottom: "norm_b_2" 679 | top: "concat_level3" 680 | concat_param { 681 | axis: 1 682 | } 683 | } 684 | layer { 685 | name: "conv3" 686 | type: "Convolution" 687 | bottom: "concat_level3" 688 | top: "conv3" 689 | convolution_param { 690 | num_output: 256 691 | kernel_size: 3 692 | pad: 1 693 | weight_filler { 694 | type: "msra" 695 | } 696 | bias_filler { 697 | type: "constant" 698 | } 699 | } 700 | } 701 | layer { 702 | name: "norm3" 703 | type: "BatchNorm" 704 | bottom: "conv3" 705 | top: "norm3" 706 | include { 707 | phase: TRAIN 708 | } 709 | batch_norm_param { 710 | use_global_stats: false 711 | moving_average_fraction: 0.999 712 | } 713 | param { lr_mult: 0 } 714 | param { lr_mult: 0 } 715 | param { lr_mult: 0 } 716 | } 717 | layer { 718 | name: "norm3_scale" 719 | type: "Scale" 720 | bottom: "norm3" 721 | top: "norm3" 722 | include { 723 | phase: TRAIN 724 | } 725 | scale_param { 726 | bias_term: true 727 | axis: 1 728 | num_axes: 1 729 | filler { 730 | type: "constant" 731 | value: 1 732 | } 733 | bias_filler { 734 | type: "constant" 735 | value: 0 736 | } 737 | } 738 | } 739 | layer { 740 | name: "norm3" 741 | type: "BatchNorm" 742 | bottom: "conv3" 743 | top: "norm3" 744 | include { 745 | phase: TEST 746 | } 747 | batch_norm_param { 748 | use_global_stats: true 749 | } 750 | param { lr_mult: 0 } 751 | param { lr_mult: 0 } 752 | param { lr_mult: 0 } 753 | } 754 | layer { 755 | name: "norm3_scale" 756 | type: "Scale" 757 | bottom: "norm3" 758 | top: "norm3" 759 | include { 760 | phase: TEST 761 | } 762 | scale_param { 763 | bias_term: true 764 | axis: 1 765 | num_axes: 1 766 | } 767 | } 768 | layer { 769 | name: "relu3" 770 | bottom: "norm3" 771 | type: "ReLU" 772 | top: "norm3" 773 | } 774 | layer { 775 | name: "conv3_2" 776 | type: "Convolution" 777 | bottom: "norm3" 778 | top: "conv3_2" 779 | convolution_param { 780 | num_output: 256 781 | kernel_size: 3 782 | pad: 1 783 | stride: 2 784 | weight_filler { 785 | type: "msra" 786 | } 787 | bias_filler { 788 | type: "constant" 789 | } 790 | } 791 | } 792 | layer { 793 | name: "norm3_2" 794 | type: "BatchNorm" 795 | bottom: "conv3_2" 796 | top: "norm3_2" 797 | include { 798 | phase: TRAIN 799 | } 800 | batch_norm_param { 801 | use_global_stats: false 802 | moving_average_fraction: 0.999 803 | } 804 | param { lr_mult: 0 } 805 | param { lr_mult: 0 } 806 | param { lr_mult: 0 } 807 | } 808 | layer { 809 | name: "norm3_2_scale" 810 | type: "Scale" 811 | bottom: "norm3_2" 812 | top: "norm3_2" 813 | include { 814 | phase: TRAIN 815 | } 816 | scale_param { 817 | bias_term: true 818 | axis: 1 819 | num_axes: 1 820 | filler { 821 | type: "constant" 822 | value: 1 823 | } 824 | bias_filler { 825 | type: "constant" 826 | value: 0 827 | } 828 | } 829 | } 830 | layer { 831 | name: "norm3_2" 832 | type: "BatchNorm" 833 | bottom: "conv3_2" 834 | top: "norm3_2" 835 | include { 836 | phase: TEST 837 | } 838 | batch_norm_param { 839 | use_global_stats: true 840 | } 841 | param { lr_mult: 0 } 842 | param { lr_mult: 0 } 843 | param { lr_mult: 0 } 844 | } 845 | layer { 846 | name: "norm3_2_scale" 847 | type: "Scale" 848 | bottom: "norm3_2" 849 | top: "norm3_2" 850 | include { 851 | phase: TEST 852 | } 853 | scale_param { 854 | bias_term: true 855 | axis: 1 856 | num_axes: 1 857 | } 858 | } 859 | layer { 860 | name: "relu3_2" 861 | bottom: "norm3_2" 862 | type: "ReLU" 863 | top: "norm3_2" 864 | } 865 | layer { 866 | name: "conv_c" 867 | type: "Convolution" 868 | bottom: "wavelet_level4" 869 | top: "conv_c" 870 | convolution_param { 871 | num_output: 256 872 | kernel_size: 3 873 | pad: 1 874 | weight_filler { 875 | type: "msra" 876 | } 877 | bias_filler { 878 | type: "constant" 879 | } 880 | } 881 | } 882 | layer { 883 | name: "norm_c" 884 | type: "BatchNorm" 885 | bottom: "conv_c" 886 | top: "norm_c" 887 | include { 888 | phase: TRAIN 889 | } 890 | batch_norm_param { 891 | use_global_stats: false 892 | moving_average_fraction: 0.999 893 | } 894 | param { lr_mult: 0 } 895 | param { lr_mult: 0 } 896 | param { lr_mult: 0 } 897 | } 898 | layer { 899 | name: "norm_c_scale" 900 | type: "Scale" 901 | bottom: "norm_c" 902 | top: "norm_c" 903 | include { 904 | phase: TRAIN 905 | } 906 | scale_param { 907 | bias_term: true 908 | axis: 1 909 | num_axes: 1 910 | filler { 911 | type: "constant" 912 | value: 1 913 | } 914 | bias_filler { 915 | type: "constant" 916 | value: 0 917 | } 918 | } 919 | } 920 | layer { 921 | name: "norm_c" 922 | type: "BatchNorm" 923 | bottom: "conv_c" 924 | top: "norm_c" 925 | include { 926 | phase: TEST 927 | } 928 | batch_norm_param { 929 | use_global_stats: true 930 | } 931 | param { lr_mult: 0 } 932 | param { lr_mult: 0 } 933 | param { lr_mult: 0 } 934 | } 935 | layer { 936 | name: "norm_c_scale" 937 | type: "Scale" 938 | bottom: "norm_c" 939 | top: "norm_c" 940 | include { 941 | phase: TEST 942 | } 943 | scale_param { 944 | bias_term: true 945 | axis: 1 946 | num_axes: 1 947 | } 948 | } 949 | layer { 950 | name: "relu_c" 951 | bottom: "norm_c" 952 | type: "ReLU" 953 | top: "norm_c" 954 | } 955 | layer { 956 | name: "conv_c_2" 957 | type: "Convolution" 958 | bottom: "norm_c" 959 | top: "conv_c_2" 960 | convolution_param { 961 | num_output: 256 962 | kernel_size: 3 963 | pad: 1 964 | weight_filler { 965 | type: "msra" 966 | } 967 | bias_filler { 968 | type: "constant" 969 | } 970 | } 971 | } 972 | layer { 973 | name: "norm_c_2" 974 | type: "BatchNorm" 975 | bottom: "conv_c_2" 976 | top: "norm_c_2" 977 | include { 978 | phase: TRAIN 979 | } 980 | batch_norm_param { 981 | use_global_stats: false 982 | moving_average_fraction: 0.999 983 | } 984 | param { lr_mult: 0 } 985 | param { lr_mult: 0 } 986 | param { lr_mult: 0 } 987 | } 988 | layer { 989 | name: "norm_c_2_scale" 990 | type: "Scale" 991 | bottom: "norm_c_2" 992 | top: "norm_c_2" 993 | include { 994 | phase: TRAIN 995 | } 996 | scale_param { 997 | bias_term: true 998 | axis: 1 999 | num_axes: 1 1000 | filler { 1001 | type: "constant" 1002 | value: 1 1003 | } 1004 | bias_filler { 1005 | type: "constant" 1006 | value: 0 1007 | } 1008 | } 1009 | } 1010 | layer { 1011 | name: "norm_c_2" 1012 | type: "BatchNorm" 1013 | bottom: "conv_c_2" 1014 | top: "norm_c_2" 1015 | include { 1016 | phase: TEST 1017 | } 1018 | batch_norm_param { 1019 | use_global_stats: true 1020 | } 1021 | param { lr_mult: 0 } 1022 | param { lr_mult: 0 } 1023 | param { lr_mult: 0 } 1024 | } 1025 | layer { 1026 | name: "norm_c_2_scale" 1027 | type: "Scale" 1028 | bottom: "norm_c_2" 1029 | top: "norm_c_2" 1030 | include { 1031 | phase: TEST 1032 | } 1033 | scale_param { 1034 | bias_term: true 1035 | axis: 1 1036 | num_axes: 1 1037 | } 1038 | } 1039 | layer { 1040 | name: "relu_c_2" 1041 | bottom: "norm_c_2" 1042 | type: "ReLU" 1043 | top: "norm_c_2" 1044 | } 1045 | layer { 1046 | name: "conv_c_3" 1047 | type: "Convolution" 1048 | bottom: "norm_c_2" 1049 | top: "conv_c_3" 1050 | convolution_param { 1051 | num_output: 256 1052 | kernel_size: 3 1053 | pad: 1 1054 | weight_filler { 1055 | type: "msra" 1056 | } 1057 | bias_filler { 1058 | type: "constant" 1059 | } 1060 | } 1061 | } 1062 | layer { 1063 | name: "norm_c_3" 1064 | type: "BatchNorm" 1065 | bottom: "conv_c_3" 1066 | top: "norm_c_3" 1067 | include { 1068 | phase: TRAIN 1069 | } 1070 | batch_norm_param { 1071 | use_global_stats: false 1072 | moving_average_fraction: 0.999 1073 | } 1074 | param { lr_mult: 0 } 1075 | param { lr_mult: 0 } 1076 | param { lr_mult: 0 } 1077 | } 1078 | layer { 1079 | name: "norm_c_3_scale" 1080 | type: "Scale" 1081 | bottom: "norm_c_3" 1082 | top: "norm_c_3" 1083 | include { 1084 | phase: TRAIN 1085 | } 1086 | scale_param { 1087 | bias_term: true 1088 | axis: 1 1089 | num_axes: 1 1090 | filler { 1091 | type: "constant" 1092 | value: 1 1093 | } 1094 | bias_filler { 1095 | type: "constant" 1096 | value: 0 1097 | } 1098 | } 1099 | } 1100 | layer { 1101 | name: "norm_c_3" 1102 | type: "BatchNorm" 1103 | bottom: "conv_c_3" 1104 | top: "norm_c_3" 1105 | include { 1106 | phase: TEST 1107 | } 1108 | batch_norm_param { 1109 | use_global_stats: true 1110 | } 1111 | param { lr_mult: 0 } 1112 | param { lr_mult: 0 } 1113 | param { lr_mult: 0 } 1114 | } 1115 | layer { 1116 | name: "norm_c_3_scale" 1117 | type: "Scale" 1118 | bottom: "norm_c_3" 1119 | top: "norm_c_3" 1120 | include { 1121 | phase: TEST 1122 | } 1123 | scale_param { 1124 | bias_term: true 1125 | axis: 1 1126 | num_axes: 1 1127 | } 1128 | } 1129 | layer { 1130 | name: "relu_c_3" 1131 | bottom: "norm_c_3" 1132 | type: "ReLU" 1133 | top: "norm_c_3" 1134 | } 1135 | layer { 1136 | name: "concat_level4" 1137 | type: "Concat" 1138 | bottom: "norm3_2" 1139 | bottom: "norm_c_3" 1140 | top: "concat_level4" 1141 | concat_param { 1142 | axis: 1 1143 | } 1144 | } 1145 | layer { 1146 | name: "conv4" 1147 | type: "Convolution" 1148 | bottom: "concat_level4" 1149 | top: "conv4" 1150 | convolution_param { 1151 | num_output: 256 1152 | kernel_size: 3 1153 | pad: 1 1154 | weight_filler { 1155 | type: "msra" 1156 | } 1157 | bias_filler { 1158 | type: "constant" 1159 | } 1160 | } 1161 | } 1162 | layer { 1163 | name: "norm4" 1164 | type: "BatchNorm" 1165 | bottom: "conv4" 1166 | top: "norm4" 1167 | include { 1168 | phase: TRAIN 1169 | } 1170 | batch_norm_param { 1171 | use_global_stats: false 1172 | moving_average_fraction: 0.999 1173 | } 1174 | param { lr_mult: 0 } 1175 | param { lr_mult: 0 } 1176 | param { lr_mult: 0 } 1177 | } 1178 | layer { 1179 | name: "norm4_scale" 1180 | type: "Scale" 1181 | bottom: "norm4" 1182 | top: "norm4" 1183 | include { 1184 | phase: TRAIN 1185 | } 1186 | scale_param { 1187 | bias_term: true 1188 | axis: 1 1189 | num_axes: 1 1190 | filler { 1191 | type: "constant" 1192 | value: 1 1193 | } 1194 | bias_filler { 1195 | type: "constant" 1196 | value: 0 1197 | } 1198 | } 1199 | } 1200 | layer { 1201 | name: "norm4" 1202 | type: "BatchNorm" 1203 | bottom: "conv4" 1204 | top: "norm4" 1205 | include { 1206 | phase: TEST 1207 | } 1208 | batch_norm_param { 1209 | use_global_stats: true 1210 | } 1211 | param { lr_mult: 0 } 1212 | param { lr_mult: 0 } 1213 | param { lr_mult: 0 } 1214 | } 1215 | layer { 1216 | name: "norm4_scale" 1217 | type: "Scale" 1218 | bottom: "norm4" 1219 | top: "norm4" 1220 | include { 1221 | phase: TEST 1222 | } 1223 | scale_param { 1224 | bias_term: true 1225 | axis: 1 1226 | num_axes: 1 1227 | } 1228 | } 1229 | layer { 1230 | name: "relu4" 1231 | bottom: "norm4" 1232 | type: "ReLU" 1233 | top: "norm4" 1234 | } 1235 | layer { 1236 | name: "conv4_2" 1237 | type: "Convolution" 1238 | bottom: "norm4" 1239 | top: "conv4_2" 1240 | convolution_param { 1241 | num_output: 256 1242 | kernel_size: 3 1243 | pad: 1 1244 | stride: 2 1245 | weight_filler { 1246 | type: "msra" 1247 | } 1248 | bias_filler { 1249 | type: "constant" 1250 | } 1251 | } 1252 | } 1253 | layer { 1254 | name: "norm4_2" 1255 | type: "BatchNorm" 1256 | bottom: "conv4_2" 1257 | top: "norm4_2" 1258 | include { 1259 | phase: TRAIN 1260 | } 1261 | batch_norm_param { 1262 | use_global_stats: false 1263 | moving_average_fraction: 0.999 1264 | } 1265 | param { lr_mult: 0 } 1266 | param { lr_mult: 0 } 1267 | param { lr_mult: 0 } 1268 | } 1269 | layer { 1270 | name: "norm4_2_scale" 1271 | type: "Scale" 1272 | bottom: "norm4_2" 1273 | top: "norm4_2" 1274 | include { 1275 | phase: TRAIN 1276 | } 1277 | scale_param { 1278 | bias_term: true 1279 | axis: 1 1280 | num_axes: 1 1281 | filler { 1282 | type: "constant" 1283 | value: 1 1284 | } 1285 | bias_filler { 1286 | type: "constant" 1287 | value: 0 1288 | } 1289 | } 1290 | } 1291 | layer { 1292 | name: "norm4_2" 1293 | type: "BatchNorm" 1294 | bottom: "conv4_2" 1295 | top: "norm4_2" 1296 | include { 1297 | phase: TEST 1298 | } 1299 | batch_norm_param { 1300 | use_global_stats: true 1301 | } 1302 | param { lr_mult: 0 } 1303 | param { lr_mult: 0 } 1304 | param { lr_mult: 0 } 1305 | } 1306 | layer { 1307 | name: "norm4_2_scale" 1308 | type: "Scale" 1309 | bottom: "norm4_2" 1310 | top: "norm4_2" 1311 | include { 1312 | phase: TEST 1313 | } 1314 | scale_param { 1315 | bias_term: true 1316 | axis: 1 1317 | num_axes: 1 1318 | } 1319 | } 1320 | layer { 1321 | name: "relu4_2" 1322 | bottom: "norm4_2" 1323 | type: "ReLU" 1324 | top: "norm4_2" 1325 | } 1326 | layer { 1327 | name: "conv5_1" 1328 | type: "Convolution" 1329 | bottom: "norm4_2" 1330 | top: "conv5_1" 1331 | convolution_param { 1332 | num_output: 128 1333 | kernel_size: 3 1334 | pad: 1 1335 | weight_filler { 1336 | type: "msra" 1337 | } 1338 | bias_filler { 1339 | type: "constant" 1340 | } 1341 | } 1342 | } 1343 | layer { 1344 | name: "norm5_1" 1345 | type: "BatchNorm" 1346 | bottom: "conv5_1" 1347 | top: "norm5_1" 1348 | include { 1349 | phase: TRAIN 1350 | } 1351 | batch_norm_param { 1352 | use_global_stats: false 1353 | moving_average_fraction: 0.999 1354 | } 1355 | param { lr_mult: 0 } 1356 | param { lr_mult: 0 } 1357 | param { lr_mult: 0 } 1358 | } 1359 | layer { 1360 | name: "norm5_1_scale" 1361 | type: "Scale" 1362 | bottom: "norm5_1" 1363 | top: "norm5_1" 1364 | include { 1365 | phase: TRAIN 1366 | } 1367 | scale_param { 1368 | bias_term: true 1369 | axis: 1 1370 | num_axes: 1 1371 | filler { 1372 | type: "constant" 1373 | value: 1 1374 | } 1375 | bias_filler { 1376 | type: "constant" 1377 | value: 0 1378 | } 1379 | } 1380 | } 1381 | layer { 1382 | name: "norm5_1" 1383 | type: "BatchNorm" 1384 | bottom: "conv5_1" 1385 | top: "norm5_1" 1386 | include { 1387 | phase: TEST 1388 | } 1389 | batch_norm_param { 1390 | use_global_stats: true 1391 | } 1392 | param { lr_mult: 0 } 1393 | param { lr_mult: 0 } 1394 | param { lr_mult: 0 } 1395 | } 1396 | layer { 1397 | name: "norm5_1_scale" 1398 | type: "Scale" 1399 | bottom: "norm5_1" 1400 | top: "norm5_1" 1401 | include { 1402 | phase: TEST 1403 | } 1404 | scale_param { 1405 | bias_term: true 1406 | axis: 1 1407 | num_axes: 1 1408 | } 1409 | } 1410 | layer { 1411 | name: "relu5_1" 1412 | bottom: "norm5_1" 1413 | type: "ReLU" 1414 | top: "norm5_1" 1415 | } 1416 | layer { 1417 | name: "pool5_1" 1418 | type: "Pooling" 1419 | bottom: "norm5_1" 1420 | top: "pool5_1" 1421 | pooling_param { 1422 | pool: AVE 1423 | kernel_size: 7 1424 | stride: 1 1425 | } 1426 | } 1427 | layer { 1428 | name: "fc5" 1429 | type: "InnerProduct" 1430 | bottom: "pool5_1" 1431 | top: "fc5" 1432 | inner_product_param { 1433 | num_output: 2048 1434 | weight_filler { 1435 | type: "msra" 1436 | } 1437 | bias_filler { 1438 | type: "constant" 1439 | } 1440 | } 1441 | } 1442 | layer { 1443 | name: "norm5" 1444 | type: "BatchNorm" 1445 | bottom: "fc5" 1446 | top: "norm5" 1447 | include { 1448 | phase: TRAIN 1449 | } 1450 | batch_norm_param { 1451 | use_global_stats: false 1452 | moving_average_fraction: 0.999 1453 | } 1454 | param { lr_mult: 0 } 1455 | param { lr_mult: 0 } 1456 | param { lr_mult: 0 } 1457 | } 1458 | layer { 1459 | name: "norm5_scale" 1460 | type: "Scale" 1461 | bottom: "norm5" 1462 | top: "norm5" 1463 | include { 1464 | phase: TRAIN 1465 | } 1466 | scale_param { 1467 | bias_term: true 1468 | axis: 1 1469 | num_axes: 1 1470 | filler { 1471 | type: "constant" 1472 | value: 1 1473 | } 1474 | bias_filler { 1475 | type: "constant" 1476 | value: 0 1477 | } 1478 | } 1479 | } 1480 | layer { 1481 | name: "norm5" 1482 | type: "BatchNorm" 1483 | bottom: "fc5" 1484 | top: "norm5" 1485 | include { 1486 | phase: TEST 1487 | } 1488 | batch_norm_param { 1489 | use_global_stats: true 1490 | } 1491 | param { lr_mult: 0 } 1492 | param { lr_mult: 0 } 1493 | param { lr_mult: 0 } 1494 | } 1495 | layer { 1496 | name: "norm5_scale" 1497 | type: "Scale" 1498 | bottom: "norm5" 1499 | top: "norm5" 1500 | include { 1501 | phase: TEST 1502 | } 1503 | scale_param { 1504 | bias_term: true 1505 | axis: 1 1506 | num_axes: 1 1507 | } 1508 | } 1509 | layer { 1510 | name: "relu5" 1511 | type: "ReLU" 1512 | bottom: "norm5" 1513 | top: "norm5" 1514 | } 1515 | layer { 1516 | name: "drop5" 1517 | type: "Dropout" 1518 | bottom: "norm5" 1519 | top: "norm5" 1520 | dropout_param { 1521 | dropout_ratio: 0.5 1522 | } 1523 | } 1524 | layer { 1525 | name: "fc6" 1526 | type: "InnerProduct" 1527 | bottom: "norm5" 1528 | top: "fc6" 1529 | inner_product_param { 1530 | num_output: 2048 1531 | weight_filler { 1532 | type: "msra" 1533 | } 1534 | bias_filler { 1535 | type: "constant" 1536 | } 1537 | } 1538 | } 1539 | layer { 1540 | name: "norm6" 1541 | type: "BatchNorm" 1542 | bottom: "fc6" 1543 | top: "norm6" 1544 | include { 1545 | phase: TRAIN 1546 | } 1547 | batch_norm_param { 1548 | use_global_stats: false 1549 | moving_average_fraction: 0.999 1550 | } 1551 | param { lr_mult: 0 } 1552 | param { lr_mult: 0 } 1553 | param { lr_mult: 0 } 1554 | } 1555 | layer { 1556 | name: "norm6_scale" 1557 | type: "Scale" 1558 | bottom: "norm6" 1559 | top: "norm6" 1560 | include { 1561 | phase: TRAIN 1562 | } 1563 | scale_param { 1564 | bias_term: true 1565 | axis: 1 1566 | num_axes: 1 1567 | filler { 1568 | type: "constant" 1569 | value: 1 1570 | } 1571 | bias_filler { 1572 | type: "constant" 1573 | value: 0 1574 | } 1575 | } 1576 | } 1577 | layer { 1578 | name: "norm6" 1579 | type: "BatchNorm" 1580 | bottom: "fc6" 1581 | top: "norm6" 1582 | include { 1583 | phase: TEST 1584 | } 1585 | batch_norm_param { 1586 | use_global_stats: true 1587 | } 1588 | param { lr_mult: 0 } 1589 | param { lr_mult: 0 } 1590 | param { lr_mult: 0 } 1591 | } 1592 | layer { 1593 | name: "norm6_scale" 1594 | type: "Scale" 1595 | bottom: "norm6" 1596 | top: "norm6" 1597 | include { 1598 | phase: TEST 1599 | } 1600 | scale_param { 1601 | bias_term: true 1602 | axis: 1 1603 | num_axes: 1 1604 | } 1605 | } 1606 | layer { 1607 | name: "relu6" 1608 | type: "ReLU" 1609 | bottom: "norm6" 1610 | top: "norm6" 1611 | } 1612 | layer { 1613 | name: "drop6" 1614 | type: "Dropout" 1615 | bottom: "norm6" 1616 | top: "norm6" 1617 | dropout_param { 1618 | dropout_ratio: 0.5 1619 | } 1620 | } 1621 | layer { 1622 | name: "fc7" 1623 | type: "InnerProduct" 1624 | bottom: "norm6" 1625 | top: "fc7" 1626 | inner_product_param { 1627 | num_output: 1000 1628 | weight_filler { 1629 | type: "msra" 1630 | } 1631 | bias_filler { 1632 | type: "constant" 1633 | } 1634 | } 1635 | } 1636 | layer { 1637 | name: "prob" 1638 | type: "Softmax" 1639 | bottom: "fc7" 1640 | top: "prob" 1641 | } 1642 | -------------------------------------------------------------------------------- /models/solver_WaveletCNN_4level.prototxt: -------------------------------------------------------------------------------- 1 | net: "models/WaveletCNN_4level.prototxt" 2 | type: "Adam" 3 | test_iter: 60 4 | test_interval: 500 5 | base_lr: 0.01 6 | lr_policy: "fixed" 7 | momentum: 0.9 8 | momentum2: 0.999 9 | display: 100 10 | max_iter: 20000 11 | snapshot: 5000 12 | snapshot_prefix: "models/caffe_waveletCNN_4level_train" 13 | solver_mode: GPU 14 | -------------------------------------------------------------------------------- /pylayers.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import numpy as np 3 | import caffe 4 | import functions 5 | 6 | 7 | class GCN(caffe.Layer): 8 | def setup(self, bottom, top): 9 | pass 10 | 11 | def reshape(self, bottom, top): 12 | top[0].reshape(*bottom[0].data.shape) 13 | 14 | def forward(self, bottom, top): 15 | batch_size = len(bottom[0].data) 16 | for index in range(batch_size): 17 | img = bottom[0].data[index].transpose(1,2,0) 18 | img_vec = img.flatten('F') 19 | img_vec = img_vec.reshape(1, len(img_vec)) 20 | img_gcn = functions.misc.global_contrast_normalize(img_vec) 21 | img_pp = img_gcn.reshape(img.shape[0], img.shape[1], img.shape[2], order='F') 22 | img_pp = img_pp.transpose(2, 0, 1) 23 | top[0].data[index] = img_pp 24 | 25 | def backward(self, top, propagate_down, bottom): 26 | pass 27 | 28 | 29 | class GramMatrix(caffe.Layer): 30 | def setup(self, bottom, top): 31 | bt_shape = bottom[0].data.shape 32 | top[0].reshape(bt_shape[0], 1, bt_shape[1], bt_shape[1]) 33 | 34 | def reshape(self, bottom, top): 35 | bt_shape = bottom[0].data.shape 36 | top[0].reshape(bt_shape[0], 1, bt_shape[1], bt_shape[1]) 37 | 38 | def forward(self, bottom, top): 39 | batch_size = len(bottom[0].data) 40 | for index in range(batch_size): 41 | activations = bottom[0].data[index] 42 | G, F = functions.misc.gram_matrix(activations[None, :, :, :]) 43 | top[0].data[index] = G[None, :, :] 44 | 45 | def backward(self, top, propagate_down, bottom): 46 | M = bottom[0].data.shape[2] * bottom[0].data.shape[3] 47 | diff_tmp = top[0].diff / M 48 | batch_size = len(top[0].diff) 49 | for index in range(batch_size): 50 | activations = bottom[0].data[index] 51 | G, F = functions.misc.gram_matrix(activations[None, :, :, :]) 52 | top_tmp = diff_tmp[index][0] + diff_tmp[index][0].T 53 | bottom[0].diff[index] = np.dot(top_tmp, F).reshape(bottom[0].diff.shape[1], bottom[0].diff.shape[2], bottom[0].diff.shape[2]) 54 | 55 | 56 | class WaveletHaarLevelLayer(caffe.Layer): 57 | def setup(self, bottom, top): 58 | try: 59 | self.level = int(self.param_str) # string style of number 60 | except ValueError: 61 | raise ValueError("param_str must be string") 62 | 63 | # check if the number of tops is equal to that of self.level 64 | if len(top) != self.level: 65 | raise Exception(" number of tops must be equal to that of levels") 66 | 67 | bt_shape = bottom[0].data.shape 68 | for i in range(self.level): 69 | div = 2**(i+1) 70 | top[i].reshape(bt_shape[0], 4*bt_shape[1], int(bt_shape[2]/div), int(bt_shape[3]/div)) 71 | 72 | def reshape(self, bottom, top): 73 | bt_shape = bottom[0].data.shape 74 | for i in range(self.level): 75 | div = 2**(i+1) 76 | top[i].reshape(bt_shape[0], 4*bt_shape[1], int(bt_shape[2]/div), int(bt_shape[3]/div)) 77 | 78 | def forward(self, bottom, top): 79 | batch_size = len(bottom[0].data) 80 | for index in range(batch_size): 81 | for i in range(len(bottom[0].data[0])): 82 | wavelets = functions.wavelet_haar.WaveletTransform(bottom[0].data[index][i], self.level) 83 | for j in range(self.level): 84 | top[j].data[index][4*i] = wavelets["LL_"+str(j+1)] 85 | top[j].data[index][4*i+1] = wavelets["LH_"+str(j+1)] 86 | top[j].data[index][4*i+2] = wavelets["HL_"+str(j+1)] 87 | top[j].data[index][4*i+3] = wavelets["HH_"+str(j+1)] 88 | 89 | def backward(self, top, propagate_down, bottom): 90 | pass 91 | -------------------------------------------------------------------------------- /run_waveletcnn.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | ''' 3 | Usage: 4 | (for train) python run_waveletcnn.py -p train [-g 0] -d path/to/training/dataset 5 | (for test) python run_waveletcnn.py -p test [-g 0] -i path/to/trained/model -t path/to/target/image/file 6 | This program try to train/test wavelet CNNs with 4-level decomposition. 7 | ''' 8 | 9 | import os 10 | import sys 11 | import argparse 12 | import numpy as np 13 | import caffe 14 | import functions 15 | 16 | 17 | parser = argparse.ArgumentParser(description='Clasify the input image into the correct category.') 18 | parser.add_argument('--phase', '-p', type=str, required=True, 19 | help='Run Wavelet CNN on train/test mode (input train or test)') 20 | parser.add_argument('--gpu', '-g', default=0, type=int, 21 | help='GPU ID (negative value indicates CPU)') 22 | # for Train phase 23 | parser.add_argument('--dataset', '-d', default='Dataset', type=str, 24 | help='dataset directory path for training') 25 | # for Test phase 26 | parser.add_argument('--initmodel', '-i', default=None, type=str, 27 | help='initialize the model from given file') 28 | parser.add_argument('--target_image', '-t', default=None, type=str, 29 | help='target image path') 30 | args = parser.parse_args() 31 | 32 | base_dir = os.getcwd() 33 | sys.path.append(base_dir) 34 | 35 | if args.gpu < 0: 36 | caffe.set_mode_cpu() 37 | else: 38 | caffe.set_device(args.gpu) 39 | caffe.set_mode_gpu() 40 | 41 | 42 | if args.phase == "train": 43 | functions.misc.rewrite_data('models/WaveletCNN_4level.prototxt', args.dataset) 44 | Netsolver = os.path.join(base_dir, 'models/solver_WaveletCNN_4level.prototxt') 45 | solver = caffe.SGDSolver(Netsolver) 46 | solver.solve() 47 | elif args.phase == "test": 48 | net = caffe.Net('models/WaveletCNN_4level_deploy.prototxt', args.initmodel, caffe.TEST) 49 | # load input and configure preprocessing 50 | transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) 51 | transformer.set_transpose('data', (2,0,1)) 52 | transformer.set_channel_swap('data', (2,1,0)) 53 | transformer.set_raw_scale('data', 255.0) 54 | 55 | #load the image in the data layer 56 | image = caffe.io.load_image(args.target_image) 57 | min_length = min(image.shape[:2]) 58 | crop_length = int(min_length * 0.6) # crop image with 60% length of shorter edge 59 | cropped_imgs = functions.misc.random_crop(image, (crop_length, crop_length), 1) # shape is N x H x W x C 60 | cropped_im = cropped_imgs[0] 61 | resized_im = caffe.io.resize_image(cropped_im, (224, 224), interp_order=3) 62 | 63 | net.blobs['data'].data[...] = transformer.preprocess('data', resized_im) 64 | out = net.forward() 65 | # the output probability vector for the first image in the batch 66 | output_prob = out['prob'][0] 67 | 68 | labels = 'data/imagenet_labels.txt' # Path to the text file containing a label name per each line. 69 | label_list = np.loadtxt(labels, str, delimiter='\t') 70 | 71 | # top-5 for the probability 72 | top_idx = output_prob.argsort()[::-1][:5] 73 | print(args.target_image + ':') 74 | # print zip(label_list[top_idx], output_prob[top_idx]) 75 | 76 | for i in range(len(top_idx)): 77 | print(label_list[top_idx][i] + ': ' + str(round(output_prob[top_idx][i]*100, 3))) 78 | --------------------------------------------------------------------------------