tensorflow placeholder shape [None] [None,1] difference
I am new to tensorflow. I experimented a DQN algorithm with a section involving
a = tf.placeholder(tf.int32, shape = [None],name='A')
q = tf.reduce_sum(critic_q * tf.one_hot(a,n_outputs),axis=1,keepdims=True,name='Q')#Q value for chosen action
y = tf.placeholder(tf.float32, shape = [None],name='Y')
learning_rate = 1e-4
cost = tf.reduce_mean(tf.square(y-q))#mean squared error
global_step = tf.Variable(0,trainable=False,name='global_step')
optimizer = tf.train.AdamOptimizer(learning_rate)
training_op = optimizer.minimize(cost,global_step=global_step)
and initialized the input y with y_batch=np.zeros(nbatch)
. The network hardly trained at all.
Then, I switched to defining y as
y = tf.placeholder(tf.float32, shape = [None,1],name='Y')
and initialized the input with y_batch=np.zeros(nbatch).reshape(-1,1)
, which worked nicely.
What was happening in the first implementation?
python tensorflow
add a comment |
I am new to tensorflow. I experimented a DQN algorithm with a section involving
a = tf.placeholder(tf.int32, shape = [None],name='A')
q = tf.reduce_sum(critic_q * tf.one_hot(a,n_outputs),axis=1,keepdims=True,name='Q')#Q value for chosen action
y = tf.placeholder(tf.float32, shape = [None],name='Y')
learning_rate = 1e-4
cost = tf.reduce_mean(tf.square(y-q))#mean squared error
global_step = tf.Variable(0,trainable=False,name='global_step')
optimizer = tf.train.AdamOptimizer(learning_rate)
training_op = optimizer.minimize(cost,global_step=global_step)
and initialized the input y with y_batch=np.zeros(nbatch)
. The network hardly trained at all.
Then, I switched to defining y as
y = tf.placeholder(tf.float32, shape = [None,1],name='Y')
and initialized the input with y_batch=np.zeros(nbatch).reshape(-1,1)
, which worked nicely.
What was happening in the first implementation?
python tensorflow
add a comment |
I am new to tensorflow. I experimented a DQN algorithm with a section involving
a = tf.placeholder(tf.int32, shape = [None],name='A')
q = tf.reduce_sum(critic_q * tf.one_hot(a,n_outputs),axis=1,keepdims=True,name='Q')#Q value for chosen action
y = tf.placeholder(tf.float32, shape = [None],name='Y')
learning_rate = 1e-4
cost = tf.reduce_mean(tf.square(y-q))#mean squared error
global_step = tf.Variable(0,trainable=False,name='global_step')
optimizer = tf.train.AdamOptimizer(learning_rate)
training_op = optimizer.minimize(cost,global_step=global_step)
and initialized the input y with y_batch=np.zeros(nbatch)
. The network hardly trained at all.
Then, I switched to defining y as
y = tf.placeholder(tf.float32, shape = [None,1],name='Y')
and initialized the input with y_batch=np.zeros(nbatch).reshape(-1,1)
, which worked nicely.
What was happening in the first implementation?
python tensorflow
I am new to tensorflow. I experimented a DQN algorithm with a section involving
a = tf.placeholder(tf.int32, shape = [None],name='A')
q = tf.reduce_sum(critic_q * tf.one_hot(a,n_outputs),axis=1,keepdims=True,name='Q')#Q value for chosen action
y = tf.placeholder(tf.float32, shape = [None],name='Y')
learning_rate = 1e-4
cost = tf.reduce_mean(tf.square(y-q))#mean squared error
global_step = tf.Variable(0,trainable=False,name='global_step')
optimizer = tf.train.AdamOptimizer(learning_rate)
training_op = optimizer.minimize(cost,global_step=global_step)
and initialized the input y with y_batch=np.zeros(nbatch)
. The network hardly trained at all.
Then, I switched to defining y as
y = tf.placeholder(tf.float32, shape = [None,1],name='Y')
and initialized the input with y_batch=np.zeros(nbatch).reshape(-1,1)
, which worked nicely.
What was happening in the first implementation?
python tensorflow
python tensorflow
asked Jan 1 at 6:57
user15988user15988
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Every tensor has a rank (number of dimensions) and a set of dimensions.
A placeholder with shape [1]
is a placeholder with rank 1 and the dimension in position 0 of 1.
A placeholder with shape [None, 1]
is a placeholder with rank 2, hence it has 2 dimensions. The first dimension (index 0) has unknown size (it will be resolved at runtime) while the second dimension (index 1) has the known size of 1.
In order to be compatible, tensors must have the same rank a dimensions.
You can read a more complete assessment about the tensors shape here: https://pgaleone.eu/tensorflow/2018/07/28/understanding-tensorflow-tensors-shape-static-dynamic/#tensors-the-basic
I suppose you are implying that q has a dimension [None,1] as well. What happens when you make an operation of y-q, when y has dimension [None]?
– user15988
Jan 1 at 18:40
Tensorflow operations use the broadcasting semantics, that's well explained here: docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html (it uses the same semantics of numpy). Hence, if there's a1
dimension, the data of one operand is duplicated and the operation is repeated
– nessuno
Jan 1 at 19:51
add a comment |
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%2f53993596%2ftensorflow-placeholder-shape-none-none-1-difference%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Every tensor has a rank (number of dimensions) and a set of dimensions.
A placeholder with shape [1]
is a placeholder with rank 1 and the dimension in position 0 of 1.
A placeholder with shape [None, 1]
is a placeholder with rank 2, hence it has 2 dimensions. The first dimension (index 0) has unknown size (it will be resolved at runtime) while the second dimension (index 1) has the known size of 1.
In order to be compatible, tensors must have the same rank a dimensions.
You can read a more complete assessment about the tensors shape here: https://pgaleone.eu/tensorflow/2018/07/28/understanding-tensorflow-tensors-shape-static-dynamic/#tensors-the-basic
I suppose you are implying that q has a dimension [None,1] as well. What happens when you make an operation of y-q, when y has dimension [None]?
– user15988
Jan 1 at 18:40
Tensorflow operations use the broadcasting semantics, that's well explained here: docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html (it uses the same semantics of numpy). Hence, if there's a1
dimension, the data of one operand is duplicated and the operation is repeated
– nessuno
Jan 1 at 19:51
add a comment |
Every tensor has a rank (number of dimensions) and a set of dimensions.
A placeholder with shape [1]
is a placeholder with rank 1 and the dimension in position 0 of 1.
A placeholder with shape [None, 1]
is a placeholder with rank 2, hence it has 2 dimensions. The first dimension (index 0) has unknown size (it will be resolved at runtime) while the second dimension (index 1) has the known size of 1.
In order to be compatible, tensors must have the same rank a dimensions.
You can read a more complete assessment about the tensors shape here: https://pgaleone.eu/tensorflow/2018/07/28/understanding-tensorflow-tensors-shape-static-dynamic/#tensors-the-basic
I suppose you are implying that q has a dimension [None,1] as well. What happens when you make an operation of y-q, when y has dimension [None]?
– user15988
Jan 1 at 18:40
Tensorflow operations use the broadcasting semantics, that's well explained here: docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html (it uses the same semantics of numpy). Hence, if there's a1
dimension, the data of one operand is duplicated and the operation is repeated
– nessuno
Jan 1 at 19:51
add a comment |
Every tensor has a rank (number of dimensions) and a set of dimensions.
A placeholder with shape [1]
is a placeholder with rank 1 and the dimension in position 0 of 1.
A placeholder with shape [None, 1]
is a placeholder with rank 2, hence it has 2 dimensions. The first dimension (index 0) has unknown size (it will be resolved at runtime) while the second dimension (index 1) has the known size of 1.
In order to be compatible, tensors must have the same rank a dimensions.
You can read a more complete assessment about the tensors shape here: https://pgaleone.eu/tensorflow/2018/07/28/understanding-tensorflow-tensors-shape-static-dynamic/#tensors-the-basic
Every tensor has a rank (number of dimensions) and a set of dimensions.
A placeholder with shape [1]
is a placeholder with rank 1 and the dimension in position 0 of 1.
A placeholder with shape [None, 1]
is a placeholder with rank 2, hence it has 2 dimensions. The first dimension (index 0) has unknown size (it will be resolved at runtime) while the second dimension (index 1) has the known size of 1.
In order to be compatible, tensors must have the same rank a dimensions.
You can read a more complete assessment about the tensors shape here: https://pgaleone.eu/tensorflow/2018/07/28/understanding-tensorflow-tensors-shape-static-dynamic/#tensors-the-basic
answered Jan 1 at 13:01
nessunonessuno
14.7k34348
14.7k34348
I suppose you are implying that q has a dimension [None,1] as well. What happens when you make an operation of y-q, when y has dimension [None]?
– user15988
Jan 1 at 18:40
Tensorflow operations use the broadcasting semantics, that's well explained here: docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html (it uses the same semantics of numpy). Hence, if there's a1
dimension, the data of one operand is duplicated and the operation is repeated
– nessuno
Jan 1 at 19:51
add a comment |
I suppose you are implying that q has a dimension [None,1] as well. What happens when you make an operation of y-q, when y has dimension [None]?
– user15988
Jan 1 at 18:40
Tensorflow operations use the broadcasting semantics, that's well explained here: docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html (it uses the same semantics of numpy). Hence, if there's a1
dimension, the data of one operand is duplicated and the operation is repeated
– nessuno
Jan 1 at 19:51
I suppose you are implying that q has a dimension [None,1] as well. What happens when you make an operation of y-q, when y has dimension [None]?
– user15988
Jan 1 at 18:40
I suppose you are implying that q has a dimension [None,1] as well. What happens when you make an operation of y-q, when y has dimension [None]?
– user15988
Jan 1 at 18:40
Tensorflow operations use the broadcasting semantics, that's well explained here: docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html (it uses the same semantics of numpy). Hence, if there's a
1
dimension, the data of one operand is duplicated and the operation is repeated– nessuno
Jan 1 at 19:51
Tensorflow operations use the broadcasting semantics, that's well explained here: docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html (it uses the same semantics of numpy). Hence, if there's a
1
dimension, the data of one operand is duplicated and the operation is repeated– nessuno
Jan 1 at 19:51
add a comment |
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%2f53993596%2ftensorflow-placeholder-shape-none-none-1-difference%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