小编박호민*_*박호민的帖子

无法使用自定义指标加载keras模型

嗨,我想在keras上制作超分辨率模型.

我指的是https://github.com/titu1994/Image-Super-Resolution.

但是在编译并保存新模型之后,当我加载模型时,会发生度量标准错误

    Traceback (most recent call last):
  File "autoencoder2.py", line 56, in <module>
    load_model("./ani.model")
  File "/home/simmani91/anaconda2/lib/python2.7/site-packages/keras/models.py", line 155, in load_model
    sample_weight_mode=sample_weight_mode)
  File "/home/simmani91/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 665, in compile
    metric_fn = metrics_module.get(metric)
  File "/home/simmani91/anaconda2/lib/python2.7/site-packages/keras/metrics.py", line 84, in get
    return get_from_module(identifier, globals(), 'metric')
  File "/home/simmani91/anaconda2/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 14, in get_from_module
    str(identifier))
Exception: Invalid metric: PSNRLoss
Run Code Online (Sandbox Code Playgroud)

这是我的度量代码(PSNRLoss),创建模型,执行

def PSNRLoss(y_true, y_pred):
    return -10. * np.log10(K.mean(K.square(y_pred - y_true)))

def create_model():
    shape = (360,640,3)
    input_img = Input(shape=shape)

    x = Convolution2D(64, shape[0],shape[1], activation='relu', border_mode='same', name='level1')(input_img)
    x …
Run Code Online (Sandbox Code Playgroud)

keras

15
推荐指数
1
解决办法
3138
查看次数

标签 统计

keras ×1