Skip to content

Commit

Permalink
Fixes 1adrianb#16
Browse files Browse the repository at this point in the history
  • Loading branch information
1adrianb committed Oct 7, 2017
1 parent 77ec1ce commit 2aa7c57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/detect_landmarks_in_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@

ax.view_init(elev=90., azim=90.)
ax.set_xlim(ax.get_xlim()[::-1])
plt.show()
plt.show()
10 changes: 9 additions & 1 deletion face_alignment/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,13 @@ def shuffle_lr(parts, pairs=None):


def flip(tensor, is_label=False):
was_cuda = False
if isinstance(tensor, torch.Tensor):
tensor = tensor.numpy()
elif isinstance(tensor, torch.cuda.FloatTensor):
tensor = tensor.cpu().numpy()
was_cuda = True

was_squeezed = False
if tensor.ndim == 4:
tensor = np.squeeze(tensor)
Expand All @@ -223,4 +228,7 @@ def flip(tensor, is_label=False):
tensor = cv2.flip(tensor, 1).reshape(tensor.shape)
if was_squeezed:
tensor = np.expand_dims(tensor, axis=0)
return torch.from_numpy(tensor)
tensor = torch.from_numpy(tensor)
if was_cuda:
tensor = tensor.cuda()
return tensor

0 comments on commit 2aa7c57

Please sign in to comment.