ValueError:形状必须为2级,但为3级

时间:2018-11-22 09:19:18

标签: python tensorflow

我正在尝试为RNN运行代码,但出现此错误:

  

ValueError:形状必须为“ echo_state_rnn_cell / MatMul_3”(操作数:“ MatMul”)的形状为2级,但其输入形状为[2,1,1000],[1000,1000]则为3级。

我不明白的是为什么我的张量具有三个维度,应该为[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   

感谢您的帮助!

0 个答案:

没有答案
相关问题