def build_model(self, input_shape, nb_classes): x = keras.layers.Input(input_shape) conv1 = keras.layers.Conv1D(128, 8, 1, padding='same')(x) conv1 = keras.layers.BatchNormalization()(conv1) conv1 = keras.layers.Activation('relu')(conv1) conv2 = keras.layers.Conv1D(256, 5, 1, padding='same')(conv1) conv2 = keras.layers.BatchNormalization()(conv2) conv2 = keras.layers.Activation('relu')(conv2) conv3 = keras.layers.Conv1D(128, 3, 1, padding='same')(conv2) conv3 = keras.layers.BatchNormalization()(conv3) conv3 = keras.layers.Activation('relu')(conv3) full = keras.layers.GlobalAveragePooling1D()(conv3) out = keras.layers.Dense(nb_classes, activation='softmax')(full) model = keras.models.Model(inputs=x, outputs=out) # optimizer = keras.optimizers.Adam() optimizer = keras.optimizers.Nadam() model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['accuracy']) return model
时间: 2023-02-09 12:25:45 浏览: 70
浅谈Keras参数 input_shape、input_dim和input_length用法
5星 · 资源好评率100%
这是在 Keras 框架中定义一个模型的代码。这个模型由输入层、三个卷积层、全局平均池化层、全连接层和输出层组成。卷积层之间还有批归一化层和激活层。这个模型的输入尺寸为 `input_shape` ,输出的类别数为 `nb_classes` 。
阅读全文