关于创建多分类器模型

为什么以下代码会报这个错误
ValueError: Output tensors of a Functional model must be the output of a TensorFlow Layer (thus holding past layer metadata). Found: None. 我应该怎么解决

from tensorflow.keras import layers
from tensorflow.keras.layers import concatenate,Input, Dense, Conv2D, MaxPooling2D, UpSampling2D, BatchNormalization, Flatten, Dropout
from tensorflow.keras.models import Model, Sequential
from tensorflow.keras.optimizers import SGD

#define inception_module
def inception_module(x,cov1_1,cov_reduce3_3,cov3_3,cov_reduce5_5,cov5_5,pool_proj):
    conv11 = Conv2D(cov1_1,(1,1), padding='same', activation='relu')(x)
    
    conv31 = Conv2D(cov_reduce3_3, (1,1), padding='same', activation='relu')(x)
    conv3 = Conv2D(cov3_3, (3,3), padding='same', activation='relu')(conv31)
    
    conv51 = Conv2D(cov_reduce5_5, (1,1), padding='same', activation='relu')(x)
    conv5 = Conv2D(cov5_5, (5,5), padding='same', activation='relu')(conv51)
    
    pool3 = MaxPooling2D((3,3), strides=(1,1), padding='same')(x)
    conv1 = Conv2D(pool_proj, (1,1), padding='same', activation='relu')(pool3)
    
    output = concatenate([conv11,conv3,conv5,conv1], axis=-1)
    return output


denseSize = 1024

#left loss layer
def loss_layer(x,cov1_1):
    x = tf.keras.layers.AveragePooling2D(pool_size=(5, 5),strides=(2, 2), padding='valid')(x)
    x = Conv2D(cov1_1, (1,1), padding='same', activation='relu')(x)
    x = layers.Flatten()(x)
    x = layers.Dense(denseSize)(x)
    x = layers.Dropout(rate=0.5)(x)
    x = layers.Dense(denseSize)(x)
    x = layers.Dropout(rate=0.5)(x)
    x = layers.Dense(CLASS_NUM)
    x = layers.Softmax()

def center_loss_layer(x):
    x = layers.AveragePooling2D(pool_size=(5, 5),strides=(2, 2), padding='valid')(x)
    x = layers.Flatten()(x)
    x = layers.Dense(denseSize)(x)
    x = layers.Dropout(rate=0.5)(x)
    x = layers.Dense(CLASS_NUM)
    x = layers.Softmax()
    
def GoogLeNetForFont(im_height=224, im_width=224, class_num=45):

    input_image = layers.Input(shape=(im_height, im_width, 3))
    x = layers.Conv2D(64, kernel_size=5,strides=2, padding='same',activation='relu',name="conv2d_1_5")(input_image)
    x = layers.MaxPool2D(pool_size=2, strides=2, padding="same", name="maxpool_1")(x)
    x = BatchNormalization()(x)
   
    # (None, 56, 56, 64)
    x = layers.Conv2D(64, kernel_size=1, padding="same", activation="relu", name="conv2d_1_1")(x)
    x = layers.Conv2D(192, kernel_size=3, padding="same", activation="relu", name="conv2d_1_3")(x)
    # (None, 56, 56, 192)
    x = layers.MaxPool2D(pool_size=3, strides=2, padding="same", name="maxpool_2")(x)
    x = BatchNormalization()(x)

    
    # (None, 28, 28, 192)
    x = inception_module(x,64, 96, 128, 16, 32, 32)# name="inception_1"
    # (None, 28, 28, 256)
    x = inception_module(x,128, 128, 192, 32, 96, 64)# name="inception_2"
    inception3 = inception_module(x,192, 96, 208, 16, 48, 64)# name="inception_3"
    rightAux = loss_layer(inception3,192)
    
    
    x = inception_module(inception3,160, 112, 224, 24, 64, 64)
    # (None, 14, 14, 512)
    x = inception_module(x,128, 128, 256, 24, 64, 64)
    # (None, 14, 14, 512)
    inception6 = inception_module(x,112, 144, 288, 32, 64, 64)
    leftAux = loss_layer(inception6,112)

    # (None, 14, 14, 528)
    x = inception_module(inception6,256, 160, 320, 32, 128, 128)
    
    # (None, 7, 7, 832)
    x = inception_module(x,256, 160, 320, 32, 128, 128)
    # (None, 7, 7, 832)
    x = inception_module(x,384, 192, 384, 48, 128, 128)
    x = center_loss_layer(x)
    
    #outlyr = concatenate([leftAux, rightAux,x])
    #model = Model(inputs=input_image, outputs=outlyr)
    model = Model(inputs=input_image, outputs=[leftAux, rightAux, x])#第一个和第二个是辅助分类器 第三个是主输出

    return model

cnn = GoogLeNetForFont(isize,isize,CLASS_NUM)
cnn.summary()

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^