在tf.keras.layers.Lambda中包装一个函数

时间:2019-07-14 05:07:22

标签: keras keras-layer tf.keras

我具有以下功能:

import tensorflow.keras.layers as tks

def conv_bn_acttivation(x, filters, kernel_size, strides, data_format, activation=relu, is_training=False, name=None):
   conv = tks.Conv2D(....)(x)
   bn = tks.BatchNormalization()(conv, is_training)
   if activation:
      return activation(bn)
   return bn

现在,我想使用tf.cond

conv =  conv_bn_acttivation(x,....)
short_cut = tf.cond(
        tf.equal(input_channels, filters),
        tks.Lambda(lambda: x), # identity
        tks.Lambda(lambda: conv_bn_activation(x=x, filters=filters, kernel_size=1, strides=1,data_format=data_format))

result = conv + short_cut

我在false_fn中遇到此错误 TypeError:__call __()缺少1个必需的位置参数:“ inputs” ?!

0 个答案:

没有答案