In this guide, we will go through the process of setting up the Real-ESRGAN package for image super-resolution. Real-ESRGAN allows you to enhance the quality of images using deep learning techniques. Follow these steps to clone the repository, install the necessary dependencies, and perform inference on your images.
Prerequisites
- Ensure you have Python 3.10 installed on your system.
- Make sure you have Git installed to clone the repository.
Step 1: Clone the Repository
Open your terminal or command prompt and run the following commands to clone the Real-ESRGAN repository:
git clone https://github.com/xinntao/Real-ESRGAN.git
cd Real-ESRGAN
Step 2: Install Dependent Packages
Real-ESRGAN relies on several packages for training and inference. Install the required dependencies by running:
# Install specific versions of NumPy
pip install numpy<2
# Install PyTorch and torchvision for CUDA 11.6
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 -f https://download.pytorch.org/whl/torch_stable.html
# Install BasicSR
pip install basicsr
# Install facexlib and gfpgan for face enhancement
pip install facexlib
pip install gfpgan
# Install other requirements
pip install -r requirements.txt
# Set up the package
python setup.py develop
Step 3: Check CUDA Version (Optional)
You can check your NVIDIA GPU status and installed CUDA version using the following command:
nvidia-smi
Note: Checking the CUDA version is optional. You only need to do this if you encounter any errors while running the following command to install PyTorch:
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 -f https://download.pytorch.org/whl/torch_stable.html
If you face issues during installation, verifying your CUDA version can help troubleshoot the problem.
Step 4: Download Pre-trained Models
Download the pre-trained model for Real-ESRGAN using the following command or by visiting the Real-ESRGAN releases page:
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth
Ensure that the downloaded model file is placed in the appropriate directory as specified in the inference script.
Step 5: Running Inference
You can use the inference_realesrgan.py
script to enhance images. The usage format for the script is as follows:
python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...
Common Command Example
To perform image enhancement using the X4 model with face enhancement, use the following command:
python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --outscale 3.5 --face_enhance
Command Options
-h
: Show help information.-i --input
: Specify the input image or folder. Default isinputs
.-o --output
: Specify the output folder. Default isresults
.-n --model_name
: Choose the model name. Default isRealESRGAN_x4plus
.-s, --outscale
: Set the final upsampling scale of the image. Default is4
.--suffix
: Define the suffix for the restored image. Default isout
.-t, --tile
: Set tile size for testing. Use0
for no tiling. Default is0
.--face_enhance
: Use GFPGAN to enhance faces. Default isFalse
.--fp32
: Use full precision during inference. Default isfp16
.--ext
: Specify the image extension. Options areauto
,jpg
, orpng
. Default isauto
.
Example Command to Enhance Faces
To enhance faces in images located in the inputs
folder, run:
python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
Check Your Processed Images After executing the inference command, navigate to the results folder. Here, you will find the final output images enhanced by Real-ESRGAN. This folder will contain the processed images, allowing you to compare them with the original inputs.
Conclusion
You have successfully set up Real-ESRGAN and performed image super-resolution. By following these steps, you can enhance the quality of your images, bringing out fine details and textures. This process can be especially useful in various fields such as photography, digital art, and more.
Additional Resources
With Real-ESRGAN, you can transform low-resolution images into stunning high-resolution masterpieces! Enjoy enhancing your images!