1 Star 0 Fork 0

kangchi/Competition_CAIL

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
resnet.py 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
renjunxiang 提交于 2018-07-13 14:21 . 全部代码
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)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/kangchi/Competition_CAIL.git
git@gitee.com:kangchi/Competition_CAIL.git
kangchi
Competition_CAIL
Competition_CAIL
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385