Module Name | reasr |
---|---|
Category | Image editing |
Network | LP-KPN |
Dataset | RealSR dataset |
Fine-tuning supported or not | No |
Module Size | 64MB |
Latest update date | 2021-02-26 |
Data indicators | PSNR29.05 |
-
-
Realsr is a super resolution model for image and video based on "Toward Real-World Single Image Super-Resolution: A New Benchmark and A New Mode". This model provides super resolution result with scale factor x4.
-
For more information, please refer to: realsr
-
-
-
paddlepaddle >= 2.0.0
-
paddlehub >= 2.0.0
-
NOTE: This Module relies on ffmpeg, Please install ffmpeg before using this Module.
$ conda install x264=='1!152.20180717' ffmpeg=4.0.2 -c conda-forge
-
-
-
$ hub install realsr
-
In case of any problems during installation, please refer to:Windows_Quickstart | Linux_Quickstart | Mac_Quickstart
-
-
-
import paddlehub as hub model = hub.Module(name='realsr') model.predict('/PATH/TO/IMAGE') # model.predict('/PATH/TO/VIDEO')
-
-
-
def predict(self, input):
-
Prediction API.
-
Parameter
- input (str): image path.
-
Return
-
If input is image path, the output is:
- pred_img(np.ndarray): image data, ndarray.shape is in the format [H, W, C], BGR.
- out_path(str): save path of images.
-
If input is video path, the output is :
- frame_pattern_combined(str): save path of frames from output video.
- vid_out_path(str): save path of output video.
-
-
-
def run_image(self, img):
-
Prediction API for images.
-
Parameter
- img (str|np.ndarray): Image data, str or ndarray. ndarray.shape is in the format [H, W, C], BGR.
-
Return
- pred_img(np.ndarray): Prediction result, ndarray.shape is in the format [H, W, C], BGR.
-
-
def run_video(self, video):
-
Prediction API for video.
-
Parameter
- video(str): Video path.
-
Return
- frame_pattern_combined(str): Save path of frames from output video.
- vid_out_path(str): Save path of output video.
-
-
-
-
PaddleHub Serving can deploy an online service of image super resolution.
-
-
Run the startup command:
-
$ hub serving start -m realsr
-
-
The servitization API is now deployed and the default port number is 8866.
-
NOTE: If GPU is used for prediction, set CUDA_VISIBLE_DEVICES environment variable before the service, otherwise it need not be set.
-
-
-
With a configured server, use the following lines of code to send the prediction request and obtain the result
-
import requests import json import base64 import cv2 import numpy as np def cv2_to_base64(image): data = cv2.imencode('.jpg', image)[1] return base64.b64encode(data.tostring()).decode('utf8') def base64_to_cv2(b64str): data = base64.b64decode(b64str.encode('utf8')) data = np.fromstring(data, np.uint8) data = cv2.imdecode(data, cv2.IMREAD_COLOR) return data org_im = cv2.imread('/PATH/TO/IMAGE') data = {'images':cv2_to_base64(org_im)} headers = {"Content-type": "application/json"} url = "http://127.0.0.1:8866/predict/realsr" r = requests.post(url=url, headers=headers, data=json.dumps(data)) img = base64_to_cv2(r.json()["results"]) cv2.imwrite('/PATH/TO/SAVE/IMAGE', img)
-
-
-
1.0.0
First release
-
1.0.1
Support paddlehub2.0
-
1.1.0
Update code format
$ hub install realsr == 1.1.0