Convolution2D gives wrong output shape in Keras
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm following tutorial from here and have stuck with simple model creation
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3), activation='relu', input_shape=(1, 28, 28)))
model.output_shape
This should give (None, 32, 26, 26)
output but instead I get (None, -1, 26, 32)
. I guess something wrong with parameters provided or I need to make additional reshape. Maybe something has been changed for Convolution2D
and Conv2D
in Keras? I'm running 2.2.4
with Theano
backend
python machine-learning keras theano convolution
add a comment |
I'm following tutorial from here and have stuck with simple model creation
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3), activation='relu', input_shape=(1, 28, 28)))
model.output_shape
This should give (None, 32, 26, 26)
output but instead I get (None, -1, 26, 32)
. I guess something wrong with parameters provided or I need to make additional reshape. Maybe something has been changed for Convolution2D
and Conv2D
in Keras? I'm running 2.2.4
with Theano
backend
python machine-learning keras theano convolution
I get InvalidArgumentError with your code.
– Tzomas
Nov 16 '18 at 12:13
@Tzomas check keras version you are running, probably you have old one
– Most Wanted
Nov 16 '18 at 15:04
add a comment |
I'm following tutorial from here and have stuck with simple model creation
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3), activation='relu', input_shape=(1, 28, 28)))
model.output_shape
This should give (None, 32, 26, 26)
output but instead I get (None, -1, 26, 32)
. I guess something wrong with parameters provided or I need to make additional reshape. Maybe something has been changed for Convolution2D
and Conv2D
in Keras? I'm running 2.2.4
with Theano
backend
python machine-learning keras theano convolution
I'm following tutorial from here and have stuck with simple model creation
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3), activation='relu', input_shape=(1, 28, 28)))
model.output_shape
This should give (None, 32, 26, 26)
output but instead I get (None, -1, 26, 32)
. I guess something wrong with parameters provided or I need to make additional reshape. Maybe something has been changed for Convolution2D
and Conv2D
in Keras? I'm running 2.2.4
with Theano
backend
python machine-learning keras theano convolution
python machine-learning keras theano convolution
edited Nov 16 '18 at 12:09
Mihai Alexandru-Ionut
30.7k64375
30.7k64375
asked Nov 16 '18 at 12:06
Most WantedMost Wanted
1,14721733
1,14721733
I get InvalidArgumentError with your code.
– Tzomas
Nov 16 '18 at 12:13
@Tzomas check keras version you are running, probably you have old one
– Most Wanted
Nov 16 '18 at 15:04
add a comment |
I get InvalidArgumentError with your code.
– Tzomas
Nov 16 '18 at 12:13
@Tzomas check keras version you are running, probably you have old one
– Most Wanted
Nov 16 '18 at 15:04
I get InvalidArgumentError with your code.
– Tzomas
Nov 16 '18 at 12:13
I get InvalidArgumentError with your code.
– Tzomas
Nov 16 '18 at 12:13
@Tzomas check keras version you are running, probably you have old one
– Most Wanted
Nov 16 '18 at 15:04
@Tzomas check keras version you are running, probably you have old one
– Most Wanted
Nov 16 '18 at 15:04
add a comment |
3 Answers
3
active
oldest
votes
It seems that the channels are in the first axis of input data. Therefore, you need to set data_format
argument to "channels_first"
:
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3),
data_format='channels_first',
activation='relu', input_shape=(1, 28, 28)))
model.output_shape
Which gives:
(None, 32, 26, 26)
perfect, works like a charm
– Most Wanted
Nov 16 '18 at 15:03
add a comment |
The problem is that it uses Theano as a backend and probably you are using tensorflow (you should check your setting once again). You can change it with:
import os
os.environ['KERAS_BACKEND'] = 'theano'
This should be done before importing keras
add a comment |
Well like I wrote in my comment. I got a error with your code. So see that it looks like you have bad shape on input, if you change to input_shape=(28,28,1)
then output_shape returns (None, 26, 26, 32)
I don't know if this is what you are exactly looking for.
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%2f53337586%2fconvolution2d-gives-wrong-output-shape-in-keras%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
It seems that the channels are in the first axis of input data. Therefore, you need to set data_format
argument to "channels_first"
:
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3),
data_format='channels_first',
activation='relu', input_shape=(1, 28, 28)))
model.output_shape
Which gives:
(None, 32, 26, 26)
perfect, works like a charm
– Most Wanted
Nov 16 '18 at 15:03
add a comment |
It seems that the channels are in the first axis of input data. Therefore, you need to set data_format
argument to "channels_first"
:
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3),
data_format='channels_first',
activation='relu', input_shape=(1, 28, 28)))
model.output_shape
Which gives:
(None, 32, 26, 26)
perfect, works like a charm
– Most Wanted
Nov 16 '18 at 15:03
add a comment |
It seems that the channels are in the first axis of input data. Therefore, you need to set data_format
argument to "channels_first"
:
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3),
data_format='channels_first',
activation='relu', input_shape=(1, 28, 28)))
model.output_shape
Which gives:
(None, 32, 26, 26)
It seems that the channels are in the first axis of input data. Therefore, you need to set data_format
argument to "channels_first"
:
model = Sequential()
model.add(Convolution2D(32, kernel_size=(3, 3),
data_format='channels_first',
activation='relu', input_shape=(1, 28, 28)))
model.output_shape
Which gives:
(None, 32, 26, 26)
answered Nov 16 '18 at 12:44
todaytoday
11.6k22239
11.6k22239
perfect, works like a charm
– Most Wanted
Nov 16 '18 at 15:03
add a comment |
perfect, works like a charm
– Most Wanted
Nov 16 '18 at 15:03
perfect, works like a charm
– Most Wanted
Nov 16 '18 at 15:03
perfect, works like a charm
– Most Wanted
Nov 16 '18 at 15:03
add a comment |
The problem is that it uses Theano as a backend and probably you are using tensorflow (you should check your setting once again). You can change it with:
import os
os.environ['KERAS_BACKEND'] = 'theano'
This should be done before importing keras
add a comment |
The problem is that it uses Theano as a backend and probably you are using tensorflow (you should check your setting once again). You can change it with:
import os
os.environ['KERAS_BACKEND'] = 'theano'
This should be done before importing keras
add a comment |
The problem is that it uses Theano as a backend and probably you are using tensorflow (you should check your setting once again). You can change it with:
import os
os.environ['KERAS_BACKEND'] = 'theano'
This should be done before importing keras
The problem is that it uses Theano as a backend and probably you are using tensorflow (you should check your setting once again). You can change it with:
import os
os.environ['KERAS_BACKEND'] = 'theano'
This should be done before importing keras
answered Nov 16 '18 at 12:17
GabeGabe
322210
322210
add a comment |
add a comment |
Well like I wrote in my comment. I got a error with your code. So see that it looks like you have bad shape on input, if you change to input_shape=(28,28,1)
then output_shape returns (None, 26, 26, 32)
I don't know if this is what you are exactly looking for.
add a comment |
Well like I wrote in my comment. I got a error with your code. So see that it looks like you have bad shape on input, if you change to input_shape=(28,28,1)
then output_shape returns (None, 26, 26, 32)
I don't know if this is what you are exactly looking for.
add a comment |
Well like I wrote in my comment. I got a error with your code. So see that it looks like you have bad shape on input, if you change to input_shape=(28,28,1)
then output_shape returns (None, 26, 26, 32)
I don't know if this is what you are exactly looking for.
Well like I wrote in my comment. I got a error with your code. So see that it looks like you have bad shape on input, if you change to input_shape=(28,28,1)
then output_shape returns (None, 26, 26, 32)
I don't know if this is what you are exactly looking for.
answered Nov 16 '18 at 12:22
TzomasTzomas
517314
517314
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%2f53337586%2fconvolution2d-gives-wrong-output-shape-in-keras%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
I get InvalidArgumentError with your code.
– Tzomas
Nov 16 '18 at 12:13
@Tzomas check keras version you are running, probably you have old one
– Most Wanted
Nov 16 '18 at 15:04