
Real-Enhanced Super-Resolution Generative Adversarial Networks (Real-ESRGAN) is an open-source algorithm for image and video restoration. You can use Real-ESRGAN to restore or enhance low-resolution images by reducing the noise and upscaling them. This guide explains how to build a Super Resolution Image Web Application on a Vultr Cloud GPU using Streamlit and Real-ESRGAN.
Clone the Real-Enhanced Super-Resolution Generative Adversarial Networks (Real-ESRGAN) Repository. It contains the Machine Learning models to be used for the web application.
Change the directory to the cloned repository Real-ESRGAN.
Install Python3 Virtual Environment.
Create a Virtual Environment for Real-ESRGAN.
Activate the Virtual Environment.
Install BasicSR using pip. BasicSR is used for both training and inference.
Install FaceXLib and GFPGAN. FaceXLib and GFPGAN are both used for the face enhancement feature.
Install the required dependencies for Real-ESRGAN.
Set up Real-ESRGAN by running the setup.py file.
Install Streamlit. You will use the framework Streamlit for the Web Application's User Interface.
Create a new folder named uploads. This folder is where the uploaded images will be saved.
Create a new folder named outputs. This folder is where the enhanced images will be saved.
Create a web-ui.py file.
Populate the web-ui.py file with the codes below:
Import the required modules:
Define the load_image() function. This function will open and identify the uploaded image file using Pillow, a fork of Python Imaging Library (PIL).
Define the main() function.
Set the Web Application's title and sub-header.
Create a File Uploader widget (dropbox) that accepts image files with png, jpeg, and jpg extensions.
Check if the dropbox widget already contains a file, and then display the image's filename, MIME type, and the image itself with a 500px width.
Save the uploaded image file to the uploads folder you created in step 11.
Real-ESRGAN has five image enhancement and restoration models: RealESRGAN_x4plus, RealESRNet_x4plus, RealESRGAN_x4plus_anime_6B, RealESRGAN_x2plus, and realesr-general-x4v3. Please see the Model Zoo Documentation for more information.
Create a drop-down menu to select what model to use.
Create a checkbox that will either enable or disable the face enhancement feature.
Create a button that will run the inference_realesrgan.py with the appropriate arguments when clicked. The arguments will be based on the chosen model and if the face enhancement feature is enabled or disabled. The enhanced image output will be placed in the outputs folder you created in step 12.
Get the image's filename without the file extension.
Get the image's file extension.
Open and identify the enhanced image file using Pillow.
Display the enhanced image.
Create a Download button that will download the enhanced image when clicked.
Run the main() function when executed.
Save and exit the web-ui.py file by pressing Ctrl + X then Y then Enter.
Your web-ui.py file should look like this:
When you run your Streamlit-based web application on a normal SSH session, the Streamlit process closes when you exit the SSH session. To continuously run your web application even when you leave the SSH session, use tmux, a terminal multiplexer.
To create a Tmux process, run:
You may change esrgan-webapp with any session name you prefer. Please see How to Install and Use Tmux for more information about Tmux.
Streamlit runs on port 8501 by default, so you need to allow port 8501 on the firewall.
Launch the Super Resolution Image Web Application.
When you run Streamlit for the first time, you will be prompted to enter your email address. If you want to receive Streamlit updates, kindly enter your email address, or you can press Enter to skip it.
To detach from the Streamlit session, press Ctrl + B then D.
To view your Super Resolution Image Web Application, navigate port 8501 in your browser at your server's IP address. For example, http://192.0.1.2:8501.
8501 at your server's IP address. For example, http://192.0.1.2:8501.Sample Execution:
Model: RealESRGAN_x4plus Face Enhancement: Disabled
Low-Resolution Image Input:
Enhanced Image:
You have successfully created a Super Resolution Image Server on a Vultr Cloud GPU using Streamlit and Real-ESRGAN.
To learn more about Streamlit and Real-ESRGAN, please see these resources:
0 Comments
Be the first to comment and share your perspective with the community.