I have a neural network with SeqSelfAttention (https://pypi.org/project/keras-self-attention/). Also I implemented a custom metric for F1. Then I saved the model without problems, but when the model is loaded using keras.models.load_model(model_path, custom_objects=SeqSelfAttention.get_custom_objects())

the next error is presented: ValueError: Unknown metric function: f1

If I coded with the F1 metric as: saved_model = load_model(Modelfilename, custom_objects={"f1": f1})

the error say:

ValueError: Unknown layer: SeqSelfAttention

Are there a way of combine the two parameters in "custom_objects"?

You need to use the custom_objects with dependencies term, check this code, I will explain line by line below:

iou_metric = train.iou_metric

dependencies = {'iou_metric': iou_metric}