facial_emotion_detector / utils /preprocessor.py
AhmedIbrahim007's picture
Upload 36 files
8f412ba verified
raw
history blame
706 Bytes
import numpy as np
from imageio import imread
from skimage.transform import resize as imresize
def preprocess_input(x, v2=True):
x = x.astype('float32')
x = x / 255.0
if v2:
x = x - 0.5
x = x * 2.0
return x
def _imread(image_name):
return imread(image_name)
def _imresize(image_array, size):
return imresize(image_array, size)
def to_categorical(integer_classes, num_classes=2):
integer_classes = np.asarray(integer_classes, dtype='int')
num_samples = integer_classes.shape[0]
categorical = np.zeros((num_samples, num_classes))
categorical[np.arange(num_samples), integer_classes] = 1
return categorical