Registry / ai-ml / gfpgan

gfpgan

JSON →
library1.3.8pypypiunverified

GFPGAN (Generative Facial Prior-guided Face Restoration) is a Python library that provides practical algorithms for high-quality face restoration, especially for degraded real-world images. It leverages a pre-trained GAN (Generative Adversarial Network) as a facial prior for robust restoration. The current version is 1.3.8, with a history of frequent minor updates addressing bugs, adding features, and refining model architectures.

pip install gfpgan
INSTALL
IMPORT
SIG · GFPGAN
G
gfpgan
ai-mlpythonv1.3.8
Install
—
Import
—
Disk
—
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
build_error
glibc
py 3.10–3.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GFPGANer
✓ from gfpgan import GFPGANer
✗ from gfpgan import GFPGANer

This quickstart demonstrates how to initialize the GFPGANer and enhance an image. Before running, you *must* manually download a pre-trained model checkpoint (e.g., `GFPGANv1.3.pth`) from the official GitHub releases and place it in the same directory as your script. The example code includes a dummy image for testing, but for real use, replace `input_img` with your actual image loaded via `cv2.imread`.

import cv2 import numpy as np import os from gfpgan import GFPGANer # 1. Prepare a dummy input image # In a real scenario, you would load your image: img = cv2.imread('path/to/your/image.jpg', cv2.IMREAD_COLOR) # For a runnable example, create a 256x256 black image with some noise. input_img = np.zeros((256, 256, 3), dtype=np.uint8) noise = np.random.randint(-50, 50, (256, 256, 3), dtype=np.int16) input_img = np.clip(input_img + noise, 0, 255).astype(np.uint8) # 2. Download the pre-trained GFPGAN model # GFPGAN models are NOT bundled with the pip package and must be downloaded manually. # Download GFPGANv1.3.pth from: https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth model_path = 'GFPGANv1.3.pth' # Place the downloaded model in the same directory as your script if not os.path.exists(model_path): print(f"Warning: Model file '{model_path}' not found. Please download it from:") print(" https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth") print(" Proceeding with a placeholder; actual enhancement will not occur without the model.") enhanced_img = input_img.copy() # Fallback for quickstart if model not present else: # 3. Initialize GFPGANer # Use 'cpu' for broad compatibility. Change to 'cuda' if a GPU is available. restorer = GFPGANer( model_path=model_path, upscale=2, # Upscale factor: 1, 2, or 4 arch='clean', # Model architecture: 'original' or 'clean' channel_multiplier=2, bg_upsampler=None, # Set to 'realesrgan' if you want background upsampling device='cpu' # 'cuda' for GPU, 'cpu' for CPU ) # 4. Enhance the image # The enhance method returns cropped_faces, restored_faces, and the final enhanced_img. cropped_faces, restored_faces, enhanced_img = restorer.enhance( input_img, # Input image (BGR format) has_aligned=False, # Set to True if input faces are already aligned only_center_face=False, # Set to True to only enhance the most prominent face paste_back=True # Set to True to paste restored faces back into the original image ) # 5. Save the output image output_path = 'gfpgan_enhanced_output.jpg' cv2.imwrite(output_path, enhanced_img) print(f"Enhanced image (or original if model was missing) saved to {output_path}")
gfpgan --version
Debug
Known issues
breakingThe `codeformer` integration was removed in GFPGAN v1.3.8. If your code relied on this component, it will break or require modification.
fix
Downgrade to GFPGAN v1.3.7 or earlier if `codeformer` functionality is essential. Alternatively, adapt your workflow to use other available components or remove `codeformer`-specific calls.
affects: >=1.3.8
gotchaGFPGAN models (e.g., `GFPGANv1.3.pth`) are not bundled with the pip package and must be manually downloaded from the official GitHub releases page. The library will not function without a valid model path.
fix
Always download the required `.pth` model file (e.g., GFPGANv1.3.pth) from the official GitHub releases and provide its path to the `GFPGANer` constructor.
affects: All versions
gotchaGFPGAN relies on PyTorch and potentially CUDA for optimal performance. Incorrect PyTorch/CUDA installation or version mismatches can lead to runtime errors or force CPU-only processing.
fix
Ensure PyTorch is installed correctly for your specific hardware (CPU or GPU) and CUDA version. Refer to the official PyTorch installation instructions for your system. Specify `device='cuda'` in `GFPGANer` if you have a compatible GPU.
affects: All versions
breakingAn `ImportError` was present in v1.3.0 due to a missing file. While fixed in v1.3.1, this highlights potential instability in specific minor point releases.
fix
Avoid using GFPGAN v1.3.0. Upgrade to v1.3.1 or a later version to resolve import issues.
affects: 1.3.0
Upgrade
Version history
1.3.8latest on PyPI · released Sep 16, 2022
Audit
Dependencies
basicsrrequiredCore dependency for image restoration functionalities and base utilities.
facexlibrequiredUsed for face detection and parsing during the restoration process.
opencv-pythonrequiredRequired for image loading, processing, and saving (e.g., cv2.imread, cv2.imwrite).
numpyrequiredFundamental package for numerical operations, especially array handling for images.
PillowrequiredImage processing library, often used by other dependencies like torchvision.
torchrequiredThe underlying deep learning framework (PyTorch) is essential for model inference.
torchvisionrequiredPyTorch's vision library, providing dataset, models, and transformations for computer vision.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
gfpgan — pip install gfpgan · libregistry