Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
106bb9df
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
106bb9df
编写于
6月 08, 2021
作者:
F
Felix
提交者:
GitHub
6月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Create build_gallery.py
上级
3cce16d9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
91 addition
and
0 deletion
+91
-0
deploy/python/build_gallery.py
deploy/python/build_gallery.py
+91
-0
未找到文件。
deploy/python/build_gallery.py
0 → 100644
浏览文件 @
106bb9df
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
import
sys
__dir__
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
sys
.
path
.
append
(
os
.
path
.
abspath
(
os
.
path
.
join
(
__dir__
,
'../'
)))
import
copy
import
cv2
import
numpy
as
np
from
tqdm
import
tqdm
from
python.predict_rec
import
RecPredictor
from
vector_search
import
Graph_Index
from
utils
import
logger
from
utils
import
config
def
split_datafile
(
data_file
,
image_root
,
delimiter
=
"
\t
"
):
'''
data_file: image path and info, which can be splitted by spacer
image_root: image path root
delimiter: delimiter
'''
gallery_images
=
[]
gallery_docs
=
[]
with
open
(
data_file
)
as
f
:
lines
=
f
.
readlines
()
for
i
,
line
in
enumerate
(
lines
):
line
=
line
.
strip
().
split
(
delimiter
)
image_file
=
os
.
path
.
join
(
image_root
,
line
[
0
])
image_doc
=
line
[
1
]
gallery_images
.
append
(
image_file
)
gallery_docs
.
append
(
image_doc
)
return
gallery_images
,
gallery_docs
class
GalleryBuilder
(
object
):
def
__init__
(
self
,
config
):
self
.
config
=
config
self
.
rec_predictor
=
RecPredictor
(
config
)
assert
'IndexProcess'
in
config
.
keys
(),
"Index config not found ... "
self
.
build
(
config
[
'IndexProcess'
])
def
build
(
self
,
config
):
'''
build index from scratch
'''
gallery_images
,
gallery_docs
=
split_datafile
(
config
[
'data_file'
],
config
[
'image_root'
],
config
[
'delimiter'
])
# extract gallery features
gallery_features
=
np
.
zeros
([
len
(
gallery_images
),
config
[
'embedding_size'
]],
dtype
=
np
.
float32
)
for
i
,
image_file
in
enumerate
(
tqdm
(
gallery_images
)):
img
=
cv2
.
imread
(
image_file
)[:,
:,
::
-
1
]
rec_feat
=
self
.
rec_predictor
.
predict
(
img
)
gallery_features
[
i
,:]
=
rec_feat
# train index
self
.
Searcher
=
Graph_Index
(
dist_type
=
config
[
'dist_type'
])
self
.
Searcher
.
build
(
gallery_vectors
=
gallery_features
,
gallery_docs
=
gallery_docs
,
pq_size
=
config
[
'pq_size'
],
index_path
=
config
[
'index_path'
])
def
main
(
config
):
system_builder
=
GalleryBuilder
(
config
)
return
if
__name__
==
"__main__"
:
args
=
config
.
parse_args
()
config
=
config
.
get_config
(
args
.
config
,
overrides
=
args
.
override
,
show
=
True
)
main
(
config
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录