Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法加载带有自定义度量的keras模型_Keras - Fatal编程技术网

无法加载带有自定义度量的keras模型

无法加载带有自定义度量的keras模型,keras,Keras,嗨,我想在keras上制作一个超分辨率模型 我指的是 但是在我编译并保存了一个新模型之后,当我加载该模型时,就会出现度量错误 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/ker

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

我指的是

但是在我编译并保存了一个新模型之后,当我加载该模型时,就会出现度量错误

    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
有没有办法加载具有PSNR度量的模型


谢谢阅读。

加载模型(“ani.model”,自定义对象={“PSNRLoss”: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 = Convolution2D(32,shape[0],shape[1],  activation='relu', border_mode='same', name='level2')(x)

    out = Convolution2D(3, shape[0],shape[1],  border_mode='same', name='output')(x)

    model = Model(input_img, out)
    #model.compile(optimizer='adadelta', loss='binary_crossentropy')
    adam = optimizers.Adam(lr=1e-3)
    model.compile(optimizer=adam, loss='mse', metrics=[PSNRLoss])

    return model

path = "./picture/"

if not os.path.exists("./ani.model"):
    ani_model =  create_model()
    ani_model.save("./ani.model")

load_model("./ani.model")