1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import tensorflow as tf
- from sklearn.model_selection import train_test_split
- def main():
-
- (x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()
-
- y_train_onehot = tf.keras.utils.to_categorical(y_train)
- y_test_onehot = tf.keras.utils.to_categorical(y_test)
-
- x_train = x_train / 255.0
- x_test = x_test / 255.0
-
- model = tf.keras.Sequential([
- tf.keras.layers.Input(shape=(28, 28)),
- tf.keras.layers.LSTM(128, return_sequences=True),
- tf.keras.layers.LSTM(128),
-
- tf.keras.layers.Dense(10, activation="softmax"),
- ])
-
- model.compile(
- optimizer="adam",
- loss="categorical_crossentropy",
- metrics=["acc"],
- )
-
- model.fit(
- x_train, y_train_onehot,
- batch_size=32,
- epochs=10,
- validation_data=(x_test, y_test_onehot),
- )
-
- if __name__ == "__main__":
- main()
|