Keras2.x GRUCell使用示例

网友投稿 562 2022-10-01

Keras2.x GRUCell使用示例

Keras2.x GRUCell使用示例

看过keras的人会发现有一个GRUCell,LSTMCell这样的东西,其实就是一个RNN单元,然后可能会有人去用它,但是发现按照常规的方法用的话会报错,这里我提供了一个示例代码,这个东西其实可以和RNN来配合使用:

直接上代码:

from keras.models import Modelfrom keras.layers import *encoder_inputs=Input(shape=(20,2048))cells=[GRUCell(100) for _ in range(20)]rnn_layer=RNN(cells,return_state=True)(encoder_inputs)model = Model(inputs=encoder_inputs, outputs=rnn_layer)print(model.summary())

运行的输出为:

/home/eric/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. from ._conv import register_converters as _register_convertersUsing TensorFlow backend._________________________________________________________________Layer (type) Output Shape Param # =================================================================input_1 (InputLayer) (None, 20, 2048) 0 _________________________________________________________________rnn_1 (RNN) [(None, 100), (None, 100) 1790400 =================================================================Total params: 1,790,400Trainable params: 1,790,400Non-trainable params: 0_________________________________________________________________None

没有报错啦

参考文献

[1].attention is all you need with keras. ​​https://kaggle.com/shujunge/attention-is-all-you-need-with-keras​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Spring IOC 常用注解与使用实例详解
下一篇:小程序new Date()方法失效怎么办(小程序能在电脑上打开吗)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~