Splitting a neural network in 2 microservices The Next CEO of Stack Overflow2019 Community Moderator ElectionWhen is something a Deep Neural Network (DNN) and not NN?combining trained neural nets in tensorflowAdding hand-crafted features to a convolutional neural network (CNN) in TensorFlowAmount of multiplications in a neural network modelText Localization using Convolutional NNReusing a portion of a neural network (with shared weights) in KerasNeural Network unable to track training dataTraining a convoltion neural network for localizationWhat is exactly meant by neural network that can take different types of input?How to train two neural networks together
Is it correct to say moon starry nights?
What happened in Rome, when the western empire "fell"?
Is French Guiana a (hard) EU border?
Does destroying a Lich's phylactery destroy the soul within it?
Touchpad not working on Debian 9
In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?
Is there an equivalent of cd - for cp or mv
Is it okay to majorly distort historical facts while writing a fiction story?
Why don't programming languages automatically manage the synchronous/asynchronous problem?
What CSS properties can the br tag have?
Is a distribution that is normal, but highly skewed, considered Gaussian?
TikZ: How to fill area with a special pattern?
How to use ReplaceAll on an expression that contains a rule
Yu-Gi-Oh cards in Python 3
Can this note be analyzed as a non-chord tone?
Reshaping json / reparing json inside shell script (remove trailing comma)
Is there a difference between "Fahrstuhl" and "Aufzug"?
My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?
Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?
Can I calculate next year's exemptions based on this year's refund/amount owed?
Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact
Does higher Oxidation/ reduction potential translate to higher energy storage in battery?
Is it ever safe to open a suspicious HTML file (e.g. email attachment)?
How to get the last not-null value in an ordered column of a huge table?
Splitting a neural network in 2 microservices
The Next CEO of Stack Overflow2019 Community Moderator ElectionWhen is something a Deep Neural Network (DNN) and not NN?combining trained neural nets in tensorflowAdding hand-crafted features to a convolutional neural network (CNN) in TensorFlowAmount of multiplications in a neural network modelText Localization using Convolutional NNReusing a portion of a neural network (with shared weights) in KerasNeural Network unable to track training dataTraining a convoltion neural network for localizationWhat is exactly meant by neural network that can take different types of input?How to train two neural networks together
$begingroup$
I have a neural network, that is already trained locally that can detect objects in the scene.
But I have to split the neural network into 2 parts, let's say it has 16 layers, and I want to have one microservice handle the first 8 layers and give the output of the 8th layer to the next microservice and it takes the data from there and proceeds with the 9th layer (1st layer in the 2nd microservice).
Sending an image to the 1st microservice will give the result from the 2nd microservice, is this feasible using TensorFlow?
deep-learning tensorflow cnn
$endgroup$
add a comment |
$begingroup$
I have a neural network, that is already trained locally that can detect objects in the scene.
But I have to split the neural network into 2 parts, let's say it has 16 layers, and I want to have one microservice handle the first 8 layers and give the output of the 8th layer to the next microservice and it takes the data from there and proceeds with the 9th layer (1st layer in the 2nd microservice).
Sending an image to the 1st microservice will give the result from the 2nd microservice, is this feasible using TensorFlow?
deep-learning tensorflow cnn
$endgroup$
add a comment |
$begingroup$
I have a neural network, that is already trained locally that can detect objects in the scene.
But I have to split the neural network into 2 parts, let's say it has 16 layers, and I want to have one microservice handle the first 8 layers and give the output of the 8th layer to the next microservice and it takes the data from there and proceeds with the 9th layer (1st layer in the 2nd microservice).
Sending an image to the 1st microservice will give the result from the 2nd microservice, is this feasible using TensorFlow?
deep-learning tensorflow cnn
$endgroup$
I have a neural network, that is already trained locally that can detect objects in the scene.
But I have to split the neural network into 2 parts, let's say it has 16 layers, and I want to have one microservice handle the first 8 layers and give the output of the 8th layer to the next microservice and it takes the data from there and proceeds with the 9th layer (1st layer in the 2nd microservice).
Sending an image to the 1st microservice will give the result from the 2nd microservice, is this feasible using TensorFlow?
deep-learning tensorflow cnn
deep-learning tensorflow cnn
asked Feb 22 at 11:39
AnilAnil
1062
1062
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Yes, you can split the model into two parts after training. Not sure, what would be the advantage, but it is possible. High level steps :
- Define and train the model
- Save trained model
- Create two copies of model (Layers 1 to 8 and new input layer + 9 to 16)
- Transfer weights to these copies of model
After this, service 1 can run first few layers and provide the output to service 2.
Example code to split the model (Code uses Keras as wrapper over TensorFlow):
import keras
from keras.models import Model, load_model
from keras.layers import Input, Dense
from keras.optimizers import RMSprop
import numpy as np
# Create original model and save it
inputs = Input((1,))
dense_1 = Dense(10, activation='relu')(inputs)
dense_2 = Dense(10, activation='relu')(dense_1)
dense_3 = Dense(10, activation='relu')(dense_2)
outputs = Dense(10)(dense_3)
model = Model(inputs=inputs, outputs=outputs)
model.compile(optimizer=RMSprop(), loss='mse')
model.save('test.h5')
# Load the model and make modifications to it
loaded_model = load_model('test.h5')
loaded_model.layers.pop()
loaded_model.layers.pop()
# Create your new model with the two layers removed and transfer weights
new_model = Model(inputs=inputs, outputs=dense_1)
new_model.compile(optimizer=RMSprop(), loss='mse')
new_model.set_weights(loaded_model.get_weights())
new_model.summary()
new_model.save('test_complete.h5')
Source : https://github.com/keras-team/keras/issues/8772
$endgroup$
add a comment |
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fdatascience.stackexchange.com%2fquestions%2f46017%2fsplitting-a-neural-network-in-2-microservices%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
$begingroup$
Yes, you can split the model into two parts after training. Not sure, what would be the advantage, but it is possible. High level steps :
- Define and train the model
- Save trained model
- Create two copies of model (Layers 1 to 8 and new input layer + 9 to 16)
- Transfer weights to these copies of model
After this, service 1 can run first few layers and provide the output to service 2.
Example code to split the model (Code uses Keras as wrapper over TensorFlow):
import keras
from keras.models import Model, load_model
from keras.layers import Input, Dense
from keras.optimizers import RMSprop
import numpy as np
# Create original model and save it
inputs = Input((1,))
dense_1 = Dense(10, activation='relu')(inputs)
dense_2 = Dense(10, activation='relu')(dense_1)
dense_3 = Dense(10, activation='relu')(dense_2)
outputs = Dense(10)(dense_3)
model = Model(inputs=inputs, outputs=outputs)
model.compile(optimizer=RMSprop(), loss='mse')
model.save('test.h5')
# Load the model and make modifications to it
loaded_model = load_model('test.h5')
loaded_model.layers.pop()
loaded_model.layers.pop()
# Create your new model with the two layers removed and transfer weights
new_model = Model(inputs=inputs, outputs=dense_1)
new_model.compile(optimizer=RMSprop(), loss='mse')
new_model.set_weights(loaded_model.get_weights())
new_model.summary()
new_model.save('test_complete.h5')
Source : https://github.com/keras-team/keras/issues/8772
$endgroup$
add a comment |
$begingroup$
Yes, you can split the model into two parts after training. Not sure, what would be the advantage, but it is possible. High level steps :
- Define and train the model
- Save trained model
- Create two copies of model (Layers 1 to 8 and new input layer + 9 to 16)
- Transfer weights to these copies of model
After this, service 1 can run first few layers and provide the output to service 2.
Example code to split the model (Code uses Keras as wrapper over TensorFlow):
import keras
from keras.models import Model, load_model
from keras.layers import Input, Dense
from keras.optimizers import RMSprop
import numpy as np
# Create original model and save it
inputs = Input((1,))
dense_1 = Dense(10, activation='relu')(inputs)
dense_2 = Dense(10, activation='relu')(dense_1)
dense_3 = Dense(10, activation='relu')(dense_2)
outputs = Dense(10)(dense_3)
model = Model(inputs=inputs, outputs=outputs)
model.compile(optimizer=RMSprop(), loss='mse')
model.save('test.h5')
# Load the model and make modifications to it
loaded_model = load_model('test.h5')
loaded_model.layers.pop()
loaded_model.layers.pop()
# Create your new model with the two layers removed and transfer weights
new_model = Model(inputs=inputs, outputs=dense_1)
new_model.compile(optimizer=RMSprop(), loss='mse')
new_model.set_weights(loaded_model.get_weights())
new_model.summary()
new_model.save('test_complete.h5')
Source : https://github.com/keras-team/keras/issues/8772
$endgroup$
add a comment |
$begingroup$
Yes, you can split the model into two parts after training. Not sure, what would be the advantage, but it is possible. High level steps :
- Define and train the model
- Save trained model
- Create two copies of model (Layers 1 to 8 and new input layer + 9 to 16)
- Transfer weights to these copies of model
After this, service 1 can run first few layers and provide the output to service 2.
Example code to split the model (Code uses Keras as wrapper over TensorFlow):
import keras
from keras.models import Model, load_model
from keras.layers import Input, Dense
from keras.optimizers import RMSprop
import numpy as np
# Create original model and save it
inputs = Input((1,))
dense_1 = Dense(10, activation='relu')(inputs)
dense_2 = Dense(10, activation='relu')(dense_1)
dense_3 = Dense(10, activation='relu')(dense_2)
outputs = Dense(10)(dense_3)
model = Model(inputs=inputs, outputs=outputs)
model.compile(optimizer=RMSprop(), loss='mse')
model.save('test.h5')
# Load the model and make modifications to it
loaded_model = load_model('test.h5')
loaded_model.layers.pop()
loaded_model.layers.pop()
# Create your new model with the two layers removed and transfer weights
new_model = Model(inputs=inputs, outputs=dense_1)
new_model.compile(optimizer=RMSprop(), loss='mse')
new_model.set_weights(loaded_model.get_weights())
new_model.summary()
new_model.save('test_complete.h5')
Source : https://github.com/keras-team/keras/issues/8772
$endgroup$
Yes, you can split the model into two parts after training. Not sure, what would be the advantage, but it is possible. High level steps :
- Define and train the model
- Save trained model
- Create two copies of model (Layers 1 to 8 and new input layer + 9 to 16)
- Transfer weights to these copies of model
After this, service 1 can run first few layers and provide the output to service 2.
Example code to split the model (Code uses Keras as wrapper over TensorFlow):
import keras
from keras.models import Model, load_model
from keras.layers import Input, Dense
from keras.optimizers import RMSprop
import numpy as np
# Create original model and save it
inputs = Input((1,))
dense_1 = Dense(10, activation='relu')(inputs)
dense_2 = Dense(10, activation='relu')(dense_1)
dense_3 = Dense(10, activation='relu')(dense_2)
outputs = Dense(10)(dense_3)
model = Model(inputs=inputs, outputs=outputs)
model.compile(optimizer=RMSprop(), loss='mse')
model.save('test.h5')
# Load the model and make modifications to it
loaded_model = load_model('test.h5')
loaded_model.layers.pop()
loaded_model.layers.pop()
# Create your new model with the two layers removed and transfer weights
new_model = Model(inputs=inputs, outputs=dense_1)
new_model.compile(optimizer=RMSprop(), loss='mse')
new_model.set_weights(loaded_model.get_weights())
new_model.summary()
new_model.save('test_complete.h5')
Source : https://github.com/keras-team/keras/issues/8772
answered Feb 22 at 11:56
Shamit VermaShamit Verma
1,1191211
1,1191211
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
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%2fdatascience.stackexchange.com%2fquestions%2f46017%2fsplitting-a-neural-network-in-2-microservices%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