老师,想看一下tensorflow2.x实现LSTM
来源:5-9 图像增强实战
慕慕65597133
2021-05-28
老师,想看一下tensorflow2.x实现lstm的代码
写回答
1回答
-
正十七
2021-06-07
tf2.x下实现lstm比较简单,tf2.x主推Keras的实现方式,例子如下:
embedding_dim = 16 batch_size = 512 single_rnn_model = keras.models.Sequential([ # 1. define matrix: [vocab_size, embedding_dim] # 2. [1,2,3,4..], max_length * embedding_dim # 3. batch_size * max_length * embedding_dim keras.layers.Embedding(vocab_size, embedding_dim, input_length = max_length), keras.layers.LSTM(units = 64, return_sequences = False), keras.layers.Dense(64, activation = 'relu'), keras.layers.Dense(1, activation='sigmoid'), ]) single_rnn_model.summary() single_rnn_model.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
如果想学习tf2.x的编程,可以看我的另一门课程:https://coding.imooc.com/class/344.html
00
相似问题