#๐Ÿ”’ Low accuracy.

6 messages ยท Page 1 of 1 (latest)

oak quail
#

My model gets around a 65% val_accuracy what do I do to increase it? I feel its not reliable and when I give it actual images it get like it doesn't get up to the 65 mark of validation accuracy. Its an expression identifier model btw. I have 5 classes.

half vortexBOT
#

@oak quail

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

oak quail
#

Here is the code:
`import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator # type: ignore
from tensorflow.keras.callbacks import TensorBoard # type: ignore
import time

name = "Emotion-Detecter-CNN-64x64-{}".format(int(time.time()))
tensorboard = TensorBoard(log_dir='logs/{name}')
train_datagen = ImageDataGenerator(
rescale=1./255,
rotation_range=30,
shear_range=0.3,
zoom_range=0.3,
width_shift_range=0.4,
height_shift_range=0.4,
horizontal_flip=True,
brightness_range=[0.8, 1.2],
fill_mode='nearest')

training_set = train_datagen.flow_from_directory(
'C:\Users\yatha\OneDrive\Desktop\CNN Expression identifier\Train',
target_size =(128, 128),
batch_size = 48,
classes = ['Anger', 'Fear', 'Happy', 'Sad', 'Surprise'],
class_mode = 'categorical',
shuffle=True,
)

test_datagen = ImageDataGenerator(rescale=1./255)

test_set = test_datagen.flow_from_directory(
'C:\Users\yatha\OneDrive\Desktop\CNN Expression identifier\Test',
target_size =(128, 128),
batch_size = 48,
classes = ['Anger', 'Fear', 'Happy', 'Sad', 'Surprise'],
class_mode = 'categorical',
shuffle=True,
)
cnn = tf.keras.models.Sequential()
cnn.add(tf.keras.layers.Conv2D(
filters=16,
kernel_size=3,
activation='relu',
input_shape=[128, 128, 3]
))
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
cnn.add(tf.keras.layers.Conv2D(
filters=16,
kernel_size=3,
activation='relu',
input_shape=[128, 128, 3]
))
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
cnn.add(tf.keras.layers.Conv2D(
filters=16,
kernel_size=3,
activation='relu'
))
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
cnn.add(tf.keras.layers.Flatten())
cnn.add(tf.keras.layers.Dense(units = 512, activation = 'relu'))
cnn.add(tf.keras.layers.Dense(units = 512, activation = 'relu'))
cnn.add(tf.keras.layers.Dense(units = 512, activation = 'relu'))
`

#

`cnn.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
cnn.fit(x = training_set, validation_data = test_set, epochs = 25, callbacks = [tensorboard] )

import numpy as np

Load an image for prediction

from tensorflow.keras.preprocessing import image # type: ignore
img = image.load_img('C:\Users\yatha\Desktop\DeepLearning and Machine Learning\Part 8 - Deep Learning\CNN Expression identifier\Happy.jpg', target_size=(128, 128))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0) / 255.0 # Normalize the image data

Make prediction

prediction = cnn.predict(img_array)

Get the predicted emotion

emotions = ['Anger', 'Fear', 'Happy', 'Sad', 'Surprise']
predicted_emotion = emotions[np.argmax(prediction)]

print(f"The person in this image has '{predicted_emotion}' expression.")
`

half vortexBOT
#

@oak quail

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.