当前,我正在seq2sql项目上工作,我被困在这一步。贝洛是我的代码。
inputs2=Input(shape=(C,3,100),name='col_tok')
col_lstm_layer=Bidirectional(LSTM(40,return_sequences=False),name='ColENC')
Col_last_hidden=tf.map_fn(lambda x:col_lstm_layer(x),
inputs2)
inputs2是一个4维张量,我想为inputs2中的每个元素调用col_lstm_layer。所以我的解决方案是这个,但它给出了以下错误。
Initializer for variable map_7/while/ColENC/forward_lstm_17/kernel/ is from inside a control-flow construct, such as a loop or conditional. When creating a variable inside a loop or conditional, use a lambda as the initializer.
我知道该错误表明解决方案是添加一个lambda函数,但如何正确执行。我使用lambda函数更改了代码,如下所示
Col_last_hidden=tf.map_fn(lambda x:col_lstm_layer(lambda:x),
inputs2)
但是它会给出错误信息。
Unexpectedly found an instance of type `<class 'function'>`. Expected a symbolic tensor instance.
During handling of the above exception, another exception occurred:
那么如何遍历4维张量并将3维张量传递给lstm层呢?请帮助我。