CK+数据集共七种表情,分别如下:
共981张图片;
fer2013数据集较大,也是共七种面部表情,如下:
分别存放在如下三个文件夹中:
共35887张图片;
采用基于resnet50的人脸表情识别方法,在CK+数据集准确率达98%,在fer2013数据集准确率达90%。
代码如下:
import os
import numpy as np
import matplotlib.image as mpimg
import random
import matplotlib.pyplot as plt
import plotly.graph_objects as go
from tensorflow.keras.applications import ResNet50
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, EarlyStopping
from sklearn.utils import shuffle
from sklearn.model_selection import train_test_split
# from sklearn.preprocessing import LabelEncoder
# from skimage.transform import resize
# from keras.utils import to_categorical
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
from sklearn.preprocessing import LabelEncoder
from tensorflow.keras.preprocessing.image import load_img, img_to_array
dataset_path = './ck/CK+48'
def count_images_and_classes(path):
class_counts = {}
total_count = 0
for class_name in os.listdir(path):
class_path = os.path.join(path, class_name)
if os.path.isdir(class_path):
# Count the number of images in each subfolder
count = len(os.listdir(class_path))
total_count += count
class_counts[class_name] = count
return total_count, class_counts
total_count, class_counts = count_images_and_classes(dataset_path)
print("Total number of images:", total_count)
print("Number of images in each class:")
for class_name, count in class_counts.items():
print(f