Select Git revision
Forked from
Thomas Sainrat / formation-git
Source project has a limited visibility.
utils.py 1.34 KiB
import numpy as np
import cv2
import matplotlib.pyplot as plt
from config import emotions
def afficher(image):
if len(image.shape) == 3:
if image.shape[2] == 3: # (h,l,3)
plt.imshow(image)
elif image.shape[2] == 1: # (h,l,1)->(h,l)
image2 = image
plt.imshow(tf.squeeze(image))
elif len(image.shape) == 2: # (h,l)
plt.imshow(image)
def predir(modele, image):
# Return output of image from modele
return modele.predict(np.array([image]))[0, :]
def normAndResize(image, input_shape):
# For an array image of shape (a,b,c) or (a,b), transform it into (h,l,p). Also normalize it.
h, l, p = input_shape
# resize for h and l #
image = cv2.resize(image, dsize=(h, l), interpolation=cv2.INTER_CUBIC)
# if we want (h,l,3) -> (h,l,1) , we first transform it in to (h,l) (grey the image)
if len(image.shape) == 3 and p == 1 and image.shape[2] != 1:
image = image.mean(2)
image = np.reshape(image, (h, l, p)) # restore third dimension
image = image.astype("float32")
image = (image/127.5)-1 # normalisation
return image
def emotionToNumber(emotion):
emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"]
return emotions.index(emotion)