Skip to content

Commit

Permalink
update photo_restoration (#1998)
Browse files Browse the repository at this point in the history
* update photo_restoration

* add clean func
  • Loading branch information
jm12138 authored Dec 29, 2022
1 parent 524a751 commit 1af344a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@

初始发布

* 1.0.1
* 1.1.0

适配paddlehub2.0版本

* ```shell
$ hub install photo_restoration==1.1.0
```
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@

First release

- 1.0.1
- 1.1.0

Adapt to paddlehub2.0

* ```shell
$ hub install photo_restoration==1.1.0
```

Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@
import cv2
import paddle.nn as nn
import paddlehub as hub
from paddlehub.module.module import moduleinfo, serving, Module
from paddlehub.module.module import moduleinfo, serving

import photo_restoration.utils as U
from . import utils as U


@moduleinfo(
name="photo_restoration",
type="CV/image_editing",
author="paddlepaddle",
author_email="",
summary="photo_restoration is a photo restoration model based on deoldify and realsr.",
version="1.0.0")
class PhotoRestoreModel(Module):
@moduleinfo(name="photo_restoration",
type="CV/image_editing",
author="paddlepaddle",
author_email="",
summary="photo_restoration is a photo restoration model based on deoldify and realsr.",
version="1.1.0")
class PhotoRestoreModel(nn.Layer):
"""
PhotoRestoreModel
Expand All @@ -39,8 +38,8 @@ class PhotoRestoreModel(Module):
visualization (bool): Whether to save the estimation result. Default is True.
"""

def _initialize(self, visualization: bool = False):
#super(PhotoRestoreModel, self).__init__()
def __init__(self, visualization: bool = False):
super(PhotoRestoreModel, self).__init__()
self.deoldify = hub.Module(name='deoldify')
self.realsr = hub.Module(name='realsr')
self.visualization = visualization
Expand Down
52 changes: 52 additions & 0 deletions modules/image/Image_editing/colorization/photo_restoration/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import shutil
import unittest

import cv2
import requests
import numpy as np
import paddlehub as hub


os.environ['CUDA_VISIBLE_DEVICES'] = '0'


class TestHubModule(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
img_url = 'https://unsplash.com/photos/1sLIu1XKQrY/download?ixid=MnwxMjA3fDB8MXxhbGx8MTJ8fHx8fHwyfHwxNjYyMzQxNDUx&force=true&w=640'
if not os.path.exists('tests'):
os.makedirs('tests')
response = requests.get(img_url)
assert response.status_code == 200, 'Network Error.'
with open('tests/test.jpg', 'wb') as f:
f.write(response.content)
cls.module = hub.Module(name="photo_restoration")

@classmethod
def tearDownClass(cls) -> None:
shutil.rmtree('tests')
shutil.rmtree('photo_restoration')

def test_run_image1(self):
results = self.module.run_image(
input='tests/test.jpg'
)
self.assertIsInstance(results, np.ndarray)

def test_run_image2(self):
results = self.module.run_image(
input=cv2.imread('tests/test.jpg')
)
self.assertIsInstance(results, np.ndarray)

def test_run_image3(self):
self.assertRaises(
FileNotFoundError,
self.module.run_image,
input='no.jpg'
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 1af344a

Please sign in to comment.