-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreprocess.py
More file actions
38 lines (33 loc) · 958 Bytes
/
Preprocess.py
File metadata and controls
38 lines (33 loc) · 958 Bytes
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
import tensorflow as tf
def image_preprocess(image):
"""Takes in a Tensor and transforms it to a (-1, 1) float Tensor.
Args:
image: Tensor array.
Returns:
float_image: Tensor float32 array with range (-1, 1)
"""
return (tf.to_float(image) / 127.5) - 1.0
def gaze_images_preprocess(face, left, right, gaze, pts):
"""Preprocesses all of the gaze images.
Args:
face: Face tensor.
left: Left eye tensor.
right: Right eye tensor.
gaze: Gaze direction tensor.
pts: Face pts tensor.
Returns:
face: Preprocessed face image.
left: Preprocessed left image.
right: Preprocessed right image.
gaze: Unchange gaze.
pts: Unchanged pts.
"""
return (image_preprocess(face),
image_preprocess(left),
image_preprocess(right),
gaze,
pts)
def image_correction(tensor):
red, green, blue = tf.split(tensor, 3, 3)
bgr = tf.concat([blue, green, red], 3)
return bgr