Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_batch_normalization(model_path):
- model = load_model(model_path)
- weights = model.get_weights()
- dense_idx = [index for index,layer in enumerate(model.layers) if type(layer) is Dense][-1] #get indices for dense layers
- x = model.layers[dense_idx -1].output
- new_model = Model(inputs = model.input, outputs = x)
- x= BatchNormalization()(new_model.output)
- x = Dense(2048, activation='relu')(x)
- x =BatchNormalization()(x)
- x = Dropout(.10)(x)
- x= Dense(512, activation='relu')(x)
- x= BatchNormalization()(x)
- predictions = Dense(num_of_classes, activation='softmax')(x)
- new_model = Model(inputs= new_model.input, outputs=predictions)
- print(new_model.summary())
- model.set_weights(weights)
- return new_model
Add Comment
Please, Sign In to add comment