-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_utils.py
More file actions
37 lines (22 loc) · 930 Bytes
/
Copy pathdata_utils.py
File metadata and controls
37 lines (22 loc) · 930 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
"""Data utility functions."""
import os
import matplotlib.pyplot as plt
import numpy as np
import torch
import torch.utils.data as data
from PIL import Image
from torchvision import transforms
import _pickle as pickle
def rel_error(x, y):
""" Returns relative error """
assert x.shape == y.shape, "tensors do not have the same shape. %s != %s" % (x.shape, y.shape)
return np.max(np.abs(x - y) / (np.maximum(1e-8, np.abs(x) + np.abs(y))))
def string2image(string):
"""Converts a string to a numpy array."""
return np.array([int(item) for item in string.split()]).reshape((96, 96))
def get_image(idx, key_pts_frame):
image_string = key_pts_frame.loc[idx]['Image']
return string2image(image_string)
def get_keypoints(idx, key_pts_frame):
keypoint_cols = list(key_pts_frame.columns)[:-1]
return key_pts_frame.iloc[idx][keypoint_cols].values.reshape((15, 2)).astype(np.float32)