{"library":"lpips","title":"LPIPS (Learned Perceptual Image Patch Similarity)","description":"LPIPS is a Python library that implements the Learned Perceptual Image Patch Similarity metric. This metric is designed to measure the similarity between two images in a way that aligns more closely with human perception than traditional metrics like MSE or SSIM. It leverages deep features extracted from pre-trained convolutional neural networks (like AlexNet, VGG, or SqueezeNet). The library is currently at version 0.1.4 and is primarily maintained through its GitHub repository, with releases tied to significant updates. It's often used in image generation and restoration tasks to evaluate perceptual quality or as a perceptual loss function.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install lpips"],"cli":null},"imports":["import lpips\nloss_fn = lpips.LPIPS()"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import torch\nimport lpips\n\n# Ensure PyTorch is set up (e.g., for GPU if available)\n# LPIPS does not typically require API keys for model loading\n\n# Initialize the LPIPS model, using AlexNet as the default backbone\n# 'alex' is recommended for best forward scores, 'vgg' for perceptual loss in optimization\nloss_fn_alex = lpips.LPIPS(net='alex')\n\n# Create two dummy images (batch_size, channels, height, width)\n# IMPORTANT: Images should be RGB (3 channels) and normalized to [-1, 1]\nimg0 = torch.rand(1, 3, 64, 64) * 2 - 1  # Random image 1, normalized to [-1, 1]\nimg1 = torch.rand(1, 3, 64, 64) * 2 - 1  # Random image 2, normalized to [-1, 1]\n\n# Compute the LPIPS distance\nd = loss_fn_alex(img0, img1)\n\nprint(f\"LPIPS distance: {d.item():.4f}\")\n\n# Example with VGG network, often preferred for 'perceptual loss' in training\nloss_fn_vgg = lpips.LPIPS(net='vgg')\nd_vgg = loss_fn_vgg(img0, img1)\nprint(f\"LPIPS distance (VGG): {d_vgg.item():.4f}\")","lang":"python","description":"This quickstart demonstrates how to import the LPIPS library, initialize the `LPIPS` model with different backbone networks ('alex' or 'vgg'), and compute the perceptual distance between two randomly generated PyTorch tensors. It highlights the crucial requirement for input images to be 3-channel RGB and normalized to the range `[-1, 1]`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"0.1.4","pypi_latest":"0.1.4","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":90,"avg_install_s":69.2,"avg_import_s":13.2,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":79.3,"import_time_s":10.23,"mem_mb":134.7,"disk_size":"4.9G"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"19.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":73.5,"import_time_s":15.3,"mem_mb":148.9,"disk_size":"4.9G"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"11.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":64.2,"import_time_s":15.01,"mem_mb":144.6,"disk_size":"4.9G"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"11.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":59.9,"import_time_s":12.27,"mem_mb":145.1,"disk_size":"4.9G"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"lpips","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"lpips","exit_code":1,"wheel_type":null,"failure_reason":"timeout","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}