ValueError: Shape must be rank 2 but is rank 3
I'm trying to run my code for a RNN, but got this error:
ValueError: Shape must be rank 2 but is rank 3 for 'echo_state_rnn_cell/MatMul_3' (op: 'MatMul') with input shapes: [2,1,1000], [1000,1000].
The thing that I don't understand is why my tensor has three dimensions, it should be [1,1000].
My code is:
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]
The error should be in: state = cell(inputs=inputs[t:t+1,:], state=prev_state)
.
Here is the definition of cell function:
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
Thanks for your help!
python tensorflow
add a comment |
I'm trying to run my code for a RNN, but got this error:
ValueError: Shape must be rank 2 but is rank 3 for 'echo_state_rnn_cell/MatMul_3' (op: 'MatMul') with input shapes: [2,1,1000], [1000,1000].
The thing that I don't understand is why my tensor has three dimensions, it should be [1,1000].
My code is:
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]
The error should be in: state = cell(inputs=inputs[t:t+1,:], state=prev_state)
.
Here is the definition of cell function:
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
Thanks for your help!
python tensorflow
add a comment |
I'm trying to run my code for a RNN, but got this error:
ValueError: Shape must be rank 2 but is rank 3 for 'echo_state_rnn_cell/MatMul_3' (op: 'MatMul') with input shapes: [2,1,1000], [1000,1000].
The thing that I don't understand is why my tensor has three dimensions, it should be [1,1000].
My code is:
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]
The error should be in: state = cell(inputs=inputs[t:t+1,:], state=prev_state)
.
Here is the definition of cell function:
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
Thanks for your help!
python tensorflow
I'm trying to run my code for a RNN, but got this error:
ValueError: Shape must be rank 2 but is rank 3 for 'echo_state_rnn_cell/MatMul_3' (op: 'MatMul') with input shapes: [2,1,1000], [1000,1000].
The thing that I don't understand is why my tensor has three dimensions, it should be [1,1000].
My code is:
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]
The error should be in: state = cell(inputs=inputs[t:t+1,:], state=prev_state)
.
Here is the definition of cell function:
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
Thanks for your help!
python tensorflow
python tensorflow
edited Nov 22 '18 at 11:14


Anubhav Singh
1431212
1431212
asked Nov 22 '18 at 9:19
nabbonabbo
12
12
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427489%2fvalueerror-shape-must-be-rank-2-but-is-rank-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427489%2fvalueerror-shape-must-be-rank-2-but-is-rank-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown