Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch the lpips computation from cpu to cuda. ~15x faster for evaluation. #428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import torch
import torchvision.transforms.functional as tf
from utils.loss_utils import ssim
from lpipsPyTorch import lpips
#from lpipsPyTorch import lpips
import lpips
import json
from tqdm import tqdm
from utils.image_utils import psnr
Expand Down Expand Up @@ -71,7 +72,7 @@ def evaluate(model_paths):
for idx in tqdm(range(len(renders)), desc="Metric evaluation progress"):
ssims.append(ssim(renders[idx], gts[idx]))
psnrs.append(psnr(renders[idx], gts[idx]))
lpipss.append(lpips(renders[idx], gts[idx], net_type='vgg'))
lpipss.append(lpips_fn(renders[idx], gts[idx]))

print(" SSIM : {:>12.7f}".format(torch.tensor(ssims).mean(), ".5"))
print(" PSNR : {:>12.7f}".format(torch.tensor(psnrs).mean(), ".5"))
Expand All @@ -95,6 +96,7 @@ def evaluate(model_paths):
if __name__ == "__main__":
device = torch.device("cuda:0")
torch.cuda.set_device(device)
lpips_fn = lpips.LPIPS(net='vgg').to(device)

# Set up command line argument parser
parser = ArgumentParser(description="Training script parameters")
Expand Down