Keras-retinanet: TypeError: ('Keyword argument not understood:', 'freeze') while testing the model

Created on 8 Jan 2018  Â·  14Comments  Â·  Source: fizyr/keras-retinanet

Hi, I have trained a model w.r.t. VOC2012 dataset (only training set, no validation data). I am using the latest versions of keras-retinate, keras-resnet, Keras 2.1.2, Python 3.6. The training was Ok. However, then I was using the trained model to test new images, I got an error from:
".\Continuum\anaconda3\lib\site-packages\keras\engine\topology.py", line 280, in __init__
raise TypeError('Keyword argument not understood:', kwarg)
TypeError: ('Keyword argument not understood:', 'freeze').

I think the reason is that resnet = keras_resnet.models.ResNet50(image, include_top=False, freeze_bn=True) is used in ResNet50RetinaNet. I have tried to set freeze_bn=False, but still got the same error.

Could anybody help me with this? Something I did wrong? Thanks a lot.

Most helpful comment

@de-vri-es
I found out that this happens when you trained a model with a previous version of the repo, update the repo or try to use the saved model with a newer version of the repo.

I couldn't find a way to use the previously trained model, it's a big inconvenient due to the long training times. The work around, sadly, is to retrain on the new version of the repo.

All 14 comments

I think you should load-model like this
model = keras.models.load_model('/path/to/model.h5', custom_objects=custom_objects)

It works for me

Thank you very much. Then should I use:

custom_objects = retinanet.custom_objects.copy()
custom_objects.update(keras_resnet.custom_objects)

as the custom objects?

Yep

Thanks a lot.

Note that we already provide a ready to use custom_objects dictionary for retinet with a resnet backend:
https://github.com/fizyr/keras-retinanet/blob/e3f9fc6105aa3968bc3fb9be491e62525a17e593/keras_retinanet/models/resnet.py#L26-L27

So you can also use keras_retinanet.models.resnet.custom_objects directly. It is constructed exactly like you posted.

and my loaded model is like this:

model_path = os.path.join('/devdata2/chenandong/keras-retinanet-fizyr/models', 'resnet50_coco_best_v1.2.2.h5')

model = keras.models.load_model(model_path, custom_objects=custom_objects)

but still have TypeError

File "/home/chenandong/keras-retinanet-fizyr/keras_retinanet/layers/_misc.py", line 83, in __init__
    super(NonMaximumSuppression, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/topology.py", line 292, in __init__
    raise TypeError('Keyword argument not understood:', kwarg)
TypeError: ('Keyword argument not understood:', 'top_k')

could help me ? thanks very much

I'm having the same issue here :/

Same :(

@de-vri-es
I found out that this happens when you trained a model with a previous version of the repo, update the repo or try to use the saved model with a newer version of the repo.

I couldn't find a way to use the previously trained model, it's a big inconvenient due to the long training times. The work around, sadly, is to retrain on the new version of the repo.

There's an easier workaround. Create a new model with the new repo and call
model.load_weights(old_weights_path, by_name=True)

The weights are still compatible (depending on how old your network really
is), but the architecture slightly changed.

On Wed, 4 Apr 2018, 19:52 Diego, notifications@github.com wrote:

@de-vri-es https://github.com/de-vri-es
I found out that this happens when you trained a model with a previous
version of the repo, update the repo or try to use the saved model with a
newer version of the repo.

I couldn't find a way to use the previously trained model, it's a big
inconvenient due to the long training times. The work around, sadly, is to
retrain on the new version of the repo.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/fizyr/keras-retinanet/issues/214#issuecomment-378741235,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AArtauleMsK-Xh5AfVY7a9mrvzlvt9eIks5tlTKHgaJpZM4RWDIt
.

@hgaiser Thanks! I'll give it a try and let you know if it did

Hey, I want to know what should I do when I call my model like this?

def get_model():
    # load json and create model
    json_file = open('/path/to/model/darknet/python/model_1/model.json', 'r')
    loaded_model_json = json_file.read()
    json_file.close()

    loaded_model = model_from_json(loaded_model_json)
    # load weights into new model
    config = tf.ConfigProto()
    config.gpu_options.per_process_gpu_memory_fraction = 0.5
    config.gpu_options.visible_device_list = "0"
    set_session(tf.Session(config=config))
    loaded_model.load_weights("/path/to/model/darknet/python/model_1/model_new.h5")

    loaded_model.compile(loss='binary_crossentropy',
                         optimizer='rmsprop',
                         metrics=['accuracy'])
    return loaded_model

What should I do when I get this error?

raise TypeError('Keyword argument not understood:', kwarg)
TypeError: ('Keyword argument not understood:', 'data_format')

Thank you very much. Then should I use:

custom_objects = retinanet.custom_objects.copy()
custom_objects.update(keras_resnet.custom_objects)

as the custom objects?

@junyongyou or @huangcong77 Could you elaborate on how and where you implemented this code to load the custom objects? Can't get this to work for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mayur-who picture mayur-who  Â·  5Comments

ztf-ucas picture ztf-ucas  Â·  3Comments

Doodle1106 picture Doodle1106  Â·  3Comments

RudyChin picture RudyChin  Â·  4Comments

wassname picture wassname  Â·  6Comments