Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

python - Feed keras model input to the output layer

So I am building a keras sequential model in which the last output layer is an Upsampling2D layer & I need to feed the input image to that output layer to do a simple operation and return the output, any ideas?

EDIT :

The model mentioned before is the generator of a GAN model in which I need to add the input image to the output of the generator before feeding it to the discriminator

question from:https://stackoverflow.com/questions/65835778/feed-keras-model-input-to-the-output-layer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

1.You can define a backbone model using inputs of pre-trained model and the outputs of the last layer before the output layer of pre-trained model

2.Base on that backbone model, defined new model have that new skip connection and the output layer as same as pre-trained model

3.Set the weights of output layer in new model to equal to weights of output layer in pre-trained model, using: new_model.layers[-1].set_weights(pre_model.layers[-1].get_weights())

Here is one good article about Adding Layers to the middle of a pre-trained network whithout invalidating the weights


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...