Type error for merge() function in Keras for 2d convolutional layer
I am trying to recreate the Inception model version 4. But i want to train it on my image data set standard shape (224,224,3)
,so i am not taking in any pretrained weights.
But I am getting an error like this.
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
TypeError: 'module' object is not callable
Here is the code:
def inception_stem(input):
if K.image_dim_ordering() == "th":
channel_axis = 1
else:
channel_axis = -1
# Input Shape is 299 x 299 x 3 (th) or 3 x 299 x 299 (th)
x = conv_block(input, 32, 3, 3, subsample=(2, 2), border_mode='valid')
x = conv_block(x, 32, 3, 3, border_mode='valid')
x = conv_block(x, 64, 3, 3)
x1 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x2 = conv_block(x, 96, 3, 3, subsample=(2, 2), border_mode='valid')
x = tf.concat([x1,x2],axis=channel_axis)
#x = merge([x1, x2], mode='concat', concat_axis=channel_axis) #here is the error occuring try find out the reason behind it
x1 = conv_block(x, 64, 1, 1)
x1 = conv_block(x1, 96, 3, 3, border_mode='valid')
x2 = conv_block(x, 64, 1, 1)
x2 = conv_block(x2, 64, 1, 7)
x2 = conv_block(x2, 64, 7, 1)
x2 = conv_block(x2, 96, 3, 3, border_mode='valid')
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
x1 = conv_block(x, 192, 3, 3, subsample=(2, 2), border_mode='valid')
x2 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
return x
I am using python 3.6
,keras 2.2.2
, tensorflow-gpu 1.9.0
.
I followed the GitHub for the issue, but the answers were not clear and exact.
Can anyone find the solution.
python-3.x tensorflow image-processing keras conv-neural-network
add a comment |
I am trying to recreate the Inception model version 4. But i want to train it on my image data set standard shape (224,224,3)
,so i am not taking in any pretrained weights.
But I am getting an error like this.
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
TypeError: 'module' object is not callable
Here is the code:
def inception_stem(input):
if K.image_dim_ordering() == "th":
channel_axis = 1
else:
channel_axis = -1
# Input Shape is 299 x 299 x 3 (th) or 3 x 299 x 299 (th)
x = conv_block(input, 32, 3, 3, subsample=(2, 2), border_mode='valid')
x = conv_block(x, 32, 3, 3, border_mode='valid')
x = conv_block(x, 64, 3, 3)
x1 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x2 = conv_block(x, 96, 3, 3, subsample=(2, 2), border_mode='valid')
x = tf.concat([x1,x2],axis=channel_axis)
#x = merge([x1, x2], mode='concat', concat_axis=channel_axis) #here is the error occuring try find out the reason behind it
x1 = conv_block(x, 64, 1, 1)
x1 = conv_block(x1, 96, 3, 3, border_mode='valid')
x2 = conv_block(x, 64, 1, 1)
x2 = conv_block(x2, 64, 1, 7)
x2 = conv_block(x2, 64, 7, 1)
x2 = conv_block(x2, 96, 3, 3, border_mode='valid')
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
x1 = conv_block(x, 192, 3, 3, subsample=(2, 2), border_mode='valid')
x2 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
return x
I am using python 3.6
,keras 2.2.2
, tensorflow-gpu 1.9.0
.
I followed the GitHub for the issue, but the answers were not clear and exact.
Can anyone find the solution.
python-3.x tensorflow image-processing keras conv-neural-network
add a comment |
I am trying to recreate the Inception model version 4. But i want to train it on my image data set standard shape (224,224,3)
,so i am not taking in any pretrained weights.
But I am getting an error like this.
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
TypeError: 'module' object is not callable
Here is the code:
def inception_stem(input):
if K.image_dim_ordering() == "th":
channel_axis = 1
else:
channel_axis = -1
# Input Shape is 299 x 299 x 3 (th) or 3 x 299 x 299 (th)
x = conv_block(input, 32, 3, 3, subsample=(2, 2), border_mode='valid')
x = conv_block(x, 32, 3, 3, border_mode='valid')
x = conv_block(x, 64, 3, 3)
x1 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x2 = conv_block(x, 96, 3, 3, subsample=(2, 2), border_mode='valid')
x = tf.concat([x1,x2],axis=channel_axis)
#x = merge([x1, x2], mode='concat', concat_axis=channel_axis) #here is the error occuring try find out the reason behind it
x1 = conv_block(x, 64, 1, 1)
x1 = conv_block(x1, 96, 3, 3, border_mode='valid')
x2 = conv_block(x, 64, 1, 1)
x2 = conv_block(x2, 64, 1, 7)
x2 = conv_block(x2, 64, 7, 1)
x2 = conv_block(x2, 96, 3, 3, border_mode='valid')
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
x1 = conv_block(x, 192, 3, 3, subsample=(2, 2), border_mode='valid')
x2 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
return x
I am using python 3.6
,keras 2.2.2
, tensorflow-gpu 1.9.0
.
I followed the GitHub for the issue, but the answers were not clear and exact.
Can anyone find the solution.
python-3.x tensorflow image-processing keras conv-neural-network
I am trying to recreate the Inception model version 4. But i want to train it on my image data set standard shape (224,224,3)
,so i am not taking in any pretrained weights.
But I am getting an error like this.
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
TypeError: 'module' object is not callable
Here is the code:
def inception_stem(input):
if K.image_dim_ordering() == "th":
channel_axis = 1
else:
channel_axis = -1
# Input Shape is 299 x 299 x 3 (th) or 3 x 299 x 299 (th)
x = conv_block(input, 32, 3, 3, subsample=(2, 2), border_mode='valid')
x = conv_block(x, 32, 3, 3, border_mode='valid')
x = conv_block(x, 64, 3, 3)
x1 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x2 = conv_block(x, 96, 3, 3, subsample=(2, 2), border_mode='valid')
x = tf.concat([x1,x2],axis=channel_axis)
#x = merge([x1, x2], mode='concat', concat_axis=channel_axis) #here is the error occuring try find out the reason behind it
x1 = conv_block(x, 64, 1, 1)
x1 = conv_block(x1, 96, 3, 3, border_mode='valid')
x2 = conv_block(x, 64, 1, 1)
x2 = conv_block(x2, 64, 1, 7)
x2 = conv_block(x2, 64, 7, 1)
x2 = conv_block(x2, 96, 3, 3, border_mode='valid')
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
x1 = conv_block(x, 192, 3, 3, subsample=(2, 2), border_mode='valid')
x2 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
return x
I am using python 3.6
,keras 2.2.2
, tensorflow-gpu 1.9.0
.
I followed the GitHub for the issue, but the answers were not clear and exact.
Can anyone find the solution.
python-3.x tensorflow image-processing keras conv-neural-network
python-3.x tensorflow image-processing keras conv-neural-network
asked Nov 24 '18 at 12:43
user10573543user10573543
227
227
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Use the concatenate layer, that should help you
from tensorflow.python.keras.layers import concatenate
x = concatenate([x1, x2], axis=channel_axis)
return x
i tried this but i am getting an errror like this after using the concatenate. method.'Got inputs shapes: %s' % (input_shape)) ValueError: AConcatenate
layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 74, 74, 64), (None, 75, 75, 96)]
– user10573543
Nov 26 '18 at 5:50
Yeah you need to compulsory have tensors of same dimension in all axes but for the concat axis. In your case it should either be [(None, 74, 74, 64), (None, 74, 74, 96)] or [(None, 75, 75, 64), (None, 75, 75, 96)]. I suggest you to check the shapes of previous layers
– Srihari Humbarwadi
Nov 26 '18 at 6:04
well in the conventional inception model v4 they are using no padding, so when i concat the two layers it will have different dimensions.So i used padding equal to same to overcome this issue.Is there a way i can concatenate layers with two different shapes without using padding.
– user10573543
Nov 26 '18 at 7:21
You can add padding to get them to same shape, but concatenate layer would never work with different shapes in axes other than the concat axis
– Srihari Humbarwadi
Nov 26 '18 at 7:25
Thank you for the insights. I ll consider this as the answer and close this issue.
– user10573543
Nov 26 '18 at 7:56
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%2f53458266%2ftype-error-for-merge-function-in-keras-for-2d-convolutional-layer%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
Use the concatenate layer, that should help you
from tensorflow.python.keras.layers import concatenate
x = concatenate([x1, x2], axis=channel_axis)
return x
i tried this but i am getting an errror like this after using the concatenate. method.'Got inputs shapes: %s' % (input_shape)) ValueError: AConcatenate
layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 74, 74, 64), (None, 75, 75, 96)]
– user10573543
Nov 26 '18 at 5:50
Yeah you need to compulsory have tensors of same dimension in all axes but for the concat axis. In your case it should either be [(None, 74, 74, 64), (None, 74, 74, 96)] or [(None, 75, 75, 64), (None, 75, 75, 96)]. I suggest you to check the shapes of previous layers
– Srihari Humbarwadi
Nov 26 '18 at 6:04
well in the conventional inception model v4 they are using no padding, so when i concat the two layers it will have different dimensions.So i used padding equal to same to overcome this issue.Is there a way i can concatenate layers with two different shapes without using padding.
– user10573543
Nov 26 '18 at 7:21
You can add padding to get them to same shape, but concatenate layer would never work with different shapes in axes other than the concat axis
– Srihari Humbarwadi
Nov 26 '18 at 7:25
Thank you for the insights. I ll consider this as the answer and close this issue.
– user10573543
Nov 26 '18 at 7:56
add a comment |
Use the concatenate layer, that should help you
from tensorflow.python.keras.layers import concatenate
x = concatenate([x1, x2], axis=channel_axis)
return x
i tried this but i am getting an errror like this after using the concatenate. method.'Got inputs shapes: %s' % (input_shape)) ValueError: AConcatenate
layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 74, 74, 64), (None, 75, 75, 96)]
– user10573543
Nov 26 '18 at 5:50
Yeah you need to compulsory have tensors of same dimension in all axes but for the concat axis. In your case it should either be [(None, 74, 74, 64), (None, 74, 74, 96)] or [(None, 75, 75, 64), (None, 75, 75, 96)]. I suggest you to check the shapes of previous layers
– Srihari Humbarwadi
Nov 26 '18 at 6:04
well in the conventional inception model v4 they are using no padding, so when i concat the two layers it will have different dimensions.So i used padding equal to same to overcome this issue.Is there a way i can concatenate layers with two different shapes without using padding.
– user10573543
Nov 26 '18 at 7:21
You can add padding to get them to same shape, but concatenate layer would never work with different shapes in axes other than the concat axis
– Srihari Humbarwadi
Nov 26 '18 at 7:25
Thank you for the insights. I ll consider this as the answer and close this issue.
– user10573543
Nov 26 '18 at 7:56
add a comment |
Use the concatenate layer, that should help you
from tensorflow.python.keras.layers import concatenate
x = concatenate([x1, x2], axis=channel_axis)
return x
Use the concatenate layer, that should help you
from tensorflow.python.keras.layers import concatenate
x = concatenate([x1, x2], axis=channel_axis)
return x
answered Nov 24 '18 at 14:48
Srihari HumbarwadiSrihari Humbarwadi
17010
17010
i tried this but i am getting an errror like this after using the concatenate. method.'Got inputs shapes: %s' % (input_shape)) ValueError: AConcatenate
layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 74, 74, 64), (None, 75, 75, 96)]
– user10573543
Nov 26 '18 at 5:50
Yeah you need to compulsory have tensors of same dimension in all axes but for the concat axis. In your case it should either be [(None, 74, 74, 64), (None, 74, 74, 96)] or [(None, 75, 75, 64), (None, 75, 75, 96)]. I suggest you to check the shapes of previous layers
– Srihari Humbarwadi
Nov 26 '18 at 6:04
well in the conventional inception model v4 they are using no padding, so when i concat the two layers it will have different dimensions.So i used padding equal to same to overcome this issue.Is there a way i can concatenate layers with two different shapes without using padding.
– user10573543
Nov 26 '18 at 7:21
You can add padding to get them to same shape, but concatenate layer would never work with different shapes in axes other than the concat axis
– Srihari Humbarwadi
Nov 26 '18 at 7:25
Thank you for the insights. I ll consider this as the answer and close this issue.
– user10573543
Nov 26 '18 at 7:56
add a comment |
i tried this but i am getting an errror like this after using the concatenate. method.'Got inputs shapes: %s' % (input_shape)) ValueError: AConcatenate
layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 74, 74, 64), (None, 75, 75, 96)]
– user10573543
Nov 26 '18 at 5:50
Yeah you need to compulsory have tensors of same dimension in all axes but for the concat axis. In your case it should either be [(None, 74, 74, 64), (None, 74, 74, 96)] or [(None, 75, 75, 64), (None, 75, 75, 96)]. I suggest you to check the shapes of previous layers
– Srihari Humbarwadi
Nov 26 '18 at 6:04
well in the conventional inception model v4 they are using no padding, so when i concat the two layers it will have different dimensions.So i used padding equal to same to overcome this issue.Is there a way i can concatenate layers with two different shapes without using padding.
– user10573543
Nov 26 '18 at 7:21
You can add padding to get them to same shape, but concatenate layer would never work with different shapes in axes other than the concat axis
– Srihari Humbarwadi
Nov 26 '18 at 7:25
Thank you for the insights. I ll consider this as the answer and close this issue.
– user10573543
Nov 26 '18 at 7:56
i tried this but i am getting an errror like this after using the concatenate. method.'Got inputs shapes: %s' % (input_shape)) ValueError: A
Concatenate
layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 74, 74, 64), (None, 75, 75, 96)]– user10573543
Nov 26 '18 at 5:50
i tried this but i am getting an errror like this after using the concatenate. method.'Got inputs shapes: %s' % (input_shape)) ValueError: A
Concatenate
layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 74, 74, 64), (None, 75, 75, 96)]– user10573543
Nov 26 '18 at 5:50
Yeah you need to compulsory have tensors of same dimension in all axes but for the concat axis. In your case it should either be [(None, 74, 74, 64), (None, 74, 74, 96)] or [(None, 75, 75, 64), (None, 75, 75, 96)]. I suggest you to check the shapes of previous layers
– Srihari Humbarwadi
Nov 26 '18 at 6:04
Yeah you need to compulsory have tensors of same dimension in all axes but for the concat axis. In your case it should either be [(None, 74, 74, 64), (None, 74, 74, 96)] or [(None, 75, 75, 64), (None, 75, 75, 96)]. I suggest you to check the shapes of previous layers
– Srihari Humbarwadi
Nov 26 '18 at 6:04
well in the conventional inception model v4 they are using no padding, so when i concat the two layers it will have different dimensions.So i used padding equal to same to overcome this issue.Is there a way i can concatenate layers with two different shapes without using padding.
– user10573543
Nov 26 '18 at 7:21
well in the conventional inception model v4 they are using no padding, so when i concat the two layers it will have different dimensions.So i used padding equal to same to overcome this issue.Is there a way i can concatenate layers with two different shapes without using padding.
– user10573543
Nov 26 '18 at 7:21
You can add padding to get them to same shape, but concatenate layer would never work with different shapes in axes other than the concat axis
– Srihari Humbarwadi
Nov 26 '18 at 7:25
You can add padding to get them to same shape, but concatenate layer would never work with different shapes in axes other than the concat axis
– Srihari Humbarwadi
Nov 26 '18 at 7:25
Thank you for the insights. I ll consider this as the answer and close this issue.
– user10573543
Nov 26 '18 at 7:56
Thank you for the insights. I ll consider this as the answer and close this issue.
– user10573543
Nov 26 '18 at 7:56
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%2f53458266%2ftype-error-for-merge-function-in-keras-for-2d-convolutional-layer%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