Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Import
- import matplotlib.pyplot as plt
- import tensorflow as tf
- #Verifie si tensorflow est en version 2.0
- assert hasattr(tf, 'function')
- #Charge le dataset
- fashion_mnist = tf.keras.datasets.fashion_mnist
- (images, targets), (_, _) = fashion_mnist.load_data() # Target correspond à la catégorie de l'image
- #Associe un nom à la catégorie
- targets_names = ["T-shirt", "Pantalons", "Pull", "Dress", "Veste", "Sandale", "Haut", "Chaussure", "Sac", "Bottes"]
- # On créer le modèle
- model = tf.keras.models.Sequential() # Model sequentiel : l'instruction d'après prend en entrée le résultat de l'instruction d'avant
- # Applatie l'image : (28,28) -> (1,784)
- model.add(tf.keras.layers.Flatten(input_shape=[28,28]))
- #Layers
- model.add(tf.keras.layers.Dense(256, activation="relu"))
- model.add(tf.keras.layers.Dense(128, activation="relu"))
- model.add(tf.keras.layers.Dense(10, activation="softmax"))
- model.compile(
- loss="sparse_categorical_crossentropy",
- optimizer="sgd",
- metrics=["accuracy"]
- )
- history = model.fit(images,targets, epochs=10)
- loss_curve = history.history["loss"]
- acc_curve = history.history["accuracy"]
- plt.plot(loss_curve)
- plt.title("Loss")
- plt.show()
- plt.plot(acc_curve)
- plt.title("Accuracy")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement