File: index.html

package info (click to toggle)
keras 2.3.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,288 kB
  • sloc: python: 48,266; javascript: 1,794; xml: 297; makefile: 36; sh: 30
file content (1173 lines) | stat: -rw-r--r-- 56,534 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  <link rel="canonical" href="http://keras.io/applications/">
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>Applications - Keras Documentation</title>
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Source+Sans+Pro:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
  
  <script>
    // Current page data
    var mkdocs_page_name = "Applications";
    var mkdocs_page_input_path = "applications.md";
    var mkdocs_page_url = "/applications/";
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
  <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-61785484-1', 'keras.io');
      ga('send', 'pageview');
  </script>
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <a href="">
        <div class="keras-logo">
          <img src="/img/keras-logo-small.jpg" class="keras-logo-img">
          Keras Documentation
        </div>
      </a>

      <div class="wy-side-nav-search">
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="..">Home</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../why-use-keras/">Why use Keras</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">Getting started</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../getting-started/sequential-model-guide/">Guide to the Sequential model</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../getting-started/functional-api-guide/">Guide to the Functional API</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../getting-started/faq/">FAQ</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">Models</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../models/about-keras-models/">About Keras models</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../models/sequential/">Sequential</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../models/model/">Model (functional API)</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">Layers</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/about-keras-layers/">About Keras layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/core/">Core Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/convolutional/">Convolutional Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/pooling/">Pooling Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/local/">Locally-connected Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/recurrent/">Recurrent Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/embeddings/">Embedding Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/merge/">Merge Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/advanced-activations/">Advanced Activations Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/normalization/">Normalization Layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/noise/">Noise layers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/wrappers/">Layer wrappers</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../layers/writing-your-own-keras-layers/">Writing your own Keras layers</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">Preprocessing</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../preprocessing/sequence/">Sequence Preprocessing</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../preprocessing/text/">Text Preprocessing</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../preprocessing/image/">Image Preprocessing</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../losses/">Losses</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../metrics/">Metrics</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../optimizers/">Optimizers</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../activations/">Activations</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../callbacks/">Callbacks</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../datasets/">Datasets</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="./">Applications</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#available-models">Available models</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#models-for-image-classification-with-weights-trained-on-imagenet">Models for image classification with weights trained on ImageNet:</a>
    </li>
        </ul>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#usage-examples-for-image-classification-models">Usage examples for image classification models</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#classify-imagenet-classes-with-resnet50">Classify ImageNet classes with ResNet50</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#extract-features-with-vgg16">Extract features with VGG16</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#extract-features-from-an-arbitrary-intermediate-layer-with-vgg19">Extract features from an arbitrary intermediate layer with VGG19</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#fine-tune-inceptionv3-on-a-new-set-of-classes">Fine-tune InceptionV3 on a new set of classes</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#build-inceptionv3-over-a-custom-input-tensor">Build InceptionV3 over a custom input tensor</a>
    </li>
        </ul>
    </li>
    </ul>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../backend/">Backend</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../initializers/">Initializers</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../regularizers/">Regularizers</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../constraints/">Constraints</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../visualization/">Visualization</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../scikit-learn-api/">Scikit-learn API</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../utils/">Utils</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../contributing/">Contributing</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">Examples</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/addition_rnn/">Addition RNN</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/antirectifier/">Custom layer - antirectifier</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/babi_rnn/">Baby RNN</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/babi_memnn/">Baby MemNN</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/cifar10_cnn/">CIFAR-10 CNN</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/cifar10_resnet/">CIFAR-10 ResNet</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/conv_filter_visualization/">Convolution filter visualization</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/conv_lstm/">Convolutional LSTM</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/deep_dream/">Deep Dream</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/image_ocr/">Image OCR</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/imdb_bidirectional_lstm/">Bidirectional LSTM</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/imdb_cnn/">1D CNN for text classification</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/imdb_cnn_lstm/">Sentiment classification CNN-LSTM</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/imdb_fasttext/">Fasttext for text classification</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/imdb_lstm/">Sentiment classification LSTM</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/lstm_seq2seq/">Sequence to sequence - training</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/lstm_seq2seq_restore/">Sequence to sequence - prediction</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/lstm_stateful/">Stateful LSTM</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/lstm_text_generation/">LSTM for text generation</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../examples/mnist_acgan/">Auxiliary Classifier GAN</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">Keras Documentation</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
    
    <li>Applications</li>
    <li class="wy-breadcrumbs-aside">
      
        <a href="https://github.com/keras-team/keras/tree/master/docs"
          class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1 id="applications">Applications</h1>
<p>Keras Applications are deep learning models that are made available alongside pre-trained weights.
These models can be used for prediction, feature extraction, and fine-tuning.</p>
<p>Weights are downloaded automatically when instantiating a model. They are stored at <code>~/.keras/models/</code>.</p>
<h2 id="available-models">Available models</h2>
<h3 id="models-for-image-classification-with-weights-trained-on-imagenet">Models for image classification with weights trained on ImageNet:</h3>
<ul>
<li><a href="#xception">Xception</a></li>
<li><a href="#vgg16">VGG16</a></li>
<li><a href="#vgg19">VGG19</a></li>
<li><a href="#resnet">ResNet, ResNetV2</a></li>
<li><a href="#inceptionv3">InceptionV3</a></li>
<li><a href="#inceptionresnetv2">InceptionResNetV2</a></li>
<li><a href="#mobilenet">MobileNet</a></li>
<li><a href="#mobilenetv2">MobileNetV2</a></li>
<li><a href="#densenet">DenseNet</a></li>
<li><a href="#nasnet">NASNet</a></li>
</ul>
<p>All of these architectures are compatible with all the backends (TensorFlow, Theano, and CNTK), and upon instantiation the models will be built according to the image data format set in your Keras configuration file at <code>~/.keras/keras.json</code>. For instance, if you have set <code>image_data_format=channels_last</code>, then any model loaded from this repository will get built according to the TensorFlow data format convention, "Height-Width-Depth".</p>
<p>Note that:
- For <code>Keras &lt; 2.2.0</code>, The Xception model is only available for TensorFlow, due to its reliance on <code>SeparableConvolution</code> layers.
- For <code>Keras &lt; 2.1.5</code>, The MobileNet model is only available for TensorFlow, due to its reliance on <code>DepthwiseConvolution</code> layers.</p>
<hr />
<h2 id="usage-examples-for-image-classification-models">Usage examples for image classification models</h2>
<h3 id="classify-imagenet-classes-with-resnet50">Classify ImageNet classes with ResNet50</h3>
<pre><code class="python">from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np

model = ResNet50(weights='imagenet')

img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

preds = model.predict(x)
# decode the results into a list of tuples (class, description, probability)
# (one such list for each sample in the batch)
print('Predicted:', decode_predictions(preds, top=3)[0])
# Predicted: [(u'n02504013', u'Indian_elephant', 0.82658225), (u'n01871265', u'tusker', 0.1122357), (u'n02504458', u'African_elephant', 0.061040461)]
</code></pre>

<h3 id="extract-features-with-vgg16">Extract features with VGG16</h3>
<pre><code class="python">from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
import numpy as np

model = VGG16(weights='imagenet', include_top=False)

img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

features = model.predict(x)
</code></pre>

<h3 id="extract-features-from-an-arbitrary-intermediate-layer-with-vgg19">Extract features from an arbitrary intermediate layer with VGG19</h3>
<pre><code class="python">from keras.applications.vgg19 import VGG19
from keras.preprocessing import image
from keras.applications.vgg19 import preprocess_input
from keras.models import Model
import numpy as np

base_model = VGG19(weights='imagenet')
model = Model(inputs=base_model.input, outputs=base_model.get_layer('block4_pool').output)

img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

block4_pool_features = model.predict(x)
</code></pre>

<h3 id="fine-tune-inceptionv3-on-a-new-set-of-classes">Fine-tune InceptionV3 on a new set of classes</h3>
<pre><code class="python">from keras.applications.inception_v3 import InceptionV3
from keras.preprocessing import image
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D
from keras import backend as K

# create the base pre-trained model
base_model = InceptionV3(weights='imagenet', include_top=False)

# add a global spatial average pooling layer
x = base_model.output
x = GlobalAveragePooling2D()(x)
# let's add a fully-connected layer
x = Dense(1024, activation='relu')(x)
# and a logistic layer -- let's say we have 200 classes
predictions = Dense(200, activation='softmax')(x)

# this is the model we will train
model = Model(inputs=base_model.input, outputs=predictions)

# first: train only the top layers (which were randomly initialized)
# i.e. freeze all convolutional InceptionV3 layers
for layer in base_model.layers:
    layer.trainable = False

# compile the model (should be done *after* setting layers to non-trainable)
model.compile(optimizer='rmsprop', loss='categorical_crossentropy')

# train the model on the new data for a few epochs
model.fit_generator(...)

# at this point, the top layers are well trained and we can start fine-tuning
# convolutional layers from inception V3. We will freeze the bottom N layers
# and train the remaining top layers.

# let's visualize layer names and layer indices to see how many layers
# we should freeze:
for i, layer in enumerate(base_model.layers):
   print(i, layer.name)

# we chose to train the top 2 inception blocks, i.e. we will freeze
# the first 249 layers and unfreeze the rest:
for layer in model.layers[:249]:
   layer.trainable = False
for layer in model.layers[249:]:
   layer.trainable = True

# we need to recompile the model for these modifications to take effect
# we use SGD with a low learning rate
from keras.optimizers import SGD
model.compile(optimizer=SGD(lr=0.0001, momentum=0.9), loss='categorical_crossentropy')

# we train our model again (this time fine-tuning the top 2 inception blocks
# alongside the top Dense layers
model.fit_generator(...)
</code></pre>

<h3 id="build-inceptionv3-over-a-custom-input-tensor">Build InceptionV3 over a custom input tensor</h3>
<pre><code class="python">from keras.applications.inception_v3 import InceptionV3
from keras.layers import Input

# this could also be the output a different Keras model or layer
input_tensor = Input(shape=(224, 224, 3))  # this assumes K.image_data_format() == 'channels_last'

model = InceptionV3(input_tensor=input_tensor, weights='imagenet', include_top=True)
</code></pre>

<hr />
<h1 id="documentation-for-individual-models">Documentation for individual models</h1>
<table>
<thead>
<tr>
<th>Model</th>
<th align="right">Size</th>
<th align="right">Top-1 Accuracy</th>
<th align="right">Top-5 Accuracy</th>
<th align="right">Parameters</th>
<th align="right">Depth</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#xception">Xception</a></td>
<td align="right">88 MB</td>
<td align="right">0.790</td>
<td align="right">0.945</td>
<td align="right">22,910,480</td>
<td align="right">126</td>
</tr>
<tr>
<td><a href="#vgg16">VGG16</a></td>
<td align="right">528 MB</td>
<td align="right">0.713</td>
<td align="right">0.901</td>
<td align="right">138,357,544</td>
<td align="right">23</td>
</tr>
<tr>
<td><a href="#vgg19">VGG19</a></td>
<td align="right">549 MB</td>
<td align="right">0.713</td>
<td align="right">0.900</td>
<td align="right">143,667,240</td>
<td align="right">26</td>
</tr>
<tr>
<td><a href="#resnet">ResNet50</a></td>
<td align="right">98 MB</td>
<td align="right">0.749</td>
<td align="right">0.921</td>
<td align="right">25,636,712</td>
<td align="right">-</td>
</tr>
<tr>
<td><a href="#resnet">ResNet101</a></td>
<td align="right">171 MB</td>
<td align="right">0.764</td>
<td align="right">0.928</td>
<td align="right">44,707,176</td>
<td align="right">-</td>
</tr>
<tr>
<td><a href="#resnet">ResNet152</a></td>
<td align="right">232 MB</td>
<td align="right">0.766</td>
<td align="right">0.931</td>
<td align="right">60,419,944</td>
<td align="right">-</td>
</tr>
<tr>
<td><a href="#resnet">ResNet50V2</a></td>
<td align="right">98 MB</td>
<td align="right">0.760</td>
<td align="right">0.930</td>
<td align="right">25,613,800</td>
<td align="right">-</td>
</tr>
<tr>
<td><a href="#resnet">ResNet101V2</a></td>
<td align="right">171 MB</td>
<td align="right">0.772</td>
<td align="right">0.938</td>
<td align="right">44,675,560</td>
<td align="right">-</td>
</tr>
<tr>
<td><a href="#resnet">ResNet152V2</a></td>
<td align="right">232 MB</td>
<td align="right">0.780</td>
<td align="right">0.942</td>
<td align="right">60,380,648</td>
<td align="right">-</td>
</tr>
<tr>
<td><a href="#inceptionv3">InceptionV3</a></td>
<td align="right">92 MB</td>
<td align="right">0.779</td>
<td align="right">0.937</td>
<td align="right">23,851,784</td>
<td align="right">159</td>
</tr>
<tr>
<td><a href="#inceptionresnetv2">InceptionResNetV2</a></td>
<td align="right">215 MB</td>
<td align="right">0.803</td>
<td align="right">0.953</td>
<td align="right">55,873,736</td>
<td align="right">572</td>
</tr>
<tr>
<td><a href="#mobilenet">MobileNet</a></td>
<td align="right">16 MB</td>
<td align="right">0.704</td>
<td align="right">0.895</td>
<td align="right">4,253,864</td>
<td align="right">88</td>
</tr>
<tr>
<td><a href="#mobilenetv2">MobileNetV2</a></td>
<td align="right">14 MB</td>
<td align="right">0.713</td>
<td align="right">0.901</td>
<td align="right">3,538,984</td>
<td align="right">88</td>
</tr>
<tr>
<td><a href="#densenet">DenseNet121</a></td>
<td align="right">33 MB</td>
<td align="right">0.750</td>
<td align="right">0.923</td>
<td align="right">8,062,504</td>
<td align="right">121</td>
</tr>
<tr>
<td><a href="#densenet">DenseNet169</a></td>
<td align="right">57 MB</td>
<td align="right">0.762</td>
<td align="right">0.932</td>
<td align="right">14,307,880</td>
<td align="right">169</td>
</tr>
<tr>
<td><a href="#densenet">DenseNet201</a></td>
<td align="right">80 MB</td>
<td align="right">0.773</td>
<td align="right">0.936</td>
<td align="right">20,242,984</td>
<td align="right">201</td>
</tr>
<tr>
<td><a href="#nasnet">NASNetMobile</a></td>
<td align="right">23 MB</td>
<td align="right">0.744</td>
<td align="right">0.919</td>
<td align="right">5,326,716</td>
<td align="right">-</td>
</tr>
<tr>
<td><a href="#nasnet">NASNetLarge</a></td>
<td align="right">343 MB</td>
<td align="right">0.825</td>
<td align="right">0.960</td>
<td align="right">88,949,818</td>
<td align="right">-</td>
</tr>
</tbody>
</table>
<p>The top-1 and top-5 accuracy refers to the model's performance on the ImageNet validation dataset.</p>
<p>Depth refers to the topological depth of the network. This includes activation layers, batch normalization layers etc.</p>
<hr />
<h2 id="xception">Xception</h2>
<pre><code class="python">keras.applications.xception.Xception(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
</code></pre>

<p>Xception V1 model, with weights pre-trained on ImageNet.</p>
<p>On ImageNet, this model gets to a top-1 validation accuracy of 0.790
and a top-5 validation accuracy of 0.945.</p>
<p>This model and can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 299x299.</p>
<h3 id="arguments">Arguments</h3>
<ul>
<li>include_top: whether to include the fully-connected layer at the top of the network.</li>
<li>weights: one of <code>None</code> (random initialization) or <code>'imagenet'</code> (pre-training on ImageNet).</li>
<li>input_tensor: optional Keras tensor (i.e. output of <code>layers.Input()</code>) to use as image input for the model.</li>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is <code>False</code> (otherwise the input shape
    has to be <code>(299, 299, 3)</code>.
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 71.
    E.g. <code>(150, 150, 3)</code> would be one valid value.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model will be
    the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a 2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images 
    into, only to be specified if <code>include_top</code> is <code>True</code>, and 
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns">Returns</h3>
<p>A Keras <code>Model</code> instance.</p>
<h3 id="references">References</h3>
<ul>
<li><a href="https://arxiv.org/abs/1610.02357">Xception: Deep Learning with Depthwise Separable Convolutions</a></li>
</ul>
<h3 id="license">License</h3>
<p>These weights are trained by ourselves and are released under the MIT license.</p>
<hr />
<h2 id="vgg16">VGG16</h2>
<pre><code class="python">keras.applications.vgg16.VGG16(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
</code></pre>

<p>VGG16 model, with weights pre-trained on ImageNet.</p>
<p>This model can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 224x224.</p>
<h3 id="arguments_1">Arguments</h3>
<ul>
<li>include_top: whether to include the 3 fully-connected layers at the top of the network.</li>
<li>weights: one of <code>None</code> (random initialization) or <code>'imagenet'</code> (pre-training on ImageNet).</li>
<li>input_tensor: optional Keras tensor (i.e. output of <code>layers.Input()</code>) to use as image input for the model.</li>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is <code>False</code> (otherwise the input shape
    has to be <code>(224, 224, 3)</code> (with <code>'channels_last'</code> data format)
    or <code>(3, 224, 224)</code> (with <code>'channels_first'</code> data format).
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 32.
    E.g. <code>(200, 200, 3)</code> would be one valid value.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model will be
    the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a 2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images 
    into, only to be specified if <code>include_top</code> is <code>True</code>, and 
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_1">Returns</h3>
<p>A Keras <code>Model</code> instance.</p>
<h3 id="references_1">References</h3>
<ul>
<li><a href="https://arxiv.org/abs/1409.1556">Very Deep Convolutional Networks for Large-Scale Image Recognition</a>: please cite this paper if you use the VGG models in your work.</li>
</ul>
<h3 id="license_1">License</h3>
<p>These weights are ported from the ones <a href="http://www.robots.ox.ac.uk/~vgg/research/very_deep/">released by VGG at Oxford</a> under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution License</a>.</p>
<hr />
<h2 id="vgg19">VGG19</h2>
<pre><code class="python">keras.applications.vgg19.VGG19(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
</code></pre>

<p>VGG19 model, with weights pre-trained on ImageNet.</p>
<p>This model can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 224x224.</p>
<h3 id="arguments_2">Arguments</h3>
<ul>
<li>include_top: whether to include the 3 fully-connected layers at the top of the network.</li>
<li>weights: one of <code>None</code> (random initialization) or <code>'imagenet'</code> (pre-training on ImageNet).</li>
<li>input_tensor: optional Keras tensor (i.e. output of <code>layers.Input()</code>) to use as image input for the model.</li>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is <code>False</code> (otherwise the input shape
    has to be <code>(224, 224, 3)</code> (with <code>'channels_last'</code> data format)
    or <code>(3, 224, 224)</code> (with <code>'channels_first'</code> data format).
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 32.
    E.g. <code>(200, 200, 3)</code> would be one valid value.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model will be
    the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a 2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images 
    into, only to be specified if <code>include_top</code> is <code>True</code>, and 
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_2">Returns</h3>
<p>A Keras <code>Model</code> instance.</p>
<h3 id="references_2">References</h3>
<ul>
<li><a href="https://arxiv.org/abs/1409.1556">Very Deep Convolutional Networks for Large-Scale Image Recognition</a></li>
</ul>
<h3 id="license_2">License</h3>
<p>These weights are ported from the ones <a href="http://www.robots.ox.ac.uk/~vgg/research/very_deep/">released by VGG at Oxford</a> under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution License</a>.</p>
<hr />
<h2 id="resnet">ResNet</h2>
<pre><code class="python">keras.applications.resnet.ResNet50(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet.ResNet101(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet.ResNet152(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet50V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet101V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.resnet_v2.ResNet152V2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
</code></pre>

<p>ResNet, ResNetV2 models, with weights pre-trained on ImageNet.</p>
<p>This model and can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 224x224.</p>
<h3 id="arguments_3">Arguments</h3>
<ul>
<li>include_top: whether to include the fully-connected layer at the top of the network.</li>
<li>weights: one of <code>None</code> (random initialization) or <code>'imagenet'</code> (pre-training on ImageNet).</li>
<li>input_tensor: optional Keras tensor (i.e. output of <code>layers.Input()</code>) to use as image input for the model.</li>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is <code>False</code> (otherwise the input shape
    has to be <code>(224, 224, 3)</code> (with <code>'channels_last'</code> data format)
    or <code>(3, 224, 224)</code> (with <code>'channels_first'</code> data format).
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 32.
    E.g. <code>(200, 200, 3)</code> would be one valid value.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model will be
    the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a 2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images 
    into, only to be specified if <code>include_top</code> is <code>True</code>, and 
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_3">Returns</h3>
<p>A Keras <code>Model</code> instance.</p>
<h3 id="references_3">References</h3>
<ul>
<li><code>ResNet</code>: <a href="https://arxiv.org/abs/1512.03385">Deep Residual Learning for Image Recognition</a></li>
<li><code>ResNetV2</code>: <a href="https://arxiv.org/abs/1603.05027">Identity Mappings in Deep Residual Networks</a></li>
</ul>
<h3 id="license_3">License</h3>
<p>These weights are ported from the following:</p>
<ul>
<li><code>ResNet</code>: <a href="https://github.com/KaimingHe/deep-residual-networks">The original repository of Kaiming He</a> under the <a href="https://github.com/KaimingHe/deep-residual-networks/blob/master/LICENSE">MIT license</a>.</li>
<li><code>ResNetV2</code>: <a href="https://github.com/facebook/fb.resnet.torch">Facebook</a> under the <a href="https://github.com/facebook/fb.resnet.torch/blob/master/LICENSE">BSD license</a>.</li>
</ul>
<hr />
<h2 id="inceptionv3">InceptionV3</h2>
<pre><code class="python">keras.applications.inception_v3.InceptionV3(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
</code></pre>

<p>Inception V3 model, with weights pre-trained on ImageNet.</p>
<p>This model and can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 299x299.</p>
<h3 id="arguments_4">Arguments</h3>
<ul>
<li>include_top: whether to include the fully-connected layer at the top of the network.</li>
<li>weights: one of <code>None</code> (random initialization) or <code>'imagenet'</code> (pre-training on ImageNet).</li>
<li>input_tensor: optional Keras tensor (i.e. output of <code>layers.Input()</code>) to use as image input for the model.</li>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is <code>False</code> (otherwise the input shape
    has to be <code>(299, 299, 3)</code> (with <code>'channels_last'</code> data format)
    or <code>(3, 299, 299)</code> (with <code>'channels_first'</code> data format).
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 75.
    E.g. <code>(150, 150, 3)</code> would be one valid value.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model will be
    the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a 2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images 
    into, only to be specified if <code>include_top</code> is <code>True</code>, and 
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_4">Returns</h3>
<p>A Keras <code>Model</code> instance.</p>
<h3 id="references_4">References</h3>
<ul>
<li><a href="http://arxiv.org/abs/1512.00567">Rethinking the Inception Architecture for Computer Vision</a></li>
</ul>
<h3 id="license_4">License</h3>
<p>These weights are released under <a href="https://github.com/tensorflow/models/blob/master/LICENSE">the Apache License</a>.</p>
<hr />
<h2 id="inceptionresnetv2">InceptionResNetV2</h2>
<pre><code class="python">keras.applications.inception_resnet_v2.InceptionResNetV2(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
</code></pre>

<p>Inception-ResNet V2 model, with weights pre-trained on ImageNet.</p>
<p>This model and can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 299x299.</p>
<h3 id="arguments_5">Arguments</h3>
<ul>
<li>include_top: whether to include the fully-connected layer at the top of the network.</li>
<li>weights: one of <code>None</code> (random initialization) or <code>'imagenet'</code> (pre-training on ImageNet).</li>
<li>input_tensor: optional Keras tensor (i.e. output of <code>layers.Input()</code>) to use as image input for the model.</li>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is <code>False</code> (otherwise the input shape
    has to be <code>(299, 299, 3)</code> (with <code>'channels_last'</code> data format)
    or <code>(3, 299, 299)</code> (with <code>'channels_first'</code> data format).
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 75.
    E.g. <code>(150, 150, 3)</code> would be one valid value.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model will be
    the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a 2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images 
    into, only to be specified if <code>include_top</code> is <code>True</code>, and 
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_5">Returns</h3>
<p>A Keras <code>Model</code> instance.</p>
<h3 id="references_5">References</h3>
<ul>
<li><a href="https://arxiv.org/abs/1602.07261">Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning</a></li>
</ul>
<h3 id="license_5">License</h3>
<p>These weights are released under <a href="https://github.com/tensorflow/models/blob/master/LICENSE">the Apache License</a>.</p>
<hr />
<h2 id="mobilenet">MobileNet</h2>
<pre><code class="python">keras.applications.mobilenet.MobileNet(input_shape=None, alpha=1.0, depth_multiplier=1, dropout=1e-3, include_top=True, weights='imagenet', input_tensor=None, pooling=None, classes=1000)
</code></pre>

<p>MobileNet model, with weights pre-trained on ImageNet.</p>
<p>This model and can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 224x224.</p>
<h3 id="arguments_6">Arguments</h3>
<ul>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is <code>False</code> (otherwise the input shape
    has to be <code>(224, 224, 3)</code> (with <code>'channels_last'</code> data format)
    or <code>(3, 224, 224)</code> (with <code>'channels_first'</code> data format).
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 32.
    E.g. <code>(200, 200, 3)</code> would be one valid value.</li>
<li>alpha: controls the width of the network.<ul>
<li>If <code>alpha</code> &lt; 1.0, proportionally decreases the number
    of filters in each layer.</li>
<li>If <code>alpha</code> &gt; 1.0, proportionally increases the number
    of filters in each layer.</li>
<li>If <code>alpha</code> = 1, default number of filters from the paper
    are used at each layer.</li>
</ul>
</li>
<li>depth_multiplier: depth multiplier for depthwise convolution
    (also called the resolution multiplier)</li>
<li>dropout: dropout rate</li>
<li>include_top: whether to include the fully-connected
    layer at the top of the network.</li>
<li>weights: <code>None</code> (random initialization) or
    <code>'imagenet'</code> (ImageNet weights)</li>
<li>input_tensor: optional Keras tensor (i.e. output of
    <code>layers.Input()</code>)
    to use as image input for the model.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model
will be the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a
    2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images
    into, only to be specified if <code>include_top</code> is <code>True</code>, and
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_6">Returns</h3>
<p>A Keras <code>Model</code> instance.</p>
<h3 id="references_6">References</h3>
<ul>
<li><a href="https://arxiv.org/pdf/1704.04861.pdf">MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications</a></li>
</ul>
<h3 id="license_6">License</h3>
<p>These weights are released under <a href="https://github.com/tensorflow/models/blob/master/LICENSE">the Apache License</a>.</p>
<hr />
<h2 id="densenet">DenseNet</h2>
<pre><code class="python">keras.applications.densenet.DenseNet121(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.densenet.DenseNet169(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
keras.applications.densenet.DenseNet201(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
</code></pre>

<p>DenseNet models, with weights pre-trained on ImageNet.</p>
<p>This model and can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 224x224.</p>
<h3 id="arguments_7">Arguments</h3>
<ul>
<li>blocks: numbers of building blocks for the four dense layers.</li>
<li>include_top: whether to include the fully-connected
    layer at the top of the network.</li>
<li>weights: one of <code>None</code> (random initialization),
    'imagenet' (pre-training on ImageNet),
    or the path to the weights file to be loaded.</li>
<li>input_tensor: optional Keras tensor (i.e. output of <code>layers.Input()</code>)
    to use as image input for the model.</li>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is False (otherwise the input shape
    has to be <code>(224, 224, 3)</code> (with <code>'channels_last'</code> data format)
    or <code>(3, 224, 224)</code> (with <code>'channels_first'</code> data format).
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 32.
    E.g. <code>(200, 200, 3)</code> would be one valid value.</li>
<li>pooling: optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model will be
    the 4D tensor output of the
    last convolutional block.</li>
<li><code>avg</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a 2D tensor.</li>
<li><code>max</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images
    into, only to be specified if <code>include_top</code> is True, and
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_7">Returns</h3>
<p>A Keras model instance.</p>
<h3 id="references_7">References</h3>
<ul>
<li><a href="https://arxiv.org/abs/1608.06993">Densely Connected Convolutional Networks</a> (CVPR 2017 Best Paper Award)</li>
</ul>
<h3 id="license_7">License</h3>
<p>These weights are released under <a href="https://github.com/liuzhuang13/DenseNet/blob/master/LICENSE">the BSD 3-clause License</a>.</p>
<hr />
<h2 id="nasnet">NASNet</h2>
<pre><code class="python">keras.applications.nasnet.NASNetLarge(input_shape=None, include_top=True, weights='imagenet', input_tensor=None, pooling=None, classes=1000)
keras.applications.nasnet.NASNetMobile(input_shape=None, include_top=True, weights='imagenet', input_tensor=None, pooling=None, classes=1000)
</code></pre>

<p>Neural Architecture Search Network (NASNet) models, with weights pre-trained on ImageNet.</p>
<p>The default input size for the NASNetLarge model is 331x331 and for the
NASNetMobile model is 224x224.</p>
<h3 id="arguments_8">Arguments</h3>
<ul>
<li>input_shape: optional shape tuple, only to be specified
    if <code>include_top</code> is <code>False</code> (otherwise the input shape
    has to be <code>(224, 224, 3)</code> (with <code>'channels_last'</code> data format)
    or <code>(3, 224, 224)</code> (with <code>'channels_first'</code> data format)
    for NASNetMobile or <code>(331, 331, 3)</code> (with <code>'channels_last'</code>
    data format) or <code>(3, 331, 331)</code> (with <code>'channels_first'</code>
    data format) for NASNetLarge.
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 32.
    E.g. <code>(200, 200, 3)</code> would be one valid value.</li>
<li>include_top: whether to include the fully-connected
    layer at the top of the network.</li>
<li>weights: <code>None</code> (random initialization) or
    <code>'imagenet'</code> (ImageNet weights)</li>
<li>input_tensor: optional Keras tensor (i.e. output of
    <code>layers.Input()</code>)
    to use as image input for the model.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model
will be the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a
    2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied.</li>
</ul>
</li>
<li>classes: optional number of classes to classify images
    into, only to be specified if <code>include_top</code> is <code>True</code>, and
    if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_8">Returns</h3>
<p>A Keras <code>Model</code> instance.</p>
<h3 id="references_8">References</h3>
<ul>
<li><a href="https://arxiv.org/abs/1707.07012">Learning Transferable Architectures for Scalable Image Recognition</a></li>
</ul>
<h3 id="license_8">License</h3>
<p>These weights are released under <a href="https://github.com/tensorflow/models/blob/master/LICENSE">the Apache License</a>.</p>
<hr />
<h2 id="mobilenetv2">MobileNetV2</h2>
<pre><code class="python">keras.applications.mobilenet_v2.MobileNetV2(input_shape=None, alpha=1.0, include_top=True, weights='imagenet', input_tensor=None, pooling=None, classes=1000)
</code></pre>

<p>MobileNetV2 model, with weights pre-trained on ImageNet.</p>
<p>This model and can be built both with <code>'channels_first'</code> data format (channels, height, width) or <code>'channels_last'</code> data format (height, width, channels).</p>
<p>The default input size for this model is 224x224.</p>
<h3 id="arguments_9">Arguments</h3>
<ul>
<li>input_shape: optional shape tuple, to be specified if you would
    like to use a model with an input img resolution that is not
    (224, 224, 3).
    It should have exactly 3 inputs channels (224, 224, 3).
    You can also omit this option if you would like
    to infer input_shape from an input_tensor.
    If you choose to include both input_tensor and input_shape then
    input_shape will be used if they match, if the shapes
    do not match then we will throw an error.
    E.g. <code>(160, 160, 3)</code> would be one valid value.</li>
<li>alpha: controls the width of the network. This is known as the
    width multiplier in the MobileNetV2 paper.<ul>
<li>If <code>alpha</code> &lt; 1.0, proportionally decreases the number
    of filters in each layer.</li>
<li>If <code>alpha</code> &gt; 1.0, proportionally increases the number
    of filters in each layer.</li>
<li>If <code>alpha</code> = 1, default number of filters from the paper
     are used at each layer.</li>
</ul>
</li>
<li>include_top: whether to include the fully-connected
      layer at the top of the network.</li>
<li>weights: one of <code>None</code> (random initialization),
        'imagenet' (pre-training on ImageNet),
        or the path to the weights file to be loaded.</li>
<li>input_tensor: optional Keras tensor (i.e. output of
      <code>layers.Input()</code>)
      to use as image input for the model.</li>
<li>pooling: Optional pooling mode for feature extraction
    when <code>include_top</code> is <code>False</code>.<ul>
<li><code>None</code> means that the output of the model
will be the 4D tensor output of the
    last convolutional block.</li>
<li><code>'avg'</code> means that global average pooling
    will be applied to the output of the
    last convolutional block, and thus
    the output of the model will be a
    2D tensor.</li>
<li><code>'max'</code> means that global max pooling will
    be applied. </li>
</ul>
</li>
<li>classes: optional number of classes to classify images
      into, only to be specified if <code>include_top</code> is True, and
      if no <code>weights</code> argument is specified.</li>
</ul>
<h3 id="returns_9">Returns</h3>
<p>A Keras model instance.</p>
<h3 id="raises">Raises</h3>
<p>ValueError: in case of invalid argument for <code>weights</code>,
    or invalid input shape, alpha,
    rows when weights='imagenet'</p>
<h3 id="references_9">References</h3>
<ul>
<li><a href="https://arxiv.org/abs/1801.04381">MobileNetV2: Inverted Residuals and Linear Bottlenecks</a></li>
</ul>
<h3 id="license_9">License</h3>
<p>These weights are released under <a href="https://github.com/tensorflow/models/blob/master/LICENSE">the Apache License</a>.</p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../backend/" class="btn btn-neutral float-right" title="Backend">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../datasets/" class="btn btn-neutral" title="Datasets"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a href="http://github.com/keras-team/keras/" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../datasets/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../backend/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>
    <script type="text/javascript" defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>