Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将非符号张量传递给Keras Lambda层_Python_Tensorflow_Keras - Fatal编程技术网

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