Guest User

Untitled

a guest
Jan 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. def add_batch_normalization(model_path):
  2. model = load_model(model_path)
  3. weights = model.get_weights()
  4. dense_idx = [index for index,layer in enumerate(model.layers) if type(layer) is Dense][-1] #get indices for dense layers
  5. x = model.layers[dense_idx -1].output
  6. new_model = Model(inputs = model.input, outputs = x)
  7. x= BatchNormalization()(new_model.output)
  8. x = Dense(2048, activation='relu')(x)
  9. x =BatchNormalization()(x)
  10. x = Dropout(.10)(x)
  11. x= Dense(512, activation='relu')(x)
  12. x= BatchNormalization()(x)
  13. predictions = Dense(num_of_classes, activation='softmax')(x)
  14. new_model = Model(inputs= new_model.input, outputs=predictions)
  15. print(new_model.summary())
  16. model.set_weights(weights)
  17. return new_model
Add Comment
Please, Sign In to add comment