python - Keras 合并层警告

标签 python deep-learning keras

我不断收到此警告:

lstm.py:119: UserWarning: The merge function is deprecated and will be removed after 08/2017. Use instead layers from keras.layers.merge, e.g. add, concatenate, etc. merged_vector = merge([l1, l2], mode=lambda x: (x[0] - x[1])**2, output_shape=lambda x: x[0]) /Library/Python/2.7/site-packages/keras/legacy/layers.py:456: UserWarning: The Merge layer is deprecated and will be removed after 08/2017. Use instead layers from keras.layers.merge, e.g. add, concatenate, etc. name=name)

与下面一行代码相关:

merged_vector = merge([l1, l2], mode=lambda x: (x[0] - x[1])**2, output_shape=lambda x: x[0])

我的模型工作正常,但如何在 Keras 2.0.2 中实现自定义合并?谢谢。

最佳答案

回答我自己的问题:

# Custom Merge
def euclid_dist(v):
    return (v[0] - v[1])**2

def out_shape(shapes):
    return shapes[0]

merged_vector = Lambda(euclid_dist, output_shape=out_shape)([l1, l2])

关于python - Keras 合并层警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43160181/

相关文章:

python - 请求 : Module works locally but failed on pythonanywhere

python - 使用 Python Flask/Connexion 和 Swagger 处理 API 中的图像

python - 使用 Python 更改 yaml 文件中的值

python - MySQL INSERT 在 Python 中失败,但在 MySQL Workbench 中工作正常

python - Keras 模型到 Theano 函数

tensorflow - 有没有办法在Keras框架中使用global_step?

tensorflow - 模型在训练时如何处理单个批处理的样本数量(顺序或并行)?

python - Tensorflow 2.0-GPU Windows 在CPU上运行训练代码

machine-learning - 了解计算机视觉卷积网络中滤波器的概念

python - 为什么深度学习 Keras 上的准确率总是 0.00%,损失很高