The mannequin is getting actually low accuracy. That is my first time writing a neural community so I dont actually know methods to make it higher
import tensorflow as tf
import matplotlib.pyplot as plt#knowledge set
knowledge = tf.keras.datasets.cifar10
(x_train, y_train), (x_test, y_test) = knowledge.load_data()
plt.imshow(x_train[0], cmap=plt.cm.binary)
#normalize knowledge
x_train = tf.keras.utils.normalize(x_train, axis=1)
x_test = tf.keras.utils.normalize(x_test, axis=1)
#constructing AI mannequin
mannequin = tf.keras.fashions.Sequential()
mannequin.add(tf.keras.layers.Flatten())
mannequin.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
mannequin.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
mannequin.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))
#compile mannequin
mannequin.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
plt.present()
#practice AI mannequin
mannequin.match(x_train, y_train, epochs=3)
I ran your mannequin and obtained 50% accuracy by growing the variety of epochs to about 30.
- When coaching a mannequin, make certain to let it run till your loss operate plateaus.
Coin-toss accuracy is 10%, so your mannequin is a lot better than likelihood.
- At all times make certain to grasp what could be “good” or “dangerous” accuracy in your dataset.
To enhance the mannequin structure, including convolutional layers will assist loads. Convolutional Neural Networks are the state-of-the-art for picture classificayion and you need to learn up on them if you wish to perceive pc imaginative and prescient.
mannequin = tf.keras.fashions.Sequential()
# the subsequent two strains add convolution layers to your code above
mannequin.add(tf.keras.layers.Conv2D(6, 3, strides=(1, 1), padding="legitimate"))
mannequin.add(tf.keras.layers.Conv2D(10, 5))
mannequin.add(tf.keras.layers.Flatten())
Operating this for 12 epochs will get to 78% accuracy on my native machine and it has not completed studying.
- Use convolutional NNs when dealing with photos.
Answered By — philosofool
Reply Checked By — Candace Johnson (FixIt Volunteer)
This Reply collected from stackoverflow, is licensed beneath cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0