Tensorflow Dense label shape
I'm new to using Tensorflow and Python, I've seen all tutorial in the website and now I'm working with my first real dataset.
What I want to do with the NN is to predict some power plant energy consumes knowing the daily trends. I have an .xlsx file with all those (real) values. Using Pandas I'splitted and normalized the data in train set and validation set (i.e. train_x and train_y, where train_x is the time and train_y is the label). The x and y array are both numpy.ndarray and formatted as below (just the head):
print(train_x)
[ 644]
[ 645]
[ 646]
print(train_y)
[-0.09154356 1.10702972 1.13661838]
[ 0.05104414 1.39112378 1.5319337 ]
[-0.05719421 1.40702419 1.48187637]
Then I created the model:
model = keras.Sequential([
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape([0]))),
keras.layers.Dense(3, activation=tf.nn.softmax)])
model.compile(loss='categorical_cross_entropy',
optimizer='Adam',
metrics=['accuracy'])
history = model.fit(train_x, train_y, epochs=5, verbose=1)
But when I run the script I got this error:
TypeError: 'tuple' object is not callable
I guess the problem is about the input shape of the layer or maybe of the loss function as is suggested here, so I tried to modify the loss function in:
LOSS = tf.nn.categorical_cross_entropy_with_logits(logits=3, labels=3)
and, of course, the model.compile:
model.compile(loss=LOSS,
optimizer='Adam',
metrics=['accuracy'])
but I got the same error again:
TypeError: 'tuple' object is not callable
Where I go wrong?
python tensorflow
add a comment |
I'm new to using Tensorflow and Python, I've seen all tutorial in the website and now I'm working with my first real dataset.
What I want to do with the NN is to predict some power plant energy consumes knowing the daily trends. I have an .xlsx file with all those (real) values. Using Pandas I'splitted and normalized the data in train set and validation set (i.e. train_x and train_y, where train_x is the time and train_y is the label). The x and y array are both numpy.ndarray and formatted as below (just the head):
print(train_x)
[ 644]
[ 645]
[ 646]
print(train_y)
[-0.09154356 1.10702972 1.13661838]
[ 0.05104414 1.39112378 1.5319337 ]
[-0.05719421 1.40702419 1.48187637]
Then I created the model:
model = keras.Sequential([
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape([0]))),
keras.layers.Dense(3, activation=tf.nn.softmax)])
model.compile(loss='categorical_cross_entropy',
optimizer='Adam',
metrics=['accuracy'])
history = model.fit(train_x, train_y, epochs=5, verbose=1)
But when I run the script I got this error:
TypeError: 'tuple' object is not callable
I guess the problem is about the input shape of the layer or maybe of the loss function as is suggested here, so I tried to modify the loss function in:
LOSS = tf.nn.categorical_cross_entropy_with_logits(logits=3, labels=3)
and, of course, the model.compile:
model.compile(loss=LOSS,
optimizer='Adam',
metrics=['accuracy'])
but I got the same error again:
TypeError: 'tuple' object is not callable
Where I go wrong?
python tensorflow
add a comment |
I'm new to using Tensorflow and Python, I've seen all tutorial in the website and now I'm working with my first real dataset.
What I want to do with the NN is to predict some power plant energy consumes knowing the daily trends. I have an .xlsx file with all those (real) values. Using Pandas I'splitted and normalized the data in train set and validation set (i.e. train_x and train_y, where train_x is the time and train_y is the label). The x and y array are both numpy.ndarray and formatted as below (just the head):
print(train_x)
[ 644]
[ 645]
[ 646]
print(train_y)
[-0.09154356 1.10702972 1.13661838]
[ 0.05104414 1.39112378 1.5319337 ]
[-0.05719421 1.40702419 1.48187637]
Then I created the model:
model = keras.Sequential([
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape([0]))),
keras.layers.Dense(3, activation=tf.nn.softmax)])
model.compile(loss='categorical_cross_entropy',
optimizer='Adam',
metrics=['accuracy'])
history = model.fit(train_x, train_y, epochs=5, verbose=1)
But when I run the script I got this error:
TypeError: 'tuple' object is not callable
I guess the problem is about the input shape of the layer or maybe of the loss function as is suggested here, so I tried to modify the loss function in:
LOSS = tf.nn.categorical_cross_entropy_with_logits(logits=3, labels=3)
and, of course, the model.compile:
model.compile(loss=LOSS,
optimizer='Adam',
metrics=['accuracy'])
but I got the same error again:
TypeError: 'tuple' object is not callable
Where I go wrong?
python tensorflow
I'm new to using Tensorflow and Python, I've seen all tutorial in the website and now I'm working with my first real dataset.
What I want to do with the NN is to predict some power plant energy consumes knowing the daily trends. I have an .xlsx file with all those (real) values. Using Pandas I'splitted and normalized the data in train set and validation set (i.e. train_x and train_y, where train_x is the time and train_y is the label). The x and y array are both numpy.ndarray and formatted as below (just the head):
print(train_x)
[ 644]
[ 645]
[ 646]
print(train_y)
[-0.09154356 1.10702972 1.13661838]
[ 0.05104414 1.39112378 1.5319337 ]
[-0.05719421 1.40702419 1.48187637]
Then I created the model:
model = keras.Sequential([
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape([0]))),
keras.layers.Dense(3, activation=tf.nn.softmax)])
model.compile(loss='categorical_cross_entropy',
optimizer='Adam',
metrics=['accuracy'])
history = model.fit(train_x, train_y, epochs=5, verbose=1)
But when I run the script I got this error:
TypeError: 'tuple' object is not callable
I guess the problem is about the input shape of the layer or maybe of the loss function as is suggested here, so I tried to modify the loss function in:
LOSS = tf.nn.categorical_cross_entropy_with_logits(logits=3, labels=3)
and, of course, the model.compile:
model.compile(loss=LOSS,
optimizer='Adam',
metrics=['accuracy'])
but I got the same error again:
TypeError: 'tuple' object is not callable
Where I go wrong?
python tensorflow
python tensorflow
asked Nov 17 '18 at 12:12
Riccardo QuagliaRiccardo Quaglia
62
62
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
it should be array.shape[0]
,not array.shape([0])
. shape
is an attribute of a numpy array, not a method. The correct syntax should be:
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape[-1],)),
Also, change train_x
and train_y
to 2d arrays, with the shape of [length_of_array,1].
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%2f53351130%2ftensorflow-dense-label-shape%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
it should be array.shape[0]
,not array.shape([0])
. shape
is an attribute of a numpy array, not a method. The correct syntax should be:
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape[-1],)),
Also, change train_x
and train_y
to 2d arrays, with the shape of [length_of_array,1].
add a comment |
it should be array.shape[0]
,not array.shape([0])
. shape
is an attribute of a numpy array, not a method. The correct syntax should be:
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape[-1],)),
Also, change train_x
and train_y
to 2d arrays, with the shape of [length_of_array,1].
add a comment |
it should be array.shape[0]
,not array.shape([0])
. shape
is an attribute of a numpy array, not a method. The correct syntax should be:
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape[-1],)),
Also, change train_x
and train_y
to 2d arrays, with the shape of [length_of_array,1].
it should be array.shape[0]
,not array.shape([0])
. shape
is an attribute of a numpy array, not a method. The correct syntax should be:
keras.layers.Dense(64, activation=tf.nn.relu, input_shape= (train_x.shape[-1],)),
Also, change train_x
and train_y
to 2d arrays, with the shape of [length_of_array,1].
edited Nov 17 '18 at 13:53
answered Nov 17 '18 at 12:58
SidSid
216
216
add a comment |
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%2f53351130%2ftensorflow-dense-label-shape%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