Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
1c423b6b
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 2 年 前同步成功
通知
285
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1c423b6b
编写于
12月 29, 2022
作者:
jm_12138
提交者:
GitHub
12月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update falsr_c (#2186)
上级
d0355914
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
100 addition
and
99 deletion
+100
-99
modules/image/Image_editing/super_resolution/falsr_c/README.md
...es/image/Image_editing/super_resolution/falsr_c/README.md
+9
-5
modules/image/Image_editing/super_resolution/falsr_c/README_en.md
...image/Image_editing/super_resolution/falsr_c/README_en.md
+12
-8
modules/image/Image_editing/super_resolution/falsr_c/data_feed.py
...image/Image_editing/super_resolution/falsr_c/data_feed.py
+0
-2
modules/image/Image_editing/super_resolution/falsr_c/module.py
...es/image/Image_editing/super_resolution/falsr_c/module.py
+68
-49
modules/image/Image_editing/super_resolution/falsr_c/processor.py
...image/Image_editing/super_resolution/falsr_c/processor.py
+1
-2
modules/image/Image_editing/super_resolution/falsr_c/test.py
modules/image/Image_editing/super_resolution/falsr_c/test.py
+10
-33
未找到文件。
modules/image/Image_editing/super_resolution/falsr_c/README.md
浏览文件 @
1c423b6b
...
@@ -149,19 +149,23 @@
...
@@ -149,19 +149,23 @@
print("save image as falsr_c_X2.png")
print("save image as falsr_c_X2.png")
```
```
-
### Gradio APP 支持
从 PaddleHub 2.3.1 开始支持使用链接 http://127.0.0.1:8866/gradio/falsr_c 在浏览器中访问 falsr_c 的 Gradio APP。
## 五、更新历史
## 五、更新历史
*
1.0.0
*
1.0.0
初始发布
初始发布
*
1.1.0
*
1.1.0
移除 fluid API
移除 fluid API
*
1.2.0
添加 Gradio APP 支持
```
shell
```
shell
$
hub
install
falsr_c
==
1.
1
.0
$
hub
install
falsr_c
==
1.
2
.0
```
```
modules/image/Image_editing/super_resolution/falsr_c/README_en.md
浏览文件 @
1c423b6b
...
@@ -153,19 +153,23 @@
...
@@ -153,19 +153,23 @@
print("save image as falsr_c_X2.png")
print("save image as falsr_c_X2.png")
```
```
-
### Gradio APP support
Starting with PaddleHub 2.3.1, the Gradio APP for falsr_c is supported to be accessed in the browser using the link http://127.0.0.1:8866/gradio/falsr_c.
## V. Release Note
## V. Release Note
-
1.0.0
*
1.0.0
First release
First release
*
1.1.0
-
1.1.0
Remove Fluid API
Remove Fluid API
*
1.2.0
Add Gradio APP support.
```
shell
```
shell
$
hub
install
falsr_c
==
1.
1
.0
$
hub
install
falsr_c
==
1.
2
.0
```
```
modules/image/Image_editing/super_resolution/falsr_c/data_feed.py
浏览文件 @
1c423b6b
# -*- coding:utf-8 -*-
import
os
import
os
import
time
import
time
from
collections
import
OrderedDict
from
collections
import
OrderedDict
...
@@ -6,7 +5,6 @@ from collections import OrderedDict
...
@@ -6,7 +5,6 @@ from collections import OrderedDict
import
cv2
import
cv2
import
numpy
as
np
import
numpy
as
np
__all__
=
[
'reader'
]
__all__
=
[
'reader'
]
...
...
modules/image/Image_editing/super_resolution/falsr_c/module.py
浏览文件 @
1c423b6b
...
@@ -12,30 +12,32 @@
...
@@ -12,30 +12,32 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
argparse
import
ast
import
ast
import
os
import
os
import
argparse
import
numpy
as
np
import
numpy
as
np
import
paddle
from
paddle.inference
import
Config
import
paddle.jit
from
paddle.inference
import
create_predictor
import
paddle.static
from
paddle.inference
import
Config
,
create_predictor
from
paddlehub.module.module
import
moduleinfo
,
runnable
,
serving
from
.data_feed
import
reader
from
.data_feed
import
reader
from
.processor
import
postprocess
,
base64_to_cv2
,
cv2_to_base64
,
check_dir
from
.processor
import
base64_to_cv2
from
.processor
import
check_dir
from
.processor
import
cv2_to_base64
from
.processor
import
postprocess
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
runnable
from
paddlehub.module.module
import
serving
@
moduleinfo
(
@
moduleinfo
(
name
=
"falsr_c"
,
name
=
"falsr_c"
,
type
=
"CV/image_editing"
,
type
=
"CV/image_editing"
,
author
=
"paddlepaddle"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
author_email
=
""
,
summary
=
"falsr_c is a super resolution model."
,
summary
=
"falsr_c is a super resolution model."
,
version
=
"1.1
.0"
)
version
=
"1.2
.0"
)
class
Falsr_C
:
class
Falsr_C
:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
default_pretrained_model_path
=
os
.
path
.
join
(
self
.
directory
,
"falsr_c_model"
,
"model"
)
self
.
default_pretrained_model_path
=
os
.
path
.
join
(
self
.
directory
,
"falsr_c_model"
,
"model"
)
self
.
_set_config
()
self
.
_set_config
()
...
@@ -44,8 +46,8 @@ class Falsr_C:
...
@@ -44,8 +46,8 @@ class Falsr_C:
"""
"""
predictor config setting
predictor config setting
"""
"""
model
=
self
.
default_pretrained_model_path
+
'.pdmodel'
model
=
self
.
default_pretrained_model_path
+
'.pdmodel'
params
=
self
.
default_pretrained_model_path
+
'.pdiparams'
params
=
self
.
default_pretrained_model_path
+
'.pdiparams'
cpu_config
=
Config
(
model
,
params
)
cpu_config
=
Config
(
model
,
params
)
cpu_config
.
disable_glog_info
()
cpu_config
.
disable_glog_info
()
cpu_config
.
disable_gpu
()
cpu_config
.
disable_gpu
()
...
@@ -110,8 +112,7 @@ class Falsr_C:
...
@@ -110,8 +112,7 @@ class Falsr_C:
output_names
=
predictor
.
get_output_names
()
output_names
=
predictor
.
get_output_names
()
output_handle
=
predictor
.
get_output_handle
(
output_names
[
0
])
output_handle
=
predictor
.
get_output_handle
(
output_names
[
0
])
output
=
np
.
expand_dims
(
output_handle
.
copy_to_cpu
(),
axis
=
1
)
output
=
np
.
expand_dims
(
output_handle
.
copy_to_cpu
(),
axis
=
1
)
out
=
postprocess
(
out
=
postprocess
(
data_out
=
output
,
data_out
=
output
,
org_im
=
all_data
[
i
][
'org_im'
],
org_im
=
all_data
[
i
][
'org_im'
],
org_im_shape
=
all_data
[
i
][
'org_im_shape'
],
org_im_shape
=
all_data
[
i
][
'org_im_shape'
],
org_im_path
=
all_data
[
i
][
'org_im_path'
],
org_im_path
=
all_data
[
i
][
'org_im_path'
],
...
@@ -135,8 +136,7 @@ class Falsr_C:
...
@@ -135,8 +136,7 @@ class Falsr_C:
"""
"""
Run as a command.
Run as a command.
"""
"""
self
.
parser
=
argparse
.
ArgumentParser
(
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
"Run the {} module."
.
format
(
self
.
name
),
description
=
"Run the {} module."
.
format
(
self
.
name
),
prog
=
'hub run {}'
.
format
(
self
.
name
),
prog
=
'hub run {}'
.
format
(
self
.
name
),
usage
=
'%(prog)s'
,
usage
=
'%(prog)s'
,
add_help
=
True
)
add_help
=
True
)
...
@@ -147,8 +147,10 @@ class Falsr_C:
...
@@ -147,8 +147,10 @@ class Falsr_C:
self
.
add_module_config_arg
()
self
.
add_module_config_arg
()
self
.
add_module_input_arg
()
self
.
add_module_input_arg
()
args
=
self
.
parser
.
parse_args
(
argvs
)
args
=
self
.
parser
.
parse_args
(
argvs
)
results
=
self
.
reconstruct
(
results
=
self
.
reconstruct
(
paths
=
[
args
.
input_path
],
paths
=
[
args
.
input_path
],
use_gpu
=
args
.
use_gpu
,
output_dir
=
args
.
output_dir
,
visualization
=
args
.
visualization
)
use_gpu
=
args
.
use_gpu
,
output_dir
=
args
.
output_dir
,
visualization
=
args
.
visualization
)
if
args
.
save_dir
is
not
None
:
if
args
.
save_dir
is
not
None
:
check_dir
(
args
.
save_dir
)
check_dir
(
args
.
save_dir
)
self
.
save_inference_model
(
args
.
save_dir
)
self
.
save_inference_model
(
args
.
save_dir
)
...
@@ -159,14 +161,22 @@ class Falsr_C:
...
@@ -159,14 +161,22 @@ class Falsr_C:
"""
"""
Add the command config options.
Add the command config options.
"""
"""
self
.
arg_config_group
.
add_argument
(
self
.
arg_config_group
.
add_argument
(
'--use_gpu'
,
'--use_gpu'
,
type
=
ast
.
literal_eval
,
default
=
False
,
help
=
"whether use GPU or not"
)
type
=
ast
.
literal_eval
,
self
.
arg_config_group
.
add_argument
(
default
=
False
,
'--output_dir'
,
type
=
str
,
default
=
'falsr_c_output'
,
help
=
"The directory to save output images."
)
help
=
"whether use GPU or not"
)
self
.
arg_config_group
.
add_argument
(
self
.
arg_config_group
.
add_argument
(
'--output_dir'
,
'--save_dir'
,
type
=
str
,
default
=
'falsr_c_save_model'
,
help
=
"The directory to save model."
)
type
=
str
,
self
.
arg_config_group
.
add_argument
(
default
=
'falsr_c_output'
,
'--visualization'
,
type
=
ast
.
literal_eval
,
default
=
True
,
help
=
"whether to save output as images."
)
help
=
"The directory to save output images."
)
self
.
arg_config_group
.
add_argument
(
'--save_dir'
,
type
=
str
,
default
=
'falsr_c_save_model'
,
help
=
"The directory to save model."
)
self
.
arg_config_group
.
add_argument
(
'--visualization'
,
type
=
ast
.
literal_eval
,
default
=
True
,
help
=
"whether to save output as images."
)
def
add_module_input_arg
(
self
):
def
add_module_input_arg
(
self
):
"""
"""
...
@@ -174,11 +184,20 @@ class Falsr_C:
...
@@ -174,11 +184,20 @@ class Falsr_C:
"""
"""
self
.
arg_input_group
.
add_argument
(
'--input_path'
,
type
=
str
,
help
=
"path to image."
)
self
.
arg_input_group
.
add_argument
(
'--input_path'
,
type
=
str
,
help
=
"path to image."
)
def
create_gradio_app
(
self
):
if
__name__
==
"__main__"
:
import
gradio
as
gr
module
=
Falsr_C
()
import
tempfile
#module.reconstruct(paths=["BSD100_001.png","BSD100_002.png", "Set5_003.png"])
import
os
import
cv2
from
PIL
import
Image
img
=
cv2
.
imread
(
"BSD100_001.png"
).
astype
(
'float32'
)
res
=
module
.
reconstruct
(
images
=
[
img
])
def
inference
(
image
,
use_gpu
=
False
):
module
.
save_inference_model
()
with
tempfile
.
TemporaryDirectory
()
as
temp_dir
:
self
.
reconstruct
(
paths
=
[
image
],
use_gpu
=
use_gpu
,
visualization
=
True
,
output_dir
=
temp_dir
)
return
Image
.
open
(
os
.
path
.
join
(
temp_dir
,
os
.
listdir
(
temp_dir
)[
0
]))
interface
=
gr
.
Interface
(
inference
,
[
gr
.
inputs
.
Image
(
type
=
"filepath"
),
gr
.
Checkbox
(
label
=
'use_gpu'
)],
gr
.
outputs
.
Image
(
type
=
"ndarray"
),
title
=
'falsr_c'
)
return
interface
modules/image/Image_editing/super_resolution/falsr_c/processor.py
浏览文件 @
1c423b6b
# -*- coding:utf-8 -*-
import
base64
import
os
import
os
import
time
import
time
import
base64
import
cv2
import
cv2
import
numpy
as
np
import
numpy
as
np
...
...
modules/image/Image_editing/super_resolution/falsr_c/test.py
浏览文件 @
1c423b6b
...
@@ -3,18 +3,19 @@ import shutil
...
@@ -3,18 +3,19 @@ import shutil
import
unittest
import
unittest
import
cv2
import
cv2
import
requests
import
numpy
as
np
import
numpy
as
np
import
paddlehub
as
hub
import
requests
import
paddlehub
as
hub
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'0'
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'0'
class
TestHubModule
(
unittest
.
TestCase
):
class
TestHubModule
(
unittest
.
TestCase
):
@
classmethod
@
classmethod
def
setUpClass
(
cls
)
->
None
:
def
setUpClass
(
cls
)
->
None
:
img_url
=
'https://unsplash.com/photos/1sLIu1XKQrY/download?ixid=MnwxMjA3fDB8MXxhbGx8MTJ8fHx8fHwyfHwxNjYyMzQxNDUx&force=true&w=
64
0'
img_url
=
'https://unsplash.com/photos/1sLIu1XKQrY/download?ixid=MnwxMjA3fDB8MXxhbGx8MTJ8fHx8fHwyfHwxNjYyMzQxNDUx&force=true&w=
12
0'
if
not
os
.
path
.
exists
(
'tests'
):
if
not
os
.
path
.
exists
(
'tests'
):
os
.
makedirs
(
'tests'
)
os
.
makedirs
(
'tests'
)
response
=
requests
.
get
(
img_url
)
response
=
requests
.
get
(
img_url
)
...
@@ -30,50 +31,26 @@ class TestHubModule(unittest.TestCase):
...
@@ -30,50 +31,26 @@ class TestHubModule(unittest.TestCase):
shutil
.
rmtree
(
'falsr_c_output'
)
shutil
.
rmtree
(
'falsr_c_output'
)
def
test_reconstruct1
(
self
):
def
test_reconstruct1
(
self
):
results
=
self
.
module
.
reconstruct
(
results
=
self
.
module
.
reconstruct
(
paths
=
[
'tests/test.jpg'
],
use_gpu
=
False
,
visualization
=
False
)
paths
=
[
'tests/test.jpg'
],
use_gpu
=
False
,
visualization
=
False
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
def
test_reconstruct2
(
self
):
def
test_reconstruct2
(
self
):
results
=
self
.
module
.
reconstruct
(
results
=
self
.
module
.
reconstruct
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
False
)
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
False
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
def
test_reconstruct3
(
self
):
def
test_reconstruct3
(
self
):
results
=
self
.
module
.
reconstruct
(
results
=
self
.
module
.
reconstruct
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
True
)
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
True
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
def
test_reconstruct4
(
self
):
def
test_reconstruct4
(
self
):
results
=
self
.
module
.
reconstruct
(
results
=
self
.
module
.
reconstruct
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
True
,
visualization
=
False
)
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
True
,
visualization
=
False
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
def
test_reconstruct5
(
self
):
def
test_reconstruct5
(
self
):
self
.
assertRaises
(
self
.
assertRaises
(
AssertionError
,
self
.
module
.
reconstruct
,
paths
=
[
'no.jpg'
])
AssertionError
,
self
.
module
.
reconstruct
,
paths
=
[
'no.jpg'
]
)
def
test_reconstruct6
(
self
):
def
test_reconstruct6
(
self
):
self
.
assertRaises
(
self
.
assertRaises
(
AttributeError
,
self
.
module
.
reconstruct
,
images
=
[
'test.jpg'
])
AttributeError
,
self
.
module
.
reconstruct
,
images
=
[
'test.jpg'
]
)
def
test_save_inference_model
(
self
):
def
test_save_inference_model
(
self
):
self
.
module
.
save_inference_model
(
'./inference/model'
)
self
.
module
.
save_inference_model
(
'./inference/model'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录