Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unknown layer: Mish" while loading converted model from "yolo4_weight.h5" #5

Closed
shangdibufashi opened this issue Apr 29, 2020 · 3 comments

Comments

@shangdibufashi
Copy link

Source code

from tensorflow import keras
new_model = keras.models.load_model('yolo4_weight.h5')

Error occurred:

Traceback (most recent call last):
  File "/home/source/keras-yolo4/mytest.py", line 13, in <module>
    new_model = keras.models.load_model(h5)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py", line 146, in load_model
    return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 212, in load_model_from_hdf5
    custom_objects=custom_objects)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/saving/model_config.py", line 55, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/layers/serialization.py", line 89, in deserialize
    printable_module_name='layer')
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 192, in deserialize_keras_object
    list(custom_objects.items())))
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1121, in from_config
    process_layer(layer_data)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1105, in process_layer
    layer = deserialize_layer(layer_data, custom_objects=custom_objects)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/layers/serialization.py", line 89, in deserialize
    printable_module_name='layer')
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 181, in deserialize_keras_object
    config, module_objects, custom_objects, printable_module_name)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 166, in class_and_config_for_serialized_keras_object
    raise ValueError('Unknown ' + printable_module_name + ': ' + class_name)
ValueError: Unknown layer: Mish
@shangdibufashi shangdibufashi changed the title "Unknown layer: Mish" while converting to loading model from yolo4_weight.h5 "Unknown layer: Mish" while loading converted model from "yolo4_weight.h5" Apr 29, 2020
@fcxmcc
Copy link

fcxmcc commented Apr 29, 2020

you can train your dataset to get the weight such as yolov3

@apupu1
Copy link

apupu1 commented Apr 29, 2020

You can try the following code:
import keras
from yolo4.model import Mish
mish = Mish()
infer_model = keras.models.load_model('yolo4_weight.h5',custom_objects={'Mish': mish})

@shangdibufashi
Copy link
Author

@apupu1 Works like a charm. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants