This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f6498c
commit ecb243f
Showing
3 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build: | ||
python_version: "3.7" | ||
gpu: false | ||
python_packages: | ||
- ISR==2.2.0 | ||
- h5py==2.10.0 --force-reinstall | ||
|
||
predict: "predict.py:ISRPredictor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import cog | ||
import numpy as np | ||
from ISR.models import RDN, RRDN | ||
from PIL import Image | ||
|
||
|
||
class ISRPredictor(cog.Predictor): | ||
def setup(self): | ||
"""Load the super-resolution ans noise canceling models""" | ||
self.model_gans = RRDN(weights="gans") | ||
self.model_noise_cancel = RDN(weights="noise-cancel") | ||
|
||
@cog.input("input", type=Path, help="Image path") | ||
@cog.input( | ||
"type", | ||
type=str, | ||
default="super-resolution", | ||
options=["super-resolution", "noise-cancel"], | ||
help="Precessing type: super-resolution or noise-cancel", | ||
) | ||
def predict(self, input, type): | ||
"""Apply super-resolution or noise-canceling to input image""" | ||
# compute super resolution | ||
img = Image.open(str(input)) | ||
lr_img = np.array(img) | ||
|
||
if type == "super-resolution": | ||
img = self.model_gans.predict(np.array(img)) | ||
elif type == "noise-cancel": | ||
img = self.model_noise_cancel.predict(np.array(img)) | ||
else: | ||
raise NotImplementedError("Invalid processing type selected") | ||
|
||
img = Image.fromarray(img) | ||
|
||
output_path = Path(tempfile.mkdtemp()) / "output.png" | ||
img.save(str(output_path), "PNG") | ||
|
||
return output_path |