-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
Unable to Load Custom Objectives from an H5 Model File #3977
Comments
@StuartFarmer did you find a solution to your problem?
|
I think this information should be add to the doc: https://keras.io/models/model/ To Load Custom Objectives from an H5 Model File, e.g. load_model(modelPath, custom_objects={'mean_squared_abs_error': mean_squared_abs_error}) |
This may change with #5012; if not, we should submit a documentation pull request. |
@Neltherion Neltherion Thx. You save my day |
It did not work for me. I defined a custom function "dice_coef", then I also defined a custom objectives "dice_coef_loss" which is essentially -1* dice_coef. Then I compiled my model for training: After training and saving the model, it fails to load when I use above approach: Is there an option to also specify something like "custom_metric" in addition to "custom_objects"? |
I too have the same issue, but with a custom activation function. I tried the custom_objects={'my_activation' : my_activation} approach, but fails. It seems as if this function object is never even read or processed, since the same error message pops up when I do/don't include the custom_objects parameter using load_model. I also tried import keras.activations but nothing... I get the error "str(identifier)) Any help will be highly appreciated! :D |
Thanks CheRaissi! I tested and it works :)
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
|
@CheRaissi, def custom_loss_function(inputs): def custom_loss(y_true, y_pred): return custom_loss I am getting the following error Can you please help? |
I am experiencing exactly the same issue. I use a nested loss function like this because I have three inputs.
However, I received the following error: @CheRaissi any idea how to resolve this issue? |
I just found the solution here: #5916 The model has to be loaded with the following parameters: This solution works perfectly only if you're loading the model for prediction. |
@cememreakbas , that is a decorator problem, you can just custom_loss instead of custom_loss_function but you have to make sure that they share arguments, it would work, I am not sure if preventing your model to compile is a healthy thing |
Facing the same issue. Can anyone please help me on this. |
Hi I have same issue. Please help |
Traceback (most recent call last):
File "stoxnet-tester-0.0.2.py", line 75, in
model = load_model(filename)
File "C:\Users\stuart\Anaconda2\lib\site-packages\keras\models.py", line 155, in load_model
sample_weight_mode=sample_weight_mode)
File "C:\Users\stuart\Anaconda2\lib\site-packages\keras\models.py", line 547, in compile
**kwargs)
File "C:\Users\stuart\Anaconda2\lib\site-packages\keras\engine\training.py", line 537, in compile
loss_function = objectives.get(loss)
File "C:\Users\stuart\Anaconda2\lib\site-packages\keras\objectives.py", line 77, in get
return get_from_module(identifier, globals(), 'objective')
File "C:\Users\stuart\Anaconda2\lib\site-packages\keras\utils\generic_utils.py", line 16, in get_from_module
str(identifier))
Exception: Invalid objective: mean_squared_abs_error
def mean_squared_abs_error: as it exists in my original training script exists exactly as it does in the tester script.
The text was updated successfully, but these errors were encountered: