-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLSTM.py
More file actions
25 lines (21 loc) · 953 Bytes
/
LSTM.py
File metadata and controls
25 lines (21 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import matplotlib.pyplot as plt
from tensorflow.keras import datasets, layers, models
(x_train, y_train), (x_test, y_test) = datasets.mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = models.Sequential([
layers.LSTM(64, input_shape=(28, 28), activation='relu', return_sequences=True),
layers.LSTM(128, activation='relu', return_sequences=True),
layers.LSTM(256, activation='relu', return_sequences=True),
layers.LSTM(512, activation='relu', return_sequences=True),
layers.LSTM(256, activation='relu', return_sequences=True),
layers.LSTM(128, activation='relu'),
layers.Dense(10, activation='softmax')
])
model.summary()
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
history = model.fit(x_train, y_train, epochs=5, validation_data=(x_test, y_test), batch_size=64)
test_loss, test_acc = model.evaluate(x_train, y_train, batch_size=64)