Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
52ba23c8
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看板
提交
52ba23c8
编写于
8月 29, 2022
作者:
D
dongshuilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix build_gallery bug
上级
9eaa3353
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
11 deletion
+9
-11
deploy/python/build_gallery.py
deploy/python/build_gallery.py
+9
-11
未找到文件。
deploy/python/build_gallery.py
浏览文件 @
52ba23c8
...
...
@@ -50,8 +50,8 @@ class GalleryBuilder(object):
self
.
config
=
config
self
.
rec_predictor
=
RecPredictor
(
config
)
assert
'IndexProcess'
in
config
.
keys
(),
"Index config not found ... "
self
.
build
(
config
[
'IndexProcess'
])
self
.
android_demo
=
config
[
"Global"
].
get
(
"android_demo"
,
False
)
self
.
build
(
config
[
'IndexProcess'
])
def
build
(
self
,
config
):
'''
...
...
@@ -78,7 +78,8 @@ class GalleryBuilder(object):
index
,
ids
=
None
,
None
if
operation_method
in
[
"remove"
,
"append"
]:
# if remove or append, load vector.index and id_map.pkl
index
,
ids
=
self
.
_load_index
()
index
,
ids
=
self
.
_load_index
(
config
)
index_method
=
config
.
get
(
"index_method"
,
"HNSW32"
)
else
:
index_method
,
index
,
ids
=
self
.
_create_index
(
config
)
if
index_method
==
"HNSW32"
:
...
...
@@ -87,7 +88,7 @@ class GalleryBuilder(object):
if
operation_method
!=
"remove"
:
# calculate id for new data
index
,
ids
=
self
.
_add_gallery
(
index
,
ids
,
gallery_features
,
gallery_docs
)
index
,
ids
=
self
.
_add_gallery
(
index
,
ids
,
gallery_features
,
gallery_docs
,
config
,
operation_method
)
else
:
if
index_method
==
"HNSW32"
:
raise
RuntimeError
(
...
...
@@ -104,14 +105,11 @@ class GalleryBuilder(object):
os
.
makedirs
(
config
[
"index_dir"
],
exist_ok
=
True
)
#build index
index
=
faiss
.
IndexFlatIP
(
config
[
"embedding_size"
])
ids
=
{}
# calculate id for new data
ids_now
=
(
np
.
arange
(
0
,
len
(
gallery_images
))).
astype
(
np
.
int64
)
index
.
add
(
gallery_features
)
# calculate id for data
ids_now
=
(
np
.
arange
(
0
,
len
(
gallery_docs
))).
astype
(
np
.
int64
)
ids
=
{}
for
i
,
d
in
zip
(
list
(
ids_now
),
gallery_docs
):
ids
[
i
]
=
d
self
.
_save_gallery
(
config
,
index
,
ids
)
...
...
@@ -197,7 +195,7 @@ class GalleryBuilder(object):
ids
=
{}
return
index_method
,
index
,
ids
def
_add_gallery
(
self
,
index
,
ids
,
gallery_features
,
gallery_docs
):
def
_add_gallery
(
self
,
index
,
ids
,
gallery_features
,
gallery_docs
,
config
,
operation_method
):
start_id
=
max
(
ids
.
keys
())
+
1
if
ids
else
0
ids_now
=
(
np
.
arange
(
0
,
len
(
gallery_docs
))
+
start_id
).
astype
(
np
.
int64
)
...
...
@@ -216,7 +214,7 @@ class GalleryBuilder(object):
ids
[
i
]
=
d
return
index
,
ids
def
_rm_id_in_galllery
(
self
,
index
,
ids
,
gallery_docs
)
def
_rm_id_in_galllery
(
self
,
index
,
ids
,
gallery_docs
)
:
remove_ids
=
list
(
filter
(
lambda
k
:
ids
.
get
(
k
)
in
gallery_docs
,
ids
.
keys
()))
remove_ids
=
np
.
asarray
(
remove_ids
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录