forked from abdelmounim/RealtimeFacialEmotionRecognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCKPlus_convert_to_Jaffe_format.py
77 lines (57 loc) · 2.08 KB
/
CKPlus_convert_to_Jaffe_format.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
###############################################################################
# OpenCV + Caffe
# Uses OpenCV for face detection and cropping to serve as inputs to Caffe.
# Uses a Caffe VGG_S net from EmotiW'15 [1] to classify emotion.
#
# [1] Gil Levi and Tal Hassner, Emotion Recognition in the Wild via
# Convolutional Neural Networks and Mapped Binary Patterns, Proc. ACM
# International Conference on Multimodal Interaction (ICMI), Seattle, Nov. 2015
###############################################################################
import os, shutil, sys, time, re, glob
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
from PIL import Image
import caffe
from caffe_functions import *
from opencv_functions import *
from utility_functions import *
### USER-SPECIFIED VARIABLES: ###
# List your dataset root directories here:
dirCKPlus = 'datasets/CK_Plus'
# Select which dataset to use (case insensitive):
dataset = 'ckplus'
# Flags:
cropFlag = True # False disables image cropping
### START SCRIPT: ###
# Set up inputs
dir = dirCKPlus
color = False
single_face = True
# Clean up and discard anything from the last run
dirCrop = dir + '/cropped'
rmdir(dirCrop)
# Master list of categories for EmotitW network
categories = [ 'Angry' , 'Disgust' , 'Fear' , 'Happy' , 'Neutral' , 'Sad' , 'Surprise']
suffixes = ['AN', 'DI', 'FE', 'HA', 'NE', 'SA', 'SU']
# Load dataset image list
input_list, labels = importDataset(dir, dataset, categories)
# Perform detection and cropping if desired (and it should be desired)
mkdir(dirCrop)
#mkdir(dir + '/cropped/CKPlus_Images')
input_list = faceCrop(dirCrop, input_list, color, single_face)
# Print outs
print (input_list)
print (labels)
# Rename all files
for i in range(len(input_list)):
# Get file info
filename = input_list[i]
lab = labels[i]
labText = suffixes[lab]
# Generate new filename
fn = filename.split('.')
out = fn[0] + '.' + labText + '.' + fn[1]
# Rename file
os.rename(filename,out)