1

I have Keras model in format .h5. I want to read it with this code:

#model.h5 is name of mode, tf and modellib is read

custom_objects={'tf': tf,'BatchNorm':modellib.BatchNorm,'ProposalLayer':
                modellib.ProposalLayer} 
model=tf.keras.models.load_model("model.h5")

But I getting an error

TypeError: init() missing 2 required positional arguments: 'proposal_count' and 'nms_threshold'

I have the newest version of TensorFlow (2.2). Changing the version of TensorFlow is not helping.

1
  • Seems that the custom layers you use are not implemented correctly, missing get_config() method most likely. Commented Mar 1, 2020 at 8:28

1 Answer 1

1

Based on the error and the custom objects i think you are tring to save the model of matterport/MaskRcnn, I ran in the same issue. The problem was that the custom layer ProposalLayer isn't correctly defined.

The parameters of the custom layer init should be initialized by default, otherwise an error may be reported:

TypeError: init() missing 2 required positional arguments: 'proposal_count' and 'nms_threshold'

I solved the issue in this way:

first of all i load the standard configuration in this way:

from mrcnn import config as config_std

thene i modify the init of the custom layer "ProposalLayer"

    def __init__(self,  proposal_count = config_std.Config.POST_NMS_ROIS_TRAINING, 
                    nms_threshold = config_std.Config.RPN_NMS_THRESHOLD, 
                    config=None, **kwargs):

I simply put the standard config passed in build function of the framework directly as default argument as keras need.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.