我正在尝试为RNN运行我的代码,但是遇到了这个错误:
ValueError:Shape必须为rank 2,但对于'echo_state_rnn_cell / MatMul_3'(op:'MatMul'),输入形状为[2,1,1000],[1000,1000] .
我不明白的是为什么我的张量有三个维度,它应该是[1,1000] .
我的代码是:
esn_init_state = np.zeros([1, res_size], dtype="float32")
tf.reset_default_graph() static_graph = tf.Graph() with static_graph.as_default() as g:
rng = np.random.RandomState(random_seed)
cell = EchoStateRNNCell(num_inputs=input_size, num_units=res_size, decay=0.1, leaky=leak,
epsilon=1e-10, alpha=0.0100, rng=rng)
X = tf.placeholder(tf.float32, [input_size+res_size, trainlen-initlen])
Yt = data[None, initlen+1:trainlen+1]
init_state = tf.placeholder(tf.float32, [1, res_size])
inputs = tf.placeholder(tf.float32, [trainlen,input_size]) #modifica postuma
state = init_state
for t in range(trainlen):
prev_state = state
state = cell(inputs=inputs[t:t+1,:], state=prev_state)
if t >= initlen:
X[:,t-initlen] = np.vstack((inputs,state))[:,0]
错误应该是: state = cell(inputs=inputs[t:t+1,:], state=prev_state)
.
这是细胞功能的定义:
def call(self, inputs, state):
new_state = (1 - self._leaky*self.decay) * state + self.decay*self._activation(math_ops.matmul(inputs,self.W) + math_ops.matmul(self._activation(state), self.U*self.rho_one))
output = self._activation(new_state)
return output, new_state
谢谢你的帮助!