Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
5cf3c3bb
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5cf3c3bb
编写于
1月 17, 2023
作者:
G
Guoxia Wang
提交者:
GitHub
1月 17, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix cache directory and app style (#5705)
LGTM
上级
dfe7e97c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
11 deletion
+19
-11
modelcenter/PLSC-ViT/APP/app.py
modelcenter/PLSC-ViT/APP/app.py
+13
-4
modelcenter/PLSC-ViT/APP/download.py
modelcenter/PLSC-ViT/APP/download.py
+6
-7
未找到文件。
modelcenter/PLSC-ViT/APP/app.py
浏览文件 @
5cf3c3bb
import
gradio
as
gr
from
predictor
import
Predictor
model_path
=
"paddlecv://models/vit/v2.4/imagenet2012-ViT-B_16-224_infer.pdmodel"
params_path
=
"paddlecv://models/vit/v2.4/imagenet2012-ViT-B_16-224_infer.pdiparams"
label_path
=
"paddlecv://dataset/imagenet2012_labels.txt"
predictor
=
None
def
model_inference
(
image
):
predictor
=
Predictor
(
model_path
=
model_path
,
params_path
=
params_path
,
label_path
=
label_path
)
global
predictor
if
predictor
is
None
:
predictor
=
Predictor
(
model_path
=
model_path
,
params_path
=
params_path
,
label_path
=
label_path
)
scores
,
labels
=
predictor
.
predict
(
image
)
json_out
=
{
"scores"
:
scores
.
tolist
(),
"labels"
:
labels
.
tolist
()}
return
image
,
json_out
...
...
@@ -22,13 +29,15 @@ with gr.Blocks() as demo:
with
gr
.
Column
(
scale
=
1
,
min_width
=
100
):
img_in
=
gr
.
Image
(
value
=
"https://plsc.bj.bcebos.com/dataset/test_images/cat.jpg"
,
label
=
"Input"
).
style
(
height
=
200
)
img_in
=
gr
.
Image
(
value
=
"https://plsc.bj.bcebos.com/dataset/test_images/cat.jpg"
,
label
=
"Input"
)
with
gr
.
Row
():
btn1
=
gr
.
Button
(
"Clear"
)
btn2
=
gr
.
Button
(
"Submit"
)
img_out
=
gr
.
Image
(
label
=
"Output"
)
.
style
(
height
=
200
)
img_out
=
gr
.
Image
(
label
=
"Output"
)
json_out
=
gr
.
JSON
(
label
=
"jsonOutput"
)
btn2
.
click
(
fn
=
model_inference
,
inputs
=
img_in
,
outputs
=
[
img_out
,
json_out
])
...
...
modelcenter/PLSC-ViT/APP/download.py
浏览文件 @
5cf3c3bb
...
...
@@ -33,10 +33,10 @@ __all__ = [
'get_data_path'
,
]
WEIGHTS_HOME
=
osp
.
expanduser
(
"~/.cache/paddlecv/models"
)
CONFIGS_HOME
=
osp
.
expanduser
(
"~/.cache/paddlecv/configs"
)
DICTS_HOME
=
osp
.
expanduser
(
"~/.cache/paddlecv/dicts"
)
DATA_HOME
=
osp
.
expanduser
(
"~/.cache/paddlecv/dataset"
)
WEIGHTS_HOME
=
osp
.
expanduser
(
"~/.cache/paddlecv/models
/plsc
"
)
CONFIGS_HOME
=
osp
.
expanduser
(
"~/.cache/paddlecv/configs
/plsc
"
)
DICTS_HOME
=
osp
.
expanduser
(
"~/.cache/paddlecv/dicts
/plsc/
"
)
DATA_HOME
=
osp
.
expanduser
(
"~/.cache/paddlecv/dataset
/plsc
"
)
# dict of {dataset_name: (download_info, sub_dirs)}
# download info: [(url, md5sum)]
...
...
@@ -68,7 +68,7 @@ def get_model_path(path):
if
not
is_url
(
path
):
return
path
url
=
parse_url
(
path
)
path
,
_
=
get_path
(
url
,
WEIGHTS_HOME
,
path_depth
=
2
)
path
,
_
=
get_path
(
url
,
WEIGHTS_HOME
,
path_depth
=
3
)
return
path
...
...
@@ -79,7 +79,7 @@ def get_data_path(path):
if
not
is_url
(
path
):
return
path
url
=
parse_url
(
path
)
path
,
_
=
get_path
(
url
,
DATA_HOME
,
path_depth
=
2
)
path
,
_
=
get_path
(
url
,
DATA_HOME
,
path_depth
=
1
)
return
path
...
...
@@ -162,7 +162,6 @@ def _download(url, path, md5sum=None):
raise
RuntimeError
(
"Download from {} failed. "
"Retry limit reached"
.
format
(
url
))
# NOTE: windows path join may incur \, which is invalid in url
if
sys
.
platform
==
"win32"
:
url
=
url
.
replace
(
'
\\
'
,
'/'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录