Rainy commited on
Commit
fe5b88e
1 Parent(s): 7af7eb0

:tada: first commit

Browse files
README.md CHANGED
@@ -1,3 +1,34 @@
 
 
 
 
 
 
 
1
  ---
2
- license: openrail
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ---
2
+ language:
3
+ - ru
4
+ - en
5
+ tags:
6
+ - PyTorch
7
+ thumbnail: "https://github.com/sberbank-ai/Real-ESRGAN"
8
  ---
9
+ # Real-ESRGAN
10
+
11
+ PyTorch implementation of a Real-ESRGAN model trained on custom dataset. This model shows better results on faces compared to the original version. It is also easier to integrate this model into your projects.
12
+
13
+ Real-ESRGAN is an upgraded ESRGAN trained with pure synthetic data is capable of enhancing details while removing annoying artifacts for common real-world images.
14
+
15
+ - [Paper](https://arxiv.org/abs/2107.10833)
16
+ - [Original implementation](https://github.com/xinntao/Real-ESRGAN)
17
+ - [Our github](https://github.com/LikeRainDay/Real-ESRGAN)
18
+
19
+ ## Usage
20
+
21
+ Code for using model you can obtain in our [repo](https://github.com/LikeRainDay/Real-ESRGAN).
22
+ ```python
23
+ import torch
24
+ from PIL import Image
25
+ import numpy as np
26
+ from RealESRGAN import RealESRGAN
27
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
28
+ model = RealESRGAN(device, scale=4)
29
+ model.load_weights('weights/RealESRGAN_x4.pth', download=True)
30
+ path_to_image = 'inputs/lr_image.png'
31
+ image = Image.open(path_to_image).convert('RGB')
32
+ sr_image = model.predict(image)
33
+ sr_image.save('results/sr_image.png')
34
+ ```
RealESRGAN_x2plus.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49fafd45f8fd7aa8d31ab2a22d14d91b536c34494a5cfe31eb5d89c2fa266abb
3
+ size 67061725
RealESRGAN_x4plus.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fa0d38905f75ac06eb49a7951b426670021be3018265fd191d2125df9d682f1
3
+ size 67040989
RealESRGAN_x8.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b72fb469d12f05a4770813d2603eb1b550f40df6fb8b37d6c7bc2db3d2bff5e
3
+ size 67189359
handler.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from base64 import b64encode, b64decode
2
+ from io import BytesIO
3
+ from pathlib import Path
4
+
5
+ import numpy as np
6
+ from basicsr.archs.rrdbnet_arch import RRDBNet
7
+ from PIL import Image
8
+ from realesrgan import RealESRGANer
9
+
10
+
11
+ class EndpointHandler:
12
+ def __init__(self, path=""):
13
+ model = RRDBNet(num_in_ch=3, num_out_ch=3)
14
+ self.upsampler = RealESRGANer(
15
+ scale=4,
16
+ model_path=str(Path(path) / "RealESRGAN_x4plus.pth"),
17
+ model=model,
18
+ tile=0,
19
+ pre_pad=0,
20
+ half=True,
21
+ )
22
+
23
+ def __call__(self, data):
24
+ """
25
+ Args:
26
+ data (:obj:):
27
+ includes the input data and the parameters for the inference.
28
+ Return:
29
+ A :obj:`dict`:. base64 encoded image
30
+ """
31
+ image = data.pop("inputs", data)
32
+
33
+ # This lets us pass local images as well while developing
34
+ if isinstance(image, str):
35
+ image = Image.open(BytesIO(b64decode(image)))
36
+ elif isinstance(image, bytes):
37
+ image = Image.open(BytesIO(image))
38
+
39
+ image = np.array(image)
40
+ image = image[:, :, ::-1] # RGB -> BGR
41
+ image, _ = self.upsampler.enhance(image, outscale=4)
42
+ image = image[:, :, ::-1] # BGR -> RGB
43
+ image = Image.fromarray(image)
44
+
45
+ # Turn output image into bytestr
46
+ buffered = BytesIO()
47
+ image.save(buffered, format="PNG")
48
+ img_bytes = b64encode(buffered.getvalue())
49
+ img_str = img_bytes.decode()
50
+
51
+ return {"image": img_str}
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ realesrgan==0.3.0