├── README.md
├── data
├── 1.JPEG
└── 2.JPEG
├── imagenet.lua
├── images
├── 1.png
├── 10.png
├── 11.png
├── 12.png
├── 13.png
├── 14.png
├── 15.png
├── 16.png
├── 17.png
├── 18.png
├── 19.png
├── 2.png
├── 20.png
├── 3.png
├── 4.png
├── 5.png
├── 6.png
├── 7.png
├── 8.png
└── 9.png
├── transforms.lua
└── visual.lua
/README.md:
--------------------------------------------------------------------------------
1 | # visualResNet_torch
2 |
3 | Curious about where is the ResNet looking at? This repo visualizes the class specific saliency map or discriminative location.
4 | It is Torch re-implementation of [Learning Deep Features for Discriminative Localization, Bolei Zhou et. al.](http://arxiv.org/abs/1512.04150),
5 | without modifying the network or re-training. (MatConvNet re-implementation can be found at this [repo](https://github.com/zhanghang1989/visualResNet).) We look directly through the ResNet to see the world.
6 |
7 |
8 | ### Get Started
9 |
10 | - The code relies on [Torch](https://github.com/torch/torch7), which should be downloaded and built before running the experiments. Download the code:
11 | ```bash
12 | git clone https://github.com/zhanghang1989/visualResNet_torch.git
13 | ```
14 |
15 | - Download the models from [facebook git](https://github.com/facebook/fb.resnet.torch/tree/master/pretrained)
16 |
17 | - Run the progrem:
18 | ```bash
19 | th visual.lua resnet-50.t7 data/1.JPEG data/2.JPEG
20 | ```
21 |
22 | - Visualize all the images in a folder
23 | ```bash
24 | th visual.lua resnet-50.t7 data/*
25 | ```
26 |
27 | ### Examples
28 |
29 |

30 |

31 |

32 |

33 |

34 |

35 |

36 |

37 |

38 |

39 |

40 |

41 |

42 |

43 |

44 |

45 |

46 |

47 |

48 |

49 |
50 |
51 |
--------------------------------------------------------------------------------
/data/1.JPEG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/data/1.JPEG
--------------------------------------------------------------------------------
/data/2.JPEG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/data/2.JPEG
--------------------------------------------------------------------------------
/imagenet.lua:
--------------------------------------------------------------------------------
1 | return{
2 | 'tench, Tinca tinca',
3 | 'goldfish, Carassius auratus',
4 | 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
5 | 'tiger shark, Galeocerdo cuvieri',
6 | 'hammerhead, hammerhead shark',
7 | 'electric ray, crampfish, numbfish, torpedo',
8 | 'stingray',
9 | 'cock',
10 | 'hen',
11 | 'ostrich, Struthio camelus',
12 | 'brambling, Fringilla montifringilla',
13 | 'goldfinch, Carduelis carduelis',
14 | 'house finch, linnet, Carpodacus mexicanus',
15 | 'junco, snowbird',
16 | 'indigo bunting, indigo finch, indigo bird, Passerina cyanea',
17 | 'robin, American robin, Turdus migratorius',
18 | 'bulbul',
19 | 'jay',
20 | 'magpie',
21 | 'chickadee',
22 | 'water ouzel, dipper',
23 | 'kite',
24 | 'bald eagle, American eagle, Haliaeetus leucocephalus',
25 | 'vulture',
26 | 'great grey owl, great gray owl, Strix nebulosa',
27 | 'European fire salamander, Salamandra salamandra',
28 | 'common newt, Triturus vulgaris',
29 | 'eft',
30 | 'spotted salamander, Ambystoma maculatum',
31 | 'axolotl, mud puppy, Ambystoma mexicanum',
32 | 'bullfrog, Rana catesbeiana',
33 | 'tree frog, tree-frog',
34 | 'tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui',
35 | 'loggerhead, loggerhead turtle, Caretta caretta',
36 | 'leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea',
37 | 'mud turtle',
38 | 'terrapin',
39 | 'box turtle, box tortoise',
40 | 'banded gecko',
41 | 'common iguana, iguana, Iguana iguana',
42 | 'American chameleon, anole, Anolis carolinensis',
43 | 'whiptail, whiptail lizard',
44 | 'agama',
45 | 'frilled lizard, Chlamydosaurus kingi',
46 | 'alligator lizard',
47 | 'Gila monster, Heloderma suspectum',
48 | 'green lizard, Lacerta viridis',
49 | 'African chameleon, Chamaeleo chamaeleon',
50 | 'Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis',
51 | 'African crocodile, Nile crocodile, Crocodylus niloticus',
52 | 'American alligator, Alligator mississipiensis',
53 | 'triceratops',
54 | 'thunder snake, worm snake, Carphophis amoenus',
55 | 'ringneck snake, ring-necked snake, ring snake',
56 | 'hognose snake, puff adder, sand viper',
57 | 'green snake, grass snake',
58 | 'king snake, kingsnake',
59 | 'garter snake, grass snake',
60 | 'water snake',
61 | 'vine snake',
62 | 'night snake, Hypsiglena torquata',
63 | 'boa constrictor, Constrictor constrictor',
64 | 'rock python, rock snake, Python sebae',
65 | 'Indian cobra, Naja naja',
66 | 'green mamba',
67 | 'sea snake',
68 | 'horned viper, cerastes, sand viper, horned asp, Cerastes cornutus',
69 | 'diamondback, diamondback rattlesnake, Crotalus adamanteus',
70 | 'sidewinder, horned rattlesnake, Crotalus cerastes',
71 | 'trilobite',
72 | 'harvestman, daddy longlegs, Phalangium opilio',
73 | 'scorpion',
74 | 'black and gold garden spider, Argiope aurantia',
75 | 'barn spider, Araneus cavaticus',
76 | 'garden spider, Aranea diademata',
77 | 'black widow, Latrodectus mactans',
78 | 'tarantula',
79 | 'wolf spider, hunting spider',
80 | 'tick',
81 | 'centipede',
82 | 'black grouse',
83 | 'ptarmigan',
84 | 'ruffed grouse, partridge, Bonasa umbellus',
85 | 'prairie chicken, prairie grouse, prairie fowl',
86 | 'peacock',
87 | 'quail',
88 | 'partridge',
89 | 'African grey, African gray, Psittacus erithacus',
90 | 'macaw',
91 | 'sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita',
92 | 'lorikeet',
93 | 'coucal',
94 | 'bee eater',
95 | 'hornbill',
96 | 'hummingbird',
97 | 'jacamar',
98 | 'toucan',
99 | 'drake',
100 | 'red-breasted merganser, Mergus serrator',
101 | 'goose',
102 | 'black swan, Cygnus atratus',
103 | 'tusker',
104 | 'echidna, spiny anteater, anteater',
105 | 'platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus',
106 | 'wallaby, brush kangaroo',
107 | 'koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus',
108 | 'wombat',
109 | 'jellyfish',
110 | 'sea anemone, anemone',
111 | 'brain coral',
112 | 'flatworm, platyhelminth',
113 | 'nematode, nematode worm, roundworm',
114 | 'conch',
115 | 'snail',
116 | 'slug',
117 | 'sea slug, nudibranch',
118 | 'chiton, coat-of-mail shell, sea cradle, polyplacophore',
119 | 'chambered nautilus, pearly nautilus, nautilus',
120 | 'Dungeness crab, Cancer magister',
121 | 'rock crab, Cancer irroratus',
122 | 'fiddler crab',
123 | 'king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica',
124 | 'American lobster, Northern lobster, Maine lobster, Homarus americanus',
125 | 'spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish',
126 | 'crayfish, crawfish, crawdad, crawdaddy',
127 | 'hermit crab',
128 | 'isopod',
129 | 'white stork, Ciconia ciconia',
130 | 'black stork, Ciconia nigra',
131 | 'spoonbill',
132 | 'flamingo',
133 | 'little blue heron, Egretta caerulea',
134 | 'American egret, great white heron, Egretta albus',
135 | 'bittern',
136 | 'crane',
137 | 'limpkin, Aramus pictus',
138 | 'European gallinule, Porphyrio porphyrio',
139 | 'American coot, marsh hen, mud hen, water hen, Fulica americana',
140 | 'bustard',
141 | 'ruddy turnstone, Arenaria interpres',
142 | 'red-backed sandpiper, dunlin, Erolia alpina',
143 | 'redshank, Tringa totanus',
144 | 'dowitcher',
145 | 'oystercatcher, oyster catcher',
146 | 'pelican',
147 | 'king penguin, Aptenodytes patagonica',
148 | 'albatross, mollymawk',
149 | 'grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus',
150 | 'killer whale, killer, orca, grampus, sea wolf, Orcinus orca',
151 | 'dugong, Dugong dugon',
152 | 'sea lion',
153 | 'Chihuahua',
154 | 'Japanese spaniel',
155 | 'Maltese dog, Maltese terrier, Maltese',
156 | 'Pekinese, Pekingese, Peke',
157 | 'Shih-Tzu',
158 | 'Blenheim spaniel',
159 | 'papillon',
160 | 'toy terrier',
161 | 'Rhodesian ridgeback',
162 | 'Afghan hound, Afghan',
163 | 'basset, basset hound',
164 | 'beagle',
165 | 'bloodhound, sleuthhound',
166 | 'bluetick',
167 | 'black-and-tan coonhound',
168 | 'Walker hound, Walker foxhound',
169 | 'English foxhound',
170 | 'redbone',
171 | 'borzoi, Russian wolfhound',
172 | 'Irish wolfhound',
173 | 'Italian greyhound',
174 | 'whippet',
175 | 'Ibizan hound, Ibizan Podenco',
176 | 'Norwegian elkhound, elkhound',
177 | 'otterhound, otter hound',
178 | 'Saluki, gazelle hound',
179 | 'Scottish deerhound, deerhound',
180 | 'Weimaraner',
181 | 'Staffordshire bullterrier, Staffordshire bull terrier',
182 | 'American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier',
183 | 'Bedlington terrier',
184 | 'Border terrier',
185 | 'Kerry blue terrier',
186 | 'Irish terrier',
187 | 'Norfolk terrier',
188 | 'Norwich terrier',
189 | 'Yorkshire terrier',
190 | 'wire-haired fox terrier',
191 | 'Lakeland terrier',
192 | 'Sealyham terrier, Sealyham',
193 | 'Airedale, Airedale terrier',
194 | 'cairn, cairn terrier',
195 | 'Australian terrier',
196 | 'Dandie Dinmont, Dandie Dinmont terrier',
197 | 'Boston bull, Boston terrier',
198 | 'miniature schnauzer',
199 | 'giant schnauzer',
200 | 'standard schnauzer',
201 | 'Scotch terrier, Scottish terrier, Scottie',
202 | 'Tibetan terrier, chrysanthemum dog',
203 | 'silky terrier, Sydney silky',
204 | 'soft-coated wheaten terrier',
205 | 'West Highland white terrier',
206 | 'Lhasa, Lhasa apso',
207 | 'flat-coated retriever',
208 | 'curly-coated retriever',
209 | 'golden retriever',
210 | 'Labrador retriever',
211 | 'Chesapeake Bay retriever',
212 | 'German short-haired pointer',
213 | 'vizsla, Hungarian pointer',
214 | 'English setter',
215 | 'Irish setter, red setter',
216 | 'Gordon setter',
217 | 'Brittany spaniel',
218 | 'clumber, clumber spaniel',
219 | 'English springer, English springer spaniel',
220 | 'Welsh springer spaniel',
221 | 'cocker spaniel, English cocker spaniel, cocker',
222 | 'Sussex spaniel',
223 | 'Irish water spaniel',
224 | 'kuvasz',
225 | 'schipperke',
226 | 'groenendael',
227 | 'malinois',
228 | 'briard',
229 | 'kelpie',
230 | 'komondor',
231 | 'Old English sheepdog, bobtail',
232 | 'Shetland sheepdog, Shetland sheep dog, Shetland',
233 | 'collie',
234 | 'Border collie',
235 | 'Bouvier des Flandres, Bouviers des Flandres',
236 | 'Rottweiler',
237 | 'German shepherd, German shepherd dog, German police dog, alsatian',
238 | 'Doberman, Doberman pinscher',
239 | 'miniature pinscher',
240 | 'Greater Swiss Mountain dog',
241 | 'Bernese mountain dog',
242 | 'Appenzeller',
243 | 'EntleBucher',
244 | 'boxer',
245 | 'bull mastiff',
246 | 'Tibetan mastiff',
247 | 'French bulldog',
248 | 'Great Dane',
249 | 'Saint Bernard, St Bernard',
250 | 'Eskimo dog, husky',
251 | 'malamute, malemute, Alaskan malamute',
252 | 'Siberian husky',
253 | 'dalmatian, coach dog, carriage dog',
254 | 'affenpinscher, monkey pinscher, monkey dog',
255 | 'basenji',
256 | 'pug, pug-dog',
257 | 'Leonberg',
258 | 'Newfoundland, Newfoundland dog',
259 | 'Great Pyrenees',
260 | 'Samoyed, Samoyede',
261 | 'Pomeranian',
262 | 'chow, chow chow',
263 | 'keeshond',
264 | 'Brabancon griffon',
265 | 'Pembroke, Pembroke Welsh corgi',
266 | 'Cardigan, Cardigan Welsh corgi',
267 | 'toy poodle',
268 | 'miniature poodle',
269 | 'standard poodle',
270 | 'Mexican hairless',
271 | 'timber wolf, grey wolf, gray wolf, Canis lupus',
272 | 'white wolf, Arctic wolf, Canis lupus tundrarum',
273 | 'red wolf, maned wolf, Canis rufus, Canis niger',
274 | 'coyote, prairie wolf, brush wolf, Canis latrans',
275 | 'dingo, warrigal, warragal, Canis dingo',
276 | 'dhole, Cuon alpinus',
277 | 'African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus',
278 | 'hyena, hyaena',
279 | 'red fox, Vulpes vulpes',
280 | 'kit fox, Vulpes macrotis',
281 | 'Arctic fox, white fox, Alopex lagopus',
282 | 'grey fox, gray fox, Urocyon cinereoargenteus',
283 | 'tabby, tabby cat',
284 | 'tiger cat',
285 | 'Persian cat',
286 | 'Siamese cat, Siamese',
287 | 'Egyptian cat',
288 | 'cougar, puma, catamount, mountain lion, painter, panther, Felis concolor',
289 | 'lynx, catamount',
290 | 'leopard, Panthera pardus',
291 | 'snow leopard, ounce, Panthera uncia',
292 | 'jaguar, panther, Panthera onca, Felis onca',
293 | 'lion, king of beasts, Panthera leo',
294 | 'tiger, Panthera tigris',
295 | 'cheetah, chetah, Acinonyx jubatus',
296 | 'brown bear, bruin, Ursus arctos',
297 | 'American black bear, black bear, Ursus americanus, Euarctos americanus',
298 | 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus',
299 | 'sloth bear, Melursus ursinus, Ursus ursinus',
300 | 'mongoose',
301 | 'meerkat, mierkat',
302 | 'tiger beetle',
303 | 'ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle',
304 | 'ground beetle, carabid beetle',
305 | 'long-horned beetle, longicorn, longicorn beetle',
306 | 'leaf beetle, chrysomelid',
307 | 'dung beetle',
308 | 'rhinoceros beetle',
309 | 'weevil',
310 | 'fly',
311 | 'bee',
312 | 'ant, emmet, pismire',
313 | 'grasshopper, hopper',
314 | 'cricket',
315 | 'walking stick, walkingstick, stick insect',
316 | 'cockroach, roach',
317 | 'mantis, mantid',
318 | 'cicada, cicala',
319 | 'leafhopper',
320 | 'lacewing, lacewing fly',
321 | "dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
322 | 'damselfly',
323 | 'admiral',
324 | 'ringlet, ringlet butterfly',
325 | 'monarch, monarch butterfly, milkweed butterfly, Danaus plexippus',
326 | 'cabbage butterfly',
327 | 'sulphur butterfly, sulfur butterfly',
328 | 'lycaenid, lycaenid butterfly',
329 | 'starfish, sea star',
330 | 'sea urchin',
331 | 'sea cucumber, holothurian',
332 | 'wood rabbit, cottontail, cottontail rabbit',
333 | 'hare',
334 | 'Angora, Angora rabbit',
335 | 'hamster',
336 | 'porcupine, hedgehog',
337 | 'fox squirrel, eastern fox squirrel, Sciurus niger',
338 | 'marmot',
339 | 'beaver',
340 | 'guinea pig, Cavia cobaya',
341 | 'sorrel',
342 | 'zebra',
343 | 'hog, pig, grunter, squealer, Sus scrofa',
344 | 'wild boar, boar, Sus scrofa',
345 | 'warthog',
346 | 'hippopotamus, hippo, river horse, Hippopotamus amphibius',
347 | 'ox',
348 | 'water buffalo, water ox, Asiatic buffalo, Bubalus bubalis',
349 | 'bison',
350 | 'ram, tup',
351 | 'bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis',
352 | 'ibex, Capra ibex',
353 | 'hartebeest',
354 | 'impala, Aepyceros melampus',
355 | 'gazelle',
356 | 'Arabian camel, dromedary, Camelus dromedarius',
357 | 'llama',
358 | 'weasel',
359 | 'mink',
360 | 'polecat, fitch, foulmart, foumart, Mustela putorius',
361 | 'black-footed ferret, ferret, Mustela nigripes',
362 | 'otter',
363 | 'skunk, polecat, wood pussy',
364 | 'badger',
365 | 'armadillo',
366 | 'three-toed sloth, ai, Bradypus tridactylus',
367 | 'orangutan, orang, orangutang, Pongo pygmaeus',
368 | 'gorilla, Gorilla gorilla',
369 | 'chimpanzee, chimp, Pan troglodytes',
370 | 'gibbon, Hylobates lar',
371 | 'siamang, Hylobates syndactylus, Symphalangus syndactylus',
372 | 'guenon, guenon monkey',
373 | 'patas, hussar monkey, Erythrocebus patas',
374 | 'baboon',
375 | 'macaque',
376 | 'langur',
377 | 'colobus, colobus monkey',
378 | 'proboscis monkey, Nasalis larvatus',
379 | 'marmoset',
380 | 'capuchin, ringtail, Cebus capucinus',
381 | 'howler monkey, howler',
382 | 'titi, titi monkey',
383 | 'spider monkey, Ateles geoffroyi',
384 | 'squirrel monkey, Saimiri sciureus',
385 | 'Madagascar cat, ring-tailed lemur, Lemur catta',
386 | 'indri, indris, Indri indri, Indri brevicaudatus',
387 | 'Indian elephant, Elephas maximus',
388 | 'African elephant, Loxodonta africana',
389 | 'lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens',
390 | 'giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca',
391 | 'barracouta, snoek',
392 | 'eel',
393 | 'coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch',
394 | 'rock beauty, Holocanthus tricolor',
395 | 'anemone fish',
396 | 'sturgeon',
397 | 'gar, garfish, garpike, billfish, Lepisosteus osseus',
398 | 'lionfish',
399 | 'puffer, pufferfish, blowfish, globefish',
400 | 'abacus',
401 | 'abaya',
402 | "academic gown, academic robe, judge's robe",
403 | 'accordion, piano accordion, squeeze box',
404 | 'acoustic guitar',
405 | 'aircraft carrier, carrier, flattop, attack aircraft carrier',
406 | 'airliner',
407 | 'airship, dirigible',
408 | 'altar',
409 | 'ambulance',
410 | 'amphibian, amphibious vehicle',
411 | 'analog clock',
412 | 'apiary, bee house',
413 | 'apron',
414 | 'ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin',
415 | 'assault rifle, assault gun',
416 | 'backpack, back pack, knapsack, packsack, rucksack, haversack',
417 | 'bakery, bakeshop, bakehouse',
418 | 'balance beam, beam',
419 | 'balloon',
420 | 'ballpoint, ballpoint pen, ballpen, Biro',
421 | 'Band Aid',
422 | 'banjo',
423 | 'bannister, banister, balustrade, balusters, handrail',
424 | 'barbell',
425 | 'barber chair',
426 | 'barbershop',
427 | 'barn',
428 | 'barometer',
429 | 'barrel, cask',
430 | 'barrow, garden cart, lawn cart, wheelbarrow',
431 | 'baseball',
432 | 'basketball',
433 | 'bassinet',
434 | 'bassoon',
435 | 'bathing cap, swimming cap',
436 | 'bath towel',
437 | 'bathtub, bathing tub, bath, tub',
438 | 'beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon',
439 | 'beacon, lighthouse, beacon light, pharos',
440 | 'beaker',
441 | 'bearskin, busby, shako',
442 | 'beer bottle',
443 | 'beer glass',
444 | 'bell cote, bell cot',
445 | 'bib',
446 | 'bicycle-built-for-two, tandem bicycle, tandem',
447 | 'bikini, two-piece',
448 | 'binder, ring-binder',
449 | 'binoculars, field glasses, opera glasses',
450 | 'birdhouse',
451 | 'boathouse',
452 | 'bobsled, bobsleigh, bob',
453 | 'bolo tie, bolo, bola tie, bola',
454 | 'bonnet, poke bonnet',
455 | 'bookcase',
456 | 'bookshop, bookstore, bookstall',
457 | 'bottlecap',
458 | 'bow',
459 | 'bow tie, bow-tie, bowtie',
460 | 'brass, memorial tablet, plaque',
461 | 'brassiere, bra, bandeau',
462 | 'breakwater, groin, groyne, mole, bulwark, seawall, jetty',
463 | 'breastplate, aegis, egis',
464 | 'broom',
465 | 'bucket, pail',
466 | 'buckle',
467 | 'bulletproof vest',
468 | 'bullet train, bullet',
469 | 'butcher shop, meat market',
470 | 'cab, hack, taxi, taxicab',
471 | 'caldron, cauldron',
472 | 'candle, taper, wax light',
473 | 'cannon',
474 | 'canoe',
475 | 'can opener, tin opener',
476 | 'cardigan',
477 | 'car mirror',
478 | 'carousel, carrousel, merry-go-round, roundabout, whirligig',
479 | "carpenter's kit, tool kit",
480 | 'carton',
481 | 'car wheel',
482 | 'cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM',
483 | 'cassette',
484 | 'cassette player',
485 | 'castle',
486 | 'catamaran',
487 | 'CD player',
488 | 'cello, violoncello',
489 | 'cellular telephone, cellular phone, cellphone, cell, mobile phone',
490 | 'chain',
491 | 'chainlink fence',
492 | 'chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour',
493 | 'chain saw, chainsaw',
494 | 'chest',
495 | 'chiffonier, commode',
496 | 'chime, bell, gong',
497 | 'china cabinet, china closet',
498 | 'Christmas stocking',
499 | 'church, church building',
500 | 'cinema, movie theater, movie theatre, movie house, picture palace',
501 | 'cleaver, meat cleaver, chopper',
502 | 'cliff dwelling',
503 | 'cloak',
504 | 'clog, geta, patten, sabot',
505 | 'cocktail shaker',
506 | 'coffee mug',
507 | 'coffeepot',
508 | 'coil, spiral, volute, whorl, helix',
509 | 'combination lock',
510 | 'computer keyboard, keypad',
511 | 'confectionery, confectionary, candy store',
512 | 'container ship, containership, container vessel',
513 | 'convertible',
514 | 'corkscrew, bottle screw',
515 | 'cornet, horn, trumpet, trump',
516 | 'cowboy boot',
517 | 'cowboy hat, ten-gallon hat',
518 | 'cradle',
519 | 'crane',
520 | 'crash helmet',
521 | 'crate',
522 | 'crib, cot',
523 | 'Crock Pot',
524 | 'croquet ball',
525 | 'crutch',
526 | 'cuirass',
527 | 'dam, dike, dyke',
528 | 'desk',
529 | 'desktop computer',
530 | 'dial telephone, dial phone',
531 | 'diaper, nappy, napkin',
532 | 'digital clock',
533 | 'digital watch',
534 | 'dining table, board',
535 | 'dishrag, dishcloth',
536 | 'dishwasher, dish washer, dishwashing machine',
537 | 'disk brake, disc brake',
538 | 'dock, dockage, docking facility',
539 | 'dogsled, dog sled, dog sleigh',
540 | 'dome',
541 | 'doormat, welcome mat',
542 | 'drilling platform, offshore rig',
543 | 'drum, membranophone, tympan',
544 | 'drumstick',
545 | 'dumbbell',
546 | 'Dutch oven',
547 | 'electric fan, blower',
548 | 'electric guitar',
549 | 'electric locomotive',
550 | 'entertainment center',
551 | 'envelope',
552 | 'espresso maker',
553 | 'face powder',
554 | 'feather boa, boa',
555 | 'file, file cabinet, filing cabinet',
556 | 'fireboat',
557 | 'fire engine, fire truck',
558 | 'fire screen, fireguard',
559 | 'flagpole, flagstaff',
560 | 'flute, transverse flute',
561 | 'folding chair',
562 | 'football helmet',
563 | 'forklift',
564 | 'fountain',
565 | 'fountain pen',
566 | 'four-poster',
567 | 'freight car',
568 | 'French horn, horn',
569 | 'frying pan, frypan, skillet',
570 | 'fur coat',
571 | 'garbage truck, dustcart',
572 | 'gasmask, respirator, gas helmet',
573 | 'gas pump, gasoline pump, petrol pump, island dispenser',
574 | 'goblet',
575 | 'go-kart',
576 | 'golf ball',
577 | 'golfcart, golf cart',
578 | 'gondola',
579 | 'gong, tam-tam',
580 | 'gown',
581 | 'grand piano, grand',
582 | 'greenhouse, nursery, glasshouse',
583 | 'grille, radiator grille',
584 | 'grocery store, grocery, food market, market',
585 | 'guillotine',
586 | 'hair slide',
587 | 'hair spray',
588 | 'half track',
589 | 'hammer',
590 | 'hamper',
591 | 'hand blower, blow dryer, blow drier, hair dryer, hair drier',
592 | 'hand-held computer, hand-held microcomputer',
593 | 'handkerchief, hankie, hanky, hankey',
594 | 'hard disc, hard disk, fixed disk',
595 | 'harmonica, mouth organ, harp, mouth harp',
596 | 'harp',
597 | 'harvester, reaper',
598 | 'hatchet',
599 | 'holster',
600 | 'home theater, home theatre',
601 | 'honeycomb',
602 | 'hook, claw',
603 | 'hoopskirt, crinoline',
604 | 'horizontal bar, high bar',
605 | 'horse cart, horse-cart',
606 | 'hourglass',
607 | 'iPod',
608 | 'iron, smoothing iron',
609 | "jack-o'-lantern",
610 | 'jean, blue jean, denim',
611 | 'jeep, landrover',
612 | 'jersey, T-shirt, tee shirt',
613 | 'jigsaw puzzle',
614 | 'jinrikisha, ricksha, rickshaw',
615 | 'joystick',
616 | 'kimono',
617 | 'knee pad',
618 | 'knot',
619 | 'lab coat, laboratory coat',
620 | 'ladle',
621 | 'lampshade, lamp shade',
622 | 'laptop, laptop computer',
623 | 'lawn mower, mower',
624 | 'lens cap, lens cover',
625 | 'letter opener, paper knife, paperknife',
626 | 'library',
627 | 'lifeboat',
628 | 'lighter, light, igniter, ignitor',
629 | 'limousine, limo',
630 | 'liner, ocean liner',
631 | 'lipstick, lip rouge',
632 | 'Loafer',
633 | 'lotion',
634 | 'loudspeaker, speaker, speaker unit, loudspeaker system, speaker system',
635 | "loupe, jeweler's loupe",
636 | 'lumbermill, sawmill',
637 | 'magnetic compass',
638 | 'mailbag, postbag',
639 | 'mailbox, letter box',
640 | 'maillot',
641 | 'maillot, tank suit',
642 | 'manhole cover',
643 | 'maraca',
644 | 'marimba, xylophone',
645 | 'mask',
646 | 'matchstick',
647 | 'maypole',
648 | 'maze, labyrinth',
649 | 'measuring cup',
650 | 'medicine chest, medicine cabinet',
651 | 'megalith, megalithic structure',
652 | 'microphone, mike',
653 | 'microwave, microwave oven',
654 | 'military uniform',
655 | 'milk can',
656 | 'minibus',
657 | 'miniskirt, mini',
658 | 'minivan',
659 | 'missile',
660 | 'mitten',
661 | 'mixing bowl',
662 | 'mobile home, manufactured home',
663 | 'Model T',
664 | 'modem',
665 | 'monastery',
666 | 'monitor',
667 | 'moped',
668 | 'mortar',
669 | 'mortarboard',
670 | 'mosque',
671 | 'mosquito net',
672 | 'motor scooter, scooter',
673 | 'mountain bike, all-terrain bike, off-roader',
674 | 'mountain tent',
675 | 'mouse, computer mouse',
676 | 'mousetrap',
677 | 'moving van',
678 | 'muzzle',
679 | 'nail',
680 | 'neck brace',
681 | 'necklace',
682 | 'nipple',
683 | 'notebook, notebook computer',
684 | 'obelisk',
685 | 'oboe, hautboy, hautbois',
686 | 'ocarina, sweet potato',
687 | 'odometer, hodometer, mileometer, milometer',
688 | 'oil filter',
689 | 'organ, pipe organ',
690 | 'oscilloscope, scope, cathode-ray oscilloscope, CRO',
691 | 'overskirt',
692 | 'oxcart',
693 | 'oxygen mask',
694 | 'packet',
695 | 'paddle, boat paddle',
696 | 'paddlewheel, paddle wheel',
697 | 'padlock',
698 | 'paintbrush',
699 | "pajama, pyjama, pj's, jammies",
700 | 'palace',
701 | 'panpipe, pandean pipe, syrinx',
702 | 'paper towel',
703 | 'parachute, chute',
704 | 'parallel bars, bars',
705 | 'park bench',
706 | 'parking meter',
707 | 'passenger car, coach, carriage',
708 | 'patio, terrace',
709 | 'pay-phone, pay-station',
710 | 'pedestal, plinth, footstall',
711 | 'pencil box, pencil case',
712 | 'pencil sharpener',
713 | 'perfume, essence',
714 | 'Petri dish',
715 | 'photocopier',
716 | 'pick, plectrum, plectron',
717 | 'pickelhaube',
718 | 'picket fence, paling',
719 | 'pickup, pickup truck',
720 | 'pier',
721 | 'piggy bank, penny bank',
722 | 'pill bottle',
723 | 'pillow',
724 | 'ping-pong ball',
725 | 'pinwheel',
726 | 'pirate, pirate ship',
727 | 'pitcher, ewer',
728 | "plane, carpenter's plane, woodworking plane",
729 | 'planetarium',
730 | 'plastic bag',
731 | 'plate rack',
732 | 'plow, plough',
733 | "plunger, plumber's helper",
734 | 'Polaroid camera, Polaroid Land camera',
735 | 'pole',
736 | 'police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria',
737 | 'poncho',
738 | 'pool table, billiard table, snooker table',
739 | 'pop bottle, soda bottle',
740 | 'pot, flowerpot',
741 | "potter's wheel",
742 | 'power drill',
743 | 'prayer rug, prayer mat',
744 | 'printer',
745 | 'prison, prison house',
746 | 'projectile, missile',
747 | 'projector',
748 | 'puck, hockey puck',
749 | 'punching bag, punch bag, punching ball, punchball',
750 | 'purse',
751 | 'quill, quill pen',
752 | 'quilt, comforter, comfort, puff',
753 | 'racer, race car, racing car',
754 | 'racket, racquet',
755 | 'radiator',
756 | 'radio, wireless',
757 | 'radio telescope, radio reflector',
758 | 'rain barrel',
759 | 'recreational vehicle, RV, R.V.',
760 | 'reel',
761 | 'reflex camera',
762 | 'refrigerator, icebox',
763 | 'remote control, remote',
764 | 'restaurant, eating house, eating place, eatery',
765 | 'revolver, six-gun, six-shooter',
766 | 'rifle',
767 | 'rocking chair, rocker',
768 | 'rotisserie',
769 | 'rubber eraser, rubber, pencil eraser',
770 | 'rugby ball',
771 | 'rule, ruler',
772 | 'running shoe',
773 | 'safe',
774 | 'safety pin',
775 | 'saltshaker, salt shaker',
776 | 'sandal',
777 | 'sarong',
778 | 'sax, saxophone',
779 | 'scabbard',
780 | 'scale, weighing machine',
781 | 'school bus',
782 | 'schooner',
783 | 'scoreboard',
784 | 'screen, CRT screen',
785 | 'screw',
786 | 'screwdriver',
787 | 'seat belt, seatbelt',
788 | 'sewing machine',
789 | 'shield, buckler',
790 | 'shoe shop, shoe-shop, shoe store',
791 | 'shoji',
792 | 'shopping basket',
793 | 'shopping cart',
794 | 'shovel',
795 | 'shower cap',
796 | 'shower curtain',
797 | 'ski',
798 | 'ski mask',
799 | 'sleeping bag',
800 | 'slide rule, slipstick',
801 | 'sliding door',
802 | 'slot, one-armed bandit',
803 | 'snorkel',
804 | 'snowmobile',
805 | 'snowplow, snowplough',
806 | 'soap dispenser',
807 | 'soccer ball',
808 | 'sock',
809 | 'solar dish, solar collector, solar furnace',
810 | 'sombrero',
811 | 'soup bowl',
812 | 'space bar',
813 | 'space heater',
814 | 'space shuttle',
815 | 'spatula',
816 | 'speedboat',
817 | "spider web, spider's web",
818 | 'spindle',
819 | 'sports car, sport car',
820 | 'spotlight, spot',
821 | 'stage',
822 | 'steam locomotive',
823 | 'steel arch bridge',
824 | 'steel drum',
825 | 'stethoscope',
826 | 'stole',
827 | 'stone wall',
828 | 'stopwatch, stop watch',
829 | 'stove',
830 | 'strainer',
831 | 'streetcar, tram, tramcar, trolley, trolley car',
832 | 'stretcher',
833 | 'studio couch, day bed',
834 | 'stupa, tope',
835 | 'submarine, pigboat, sub, U-boat',
836 | 'suit, suit of clothes',
837 | 'sundial',
838 | 'sunglass',
839 | 'sunglasses, dark glasses, shades',
840 | 'sunscreen, sunblock, sun blocker',
841 | 'suspension bridge',
842 | 'swab, swob, mop',
843 | 'sweatshirt',
844 | 'swimming trunks, bathing trunks',
845 | 'swing',
846 | 'switch, electric switch, electrical switch',
847 | 'syringe',
848 | 'table lamp',
849 | 'tank, army tank, armored combat vehicle, armoured combat vehicle',
850 | 'tape player',
851 | 'teapot',
852 | 'teddy, teddy bear',
853 | 'television, television system',
854 | 'tennis ball',
855 | 'thatch, thatched roof',
856 | 'theater curtain, theatre curtain',
857 | 'thimble',
858 | 'thresher, thrasher, threshing machine',
859 | 'throne',
860 | 'tile roof',
861 | 'toaster',
862 | 'tobacco shop, tobacconist shop, tobacconist',
863 | 'toilet seat',
864 | 'torch',
865 | 'totem pole',
866 | 'tow truck, tow car, wrecker',
867 | 'toyshop',
868 | 'tractor',
869 | 'trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi',
870 | 'tray',
871 | 'trench coat',
872 | 'tricycle, trike, velocipede',
873 | 'trimaran',
874 | 'tripod',
875 | 'triumphal arch',
876 | 'trolleybus, trolley coach, trackless trolley',
877 | 'trombone',
878 | 'tub, vat',
879 | 'turnstile',
880 | 'typewriter keyboard',
881 | 'umbrella',
882 | 'unicycle, monocycle',
883 | 'upright, upright piano',
884 | 'vacuum, vacuum cleaner',
885 | 'vase',
886 | 'vault',
887 | 'velvet',
888 | 'vending machine',
889 | 'vestment',
890 | 'viaduct',
891 | 'violin, fiddle',
892 | 'volleyball',
893 | 'waffle iron',
894 | 'wall clock',
895 | 'wallet, billfold, notecase, pocketbook',
896 | 'wardrobe, closet, press',
897 | 'warplane, military plane',
898 | 'washbasin, handbasin, washbowl, lavabo, wash-hand basin',
899 | 'washer, automatic washer, washing machine',
900 | 'water bottle',
901 | 'water jug',
902 | 'water tower',
903 | 'whiskey jug',
904 | 'whistle',
905 | 'wig',
906 | 'window screen',
907 | 'window shade',
908 | 'Windsor tie',
909 | 'wine bottle',
910 | 'wing',
911 | 'wok',
912 | 'wooden spoon',
913 | 'wool, woolen, woollen',
914 | 'worm fence, snake fence, snake-rail fence, Virginia fence',
915 | 'wreck',
916 | 'yawl',
917 | 'yurt',
918 | 'web site, website, internet site, site',
919 | 'comic book',
920 | 'crossword puzzle, crossword',
921 | 'street sign',
922 | 'traffic light, traffic signal, stoplight',
923 | 'book jacket, dust cover, dust jacket, dust wrapper',
924 | 'menu',
925 | 'plate',
926 | 'guacamole',
927 | 'consomme',
928 | 'hot pot, hotpot',
929 | 'trifle',
930 | 'ice cream, icecream',
931 | 'ice lolly, lolly, lollipop, popsicle',
932 | 'French loaf',
933 | 'bagel, beigel',
934 | 'pretzel',
935 | 'cheeseburger',
936 | 'hotdog, hot dog, red hot',
937 | 'mashed potato',
938 | 'head cabbage',
939 | 'broccoli',
940 | 'cauliflower',
941 | 'zucchini, courgette',
942 | 'spaghetti squash',
943 | 'acorn squash',
944 | 'butternut squash',
945 | 'cucumber, cuke',
946 | 'artichoke, globe artichoke',
947 | 'bell pepper',
948 | 'cardoon',
949 | 'mushroom',
950 | 'Granny Smith',
951 | 'strawberry',
952 | 'orange',
953 | 'lemon',
954 | 'fig',
955 | 'pineapple, ananas',
956 | 'banana',
957 | 'jackfruit, jak, jack',
958 | 'custard apple',
959 | 'pomegranate',
960 | 'hay',
961 | 'carbonara',
962 | 'chocolate sauce, chocolate syrup',
963 | 'dough',
964 | 'meat loaf, meatloaf',
965 | 'pizza, pizza pie',
966 | 'potpie',
967 | 'burrito',
968 | 'red wine',
969 | 'espresso',
970 | 'cup',
971 | 'eggnog',
972 | 'alp',
973 | 'bubble',
974 | 'cliff, drop, drop-off',
975 | 'coral reef',
976 | 'geyser',
977 | 'lakeside, lakeshore',
978 | 'promontory, headland, head, foreland',
979 | 'sandbar, sand bar',
980 | 'seashore, coast, seacoast, sea-coast',
981 | 'valley, vale',
982 | 'volcano',
983 | 'ballplayer, baseball player',
984 | 'groom, bridegroom',
985 | 'scuba diver',
986 | 'rapeseed',
987 | 'daisy',
988 | "yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",
989 | 'corn',
990 | 'acorn',
991 | 'hip, rose hip, rosehip',
992 | 'buckeye, horse chestnut, conker',
993 | 'coral fungus',
994 | 'agaric',
995 | 'gyromitra',
996 | 'stinkhorn, carrion fungus',
997 | 'earthstar',
998 | 'hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa',
999 | 'bolete',
1000 | 'ear, spike, capitulum',
1001 | 'toilet tissue, toilet paper, bathroom tissue'
1002 | }
1003 |
1004 |
--------------------------------------------------------------------------------
/images/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/1.png
--------------------------------------------------------------------------------
/images/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/10.png
--------------------------------------------------------------------------------
/images/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/11.png
--------------------------------------------------------------------------------
/images/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/12.png
--------------------------------------------------------------------------------
/images/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/13.png
--------------------------------------------------------------------------------
/images/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/14.png
--------------------------------------------------------------------------------
/images/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/15.png
--------------------------------------------------------------------------------
/images/16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/16.png
--------------------------------------------------------------------------------
/images/17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/17.png
--------------------------------------------------------------------------------
/images/18.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/18.png
--------------------------------------------------------------------------------
/images/19.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/19.png
--------------------------------------------------------------------------------
/images/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/2.png
--------------------------------------------------------------------------------
/images/20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/20.png
--------------------------------------------------------------------------------
/images/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/3.png
--------------------------------------------------------------------------------
/images/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/4.png
--------------------------------------------------------------------------------
/images/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/5.png
--------------------------------------------------------------------------------
/images/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/6.png
--------------------------------------------------------------------------------
/images/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/7.png
--------------------------------------------------------------------------------
/images/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/8.png
--------------------------------------------------------------------------------
/images/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghang1989/visualResNet_torch/5d4e021cc2b2030726bf2f10c2e8dd5475ca72f3/images/9.png
--------------------------------------------------------------------------------
/transforms.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- Copyright (c) 2016, Facebook, Inc.
3 | -- All rights reserved.
4 | --
5 | -- This source code is licensed under the BSD-style license found in the
6 | -- LICENSE file in the root directory of this source tree. An additional grant
7 | -- of patent rights can be found in the PATENTS file in the same directory.
8 | --
9 | -- Image transforms for data augmentation and input normalization
10 | --
11 |
12 | require 'image'
13 |
14 | local M = {}
15 |
16 | function M.Compose(transforms)
17 | return function(input)
18 | for _, transform in ipairs(transforms) do
19 | input = transform(input)
20 | end
21 | return input
22 | end
23 | end
24 |
25 | function M.ColorNormalize(meanstd)
26 | return function(img)
27 | img = img:clone()
28 | for i=1,3 do
29 | img[i]:add(-meanstd.mean[i])
30 | img[i]:div(meanstd.std[i])
31 | end
32 | return img
33 | end
34 | end
35 |
36 | -- Scales the smaller edge to size
37 | function M.Scale(size, interpolation)
38 | interpolation = interpolation or 'bicubic'
39 | return function(input)
40 | local w, h = input:size(3), input:size(2)
41 | if (w <= h and w == size) or (h <= w and h == size) then
42 | return input
43 | end
44 | if w < h then
45 | return image.scale(input, size, h/w * size, interpolation)
46 | else
47 | return image.scale(input, w/h * size, size, interpolation)
48 | end
49 | end
50 | end
51 |
52 | -- Crop to centered rectangle
53 | function M.CenterCrop(size)
54 | return function(input)
55 | local w1 = math.ceil((input:size(3) - size)/2)
56 | local h1 = math.ceil((input:size(2) - size)/2)
57 | return image.crop(input, w1, h1, w1 + size, h1 + size) -- center patch
58 | end
59 | end
60 |
61 | -- Random crop form larger image with optional zero padding
62 | function M.RandomCrop(size, padding)
63 | padding = padding or 0
64 |
65 | return function(input)
66 | if padding > 0 then
67 | local temp = input.new(3, input:size(2) + 2*padding, input:size(3) + 2*padding)
68 | temp:zero()
69 | :narrow(2, padding+1, input:size(2))
70 | :narrow(3, padding+1, input:size(3))
71 | :copy(input)
72 | input = temp
73 | end
74 |
75 | local w, h = input:size(3), input:size(2)
76 | if w == size and h == size then
77 | return input
78 | end
79 |
80 | local x1, y1 = torch.random(0, w - size), torch.random(0, h - size)
81 | local out = image.crop(input, x1, y1, x1 + size, y1 + size)
82 | assert(out:size(2) == size and out:size(3) == size, 'wrong crop size')
83 | return out
84 | end
85 | end
86 |
87 | -- Four corner patches and center crop from image and its horizontal reflection
88 | function M.TenCrop(size)
89 | local centerCrop = M.CenterCrop(size)
90 |
91 | return function(input)
92 | local w, h = input:size(3), input:size(2)
93 |
94 | local output = {}
95 | for _, img in ipairs{input, image.hflip(input)} do
96 | table.insert(output, centerCrop(img))
97 | table.insert(output, image.crop(img, 0, 0, size, size))
98 | table.insert(output, image.crop(img, w-size, 0, w, size))
99 | table.insert(output, image.crop(img, 0, h-size, size, h))
100 | table.insert(output, image.crop(img, w-size, h-size, w, h))
101 | end
102 |
103 | -- View as mini-batch
104 | for i, img in ipairs(output) do
105 | output[i] = img:view(1, img:size(1), img:size(2), img:size(3))
106 | end
107 |
108 | return input.cat(output, 1)
109 | end
110 | end
111 |
112 | -- Resized with shorter side randomly sampled from [minSize, maxSize] (ResNet-style)
113 | function M.RandomScale(minSize, maxSize)
114 | return function(input)
115 | local w, h = input:size(3), input:size(2)
116 |
117 | local targetSz = torch.random(minSize, maxSize)
118 | local targetW, targetH = targetSz, targetSz
119 | if w < h then
120 | targetH = torch.round(h / w * targetW)
121 | else
122 | targetW = torch.round(w / h * targetH)
123 | end
124 |
125 | return image.scale(input, targetW, targetH, 'bicubic')
126 | end
127 | end
128 |
129 | -- Random crop with size 8%-100% and aspect ratio 3/4 - 4/3 (Inception-style)
130 | function M.RandomSizedCrop(size)
131 | local scale = M.Scale(size)
132 | local crop = M.CenterCrop(size)
133 |
134 | return function(input)
135 | local attempt = 0
136 | repeat
137 | local area = input:size(2) * input:size(3)
138 | local targetArea = torch.uniform(0.08, 1.0) * area
139 |
140 | local aspectRatio = torch.uniform(3/4, 4/3)
141 | local w = torch.round(math.sqrt(targetArea * aspectRatio))
142 | local h = torch.round(math.sqrt(targetArea / aspectRatio))
143 |
144 | if torch.uniform() < 0.5 then
145 | w, h = h, w
146 | end
147 |
148 | if h <= input:size(2) and w <= input:size(3) then
149 | local y1 = torch.random(0, input:size(2) - h)
150 | local x1 = torch.random(0, input:size(3) - w)
151 |
152 | local out = image.crop(input, x1, y1, x1 + w, y1 + h)
153 | assert(out:size(2) == h and out:size(3) == w, 'wrong crop size')
154 |
155 | return image.scale(out, size, size, 'bicubic')
156 | end
157 | attempt = attempt + 1
158 | until attempt >= 10
159 |
160 | -- fallback
161 | return crop(scale(input))
162 | end
163 | end
164 |
165 | function M.HorizontalFlip(prob)
166 | return function(input)
167 | if torch.uniform() < prob then
168 | input = image.hflip(input)
169 | end
170 | return input
171 | end
172 | end
173 |
174 | function M.Rotation(deg)
175 | return function(input)
176 | if deg ~= 0 then
177 | input = image.rotate(input, (torch.uniform() - 0.5) * deg * math.pi / 180, 'bilinear')
178 | end
179 | return input
180 | end
181 | end
182 |
183 | -- Lighting noise (AlexNet-style PCA-based noise)
184 | function M.Lighting(alphastd, eigval, eigvec)
185 | return function(input)
186 | if alphastd == 0 then
187 | return input
188 | end
189 |
190 | local alpha = torch.Tensor(3):normal(0, alphastd)
191 | local rgb = eigvec:clone()
192 | :cmul(alpha:view(1, 3):expand(3, 3))
193 | :cmul(eigval:view(1, 3):expand(3, 3))
194 | :sum(2)
195 | :squeeze()
196 |
197 | input = input:clone()
198 | for i=1,3 do
199 | input[i]:add(rgb[i])
200 | end
201 | return input
202 | end
203 | end
204 |
205 | local function blend(img1, img2, alpha)
206 | return img1:mul(alpha):add(1 - alpha, img2)
207 | end
208 |
209 | local function grayscale(dst, img)
210 | dst:resizeAs(img)
211 | dst[1]:zero()
212 | dst[1]:add(0.299, img[1]):add(0.587, img[2]):add(0.114, img[3])
213 | dst[2]:copy(dst[1])
214 | dst[3]:copy(dst[1])
215 | return dst
216 | end
217 |
218 | function M.Saturation(var)
219 | local gs
220 |
221 | return function(input)
222 | gs = gs or input.new()
223 | grayscale(gs, input)
224 |
225 | local alpha = 1.0 + torch.uniform(-var, var)
226 | blend(input, gs, alpha)
227 | return input
228 | end
229 | end
230 |
231 | function M.Brightness(var)
232 | local gs
233 |
234 | return function(input)
235 | gs = gs or input.new()
236 | gs:resizeAs(input):zero()
237 |
238 | local alpha = 1.0 + torch.uniform(-var, var)
239 | blend(input, gs, alpha)
240 | return input
241 | end
242 | end
243 |
244 | function M.Contrast(var)
245 | local gs
246 |
247 | return function(input)
248 | gs = gs or input.new()
249 | grayscale(gs, input)
250 | gs:fill(gs[1]:mean())
251 |
252 | local alpha = 1.0 + torch.uniform(-var, var)
253 | blend(input, gs, alpha)
254 | return input
255 | end
256 | end
257 |
258 | function M.RandomOrder(ts)
259 | return function(input)
260 | local img = input.img or input
261 | local order = torch.randperm(#ts)
262 | for i=1,#ts do
263 | img = ts[order[i]](img)
264 | end
265 | return input
266 | end
267 | end
268 |
269 | function M.ColorJitter(opt)
270 | local brightness = opt.brightness or 0
271 | local contrast = opt.contrast or 0
272 | local saturation = opt.saturation or 0
273 |
274 | local ts = {}
275 | if brightness ~= 0 then
276 | table.insert(ts, M.Brightness(brightness))
277 | end
278 | if contrast ~= 0 then
279 | table.insert(ts, M.Contrast(contrast))
280 | end
281 | if saturation ~= 0 then
282 | table.insert(ts, M.Saturation(saturation))
283 | end
284 |
285 | if #ts == 0 then
286 | return function(input) return input end
287 | end
288 |
289 | return M.RandomOrder(ts)
290 | end
291 |
292 | return M
293 |
294 |
--------------------------------------------------------------------------------
/visual.lua:
--------------------------------------------------------------------------------
1 |
2 | require 'nn'
3 | require 'cunn'
4 | require 'cudnn'
5 | require 'image'
6 | local t = require 'transforms'
7 | local imagenetLabel = require './imagenet'
8 |
9 | if #arg < 2 then
10 | io.stderr:write('Usage: th visual.lua [MODEL] [FILE]...\n')
11 | os.exit(1)
12 | end
13 | for _, f in ipairs(arg) do
14 | if not paths.filep(f) then
15 | io.stderr:write('file not found: ' .. f .. '\n')
16 | os.exit(1)
17 | end
18 | end
19 |
20 |
21 | -- Load the model
22 | local model = torch.load(arg[1])
23 | local net = model:clone()
24 | local softMaxLayer = cudnn.SoftMax():cuda()
25 |
26 | -- add Softmax layer
27 | model:add(softMaxLayer)
28 |
29 | -- Evaluate mode
30 | model:evaluate()
31 |
32 | -- For visualization
33 | weight_lr = net:get(#net.modules).weight:clone()
34 | bias_lr = net:get(#net.modules).bias:clone()
35 | net:remove(#net.modules)
36 | net:remove(#net.modules)
37 | net:remove(#net.modules)
38 | net:add(cudnn.SpatialConvolution(2048,1000,1,1,1,1,0,0))
39 | net:get(#net.modules).weight = torch.reshape(weight_lr, net:get(#net.modules).weight:size())
40 | net:get(#net.modules).bias = torch.reshape(bias_lr, net:get(#net.modules).bias:size())
41 | net:cuda()
42 | net:evaluate()
43 |
44 | -- The model was trained with this input normalization
45 | local meanstd = {
46 | mean = { 0.485, 0.456, 0.406 },
47 | std = { 0.229, 0.224, 0.225 },
48 | }
49 |
50 | local transform = t.Compose{
51 | t.Scale(256),
52 | t.ColorNormalize(meanstd),
53 | t.CenterCrop(224),
54 | }
55 |
56 | local N = 3
57 |
58 | for i=2,#arg do
59 | -- load the image as a RGB float tensor with values 0..1
60 | local img = image.load(arg[i], 3, 'float')
61 | local im = img:clone()
62 | local name = paths.basename(arg[i], 'JPEG')
63 |
64 | -- Scale, normalize, and crop the image
65 | img = transform(img)
66 |
67 | -- View as mini-batch of size 1
68 | local batch = img:view(1, table.unpack(img:size():totable()))
69 |
70 | -- Get the output of the softmax
71 | local output = model:forward(batch:cuda()):squeeze()
72 |
73 | -- Get the featuremap
74 | local featuremap = net:forward(batch:cuda()):squeeze()
75 |
76 | -- Get the top N class indexes and probabilities
77 | local probs, indexes = output:topk(N, true, true)
78 | print('Classes for', arg[i])
79 |
80 | for n=1,1 do
81 | print(probs[n], imagenetLabel[indexes[n]])
82 | map = image.scale(featuremap[indexes[n]]:float(), img:size(2),img:size(3))
83 | im = image.scale(im, img:size(2),img:size(3))
84 | map = (torch.div((map - torch.min(map)), (torch.max(map)-torch.min(map))):mul(255)+1):round()
85 | map = image.y2jet(map)
86 | map = img:mul(0.2)+map:mul(0.8)
87 | frame = torch.cat(im, map, 3)
88 | frame=image.drawText(frame, imagenetLabel[indexes[n]], 10, 10)
89 | image.save(string.format('images/%s.png', name), frame)
90 | end
91 | end
92 |
93 |
--------------------------------------------------------------------------------