问题
# import the necessary packages
import keras
from keras.initializers import glorot_uniform
from keras.layers import AveragePooling2D, Input, Add
from keras.models import Model
from keras.layers.normalization import BatchNormalization
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.layers.core import Activation
from keras.layers.core import Flatten
from keras.layers.core import Dropout
from keras.layers.core import Dense
class SmallerVGGNet:
@staticmethod
def build(width, height, depth, classes, finalact):
X1 = Input(shape=(height, width, depth))
# # CONV => RELU => POOL
X = Conv2D(16, (3, 3), padding="same", strides=(1, 1), name="con_layer1")(X1)
X = BatchNormalization(axis=3)(X)
X = Activation("relu")(X)
X = MaxPooling2D(pool_size=(3, 3), strides=(1, 1))(X)
X = Conv2D(32, (3, 3), padding="same", strides=(2, 2), name="con_layer2")(X)
X = BatchNormalization(axis=3)(X)
X = Activation("relu")(X)
X = Conv2D(32, (3, 3), padding="same", strides=(1, 1), name="con_layer3")(X)
X = Activation("relu")(X)
X = BatchNormalization(axis=3)(X)
X = MaxPooling2D(pool_size=(3, 3), strides=(1, 1))(X)
# First component
X0 = Conv2D(256, (5, 5), strides=(1, 1), padding='same', kernel_initializer=glorot_uniform(seed=0))(X)
X0 = BatchNormalization(axis=3)(X0)
X0 = Activation("relu")(X0)
# (CONV => RELU) * 2 => POOL
X = Conv2D(64, (3, 3), padding="same", strides=(2, 2), name="con_layer4")(X0)
X = BatchNormalization(axis=3)(X)
X = Activation("relu")(X)
X = Conv2D(64, (3, 3), padding="same", strides=(1, 1), name="con_layer5")(X)
X = BatchNormalization(axis=3)(X)
X = Activation("relu")(X)
X = AveragePooling2D(pool_size=(3, 3), strides=(1, 1))(X)
# Second Component
X0 = Conv2D(512, (5, 5), strides=(1, 1), padding='valid', kernel_initializer=glorot_uniform(seed=0))(X)
X0 = BatchNormalization(axis=3)(X0)
X0 = Activation("relu")(X0)
# (CONV => RELU) * 2 => POOL
X = Conv2D(128, (3, 3), padding="same", strides=(2, 2), name="con_layer6")(X0)
X = BatchNormalization(axis=3)(X)
X = Activation("relu")(X)
X = Conv2D(128, (3, 3), padding="same", strides=(1, 1), name="con_layer7")(X)
X = BatchNormalization(axis=3)(X)
X = Activation("relu")(X)
X = MaxPooling2D(pool_size=(3, 3), strides=(1, 1))(X)
# Third Component
X0 = Conv2D(1024, (7, 7), strides=(2, 2), padding='valid', kernel_initializer=glorot_uniform(seed=0))(X)
X0 = BatchNormalization(axis=3)(X0)
X0 = Dense(128, activation="relu")(X0)
X0 = Activation("relu")(X0)
X = Add()([X0])
X = Flatten()(X1)
X = BatchNormalization()(X)
X = Dropout(0.5)(X)
output = Dense(classes, activation=finalact)(X)
model = Model(inputs=[X1], outputs=output)
print(model.summary())
return model
I want to add third components last Activation function for that i created a add function to add all the X0 values. but while adding this this error occurs. This happens while adding ADD function.
raise ValueError('A merge layer should be called ' ValueError: A merge layer should be called on a list of inputs.
来源:https://stackoverflow.com/questions/59964803/valueerror-a-merge-layer-should-be-called-on-a-list-of-inputs-add