【发布时间】:2020-05-11 16:24:42
【问题描述】:
我正在构建一个自动编码器,我的数据中有 NaN 值。如何创建自定义 (MSE) 损失函数,如果在验证数据中遇到 NaN,则不计算损失?
从网上得到提示:
def nan_mse(y_actual, y_predicted):
per_instance = tf.where(tf.is_nan(y_actual),
tf.zeros_like(y_actual),
tf.square(tf.subtract(y_predicted, y_actual)))
return tf.reduce_mean(per_instance, axis=0)
但收到 NaN 的损失:
纪元 1/50 - 25s - 损失:nan
当我尝试在回调函数中使用自定义损失函数时,在每个 epoch 之后:
predictions = autoencoder.predict(x_pred)
mae = (nan_mse(x_pred, predictions))
TypeError: 'Select' Op 的输入 'e' 的 float32 类型与参数 't' 的 float64 类型不匹配。
【问题讨论】:
标签: python tensorflow keras autoencoder