Skip to content

Commit

Permalink
remove duplicate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Zhang authored and Richard Zhang committed Aug 26, 2021
1 parent 3767a70 commit 6c5877c
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions lpips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ def dssim(p0, p1, range=255.):
from skimage.measure import compare_ssim
return (1 - compare_ssim(p0, p1, data_range=range, multichannel=True)) / 2.

def rgb2lab(in_img,mean_cent=False):
from skimage import color
img_lab = color.rgb2lab(in_img)
if(mean_cent):
img_lab[:,:,0] = img_lab[:,:,0]-50
return img_lab

def tensor2np(tensor_obj):
# change dimension of a tensor object into a numpy array
return tensor_obj[0].cpu().float().numpy().transpose((1,2,0))
Expand Down Expand Up @@ -84,9 +77,16 @@ def load_image(path):

return img

def rgb2lab(input):
from skimage import color
return color.rgb2lab(input / 255.)
# def rgb2lab(input):
# from skimage import color
# return color.rgb2lab(input / 255.)

# def rgb2lab(in_img,mean_cent=False):
# from skimage import color
# img_lab = color.rgb2lab(in_img)
# if(mean_cent):
# img_lab[:,:,0] = img_lab[:,:,0]-50
# return img_lab

def tensor2im(image_tensor, imtype=np.uint8, cent=1., factor=255./2.):
image_numpy = image_tensor[0].cpu().float().numpy()
Expand All @@ -101,19 +101,6 @@ def tensor2vec(vector_tensor):
return vector_tensor.data.cpu().numpy()[:, :, 0, 0]


def tensor2im(image_tensor, imtype=np.uint8, cent=1., factor=255./2.):
# def tensor2im(image_tensor, imtype=np.uint8, cent=1., factor=1.):
image_numpy = image_tensor[0].cpu().float().numpy()
image_numpy = (np.transpose(image_numpy, (1, 2, 0)) + cent) * factor
return image_numpy.astype(imtype)

def im2tensor(image, imtype=np.uint8, cent=1., factor=255./2.):
# def im2tensor(image, imtype=np.uint8, cent=1., factor=1.):
return torch.Tensor((image / factor - cent)
[:, :, :, np.newaxis].transpose((3, 2, 0, 1)))



def voc_ap(rec, prec, use_07_metric=False):
""" ap = voc_ap(rec, prec, [use_07_metric])
Compute VOC AP given precision and recall.
Expand Down

0 comments on commit 6c5877c

Please sign in to comment.