Python 在ML/DL中是否有多个模型层?

Python 在ML/DL中是否有多个模型层?,python,tensorflow,Python,Tensorflow,我在Keras/Tensorflow中做了一些研究和编程,我想知道是否有可能创建一个多模型。基本上,您将有n个子模型和一个不同权重的父模型 例如,如果您想将较大的模型分解以进行更快的训练,则可以分割数据的一部分并单独训练它们。我的用例是源代码分析,因此如果我从源代码中提取注释并使用两个模型(一个用于注释,一个用于代码),那么我可能能够在不同的机器上训练这两个模型 比如: source_code, comments = parse_files(file_list) // magic... tra

我在Keras/Tensorflow中做了一些研究和编程,我想知道是否有可能创建一个多模型。基本上,您将有n个子模型和一个不同权重的父模型

例如,如果您想将较大的模型分解以进行更快的训练,则可以分割数据的一部分并单独训练它们。我的用例是源代码分析,因此如果我从源代码中提取注释并使用两个模型(一个用于注释,一个用于代码),那么我可能能够在不同的机器上训练这两个模型

比如:

source_code, comments = parse_files(file_list)

// magic... train the models

parent_model = Model(inputs=[source_code_model, comment_model], outputs=[b1, b2, b3])
这类事情完成了吗?

我搜索了一下后发现:

# define two sets of inputs
inputA = Input(shape=(32,))
inputB = Input(shape=(128,))
# the first branch operates on the first input
x = Dense(8, activation="relu")(inputA)
x = Dense(4, activation="relu")(x)
x = Model(inputs=inputA, outputs=x)
# the second branch opreates on the second input
y = Dense(64, activation="relu")(inputB)
y = Dense(32, activation="relu")(y)
y = Dense(4, activation="relu")(y)
y = Model(inputs=inputB, outputs=y)
# combine the output of the two branches
combined = concatenate([x.output, y.output])
# apply a FC layer and then a regression prediction on the
# combined outputs
z = Dense(2, activation="relu")(combined)
z = Dense(1, activation="linear")(z)
# our model will accept the inputs of the two branches and
# then output a single value
model = Model(inputs=[x.input, y.input], outputs=z)

和你要找的东西相似吗?我不这么认为,但我只看了几遍。大概