代码拉取完成,页面将自动刷新
from keras.models import Model
from keras.layers import Dense, Input, Embedding
from keras.layers import GlobalMaxPool1D, Dropout, Conv1D, BatchNormalization, Activation, Add
from keras.utils import plot_model
def block(x, kernel_size):
x_Conv_1 = Conv1D(filters=512, kernel_size=[kernel_size], strides=1, padding='same')(x)
x_Conv_1 = Activation(activation='relu')(x_Conv_1)
x_Conv_2 = Conv1D(filters=512, kernel_size=[kernel_size], strides=1, padding='same')(x_Conv_1)
x_Conv_2 = Add()([x, x_Conv_2])
x = Activation(activation='relu')(x_Conv_2)
return x
if __name__ == '__main__':
num_words = 80000
maxlen = 400
kernel_size = 3
DIM = 512
batch_size = 256
data_input = Input(shape=[maxlen])
word_vec = Embedding(input_dim=num_words + 1,
input_length=maxlen,
output_dim=DIM,
mask_zero=0,
name='Embedding')(data_input)
block1 = block(x=word_vec, kernel_size=3)
block2 = block(x=block1, kernel_size=3)
x = GlobalMaxPool1D()(block2)
x = BatchNormalization()(x)
x = Dense(1000, activation="relu")(x)
x = Dropout(0.2)(x)
x = Dense(202, activation="sigmoid")(x)
model = Model(inputs=data_input, outputs=x)
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
plot_model(model, './resnet.png', show_shapes=True)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。