LPIPS metric wrapper.
| 63 | |
| 64 | |
| 65 | class LPIPS: |
| 66 | """LPIPS metric wrapper.""" |
| 67 | |
| 68 | def __init__(self, device='cuda'): |
| 69 | self.device = device |
| 70 | self.model = LPIPS_VTP().to(device).eval() |
| 71 | |
| 72 | def __call__(self, img1: torch.Tensor, img2: torch.Tensor) -> torch.Tensor: |
| 73 | """Calculate LPIPS between two images. |
| 74 | |
| 75 | Args: |
| 76 | img1, img2: Images in range [-1, 1] with shape (B, C, H, W) |
| 77 | """ |
| 78 | with torch.no_grad(): |
| 79 | return self.model(img1, img2) |
| 80 | |
| 81 | |
| 82 | def get_ssim_metric(device): |
no outgoing calls