Replacing LSTMBlockCell with LSTMBlockFusedCell throws an error. The full error message:
Traceback (most recent call last):
File "Classification-DL_ULSTM4.py", line 81, in <module>
logits=ULSTM(x_,n_input,n_hidden,n_steps,n_classes)
File "Classification-DL_ULSTM4.py", line 25, in ULSTM
outputs,_=lstm_cell(x,dtype=tf.float32)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/layers/base.py", line 548, in __call__
outputs = super(Layer, self).__call__(inputs, *args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/keras/engine/base_layer.py", line 819, in __call__
self.name)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/keras/engine/input_spec.py", line 155, in assert_input_compatibility
' input tensors. Inputs received: ' + str(inputs))
ValueError: Layer lstm_fused_cell expects 1 inputs, but it received 250 input tensors. Inputs received: [<tf.Tensor 'split:0' shape=(?, 1) dtype=float32>, <tf.Tensor 'split:1' shape=(?, 1) dtype=float32>
previews code
def ULSTM(x,n_input,n_hidden,n_steps,n_classes):
x=tf.transpose(x,[1,0,2])
x=tf.reshape(x,[-1,n_input])
x=tf.split(x,n_steps)
lstm_cell=tf.contrib.rnn.LSTMBlockCell(n_hidden,forget_bias=1.0)
outputs,_=tf.contrib.rnn.static_rnn(lstm_cell,x,dtype=tf.float32)
what I replace
lstm_cell=tf.contrib.rnn.LSTMBlockFusedCell(n_hidden,forget_bias=1.0)
outputs,_=lstm_cell(x,dtype=tf.float32)
args
n_input=1
n_hidden=1
n_steps=250
n_classes=4
tic=time.time()
x=tf.placeholder(tf.float32, [None, 250])
x_=tf.reshape(x,[-1,250,1])
y_=tf.placeholder(tf.float32,[None,4])
logits=ULSTM(x_,n_input,n_hidden,n_steps,n_classes)
learning_rate=0.001
batch_size=16
maxiters=10000
I know LSTMBlockFusedCell is inherited from FusedRNNCell instead of RNNCell, so I cannot use standard tf.nn.static_rnn or tf.nn.dynamic_rnn in which they require RNNCell instance.But I don't know how to change it without error.