def save_model_to_json(modeljsonfname): layers = get_feature_layers(backbone_name, 4) if backbone_type == 'FPN': model = FPN(input_shape=(None, None, num_channels), classes=num_mask_channels, encoder_weights=encoder_weights, backbone_name=backbone_name, activation=act_fcn, encoder_features=layers) elif backbone_type == 'Unet': model = Unet(input_shape=(None, None, num_channels), classes=num_mask_channels, encoder_weights=encoder_weights, backbone_name=backbone_name, activation=act_fcn, encoder_features=layers) #model.summary() # serialize model to JSON model_json = model.to_json() with open(modeljsonfname, "w") as json_file: json_file.write(model_json)
save_name = 'weights/' + args.backbone + '.h5' callbacks_list = [ ModelCheckpoint(save_name, monitor='loss', verbose=1, save_best_only=True, mode='min', save_weights_only=True), ReduceLROnPlateau(monitor='loss', factor=0.2, patience=2, min_lr=1e-5) ] model.compile(optimizer=Adam(1e-4), loss=custom_loss, metrics=[dice_coef, jaccard_coef, mean_iou]) history = model.fit_generator(generator, steps_per_epoch=3000, epochs=10, verbose=1, callbacks=callbacks_list) model_json = model.to_json() json_file = open('models/' + args.backbone + '.json', 'w') json_file.write(model_json) json_file.close() print('Model saved!') K.clear_session() print('Cache cleared')