import numpy as np
from tensorflow.keras.callbacks import EarlyStopping, TensorBoard
from tensorflow.keras.datasets import fashion_mnist
from tensorflow.keras.layers import LSTM, Dense
from tensorflow.keras.models import Sequential
from tensorflow.keras.utils import to_categorical

(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()

y_train = to_categorical(y_train)
y_test = to_categorical(y_test)

x_train = x_train.reshape(
    (x_train.shape[0], x_train.shape[1], x_train.shape[2])).astype('float32')/255
x_test = x_test.reshape(
    (x_test.shape[0], x_test.shape[1], x_test.shape[2])).astype('float32')/255

model = Sequential()
model.add(LSTM(64, activation='relu', input_shape=(
    x_train.shape[1], x_train.shape[2])))
model.add(Dense(512))
model.add(Dense(256))
model.add(Dense(10))

model.summary()

es = EarlyStopping(monitor='loss', patience=125, mode='auto')
to_hist = TensorBoard(log_dir='graph', histogram_freq=0,
                      write_graph=True, write_images=True)

model.compile(loss='categorical_crossentropy',
              optimizer='adam', metrics=['acc'])
history = model.fit(x_train, y_train, epochs=10, batch_size=32,
                    verbose=1, validation_split=0.2, callbacks=[es, to_hist])

loss, acc = model.evaluate(x_test, y_test, batch_size=32)
print("loss: ", loss)
print("acc:", acc)


y_predict = model.predict(x_test[:10])
print("y predicts: ")
print([np.argmax(y, axis=None, out=None) for y in y_predict])
print()
print("real y's")
print([np.argmax(y, axis=None, out=None) for y in y_test[:10]])

e4111053a73175bbc7eb72ba76404ac49b524a1e
<mask token>

<mask token>
model.add(LSTM(64, activation='relu', input_shape=(x_train.shape[1],
    x_train.shape[2])))
model.add(Dense(512))
model.add(Dense(256))
model.add(Dense(10))
model.summary()
<mask token>
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=[
    'acc'])
<mask token>
print('loss: ', loss)
print('acc:', acc)
<mask token>
print('y predicts: ')
print([np.argmax(y, axis=None, out=None) for y in y_predict])
print()
print("real y's")
print([np.argmax(y, axis=None, out=None) for y in y_test[:10]])

<mask token>
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)
x_train = x_train.reshape((x_train.shape[0], x_train.shape[1], x_train.
    shape[2])).astype('float32') / 255
x_test = x_test.reshape((x_test.shape[0], x_test.shape[1], x_test.shape[2])
    ).astype('float32') / 255
model = Sequential()
model.add(LSTM(64, activation='relu', input_shape=(x_train.shape[1],
    x_train.shape[2])))
model.add(Dense(512))
model.add(Dense(256))
model.add(Dense(10))
model.summary()
es = EarlyStopping(monitor='loss', patience=125, mode='auto')
to_hist = TensorBoard(log_dir='graph', histogram_freq=0, write_graph=True,
    write_images=True)
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=[
    'acc'])
history = model.fit(x_train, y_train, epochs=10, batch_size=32, verbose=1,
    validation_split=0.2, callbacks=[es, to_hist])
loss, acc = model.evaluate(x_test, y_test, batch_size=32)
print('loss: ', loss)
print('acc:', acc)
y_predict = model.predict(x_test[:10])
print('y predicts: ')
print([np.argmax(y, axis=None, out=None) for y in y_predict])
print()
print("real y's")
print([np.argmax(y, axis=None, out=None) for y in y_test[:10]])

import numpy as np
from tensorflow.keras.callbacks import EarlyStopping, TensorBoard
from tensorflow.keras.datasets import fashion_mnist
from tensorflow.keras.layers import LSTM, Dense
from tensorflow.keras.models import Sequential
from tensorflow.keras.utils import to_categorical
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)
x_train = x_train.reshape((x_train.shape[0], x_train.shape[1], x_train.
    shape[2])).astype('float32') / 255
x_test = x_test.reshape((x_test.shape[0], x_test.shape[1], x_test.shape[2])
    ).astype('float32') / 255
model = Sequential()
model.add(LSTM(64, activation='relu', input_shape=(x_train.shape[1],
    x_train.shape[2])))
model.add(Dense(512))
model.add(Dense(256))
model.add(Dense(10))
model.summary()
es = EarlyStopping(monitor='loss', patience=125, mode='auto')
to_hist = TensorBoard(log_dir='graph', histogram_freq=0, write_graph=True,
    write_images=True)
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=[
    'acc'])
history = model.fit(x_train, y_train, epochs=10, batch_size=32, verbose=1,
    validation_split=0.2, callbacks=[es, to_hist])
loss, acc = model.evaluate(x_test, y_test, batch_size=32)
print('loss: ', loss)
print('acc:', acc)
y_predict = model.predict(x_test[:10])
print('y predicts: ')
print([np.argmax(y, axis=None, out=None) for y in y_predict])
print()
print("real y's")
print([np.argmax(y, axis=None, out=None) for y in y_test[:10]])

import numpy as np
from tensorflow.keras.callbacks import EarlyStopping, TensorBoard
from tensorflow.keras.datasets import fashion_mnist
from tensorflow.keras.layers import LSTM, Dense
from tensorflow.keras.models import Sequential
from tensorflow.keras.utils import to_categorical

(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()

y_train = to_categorical(y_train)
y_test = to_categorical(y_test)

x_train = x_train.reshape(
    (x_train.shape[0], x_train.shape[1], x_train.shape[2])).astype('float32')/255
x_test = x_test.reshape(
    (x_test.shape[0], x_test.shape[1], x_test.shape[2])).astype('float32')/255

model = Sequential()
model.add(LSTM(64, activation='relu', input_shape=(
    x_train.shape[1], x_train.shape[2])))
model.add(Dense(512))
model.add(Dense(256))
model.add(Dense(10))

model.summary()

es = EarlyStopping(monitor='loss', patience=125, mode='auto')
to_hist = TensorBoard(log_dir='graph', histogram_freq=0,
                      write_graph=True, write_images=True)

model.compile(loss='categorical_crossentropy',
              optimizer='adam', metrics=['acc'])
history = model.fit(x_train, y_train, epochs=10, batch_size=32,
                    verbose=1, validation_split=0.2, callbacks=[es, to_hist])

loss, acc = model.evaluate(x_test, y_test, batch_size=32)
print("loss: ", loss)
print("acc:", acc)


y_predict = model.predict(x_test[:10])
print("y predicts: ")
print([np.argmax(y, axis=None, out=None) for y in y_predict])
print()
print("real y's")
print([np.argmax(y, axis=None, out=None) for y in y_test[:10]])
