是否可以在keras中将中间层设置为输出层 [英] Is it possible to set a middle layer as an output layer in keras

查看:164
本文介绍了是否可以在keras中将中间层设置为输出层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试一下有关自动编码器的想法. 该模型是这样的:

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)

是否可以训练具有dense(supervised output)output (pictures)所需输出的NN?换句话说,我要进行分类并返回.

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.

推荐答案

这可以通过Keras功能API(

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

一个最小的示例,其中模型有2个输出,一个来自中间层,一个来自最终层:

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])

这篇关于是否可以在keras中将中间层设置为输出层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆