Python 将非符号张量传递给Keras Lambda层
我试图将Python 将非符号张量传递给Keras Lambda层,python,tensorflow,keras,Python,Tensorflow,Keras,我试图将RNNCell对象传递给Keras lambda层,以便在Keras模型中使用Tensorflow层,如下所示 conv_cell = ConvGRUCell(shape = [14, 14], filters = 32, kernel = [3,3], padding = 'SAME') def convGRU(inputs, cell, leng
RNNCell
对象传递给Keras lambda层,以便在Keras模型中使用Tensorflow层,如下所示
conv_cell = ConvGRUCell(shape = [14, 14],
filters = 32,
kernel = [3,3],
padding = 'SAME')
def convGRU(inputs, cell, length):
output, final = tf.nn.bidirectional_dynamic_rnn(
cell, cell, x, length, dtype=tf.float32)
output = tf.concat(output, -1)
final = tf.concat(final, -1)
return [output, final]
lm = Lambda(lambda x: convGRU(x[0], x[1], x[2])([input, conv_cell, length])
但是,我得到一个错误,即conv_cell
不是符号张量(它是基于Tensorflow的GRUCell的自定义层)
有没有办法把细胞传给lambda层?我让它与functools.partial一起工作,但它无法保存/加载模型,因为它无法访问模型内的函数
def convGRU(cell, length): # if length is produced by the model, use it with the inputs
def inner_func(inputs):
code...
return inner_func
lm = Lambda(convGRU(cell, length))(input)
对于保存/加载,您需要使用custom_objects={'convGRU':convGRU'cell':cell'length':length}
等。对于加载保存的模型,Keras不知道的任何内容都需要自动位于custom_objects
中
对于保存/加载,您需要使用custom_objects={'convGRU':convGRU'cell':cell'length':length}
等。对于加载保存的模型,Keras不知道的任何内容都需要自动位于custom_objects
中