Is it possible to set a middle layer as an output layer in keras

我怕爱的太早我们不能终老 提交于 2019-12-25 01:24:30

问题


I would like to try out an idea about autoencoder. The model is like this:

input (pictures) - conv2d - pooling - dense - dense(supervised output) - dense - conv - upsampling - output (pictures)

If it is possible to train the NN having desired outputs for dense(supervised output) and output (pictures)? In other words, I want to make a classifier-and-back.


回答1:


This can be done with the Keras functional API (https://keras.io/getting-started/functional-api-guide/).

A minimal example, where the model has 2 outputs, one from an intermediate layer, and one from the final layer:

import keras
input = keras.layers.Input(shape=(3,))

intermediate = keras.layers.Dense(10)(input)
final_output = keras.layers.Dense(3)(intermediate)

model = keras.Model(inputs=input, outputs=[intermediate, final_output])


来源:https://stackoverflow.com/questions/58372457/is-it-possible-to-set-a-middle-layer-as-an-output-layer-in-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!