If you like the video, please subscribe to the channel by using the below link
tinyurl.com/1w5i9nnu
In this video, I have explained how you can train a neural network for facial expression detection. we have trained tensorflow here for model tarining
Link to download the file
drive.google.com/file/d/1-lto...
Here is the script to extract the image dataset
##########################
import tarfile
fname = 'fer2013.tar.gz'
if fname.endswith("tar.gz"):
tar = tarfile.open(fname, "r:gz")
tar.extractall()
tar.close()
elif fname.endswith("tar"):
tar = tarfile.open(fname, "r:")
tar.extractall()
tar.close()
###########################
Data Dictionary
######################
label_to_text = {0:'anger', 1:'disgust', 2:'fear', 3:'happiness', 4: 'sadness', 5: 'surprise', 6: 'neutral'}
######################
Visulize sample dataset
######################
fig = pyplot.figure(1, (14, 14))
k = 0
for label in sorted(df.emotion.unique()):
for j in range(3):
px = df[df.emotion==label].pixels.iloc[k]
px = np.array(px.split(' ')).reshape(48, 48).astype('float32')
k += 1
ax = pyplot.subplot(7, 7, k)
ax.imshow(px)
ax.set_xticks([])
ax.set_yticks([])
ax.set_title(label_to_text[label])
pyplot.tight_layout()
########################
callback and checkpoint code
#######################################
file_name = 'best_model.h5'
checkpoint_path= os.path.join('checkpoint',file_name)
call_back = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
monitor='val_accuracy',
verbose=1,
save_freq='epoch',
save_best_only=True,
save_weights_only=False,
mode='max')
##############################################
Model build code
basemodel = tf.keras.models.Sequential([tf.keras.layers.Conv2D(32,(3,3),activation='relu',input_shape = (48,48,1)),
tf.keras.layers.MaxPool2D(2,2),
#
tf.keras.layers.Conv2D(64,(3,3),activation='relu',input_shape = (48,48,1)),
tf.keras.layers.MaxPool2D(2,2),
#
tf.keras.layers.Conv2D(128,(3,3),activation='relu),
tf.keras.layers.MaxPool2D(2,2),
#
tf.keras.layers.Conv2D(256,(3,3),activation='relu'),
tf.keras.layers.MaxPool2D(2,2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(1000,activation='relu'),
tf.keras.layers.Dense(7,activation = 'softmax')
])
Dataset Developed by
"Challenges in Representation Learning: A report on three machine learning
contests." I Goodfellow, D Erhan, PL Carrier, A Courville, M Mirza, B
Hamner, W Cukierski, Y Tang, DH Lee, Y Zhou, C Ramaiah, F Feng, R Li,
X Wang, D Athanasakis, J Shawe-Taylor, M Milakov, J Park, R Ionescu,
M Popescu, C Grozea, J Bergstra, J Xie, L Romaszko, B Xu, Z Chuang, and
Y. Bengio. arXiv 2013.
See fer2013.bib for a bibtex entry.
13 фев 2021