Python ValueError:模型的输出张量必须是Keras`层的输出`
我试图创建一个共享权重且具有多个分支的模型,因此每个分支层都附加在一个列表上,但当我将列表提供给模型输出时,它给了我错误:Python ValueError:模型的输出张量必须是Keras`层的输出`,python,keras,Python,Keras,我试图创建一个共享权重且具有多个分支的模型,因此每个分支层都附加在一个列表上,但当我将列表提供给模型输出时,它给了我错误: ValueError: Output tensors to a Model must be the output of a Keras `Layer` (thus holding past layer metadata). Found: [<tf.Tensor 'dense_260/Relu:0' shape=(?, 3) dtype=float32>, <
ValueError: Output tensors to a Model must be the output of a Keras `Layer` (thus holding past layer metadata). Found: [<tf.Tensor 'dense_260/Relu:0' shape=(?, 3) dtype=float32>, <tf.Tensor 'dense_263/Relu:0' shape=(?, 3) dtype=float32>, <tf.Tensor 'dense_266/Relu:0' shape=(?, 3) dtype=float32>, <tf.Tensor 'dense_269/Relu:0' shape=(?, 3) dtype=float32>, <tf.Tensor 'dense_272/Relu:0' shape=(?, 1) dtype=float32>]
我的目标是能够使用列表中选定的分支训练此网络,以便在
branch\u config
Tryoutputs=branchs
上添加尽可能多的分支,因为分支已经是一个列表。我这样做了,错误更改为“AttributeError:“NoneType”对象没有属性“\u inbound\u nodes”
branch_config = [
["Steer", "Gas", "Brake"], ["Steer", "Gas", "Brake"],
["Steer", "Gas", "Brake"], ["Steer", "Gas", "Brake"],
["Speed"]
]
def conv_block(inputs, filters, kernel_size, strides):
x = Conv2D(filters, (kernel_size, kernel_size), strides = strides, activation='relu')(inputs)
x = MaxPooling2D(pool_size=(1,1), strides=(1,1))(x)
x = BatchNormalization()(x)
x = Dropout(0.4)(x)
return x
def fc_block(inputs, units):
fc = Dense(units, activation = 'relu')(inputs)
fc = Dropout(0.2)(fc)
return fc
branches = []
inputs = Input(input_image)
'''inputs, filters, kernel_size, strides'''
""" Conv 1 """
x = conv_block(inputs, 32, 5, 2)
x = conv_block(x, 32, 3, 1)
""" Conv 2 """
x = conv_block(x, 64, 3, 2)
x = conv_block(x, 64, 3, 1)
""" Conv 3 """
x = conv_block(x, 128, 3, 2)
x = conv_block(x, 128, 3, 1)
""" Conv 4 """
x = conv_block(x, 256, 3, 1)
x = conv_block(x, 256, 3, 1)
""" Reshape """
x = Flatten()(x)
""" FC1 """
x = fc_block(x, 512)
""" FC2 """
x = fc_block(x, 512)
"""Process Control"""
""" Speed (measurements) """
speed = input_data[1] # input_speed
speed = fc_block(speed, 128)
speed = fc_block(speed, 128)
""" Joint sensory """
j = concatenate([x, speed])
j = fc_block(j, 512)
for i in range(len(branch_config)):
# Use only image input to predict the speed
if branch_config[i][0] == "Speed":
branch_output = fc_block(x, 256)
branch_output = fc_block(branch_output, 256)
else:
branch_output = fc_block(j, 256)
branch_output = fc_block(branch_output, 256)
fully_connected = Dense(len(branch_config[i]), activation = 'relu')(branch_output)
branches.append(fully_connected)
model = Model(inputs=inputs,outputs=[branches])