├── README.md ├── matlab ├── change_input_blob.m ├── data │ ├── deploy_caffenet.prototxt │ ├── deploy_googlenet.prototxt │ ├── deploy_resnet.prototxt │ ├── deploy_vgg_16.prototxt │ ├── deploy_vgg_19.prototxt │ ├── deploy_vgg_f.prototxt │ ├── ilsvrc_2012_mean.mat │ ├── synset_words.txt │ └── test_img.png ├── demo_caffe.m ├── makeImagenetData.m ├── predict_caffe.m ├── predict_matconvnet.m ├── preprocess_img.m ├── readme.md ├── universal_perturbation.m └── vl_argparse.m ├── precomputed ├── CaffeNet.mat ├── GoogLeNet.mat ├── README.md ├── ResNet-152.mat ├── VGG-16.mat ├── VGG-19.mat └── VGG-F.mat └── python ├── README.md ├── data ├── labels.txt ├── test_img.png └── universal.npy ├── deepfool.py ├── demo_inception.py ├── prepare_imagenet_data.py └── universal_pert.py /README.md: -------------------------------------------------------------------------------- 1 | # Universal adversarial perturbations 2 | 3 | *matlab*: MATLAB code to generate universal perturbations, using [Caffe](https://github.com/BVLC/caffe) or [MatConvNet](https://github.com/vlfeat/matconvnet). 4 | 5 | *python*: Python code to generate universal perturbations using [TensorFlow](https://github.com/tensorflow/tensorflow). 6 | 7 | *precomputed*: Precomputed universal perturbations, for pre-trained models on ImageNet. 8 | 9 | ## Reference 10 | [1] S. Moosavi-Dezfooli\*, A. Fawzi\*, O. Fawzi, P. Frossard: 11 | [*Universal adversarial perturbations*](http://arxiv.org/pdf/1610.08401), CVPR 2017 12 | -------------------------------------------------------------------------------- /matlab/change_input_blob.m: -------------------------------------------------------------------------------- 1 | function change_input_blob(net,n) 2 | blob_shape = net.blobs('data').shape(); 3 | blob_shape(4) = n; 4 | net.blobs('data').reshape(blob_shape); 5 | 6 | net.reshape(); 7 | end 8 | -------------------------------------------------------------------------------- /matlab/data/deploy_caffenet.prototxt: -------------------------------------------------------------------------------- 1 | force_backward: true 2 | 3 | name: "CaffeNet" 4 | layer { 5 | name: "data" 6 | type: "Input" 7 | top: "data" 8 | input_param { shape: { dim: 1 dim: 3 dim: 224 dim: 224 } } 9 | } 10 | layer { 11 | name: "conv1" 12 | type: "Convolution" 13 | bottom: "data" 14 | top: "conv1" 15 | convolution_param { 16 | num_output: 96 17 | kernel_size: 11 18 | stride: 4 19 | } 20 | } 21 | layer { 22 | name: "relu1" 23 | type: "ReLU" 24 | bottom: "conv1" 25 | top: "conv1" 26 | } 27 | layer { 28 | name: "pool1" 29 | type: "Pooling" 30 | bottom: "conv1" 31 | top: "pool1" 32 | pooling_param { 33 | pool: MAX 34 | kernel_size: 3 35 | stride: 2 36 | } 37 | } 38 | layer { 39 | name: "norm1" 40 | type: "LRN" 41 | bottom: "pool1" 42 | top: "norm1" 43 | lrn_param { 44 | local_size: 5 45 | alpha: 0.0001 46 | beta: 0.75 47 | } 48 | } 49 | layer { 50 | name: "conv2" 51 | type: "Convolution" 52 | bottom: "norm1" 53 | top: "conv2" 54 | convolution_param { 55 | num_output: 256 56 | pad: 2 57 | kernel_size: 5 58 | group: 2 59 | } 60 | } 61 | layer { 62 | name: "relu2" 63 | type: "ReLU" 64 | bottom: "conv2" 65 | top: "conv2" 66 | } 67 | layer { 68 | name: "pool2" 69 | type: "Pooling" 70 | bottom: "conv2" 71 | top: "pool2" 72 | pooling_param { 73 | pool: MAX 74 | kernel_size: 3 75 | stride: 2 76 | } 77 | } 78 | layer { 79 | name: "norm2" 80 | type: "LRN" 81 | bottom: "pool2" 82 | top: "norm2" 83 | lrn_param { 84 | local_size: 5 85 | alpha: 0.0001 86 | beta: 0.75 87 | } 88 | } 89 | layer { 90 | name: "conv3" 91 | type: "Convolution" 92 | bottom: "norm2" 93 | top: "conv3" 94 | convolution_param { 95 | num_output: 384 96 | pad: 1 97 | kernel_size: 3 98 | } 99 | } 100 | layer { 101 | name: "relu3" 102 | type: "ReLU" 103 | bottom: "conv3" 104 | top: "conv3" 105 | } 106 | layer { 107 | name: "conv4" 108 | type: "Convolution" 109 | bottom: "conv3" 110 | top: "conv4" 111 | convolution_param { 112 | num_output: 384 113 | pad: 1 114 | kernel_size: 3 115 | group: 2 116 | } 117 | } 118 | layer { 119 | name: "relu4" 120 | type: "ReLU" 121 | bottom: "conv4" 122 | top: "conv4" 123 | } 124 | layer { 125 | name: "conv5" 126 | type: "Convolution" 127 | bottom: "conv4" 128 | top: "conv5" 129 | convolution_param { 130 | num_output: 256 131 | pad: 1 132 | kernel_size: 3 133 | group: 2 134 | } 135 | } 136 | layer { 137 | name: "relu5" 138 | type: "ReLU" 139 | bottom: "conv5" 140 | top: "conv5" 141 | } 142 | layer { 143 | name: "pool5" 144 | type: "Pooling" 145 | bottom: "conv5" 146 | top: "pool5" 147 | pooling_param { 148 | pool: MAX 149 | kernel_size: 3 150 | stride: 2 151 | } 152 | } 153 | layer { 154 | name: "fc6" 155 | type: "InnerProduct" 156 | bottom: "pool5" 157 | top: "fc6" 158 | inner_product_param { 159 | num_output: 4096 160 | } 161 | } 162 | layer { 163 | name: "relu6" 164 | type: "ReLU" 165 | bottom: "fc6" 166 | top: "fc6" 167 | } 168 | layer { 169 | name: "drop6" 170 | type: "Dropout" 171 | bottom: "fc6" 172 | top: "fc6" 173 | dropout_param { 174 | dropout_ratio: 0.5 175 | } 176 | } 177 | layer { 178 | name: "fc7" 179 | type: "InnerProduct" 180 | bottom: "fc6" 181 | top: "fc7" 182 | inner_product_param { 183 | num_output: 4096 184 | } 185 | } 186 | layer { 187 | name: "relu7" 188 | type: "ReLU" 189 | bottom: "fc7" 190 | top: "fc7" 191 | } 192 | layer { 193 | name: "drop7" 194 | type: "Dropout" 195 | bottom: "fc7" 196 | top: "fc7" 197 | dropout_param { 198 | dropout_ratio: 0.5 199 | } 200 | } 201 | layer { 202 | name: "fc8" 203 | type: "InnerProduct" 204 | bottom: "fc7" 205 | top: "fc8" 206 | inner_product_param { 207 | num_output: 1000 208 | } 209 | } 210 | 211 | #layer { 212 | # name: "prob" 213 | # type: "Softmax" 214 | # bottom: "fc8" 215 | # top: "prob" 216 | #} 217 | -------------------------------------------------------------------------------- /matlab/data/deploy_googlenet.prototxt: -------------------------------------------------------------------------------- 1 | force_backward: true 2 | name: "GoogleNet" 3 | layer { 4 | name: "data" 5 | type: "Input" 6 | top: "data" 7 | input_param { shape: { dim: 1 dim: 3 dim: 224 dim: 224 } } 8 | } 9 | layer { 10 | name: "conv1/7x7_s2" 11 | type: "Convolution" 12 | bottom: "data" 13 | top: "conv1/7x7_s2" 14 | param { 15 | lr_mult: 1 16 | decay_mult: 1 17 | } 18 | param { 19 | lr_mult: 2 20 | decay_mult: 0 21 | } 22 | convolution_param { 23 | num_output: 64 24 | pad: 3 25 | kernel_size: 7 26 | stride: 2 27 | weight_filler { 28 | type: "xavier" 29 | std: 0.1 30 | } 31 | bias_filler { 32 | type: "constant" 33 | value: 0.2 34 | } 35 | } 36 | } 37 | layer { 38 | name: "conv1/relu_7x7" 39 | type: "ReLU" 40 | bottom: "conv1/7x7_s2" 41 | top: "conv1/7x7_s2" 42 | } 43 | layer { 44 | name: "pool1/3x3_s2" 45 | type: "Pooling" 46 | bottom: "conv1/7x7_s2" 47 | top: "pool1/3x3_s2" 48 | pooling_param { 49 | pool: MAX 50 | kernel_size: 3 51 | stride: 2 52 | } 53 | } 54 | layer { 55 | name: "pool1/norm1" 56 | type: "LRN" 57 | bottom: "pool1/3x3_s2" 58 | top: "pool1/norm1" 59 | lrn_param { 60 | local_size: 5 61 | alpha: 0.0001 62 | beta: 0.75 63 | } 64 | } 65 | layer { 66 | name: "conv2/3x3_reduce" 67 | type: "Convolution" 68 | bottom: "pool1/norm1" 69 | top: "conv2/3x3_reduce" 70 | param { 71 | lr_mult: 1 72 | decay_mult: 1 73 | } 74 | param { 75 | lr_mult: 2 76 | decay_mult: 0 77 | } 78 | convolution_param { 79 | num_output: 64 80 | kernel_size: 1 81 | weight_filler { 82 | type: "xavier" 83 | std: 0.1 84 | } 85 | bias_filler { 86 | type: "constant" 87 | value: 0.2 88 | } 89 | } 90 | } 91 | layer { 92 | name: "conv2/relu_3x3_reduce" 93 | type: "ReLU" 94 | bottom: "conv2/3x3_reduce" 95 | top: "conv2/3x3_reduce" 96 | } 97 | layer { 98 | name: "conv2/3x3" 99 | type: "Convolution" 100 | bottom: "conv2/3x3_reduce" 101 | top: "conv2/3x3" 102 | param { 103 | lr_mult: 1 104 | decay_mult: 1 105 | } 106 | param { 107 | lr_mult: 2 108 | decay_mult: 0 109 | } 110 | convolution_param { 111 | num_output: 192 112 | pad: 1 113 | kernel_size: 3 114 | weight_filler { 115 | type: "xavier" 116 | std: 0.03 117 | } 118 | bias_filler { 119 | type: "constant" 120 | value: 0.2 121 | } 122 | } 123 | } 124 | layer { 125 | name: "conv2/relu_3x3" 126 | type: "ReLU" 127 | bottom: "conv2/3x3" 128 | top: "conv2/3x3" 129 | } 130 | layer { 131 | name: "conv2/norm2" 132 | type: "LRN" 133 | bottom: "conv2/3x3" 134 | top: "conv2/norm2" 135 | lrn_param { 136 | local_size: 5 137 | alpha: 0.0001 138 | beta: 0.75 139 | } 140 | } 141 | layer { 142 | name: "pool2/3x3_s2" 143 | type: "Pooling" 144 | bottom: "conv2/norm2" 145 | top: "pool2/3x3_s2" 146 | pooling_param { 147 | pool: MAX 148 | kernel_size: 3 149 | stride: 2 150 | } 151 | } 152 | layer { 153 | name: "inception_3a/1x1" 154 | type: "Convolution" 155 | bottom: "pool2/3x3_s2" 156 | top: "inception_3a/1x1" 157 | param { 158 | lr_mult: 1 159 | decay_mult: 1 160 | } 161 | param { 162 | lr_mult: 2 163 | decay_mult: 0 164 | } 165 | convolution_param { 166 | num_output: 64 167 | kernel_size: 1 168 | weight_filler { 169 | type: "xavier" 170 | std: 0.03 171 | } 172 | bias_filler { 173 | type: "constant" 174 | value: 0.2 175 | } 176 | } 177 | } 178 | layer { 179 | name: "inception_3a/relu_1x1" 180 | type: "ReLU" 181 | bottom: "inception_3a/1x1" 182 | top: "inception_3a/1x1" 183 | } 184 | layer { 185 | name: "inception_3a/3x3_reduce" 186 | type: "Convolution" 187 | bottom: "pool2/3x3_s2" 188 | top: "inception_3a/3x3_reduce" 189 | param { 190 | lr_mult: 1 191 | decay_mult: 1 192 | } 193 | param { 194 | lr_mult: 2 195 | decay_mult: 0 196 | } 197 | convolution_param { 198 | num_output: 96 199 | kernel_size: 1 200 | weight_filler { 201 | type: "xavier" 202 | std: 0.09 203 | } 204 | bias_filler { 205 | type: "constant" 206 | value: 0.2 207 | } 208 | } 209 | } 210 | layer { 211 | name: "inception_3a/relu_3x3_reduce" 212 | type: "ReLU" 213 | bottom: "inception_3a/3x3_reduce" 214 | top: "inception_3a/3x3_reduce" 215 | } 216 | layer { 217 | name: "inception_3a/3x3" 218 | type: "Convolution" 219 | bottom: "inception_3a/3x3_reduce" 220 | top: "inception_3a/3x3" 221 | param { 222 | lr_mult: 1 223 | decay_mult: 1 224 | } 225 | param { 226 | lr_mult: 2 227 | decay_mult: 0 228 | } 229 | convolution_param { 230 | num_output: 128 231 | pad: 1 232 | kernel_size: 3 233 | weight_filler { 234 | type: "xavier" 235 | std: 0.03 236 | } 237 | bias_filler { 238 | type: "constant" 239 | value: 0.2 240 | } 241 | } 242 | } 243 | layer { 244 | name: "inception_3a/relu_3x3" 245 | type: "ReLU" 246 | bottom: "inception_3a/3x3" 247 | top: "inception_3a/3x3" 248 | } 249 | layer { 250 | name: "inception_3a/5x5_reduce" 251 | type: "Convolution" 252 | bottom: "pool2/3x3_s2" 253 | top: "inception_3a/5x5_reduce" 254 | param { 255 | lr_mult: 1 256 | decay_mult: 1 257 | } 258 | param { 259 | lr_mult: 2 260 | decay_mult: 0 261 | } 262 | convolution_param { 263 | num_output: 16 264 | kernel_size: 1 265 | weight_filler { 266 | type: "xavier" 267 | std: 0.2 268 | } 269 | bias_filler { 270 | type: "constant" 271 | value: 0.2 272 | } 273 | } 274 | } 275 | layer { 276 | name: "inception_3a/relu_5x5_reduce" 277 | type: "ReLU" 278 | bottom: "inception_3a/5x5_reduce" 279 | top: "inception_3a/5x5_reduce" 280 | } 281 | layer { 282 | name: "inception_3a/5x5" 283 | type: "Convolution" 284 | bottom: "inception_3a/5x5_reduce" 285 | top: "inception_3a/5x5" 286 | param { 287 | lr_mult: 1 288 | decay_mult: 1 289 | } 290 | param { 291 | lr_mult: 2 292 | decay_mult: 0 293 | } 294 | convolution_param { 295 | num_output: 32 296 | pad: 2 297 | kernel_size: 5 298 | weight_filler { 299 | type: "xavier" 300 | std: 0.03 301 | } 302 | bias_filler { 303 | type: "constant" 304 | value: 0.2 305 | } 306 | } 307 | } 308 | layer { 309 | name: "inception_3a/relu_5x5" 310 | type: "ReLU" 311 | bottom: "inception_3a/5x5" 312 | top: "inception_3a/5x5" 313 | } 314 | layer { 315 | name: "inception_3a/pool" 316 | type: "Pooling" 317 | bottom: "pool2/3x3_s2" 318 | top: "inception_3a/pool" 319 | pooling_param { 320 | pool: MAX 321 | kernel_size: 3 322 | stride: 1 323 | pad: 1 324 | } 325 | } 326 | layer { 327 | name: "inception_3a/pool_proj" 328 | type: "Convolution" 329 | bottom: "inception_3a/pool" 330 | top: "inception_3a/pool_proj" 331 | param { 332 | lr_mult: 1 333 | decay_mult: 1 334 | } 335 | param { 336 | lr_mult: 2 337 | decay_mult: 0 338 | } 339 | convolution_param { 340 | num_output: 32 341 | kernel_size: 1 342 | weight_filler { 343 | type: "xavier" 344 | std: 0.1 345 | } 346 | bias_filler { 347 | type: "constant" 348 | value: 0.2 349 | } 350 | } 351 | } 352 | layer { 353 | name: "inception_3a/relu_pool_proj" 354 | type: "ReLU" 355 | bottom: "inception_3a/pool_proj" 356 | top: "inception_3a/pool_proj" 357 | } 358 | layer { 359 | name: "inception_3a/output" 360 | type: "Concat" 361 | bottom: "inception_3a/1x1" 362 | bottom: "inception_3a/3x3" 363 | bottom: "inception_3a/5x5" 364 | bottom: "inception_3a/pool_proj" 365 | top: "inception_3a/output" 366 | } 367 | layer { 368 | name: "inception_3b/1x1" 369 | type: "Convolution" 370 | bottom: "inception_3a/output" 371 | top: "inception_3b/1x1" 372 | param { 373 | lr_mult: 1 374 | decay_mult: 1 375 | } 376 | param { 377 | lr_mult: 2 378 | decay_mult: 0 379 | } 380 | convolution_param { 381 | num_output: 128 382 | kernel_size: 1 383 | weight_filler { 384 | type: "xavier" 385 | std: 0.03 386 | } 387 | bias_filler { 388 | type: "constant" 389 | value: 0.2 390 | } 391 | } 392 | } 393 | layer { 394 | name: "inception_3b/relu_1x1" 395 | type: "ReLU" 396 | bottom: "inception_3b/1x1" 397 | top: "inception_3b/1x1" 398 | } 399 | layer { 400 | name: "inception_3b/3x3_reduce" 401 | type: "Convolution" 402 | bottom: "inception_3a/output" 403 | top: "inception_3b/3x3_reduce" 404 | param { 405 | lr_mult: 1 406 | decay_mult: 1 407 | } 408 | param { 409 | lr_mult: 2 410 | decay_mult: 0 411 | } 412 | convolution_param { 413 | num_output: 128 414 | kernel_size: 1 415 | weight_filler { 416 | type: "xavier" 417 | std: 0.09 418 | } 419 | bias_filler { 420 | type: "constant" 421 | value: 0.2 422 | } 423 | } 424 | } 425 | layer { 426 | name: "inception_3b/relu_3x3_reduce" 427 | type: "ReLU" 428 | bottom: "inception_3b/3x3_reduce" 429 | top: "inception_3b/3x3_reduce" 430 | } 431 | layer { 432 | name: "inception_3b/3x3" 433 | type: "Convolution" 434 | bottom: "inception_3b/3x3_reduce" 435 | top: "inception_3b/3x3" 436 | param { 437 | lr_mult: 1 438 | decay_mult: 1 439 | } 440 | param { 441 | lr_mult: 2 442 | decay_mult: 0 443 | } 444 | convolution_param { 445 | num_output: 192 446 | pad: 1 447 | kernel_size: 3 448 | weight_filler { 449 | type: "xavier" 450 | std: 0.03 451 | } 452 | bias_filler { 453 | type: "constant" 454 | value: 0.2 455 | } 456 | } 457 | } 458 | layer { 459 | name: "inception_3b/relu_3x3" 460 | type: "ReLU" 461 | bottom: "inception_3b/3x3" 462 | top: "inception_3b/3x3" 463 | } 464 | layer { 465 | name: "inception_3b/5x5_reduce" 466 | type: "Convolution" 467 | bottom: "inception_3a/output" 468 | top: "inception_3b/5x5_reduce" 469 | param { 470 | lr_mult: 1 471 | decay_mult: 1 472 | } 473 | param { 474 | lr_mult: 2 475 | decay_mult: 0 476 | } 477 | convolution_param { 478 | num_output: 32 479 | kernel_size: 1 480 | weight_filler { 481 | type: "xavier" 482 | std: 0.2 483 | } 484 | bias_filler { 485 | type: "constant" 486 | value: 0.2 487 | } 488 | } 489 | } 490 | layer { 491 | name: "inception_3b/relu_5x5_reduce" 492 | type: "ReLU" 493 | bottom: "inception_3b/5x5_reduce" 494 | top: "inception_3b/5x5_reduce" 495 | } 496 | layer { 497 | name: "inception_3b/5x5" 498 | type: "Convolution" 499 | bottom: "inception_3b/5x5_reduce" 500 | top: "inception_3b/5x5" 501 | param { 502 | lr_mult: 1 503 | decay_mult: 1 504 | } 505 | param { 506 | lr_mult: 2 507 | decay_mult: 0 508 | } 509 | convolution_param { 510 | num_output: 96 511 | pad: 2 512 | kernel_size: 5 513 | weight_filler { 514 | type: "xavier" 515 | std: 0.03 516 | } 517 | bias_filler { 518 | type: "constant" 519 | value: 0.2 520 | } 521 | } 522 | } 523 | layer { 524 | name: "inception_3b/relu_5x5" 525 | type: "ReLU" 526 | bottom: "inception_3b/5x5" 527 | top: "inception_3b/5x5" 528 | } 529 | layer { 530 | name: "inception_3b/pool" 531 | type: "Pooling" 532 | bottom: "inception_3a/output" 533 | top: "inception_3b/pool" 534 | pooling_param { 535 | pool: MAX 536 | kernel_size: 3 537 | stride: 1 538 | pad: 1 539 | } 540 | } 541 | layer { 542 | name: "inception_3b/pool_proj" 543 | type: "Convolution" 544 | bottom: "inception_3b/pool" 545 | top: "inception_3b/pool_proj" 546 | param { 547 | lr_mult: 1 548 | decay_mult: 1 549 | } 550 | param { 551 | lr_mult: 2 552 | decay_mult: 0 553 | } 554 | convolution_param { 555 | num_output: 64 556 | kernel_size: 1 557 | weight_filler { 558 | type: "xavier" 559 | std: 0.1 560 | } 561 | bias_filler { 562 | type: "constant" 563 | value: 0.2 564 | } 565 | } 566 | } 567 | layer { 568 | name: "inception_3b/relu_pool_proj" 569 | type: "ReLU" 570 | bottom: "inception_3b/pool_proj" 571 | top: "inception_3b/pool_proj" 572 | } 573 | layer { 574 | name: "inception_3b/output" 575 | type: "Concat" 576 | bottom: "inception_3b/1x1" 577 | bottom: "inception_3b/3x3" 578 | bottom: "inception_3b/5x5" 579 | bottom: "inception_3b/pool_proj" 580 | top: "inception_3b/output" 581 | } 582 | layer { 583 | name: "pool3/3x3_s2" 584 | type: "Pooling" 585 | bottom: "inception_3b/output" 586 | top: "pool3/3x3_s2" 587 | pooling_param { 588 | pool: MAX 589 | kernel_size: 3 590 | stride: 2 591 | } 592 | } 593 | layer { 594 | name: "inception_4a/1x1" 595 | type: "Convolution" 596 | bottom: "pool3/3x3_s2" 597 | top: "inception_4a/1x1" 598 | param { 599 | lr_mult: 1 600 | decay_mult: 1 601 | } 602 | param { 603 | lr_mult: 2 604 | decay_mult: 0 605 | } 606 | convolution_param { 607 | num_output: 192 608 | kernel_size: 1 609 | weight_filler { 610 | type: "xavier" 611 | std: 0.03 612 | } 613 | bias_filler { 614 | type: "constant" 615 | value: 0.2 616 | } 617 | } 618 | } 619 | layer { 620 | name: "inception_4a/relu_1x1" 621 | type: "ReLU" 622 | bottom: "inception_4a/1x1" 623 | top: "inception_4a/1x1" 624 | } 625 | layer { 626 | name: "inception_4a/3x3_reduce" 627 | type: "Convolution" 628 | bottom: "pool3/3x3_s2" 629 | top: "inception_4a/3x3_reduce" 630 | param { 631 | lr_mult: 1 632 | decay_mult: 1 633 | } 634 | param { 635 | lr_mult: 2 636 | decay_mult: 0 637 | } 638 | convolution_param { 639 | num_output: 96 640 | kernel_size: 1 641 | weight_filler { 642 | type: "xavier" 643 | std: 0.09 644 | } 645 | bias_filler { 646 | type: "constant" 647 | value: 0.2 648 | } 649 | } 650 | } 651 | layer { 652 | name: "inception_4a/relu_3x3_reduce" 653 | type: "ReLU" 654 | bottom: "inception_4a/3x3_reduce" 655 | top: "inception_4a/3x3_reduce" 656 | } 657 | layer { 658 | name: "inception_4a/3x3" 659 | type: "Convolution" 660 | bottom: "inception_4a/3x3_reduce" 661 | top: "inception_4a/3x3" 662 | param { 663 | lr_mult: 1 664 | decay_mult: 1 665 | } 666 | param { 667 | lr_mult: 2 668 | decay_mult: 0 669 | } 670 | convolution_param { 671 | num_output: 208 672 | pad: 1 673 | kernel_size: 3 674 | weight_filler { 675 | type: "xavier" 676 | std: 0.03 677 | } 678 | bias_filler { 679 | type: "constant" 680 | value: 0.2 681 | } 682 | } 683 | } 684 | layer { 685 | name: "inception_4a/relu_3x3" 686 | type: "ReLU" 687 | bottom: "inception_4a/3x3" 688 | top: "inception_4a/3x3" 689 | } 690 | layer { 691 | name: "inception_4a/5x5_reduce" 692 | type: "Convolution" 693 | bottom: "pool3/3x3_s2" 694 | top: "inception_4a/5x5_reduce" 695 | param { 696 | lr_mult: 1 697 | decay_mult: 1 698 | } 699 | param { 700 | lr_mult: 2 701 | decay_mult: 0 702 | } 703 | convolution_param { 704 | num_output: 16 705 | kernel_size: 1 706 | weight_filler { 707 | type: "xavier" 708 | std: 0.2 709 | } 710 | bias_filler { 711 | type: "constant" 712 | value: 0.2 713 | } 714 | } 715 | } 716 | layer { 717 | name: "inception_4a/relu_5x5_reduce" 718 | type: "ReLU" 719 | bottom: "inception_4a/5x5_reduce" 720 | top: "inception_4a/5x5_reduce" 721 | } 722 | layer { 723 | name: "inception_4a/5x5" 724 | type: "Convolution" 725 | bottom: "inception_4a/5x5_reduce" 726 | top: "inception_4a/5x5" 727 | param { 728 | lr_mult: 1 729 | decay_mult: 1 730 | } 731 | param { 732 | lr_mult: 2 733 | decay_mult: 0 734 | } 735 | convolution_param { 736 | num_output: 48 737 | pad: 2 738 | kernel_size: 5 739 | weight_filler { 740 | type: "xavier" 741 | std: 0.03 742 | } 743 | bias_filler { 744 | type: "constant" 745 | value: 0.2 746 | } 747 | } 748 | } 749 | layer { 750 | name: "inception_4a/relu_5x5" 751 | type: "ReLU" 752 | bottom: "inception_4a/5x5" 753 | top: "inception_4a/5x5" 754 | } 755 | layer { 756 | name: "inception_4a/pool" 757 | type: "Pooling" 758 | bottom: "pool3/3x3_s2" 759 | top: "inception_4a/pool" 760 | pooling_param { 761 | pool: MAX 762 | kernel_size: 3 763 | stride: 1 764 | pad: 1 765 | } 766 | } 767 | layer { 768 | name: "inception_4a/pool_proj" 769 | type: "Convolution" 770 | bottom: "inception_4a/pool" 771 | top: "inception_4a/pool_proj" 772 | param { 773 | lr_mult: 1 774 | decay_mult: 1 775 | } 776 | param { 777 | lr_mult: 2 778 | decay_mult: 0 779 | } 780 | convolution_param { 781 | num_output: 64 782 | kernel_size: 1 783 | weight_filler { 784 | type: "xavier" 785 | std: 0.1 786 | } 787 | bias_filler { 788 | type: "constant" 789 | value: 0.2 790 | } 791 | } 792 | } 793 | layer { 794 | name: "inception_4a/relu_pool_proj" 795 | type: "ReLU" 796 | bottom: "inception_4a/pool_proj" 797 | top: "inception_4a/pool_proj" 798 | } 799 | layer { 800 | name: "inception_4a/output" 801 | type: "Concat" 802 | bottom: "inception_4a/1x1" 803 | bottom: "inception_4a/3x3" 804 | bottom: "inception_4a/5x5" 805 | bottom: "inception_4a/pool_proj" 806 | top: "inception_4a/output" 807 | } 808 | layer { 809 | name: "inception_4b/1x1" 810 | type: "Convolution" 811 | bottom: "inception_4a/output" 812 | top: "inception_4b/1x1" 813 | param { 814 | lr_mult: 1 815 | decay_mult: 1 816 | } 817 | param { 818 | lr_mult: 2 819 | decay_mult: 0 820 | } 821 | convolution_param { 822 | num_output: 160 823 | kernel_size: 1 824 | weight_filler { 825 | type: "xavier" 826 | std: 0.03 827 | } 828 | bias_filler { 829 | type: "constant" 830 | value: 0.2 831 | } 832 | } 833 | } 834 | layer { 835 | name: "inception_4b/relu_1x1" 836 | type: "ReLU" 837 | bottom: "inception_4b/1x1" 838 | top: "inception_4b/1x1" 839 | } 840 | layer { 841 | name: "inception_4b/3x3_reduce" 842 | type: "Convolution" 843 | bottom: "inception_4a/output" 844 | top: "inception_4b/3x3_reduce" 845 | param { 846 | lr_mult: 1 847 | decay_mult: 1 848 | } 849 | param { 850 | lr_mult: 2 851 | decay_mult: 0 852 | } 853 | convolution_param { 854 | num_output: 112 855 | kernel_size: 1 856 | weight_filler { 857 | type: "xavier" 858 | std: 0.09 859 | } 860 | bias_filler { 861 | type: "constant" 862 | value: 0.2 863 | } 864 | } 865 | } 866 | layer { 867 | name: "inception_4b/relu_3x3_reduce" 868 | type: "ReLU" 869 | bottom: "inception_4b/3x3_reduce" 870 | top: "inception_4b/3x3_reduce" 871 | } 872 | layer { 873 | name: "inception_4b/3x3" 874 | type: "Convolution" 875 | bottom: "inception_4b/3x3_reduce" 876 | top: "inception_4b/3x3" 877 | param { 878 | lr_mult: 1 879 | decay_mult: 1 880 | } 881 | param { 882 | lr_mult: 2 883 | decay_mult: 0 884 | } 885 | convolution_param { 886 | num_output: 224 887 | pad: 1 888 | kernel_size: 3 889 | weight_filler { 890 | type: "xavier" 891 | std: 0.03 892 | } 893 | bias_filler { 894 | type: "constant" 895 | value: 0.2 896 | } 897 | } 898 | } 899 | layer { 900 | name: "inception_4b/relu_3x3" 901 | type: "ReLU" 902 | bottom: "inception_4b/3x3" 903 | top: "inception_4b/3x3" 904 | } 905 | layer { 906 | name: "inception_4b/5x5_reduce" 907 | type: "Convolution" 908 | bottom: "inception_4a/output" 909 | top: "inception_4b/5x5_reduce" 910 | param { 911 | lr_mult: 1 912 | decay_mult: 1 913 | } 914 | param { 915 | lr_mult: 2 916 | decay_mult: 0 917 | } 918 | convolution_param { 919 | num_output: 24 920 | kernel_size: 1 921 | weight_filler { 922 | type: "xavier" 923 | std: 0.2 924 | } 925 | bias_filler { 926 | type: "constant" 927 | value: 0.2 928 | } 929 | } 930 | } 931 | layer { 932 | name: "inception_4b/relu_5x5_reduce" 933 | type: "ReLU" 934 | bottom: "inception_4b/5x5_reduce" 935 | top: "inception_4b/5x5_reduce" 936 | } 937 | layer { 938 | name: "inception_4b/5x5" 939 | type: "Convolution" 940 | bottom: "inception_4b/5x5_reduce" 941 | top: "inception_4b/5x5" 942 | param { 943 | lr_mult: 1 944 | decay_mult: 1 945 | } 946 | param { 947 | lr_mult: 2 948 | decay_mult: 0 949 | } 950 | convolution_param { 951 | num_output: 64 952 | pad: 2 953 | kernel_size: 5 954 | weight_filler { 955 | type: "xavier" 956 | std: 0.03 957 | } 958 | bias_filler { 959 | type: "constant" 960 | value: 0.2 961 | } 962 | } 963 | } 964 | layer { 965 | name: "inception_4b/relu_5x5" 966 | type: "ReLU" 967 | bottom: "inception_4b/5x5" 968 | top: "inception_4b/5x5" 969 | } 970 | layer { 971 | name: "inception_4b/pool" 972 | type: "Pooling" 973 | bottom: "inception_4a/output" 974 | top: "inception_4b/pool" 975 | pooling_param { 976 | pool: MAX 977 | kernel_size: 3 978 | stride: 1 979 | pad: 1 980 | } 981 | } 982 | layer { 983 | name: "inception_4b/pool_proj" 984 | type: "Convolution" 985 | bottom: "inception_4b/pool" 986 | top: "inception_4b/pool_proj" 987 | param { 988 | lr_mult: 1 989 | decay_mult: 1 990 | } 991 | param { 992 | lr_mult: 2 993 | decay_mult: 0 994 | } 995 | convolution_param { 996 | num_output: 64 997 | kernel_size: 1 998 | weight_filler { 999 | type: "xavier" 1000 | std: 0.1 1001 | } 1002 | bias_filler { 1003 | type: "constant" 1004 | value: 0.2 1005 | } 1006 | } 1007 | } 1008 | layer { 1009 | name: "inception_4b/relu_pool_proj" 1010 | type: "ReLU" 1011 | bottom: "inception_4b/pool_proj" 1012 | top: "inception_4b/pool_proj" 1013 | } 1014 | layer { 1015 | name: "inception_4b/output" 1016 | type: "Concat" 1017 | bottom: "inception_4b/1x1" 1018 | bottom: "inception_4b/3x3" 1019 | bottom: "inception_4b/5x5" 1020 | bottom: "inception_4b/pool_proj" 1021 | top: "inception_4b/output" 1022 | } 1023 | layer { 1024 | name: "inception_4c/1x1" 1025 | type: "Convolution" 1026 | bottom: "inception_4b/output" 1027 | top: "inception_4c/1x1" 1028 | param { 1029 | lr_mult: 1 1030 | decay_mult: 1 1031 | } 1032 | param { 1033 | lr_mult: 2 1034 | decay_mult: 0 1035 | } 1036 | convolution_param { 1037 | num_output: 128 1038 | kernel_size: 1 1039 | weight_filler { 1040 | type: "xavier" 1041 | std: 0.03 1042 | } 1043 | bias_filler { 1044 | type: "constant" 1045 | value: 0.2 1046 | } 1047 | } 1048 | } 1049 | layer { 1050 | name: "inception_4c/relu_1x1" 1051 | type: "ReLU" 1052 | bottom: "inception_4c/1x1" 1053 | top: "inception_4c/1x1" 1054 | } 1055 | layer { 1056 | name: "inception_4c/3x3_reduce" 1057 | type: "Convolution" 1058 | bottom: "inception_4b/output" 1059 | top: "inception_4c/3x3_reduce" 1060 | param { 1061 | lr_mult: 1 1062 | decay_mult: 1 1063 | } 1064 | param { 1065 | lr_mult: 2 1066 | decay_mult: 0 1067 | } 1068 | convolution_param { 1069 | num_output: 128 1070 | kernel_size: 1 1071 | weight_filler { 1072 | type: "xavier" 1073 | std: 0.09 1074 | } 1075 | bias_filler { 1076 | type: "constant" 1077 | value: 0.2 1078 | } 1079 | } 1080 | } 1081 | layer { 1082 | name: "inception_4c/relu_3x3_reduce" 1083 | type: "ReLU" 1084 | bottom: "inception_4c/3x3_reduce" 1085 | top: "inception_4c/3x3_reduce" 1086 | } 1087 | layer { 1088 | name: "inception_4c/3x3" 1089 | type: "Convolution" 1090 | bottom: "inception_4c/3x3_reduce" 1091 | top: "inception_4c/3x3" 1092 | param { 1093 | lr_mult: 1 1094 | decay_mult: 1 1095 | } 1096 | param { 1097 | lr_mult: 2 1098 | decay_mult: 0 1099 | } 1100 | convolution_param { 1101 | num_output: 256 1102 | pad: 1 1103 | kernel_size: 3 1104 | weight_filler { 1105 | type: "xavier" 1106 | std: 0.03 1107 | } 1108 | bias_filler { 1109 | type: "constant" 1110 | value: 0.2 1111 | } 1112 | } 1113 | } 1114 | layer { 1115 | name: "inception_4c/relu_3x3" 1116 | type: "ReLU" 1117 | bottom: "inception_4c/3x3" 1118 | top: "inception_4c/3x3" 1119 | } 1120 | layer { 1121 | name: "inception_4c/5x5_reduce" 1122 | type: "Convolution" 1123 | bottom: "inception_4b/output" 1124 | top: "inception_4c/5x5_reduce" 1125 | param { 1126 | lr_mult: 1 1127 | decay_mult: 1 1128 | } 1129 | param { 1130 | lr_mult: 2 1131 | decay_mult: 0 1132 | } 1133 | convolution_param { 1134 | num_output: 24 1135 | kernel_size: 1 1136 | weight_filler { 1137 | type: "xavier" 1138 | std: 0.2 1139 | } 1140 | bias_filler { 1141 | type: "constant" 1142 | value: 0.2 1143 | } 1144 | } 1145 | } 1146 | layer { 1147 | name: "inception_4c/relu_5x5_reduce" 1148 | type: "ReLU" 1149 | bottom: "inception_4c/5x5_reduce" 1150 | top: "inception_4c/5x5_reduce" 1151 | } 1152 | layer { 1153 | name: "inception_4c/5x5" 1154 | type: "Convolution" 1155 | bottom: "inception_4c/5x5_reduce" 1156 | top: "inception_4c/5x5" 1157 | param { 1158 | lr_mult: 1 1159 | decay_mult: 1 1160 | } 1161 | param { 1162 | lr_mult: 2 1163 | decay_mult: 0 1164 | } 1165 | convolution_param { 1166 | num_output: 64 1167 | pad: 2 1168 | kernel_size: 5 1169 | weight_filler { 1170 | type: "xavier" 1171 | std: 0.03 1172 | } 1173 | bias_filler { 1174 | type: "constant" 1175 | value: 0.2 1176 | } 1177 | } 1178 | } 1179 | layer { 1180 | name: "inception_4c/relu_5x5" 1181 | type: "ReLU" 1182 | bottom: "inception_4c/5x5" 1183 | top: "inception_4c/5x5" 1184 | } 1185 | layer { 1186 | name: "inception_4c/pool" 1187 | type: "Pooling" 1188 | bottom: "inception_4b/output" 1189 | top: "inception_4c/pool" 1190 | pooling_param { 1191 | pool: MAX 1192 | kernel_size: 3 1193 | stride: 1 1194 | pad: 1 1195 | } 1196 | } 1197 | layer { 1198 | name: "inception_4c/pool_proj" 1199 | type: "Convolution" 1200 | bottom: "inception_4c/pool" 1201 | top: "inception_4c/pool_proj" 1202 | param { 1203 | lr_mult: 1 1204 | decay_mult: 1 1205 | } 1206 | param { 1207 | lr_mult: 2 1208 | decay_mult: 0 1209 | } 1210 | convolution_param { 1211 | num_output: 64 1212 | kernel_size: 1 1213 | weight_filler { 1214 | type: "xavier" 1215 | std: 0.1 1216 | } 1217 | bias_filler { 1218 | type: "constant" 1219 | value: 0.2 1220 | } 1221 | } 1222 | } 1223 | layer { 1224 | name: "inception_4c/relu_pool_proj" 1225 | type: "ReLU" 1226 | bottom: "inception_4c/pool_proj" 1227 | top: "inception_4c/pool_proj" 1228 | } 1229 | layer { 1230 | name: "inception_4c/output" 1231 | type: "Concat" 1232 | bottom: "inception_4c/1x1" 1233 | bottom: "inception_4c/3x3" 1234 | bottom: "inception_4c/5x5" 1235 | bottom: "inception_4c/pool_proj" 1236 | top: "inception_4c/output" 1237 | } 1238 | layer { 1239 | name: "inception_4d/1x1" 1240 | type: "Convolution" 1241 | bottom: "inception_4c/output" 1242 | top: "inception_4d/1x1" 1243 | param { 1244 | lr_mult: 1 1245 | decay_mult: 1 1246 | } 1247 | param { 1248 | lr_mult: 2 1249 | decay_mult: 0 1250 | } 1251 | convolution_param { 1252 | num_output: 112 1253 | kernel_size: 1 1254 | weight_filler { 1255 | type: "xavier" 1256 | std: 0.03 1257 | } 1258 | bias_filler { 1259 | type: "constant" 1260 | value: 0.2 1261 | } 1262 | } 1263 | } 1264 | layer { 1265 | name: "inception_4d/relu_1x1" 1266 | type: "ReLU" 1267 | bottom: "inception_4d/1x1" 1268 | top: "inception_4d/1x1" 1269 | } 1270 | layer { 1271 | name: "inception_4d/3x3_reduce" 1272 | type: "Convolution" 1273 | bottom: "inception_4c/output" 1274 | top: "inception_4d/3x3_reduce" 1275 | param { 1276 | lr_mult: 1 1277 | decay_mult: 1 1278 | } 1279 | param { 1280 | lr_mult: 2 1281 | decay_mult: 0 1282 | } 1283 | convolution_param { 1284 | num_output: 144 1285 | kernel_size: 1 1286 | weight_filler { 1287 | type: "xavier" 1288 | std: 0.09 1289 | } 1290 | bias_filler { 1291 | type: "constant" 1292 | value: 0.2 1293 | } 1294 | } 1295 | } 1296 | layer { 1297 | name: "inception_4d/relu_3x3_reduce" 1298 | type: "ReLU" 1299 | bottom: "inception_4d/3x3_reduce" 1300 | top: "inception_4d/3x3_reduce" 1301 | } 1302 | layer { 1303 | name: "inception_4d/3x3" 1304 | type: "Convolution" 1305 | bottom: "inception_4d/3x3_reduce" 1306 | top: "inception_4d/3x3" 1307 | param { 1308 | lr_mult: 1 1309 | decay_mult: 1 1310 | } 1311 | param { 1312 | lr_mult: 2 1313 | decay_mult: 0 1314 | } 1315 | convolution_param { 1316 | num_output: 288 1317 | pad: 1 1318 | kernel_size: 3 1319 | weight_filler { 1320 | type: "xavier" 1321 | std: 0.03 1322 | } 1323 | bias_filler { 1324 | type: "constant" 1325 | value: 0.2 1326 | } 1327 | } 1328 | } 1329 | layer { 1330 | name: "inception_4d/relu_3x3" 1331 | type: "ReLU" 1332 | bottom: "inception_4d/3x3" 1333 | top: "inception_4d/3x3" 1334 | } 1335 | layer { 1336 | name: "inception_4d/5x5_reduce" 1337 | type: "Convolution" 1338 | bottom: "inception_4c/output" 1339 | top: "inception_4d/5x5_reduce" 1340 | param { 1341 | lr_mult: 1 1342 | decay_mult: 1 1343 | } 1344 | param { 1345 | lr_mult: 2 1346 | decay_mult: 0 1347 | } 1348 | convolution_param { 1349 | num_output: 32 1350 | kernel_size: 1 1351 | weight_filler { 1352 | type: "xavier" 1353 | std: 0.2 1354 | } 1355 | bias_filler { 1356 | type: "constant" 1357 | value: 0.2 1358 | } 1359 | } 1360 | } 1361 | layer { 1362 | name: "inception_4d/relu_5x5_reduce" 1363 | type: "ReLU" 1364 | bottom: "inception_4d/5x5_reduce" 1365 | top: "inception_4d/5x5_reduce" 1366 | } 1367 | layer { 1368 | name: "inception_4d/5x5" 1369 | type: "Convolution" 1370 | bottom: "inception_4d/5x5_reduce" 1371 | top: "inception_4d/5x5" 1372 | param { 1373 | lr_mult: 1 1374 | decay_mult: 1 1375 | } 1376 | param { 1377 | lr_mult: 2 1378 | decay_mult: 0 1379 | } 1380 | convolution_param { 1381 | num_output: 64 1382 | pad: 2 1383 | kernel_size: 5 1384 | weight_filler { 1385 | type: "xavier" 1386 | std: 0.03 1387 | } 1388 | bias_filler { 1389 | type: "constant" 1390 | value: 0.2 1391 | } 1392 | } 1393 | } 1394 | layer { 1395 | name: "inception_4d/relu_5x5" 1396 | type: "ReLU" 1397 | bottom: "inception_4d/5x5" 1398 | top: "inception_4d/5x5" 1399 | } 1400 | layer { 1401 | name: "inception_4d/pool" 1402 | type: "Pooling" 1403 | bottom: "inception_4c/output" 1404 | top: "inception_4d/pool" 1405 | pooling_param { 1406 | pool: MAX 1407 | kernel_size: 3 1408 | stride: 1 1409 | pad: 1 1410 | } 1411 | } 1412 | layer { 1413 | name: "inception_4d/pool_proj" 1414 | type: "Convolution" 1415 | bottom: "inception_4d/pool" 1416 | top: "inception_4d/pool_proj" 1417 | param { 1418 | lr_mult: 1 1419 | decay_mult: 1 1420 | } 1421 | param { 1422 | lr_mult: 2 1423 | decay_mult: 0 1424 | } 1425 | convolution_param { 1426 | num_output: 64 1427 | kernel_size: 1 1428 | weight_filler { 1429 | type: "xavier" 1430 | std: 0.1 1431 | } 1432 | bias_filler { 1433 | type: "constant" 1434 | value: 0.2 1435 | } 1436 | } 1437 | } 1438 | layer { 1439 | name: "inception_4d/relu_pool_proj" 1440 | type: "ReLU" 1441 | bottom: "inception_4d/pool_proj" 1442 | top: "inception_4d/pool_proj" 1443 | } 1444 | layer { 1445 | name: "inception_4d/output" 1446 | type: "Concat" 1447 | bottom: "inception_4d/1x1" 1448 | bottom: "inception_4d/3x3" 1449 | bottom: "inception_4d/5x5" 1450 | bottom: "inception_4d/pool_proj" 1451 | top: "inception_4d/output" 1452 | } 1453 | layer { 1454 | name: "inception_4e/1x1" 1455 | type: "Convolution" 1456 | bottom: "inception_4d/output" 1457 | top: "inception_4e/1x1" 1458 | param { 1459 | lr_mult: 1 1460 | decay_mult: 1 1461 | } 1462 | param { 1463 | lr_mult: 2 1464 | decay_mult: 0 1465 | } 1466 | convolution_param { 1467 | num_output: 256 1468 | kernel_size: 1 1469 | weight_filler { 1470 | type: "xavier" 1471 | std: 0.03 1472 | } 1473 | bias_filler { 1474 | type: "constant" 1475 | value: 0.2 1476 | } 1477 | } 1478 | } 1479 | layer { 1480 | name: "inception_4e/relu_1x1" 1481 | type: "ReLU" 1482 | bottom: "inception_4e/1x1" 1483 | top: "inception_4e/1x1" 1484 | } 1485 | layer { 1486 | name: "inception_4e/3x3_reduce" 1487 | type: "Convolution" 1488 | bottom: "inception_4d/output" 1489 | top: "inception_4e/3x3_reduce" 1490 | param { 1491 | lr_mult: 1 1492 | decay_mult: 1 1493 | } 1494 | param { 1495 | lr_mult: 2 1496 | decay_mult: 0 1497 | } 1498 | convolution_param { 1499 | num_output: 160 1500 | kernel_size: 1 1501 | weight_filler { 1502 | type: "xavier" 1503 | std: 0.09 1504 | } 1505 | bias_filler { 1506 | type: "constant" 1507 | value: 0.2 1508 | } 1509 | } 1510 | } 1511 | layer { 1512 | name: "inception_4e/relu_3x3_reduce" 1513 | type: "ReLU" 1514 | bottom: "inception_4e/3x3_reduce" 1515 | top: "inception_4e/3x3_reduce" 1516 | } 1517 | layer { 1518 | name: "inception_4e/3x3" 1519 | type: "Convolution" 1520 | bottom: "inception_4e/3x3_reduce" 1521 | top: "inception_4e/3x3" 1522 | param { 1523 | lr_mult: 1 1524 | decay_mult: 1 1525 | } 1526 | param { 1527 | lr_mult: 2 1528 | decay_mult: 0 1529 | } 1530 | convolution_param { 1531 | num_output: 320 1532 | pad: 1 1533 | kernel_size: 3 1534 | weight_filler { 1535 | type: "xavier" 1536 | std: 0.03 1537 | } 1538 | bias_filler { 1539 | type: "constant" 1540 | value: 0.2 1541 | } 1542 | } 1543 | } 1544 | layer { 1545 | name: "inception_4e/relu_3x3" 1546 | type: "ReLU" 1547 | bottom: "inception_4e/3x3" 1548 | top: "inception_4e/3x3" 1549 | } 1550 | layer { 1551 | name: "inception_4e/5x5_reduce" 1552 | type: "Convolution" 1553 | bottom: "inception_4d/output" 1554 | top: "inception_4e/5x5_reduce" 1555 | param { 1556 | lr_mult: 1 1557 | decay_mult: 1 1558 | } 1559 | param { 1560 | lr_mult: 2 1561 | decay_mult: 0 1562 | } 1563 | convolution_param { 1564 | num_output: 32 1565 | kernel_size: 1 1566 | weight_filler { 1567 | type: "xavier" 1568 | std: 0.2 1569 | } 1570 | bias_filler { 1571 | type: "constant" 1572 | value: 0.2 1573 | } 1574 | } 1575 | } 1576 | layer { 1577 | name: "inception_4e/relu_5x5_reduce" 1578 | type: "ReLU" 1579 | bottom: "inception_4e/5x5_reduce" 1580 | top: "inception_4e/5x5_reduce" 1581 | } 1582 | layer { 1583 | name: "inception_4e/5x5" 1584 | type: "Convolution" 1585 | bottom: "inception_4e/5x5_reduce" 1586 | top: "inception_4e/5x5" 1587 | param { 1588 | lr_mult: 1 1589 | decay_mult: 1 1590 | } 1591 | param { 1592 | lr_mult: 2 1593 | decay_mult: 0 1594 | } 1595 | convolution_param { 1596 | num_output: 128 1597 | pad: 2 1598 | kernel_size: 5 1599 | weight_filler { 1600 | type: "xavier" 1601 | std: 0.03 1602 | } 1603 | bias_filler { 1604 | type: "constant" 1605 | value: 0.2 1606 | } 1607 | } 1608 | } 1609 | layer { 1610 | name: "inception_4e/relu_5x5" 1611 | type: "ReLU" 1612 | bottom: "inception_4e/5x5" 1613 | top: "inception_4e/5x5" 1614 | } 1615 | layer { 1616 | name: "inception_4e/pool" 1617 | type: "Pooling" 1618 | bottom: "inception_4d/output" 1619 | top: "inception_4e/pool" 1620 | pooling_param { 1621 | pool: MAX 1622 | kernel_size: 3 1623 | stride: 1 1624 | pad: 1 1625 | } 1626 | } 1627 | layer { 1628 | name: "inception_4e/pool_proj" 1629 | type: "Convolution" 1630 | bottom: "inception_4e/pool" 1631 | top: "inception_4e/pool_proj" 1632 | param { 1633 | lr_mult: 1 1634 | decay_mult: 1 1635 | } 1636 | param { 1637 | lr_mult: 2 1638 | decay_mult: 0 1639 | } 1640 | convolution_param { 1641 | num_output: 128 1642 | kernel_size: 1 1643 | weight_filler { 1644 | type: "xavier" 1645 | std: 0.1 1646 | } 1647 | bias_filler { 1648 | type: "constant" 1649 | value: 0.2 1650 | } 1651 | } 1652 | } 1653 | layer { 1654 | name: "inception_4e/relu_pool_proj" 1655 | type: "ReLU" 1656 | bottom: "inception_4e/pool_proj" 1657 | top: "inception_4e/pool_proj" 1658 | } 1659 | layer { 1660 | name: "inception_4e/output" 1661 | type: "Concat" 1662 | bottom: "inception_4e/1x1" 1663 | bottom: "inception_4e/3x3" 1664 | bottom: "inception_4e/5x5" 1665 | bottom: "inception_4e/pool_proj" 1666 | top: "inception_4e/output" 1667 | } 1668 | layer { 1669 | name: "pool4/3x3_s2" 1670 | type: "Pooling" 1671 | bottom: "inception_4e/output" 1672 | top: "pool4/3x3_s2" 1673 | pooling_param { 1674 | pool: MAX 1675 | kernel_size: 3 1676 | stride: 2 1677 | } 1678 | } 1679 | layer { 1680 | name: "inception_5a/1x1" 1681 | type: "Convolution" 1682 | bottom: "pool4/3x3_s2" 1683 | top: "inception_5a/1x1" 1684 | param { 1685 | lr_mult: 1 1686 | decay_mult: 1 1687 | } 1688 | param { 1689 | lr_mult: 2 1690 | decay_mult: 0 1691 | } 1692 | convolution_param { 1693 | num_output: 256 1694 | kernel_size: 1 1695 | weight_filler { 1696 | type: "xavier" 1697 | std: 0.03 1698 | } 1699 | bias_filler { 1700 | type: "constant" 1701 | value: 0.2 1702 | } 1703 | } 1704 | } 1705 | layer { 1706 | name: "inception_5a/relu_1x1" 1707 | type: "ReLU" 1708 | bottom: "inception_5a/1x1" 1709 | top: "inception_5a/1x1" 1710 | } 1711 | layer { 1712 | name: "inception_5a/3x3_reduce" 1713 | type: "Convolution" 1714 | bottom: "pool4/3x3_s2" 1715 | top: "inception_5a/3x3_reduce" 1716 | param { 1717 | lr_mult: 1 1718 | decay_mult: 1 1719 | } 1720 | param { 1721 | lr_mult: 2 1722 | decay_mult: 0 1723 | } 1724 | convolution_param { 1725 | num_output: 160 1726 | kernel_size: 1 1727 | weight_filler { 1728 | type: "xavier" 1729 | std: 0.09 1730 | } 1731 | bias_filler { 1732 | type: "constant" 1733 | value: 0.2 1734 | } 1735 | } 1736 | } 1737 | layer { 1738 | name: "inception_5a/relu_3x3_reduce" 1739 | type: "ReLU" 1740 | bottom: "inception_5a/3x3_reduce" 1741 | top: "inception_5a/3x3_reduce" 1742 | } 1743 | layer { 1744 | name: "inception_5a/3x3" 1745 | type: "Convolution" 1746 | bottom: "inception_5a/3x3_reduce" 1747 | top: "inception_5a/3x3" 1748 | param { 1749 | lr_mult: 1 1750 | decay_mult: 1 1751 | } 1752 | param { 1753 | lr_mult: 2 1754 | decay_mult: 0 1755 | } 1756 | convolution_param { 1757 | num_output: 320 1758 | pad: 1 1759 | kernel_size: 3 1760 | weight_filler { 1761 | type: "xavier" 1762 | std: 0.03 1763 | } 1764 | bias_filler { 1765 | type: "constant" 1766 | value: 0.2 1767 | } 1768 | } 1769 | } 1770 | layer { 1771 | name: "inception_5a/relu_3x3" 1772 | type: "ReLU" 1773 | bottom: "inception_5a/3x3" 1774 | top: "inception_5a/3x3" 1775 | } 1776 | layer { 1777 | name: "inception_5a/5x5_reduce" 1778 | type: "Convolution" 1779 | bottom: "pool4/3x3_s2" 1780 | top: "inception_5a/5x5_reduce" 1781 | param { 1782 | lr_mult: 1 1783 | decay_mult: 1 1784 | } 1785 | param { 1786 | lr_mult: 2 1787 | decay_mult: 0 1788 | } 1789 | convolution_param { 1790 | num_output: 32 1791 | kernel_size: 1 1792 | weight_filler { 1793 | type: "xavier" 1794 | std: 0.2 1795 | } 1796 | bias_filler { 1797 | type: "constant" 1798 | value: 0.2 1799 | } 1800 | } 1801 | } 1802 | layer { 1803 | name: "inception_5a/relu_5x5_reduce" 1804 | type: "ReLU" 1805 | bottom: "inception_5a/5x5_reduce" 1806 | top: "inception_5a/5x5_reduce" 1807 | } 1808 | layer { 1809 | name: "inception_5a/5x5" 1810 | type: "Convolution" 1811 | bottom: "inception_5a/5x5_reduce" 1812 | top: "inception_5a/5x5" 1813 | param { 1814 | lr_mult: 1 1815 | decay_mult: 1 1816 | } 1817 | param { 1818 | lr_mult: 2 1819 | decay_mult: 0 1820 | } 1821 | convolution_param { 1822 | num_output: 128 1823 | pad: 2 1824 | kernel_size: 5 1825 | weight_filler { 1826 | type: "xavier" 1827 | std: 0.03 1828 | } 1829 | bias_filler { 1830 | type: "constant" 1831 | value: 0.2 1832 | } 1833 | } 1834 | } 1835 | layer { 1836 | name: "inception_5a/relu_5x5" 1837 | type: "ReLU" 1838 | bottom: "inception_5a/5x5" 1839 | top: "inception_5a/5x5" 1840 | } 1841 | layer { 1842 | name: "inception_5a/pool" 1843 | type: "Pooling" 1844 | bottom: "pool4/3x3_s2" 1845 | top: "inception_5a/pool" 1846 | pooling_param { 1847 | pool: MAX 1848 | kernel_size: 3 1849 | stride: 1 1850 | pad: 1 1851 | } 1852 | } 1853 | layer { 1854 | name: "inception_5a/pool_proj" 1855 | type: "Convolution" 1856 | bottom: "inception_5a/pool" 1857 | top: "inception_5a/pool_proj" 1858 | param { 1859 | lr_mult: 1 1860 | decay_mult: 1 1861 | } 1862 | param { 1863 | lr_mult: 2 1864 | decay_mult: 0 1865 | } 1866 | convolution_param { 1867 | num_output: 128 1868 | kernel_size: 1 1869 | weight_filler { 1870 | type: "xavier" 1871 | std: 0.1 1872 | } 1873 | bias_filler { 1874 | type: "constant" 1875 | value: 0.2 1876 | } 1877 | } 1878 | } 1879 | layer { 1880 | name: "inception_5a/relu_pool_proj" 1881 | type: "ReLU" 1882 | bottom: "inception_5a/pool_proj" 1883 | top: "inception_5a/pool_proj" 1884 | } 1885 | layer { 1886 | name: "inception_5a/output" 1887 | type: "Concat" 1888 | bottom: "inception_5a/1x1" 1889 | bottom: "inception_5a/3x3" 1890 | bottom: "inception_5a/5x5" 1891 | bottom: "inception_5a/pool_proj" 1892 | top: "inception_5a/output" 1893 | } 1894 | layer { 1895 | name: "inception_5b/1x1" 1896 | type: "Convolution" 1897 | bottom: "inception_5a/output" 1898 | top: "inception_5b/1x1" 1899 | param { 1900 | lr_mult: 1 1901 | decay_mult: 1 1902 | } 1903 | param { 1904 | lr_mult: 2 1905 | decay_mult: 0 1906 | } 1907 | convolution_param { 1908 | num_output: 384 1909 | kernel_size: 1 1910 | weight_filler { 1911 | type: "xavier" 1912 | std: 0.03 1913 | } 1914 | bias_filler { 1915 | type: "constant" 1916 | value: 0.2 1917 | } 1918 | } 1919 | } 1920 | layer { 1921 | name: "inception_5b/relu_1x1" 1922 | type: "ReLU" 1923 | bottom: "inception_5b/1x1" 1924 | top: "inception_5b/1x1" 1925 | } 1926 | layer { 1927 | name: "inception_5b/3x3_reduce" 1928 | type: "Convolution" 1929 | bottom: "inception_5a/output" 1930 | top: "inception_5b/3x3_reduce" 1931 | param { 1932 | lr_mult: 1 1933 | decay_mult: 1 1934 | } 1935 | param { 1936 | lr_mult: 2 1937 | decay_mult: 0 1938 | } 1939 | convolution_param { 1940 | num_output: 192 1941 | kernel_size: 1 1942 | weight_filler { 1943 | type: "xavier" 1944 | std: 0.09 1945 | } 1946 | bias_filler { 1947 | type: "constant" 1948 | value: 0.2 1949 | } 1950 | } 1951 | } 1952 | layer { 1953 | name: "inception_5b/relu_3x3_reduce" 1954 | type: "ReLU" 1955 | bottom: "inception_5b/3x3_reduce" 1956 | top: "inception_5b/3x3_reduce" 1957 | } 1958 | layer { 1959 | name: "inception_5b/3x3" 1960 | type: "Convolution" 1961 | bottom: "inception_5b/3x3_reduce" 1962 | top: "inception_5b/3x3" 1963 | param { 1964 | lr_mult: 1 1965 | decay_mult: 1 1966 | } 1967 | param { 1968 | lr_mult: 2 1969 | decay_mult: 0 1970 | } 1971 | convolution_param { 1972 | num_output: 384 1973 | pad: 1 1974 | kernel_size: 3 1975 | weight_filler { 1976 | type: "xavier" 1977 | std: 0.03 1978 | } 1979 | bias_filler { 1980 | type: "constant" 1981 | value: 0.2 1982 | } 1983 | } 1984 | } 1985 | layer { 1986 | name: "inception_5b/relu_3x3" 1987 | type: "ReLU" 1988 | bottom: "inception_5b/3x3" 1989 | top: "inception_5b/3x3" 1990 | } 1991 | layer { 1992 | name: "inception_5b/5x5_reduce" 1993 | type: "Convolution" 1994 | bottom: "inception_5a/output" 1995 | top: "inception_5b/5x5_reduce" 1996 | param { 1997 | lr_mult: 1 1998 | decay_mult: 1 1999 | } 2000 | param { 2001 | lr_mult: 2 2002 | decay_mult: 0 2003 | } 2004 | convolution_param { 2005 | num_output: 48 2006 | kernel_size: 1 2007 | weight_filler { 2008 | type: "xavier" 2009 | std: 0.2 2010 | } 2011 | bias_filler { 2012 | type: "constant" 2013 | value: 0.2 2014 | } 2015 | } 2016 | } 2017 | layer { 2018 | name: "inception_5b/relu_5x5_reduce" 2019 | type: "ReLU" 2020 | bottom: "inception_5b/5x5_reduce" 2021 | top: "inception_5b/5x5_reduce" 2022 | } 2023 | layer { 2024 | name: "inception_5b/5x5" 2025 | type: "Convolution" 2026 | bottom: "inception_5b/5x5_reduce" 2027 | top: "inception_5b/5x5" 2028 | param { 2029 | lr_mult: 1 2030 | decay_mult: 1 2031 | } 2032 | param { 2033 | lr_mult: 2 2034 | decay_mult: 0 2035 | } 2036 | convolution_param { 2037 | num_output: 128 2038 | pad: 2 2039 | kernel_size: 5 2040 | weight_filler { 2041 | type: "xavier" 2042 | std: 0.03 2043 | } 2044 | bias_filler { 2045 | type: "constant" 2046 | value: 0.2 2047 | } 2048 | } 2049 | } 2050 | layer { 2051 | name: "inception_5b/relu_5x5" 2052 | type: "ReLU" 2053 | bottom: "inception_5b/5x5" 2054 | top: "inception_5b/5x5" 2055 | } 2056 | layer { 2057 | name: "inception_5b/pool" 2058 | type: "Pooling" 2059 | bottom: "inception_5a/output" 2060 | top: "inception_5b/pool" 2061 | pooling_param { 2062 | pool: MAX 2063 | kernel_size: 3 2064 | stride: 1 2065 | pad: 1 2066 | } 2067 | } 2068 | layer { 2069 | name: "inception_5b/pool_proj" 2070 | type: "Convolution" 2071 | bottom: "inception_5b/pool" 2072 | top: "inception_5b/pool_proj" 2073 | param { 2074 | lr_mult: 1 2075 | decay_mult: 1 2076 | } 2077 | param { 2078 | lr_mult: 2 2079 | decay_mult: 0 2080 | } 2081 | convolution_param { 2082 | num_output: 128 2083 | kernel_size: 1 2084 | weight_filler { 2085 | type: "xavier" 2086 | std: 0.1 2087 | } 2088 | bias_filler { 2089 | type: "constant" 2090 | value: 0.2 2091 | } 2092 | } 2093 | } 2094 | layer { 2095 | name: "inception_5b/relu_pool_proj" 2096 | type: "ReLU" 2097 | bottom: "inception_5b/pool_proj" 2098 | top: "inception_5b/pool_proj" 2099 | } 2100 | layer { 2101 | name: "inception_5b/output" 2102 | type: "Concat" 2103 | bottom: "inception_5b/1x1" 2104 | bottom: "inception_5b/3x3" 2105 | bottom: "inception_5b/5x5" 2106 | bottom: "inception_5b/pool_proj" 2107 | top: "inception_5b/output" 2108 | } 2109 | layer { 2110 | name: "pool5/7x7_s1" 2111 | type: "Pooling" 2112 | bottom: "inception_5b/output" 2113 | top: "pool5/7x7_s1" 2114 | pooling_param { 2115 | pool: AVE 2116 | kernel_size: 7 2117 | stride: 1 2118 | } 2119 | } 2120 | layer { 2121 | name: "pool5/drop_7x7_s1" 2122 | type: "Dropout" 2123 | bottom: "pool5/7x7_s1" 2124 | top: "pool5/7x7_s1" 2125 | dropout_param { 2126 | dropout_ratio: 0.4 2127 | } 2128 | } 2129 | layer { 2130 | name: "loss3/classifier" 2131 | type: "InnerProduct" 2132 | bottom: "pool5/7x7_s1" 2133 | top: "loss3/classifier" 2134 | param { 2135 | lr_mult: 1 2136 | decay_mult: 1 2137 | } 2138 | param { 2139 | lr_mult: 2 2140 | decay_mult: 0 2141 | } 2142 | inner_product_param { 2143 | num_output: 1000 2144 | weight_filler { 2145 | type: "xavier" 2146 | } 2147 | bias_filler { 2148 | type: "constant" 2149 | value: 0 2150 | } 2151 | } 2152 | } 2153 | #layer { 2154 | # name: "prob" 2155 | # type: "Softmax" 2156 | # bottom: "loss3/classifier" 2157 | # top: "prob" 2158 | #} 2159 | -------------------------------------------------------------------------------- /matlab/data/deploy_vgg_16.prototxt: -------------------------------------------------------------------------------- 1 | force_backward: true 2 | name: "VGG_ILSVRC_16_layers" 3 | input: "data" 4 | input_dim: 1 5 | input_dim: 3 6 | input_dim: 224 7 | input_dim: 224 8 | layers { 9 | bottom: "data" 10 | top: "conv1_1" 11 | name: "conv1_1" 12 | type: CONVOLUTION 13 | convolution_param { 14 | num_output: 64 15 | pad: 1 16 | kernel_size: 3 17 | } 18 | } 19 | layers { 20 | bottom: "conv1_1" 21 | top: "conv1_1" 22 | name: "relu1_1" 23 | type: RELU 24 | } 25 | layers { 26 | bottom: "conv1_1" 27 | top: "conv1_2" 28 | name: "conv1_2" 29 | type: CONVOLUTION 30 | convolution_param { 31 | num_output: 64 32 | pad: 1 33 | kernel_size: 3 34 | } 35 | } 36 | layers { 37 | bottom: "conv1_2" 38 | top: "conv1_2" 39 | name: "relu1_2" 40 | type: RELU 41 | } 42 | layers { 43 | bottom: "conv1_2" 44 | top: "pool1" 45 | name: "pool1" 46 | type: POOLING 47 | pooling_param { 48 | pool: MAX 49 | kernel_size: 2 50 | stride: 2 51 | } 52 | } 53 | layers { 54 | bottom: "pool1" 55 | top: "conv2_1" 56 | name: "conv2_1" 57 | type: CONVOLUTION 58 | convolution_param { 59 | num_output: 128 60 | pad: 1 61 | kernel_size: 3 62 | } 63 | } 64 | layers { 65 | bottom: "conv2_1" 66 | top: "conv2_1" 67 | name: "relu2_1" 68 | type: RELU 69 | } 70 | layers { 71 | bottom: "conv2_1" 72 | top: "conv2_2" 73 | name: "conv2_2" 74 | type: CONVOLUTION 75 | convolution_param { 76 | num_output: 128 77 | pad: 1 78 | kernel_size: 3 79 | } 80 | } 81 | layers { 82 | bottom: "conv2_2" 83 | top: "conv2_2" 84 | name: "relu2_2" 85 | type: RELU 86 | } 87 | layers { 88 | bottom: "conv2_2" 89 | top: "pool2" 90 | name: "pool2" 91 | type: POOLING 92 | pooling_param { 93 | pool: MAX 94 | kernel_size: 2 95 | stride: 2 96 | } 97 | } 98 | layers { 99 | bottom: "pool2" 100 | top: "conv3_1" 101 | name: "conv3_1" 102 | type: CONVOLUTION 103 | convolution_param { 104 | num_output: 256 105 | pad: 1 106 | kernel_size: 3 107 | } 108 | } 109 | layers { 110 | bottom: "conv3_1" 111 | top: "conv3_1" 112 | name: "relu3_1" 113 | type: RELU 114 | } 115 | layers { 116 | bottom: "conv3_1" 117 | top: "conv3_2" 118 | name: "conv3_2" 119 | type: CONVOLUTION 120 | convolution_param { 121 | num_output: 256 122 | pad: 1 123 | kernel_size: 3 124 | } 125 | } 126 | layers { 127 | bottom: "conv3_2" 128 | top: "conv3_2" 129 | name: "relu3_2" 130 | type: RELU 131 | } 132 | layers { 133 | bottom: "conv3_2" 134 | top: "conv3_3" 135 | name: "conv3_3" 136 | type: CONVOLUTION 137 | convolution_param { 138 | num_output: 256 139 | pad: 1 140 | kernel_size: 3 141 | } 142 | } 143 | layers { 144 | bottom: "conv3_3" 145 | top: "conv3_3" 146 | name: "relu3_3" 147 | type: RELU 148 | } 149 | layers { 150 | bottom: "conv3_3" 151 | top: "pool3" 152 | name: "pool3" 153 | type: POOLING 154 | pooling_param { 155 | pool: MAX 156 | kernel_size: 2 157 | stride: 2 158 | } 159 | } 160 | layers { 161 | bottom: "pool3" 162 | top: "conv4_1" 163 | name: "conv4_1" 164 | type: CONVOLUTION 165 | convolution_param { 166 | num_output: 512 167 | pad: 1 168 | kernel_size: 3 169 | } 170 | } 171 | layers { 172 | bottom: "conv4_1" 173 | top: "conv4_1" 174 | name: "relu4_1" 175 | type: RELU 176 | } 177 | layers { 178 | bottom: "conv4_1" 179 | top: "conv4_2" 180 | name: "conv4_2" 181 | type: CONVOLUTION 182 | convolution_param { 183 | num_output: 512 184 | pad: 1 185 | kernel_size: 3 186 | } 187 | } 188 | layers { 189 | bottom: "conv4_2" 190 | top: "conv4_2" 191 | name: "relu4_2" 192 | type: RELU 193 | } 194 | layers { 195 | bottom: "conv4_2" 196 | top: "conv4_3" 197 | name: "conv4_3" 198 | type: CONVOLUTION 199 | convolution_param { 200 | num_output: 512 201 | pad: 1 202 | kernel_size: 3 203 | } 204 | } 205 | layers { 206 | bottom: "conv4_3" 207 | top: "conv4_3" 208 | name: "relu4_3" 209 | type: RELU 210 | } 211 | layers { 212 | bottom: "conv4_3" 213 | top: "pool4" 214 | name: "pool4" 215 | type: POOLING 216 | pooling_param { 217 | pool: MAX 218 | kernel_size: 2 219 | stride: 2 220 | } 221 | } 222 | layers { 223 | bottom: "pool4" 224 | top: "conv5_1" 225 | name: "conv5_1" 226 | type: CONVOLUTION 227 | convolution_param { 228 | num_output: 512 229 | pad: 1 230 | kernel_size: 3 231 | } 232 | } 233 | layers { 234 | bottom: "conv5_1" 235 | top: "conv5_1" 236 | name: "relu5_1" 237 | type: RELU 238 | } 239 | layers { 240 | bottom: "conv5_1" 241 | top: "conv5_2" 242 | name: "conv5_2" 243 | type: CONVOLUTION 244 | convolution_param { 245 | num_output: 512 246 | pad: 1 247 | kernel_size: 3 248 | } 249 | } 250 | layers { 251 | bottom: "conv5_2" 252 | top: "conv5_2" 253 | name: "relu5_2" 254 | type: RELU 255 | } 256 | layers { 257 | bottom: "conv5_2" 258 | top: "conv5_3" 259 | name: "conv5_3" 260 | type: CONVOLUTION 261 | convolution_param { 262 | num_output: 512 263 | pad: 1 264 | kernel_size: 3 265 | } 266 | } 267 | layers { 268 | bottom: "conv5_3" 269 | top: "conv5_3" 270 | name: "relu5_3" 271 | type: RELU 272 | } 273 | layers { 274 | bottom: "conv5_3" 275 | top: "pool5" 276 | name: "pool5" 277 | type: POOLING 278 | pooling_param { 279 | pool: MAX 280 | kernel_size: 2 281 | stride: 2 282 | } 283 | } 284 | layers { 285 | bottom: "pool5" 286 | top: "fc6" 287 | name: "fc6" 288 | type: INNER_PRODUCT 289 | inner_product_param { 290 | num_output: 4096 291 | } 292 | } 293 | layers { 294 | bottom: "fc6" 295 | top: "fc6" 296 | name: "relu6" 297 | type: RELU 298 | } 299 | layers { 300 | bottom: "fc6" 301 | top: "fc6" 302 | name: "drop6" 303 | type: DROPOUT 304 | dropout_param { 305 | dropout_ratio: 0.5 306 | } 307 | } 308 | layers { 309 | bottom: "fc6" 310 | top: "fc7" 311 | name: "fc7" 312 | type: INNER_PRODUCT 313 | inner_product_param { 314 | num_output: 4096 315 | } 316 | } 317 | layers { 318 | bottom: "fc7" 319 | top: "fc7" 320 | name: "relu7" 321 | type: RELU 322 | } 323 | layers { 324 | bottom: "fc7" 325 | top: "fc7" 326 | name: "drop7" 327 | type: DROPOUT 328 | dropout_param { 329 | dropout_ratio: 0.5 330 | } 331 | } 332 | layers { 333 | bottom: "fc7" 334 | top: "fc8" 335 | name: "fc8" 336 | type: INNER_PRODUCT 337 | inner_product_param { 338 | num_output: 1000 339 | } 340 | } 341 | #layers { 342 | # bottom: "fc8" 343 | # top: "prob" 344 | # name: "prob" 345 | # type: SOFTMAX 346 | #} 347 | -------------------------------------------------------------------------------- /matlab/data/deploy_vgg_19.prototxt: -------------------------------------------------------------------------------- 1 | force_backward: true 2 | name: "VGG_ILSVRC_19_layers" 3 | input: "data" 4 | input_dim: 1 5 | input_dim: 3 6 | input_dim: 224 7 | input_dim: 224 8 | layers { 9 | bottom: "data" 10 | top: "conv1_1" 11 | name: "conv1_1" 12 | type: CONVOLUTION 13 | convolution_param { 14 | num_output: 64 15 | pad: 1 16 | kernel_size: 3 17 | } 18 | } 19 | layers { 20 | bottom: "conv1_1" 21 | top: "conv1_1" 22 | name: "relu1_1" 23 | type: RELU 24 | } 25 | layers { 26 | bottom: "conv1_1" 27 | top: "conv1_2" 28 | name: "conv1_2" 29 | type: CONVOLUTION 30 | convolution_param { 31 | num_output: 64 32 | pad: 1 33 | kernel_size: 3 34 | } 35 | } 36 | layers { 37 | bottom: "conv1_2" 38 | top: "conv1_2" 39 | name: "relu1_2" 40 | type: RELU 41 | } 42 | layers { 43 | bottom: "conv1_2" 44 | top: "pool1" 45 | name: "pool1" 46 | type: POOLING 47 | pooling_param { 48 | pool: MAX 49 | kernel_size: 2 50 | stride: 2 51 | } 52 | } 53 | layers { 54 | bottom: "pool1" 55 | top: "conv2_1" 56 | name: "conv2_1" 57 | type: CONVOLUTION 58 | convolution_param { 59 | num_output: 128 60 | pad: 1 61 | kernel_size: 3 62 | } 63 | } 64 | layers { 65 | bottom: "conv2_1" 66 | top: "conv2_1" 67 | name: "relu2_1" 68 | type: RELU 69 | } 70 | layers { 71 | bottom: "conv2_1" 72 | top: "conv2_2" 73 | name: "conv2_2" 74 | type: CONVOLUTION 75 | convolution_param { 76 | num_output: 128 77 | pad: 1 78 | kernel_size: 3 79 | } 80 | } 81 | layers { 82 | bottom: "conv2_2" 83 | top: "conv2_2" 84 | name: "relu2_2" 85 | type: RELU 86 | } 87 | layers { 88 | bottom: "conv2_2" 89 | top: "pool2" 90 | name: "pool2" 91 | type: POOLING 92 | pooling_param { 93 | pool: MAX 94 | kernel_size: 2 95 | stride: 2 96 | } 97 | } 98 | layers { 99 | bottom: "pool2" 100 | top: "conv3_1" 101 | name: "conv3_1" 102 | type: CONVOLUTION 103 | convolution_param { 104 | num_output: 256 105 | pad: 1 106 | kernel_size: 3 107 | } 108 | } 109 | layers { 110 | bottom: "conv3_1" 111 | top: "conv3_1" 112 | name: "relu3_1" 113 | type: RELU 114 | } 115 | layers { 116 | bottom: "conv3_1" 117 | top: "conv3_2" 118 | name: "conv3_2" 119 | type: CONVOLUTION 120 | convolution_param { 121 | num_output: 256 122 | pad: 1 123 | kernel_size: 3 124 | } 125 | } 126 | layers { 127 | bottom: "conv3_2" 128 | top: "conv3_2" 129 | name: "relu3_2" 130 | type: RELU 131 | } 132 | layers { 133 | bottom: "conv3_2" 134 | top: "conv3_3" 135 | name: "conv3_3" 136 | type: CONVOLUTION 137 | convolution_param { 138 | num_output: 256 139 | pad: 1 140 | kernel_size: 3 141 | } 142 | } 143 | layers { 144 | bottom: "conv3_3" 145 | top: "conv3_3" 146 | name: "relu3_3" 147 | type: RELU 148 | } 149 | layers { 150 | bottom: "conv3_3" 151 | top: "conv3_4" 152 | name: "conv3_4" 153 | type: CONVOLUTION 154 | convolution_param { 155 | num_output: 256 156 | pad: 1 157 | kernel_size: 3 158 | } 159 | } 160 | layers { 161 | bottom: "conv3_4" 162 | top: "conv3_4" 163 | name: "relu3_4" 164 | type: RELU 165 | } 166 | layers { 167 | bottom: "conv3_4" 168 | top: "pool3" 169 | name: "pool3" 170 | type: POOLING 171 | pooling_param { 172 | pool: MAX 173 | kernel_size: 2 174 | stride: 2 175 | } 176 | } 177 | layers { 178 | bottom: "pool3" 179 | top: "conv4_1" 180 | name: "conv4_1" 181 | type: CONVOLUTION 182 | convolution_param { 183 | num_output: 512 184 | pad: 1 185 | kernel_size: 3 186 | } 187 | } 188 | layers { 189 | bottom: "conv4_1" 190 | top: "conv4_1" 191 | name: "relu4_1" 192 | type: RELU 193 | } 194 | layers { 195 | bottom: "conv4_1" 196 | top: "conv4_2" 197 | name: "conv4_2" 198 | type: CONVOLUTION 199 | convolution_param { 200 | num_output: 512 201 | pad: 1 202 | kernel_size: 3 203 | } 204 | } 205 | layers { 206 | bottom: "conv4_2" 207 | top: "conv4_2" 208 | name: "relu4_2" 209 | type: RELU 210 | } 211 | layers { 212 | bottom: "conv4_2" 213 | top: "conv4_3" 214 | name: "conv4_3" 215 | type: CONVOLUTION 216 | convolution_param { 217 | num_output: 512 218 | pad: 1 219 | kernel_size: 3 220 | } 221 | } 222 | layers { 223 | bottom: "conv4_3" 224 | top: "conv4_3" 225 | name: "relu4_3" 226 | type: RELU 227 | } 228 | layers { 229 | bottom: "conv4_3" 230 | top: "conv4_4" 231 | name: "conv4_4" 232 | type: CONVOLUTION 233 | convolution_param { 234 | num_output: 512 235 | pad: 1 236 | kernel_size: 3 237 | } 238 | } 239 | layers { 240 | bottom: "conv4_4" 241 | top: "conv4_4" 242 | name: "relu4_4" 243 | type: RELU 244 | } 245 | layers { 246 | bottom: "conv4_4" 247 | top: "pool4" 248 | name: "pool4" 249 | type: POOLING 250 | pooling_param { 251 | pool: MAX 252 | kernel_size: 2 253 | stride: 2 254 | } 255 | } 256 | layers { 257 | bottom: "pool4" 258 | top: "conv5_1" 259 | name: "conv5_1" 260 | type: CONVOLUTION 261 | convolution_param { 262 | num_output: 512 263 | pad: 1 264 | kernel_size: 3 265 | } 266 | } 267 | layers { 268 | bottom: "conv5_1" 269 | top: "conv5_1" 270 | name: "relu5_1" 271 | type: RELU 272 | } 273 | layers { 274 | bottom: "conv5_1" 275 | top: "conv5_2" 276 | name: "conv5_2" 277 | type: CONVOLUTION 278 | convolution_param { 279 | num_output: 512 280 | pad: 1 281 | kernel_size: 3 282 | } 283 | } 284 | layers { 285 | bottom: "conv5_2" 286 | top: "conv5_2" 287 | name: "relu5_2" 288 | type: RELU 289 | } 290 | layers { 291 | bottom: "conv5_2" 292 | top: "conv5_3" 293 | name: "conv5_3" 294 | type: CONVOLUTION 295 | convolution_param { 296 | num_output: 512 297 | pad: 1 298 | kernel_size: 3 299 | } 300 | } 301 | layers { 302 | bottom: "conv5_3" 303 | top: "conv5_3" 304 | name: "relu5_3" 305 | type: RELU 306 | } 307 | layers { 308 | bottom: "conv5_3" 309 | top: "conv5_4" 310 | name: "conv5_4" 311 | type: CONVOLUTION 312 | convolution_param { 313 | num_output: 512 314 | pad: 1 315 | kernel_size: 3 316 | } 317 | } 318 | layers { 319 | bottom: "conv5_4" 320 | top: "conv5_4" 321 | name: "relu5_4" 322 | type: RELU 323 | } 324 | layers { 325 | bottom: "conv5_4" 326 | top: "pool5" 327 | name: "pool5" 328 | type: POOLING 329 | pooling_param { 330 | pool: MAX 331 | kernel_size: 2 332 | stride: 2 333 | } 334 | } 335 | layers { 336 | bottom: "pool5" 337 | top: "fc6" 338 | name: "fc6" 339 | type: INNER_PRODUCT 340 | inner_product_param { 341 | num_output: 4096 342 | } 343 | } 344 | layers { 345 | bottom: "fc6" 346 | top: "fc6" 347 | name: "relu6" 348 | type: RELU 349 | } 350 | layers { 351 | bottom: "fc6" 352 | top: "fc6" 353 | name: "drop6" 354 | type: DROPOUT 355 | dropout_param { 356 | dropout_ratio: 0.5 357 | } 358 | } 359 | layers { 360 | bottom: "fc6" 361 | top: "fc7" 362 | name: "fc7" 363 | type: INNER_PRODUCT 364 | inner_product_param { 365 | num_output: 4096 366 | } 367 | } 368 | layers { 369 | bottom: "fc7" 370 | top: "fc7" 371 | name: "relu7" 372 | type: RELU 373 | } 374 | layers { 375 | bottom: "fc7" 376 | top: "fc7" 377 | name: "drop7" 378 | type: DROPOUT 379 | dropout_param { 380 | dropout_ratio: 0.5 381 | } 382 | } 383 | layers { 384 | bottom: "fc7" 385 | top: "fc8" 386 | name: "fc8" 387 | type: INNER_PRODUCT 388 | inner_product_param { 389 | num_output: 1000 390 | } 391 | } 392 | #layers { 393 | # bottom: "fc8" 394 | # top: "prob" 395 | # name: "prob" 396 | # type: SOFTMAX 397 | #} 398 | -------------------------------------------------------------------------------- /matlab/data/deploy_vgg_f.prototxt: -------------------------------------------------------------------------------- 1 | force_backward: true 2 | name: "VGG_CNN_F" 3 | input: "data" 4 | input_dim: 1 5 | input_dim: 3 6 | input_dim: 224 7 | input_dim: 224 8 | layers { 9 | bottom: "data" 10 | top: "conv1" 11 | name: "conv1" 12 | type: CONVOLUTION 13 | convolution_param { 14 | num_output: 64 15 | kernel_size: 11 16 | stride: 4 17 | } 18 | } 19 | layers { 20 | bottom: "conv1" 21 | top: "conv1" 22 | name: "relu1" 23 | type: RELU 24 | } 25 | layers { 26 | bottom: "conv1" 27 | top: "norm1" 28 | name: "norm1" 29 | type: LRN 30 | lrn_param { 31 | local_size: 5 32 | alpha: 0.0005 33 | beta: 0.75 34 | k: 2 35 | } 36 | } 37 | layers { 38 | bottom: "norm1" 39 | top: "pool1" 40 | name: "pool1" 41 | type: POOLING 42 | pooling_param { 43 | pool: MAX 44 | kernel_size: 3 45 | stride: 2 46 | } 47 | } 48 | layers { 49 | bottom: "pool1" 50 | top: "conv2" 51 | name: "conv2" 52 | type: CONVOLUTION 53 | convolution_param { 54 | num_output: 256 55 | pad: 2 56 | kernel_size: 5 57 | } 58 | } 59 | layers { 60 | bottom: "conv2" 61 | top: "conv2" 62 | name: "relu2" 63 | type: RELU 64 | } 65 | layers { 66 | bottom: "conv2" 67 | top: "norm2" 68 | name: "norm2" 69 | type: LRN 70 | lrn_param { 71 | local_size: 5 72 | alpha: 0.0005 73 | beta: 0.75 74 | k: 2 75 | } 76 | } 77 | layers { 78 | bottom: "norm2" 79 | top: "pool2" 80 | name: "pool2" 81 | type: POOLING 82 | pooling_param { 83 | pool: MAX 84 | kernel_size: 3 85 | stride: 2 86 | } 87 | } 88 | layers { 89 | bottom: "pool2" 90 | top: "conv3" 91 | name: "conv3" 92 | type: CONVOLUTION 93 | convolution_param { 94 | num_output: 256 95 | pad: 1 96 | kernel_size: 3 97 | } 98 | } 99 | layers { 100 | bottom: "conv3" 101 | top: "conv3" 102 | name: "relu3" 103 | type: RELU 104 | } 105 | layers { 106 | bottom: "conv3" 107 | top: "conv4" 108 | name: "conv4" 109 | type: CONVOLUTION 110 | convolution_param { 111 | num_output: 256 112 | pad: 1 113 | kernel_size: 3 114 | } 115 | } 116 | layers { 117 | bottom: "conv4" 118 | top: "conv4" 119 | name: "relu4" 120 | type: RELU 121 | } 122 | layers { 123 | bottom: "conv4" 124 | top: "conv5" 125 | name: "conv5" 126 | type: CONVOLUTION 127 | convolution_param { 128 | num_output: 256 129 | pad: 1 130 | kernel_size: 3 131 | } 132 | } 133 | layers { 134 | bottom: "conv5" 135 | top: "conv5" 136 | name: "relu5" 137 | type: RELU 138 | } 139 | layers { 140 | bottom: "conv5" 141 | top: "pool5" 142 | name: "pool5" 143 | type: POOLING 144 | pooling_param { 145 | pool: MAX 146 | kernel_size: 3 147 | stride: 2 148 | } 149 | } 150 | layers { 151 | bottom: "pool5" 152 | top: "fc6" 153 | name: "fc6" 154 | type: INNER_PRODUCT 155 | inner_product_param { 156 | num_output: 4096 157 | } 158 | } 159 | layers { 160 | bottom: "fc6" 161 | top: "fc6" 162 | name: "relu6" 163 | type: RELU 164 | } 165 | layers { 166 | bottom: "fc6" 167 | top: "fc6" 168 | name: "drop6" 169 | type: DROPOUT 170 | dropout_param { 171 | dropout_ratio: 0.5 172 | } 173 | } 174 | layers { 175 | bottom: "fc6" 176 | top: "fc7" 177 | name: "fc7" 178 | type: INNER_PRODUCT 179 | inner_product_param { 180 | num_output: 4096 181 | } 182 | } 183 | layers { 184 | bottom: "fc7" 185 | top: "fc7" 186 | name: "relu7" 187 | type: RELU 188 | } 189 | layers { 190 | bottom: "fc7" 191 | top: "fc7" 192 | name: "drop7" 193 | type: DROPOUT 194 | dropout_param { 195 | dropout_ratio: 0.5 196 | } 197 | } 198 | layers { 199 | bottom: "fc7" 200 | top: "fc8" 201 | name: "fc8" 202 | type: INNER_PRODUCT 203 | inner_product_param { 204 | num_output: 1000 205 | } 206 | } 207 | #layers { 208 | # bottom: "fc8" 209 | # top: "prob" 210 | # name: "prob" 211 | # type: SOFTMAX 212 | #} 213 | -------------------------------------------------------------------------------- /matlab/data/ilsvrc_2012_mean.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/matlab/data/ilsvrc_2012_mean.mat -------------------------------------------------------------------------------- /matlab/data/synset_words.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 | -------------------------------------------------------------------------------- /matlab/data/test_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/matlab/data/test_img.png -------------------------------------------------------------------------------- /matlab/demo_caffe.m: -------------------------------------------------------------------------------- 1 | clear; clc; close all; 2 | 3 | DEVICE_ID = 0; %set gpu id starting from 0 4 | 5 | % set paths to Caffe and DeepFool 6 | PATH_CAFFE = '/path/to/caffe/matlab'; 7 | PATH_DEEPFOOL = '/path/to/DeepFool'; 8 | PATH_IMAGENET_TRAIN = '/path/to/ILSVRC2012/train'; 9 | 10 | addpath(PATH_CAFFE); 11 | addpath(PATH_DEEPFOOL); 12 | 13 | caffe.set_mode_gpu(); 14 | caffe.set_device(DEVICE_ID); 15 | 16 | model = 'caffenet'; 17 | 18 | if (strcmp(model, 'vgg_16')) 19 | fprintf('Loading VGG 16\n'); 20 | net_model_path = fullfile('data', 'deploy_vgg_16.prototxt'); 21 | net_weights_path = fullfile('data', 'vgg_16.caffemodel'); 22 | net_url = 'http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel'; 23 | elseif (strcmp(model, 'vgg_19')) 24 | fprintf('Loading VGG 19\n'); 25 | net_model_path = fullfile('data', 'deploy_vgg_19.prototxt'); 26 | net_weights_path = fullfile('data', 'vgg_19.caffemodel'); 27 | net_url = 'http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_19_layers.caffemodel'; 28 | elseif (strcmp(model, 'googlenet')) 29 | fprintf('Loading GoogLeNet\n'); 30 | net_model_path = fullfile('data', 'deploy_googlenet.prototxt'); 31 | net_weights_path = fullfile('data', 'googlenet.caffemodel'); 32 | net_url = 'http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel'; 33 | elseif (strcmp(model, 'vgg_f')) 34 | fprintf('Loading VGG-F\n'); 35 | net_model_path = fullfile('data', 'deploy_vgg_f.prototxt'); 36 | net_weights_path = fullfile('data', 'googlenet.caffemodel'); 37 | net_url = 'http://dl.caffe.berkeleyvision.org/bvlc_vgg_f.caffemodel'; 38 | elseif (strcmp(model, 'caffenet')) 39 | fprintf('Loading CaffeNet\n'); 40 | net_model_path = fullfile('data', 'deploy_caffenet.prototxt'); 41 | net_weights_path = fullfile('data', 'caffenet.caffemodel'); 42 | net_url = 'http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel'; 43 | elseif (strcmp(model, 'resnet-152')) 44 | fprintf('Loading ResNet-152\n'); 45 | net_model_path = fullfile('data', 'deploy_resnet.prototxt'); 46 | net_weights_path = fullfile('data', 'caffenet.caffemodel'); 47 | net_url = 'https://deepdetect.com/models/resnet/ResNet-152-model.caffemodel'; 48 | else 49 | error('Model is not recognized!'); 50 | end 51 | 52 | if (~exist(net_weights_path, 'file')) 53 | fprintf('Downloading model...\n'); 54 | websave(net_weights_path, net_url); 55 | end 56 | 57 | 58 | net = caffe.Net(net_model_path, net_weights_path, 'test'); % run with phase test (so that dropout isn't applied) 59 | fprintf('Network is loaded\n'); 60 | 61 | % Loading the data 62 | fprintf('Loading the data...\n'); 63 | im_array = makeImagenetData(PATH_IMAGENET_TRAIN); 64 | fprintf('Data is loaded\n'); 65 | 66 | % set options 67 | opts.library = 'caffe'; 68 | opts.net = net; 69 | 70 | v = universal_perturbation(im_array, opts); 71 | 72 | % Test perturbation on a sample image 73 | 74 | d = load(fullfile('data', 'ilsvrc_2012_mean.mat')); 75 | mean_data = d.mean_data; 76 | 77 | labels_file = fullfile('data', 'synset_words.txt'); 78 | fileID = fopen(labels_file); 79 | C = textscan(fileID, '%c %d %s', 'Delimiter', '\n'); 80 | synset_names = C{3}; 81 | synset_names_short = synset_names; 82 | for i = 1:1000 83 | synset_names_short(i) = strtok(synset_names(i), ','); 84 | end 85 | 86 | im_test = imread(fullfile('data', 'test_img.png')); 87 | im_test = preprocess_img(im_test, mean_data); 88 | 89 | original_label = predict_caffe(im_test, net, 1); 90 | perturbed_label = predict_caffe(im_test+v, net, 1); 91 | 92 | % Show original and perturbed images 93 | im_ = im_test + mean_data(1:224, 1:224, :); 94 | im_ = permute(im_,[2,1,3]); 95 | im_ = im_(:,:,[3,2,1],:); 96 | 97 | figure; imshow(uint8(im_)); 98 | xlabel(synset_names_short(original_label)); 99 | set(gca,'xtick',[],'ytick',[]) 100 | set(gcf, 'Color', 'white'); 101 | set(gca, 'FontSize', 15); 102 | title('Original image'); 103 | 104 | v_ = permute(v,[2,1,3]); 105 | v_ = v_(:,:,[3,2,1],:); 106 | figure; imshow(uint8(im_ + v_)); 107 | xlabel(synset_names_short(perturbed_label)); 108 | set(gca,'xtick',[],'ytick',[]) 109 | set(gcf, 'Color', 'white'); 110 | set(gca, 'FontSize', 15); 111 | title('Perturbed image'); 112 | -------------------------------------------------------------------------------- /matlab/makeImagenetData.m: -------------------------------------------------------------------------------- 1 | function im_array = makeImagenetData(imagenet_path) 2 | 3 | if (exist(fullfile('data', 'ImageNet.h5'), 'file')) 4 | im_array = h5read(fullfile('data', 'ImageNet.h5'), ['/batch',num2str(1)]); 5 | return; 6 | end 7 | 8 | d = load(fullfile('data', 'ilsvrc_2012_mean.mat')); 9 | mean_data = d.mean_data; 10 | 11 | num_class = 1000; 12 | num_images = 10000; 13 | num_per_class = num_images/num_class; 14 | 15 | allLabels = dir( [imagenet_path] ); 16 | class_name = {allLabels(3:end).name}; 17 | 18 | im_array = zeros(224,224,3,num_images,'single'); 19 | 20 | for j=1:num_class 21 | fprintf('Processing data %d\n', j); 22 | ff = fullfile(imagenet_path, class_name{j}); 23 | allFiles = dir( ff ); 24 | fullfile(imagenet_path, class_name{j}) 25 | allNames = { allFiles.name }; 26 | for i=1:num_per_class 27 | im = imread(char(fullfile(ff, allNames(i+3)))); 28 | if size(im,3)==1 29 | im = repmat(im,1,1,3); 30 | end 31 | im_array_par(:,:,:,i) = preprocess_img(im, mean_data); 32 | end 33 | im_array(:,:,:,(j-1)*num_per_class+(1:num_per_class)) = im_array_par; 34 | end 35 | 36 | % Save data 37 | % This can take a significant amount of space. Comment if needed. 38 | fprintf('Saving the data...\n'); 39 | h5create(fullfile('data', 'ImageNet.h5'),['/batch',num2str(1)],[224 224 3 10000],'DataType','single'); 40 | h5write(fullfile('data', 'ImageNet.h5'), ['/batch',num2str(1)], im_array); -------------------------------------------------------------------------------- /matlab/predict_caffe.m: -------------------------------------------------------------------------------- 1 | function [l,out] = predict_caffe(im,net,BATCH_SIZE) 2 | % Computes the labels of im predicted by net 3 | 4 | blob_shape = net.blobs('data').shape(); % store the original input size 5 | n = size(im,4); 6 | 7 | change_input_blob(net,BATCH_SIZE); % rehsape the input batch size 8 | 9 | K = floor(n/BATCH_SIZE); 10 | R = rem(n,BATCH_SIZE); 11 | 12 | for k=1:K 13 | res = net.forward({im(:,:,:,(k-1)*BATCH_SIZE+(1:BATCH_SIZE))}); 14 | res2(:,((k-1)*BATCH_SIZE+1):k*BATCH_SIZE)=res{1}; 15 | end 16 | 17 | if(R~=0) 18 | change_input_blob(net,R); 19 | res = net.forward({im(:,:,:,K*BATCH_SIZE+(1:R))}); 20 | res2(:,(K*BATCH_SIZE+1):K*BATCH_SIZE+R)=res{1}; 21 | end 22 | [~,l] = max(res2,[],1); 23 | out = res2; 24 | 25 | net.blobs('data').reshape(blob_shape); % reshape to the original input size 26 | net.reshape(); 27 | end 28 | -------------------------------------------------------------------------------- /matlab/predict_matconvnet.m: -------------------------------------------------------------------------------- 1 | function [ys, scores] = predict_matconvnet(ims, net, batchsize) 2 | 3 | ys = zeros(size(ims, 4), 1); 4 | scores = zeros(1000, size(ims, 4)); % Number of classes 5 | for b = 1:batchsize:size(ims, 4) 6 | res = vl_simplenn(net, gpuArray(ims(:, :, :, b:(b+batchsize-1))), [], [], 'Mode', 'test'); 7 | 8 | cc = squeeze(gather(res(end).x)); 9 | scores(:, b:(b+batchsize-1)) = cc; 10 | [~, ys(b:(b+batchsize-1))] = max(squeeze(gather(res(end).x))); 11 | end 12 | 13 | end -------------------------------------------------------------------------------- /matlab/preprocess_img.m: -------------------------------------------------------------------------------- 1 | function imgs_out = preprocess_img(imgs, mean_data) 2 | 3 | IMAGE_DIM = 256; 4 | 5 | if size(imgs,3)==1 6 | imgs = repmat(imgs,1,1,3); 7 | end 8 | im_ = imgs(:, :, [3, 2, 1]); % permute channels from RGB to BGR 9 | im_ = permute(im_, [2, 1, 3]); % flip width and height 10 | im_ = single(im_); % convert from uint8 to single 11 | im_ = imresize(im_, [IMAGE_DIM IMAGE_DIM], 'bilinear'); % resize im_data 12 | im_ = im_ - mean_data; % subtract mean_data (already in W x H x C, BGR) 13 | imgs_out = im_(1:224,1:224,:); 14 | 15 | end -------------------------------------------------------------------------------- /matlab/readme.md: -------------------------------------------------------------------------------- 1 | #MATLAB 2 | 3 | ###universal_perturbation.m 4 | 5 | This function implements the algorithm proposed in [[1]](http://arxiv.org/pdf/1610.08401) to find a universal perturbation. 6 | 7 | ###Inputs 8 | - `dataset`: images in `W*H*C*N` format, where `W`:width, `H`:height, `C`:channels (RGB), and `N`:number of images. 9 | - `opts`: A structure containing the following optionals and non-optionals parameters: 10 | - `library`: framework to be used: Caffe or MatConvNet. __(Obligatory)__ 11 | - `net`: corresponding network structure. __(Obligatory)__ 12 | - `delta`: controls the desired fooling rate (default = 80% fooling rate). 13 | - `MAX_ITER_UNIV`: termination criterion (maximum number of iterations, default = Inf). 14 | - `xi`: controls the l_p magnitude of the perturbation (default = 10). 15 | - `p`: norm to be used (FOR NOW, ONLY p = 2, and p = Inf ARE ACCEPTED!) (default = Inf). 16 | - `df`: DeepFool's parameters (see [DeepFool](http://github.com/lts4/deepfool) for more information). 17 | 18 | ###Output 19 | - `v`: a `W*H*C` perturbation image. 20 | 21 | ##Usage 22 | 23 | A demo using Caffe is provided in `demo_caffe.m`. 24 | 25 | First of all, you need to setup the paths to [DeepFool](http://github.com/lts4/deepfool) and [Caffe](http://caffe.berkeleyvision.org) (or [MatConvNet](http://www.vlfeat.org/matconvnet/)), e.g.: 26 | ``` 27 | addpath('./DeepFool'); 28 | addpath('./caffe/matlab'); 29 | ``` 30 | Next, you have to load your pre-trained model. __Note that the last layer (usually softmax layer) should have been removed (see [DeepFool](http://github.com/lts4/deepfool) for more information).__ We provide in the `data` folder the prototxt files for the common networks, without the softmax layer. The pre-trained model can be loaded as follows, using Caffe: 31 | ``` 32 | caffe.set_mode_gpu(); % initialize Caffe in gpu mode 33 | caffe.set_device(0); % choose the first gpu 34 | 35 | net_model = 'deploy_googlenet.prototxt'; % GoogLeNet without softmax layer 36 | net_weights = 'googlenet.caffemodel'; % weights 37 | net = caffe.Net(net_model, net_weights, 'test'); % run with phase test 38 | ``` 39 | After loading your pre-trained model using your preferred framework, you have to load the set of images to compute the universal perturbation. __Be careful that the images should be pre-processed in the same way that the training images are pre-processed.__ We provide an example script in `makeImagenetData.m`, where 10,000 training images are used. Once you have your data, you can load it and compute a universal perturbation as follows: 40 | 41 | ``` 42 | % Load data 43 | dataset = h5read(fullfile('data', 'ImageNet.h5'), ['/batch1']); 44 | % Set parameters 45 | opts.library = 'caffe' % or 'matconvnet'; 46 | opts.net = net; 47 | % Compute universal perturbation 48 | v = universal_perturbation(dataset, opts); 49 | ``` 50 | 51 | ##Reference 52 | [1] S. Moosavi-Dezfooli\*, A. Fawzi\*, O. Fawzi, P. Frossard: 53 | [*Universal adversarial perturbations*](http://arxiv.org/pdf/1610.08401), CVPR 2017. 54 | -------------------------------------------------------------------------------- /matlab/universal_perturbation.m: -------------------------------------------------------------------------------- 1 | %% 2 | % MATLAB code for Universal Perturbation 3 | % 4 | % universal_perturbation(dataset, varargin): 5 | % computes a universal perturbation for a Caffe's or MatConvNet's model 6 | % 7 | % INPUTS 8 | % dataset: images in W*H*C*N format 9 | % opts: A struct containing the following parameters: 10 | % delta: controls the desired fooling rate (default = 80% fooling rate) 11 | % MAX_ITER_UNIV: optional other termination criterion (maximum number of iteration, default = Inf) 12 | % xi: controls the l_p magnitude of the perturbation (default = 10) 13 | % p: norm to be used (FOR NOW, ONLY p = 2, and p = Inf ARE ACCEPTED!) (default = Inf) 14 | % df.labels_limit: DeepFool's labels_limit (limits the number of classes to test against, by default = 10) 15 | % df.overshoot: DeepFool's overshoot (used as a termination criterion to prevent vanishing updates, by default = 0.02) 16 | % df.MAX_ITER: DeepFool's MAX_ITER (maximum number of iterations for DeepFool , by default = 10) 17 | % 18 | % OUTPUT 19 | % v: universal perturbation 20 | % 21 | % S. Moosavi-Dezfooli, A. Fawzi, O.Fawzi, P. Frossard: Universal Adversarial Perturbations, arXiv:1610.08401. 22 | %% 23 | function v = universal_perturbation(dataset, varargin) 24 | 25 | %Options 26 | opts.delta=0.2; 27 | opts.MAX_ITER_UNIV = 10; 28 | opts.xi = 10; 29 | opts.p = Inf; 30 | opts.BATCH_SIZE = 100; 31 | opts.df.labels_limit=10; 32 | opts.df.overshoot=0.02; 33 | opts.df.MAX_ITER=10; 34 | opts.library = []; 35 | opts.net = []; 36 | 37 | opts = vl_argparse(opts, varargin); 38 | 39 | v = 0; 40 | fooling_rate = 0; 41 | num_images = size(dataset,4); 42 | 43 | if isempty(opts.net) % check the network 44 | fprintf('Please specify the network!\nopts.net = net'); 45 | return; 46 | end 47 | 48 | if(strcmp(opts.library,'caffe')) % check the framework: only Caffe and MatConvNet are supported. 49 | adversarial_DF = @(x) adversarial_DeepFool_caffe(x,opts.net,opts.df); 50 | predict = @(x)predict_caffe(x,opts.net,opts.BATCH_SIZE); 51 | elseif(strcmp(opts.library,'matconvnet')) 52 | adversarial_DF = @(x) adversarial_DeepFool_matconvnet(x,opts.net,opts.df); 53 | predict = @(x)predict_matconvnet(x,opts.net,opts.BATCH_SIZE); 54 | else 55 | fprintf('Library is not supported!\n'); 56 | return; 57 | end 58 | 59 | itr = 0; 60 | while(fooling_rate<(1-opts.delta) && itr 1 64 | error('There can be at most one option.') ; 65 | end 66 | 67 | optNames = fieldnames(opts)' ; 68 | 69 | % convert ARGS into a structure 70 | ai = 1 ; 71 | keep = false(size(args)) ; 72 | while ai <= numel(args) 73 | 74 | % Check whether the argument is a (param,value) pair or a structure. 75 | if recursive && isstruct(args{ai}) 76 | params = fieldnames(args{ai})' ; 77 | values = struct2cell(args{ai})' ; 78 | if nargout == 1 79 | opts = vl_argparse(opts, vertcat(params,values)) ; 80 | else 81 | [opts, rest] = vl_argparse(opts, reshape(vertcat(params,values), 1, [])) ; 82 | args{ai} = cell2struct(rest(2:2:end), rest(1:2:end), 2) ; 83 | keep(ai) = true ; 84 | end 85 | ai = ai + 1 ; 86 | continue ; 87 | end 88 | 89 | if ~isstr(args{ai}) 90 | error('Expected either a param-value pair or a structure.') ; 91 | end 92 | 93 | param = args{ai} ; 94 | value = args{ai+1} ; 95 | 96 | p = find(strcmpi(param, optNames)) ; 97 | if numel(p) ~= 1 98 | if nargout == 1 99 | error('Unknown parameter ''%s''', param) ; 100 | else 101 | keep([ai,ai+1]) = true ; 102 | ai = ai + 2 ; 103 | continue ; 104 | end 105 | end 106 | field = optNames{p} ; 107 | 108 | if ~recursive 109 | opts.(field) = value ; 110 | else 111 | if isstruct(opts.(field)) && numel(fieldnames(opts.(field))) > 0 112 | % The parameter has a non-empty struct value in OPTS: 113 | % process recursively. 114 | if ~isstruct(value) 115 | error('Cannot assign a non-struct value to the struct parameter ''%s''.', ... 116 | field) ; 117 | end 118 | if nargout > 1 119 | [opts.(field), args{ai+1}] = vl_argparse(opts.(field), value) ; 120 | else 121 | opts.(field) = vl_argparse(opts.(field), value) ; 122 | end 123 | else 124 | % The parameter does not have a struct value in OPTS: copy as is. 125 | opts.(field) = value ; 126 | end 127 | end 128 | 129 | ai = ai + 2 ; 130 | end 131 | 132 | args = args(keep) ; 133 | -------------------------------------------------------------------------------- /precomputed/CaffeNet.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/precomputed/CaffeNet.mat -------------------------------------------------------------------------------- /precomputed/GoogLeNet.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/precomputed/GoogLeNet.mat -------------------------------------------------------------------------------- /precomputed/README.md: -------------------------------------------------------------------------------- 1 | #Precomputed perturbations 2 | 3 | Precomputed universal perturbations for different classification models. 4 | 5 | Perturbations have a format `WxHxC`, where the channels are arranged in RGB format. 6 | ##Reference 7 | [1] S. Moosavi-Dezfooli\*, A. Fawzi\*, O. Fawzi, P. Frossard: 8 | [*Universal adversarial perturbations*](http://arxiv.org/pdf/1610.08401), CVPR 2017. 9 | -------------------------------------------------------------------------------- /precomputed/ResNet-152.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/precomputed/ResNet-152.mat -------------------------------------------------------------------------------- /precomputed/VGG-16.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/precomputed/VGG-16.mat -------------------------------------------------------------------------------- /precomputed/VGG-19.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/precomputed/VGG-19.mat -------------------------------------------------------------------------------- /precomputed/VGG-F.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/precomputed/VGG-F.mat -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # Python 2 | 3 | Python code to find a universal perturbation [[1]](http://arxiv.org/pdf/1610.08401), using the [TensorFlow](https://www.tensorflow.org/) library. 4 | 5 | ## Usage 6 | 7 | ### Get started 8 | 9 | To get started, you can run the demo code to apply a pre-computed universal perturbation for Inception on the image of your choice 10 | ``` 11 | python demo_inception.py -i data/test_img.png 12 | ``` 13 | This will download the pre-trained model, and show the image without and with universal perturbation with the estimated labels. 14 | In this example, the pre-computed universal perturbation in `data/universal.npy` is used. 15 | 16 | ### Computing a universal perturbation for your model 17 | 18 | To compute a universal perturbation for your model, please follow the same struture as in `demo_inception.py`. 19 | In particular, you should use the `universal_perturbation` function (see `universal_pert.py` for details), with the set of training images 20 | used to compute the perturbation, as well as the feedforward and gradient functions. 21 | 22 | ## Reference 23 | [1] S. Moosavi-Dezfooli\*, A. Fawzi\*, O. Fawzi, P. Frossard: 24 | [*Universal adversarial perturbations*](http://arxiv.org/pdf/1610.08401), CVPR 2017. 25 | -------------------------------------------------------------------------------- /python/data/labels.txt: -------------------------------------------------------------------------------- 1 | kit fox, Vulpes macrotis 2 | English setter 3 | Siberian husky 4 | Australian terrier 5 | English springer, English springer spaniel 6 | grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus 7 | lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens 8 | Egyptian cat 9 | ibex, Capra ibex 10 | Persian cat 11 | cougar, puma, catamount, mountain lion, painter, panther, Felis concolor 12 | gazelle 13 | porcupine, hedgehog 14 | sea lion 15 | malamute, malemute, Alaskan malamute 16 | badger 17 | Great Dane 18 | Walker hound, Walker foxhound 19 | Welsh springer spaniel 20 | whippet 21 | Scottish deerhound, deerhound 22 | killer whale, killer, orca, grampus, sea wolf, Orcinus orca 23 | mink 24 | African elephant, Loxodonta africana 25 | Weimaraner 26 | soft-coated wheaten terrier 27 | Dandie Dinmont, Dandie Dinmont terrier 28 | red wolf, maned wolf, Canis rufus, Canis niger 29 | Old English sheepdog, bobtail 30 | jaguar, panther, Panthera onca, Felis onca 31 | otterhound, otter hound 32 | bloodhound, sleuthhound 33 | Airedale, Airedale terrier 34 | hyena, hyaena 35 | meerkat, mierkat 36 | giant schnauzer 37 | titi, titi monkey 38 | three-toed sloth, ai, Bradypus tridactylus 39 | sorrel 40 | black-footed ferret, ferret, Mustela nigripes 41 | dalmatian, coach dog, carriage dog 42 | black-and-tan coonhound 43 | papillon 44 | skunk, polecat, wood pussy 45 | Staffordshire bullterrier, Staffordshire bull terrier 46 | Mexican hairless 47 | Bouvier des Flandres, Bouviers des Flandres 48 | weasel 49 | miniature poodle 50 | Cardigan, Cardigan Welsh corgi 51 | malinois 52 | bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis 53 | fox squirrel, eastern fox squirrel, Sciurus niger 54 | colobus, colobus monkey 55 | tiger cat 56 | Lhasa, Lhasa apso 57 | impala, Aepyceros melampus 58 | coyote, prairie wolf, brush wolf, Canis latrans 59 | Yorkshire terrier 60 | Newfoundland, Newfoundland dog 61 | brown bear, bruin, Ursus arctos 62 | red fox, Vulpes vulpes 63 | Norwegian elkhound, elkhound 64 | Rottweiler 65 | hartebeest 66 | Saluki, gazelle hound 67 | grey fox, gray fox, Urocyon cinereoargenteus 68 | schipperke 69 | Pekinese, Pekingese, Peke 70 | Brabancon griffon 71 | West Highland white terrier 72 | Sealyham terrier, Sealyham 73 | guenon, guenon monkey 74 | mongoose 75 | indri, indris, Indri indri, Indri brevicaudatus 76 | tiger, Panthera tigris 77 | Irish wolfhound 78 | wild boar, boar, Sus scrofa 79 | EntleBucher 80 | zebra 81 | ram, tup 82 | French bulldog 83 | orangutan, orang, orangutang, Pongo pygmaeus 84 | basenji 85 | leopard, Panthera pardus 86 | Bernese mountain dog 87 | Maltese dog, Maltese terrier, Maltese 88 | Norfolk terrier 89 | toy terrier 90 | vizsla, Hungarian pointer 91 | cairn, cairn terrier 92 | squirrel monkey, Saimiri sciureus 93 | groenendael 94 | clumber, clumber spaniel 95 | Siamese cat, Siamese 96 | chimpanzee, chimp, Pan troglodytes 97 | komondor 98 | Afghan hound, Afghan 99 | Japanese spaniel 100 | proboscis monkey, Nasalis larvatus 101 | guinea pig, Cavia cobaya 102 | white wolf, Arctic wolf, Canis lupus tundrarum 103 | ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus 104 | gorilla, Gorilla gorilla 105 | borzoi, Russian wolfhound 106 | toy poodle 107 | Kerry blue terrier 108 | ox 109 | Scotch terrier, Scottish terrier, Scottie 110 | Tibetan mastiff 111 | spider monkey, Ateles geoffroyi 112 | Doberman, Doberman pinscher 113 | Boston bull, Boston terrier 114 | Greater Swiss Mountain dog 115 | Appenzeller 116 | Shih-Tzu 117 | Irish water spaniel 118 | Pomeranian 119 | Bedlington terrier 120 | warthog 121 | Arabian camel, dromedary, Camelus dromedarius 122 | siamang, Hylobates syndactylus, Symphalangus syndactylus 123 | miniature schnauzer 124 | collie 125 | golden retriever 126 | Irish terrier 127 | affenpinscher, monkey pinscher, monkey dog 128 | Border collie 129 | hare 130 | boxer 131 | silky terrier, Sydney silky 132 | beagle 133 | Leonberg 134 | German short-haired pointer 135 | patas, hussar monkey, Erythrocebus patas 136 | dhole, Cuon alpinus 137 | baboon 138 | macaque 139 | Chesapeake Bay retriever 140 | bull mastiff 141 | kuvasz 142 | capuchin, ringtail, Cebus capucinus 143 | pug, pug-dog 144 | curly-coated retriever 145 | Norwich terrier 146 | flat-coated retriever 147 | hog, pig, grunter, squealer, Sus scrofa 148 | keeshond 149 | Eskimo dog, husky 150 | Brittany spaniel 151 | standard poodle 152 | Lakeland terrier 153 | snow leopard, ounce, Panthera uncia 154 | Gordon setter 155 | dingo, warrigal, warragal, Canis dingo 156 | standard schnauzer 157 | hamster 158 | Tibetan terrier, chrysanthemum dog 159 | Arctic fox, white fox, Alopex lagopus 160 | wire-haired fox terrier 161 | basset, basset hound 162 | water buffalo, water ox, Asiatic buffalo, Bubalus bubalis 163 | American black bear, black bear, Ursus americanus, Euarctos americanus 164 | Angora, Angora rabbit 165 | bison 166 | howler monkey, howler 167 | hippopotamus, hippo, river horse, Hippopotamus amphibius 168 | chow, chow chow 169 | giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca 170 | American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier 171 | Shetland sheepdog, Shetland sheep dog, Shetland 172 | Great Pyrenees 173 | Chihuahua 174 | tabby, tabby cat 175 | marmoset 176 | Labrador retriever 177 | Saint Bernard, St Bernard 178 | armadillo 179 | Samoyed, Samoyede 180 | bluetick 181 | redbone 182 | polecat, fitch, foulmart, foumart, Mustela putorius 183 | marmot 184 | kelpie 185 | gibbon, Hylobates lar 186 | llama 187 | miniature pinscher 188 | wood rabbit, cottontail, cottontail rabbit 189 | Italian greyhound 190 | lion, king of beasts, Panthera leo 191 | cocker spaniel, English cocker spaniel, cocker 192 | Irish setter, red setter 193 | dugong, Dugong dugon 194 | Indian elephant, Elephas maximus 195 | beaver 196 | Sussex spaniel 197 | Pembroke, Pembroke Welsh corgi 198 | Blenheim spaniel 199 | Madagascar cat, ring-tailed lemur, Lemur catta 200 | Rhodesian ridgeback 201 | lynx, catamount 202 | African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus 203 | langur 204 | Ibizan hound, Ibizan Podenco 205 | timber wolf, grey wolf, gray wolf, Canis lupus 206 | cheetah, chetah, Acinonyx jubatus 207 | English foxhound 208 | briard 209 | sloth bear, Melursus ursinus, Ursus ursinus 210 | Border terrier 211 | German shepherd, German shepherd dog, German police dog, alsatian 212 | otter 213 | koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus 214 | tusker 215 | echidna, spiny anteater, anteater 216 | wallaby, brush kangaroo 217 | platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus 218 | wombat 219 | revolver, six-gun, six-shooter 220 | umbrella 221 | schooner 222 | soccer ball 223 | accordion, piano accordion, squeeze box 224 | ant, emmet, pismire 225 | starfish, sea star 226 | chambered nautilus, pearly nautilus, nautilus 227 | grand piano, grand 228 | laptop, laptop computer 229 | strawberry 230 | airliner 231 | warplane, military plane 232 | airship, dirigible 233 | balloon 234 | space shuttle 235 | fireboat 236 | gondola 237 | speedboat 238 | lifeboat 239 | canoe 240 | yawl 241 | catamaran 242 | trimaran 243 | container ship, containership, container vessel 244 | liner, ocean liner 245 | pirate, pirate ship 246 | aircraft carrier, carrier, flattop, attack aircraft carrier 247 | submarine, pigboat, sub, U-boat 248 | wreck 249 | half track 250 | tank, army tank, armored combat vehicle, armoured combat vehicle 251 | missile 252 | bobsled, bobsleigh, bob 253 | dogsled, dog sled, dog sleigh 254 | bicycle-built-for-two, tandem bicycle, tandem 255 | mountain bike, all-terrain bike, off-roader 256 | freight car 257 | passenger car, coach, carriage 258 | barrow, garden cart, lawn cart, wheelbarrow 259 | shopping cart 260 | motor scooter, scooter 261 | forklift 262 | electric locomotive 263 | steam locomotive 264 | amphibian, amphibious vehicle 265 | ambulance 266 | beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon 267 | cab, hack, taxi, taxicab 268 | convertible 269 | jeep, landrover 270 | limousine, limo 271 | minivan 272 | Model T 273 | racer, race car, racing car 274 | sports car, sport car 275 | go-kart 276 | golfcart, golf cart 277 | moped 278 | snowplow, snowplough 279 | fire engine, fire truck 280 | garbage truck, dustcart 281 | pickup, pickup truck 282 | tow truck, tow car, wrecker 283 | trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi 284 | moving van 285 | police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria 286 | recreational vehicle, RV, R.V. 287 | streetcar, tram, tramcar, trolley, trolley car 288 | snowmobile 289 | tractor 290 | mobile home, manufactured home 291 | tricycle, trike, velocipede 292 | unicycle, monocycle 293 | horse cart, horse-cart 294 | jinrikisha, ricksha, rickshaw 295 | oxcart 296 | bassinet 297 | cradle 298 | crib, cot 299 | four-poster 300 | bookcase 301 | china cabinet, china closet 302 | medicine chest, medicine cabinet 303 | chiffonier, commode 304 | table lamp 305 | file, file cabinet, filing cabinet 306 | park bench 307 | barber chair 308 | throne 309 | folding chair 310 | rocking chair, rocker 311 | studio couch, day bed 312 | toilet seat 313 | desk 314 | pool table, billiard table, snooker table 315 | dining table, board 316 | entertainment center 317 | wardrobe, closet, press 318 | Granny Smith 319 | orange 320 | lemon 321 | fig 322 | pineapple, ananas 323 | banana 324 | jackfruit, jak, jack 325 | custard apple 326 | pomegranate 327 | acorn 328 | hip, rose hip, rosehip 329 | ear, spike, capitulum 330 | rapeseed 331 | corn 332 | buckeye, horse chestnut, conker 333 | organ, pipe organ 334 | upright, upright piano 335 | chime, bell, gong 336 | drum, membranophone, tympan 337 | gong, tam-tam 338 | maraca 339 | marimba, xylophone 340 | steel drum 341 | banjo 342 | cello, violoncello 343 | violin, fiddle 344 | harp 345 | acoustic guitar 346 | electric guitar 347 | cornet, horn, trumpet, trump 348 | French horn, horn 349 | trombone 350 | harmonica, mouth organ, harp, mouth harp 351 | ocarina, sweet potato 352 | panpipe, pandean pipe, syrinx 353 | bassoon 354 | oboe, hautboy, hautbois 355 | sax, saxophone 356 | flute, transverse flute 357 | daisy 358 | yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum 359 | cliff, drop, drop-off 360 | valley, vale 361 | alp 362 | volcano 363 | promontory, headland, head, foreland 364 | sandbar, sand bar 365 | coral reef 366 | lakeside, lakeshore 367 | seashore, coast, seacoast, sea-coast 368 | geyser 369 | hatchet 370 | cleaver, meat cleaver, chopper 371 | letter opener, paper knife, paperknife 372 | plane, carpenter's plane, woodworking plane 373 | power drill 374 | lawn mower, mower 375 | hammer 376 | corkscrew, bottle screw 377 | can opener, tin opener 378 | plunger, plumber's helper 379 | screwdriver 380 | shovel 381 | plow, plough 382 | chain saw, chainsaw 383 | cock 384 | hen 385 | ostrich, Struthio camelus 386 | brambling, Fringilla montifringilla 387 | goldfinch, Carduelis carduelis 388 | house finch, linnet, Carpodacus mexicanus 389 | junco, snowbird 390 | indigo bunting, indigo finch, indigo bird, Passerina cyanea 391 | robin, American robin, Turdus migratorius 392 | bulbul 393 | jay 394 | magpie 395 | chickadee 396 | water ouzel, dipper 397 | kite 398 | bald eagle, American eagle, Haliaeetus leucocephalus 399 | vulture 400 | great grey owl, great gray owl, Strix nebulosa 401 | black grouse 402 | ptarmigan 403 | ruffed grouse, partridge, Bonasa umbellus 404 | prairie chicken, prairie grouse, prairie fowl 405 | peacock 406 | quail 407 | partridge 408 | African grey, African gray, Psittacus erithacus 409 | macaw 410 | sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita 411 | lorikeet 412 | coucal 413 | bee eater 414 | hornbill 415 | hummingbird 416 | jacamar 417 | toucan 418 | drake 419 | red-breasted merganser, Mergus serrator 420 | goose 421 | black swan, Cygnus atratus 422 | white stork, Ciconia ciconia 423 | black stork, Ciconia nigra 424 | spoonbill 425 | flamingo 426 | American egret, great white heron, Egretta albus 427 | little blue heron, Egretta caerulea 428 | bittern 429 | crane 430 | limpkin, Aramus pictus 431 | American coot, marsh hen, mud hen, water hen, Fulica americana 432 | bustard 433 | ruddy turnstone, Arenaria interpres 434 | red-backed sandpiper, dunlin, Erolia alpina 435 | redshank, Tringa totanus 436 | dowitcher 437 | oystercatcher, oyster catcher 438 | European gallinule, Porphyrio porphyrio 439 | pelican 440 | king penguin, Aptenodytes patagonica 441 | albatross, mollymawk 442 | great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias 443 | tiger shark, Galeocerdo cuvieri 444 | hammerhead, hammerhead shark 445 | electric ray, crampfish, numbfish, torpedo 446 | stingray 447 | barracouta, snoek 448 | coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch 449 | tench, Tinca tinca 450 | goldfish, Carassius auratus 451 | eel 452 | rock beauty, Holocanthus tricolor 453 | anemone fish 454 | lionfish 455 | puffer, pufferfish, blowfish, globefish 456 | sturgeon 457 | gar, garfish, garpike, billfish, Lepisosteus osseus 458 | loggerhead, loggerhead turtle, Caretta caretta 459 | leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea 460 | mud turtle 461 | terrapin 462 | box turtle, box tortoise 463 | banded gecko 464 | common iguana, iguana, Iguana iguana 465 | American chameleon, anole, Anolis carolinensis 466 | whiptail, whiptail lizard 467 | agama 468 | frilled lizard, Chlamydosaurus kingi 469 | alligator lizard 470 | Gila monster, Heloderma suspectum 471 | green lizard, Lacerta viridis 472 | African chameleon, Chamaeleo chamaeleon 473 | Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis 474 | triceratops 475 | African crocodile, Nile crocodile, Crocodylus niloticus 476 | American alligator, Alligator mississipiensis 477 | thunder snake, worm snake, Carphophis amoenus 478 | ringneck snake, ring-necked snake, ring snake 479 | hognose snake, puff adder, sand viper 480 | green snake, grass snake 481 | king snake, kingsnake 482 | garter snake, grass snake 483 | water snake 484 | vine snake 485 | night snake, Hypsiglena torquata 486 | boa constrictor, Constrictor constrictor 487 | rock python, rock snake, Python sebae 488 | Indian cobra, Naja naja 489 | green mamba 490 | sea snake 491 | horned viper, cerastes, sand viper, horned asp, Cerastes cornutus 492 | diamondback, diamondback rattlesnake, Crotalus adamanteus 493 | sidewinder, horned rattlesnake, Crotalus cerastes 494 | European fire salamander, Salamandra salamandra 495 | common newt, Triturus vulgaris 496 | eft 497 | spotted salamander, Ambystoma maculatum 498 | axolotl, mud puppy, Ambystoma mexicanum 499 | bullfrog, Rana catesbeiana 500 | tree frog, tree-frog 501 | tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui 502 | whistle 503 | wing 504 | paintbrush 505 | hand blower, blow dryer, blow drier, hair dryer, hair drier 506 | oxygen mask 507 | snorkel 508 | loudspeaker, speaker, speaker unit, loudspeaker system, speaker system 509 | microphone, mike 510 | screen, CRT screen 511 | mouse, computer mouse 512 | electric fan, blower 513 | oil filter 514 | strainer 515 | space heater 516 | stove 517 | guillotine 518 | barometer 519 | rule, ruler 520 | odometer, hodometer, mileometer, milometer 521 | scale, weighing machine 522 | analog clock 523 | digital clock 524 | wall clock 525 | hourglass 526 | sundial 527 | parking meter 528 | stopwatch, stop watch 529 | digital watch 530 | stethoscope 531 | syringe 532 | magnetic compass 533 | binoculars, field glasses, opera glasses 534 | projector 535 | sunglasses, dark glasses, shades 536 | loupe, jeweler's loupe 537 | radio telescope, radio reflector 538 | bow 539 | cannon 540 | assault rifle, assault gun 541 | rifle 542 | projectile, missile 543 | computer keyboard, keypad 544 | typewriter keyboard 545 | crane 546 | lighter, light, igniter, ignitor 547 | abacus 548 | cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM 549 | slide rule, slipstick 550 | desktop computer 551 | hand-held computer, hand-held microcomputer 552 | notebook, notebook computer 553 | web site, website, internet site, site 554 | harvester, reaper 555 | thresher, thrasher, threshing machine 556 | printer 557 | slot, one-armed bandit 558 | vending machine 559 | sewing machine 560 | joystick 561 | switch, electric switch, electrical switch 562 | hook, claw 563 | car wheel 564 | paddlewheel, paddle wheel 565 | pinwheel 566 | potter's wheel 567 | gas pump, gasoline pump, petrol pump, island dispenser 568 | carousel, carrousel, merry-go-round, roundabout, whirligig 569 | swing 570 | reel 571 | radiator 572 | puck, hockey puck 573 | hard disc, hard disk, fixed disk 574 | sunglass 575 | pick, plectrum, plectron 576 | car mirror 577 | solar dish, solar collector, solar furnace 578 | remote control, remote 579 | disk brake, disc brake 580 | buckle 581 | hair slide 582 | knot 583 | combination lock 584 | padlock 585 | nail 586 | safety pin 587 | screw 588 | muzzle 589 | seat belt, seatbelt 590 | ski 591 | candle, taper, wax light 592 | jack-o'-lantern 593 | spotlight, spot 594 | torch 595 | neck brace 596 | pier 597 | tripod 598 | maypole 599 | mousetrap 600 | spider web, spider's web 601 | trilobite 602 | harvestman, daddy longlegs, Phalangium opilio 603 | scorpion 604 | black and gold garden spider, Argiope aurantia 605 | barn spider, Araneus cavaticus 606 | garden spider, Aranea diademata 607 | black widow, Latrodectus mactans 608 | tarantula 609 | wolf spider, hunting spider 610 | tick 611 | centipede 612 | isopod 613 | Dungeness crab, Cancer magister 614 | rock crab, Cancer irroratus 615 | fiddler crab 616 | king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica 617 | American lobster, Northern lobster, Maine lobster, Homarus americanus 618 | spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish 619 | crayfish, crawfish, crawdad, crawdaddy 620 | hermit crab 621 | tiger beetle 622 | ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle 623 | ground beetle, carabid beetle 624 | long-horned beetle, longicorn, longicorn beetle 625 | leaf beetle, chrysomelid 626 | dung beetle 627 | rhinoceros beetle 628 | weevil 629 | fly 630 | bee 631 | grasshopper, hopper 632 | cricket 633 | walking stick, walkingstick, stick insect 634 | cockroach, roach 635 | mantis, mantid 636 | cicada, cicala 637 | leafhopper 638 | lacewing, lacewing fly 639 | dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk 640 | damselfly 641 | admiral 642 | ringlet, ringlet butterfly 643 | monarch, monarch butterfly, milkweed butterfly, Danaus plexippus 644 | cabbage butterfly 645 | sulphur butterfly, sulfur butterfly 646 | lycaenid, lycaenid butterfly 647 | jellyfish 648 | sea anemone, anemone 649 | brain coral 650 | flatworm, platyhelminth 651 | nematode, nematode worm, roundworm 652 | conch 653 | snail 654 | slug 655 | sea slug, nudibranch 656 | chiton, coat-of-mail shell, sea cradle, polyplacophore 657 | sea urchin 658 | sea cucumber, holothurian 659 | iron, smoothing iron 660 | espresso maker 661 | microwave, microwave oven 662 | Dutch oven 663 | rotisserie 664 | toaster 665 | waffle iron 666 | vacuum, vacuum cleaner 667 | dishwasher, dish washer, dishwashing machine 668 | refrigerator, icebox 669 | washer, automatic washer, washing machine 670 | Crock Pot 671 | frying pan, frypan, skillet 672 | wok 673 | caldron, cauldron 674 | coffeepot 675 | teapot 676 | spatula 677 | altar 678 | triumphal arch 679 | patio, terrace 680 | steel arch bridge 681 | suspension bridge 682 | viaduct 683 | barn 684 | greenhouse, nursery, glasshouse 685 | palace 686 | monastery 687 | library 688 | apiary, bee house 689 | boathouse 690 | church, church building 691 | mosque 692 | stupa, tope 693 | planetarium 694 | restaurant, eating house, eating place, eatery 695 | cinema, movie theater, movie theatre, movie house, picture palace 696 | home theater, home theatre 697 | lumbermill, sawmill 698 | coil, spiral, volute, whorl, helix 699 | obelisk 700 | totem pole 701 | castle 702 | prison, prison house 703 | grocery store, grocery, food market, market 704 | bakery, bakeshop, bakehouse 705 | barbershop 706 | bookshop, bookstore, bookstall 707 | butcher shop, meat market 708 | confectionery, confectionary, candy store 709 | shoe shop, shoe-shop, shoe store 710 | tobacco shop, tobacconist shop, tobacconist 711 | toyshop 712 | fountain 713 | cliff dwelling 714 | yurt 715 | dock, dockage, docking facility 716 | brass, memorial tablet, plaque 717 | megalith, megalithic structure 718 | bannister, banister, balustrade, balusters, handrail 719 | breakwater, groin, groyne, mole, bulwark, seawall, jetty 720 | dam, dike, dyke 721 | chainlink fence 722 | picket fence, paling 723 | worm fence, snake fence, snake-rail fence, Virginia fence 724 | stone wall 725 | grille, radiator grille 726 | sliding door 727 | turnstile 728 | mountain tent 729 | scoreboard 730 | honeycomb 731 | plate rack 732 | pedestal, plinth, footstall 733 | beacon, lighthouse, beacon light, pharos 734 | mashed potato 735 | bell pepper 736 | head cabbage 737 | broccoli 738 | cauliflower 739 | zucchini, courgette 740 | spaghetti squash 741 | acorn squash 742 | butternut squash 743 | cucumber, cuke 744 | artichoke, globe artichoke 745 | cardoon 746 | mushroom 747 | shower curtain 748 | jean, blue jean, denim 749 | carton 750 | handkerchief, hankie, hanky, hankey 751 | sandal 752 | ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin 753 | safe 754 | plate 755 | necklace 756 | croquet ball 757 | fur coat 758 | thimble 759 | pajama, pyjama, pj's, jammies 760 | running shoe 761 | cocktail shaker 762 | chest 763 | manhole cover 764 | modem 765 | tub, vat 766 | tray 767 | balance beam, beam 768 | bagel, beigel 769 | prayer rug, prayer mat 770 | kimono 771 | hot pot, hotpot 772 | whiskey jug 773 | knee pad 774 | book jacket, dust cover, dust jacket, dust wrapper 775 | spindle 776 | ski mask 777 | beer bottle 778 | crash helmet 779 | bottlecap 780 | tile roof 781 | mask 782 | maillot 783 | Petri dish 784 | football helmet 785 | bathing cap, swimming cap 786 | teddy, teddy bear 787 | holster 788 | pop bottle, soda bottle 789 | photocopier 790 | vestment 791 | crossword puzzle, crossword 792 | golf ball 793 | trifle 794 | suit, suit of clothes 795 | water tower 796 | feather boa, boa 797 | cloak 798 | red wine 799 | drumstick 800 | shield, buckler 801 | Christmas stocking 802 | hoopskirt, crinoline 803 | menu 804 | stage 805 | bonnet, poke bonnet 806 | meat loaf, meatloaf 807 | baseball 808 | face powder 809 | scabbard 810 | sunscreen, sunblock, sun blocker 811 | beer glass 812 | hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa 813 | guacamole 814 | lampshade, lamp shade 815 | wool, woolen, woollen 816 | hay 817 | bow tie, bow-tie, bowtie 818 | mailbag, postbag 819 | water jug 820 | bucket, pail 821 | dishrag, dishcloth 822 | soup bowl 823 | eggnog 824 | mortar 825 | trench coat 826 | paddle, boat paddle 827 | chain 828 | swab, swob, mop 829 | mixing bowl 830 | potpie 831 | wine bottle 832 | shoji 833 | bulletproof vest 834 | drilling platform, offshore rig 835 | binder, ring-binder 836 | cardigan 837 | sweatshirt 838 | pot, flowerpot 839 | birdhouse 840 | hamper 841 | ping-pong ball 842 | pencil box, pencil case 843 | pay-phone, pay-station 844 | consomme 845 | apron 846 | punching bag, punch bag, punching ball, punchball 847 | backpack, back pack, knapsack, packsack, rucksack, haversack 848 | groom, bridegroom 849 | bearskin, busby, shako 850 | pencil sharpener 851 | broom 852 | mosquito net 853 | abaya 854 | mortarboard 855 | poncho 856 | crutch 857 | Polaroid camera, Polaroid Land camera 858 | space bar 859 | cup 860 | racket, racquet 861 | traffic light, traffic signal, stoplight 862 | quill, quill pen 863 | radio, wireless 864 | dough 865 | cuirass 866 | military uniform 867 | lipstick, lip rouge 868 | shower cap 869 | monitor 870 | oscilloscope, scope, cathode-ray oscilloscope, CRO 871 | mitten 872 | brassiere, bra, bandeau 873 | French loaf 874 | vase 875 | milk can 876 | rugby ball 877 | paper towel 878 | earthstar 879 | envelope 880 | miniskirt, mini 881 | cowboy hat, ten-gallon hat 882 | trolleybus, trolley coach, trackless trolley 883 | perfume, essence 884 | bathtub, bathing tub, bath, tub 885 | hotdog, hot dog, red hot 886 | coral fungus 887 | bullet train, bullet 888 | pillow 889 | toilet tissue, toilet paper, bathroom tissue 890 | cassette 891 | carpenter's kit, tool kit 892 | ladle 893 | stinkhorn, carrion fungus 894 | lotion 895 | hair spray 896 | academic gown, academic robe, judge's robe 897 | dome 898 | crate 899 | wig 900 | burrito 901 | pill bottle 902 | chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour 903 | theater curtain, theatre curtain 904 | window shade 905 | barrel, cask 906 | washbasin, handbasin, washbowl, lavabo, wash-hand basin 907 | ballpoint, ballpoint pen, ballpen, Biro 908 | basketball 909 | bath towel 910 | cowboy boot 911 | gown 912 | window screen 913 | agaric 914 | cellular telephone, cellular phone, cellphone, cell, mobile phone 915 | nipple 916 | barbell 917 | mailbox, letter box 918 | lab coat, laboratory coat 919 | fire screen, fireguard 920 | minibus 921 | packet 922 | maze, labyrinth 923 | pole 924 | horizontal bar, high bar 925 | sombrero 926 | pickelhaube 927 | rain barrel 928 | wallet, billfold, notecase, pocketbook 929 | cassette player 930 | comic book 931 | piggy bank, penny bank 932 | street sign 933 | bell cote, bell cot 934 | fountain pen 935 | Windsor tie 936 | volleyball 937 | overskirt 938 | sarong 939 | purse 940 | bolo tie, bolo, bola tie, bola 941 | bib 942 | parachute, chute 943 | sleeping bag 944 | television, television system 945 | swimming trunks, bathing trunks 946 | measuring cup 947 | espresso 948 | pizza, pizza pie 949 | breastplate, aegis, egis 950 | shopping basket 951 | wooden spoon 952 | saltshaker, salt shaker 953 | chocolate sauce, chocolate syrup 954 | ballplayer, baseball player 955 | goblet 956 | gyromitra 957 | stretcher 958 | water bottle 959 | dial telephone, dial phone 960 | soap dispenser 961 | jersey, T-shirt, tee shirt 962 | school bus 963 | jigsaw puzzle 964 | plastic bag 965 | reflex camera 966 | diaper, nappy, napkin 967 | Band Aid 968 | ice lolly, lolly, lollipop, popsicle 969 | velvet 970 | tennis ball 971 | gasmask, respirator, gas helmet 972 | doormat, welcome mat 973 | Loafer 974 | ice cream, icecream 975 | pretzel 976 | quilt, comforter, comfort, puff 977 | maillot, tank suit 978 | tape player 979 | clog, geta, patten, sabot 980 | iPod 981 | bolete 982 | scuba diver 983 | pitcher, ewer 984 | matchstick 985 | bikini, two-piece 986 | sock 987 | CD player 988 | lens cap, lens cover 989 | thatch, thatched roof 990 | vault 991 | beaker 992 | bubble 993 | cheeseburger 994 | parallel bars, bars 995 | flagpole, flagstaff 996 | coffee mug 997 | rubber eraser, rubber, pencil eraser 998 | stole 999 | carbonara 1000 | dumbbell 1001 | -------------------------------------------------------------------------------- /python/data/test_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/python/data/test_img.png -------------------------------------------------------------------------------- /python/data/universal.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LTS4/universal/2e5ab1544a5c0ea53f07b6c21dbecb6053bb1ca1/python/data/universal.npy -------------------------------------------------------------------------------- /python/deepfool.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def deepfool(image, f, grads, num_classes=10, overshoot=0.02, max_iter=50): 4 | 5 | """ 6 | :param image: Image of size HxWx3 7 | :param f: feedforward function (input: images, output: values of activation BEFORE softmax). 8 | :param grads: gradient functions with respect to input (as many gradients as classes). 9 | :param num_classes: num_classes (limits the number of classes to test against, by default = 10) 10 | :param overshoot: used as a termination criterion to prevent vanishing updates (default = 0.02). 11 | :param max_iter: maximum number of iterations for deepfool (default = 10) 12 | :return: minimal perturbation that fools the classifier, number of iterations that it required, new estimated_label and perturbed image 13 | """ 14 | 15 | f_image = np.array(f(image)).flatten() 16 | I = (np.array(f_image)).flatten().argsort()[::-1] 17 | 18 | I = I[0:num_classes] 19 | label = I[0] 20 | 21 | input_shape = image.shape 22 | pert_image = image 23 | 24 | f_i = np.array(f(pert_image)).flatten() 25 | k_i = int(np.argmax(f_i)) 26 | 27 | w = np.zeros(input_shape) 28 | r_tot = np.zeros(input_shape) 29 | 30 | loop_i = 0 31 | 32 | while k_i == label and loop_i < max_iter: 33 | 34 | pert = np.inf 35 | gradients = np.asarray(grads(pert_image,I)) 36 | 37 | for k in range(1, num_classes): 38 | 39 | # set new w_k and new f_k 40 | w_k = gradients[k, :, :, :, :] - gradients[0, :, :, :, :] 41 | f_k = f_i[I[k]] - f_i[I[0]] 42 | pert_k = abs(f_k)/np.linalg.norm(w_k.flatten()) 43 | 44 | # determine which w_k to use 45 | if pert_k < pert: 46 | pert = pert_k 47 | w = w_k 48 | 49 | # compute r_i and r_tot 50 | r_i = pert * w / np.linalg.norm(w) 51 | r_tot = r_tot + r_i 52 | 53 | # compute new perturbed image 54 | pert_image = image + (1+overshoot)*r_tot 55 | loop_i += 1 56 | 57 | # compute new label 58 | f_i = np.array(f(pert_image)).flatten() 59 | k_i = int(np.argmax(f_i)) 60 | 61 | r_tot = (1+overshoot)*r_tot 62 | 63 | return r_tot, loop_i, k_i, pert_image 64 | -------------------------------------------------------------------------------- /python/demo_inception.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | from tensorflow.python.platform import gfile 4 | import os.path 5 | from prepare_imagenet_data import preprocess_image_batch, create_imagenet_npy, undo_image_avg 6 | import matplotlib.pyplot as plt 7 | import sys, getopt 8 | import zipfile 9 | from timeit import time 10 | 11 | if sys.version_info[0] >= 3: 12 | from urllib.request import urlretrieve 13 | else: 14 | from urllib import urlretrieve 15 | 16 | 17 | from universal_pert import universal_perturbation 18 | device = '/gpu:0' 19 | num_classes = 10 20 | 21 | def jacobian(y_flat, x, inds): 22 | n = num_classes # Not really necessary, just a quick fix. 23 | loop_vars = [ 24 | tf.constant(0, tf.int32), 25 | tf.TensorArray(tf.float32, size=n), 26 | ] 27 | _, jacobian = tf.while_loop( 28 | lambda j,_: j < n, 29 | lambda j,result: (j+1, result.write(j, tf.gradients(y_flat[inds[j]], x))), 30 | loop_vars) 31 | return jacobian.stack() 32 | 33 | if __name__ == '__main__': 34 | 35 | # Parse arguments 36 | argv = sys.argv[1:] 37 | 38 | # Default values 39 | path_train_imagenet = '/datasets2/ILSVRC2012/train' 40 | path_test_image = 'data/test_img.png' 41 | 42 | try: 43 | opts, args = getopt.getopt(argv,"i:t:",["test_image=","training_path="]) 44 | except getopt.GetoptError: 45 | print ('python ' + sys.argv[0] + ' -i -t ') 46 | sys.exit(2) 47 | 48 | for opt, arg in opts: 49 | if opt == '-t': 50 | path_train_imagenet = arg 51 | if opt == '-i': 52 | path_test_image = arg 53 | 54 | with tf.device(device): 55 | persisted_sess = tf.Session() 56 | inception_model_path = os.path.join('data', 'tensorflow_inception_graph.pb') 57 | 58 | if os.path.isfile(inception_model_path) == 0: 59 | print('Downloading Inception model...') 60 | urlretrieve ("https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip", os.path.join('data', 'inception5h.zip')) 61 | # Unzipping the file 62 | zip_ref = zipfile.ZipFile(os.path.join('data', 'inception5h.zip'), 'r') 63 | zip_ref.extract('tensorflow_inception_graph.pb', 'data') 64 | zip_ref.close() 65 | 66 | model = os.path.join(inception_model_path) 67 | 68 | # Load the Inception model 69 | with gfile.FastGFile(model, 'rb') as f: 70 | graph_def = tf.GraphDef() 71 | graph_def.ParseFromString(f.read()) 72 | persisted_sess.graph.as_default() 73 | tf.import_graph_def(graph_def, name='') 74 | 75 | persisted_sess.graph.get_operations() 76 | 77 | persisted_input = persisted_sess.graph.get_tensor_by_name("input:0") 78 | persisted_output = persisted_sess.graph.get_tensor_by_name("softmax2_pre_activation:0") 79 | 80 | print('>> Computing feedforward function...') 81 | def f(image_inp): return persisted_sess.run(persisted_output, feed_dict={persisted_input: np.reshape(image_inp, (-1, 224, 224, 3))}) 82 | 83 | file_perturbation = os.path.join('data', 'universal.npy') 84 | 85 | if os.path.isfile(file_perturbation) == 0: 86 | 87 | # TODO: Optimize this construction part! 88 | print('>> Compiling the gradient tensorflow functions. This might take some time...') 89 | y_flat = tf.reshape(persisted_output, (-1,)) 90 | inds = tf.placeholder(tf.int32, shape=(num_classes,)) 91 | dydx = jacobian(y_flat,persisted_input,inds) 92 | 93 | print('>> Computing gradient function...') 94 | def grad_fs(image_inp, indices): return persisted_sess.run(dydx, feed_dict={persisted_input: image_inp, inds: indices}).squeeze(axis=1) 95 | 96 | # Load/Create data 97 | datafile = os.path.join('data', 'imagenet_data.npy') 98 | if os.path.isfile(datafile) == 0: 99 | print('>> Creating pre-processed imagenet data...') 100 | X = create_imagenet_npy(path_train_imagenet) 101 | 102 | print('>> Saving the pre-processed imagenet data') 103 | if not os.path.exists('data'): 104 | os.makedirs('data') 105 | 106 | # Save the pre-processed images 107 | # Caution: This can take take a lot of space. Comment this part to discard saving. 108 | np.save(os.path.join('data', 'imagenet_data.npy'), X) 109 | 110 | else: 111 | print('>> Pre-processed imagenet data detected') 112 | X = np.load(datafile) 113 | 114 | # Running universal perturbation 115 | v = universal_perturbation(X, f, grad_fs, delta=0.2,num_classes=num_classes) 116 | 117 | # Saving the universal perturbation 118 | np.save(os.path.join(file_perturbation), v) 119 | 120 | else: 121 | print('>> Found a pre-computed universal perturbation! Retrieving it from ", file_perturbation') 122 | v = np.load(file_perturbation) 123 | 124 | print('>> Testing the universal perturbation on an image') 125 | 126 | # Test the perturbation on the image 127 | labels = open(os.path.join('data', 'labels.txt'), 'r').read().split('\n') 128 | 129 | image_original = preprocess_image_batch([path_test_image], img_size=(256, 256), crop_size=(224, 224), color_mode="rgb") 130 | label_original = np.argmax(f(image_original), axis=1).flatten() 131 | str_label_original = labels[np.int(label_original)-1].split(',')[0] 132 | 133 | # Clip the perturbation to make sure images fit in uint8 134 | clipped_v = np.clip(undo_image_avg(image_original[0,:,:,:]+v[0,:,:,:]), 0, 255) - np.clip(undo_image_avg(image_original[0,:,:,:]), 0, 255) 135 | 136 | image_perturbed = image_original + clipped_v[None, :, :, :] 137 | label_perturbed = np.argmax(f(image_perturbed), axis=1).flatten() 138 | str_label_perturbed = labels[np.int(label_perturbed)-1].split(',')[0] 139 | 140 | # Show original and perturbed image 141 | plt.figure() 142 | plt.subplot(1, 2, 1) 143 | plt.imshow(undo_image_avg(image_original[0, :, :, :]).astype(dtype='uint8'), interpolation=None) 144 | plt.title(str_label_original) 145 | 146 | plt.subplot(1, 2, 2) 147 | plt.imshow(undo_image_avg(image_perturbed[0, :, :, :]).astype(dtype='uint8'), interpolation=None) 148 | plt.title(str_label_perturbed) 149 | 150 | plt.show() 151 | -------------------------------------------------------------------------------- /python/prepare_imagenet_data.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import os 3 | from scipy.misc import imread, imresize 4 | 5 | CLASS_INDEX = None 6 | CLASS_INDEX_PATH = 'https://s3.amazonaws.com/deep-learning-models/image-models/imagenet_class_index.json' 7 | 8 | 9 | def preprocess_image_batch(image_paths, img_size=None, crop_size=None, color_mode="rgb", out=None): 10 | img_list = [] 11 | 12 | for im_path in image_paths: 13 | img = imread(im_path, mode='RGB') 14 | if img_size: 15 | img = imresize(img,img_size) 16 | 17 | img = img.astype('float32') 18 | # We normalize the colors (in RGB space) with the empirical means on the training set 19 | img[:, :, 0] -= 123.68 20 | img[:, :, 1] -= 116.779 21 | img[:, :, 2] -= 103.939 22 | # We permute the colors to get them in the BGR order 23 | # if color_mode=="bgr": 24 | # img[:,:,[0,1,2]] = img[:,:,[2,1,0]] 25 | 26 | if crop_size: 27 | img = img[(img_size[0] - crop_size[0]) // 2:(img_size[0] + crop_size[0]) // 2, (img_size[1]-crop_size[1])//2:(img_size[1]+crop_size[1])//2, :]; 28 | 29 | img_list.append(img) 30 | 31 | try: 32 | img_batch = np.stack(img_list, axis=0) 33 | except: 34 | raise ValueError('when img_size and crop_size are None, images' 35 | ' in image_paths must have the same shapes.') 36 | 37 | if out is not None and hasattr(out, 'append'): 38 | out.append(img_batch) 39 | else: 40 | return img_batch 41 | 42 | def undo_image_avg(img): 43 | img_copy = np.copy(img) 44 | img_copy[:, :, 0] = img_copy[:, :, 0] + 123.68 45 | img_copy[:, :, 1] = img_copy[:, :, 1] + 116.779 46 | img_copy[:, :, 2] = img_copy[:, :, 2] + 103.939 47 | return img_copy 48 | 49 | def create_imagenet_npy(path_train_imagenet, len_batch=10000): 50 | 51 | # path_train_imagenet = '/datasets2/ILSVRC2012/train'; 52 | 53 | sz_img = [224, 224] 54 | num_channels = 3 55 | num_classes = 1000 56 | 57 | im_array = np.zeros([len_batch] + sz_img + [num_channels], dtype=np.float32) 58 | num_imgs_per_batch = int(len_batch / num_classes) 59 | 60 | dirs = [x[0] for x in os.walk(path_train_imagenet)] 61 | dirs = dirs[1:] 62 | 63 | # Sort the directory in alphabetical order (same as synset_words.txt) 64 | dirs = sorted(dirs) 65 | 66 | it = 0 67 | Matrix = [0 for x in range(1000)] 68 | 69 | for d in dirs: 70 | for _, _, filename in os.walk(os.path.join(path_train_imagenet, d)): 71 | Matrix[it] = filename 72 | it = it+1 73 | 74 | 75 | it = 0 76 | # Load images, pre-process, and save 77 | for k in range(num_classes): 78 | for u in range(num_imgs_per_batch): 79 | print('Processing image number ', it) 80 | path_img = os.path.join(dirs[k], Matrix[k][u]) 81 | image = preprocess_image_batch([path_img],img_size=(256,256), crop_size=(224,224), color_mode="rgb") 82 | im_array[it:(it+1), :, :, :] = image 83 | it = it + 1 84 | 85 | return im_array 86 | -------------------------------------------------------------------------------- /python/universal_pert.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from deepfool import deepfool 3 | 4 | def proj_lp(v, xi, p): 5 | 6 | # Project on the lp ball centered at 0 and of radius xi 7 | 8 | # SUPPORTS only p = 2 and p = Inf for now 9 | if p == 2: 10 | v = v * min(1, xi/np.linalg.norm(v.flatten(1))) 11 | # v = v / np.linalg.norm(v.flatten(1)) * xi 12 | elif p == np.inf: 13 | v = np.sign(v) * np.minimum(abs(v), xi) 14 | else: 15 | raise ValueError('Values of p different from 2 and Inf are currently not supported...') 16 | 17 | return v 18 | 19 | def universal_perturbation(dataset, f, grads, delta=0.2, max_iter_uni = np.inf, xi=10, p=np.inf, num_classes=10, overshoot=0.02, max_iter_df=10): 20 | """ 21 | :param dataset: Images of size MxHxWxC (M: number of images) 22 | 23 | :param f: feedforward function (input: images, output: values of activation BEFORE softmax). 24 | 25 | :param grads: gradient functions with respect to input (as many gradients as classes). 26 | 27 | :param delta: controls the desired fooling rate (default = 80% fooling rate) 28 | 29 | :param max_iter_uni: optional other termination criterion (maximum number of iteration, default = np.inf) 30 | 31 | :param xi: controls the l_p magnitude of the perturbation (default = 10) 32 | 33 | :param p: norm to be used (FOR NOW, ONLY p = 2, and p = np.inf ARE ACCEPTED!) (default = np.inf) 34 | 35 | :param num_classes: num_classes (limits the number of classes to test against, by default = 10) 36 | 37 | :param overshoot: used as a termination criterion to prevent vanishing updates (default = 0.02). 38 | 39 | :param max_iter_df: maximum number of iterations for deepfool (default = 10) 40 | 41 | :return: the universal perturbation. 42 | """ 43 | 44 | v = 0 45 | fooling_rate = 0.0 46 | num_images = np.shape(dataset)[0] # The images should be stacked ALONG FIRST DIMENSION 47 | 48 | itr = 0 49 | while fooling_rate < 1-delta and itr < max_iter_uni: 50 | # Shuffle the dataset 51 | np.random.shuffle(dataset) 52 | 53 | print ('Starting pass number ', itr) 54 | 55 | # Go through the data set and compute the perturbation increments sequentially 56 | for k in range(0, num_images): 57 | cur_img = dataset[k:(k+1), :, :, :] 58 | 59 | if int(np.argmax(np.array(f(cur_img)).flatten())) == int(np.argmax(np.array(f(cur_img+v)).flatten())): 60 | print('>> k = ', k, ', pass #', itr) 61 | 62 | # Compute adversarial perturbation 63 | dr,iter,_,_ = deepfool(cur_img + v, f, grads, num_classes=num_classes, overshoot=overshoot, max_iter=max_iter_df) 64 | 65 | # Make sure it converged... 66 | if iter < max_iter_df-1: 67 | v = v + dr 68 | 69 | # Project on l_p ball 70 | v = proj_lp(v, xi, p) 71 | 72 | itr = itr + 1 73 | 74 | # Perturb the dataset with computed perturbation 75 | dataset_perturbed = dataset + v 76 | 77 | est_labels_orig = np.zeros((num_images)) 78 | est_labels_pert = np.zeros((num_images)) 79 | 80 | batch_size = 100 81 | num_batches = np.int(np.ceil(np.float(num_images) / np.float(batch_size))) 82 | 83 | # Compute the estimated labels in batches 84 | for ii in range(0, num_batches): 85 | m = (ii * batch_size) 86 | M = min((ii+1)*batch_size, num_images) 87 | est_labels_orig[m:M] = np.argmax(f(dataset[m:M, :, :, :]), axis=1).flatten() 88 | est_labels_pert[m:M] = np.argmax(f(dataset_perturbed[m:M, :, :, :]), axis=1).flatten() 89 | 90 | # Compute the fooling rate 91 | fooling_rate = float(np.sum(est_labels_pert != est_labels_orig) / float(num_images)) 92 | print('FOOLING RATE = ', fooling_rate) 93 | 94 | return v 95 | --------------------------------------------------------------------------------