Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit ecb243f

Browse files
committed
cog-ified
1 parent 3f6498c commit ecb243f

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![Build Status](https://travis-ci.org/idealo/image-super-resolution.svg?branch=master)](https://travis-ci.org/idealo/image-super-resolution)
66
[![Docs](https://img.shields.io/badge/docs-online-brightgreen)](https://idealo.github.io/image-super-resolution/)
77
[![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg)](https://github.com/idealo/image-super-resolution/blob/master/LICENSE)
8+
<a href="https://replicate.ai/idealo/image-super-resolution"><img src="https://img.shields.io/static/v1?label=Replicate&message=Demo and Docker Image&color=darkgreen" height=20></a>
89

910
The goal of this project is to upscale and improve the quality of low resolution images.
1011

@@ -65,18 +66,18 @@ pip install 'h5py==2.10.0' --force-reinstall
6566

6667
## Pre-trained networks
6768

68-
The weights used to produced these images are available directly when creating the model object.
69+
The weights used to produced these images are available directly when creating the model object.
6970

7071
Currently 4 models are available:
7172
- RDN: psnr-large, psnr-small, noise-cancel
7273
- RRDN: gans
73-
74+
7475
Example usage:
7576

7677
```
7778
model = RRDN(weights='gans')
7879
```
79-
80+
8081
The network parameters will be automatically chosen.
8182
(see [Additional Information](#additional-information)).
8283

cog.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build:
2+
python_version: "3.7"
3+
gpu: false
4+
python_packages:
5+
- ISR==2.2.0
6+
- h5py==2.10.0 --force-reinstall
7+
8+
predict: "predict.py:ISRPredictor"

predict.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import tempfile
3+
from pathlib import Path
4+
5+
import cog
6+
import numpy as np
7+
from ISR.models import RDN, RRDN
8+
from PIL import Image
9+
10+
11+
class ISRPredictor(cog.Predictor):
12+
def setup(self):
13+
"""Load the super-resolution ans noise canceling models"""
14+
self.model_gans = RRDN(weights="gans")
15+
self.model_noise_cancel = RDN(weights="noise-cancel")
16+
17+
@cog.input("input", type=Path, help="Image path")
18+
@cog.input(
19+
"type",
20+
type=str,
21+
default="super-resolution",
22+
options=["super-resolution", "noise-cancel"],
23+
help="Precessing type: super-resolution or noise-cancel",
24+
)
25+
def predict(self, input, type):
26+
"""Apply super-resolution or noise-canceling to input image"""
27+
# compute super resolution
28+
img = Image.open(str(input))
29+
lr_img = np.array(img)
30+
31+
if type == "super-resolution":
32+
img = self.model_gans.predict(np.array(img))
33+
elif type == "noise-cancel":
34+
img = self.model_noise_cancel.predict(np.array(img))
35+
else:
36+
raise NotImplementedError("Invalid processing type selected")
37+
38+
img = Image.fromarray(img)
39+
40+
output_path = Path(tempfile.mkdtemp()) / "output.png"
41+
img.save(str(output_path), "PNG")
42+
43+
return output_path

0 commit comments

Comments
 (0)