可以在Keras中创建断开连接的隐藏层吗? [英] Can one create disconnected hidden layers in Keras?
本文介绍了可以在Keras中创建断开连接的隐藏层吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用Keras创建具有不同激活功能的隐藏层,这些激活层都连接到输入层而不相互连接?
例如,具有10个神经元的隐藏层,其中5个神经元具有ReLU激活,而5个神经元具有Sigmoid激活功能.我想创建一个平板架构神经网络.解决方案
您可以创建两个单独的密集层.这是最简单的方法.
单独的图层:
from keras.layers import *
from keras.models import Model
#model's input and the basic syntax for creating layers
inputTensor = Input(some_shape)
outputTensor = SomeLayer(blablabla)(inputTensor)
outputTensor = AnotherLayer(bblablabla)(outputTensor)
#keep creating other layers like the previous one
#when you reach the point you want to divide:
out1 = Dense(5,activation='relu')(outputTensor)
out2 = Dense(5,activation='sigmoid')(outputTensor)
#you may concatenate the results:
outputTensor = Concatenate()([out1,out2])
#keep creating more layers....
#create the model
model = Model(inputTensor,outputTensor)
Is it possible to create hidden layers with different activation functions, which are both connected to the input layer and not to each other, using Keras?
For example a hidden layer with 10 neurons where say 5 neurons have ReLU activation and 5 neurons have say Sigmoid activation functions. I want to create a slab architecture neural network.
解决方案
You can create two separate dense layers. It's the simpliest way of doing it.
Separate layers:
from keras.layers import *
from keras.models import Model
#model's input and the basic syntax for creating layers
inputTensor = Input(some_shape)
outputTensor = SomeLayer(blablabla)(inputTensor)
outputTensor = AnotherLayer(bblablabla)(outputTensor)
#keep creating other layers like the previous one
#when you reach the point you want to divide:
out1 = Dense(5,activation='relu')(outputTensor)
out2 = Dense(5,activation='sigmoid')(outputTensor)
#you may concatenate the results:
outputTensor = Concatenate()([out1,out2])
#keep creating more layers....
#create the model
model = Model(inputTensor,outputTensor)
这篇关于可以在Keras中创建断开连接的隐藏层吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文