7

How do I take an existing model and create a new one that has batchnormalisation after each dropout layer?

I have tried this:

bn = []
for layer in model.layers:
    bn.append(layer)
    if type(layer) is Dropout:
        bn.append(BatchNormalization())
bn = Sequential(bn)
bn.summary()

Looking at the summary it has inserted the new layers. However in the "connected to" column it lists the predecessor twice; if I run it n times it lists each predecessor n+1 times.

For example in the "connected to" for a maxpool layer:

convolution2d_394[0][0]          
                                                                 convolution2d_394[1][0]          
                                                                   convolution2d_394[2][0]          
                                                                   convolution2d_394[3][0]          
                                                                   convolution2d_394[4][0]          
                                                                   convolution2d_394[5][0]          
                                                                   convolution2d_394[6][0]          
                                                                   convolution2d_394[7][0]          
                                                                   convolution2d_394[8][0]          
                                                                   convolution2d_394[9][0]    
simon
  • 2,561
  • 16
  • 26
  • You have to copy the weights of all the layers from the old network and assign them to specific layers in the new one. You can name the layers in your old network and give same names to the *corresponding* layers in the new network. Then assign the weights using layer names as discussed [here](https://github.com/fchollet/keras/issues/1873). You can also do this manually, but it will be error prone and will take more time. – Autonomous Apr 08 '17 at 10:47

0 Answers0