jhan15 / facial_emotion_recognition

It's a project of facial emotion recognition.
25 stars 6 forks source link

About data types #1

Open spr1teZzz opened 1 year ago

spr1teZzz commented 1 year ago

Can you show me the data type of your training?

gipinze commented 1 year ago

Hi, I hope you are asking about the data type (file format .p), if its so, this is the explanation chatGPT gave me

A .p file is not a common file extension, so it's hard to say what type of file it is without more information. In general, pickle files are a widely used format for serializing and deserializing Python objects, and they have some advantages such as being easy to use and supporting most Python objects. However, the choice of file format depends on the specific use case and requirements

And here is the code to convert your dataset into a archive with a .p format

import os import cv2 import numpy as np import pickle

Define the path to your data folder

data_folder = "path/to/your/data/folder/" (the dataset its no divided in test and train yet)

Define the list of classes

classes = ["class1", "class2", "class3"] # The names of your classes (emotions in this case)

Define the size of the images

img_size = 224 ## Image size

Initialize the list of image data and labels

data = [] labels = []

Loop over each class folder

for class_idx, class_name in enumerate(classes):

Define the path to the class folder

class_folder = os.path.join(data_folder, class_name)
# Loop over each image in the class folder
for img_name in os.listdir(class_folder):
    # Read the image using OpenCV
    img_path = os.path.join(class_folder, img_name)
    img = cv2.imread(img_path)
    # Resize the image to the desired size
    img = cv2.resize(img, (img_size, img_size))
    # Convert the image to grayscale
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    # Add the image data and label to the lists
    data.append(img)
    labels.append(class_idx)

Convert the lists to numpy arrays

data = np.array(data) labels = np.array(labels)

Save the data and labels as a .p file

with open("image_data.p", "wb") as f: pickle.dump((data, labels), f)

Hope this helps

gipinze commented 1 year ago

Can you show me the data type of your training?

Hello,

Sorry for the span, but I spent the weekend modifying the code and now it works,

here you can go to see in my github repo

https://github.com/gipinze/Computer-Vision-Thesis/tree/main/MediaPipe%20CNN

In short, you need to convert your dataset to pickle file or .p format, so I have 2 files to do that (one for pickle and one for .p)

Once you do that the code is basically the same, but I did some modifications to make it easier and similar to my previous work.

I trained one model with 48 x 48 x 1 images using RAF-DB and got me 74% accuracy, so its pretty good and also very fast

Hope is not late for what you need and it still works for you.

Have a nice day