keras的“未知损失函数"定义自定义损失函数后出现错误 [英] keras "unknown loss function" error after defining custom loss function

查看:279
本文介绍了keras的“未知损失函数"定义自定义损失函数后出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在loss.py文件中的keras中定义了一个新的损失函数.我关闭并重新启动anaconda提示符,但得到了ValueError: ('Unknown loss function', ':binary_crossentropy_2').我正在Windows 10上使用python2.7和anaconda运行keras.

I defined a new loss function in keras in losses.py file. I close and relaunch anaconda prompt, but I got ValueError: ('Unknown loss function', ':binary_crossentropy_2'). I'm running keras using python2.7 and anaconda on windows 10.

我通过在编译模型的python文件中添加损失函数来暂时解决该问题.

I temporarily solve it by adding the loss function in the python file I compile my model.

推荐答案

在Keras中,我们必须在load_model函数中传递自定义函数:

In Keras we have to pass the custom functions in the load_model function:

def my_custom_func():
    # your code
    return
from keras.models import load_model
model = load_model('my_model.h5', custom_objects={'my_custom_func':                   
my_custom_func})

这篇关于keras的“未知损失函数"定义自定义损失函数后出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆