python - 连接神经网络中 split 的密集层 - Keras

标签 python tensorflow keras deep-learning neural-network

我已经看到在keras中我可以使用tf.slpit来分割图层。我的问题是我不明白如何在每层必须采用的“ fork 方式”之间进行连接。

这是我正在尝试做的示例的图像。它基本上是一个输入层,分为 2 个子神经网络,然后在输出之前的层中重新组合。

图表(细黑线白色多边形代表高度连接矩阵): enter image description here

最佳答案

在谷歌上搜索更好的词(如合并神经网络)后,我发现 Keras 功能 API 就是答案。

有用的链接:

第一个链接的示例代码:

# Shared Input Layer
from keras.utils import plot_model
from keras.models import Model
from keras.layers import Input
from keras.layers import Dense
from keras.layers import Flatten
from keras.layers.convolutional import Conv2D
from keras.layers.pooling import MaxPooling2D
from keras.layers.merge import concatenate
# input layer
visible = Input(shape=(64,64,1))
# first feature extractor
conv1 = Conv2D(32, kernel_size=4, activation='relu')(visible)
pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
flat1 = Flatten()(pool1)
# second feature extractor
conv2 = Conv2D(16, kernel_size=8, activation='relu')(visible)
pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
flat2 = Flatten()(pool2)
# merge feature extractors
merge = concatenate([flat1, flat2])
# interpretation layer
hidden1 = Dense(10, activation='relu')(merge)
# prediction output
output = Dense(1, activation='sigmoid')(hidden1)
model = Model(inputs=visible, outputs=output)
# summarize layers
print(model.summary())
# plot graph
plot_model(model, to_file='shared_input_layer.png')

关于python - 连接神经网络中 split 的密集层 - Keras,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73111934/

相关文章:

Python Twitter 库 : which one?

python - tf.keras.metrics.SpecificityAtSensitivity num_thresholds 解释

tensorflow - 如何在jupyter笔记本中多次拟合/运行神经网络?

python - 为什么 tf.executing_eagerly() 在 TensorFlow 2 中返回 False?

python - 将 PNG 形状转换为 KML 或 GeoJson

python - 即使是 .00 如何保持小数点后 2 位

python - 为什么我需要在Keras中编译和拟合预训练模型?

python - 训练 Keras 模型时使用稀疏数组表示标签

javascript - 使用 JavaScript 将 var res 更改为给定数组的最大值

python - 如何选择 tf.keras 模型隐藏层输出神经元的值?