【问题标题】:Tensorflow layer in keras [duplicate]keras中的Tensorflow层[重复]
【发布时间】:2018-08-24 08:29:30
【问题描述】:

我们如何在 keras 中使用来自tf.contrib.layers 的层?

我尝试将 tf 层混合到我的其他 keras 层中。

input = Input(shape=state_shape)
conv = Conv2D(64, (6, 6), strides=(1, 1), activation='relu')(input)
spatial_softmax = tf.contrib.layers.spatial_softmax(conv, name='spatial_softmax', data_format='NHWC')
fc = Dense(128, activation='relu')(spatial_softmax)
fc = Dense(128, activation='relu')(fc)
output = Dense(action_size, activation='softmax')(fc)

Model(inputs=input, outputs=output)

但是当我运行代码时出现以下错误

AttributeError: 'Tensor' object has no attribute '_keras_history'

有什么想法吗?

谢谢!

编辑:这与here 的问题不同,我要求的是具有可训练权重的层而不是确定性层。渐变会反向传播到图层吗?

【问题讨论】:

    标签: tensorflow keras


    【解决方案1】:

    我相信您需要将其放在 Lambda 层中:

    spatial_softmax = Lambda(lambda x: spatial_softmax(x, name='spatial_softmax',
                             data_format='NHWC'))(conv)
    

    【讨论】:

    猜你喜欢
    • 2021-12-18
    • 2017-12-12
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 2020-06-16
    • 2020-06-16
    • 2018-04-20
    相关资源
    最近更新 更多