14.Finetune InceptionV3样例

程序说明

时间:2016年11月22日

说明:finetune InceptionV3网络。

1.加载keras模块

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
Using TensorFlow backend.

如需绘制模型请加载plot

from keras.utils.visualize_util import plot
# create the base pre-trained model
base_model = InceptionV3(weights='imagenet', include_top=False)
Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.2/inception_v3_weights_tf_dim_ordering_tf_kernels_notop.h5
86695936/86916664 [============================>.] - ETA: 0s
base_model.summary()
____________________________________________________________________________________________________
Layer (type)                     Output Shape          Param #     Connected to                     
====================================================================================================
input_1 (InputLayer)             (None, None, None, 3) 0                                            
____________________________________________________________________________________________________
convolution2d_1 (Convolution2D)  (None, None, None, 32)896         input_1[0][0]                    
____________________________________________________________________________________________________
batchnormalization_1 (BatchNormal(None, None, None, 32)64          convolution2d_1[0][0]            
____________________________________________________________________________________________________
convolution2d_2 (Convolution2D)  (None, None, None, 32)9248        batchnormalization_1[0][0]       
____________________________________________________________________________________________________
batchnormalization_2 (BatchNormal(None, None, None, 32)64          convolution2d_2[0][0]            
____________________________________________________________________________________________________
convolution2d_3 (Convolution2D)  (None, None, None, 64)18496       batchnormalization_2[0][0]       
____________________________________________________________________________________________________
batchnormalization_3 (BatchNormal(None, None, None, 64)128         convolution2d_3[0][0]            
____________________________________________________________________________________________________
maxpooling2d_1 (MaxPooling2D)    (None, None, None, 64)0           batchnormalization_3[0][0]       
____________________________________________________________________________________________________
convolution2d_4 (Convolution2D)  (None, None, None, 80)5200        maxpooling2d_1[0][0]             
____________________________________________________________________________________________________
batchnormalization_4 (BatchNormal(None, None, None, 80)160         convolution2d_4[0][0]            
____________________________________________________________________________________________________
convolution2d_5 (Convolution2D)  (None, None, None, 192138432      batchnormalization_4[0][0]       
____________________________________________________________________________________________________
batchnormalization_5 (BatchNormal(None, None, None, 192384         convolution2d_5[0][0]            
____________________________________________________________________________________________________
maxpooling2d_2 (MaxPooling2D)    (None, None, None, 1920           batchnormalization_5[0][0]       
____________________________________________________________________________________________________
convolution2d_9 (Convolution2D)  (None, None, None, 64)12352       maxpooling2d_2[0][0]             
____________________________________________________________________________________________________
batchnormalization_9 (BatchNormal(None, None, None, 64)128         convolution2d_9[0][0]            
____________________________________________________________________________________________________
convolution2d_7 (Convolution2D)  (None, None, None, 48)9264        maxpooling2d_2[0][0]             
____________________________________________________________________________________________________
convolution2d_10 (Convolution2D) (None, None, None, 96)55392       batchnormalization_9[0][0]       
____________________________________________________________________________________________________
batchnormalization_7 (BatchNormal(None, None, None, 48)96          convolution2d_7[0][0]            
____________________________________________________________________________________________________
batchnormalization_10 (BatchNorma(None, None, None, 96)192         convolution2d_10[0][0]           
____________________________________________________________________________________________________
averagepooling2d_1 (AveragePoolin(None, None, None, 1920           maxpooling2d_2[0][0]             
____________________________________________________________________________________________________
convolution2d_6 (Convolution2D)  (None, None, None, 64)12352       maxpooling2d_2[0][0]             
____________________________________________________________________________________________________
convolution2d_8 (Convolution2D)  (None, None, None, 64)76864       batchnormalization_7[0][0]       
____________________________________________________________________________________________________
convolution2d_11 (Convolution2D) (None, None, None, 96)83040       batchnormalization_10[0][0]      
____________________________________________________________________________________________________
convolution2d_12 (Convolution2D) (None, None, None, 32)6176        averagepooling2d_1[0][0]         
____________________________________________________________________________________________________
batchnormalization_6 (BatchNormal(None, None, None, 64)128         convolution2d_6[0][0]            
____________________________________________________________________________________________________
batchnormalization_8 (BatchNormal(None, None, None, 64)128         convolution2d_8[0][0]            
____________________________________________________________________________________________________
batchnormalization_11 (BatchNorma(None, None, None, 96)192         convolution2d_11[0][0]           
____________________________________________________________________________________________________
batchnormalization_12 (BatchNorma(None, None, None, 32)64          convolution2d_12[0][0]           
____________________________________________________________________________________________________
mixed0 (Merge)                   (None, None, None, 2560           batchnormalization_6[0][0]       
                                                                   batchnormalization_8[0][0]       
                                                                   batchnormalization_11[0][0]      
                                                                   batchnormalization_12[0][0]      
____________________________________________________________________________________________________
convolution2d_16 (Convolution2D) (None, None, None, 64)16448       mixed0[0][0]                     
____________________________________________________________________________________________________
batchnormalization_16 (BatchNorma(None, None, None, 64)128         convolution2d_16[0][0]           
____________________________________________________________________________________________________
convolution2d_14 (Convolution2D) (None, None, None, 48)12336       mixed0[0][0]                     
____________________________________________________________________________________________________
convolution2d_17 (Convolution2D) (None, None, None, 96)55392       batchnormalization_16[0][0]      
____________________________________________________________________________________________________
batchnormalization_14 (BatchNorma(None, None, None, 48)96          convolution2d_14[0][0]           
____________________________________________________________________________________________________
batchnormalization_17 (BatchNorma(None, None, None, 96)192         convolution2d_17[0][0]           
____________________________________________________________________________________________________
averagepooling2d_2 (AveragePoolin(None, None, None, 2560           mixed0[0][0]                     
____________________________________________________________________________________________________
convolution2d_13 (Convolution2D) (None, None, None, 64)16448       mixed0[0][0]                     
____________________________________________________________________________________________________
convolution2d_15 (Convolution2D) (None, None, None, 64)76864       batchnormalization_14[0][0]      
____________________________________________________________________________________________________
convolution2d_18 (Convolution2D) (None, None, None, 96)83040       batchnormalization_17[0][0]      
____________________________________________________________________________________________________
convolution2d_19 (Convolution2D) (None, None, None, 32)8224        averagepooling2d_2[0][0]         
____________________________________________________________________________________________________
batchnormalization_13 (BatchNorma(None, None, None, 64)128         convolution2d_13[0][0]           
____________________________________________________________________________________________________
batchnormalization_15 (BatchNorma(None, None, None, 64)128         convolution2d_15[0][0]           
____________________________________________________________________________________________________
batchnormalization_18 (BatchNorma(None, None, None, 96)192         convolution2d_18[0][0]           
____________________________________________________________________________________________________
batchnormalization_19 (BatchNorma(None, None, None, 32)64          convolution2d_19[0][0]           
____________________________________________________________________________________________________
mixed1 (Merge)                   (None, None, None, 2560           batchnormalization_13[0][0]      
                                                                   batchnormalization_15[0][0]      
                                                                   batchnormalization_18[0][0]      
                                                                   batchnormalization_19[0][0]      
____________________________________________________________________________________________________
convolution2d_23 (Convolution2D) (None, None, None, 64)16448       mixed1[0][0]                     
____________________________________________________________________________________________________
batchnormalization_23 (BatchNorma(None, None, None, 64)128         convolution2d_23[0][0]           
____________________________________________________________________________________________________
convolution2d_21 (Convolution2D) (None, None, None, 48)12336       mixed1[0][0]                     
____________________________________________________________________________________________________
convolution2d_24 (Convolution2D) (None, None, None, 96)55392       batchnormalization_23[0][0]      
____________________________________________________________________________________________________
batchnormalization_21 (BatchNorma(None, None, None, 48)96          convolution2d_21[0][0]           
____________________________________________________________________________________________________
batchnormalization_24 (BatchNorma(None, None, None, 96)192         convolution2d_24[0][0]           
____________________________________________________________________________________________________
averagepooling2d_3 (AveragePoolin(None, None, None, 2560           mixed1[0][0]                     
____________________________________________________________________________________________________
convolution2d_20 (Convolution2D) (None, None, None, 64)16448       mixed1[0][0]                     
____________________________________________________________________________________________________
convolution2d_22 (Convolution2D) (None, None, None, 64)76864       batchnormalization_21[0][0]      
____________________________________________________________________________________________________
convolution2d_25 (Convolution2D) (None, None, None, 96)83040       batchnormalization_24[0][0]      
____________________________________________________________________________________________________
convolution2d_26 (Convolution2D) (None, None, None, 32)8224        averagepooling2d_3[0][0]         
____________________________________________________________________________________________________
batchnormalization_20 (BatchNorma(None, None, None, 64)128         convolution2d_20[0][0]           
____________________________________________________________________________________________________
batchnormalization_22 (BatchNorma(None, None, None, 64)128         convolution2d_22[0][0]           
____________________________________________________________________________________________________
batchnormalization_25 (BatchNorma(None, None, None, 96)192         convolution2d_25[0][0]           
____________________________________________________________________________________________________
batchnormalization_26 (BatchNorma(None, None, None, 32)64          convolution2d_26[0][0]           
____________________________________________________________________________________________________
mixed2 (Merge)                   (None, None, None, 2560           batchnormalization_20[0][0]      
                                                                   batchnormalization_22[0][0]      
                                                                   batchnormalization_25[0][0]      
                                                                   batchnormalization_26[0][0]      
____________________________________________________________________________________________________
convolution2d_28 (Convolution2D) (None, None, None, 64)16448       mixed2[0][0]                     
____________________________________________________________________________________________________
batchnormalization_28 (BatchNorma(None, None, None, 64)128         convolution2d_28[0][0]           
____________________________________________________________________________________________________
convolution2d_29 (Convolution2D) (None, None, None, 96)55392       batchnormalization_28[0][0]      
____________________________________________________________________________________________________
batchnormalization_29 (BatchNorma(None, None, None, 96)192         convolution2d_29[0][0]           
____________________________________________________________________________________________________
convolution2d_27 (Convolution2D) (None, None, None, 384885120      mixed2[0][0]                     
____________________________________________________________________________________________________
convolution2d_30 (Convolution2D) (None, None, None, 96)83040       batchnormalization_29[0][0]      
____________________________________________________________________________________________________
batchnormalization_27 (BatchNorma(None, None, None, 384768         convolution2d_27[0][0]           
____________________________________________________________________________________________________
batchnormalization_30 (BatchNorma(None, None, None, 96)192         convolution2d_30[0][0]           
____________________________________________________________________________________________________
maxpooling2d_3 (MaxPooling2D)    (None, None, None, 2560           mixed2[0][0]                     
____________________________________________________________________________________________________
mixed3 (Merge)                   (None, None, None, 7360           batchnormalization_27[0][0]      
                                                                   batchnormalization_30[0][0]      
                                                                   maxpooling2d_3[0][0]             
____________________________________________________________________________________________________
convolution2d_35 (Convolution2D) (None, None, None, 12894336       mixed3[0][0]                     
____________________________________________________________________________________________________
batchnormalization_35 (BatchNorma(None, None, None, 128256         convolution2d_35[0][0]           
____________________________________________________________________________________________________
convolution2d_36 (Convolution2D) (None, None, None, 128114816      batchnormalization_35[0][0]      
____________________________________________________________________________________________________
batchnormalization_36 (BatchNorma(None, None, None, 128256         convolution2d_36[0][0]           
____________________________________________________________________________________________________
convolution2d_32 (Convolution2D) (None, None, None, 12894336       mixed3[0][0]                     
____________________________________________________________________________________________________
convolution2d_37 (Convolution2D) (None, None, None, 128114816      batchnormalization_36[0][0]      
____________________________________________________________________________________________________
batchnormalization_32 (BatchNorma(None, None, None, 128256         convolution2d_32[0][0]           
____________________________________________________________________________________________________
batchnormalization_37 (BatchNorma(None, None, None, 128256         convolution2d_37[0][0]           
____________________________________________________________________________________________________
convolution2d_33 (Convolution2D) (None, None, None, 128114816      batchnormalization_32[0][0]      
____________________________________________________________________________________________________
convolution2d_38 (Convolution2D) (None, None, None, 128114816      batchnormalization_37[0][0]      
____________________________________________________________________________________________________
batchnormalization_33 (BatchNorma(None, None, None, 128256         convolution2d_33[0][0]           
____________________________________________________________________________________________________
batchnormalization_38 (BatchNorma(None, None, None, 128256         convolution2d_38[0][0]           
____________________________________________________________________________________________________
averagepooling2d_4 (AveragePoolin(None, None, None, 7360           mixed3[0][0]                     
____________________________________________________________________________________________________
convolution2d_31 (Convolution2D) (None, None, None, 192141504      mixed3[0][0]                     
____________________________________________________________________________________________________
convolution2d_34 (Convolution2D) (None, None, None, 192172224      batchnormalization_33[0][0]      
____________________________________________________________________________________________________
convolution2d_39 (Convolution2D) (None, None, None, 192172224      batchnormalization_38[0][0]      
____________________________________________________________________________________________________
convolution2d_40 (Convolution2D) (None, None, None, 192141504      averagepooling2d_4[0][0]         
____________________________________________________________________________________________________
batchnormalization_31 (BatchNorma(None, None, None, 192384         convolution2d_31[0][0]           
____________________________________________________________________________________________________
batchnormalization_34 (BatchNorma(None, None, None, 192384         convolution2d_34[0][0]           
____________________________________________________________________________________________________
batchnormalization_39 (BatchNorma(None, None, None, 192384         convolution2d_39[0][0]           
____________________________________________________________________________________________________
batchnormalization_40 (BatchNorma(None, None, None, 192384         convolution2d_40[0][0]           
____________________________________________________________________________________________________
mixed4 (Merge)                   (None, None, None, 7680           batchnormalization_31[0][0]      
                                                                   batchnormalization_34[0][0]      
                                                                   batchnormalization_39[0][0]      
                                                                   batchnormalization_40[0][0]      
____________________________________________________________________________________________________
convolution2d_45 (Convolution2D) (None, None, None, 160123040      mixed4[0][0]                     
____________________________________________________________________________________________________
batchnormalization_45 (BatchNorma(None, None, None, 160320         convolution2d_45[0][0]           
____________________________________________________________________________________________________
convolution2d_46 (Convolution2D) (None, None, None, 160179360      batchnormalization_45[0][0]      
____________________________________________________________________________________________________
batchnormalization_46 (BatchNorma(None, None, None, 160320         convolution2d_46[0][0]           
____________________________________________________________________________________________________
convolution2d_42 (Convolution2D) (None, None, None, 160123040      mixed4[0][0]                     
____________________________________________________________________________________________________
convolution2d_47 (Convolution2D) (None, None, None, 160179360      batchnormalization_46[0][0]      
____________________________________________________________________________________________________
batchnormalization_42 (BatchNorma(None, None, None, 160320         convolution2d_42[0][0]           
____________________________________________________________________________________________________
batchnormalization_47 (BatchNorma(None, None, None, 160320         convolution2d_47[0][0]           
____________________________________________________________________________________________________
convolution2d_43 (Convolution2D) (None, None, None, 160179360      batchnormalization_42[0][0]      
____________________________________________________________________________________________________
convolution2d_48 (Convolution2D) (None, None, None, 160179360      batchnormalization_47[0][0]      
____________________________________________________________________________________________________
batchnormalization_43 (BatchNorma(None, None, None, 160320         convolution2d_43[0][0]           
____________________________________________________________________________________________________
batchnormalization_48 (BatchNorma(None, None, None, 160320         convolution2d_48[0][0]           
____________________________________________________________________________________________________
averagepooling2d_5 (AveragePoolin(None, None, None, 7680           mixed4[0][0]                     
____________________________________________________________________________________________________
convolution2d_41 (Convolution2D) (None, None, None, 192147648      mixed4[0][0]                     
____________________________________________________________________________________________________
convolution2d_44 (Convolution2D) (None, None, None, 192215232      batchnormalization_43[0][0]      
____________________________________________________________________________________________________
convolution2d_49 (Convolution2D) (None, None, None, 192215232      batchnormalization_48[0][0]      
____________________________________________________________________________________________________
convolution2d_50 (Convolution2D) (None, None, None, 192147648      averagepooling2d_5[0][0]         
____________________________________________________________________________________________________
batchnormalization_41 (BatchNorma(None, None, None, 192384         convolution2d_41[0][0]           
____________________________________________________________________________________________________
batchnormalization_44 (BatchNorma(None, None, None, 192384         convolution2d_44[0][0]           
____________________________________________________________________________________________________
batchnormalization_49 (BatchNorma(None, None, None, 192384         convolution2d_49[0][0]           
____________________________________________________________________________________________________
batchnormalization_50 (BatchNorma(None, None, None, 192384         convolution2d_50[0][0]           
____________________________________________________________________________________________________
mixed5 (Merge)                   (None, None, None, 7680           batchnormalization_41[0][0]      
                                                                   batchnormalization_44[0][0]      
                                                                   batchnormalization_49[0][0]      
                                                                   batchnormalization_50[0][0]      
____________________________________________________________________________________________________
convolution2d_55 (Convolution2D) (None, None, None, 160123040      mixed5[0][0]                     
____________________________________________________________________________________________________
batchnormalization_55 (BatchNorma(None, None, None, 160320         convolution2d_55[0][0]           
____________________________________________________________________________________________________
convolution2d_56 (Convolution2D) (None, None, None, 160179360      batchnormalization_55[0][0]      
____________________________________________________________________________________________________
batchnormalization_56 (BatchNorma(None, None, None, 160320         convolution2d_56[0][0]           
____________________________________________________________________________________________________
convolution2d_52 (Convolution2D) (None, None, None, 160123040      mixed5[0][0]                     
____________________________________________________________________________________________________
convolution2d_57 (Convolution2D) (None, None, None, 160179360      batchnormalization_56[0][0]      
____________________________________________________________________________________________________
batchnormalization_52 (BatchNorma(None, None, None, 160320         convolution2d_52[0][0]           
____________________________________________________________________________________________________
batchnormalization_57 (BatchNorma(None, None, None, 160320         convolution2d_57[0][0]           
____________________________________________________________________________________________________
convolution2d_53 (Convolution2D) (None, None, None, 160179360      batchnormalization_52[0][0]      
____________________________________________________________________________________________________
convolution2d_58 (Convolution2D) (None, None, None, 160179360      batchnormalization_57[0][0]      
____________________________________________________________________________________________________
batchnormalization_53 (BatchNorma(None, None, None, 160320         convolution2d_53[0][0]           
____________________________________________________________________________________________________
batchnormalization_58 (BatchNorma(None, None, None, 160320         convolution2d_58[0][0]           
____________________________________________________________________________________________________
averagepooling2d_6 (AveragePoolin(None, None, None, 7680           mixed5[0][0]                     
____________________________________________________________________________________________________
convolution2d_51 (Convolution2D) (None, None, None, 192147648      mixed5[0][0]                     
____________________________________________________________________________________________________
convolution2d_54 (Convolution2D) (None, None, None, 192215232      batchnormalization_53[0][0]      
____________________________________________________________________________________________________
convolution2d_59 (Convolution2D) (None, None, None, 192215232      batchnormalization_58[0][0]      
____________________________________________________________________________________________________
convolution2d_60 (Convolution2D) (None, None, None, 192147648      averagepooling2d_6[0][0]         
____________________________________________________________________________________________________
batchnormalization_51 (BatchNorma(None, None, None, 192384         convolution2d_51[0][0]           
____________________________________________________________________________________________________
batchnormalization_54 (BatchNorma(None, None, None, 192384         convolution2d_54[0][0]           
____________________________________________________________________________________________________
batchnormalization_59 (BatchNorma(None, None, None, 192384         convolution2d_59[0][0]           
____________________________________________________________________________________________________
batchnormalization_60 (BatchNorma(None, None, None, 192384         convolution2d_60[0][0]           
____________________________________________________________________________________________________
mixed6 (Merge)                   (None, None, None, 7680           batchnormalization_51[0][0]      
                                                                   batchnormalization_54[0][0]      
                                                                   batchnormalization_59[0][0]      
                                                                   batchnormalization_60[0][0]      
____________________________________________________________________________________________________
convolution2d_65 (Convolution2D) (None, None, None, 160123040      mixed6[0][0]                     
____________________________________________________________________________________________________
batchnormalization_65 (BatchNorma(None, None, None, 160320         convolution2d_65[0][0]           
____________________________________________________________________________________________________
convolution2d_66 (Convolution2D) (None, None, None, 192215232      batchnormalization_65[0][0]      
____________________________________________________________________________________________________
batchnormalization_66 (BatchNorma(None, None, None, 192384         convolution2d_66[0][0]           
____________________________________________________________________________________________________
convolution2d_62 (Convolution2D) (None, None, None, 192147648      mixed6[0][0]                     
____________________________________________________________________________________________________
convolution2d_67 (Convolution2D) (None, None, None, 192258240      batchnormalization_66[0][0]      
____________________________________________________________________________________________________
batchnormalization_62 (BatchNorma(None, None, None, 192384         convolution2d_62[0][0]           
____________________________________________________________________________________________________
batchnormalization_67 (BatchNorma(None, None, None, 192384         convolution2d_67[0][0]           
____________________________________________________________________________________________________
convolution2d_63 (Convolution2D) (None, None, None, 192258240      batchnormalization_62[0][0]      
____________________________________________________________________________________________________
convolution2d_68 (Convolution2D) (None, None, None, 192258240      batchnormalization_67[0][0]      
____________________________________________________________________________________________________
batchnormalization_63 (BatchNorma(None, None, None, 192384         convolution2d_63[0][0]           
____________________________________________________________________________________________________
batchnormalization_68 (BatchNorma(None, None, None, 192384         convolution2d_68[0][0]           
____________________________________________________________________________________________________
averagepooling2d_7 (AveragePoolin(None, None, None, 7680           mixed6[0][0]                     
____________________________________________________________________________________________________
convolution2d_61 (Convolution2D) (None, None, None, 192147648      mixed6[0][0]                     
____________________________________________________________________________________________________
convolution2d_64 (Convolution2D) (None, None, None, 192258240      batchnormalization_63[0][0]      
____________________________________________________________________________________________________
convolution2d_69 (Convolution2D) (None, None, None, 192258240      batchnormalization_68[0][0]      
____________________________________________________________________________________________________
convolution2d_70 (Convolution2D) (None, None, None, 192147648      averagepooling2d_7[0][0]         
____________________________________________________________________________________________________
batchnormalization_61 (BatchNorma(None, None, None, 192384         convolution2d_61[0][0]           
____________________________________________________________________________________________________
batchnormalization_64 (BatchNorma(None, None, None, 192384         convolution2d_64[0][0]           
____________________________________________________________________________________________________
batchnormalization_69 (BatchNorma(None, None, None, 192384         convolution2d_69[0][0]           
____________________________________________________________________________________________________
batchnormalization_70 (BatchNorma(None, None, None, 192384         convolution2d_70[0][0]           
____________________________________________________________________________________________________
mixed7 (Merge)                   (None, None, None, 7680           batchnormalization_61[0][0]      
                                                                   batchnormalization_64[0][0]      
                                                                   batchnormalization_69[0][0]      
                                                                   batchnormalization_70[0][0]      
____________________________________________________________________________________________________
convolution2d_73 (Convolution2D) (None, None, None, 192147648      mixed7[0][0]                     
____________________________________________________________________________________________________
batchnormalization_73 (BatchNorma(None, None, None, 192384         convolution2d_73[0][0]           
____________________________________________________________________________________________________
convolution2d_74 (Convolution2D) (None, None, None, 192258240      batchnormalization_73[0][0]      
____________________________________________________________________________________________________
batchnormalization_74 (BatchNorma(None, None, None, 192384         convolution2d_74[0][0]           
____________________________________________________________________________________________________
convolution2d_71 (Convolution2D) (None, None, None, 192147648      mixed7[0][0]                     
____________________________________________________________________________________________________
convolution2d_75 (Convolution2D) (None, None, None, 192258240      batchnormalization_74[0][0]      
____________________________________________________________________________________________________
batchnormalization_71 (BatchNorma(None, None, None, 192384         convolution2d_71[0][0]           
____________________________________________________________________________________________________
batchnormalization_75 (BatchNorma(None, None, None, 192384         convolution2d_75[0][0]           
____________________________________________________________________________________________________
convolution2d_72 (Convolution2D) (None, None, None, 320553280      batchnormalization_71[0][0]      
____________________________________________________________________________________________________
convolution2d_76 (Convolution2D) (None, None, None, 192331968      batchnormalization_75[0][0]      
____________________________________________________________________________________________________
batchnormalization_72 (BatchNorma(None, None, None, 320640         convolution2d_72[0][0]           
____________________________________________________________________________________________________
batchnormalization_76 (BatchNorma(None, None, None, 192384         convolution2d_76[0][0]           
____________________________________________________________________________________________________
averagepooling2d_8 (AveragePoolin(None, None, None, 7680           mixed7[0][0]                     
____________________________________________________________________________________________________
mixed8 (Merge)                   (None, None, None, 1280           batchnormalization_72[0][0]      
                                                                   batchnormalization_76[0][0]      
                                                                   averagepooling2d_8[0][0]         
____________________________________________________________________________________________________
convolution2d_81 (Convolution2D) (None, None, None, 448573888      mixed8[0][0]                     
____________________________________________________________________________________________________
batchnormalization_81 (BatchNorma(None, None, None, 448896         convolution2d_81[0][0]           
____________________________________________________________________________________________________
convolution2d_78 (Convolution2D) (None, None, None, 384491904      mixed8[0][0]                     
____________________________________________________________________________________________________
convolution2d_82 (Convolution2D) (None, None, None, 3841548672     batchnormalization_81[0][0]      
____________________________________________________________________________________________________
batchnormalization_78 (BatchNorma(None, None, None, 384768         convolution2d_78[0][0]           
____________________________________________________________________________________________________
batchnormalization_82 (BatchNorma(None, None, None, 384768         convolution2d_82[0][0]           
____________________________________________________________________________________________________
convolution2d_79 (Convolution2D) (None, None, None, 384442752      batchnormalization_78[0][0]      
____________________________________________________________________________________________________
convolution2d_80 (Convolution2D) (None, None, None, 384442752      batchnormalization_78[0][0]      
____________________________________________________________________________________________________
convolution2d_83 (Convolution2D) (None, None, None, 384442752      batchnormalization_82[0][0]      
____________________________________________________________________________________________________
convolution2d_84 (Convolution2D) (None, None, None, 384442752      batchnormalization_82[0][0]      
____________________________________________________________________________________________________
averagepooling2d_9 (AveragePoolin(None, None, None, 1280           mixed8[0][0]                     
____________________________________________________________________________________________________
convolution2d_77 (Convolution2D) (None, None, None, 320409920      mixed8[0][0]                     
____________________________________________________________________________________________________
batchnormalization_79 (BatchNorma(None, None, None, 384768         convolution2d_79[0][0]           
____________________________________________________________________________________________________
batchnormalization_80 (BatchNorma(None, None, None, 384768         convolution2d_80[0][0]           
____________________________________________________________________________________________________
batchnormalization_83 (BatchNorma(None, None, None, 384768         convolution2d_83[0][0]           
____________________________________________________________________________________________________
batchnormalization_84 (BatchNorma(None, None, None, 384768         convolution2d_84[0][0]           
____________________________________________________________________________________________________
convolution2d_85 (Convolution2D) (None, None, None, 192245952      averagepooling2d_9[0][0]         
____________________________________________________________________________________________________
batchnormalization_77 (BatchNorma(None, None, None, 320640         convolution2d_77[0][0]           
____________________________________________________________________________________________________
mixed9_0 (Merge)                 (None, None, None, 7680           batchnormalization_79[0][0]      
                                                                   batchnormalization_80[0][0]      
____________________________________________________________________________________________________
merge_1 (Merge)                  (None, None, None, 7680           batchnormalization_83[0][0]      
                                                                   batchnormalization_84[0][0]      
____________________________________________________________________________________________________
batchnormalization_85 (BatchNorma(None, None, None, 192384         convolution2d_85[0][0]           
____________________________________________________________________________________________________
mixed9 (Merge)                   (None, None, None, 2040           batchnormalization_77[0][0]      
                                                                   mixed9_0[0][0]                   
                                                                   merge_1[0][0]                    
                                                                   batchnormalization_85[0][0]      
____________________________________________________________________________________________________
convolution2d_90 (Convolution2D) (None, None, None, 448917952      mixed9[0][0]                     
____________________________________________________________________________________________________
batchnormalization_90 (BatchNorma(None, None, None, 448896         convolution2d_90[0][0]           
____________________________________________________________________________________________________
convolution2d_87 (Convolution2D) (None, None, None, 384786816      mixed9[0][0]                     
____________________________________________________________________________________________________
convolution2d_91 (Convolution2D) (None, None, None, 3841548672     batchnormalization_90[0][0]      
____________________________________________________________________________________________________
batchnormalization_87 (BatchNorma(None, None, None, 384768         convolution2d_87[0][0]           
____________________________________________________________________________________________________
batchnormalization_91 (BatchNorma(None, None, None, 384768         convolution2d_91[0][0]           
____________________________________________________________________________________________________
convolution2d_88 (Convolution2D) (None, None, None, 384442752      batchnormalization_87[0][0]      
____________________________________________________________________________________________________
convolution2d_89 (Convolution2D) (None, None, None, 384442752      batchnormalization_87[0][0]      
____________________________________________________________________________________________________
convolution2d_92 (Convolution2D) (None, None, None, 384442752      batchnormalization_91[0][0]      
____________________________________________________________________________________________________
convolution2d_93 (Convolution2D) (None, None, None, 384442752      batchnormalization_91[0][0]      
____________________________________________________________________________________________________
averagepooling2d_10 (AveragePooli(None, None, None, 2040           mixed9[0][0]                     
____________________________________________________________________________________________________
convolution2d_86 (Convolution2D) (None, None, None, 320655680      mixed9[0][0]                     
____________________________________________________________________________________________________
batchnormalization_88 (BatchNorma(None, None, None, 384768         convolution2d_88[0][0]           
____________________________________________________________________________________________________
batchnormalization_89 (BatchNorma(None, None, None, 384768         convolution2d_89[0][0]           
____________________________________________________________________________________________________
batchnormalization_92 (BatchNorma(None, None, None, 384768         convolution2d_92[0][0]           
____________________________________________________________________________________________________
batchnormalization_93 (BatchNorma(None, None, None, 384768         convolution2d_93[0][0]           
____________________________________________________________________________________________________
convolution2d_94 (Convolution2D) (None, None, None, 192393408      averagepooling2d_10[0][0]        
____________________________________________________________________________________________________
batchnormalization_86 (BatchNorma(None, None, None, 320640         convolution2d_86[0][0]           
____________________________________________________________________________________________________
mixed9_1 (Merge)                 (None, None, None, 7680           batchnormalization_88[0][0]      
                                                                   batchnormalization_89[0][0]      
____________________________________________________________________________________________________
merge_2 (Merge)                  (None, None, None, 7680           batchnormalization_92[0][0]      
                                                                   batchnormalization_93[0][0]      
____________________________________________________________________________________________________
batchnormalization_94 (BatchNorma(None, None, None, 192384         convolution2d_94[0][0]           
____________________________________________________________________________________________________
mixed10 (Merge)                  (None, None, None, 2040           batchnormalization_86[0][0]      
                                                                   mixed9_1[0][0]                   
                                                                   merge_2[0][0]                    
                                                                   batchnormalization_94[0][0]      
====================================================================================================
Total params: 21577728
____________________________________________________________________________________________________
# 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(input=base_model.input, output=predictions)
tf
# 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(...)
  File "<ipython-input-11-af00eea935de>", line 2
    model.fit_generator(...)
                        ^
SyntaxError: invalid syntax
# 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)
(0, 'input_1')
(1, 'convolution2d_1')
(2, 'batchnormalization_1')
(3, 'convolution2d_2')
(4, 'batchnormalization_2')
(5, 'convolution2d_3')
(6, 'batchnormalization_3')
(7, 'maxpooling2d_1')
(8, 'convolution2d_4')
(9, 'batchnormalization_4')
(10, 'convolution2d_5')
(11, 'batchnormalization_5')
(12, 'maxpooling2d_2')
(13, 'convolution2d_9')
(14, 'batchnormalization_9')
(15, 'convolution2d_7')
(16, 'convolution2d_10')
(17, 'batchnormalization_7')
(18, 'batchnormalization_10')
(19, 'averagepooling2d_1')
(20, 'convolution2d_6')
(21, 'convolution2d_8')
(22, 'convolution2d_11')
(23, 'convolution2d_12')
(24, 'batchnormalization_6')
(25, 'batchnormalization_8')
(26, 'batchnormalization_11')
(27, 'batchnormalization_12')
(28, 'mixed0')
(29, 'convolution2d_16')
(30, 'batchnormalization_16')
(31, 'convolution2d_14')
(32, 'convolution2d_17')
(33, 'batchnormalization_14')
(34, 'batchnormalization_17')
(35, 'averagepooling2d_2')
(36, 'convolution2d_13')
(37, 'convolution2d_15')
(38, 'convolution2d_18')
(39, 'convolution2d_19')
(40, 'batchnormalization_13')
(41, 'batchnormalization_15')
(42, 'batchnormalization_18')
(43, 'batchnormalization_19')
(44, 'mixed1')
(45, 'convolution2d_23')
(46, 'batchnormalization_23')
(47, 'convolution2d_21')
(48, 'convolution2d_24')
(49, 'batchnormalization_21')
(50, 'batchnormalization_24')
(51, 'averagepooling2d_3')
(52, 'convolution2d_20')
(53, 'convolution2d_22')
(54, 'convolution2d_25')
(55, 'convolution2d_26')
(56, 'batchnormalization_20')
(57, 'batchnormalization_22')
(58, 'batchnormalization_25')
(59, 'batchnormalization_26')
(60, 'mixed2')
(61, 'convolution2d_28')
(62, 'batchnormalization_28')
(63, 'convolution2d_29')
(64, 'batchnormalization_29')
(65, 'convolution2d_27')
(66, 'convolution2d_30')
(67, 'batchnormalization_27')
(68, 'batchnormalization_30')
(69, 'maxpooling2d_3')
(70, 'mixed3')
(71, 'convolution2d_35')
(72, 'batchnormalization_35')
(73, 'convolution2d_36')
(74, 'batchnormalization_36')
(75, 'convolution2d_32')
(76, 'convolution2d_37')
(77, 'batchnormalization_32')
(78, 'batchnormalization_37')
(79, 'convolution2d_33')
(80, 'convolution2d_38')
(81, 'batchnormalization_33')
(82, 'batchnormalization_38')
(83, 'averagepooling2d_4')
(84, 'convolution2d_31')
(85, 'convolution2d_34')
(86, 'convolution2d_39')
(87, 'convolution2d_40')
(88, 'batchnormalization_31')
(89, 'batchnormalization_34')
(90, 'batchnormalization_39')
(91, 'batchnormalization_40')
(92, 'mixed4')
(93, 'convolution2d_45')
(94, 'batchnormalization_45')
(95, 'convolution2d_46')
(96, 'batchnormalization_46')
(97, 'convolution2d_42')
(98, 'convolution2d_47')
(99, 'batchnormalization_42')
(100, 'batchnormalization_47')
(101, 'convolution2d_43')
(102, 'convolution2d_48')
(103, 'batchnormalization_43')
(104, 'batchnormalization_48')
(105, 'averagepooling2d_5')
(106, 'convolution2d_41')
(107, 'convolution2d_44')
(108, 'convolution2d_49')
(109, 'convolution2d_50')
(110, 'batchnormalization_41')
(111, 'batchnormalization_44')
(112, 'batchnormalization_49')
(113, 'batchnormalization_50')
(114, 'mixed5')
(115, 'convolution2d_55')
(116, 'batchnormalization_55')
(117, 'convolution2d_56')
(118, 'batchnormalization_56')
(119, 'convolution2d_52')
(120, 'convolution2d_57')
(121, 'batchnormalization_52')
(122, 'batchnormalization_57')
(123, 'convolution2d_53')
(124, 'convolution2d_58')
(125, 'batchnormalization_53')
(126, 'batchnormalization_58')
(127, 'averagepooling2d_6')
(128, 'convolution2d_51')
(129, 'convolution2d_54')
(130, 'convolution2d_59')
(131, 'convolution2d_60')
(132, 'batchnormalization_51')
(133, 'batchnormalization_54')
(134, 'batchnormalization_59')
(135, 'batchnormalization_60')
(136, 'mixed6')
(137, 'convolution2d_65')
(138, 'batchnormalization_65')
(139, 'convolution2d_66')
(140, 'batchnormalization_66')
(141, 'convolution2d_62')
(142, 'convolution2d_67')
(143, 'batchnormalization_62')
(144, 'batchnormalization_67')
(145, 'convolution2d_63')
(146, 'convolution2d_68')
(147, 'batchnormalization_63')
(148, 'batchnormalization_68')
(149, 'averagepooling2d_7')
(150, 'convolution2d_61')
(151, 'convolution2d_64')
(152, 'convolution2d_69')
(153, 'convolution2d_70')
(154, 'batchnormalization_61')
(155, 'batchnormalization_64')
(156, 'batchnormalization_69')
(157, 'batchnormalization_70')
(158, 'mixed7')
(159, 'convolution2d_73')
(160, 'batchnormalization_73')
(161, 'convolution2d_74')
(162, 'batchnormalization_74')
(163, 'convolution2d_71')
(164, 'convolution2d_75')
(165, 'batchnormalization_71')
(166, 'batchnormalization_75')
(167, 'convolution2d_72')
(168, 'convolution2d_76')
(169, 'batchnormalization_72')
(170, 'batchnormalization_76')
(171, 'averagepooling2d_8')
(172, 'mixed8')
(173, 'convolution2d_81')
(174, 'batchnormalization_81')
(175, 'convolution2d_78')
(176, 'convolution2d_82')
(177, 'batchnormalization_78')
(178, 'batchnormalization_82')
(179, 'convolution2d_79')
(180, 'convolution2d_80')
(181, 'convolution2d_83')
(182, 'convolution2d_84')
(183, 'averagepooling2d_9')
(184, 'convolution2d_77')
(185, 'batchnormalization_79')
(186, 'batchnormalization_80')
(187, 'batchnormalization_83')
(188, 'batchnormalization_84')
(189, 'convolution2d_85')
(190, 'batchnormalization_77')
(191, 'mixed9_0')
(192, 'merge_1')
(193, 'batchnormalization_85')
(194, 'mixed9')
(195, 'convolution2d_90')
(196, 'batchnormalization_90')
(197, 'convolution2d_87')
(198, 'convolution2d_91')
(199, 'batchnormalization_87')
(200, 'batchnormalization_91')
(201, 'convolution2d_88')
(202, 'convolution2d_89')
(203, 'convolution2d_92')
(204, 'convolution2d_93')
(205, 'averagepooling2d_10')
(206, 'convolution2d_86')
(207, 'batchnormalization_88')
(208, 'batchnormalization_89')
(209, 'batchnormalization_92')
(210, 'batchnormalization_93')
(211, 'convolution2d_94')
(212, 'batchnormalization_86')
(213, 'mixed9_1')
(214, 'merge_2')
(215, 'batchnormalization_94')
(216, 'mixed10')
# we chose to train the top 2 inception blocks, i.e. we will freeze
# the first 172 layers and unfreeze the rest:
for layer in model.layers[:172]:
   layer.trainable = False
for layer in model.layers[172:]:
   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(...)

results matching ""

    No results matching ""