-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransforms.py
More file actions
29 lines (18 loc) · 795 Bytes
/
Copy pathtransforms.py
File metadata and controls
29 lines (18 loc) · 795 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
import torch
from torchvision import transforms, utils
import numpy as np
class Normalize(object):
"""Normalizes keypoints.
"""
def __call__(self, sample):
image, key_pts = sample['image'], sample['keypoints']
image = np.true_divide(image,255)
key_pts = np.true_divide(key_pts,48)-1
return {'image': image, 'keypoints': key_pts}
class ToTensor(object):
"""Convert ndarrays in sample to Tensors."""
#also add a dummy channel dimension, as per expectations of pytorch convolutional layers
def __call__(self, sample):
image, key_pts = sample['image'], sample['keypoints']
return {'image': torch.from_numpy(image).float().unsqueeze(0),
'keypoints': torch.from_numpy(key_pts).float()}