# Gated CNN
This is Keras implementation of “Gated Linear Unit”.
# Requirements
- Keras 2.1.2
- Tensorflow 1.0.0
- Others can be seen in requirements.txt
# Usage
The main Class is `GatedConvBlock` in `py/gated_cnn.py`.
Because there is a residual connection in Gated Linear Unit (GLU), the padding of conv must be `same`.
Let's take some example.
```
from gated_cnn import GatedConvBlock
model = Sequential()
model.add(Convolution2D(nb_filters, kernel_size,
padding='valid',
input_shape=input_shape))
model.add(Activation('relu'))
model.add(GatedConvBlock(Convolution2D(nb_filters*2, kernel_size,
padding='same')))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adadelta',
metrics=['accuracy'])
model.fit(X_train, Y_train, batch_size=batch_size, epochs=nb_epoch,
verbose=1, validation_data=(X_test, Y_test))
```
Check `py/mnist_gated_cnn.py` for more detail.
# Reference
- https://github.com/anantzoid/Language-Modeling-GatedCNN
> Written with [StackEdit](https://stackedit.io/).
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
门控CNN 这是Keras的“门控线性单元”的实现。 要求 Keras 2.1.2 Tensorflow 1.0.0 其他可以在requirements.txt中看到 用法 主类是GatedConvBlock在py/gated_cnn.py 。 由于门控线性单元(GLU)中存在残留连接,因此conv的填充必须same 。 让我们举个例子。 from gated_cnn import GatedConvBlock model = Sequential() model.add(Convolution2D(nb_filters, kernel_size, padding='valid', input_shape=input_shape)) model.add(Activation('relu
资源详情
资源评论
资源推荐
收起资源包目录
gated_cnn-master.zip (6个子文件)
gated_cnn-master
.gitignore 1KB
requirements.txt 230B
LICENSE 11KB
README.md 1KB
py
mnist_gated_cnn.py 2KB
gated_cnn.py 6KB
共 6 条
- 1
铭哲友野
- 粉丝: 29
- 资源: 4534
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0