我正在尝试构建一组串联或级联(实际上甚至不知道这是否是正确的定义)的模型。
为了简单起见,我的基本模型如下所示。
----Input----
|
L1-1
|
L1-2
|
Dense
|
Softmax
我对其中 7 个模型进行了交叉验证训练,并尝试以级联方式包装它们,例如:
-----------------------Input---------------------
| | | | | | |
L1-1 L1-2 L1-3 L1-4 L1-5 L1-6 L1-7
| | | | | | |
L2-1 L2-2 L2-3 L2-4 L2-5 L2-6 L2-7
| | | | | | |
|_______|_______|_______|_______|_______|_______|
| Concatenated |
|___________________Dense Layer_________________|
|
SoftMax
每一层都有512
神经元,所以最终连接的密集层总共有7*512=3584
神经元。
我所做的是:
- 训练所有模型并将它们保存在名为的列表中
models[]
.
- 弹出所有模型中的底部 Softmax 层。
然后我尝试连接它们但收到错误:
Layer merge was called with an input that isn't a symbolic tensor.
形成级联后我要做的就是冻结所有中间层,除了Concatenated Dense Layer
并稍微调整一下。但我被困在所有细节中所解释的地方。
为此,您需要使用函数式 API 模型。这种模型适用于张量。
首先定义一个公共输入张量:
inputTensor = Input(inputShape)
然后,您使用此输入调用每个模型以获取输出张量:
outputTensors = [m(inputTensor) for m in models]
然后将这些张量传递到连接层:
output = Concatenate()(outputTensors)
output = Dense(...)(output)
#you might want to use an Average layer instead of these two....
output = Activation('softmax')(output)
最后,定义从起始张量到结束张量的完整模型:
fullModel = Model(inputTensor,output)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)