2017-10-28 194 views
1

我定義了一個自定義的損失函數如下:Keras:自定義損失函數錯誤加載模型

weight_for_hierarchical_error = K.variable(np.ones(16)) 

def mse_weighted(y_true, y_pred): 
    return K.mean(weight_for_hierarchical_error * K.square(y_pred - y_true), axis=-1) 

當我保存在一個HDF5文件中的模型,然後嘗試用load_model加載它,我得到了以下錯誤信息:

ValueError: Unknown loss function:mse_weighted

有誰知道如何解決這個問題?

謝謝!

回答