(Keras-Tensorflow) How to crop an output tensor depending on another output's value?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am doing a keras application that predicts a group of coordinates from a 3D Image Input. My architecture is the following :
img_input = keras.layers.Input((96,64,64,1))
x = keras.layers.Conv3D(32, (3, 3 ,3), activation='relu', padding='same', name='block1_conv1',trainable=True)(img_input)
x = keras.layers.Conv3D(32, (3, 3 ,3), activation='relu', padding='same', name='block1_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2, 2), name='block1_pool')(x)
# Block 2
x = keras.layers. Conv3D(64, (3, 3 ,3), activation='relu', padding='same', name='block2_conv1',trainable=True)(x)
x = keras.layers.Conv3D(64, (3, 3 ,3), activation='relu', padding='same', name='block2_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block2_pool')(x)
# Block 3
x = keras.layers.Conv3D(128, (3, 3 ,3), activation='relu', padding='same', name='block3_conv1',trainable=True)(x)
x = keras.layers.Conv3D(128, (3, 3 , 3), activation='relu', padding='same', name='block3_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block3_pool')(x)
# Block 3
x = keras.layers.Conv3D(128, (3, 3 ,3), activation='relu', padding='same', name='block4_conv1',trainable=True)(x)
x = keras.layers.Conv3D(128, (3, 3 , 3), activation='relu', padding='same', name='block4_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block4_pool')(x)
x = keras.layers.Flatten(name='flatten')(x)
x = keras.layers.Dense(4096,activation='relu',name="fc7",trainable=True)(x)
x = keras.layers.Dense(4096,activation='relu',name="fc8",trainable=True)(x)
x = keras.layers.Dense(288,activation='linear',name="fc10",trainable=True)(x)
The fact is that,the outputs are not really of size 288, they have all variable lenght, but I zero-padded all of them in order to have a fixed-size output.
In the other hand, I also trained a neural net that predicts the lenght of these outputs giving the same 3D input and it does it pretty well.
What I want is to use the output of this second network to crop the output of my first network . For example ,if my second network predicted a value of 285,the first network will crop the output from 288 to 285.
Is it possible on keras ? Or could you give me and advice of how to do this task(Predict the good coordinates with the correct length)?
Thank you very much
python-3.x tensorflow keras conv-neural-network crop
add a comment |
I am doing a keras application that predicts a group of coordinates from a 3D Image Input. My architecture is the following :
img_input = keras.layers.Input((96,64,64,1))
x = keras.layers.Conv3D(32, (3, 3 ,3), activation='relu', padding='same', name='block1_conv1',trainable=True)(img_input)
x = keras.layers.Conv3D(32, (3, 3 ,3), activation='relu', padding='same', name='block1_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2, 2), name='block1_pool')(x)
# Block 2
x = keras.layers. Conv3D(64, (3, 3 ,3), activation='relu', padding='same', name='block2_conv1',trainable=True)(x)
x = keras.layers.Conv3D(64, (3, 3 ,3), activation='relu', padding='same', name='block2_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block2_pool')(x)
# Block 3
x = keras.layers.Conv3D(128, (3, 3 ,3), activation='relu', padding='same', name='block3_conv1',trainable=True)(x)
x = keras.layers.Conv3D(128, (3, 3 , 3), activation='relu', padding='same', name='block3_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block3_pool')(x)
# Block 3
x = keras.layers.Conv3D(128, (3, 3 ,3), activation='relu', padding='same', name='block4_conv1',trainable=True)(x)
x = keras.layers.Conv3D(128, (3, 3 , 3), activation='relu', padding='same', name='block4_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block4_pool')(x)
x = keras.layers.Flatten(name='flatten')(x)
x = keras.layers.Dense(4096,activation='relu',name="fc7",trainable=True)(x)
x = keras.layers.Dense(4096,activation='relu',name="fc8",trainable=True)(x)
x = keras.layers.Dense(288,activation='linear',name="fc10",trainable=True)(x)
The fact is that,the outputs are not really of size 288, they have all variable lenght, but I zero-padded all of them in order to have a fixed-size output.
In the other hand, I also trained a neural net that predicts the lenght of these outputs giving the same 3D input and it does it pretty well.
What I want is to use the output of this second network to crop the output of my first network . For example ,if my second network predicted a value of 285,the first network will crop the output from 288 to 285.
Is it possible on keras ? Or could you give me and advice of how to do this task(Predict the good coordinates with the correct length)?
Thank you very much
python-3.x tensorflow keras conv-neural-network crop
add a comment |
I am doing a keras application that predicts a group of coordinates from a 3D Image Input. My architecture is the following :
img_input = keras.layers.Input((96,64,64,1))
x = keras.layers.Conv3D(32, (3, 3 ,3), activation='relu', padding='same', name='block1_conv1',trainable=True)(img_input)
x = keras.layers.Conv3D(32, (3, 3 ,3), activation='relu', padding='same', name='block1_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2, 2), name='block1_pool')(x)
# Block 2
x = keras.layers. Conv3D(64, (3, 3 ,3), activation='relu', padding='same', name='block2_conv1',trainable=True)(x)
x = keras.layers.Conv3D(64, (3, 3 ,3), activation='relu', padding='same', name='block2_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block2_pool')(x)
# Block 3
x = keras.layers.Conv3D(128, (3, 3 ,3), activation='relu', padding='same', name='block3_conv1',trainable=True)(x)
x = keras.layers.Conv3D(128, (3, 3 , 3), activation='relu', padding='same', name='block3_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block3_pool')(x)
# Block 3
x = keras.layers.Conv3D(128, (3, 3 ,3), activation='relu', padding='same', name='block4_conv1',trainable=True)(x)
x = keras.layers.Conv3D(128, (3, 3 , 3), activation='relu', padding='same', name='block4_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block4_pool')(x)
x = keras.layers.Flatten(name='flatten')(x)
x = keras.layers.Dense(4096,activation='relu',name="fc7",trainable=True)(x)
x = keras.layers.Dense(4096,activation='relu',name="fc8",trainable=True)(x)
x = keras.layers.Dense(288,activation='linear',name="fc10",trainable=True)(x)
The fact is that,the outputs are not really of size 288, they have all variable lenght, but I zero-padded all of them in order to have a fixed-size output.
In the other hand, I also trained a neural net that predicts the lenght of these outputs giving the same 3D input and it does it pretty well.
What I want is to use the output of this second network to crop the output of my first network . For example ,if my second network predicted a value of 285,the first network will crop the output from 288 to 285.
Is it possible on keras ? Or could you give me and advice of how to do this task(Predict the good coordinates with the correct length)?
Thank you very much
python-3.x tensorflow keras conv-neural-network crop
I am doing a keras application that predicts a group of coordinates from a 3D Image Input. My architecture is the following :
img_input = keras.layers.Input((96,64,64,1))
x = keras.layers.Conv3D(32, (3, 3 ,3), activation='relu', padding='same', name='block1_conv1',trainable=True)(img_input)
x = keras.layers.Conv3D(32, (3, 3 ,3), activation='relu', padding='same', name='block1_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2, 2), name='block1_pool')(x)
# Block 2
x = keras.layers. Conv3D(64, (3, 3 ,3), activation='relu', padding='same', name='block2_conv1',trainable=True)(x)
x = keras.layers.Conv3D(64, (3, 3 ,3), activation='relu', padding='same', name='block2_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block2_pool')(x)
# Block 3
x = keras.layers.Conv3D(128, (3, 3 ,3), activation='relu', padding='same', name='block3_conv1',trainable=True)(x)
x = keras.layers.Conv3D(128, (3, 3 , 3), activation='relu', padding='same', name='block3_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block3_pool')(x)
# Block 3
x = keras.layers.Conv3D(128, (3, 3 ,3), activation='relu', padding='same', name='block4_conv1',trainable=True)(x)
x = keras.layers.Conv3D(128, (3, 3 , 3), activation='relu', padding='same', name='block4_conv2',trainable=True)(x)
x = keras.layers.MaxPooling3D((2, 2 ,2), name='block4_pool')(x)
x = keras.layers.Flatten(name='flatten')(x)
x = keras.layers.Dense(4096,activation='relu',name="fc7",trainable=True)(x)
x = keras.layers.Dense(4096,activation='relu',name="fc8",trainable=True)(x)
x = keras.layers.Dense(288,activation='linear',name="fc10",trainable=True)(x)
The fact is that,the outputs are not really of size 288, they have all variable lenght, but I zero-padded all of them in order to have a fixed-size output.
In the other hand, I also trained a neural net that predicts the lenght of these outputs giving the same 3D input and it does it pretty well.
What I want is to use the output of this second network to crop the output of my first network . For example ,if my second network predicted a value of 285,the first network will crop the output from 288 to 285.
Is it possible on keras ? Or could you give me and advice of how to do this task(Predict the good coordinates with the correct length)?
Thank you very much
python-3.x tensorflow keras conv-neural-network crop
python-3.x tensorflow keras conv-neural-network crop
asked Nov 16 '18 at 12:44
MateoMateo
133
133
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%2f53338186%2fkeras-tensorflow-how-to-crop-an-output-tensor-depending-on-another-outputs-va%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%2f53338186%2fkeras-tensorflow-how-to-crop-an-output-tensor-depending-on-another-outputs-va%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