Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gdrnpp Bop2022
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guillaume Duret
Gdrnpp Bop2022
Commits
9deff8b8
Commit
9deff8b8
authored
2 years ago
by
liuxingyu
Browse files
Options
Downloads
Patches
Plain Diff
rm files
parent
06d615e9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/gdrn_modeling/tools/convert_det_to_our_format.py
+0
-88
0 additions, 88 deletions
core/gdrn_modeling/tools/convert_det_to_our_format.py
core/gdrn_modeling/tools/convert_det_to_our_format_1b.py
+0
-97
0 additions, 97 deletions
core/gdrn_modeling/tools/convert_det_to_our_format_1b.py
with
0 additions
and
185 deletions
core/gdrn_modeling/tools/convert_det_to_our_format.py
deleted
100644 → 0
+
0
−
88
View file @
06d615e9
import
mmcv
import
sys
import
argparse
import
json
import
os
parser
=
argparse
.
ArgumentParser
(
description
=
"
convert det from bop format to ours
"
)
parser
.
add_argument
(
"
--idir
"
,
type
=
str
,
default
=
"
/data2/lxy/Storage/bop22_results/yolovx_amodal
"
,
help
=
"
input path
"
)
parser
.
add_argument
(
"
--odir
"
,
type
=
str
,
default
=
"
datasets/BOP_DATASETS/
"
,
help
=
"
output path
"
)
args
=
parser
.
parse_args
()
def
convert_format
(
ipath
,
opath
):
ds
=
mmcv
.
load
(
ipath
)
outs
=
{}
for
d
in
ds
:
scene_id
=
d
[
"
scene_id
"
]
image_id
=
d
[
"
image_id
"
]
scene_im_id
=
f
"
{
scene_id
}
/
{
image_id
}
"
obj_id
=
d
[
"
category_id
"
]
score
=
d
[
"
score
"
]
bbox
=
d
[
"
bbox
"
]
time
=
d
[
"
time
"
]
cur_dict
=
{
"
bbox_est
"
:
bbox
,
"
obj_id
"
:
obj_id
,
"
score
"
:
score
,
"
time
"
:
time
,
}
if
scene_im_id
in
outs
.
keys
():
outs
[
scene_im_id
].
append
(
cur_dict
)
else
:
outs
[
scene_im_id
]
=
[
cur_dict
]
save_json
(
opath
,
outs
)
print
(
f
"
json file has been saved at
{
opath
}
"
)
def
save_json
(
path
,
content
,
sort
=
False
):
"""
Saves the provided content to a JSON file.
:param path: Path to the output JSON file.
:param content: Dictionary/list to save.
"""
with
open
(
path
,
"
w
"
)
as
f
:
if
isinstance
(
content
,
dict
):
f
.
write
(
"
{
\n
"
)
if
sort
:
content_sorted
=
sorted
(
content
.
items
(),
key
=
lambda
x
:
x
[
0
])
else
:
content_sorted
=
content
.
items
()
for
elem_id
,
(
k
,
v
)
in
enumerate
(
content_sorted
):
f
.
write
(
'
"
{}
"
: {}
'
.
format
(
k
,
json
.
dumps
(
v
,
sort_keys
=
True
)))
if
elem_id
!=
len
(
content
)
-
1
:
f
.
write
(
"
,
"
)
f
.
write
(
"
\n
"
)
f
.
write
(
"
}
"
)
elif
isinstance
(
content
,
list
):
f
.
write
(
"
[
\n
"
)
for
elem_id
,
elem
in
enumerate
(
content
):
f
.
write
(
"
{}
"
.
format
(
json
.
dumps
(
elem
,
sort_keys
=
True
)))
if
elem_id
!=
len
(
content
)
-
1
:
f
.
write
(
"
,
"
)
f
.
write
(
"
\n
"
)
f
.
write
(
"
]
"
)
else
:
json
.
dump
(
content
,
f
,
sort_keys
=
True
)
if
__name__
==
"
__main__
"
:
dsets
=
sorted
(
os
.
listdir
(
args
.
idir
))
for
dset
in
dsets
:
json_files
=
os
.
listdir
(
os
.
path
.
join
(
args
.
idir
,
dset
))
for
json_file
in
json_files
:
ipath
=
os
.
path
.
join
(
args
.
idir
,
dset
,
json_file
)
odir
=
os
.
path
.
join
(
args
.
odir
,
dset
,
"
test/test_bboxes
"
)
mmcv
.
mkdir_or_exist
(
odir
)
opath
=
os
.
path
.
join
(
odir
,
json_file
)
convert_format
(
ipath
,
opath
)
This diff is collapsed.
Click to expand it.
core/gdrn_modeling/tools/convert_det_to_our_format_1b.py
deleted
100644 → 0
+
0
−
97
View file @
06d615e9
import
mmcv
import
sys
import
argparse
import
json
import
os
parser
=
argparse
.
ArgumentParser
(
description
=
"
convert det from bop format to ours
"
)
parser
.
add_argument
(
"
--idir
"
,
type
=
str
,
default
=
"
/data1/tangjw/projects/YOLOX_benckmark/master/object_pose_benchmark/output/yolox/bop_pbr/multi_scale_test
"
,
help
=
"
input path
"
,
)
parser
.
add_argument
(
"
--odir
"
,
type
=
str
,
default
=
"
datasets/BOP_DATASETS/
"
,
help
=
"
output path
"
)
args
=
parser
.
parse_args
()
dataset_names
=
[
"
hb
"
,
"
icbin
"
,
"
itodd
"
,
"
lmo
"
,
"
tless
"
,
"
tudl
"
,
"
ycbv
"
]
def
convert_format
(
ipath
,
opath
):
ds
=
mmcv
.
load
(
ipath
)
outs
=
{}
for
d
in
ds
:
scene_id
=
d
[
"
scene_id
"
]
image_id
=
d
[
"
image_id
"
]
scene_im_id
=
f
"
{
scene_id
}
/
{
image_id
}
"
obj_id
=
d
[
"
category_id
"
]
score
=
d
[
"
score
"
]
bbox
=
d
[
"
bbox
"
]
time
=
d
[
"
time
"
]
cur_dict
=
{
"
bbox_est
"
:
bbox
,
"
obj_id
"
:
obj_id
,
"
score
"
:
score
,
"
time
"
:
time
,
}
if
scene_im_id
in
outs
.
keys
():
outs
[
scene_im_id
].
append
(
cur_dict
)
else
:
outs
[
scene_im_id
]
=
[
cur_dict
]
save_json
(
opath
,
outs
)
print
(
f
"
json file has been saved at
{
opath
}
"
)
def
save_json
(
path
,
content
,
sort
=
False
):
"""
Saves the provided content to a JSON file.
:param path: Path to the output JSON file.
:param content: Dictionary/list to save.
"""
with
open
(
path
,
"
w
"
)
as
f
:
if
isinstance
(
content
,
dict
):
f
.
write
(
"
{
\n
"
)
if
sort
:
content_sorted
=
sorted
(
content
.
items
(),
key
=
lambda
x
:
x
[
0
])
else
:
content_sorted
=
content
.
items
()
for
elem_id
,
(
k
,
v
)
in
enumerate
(
content_sorted
):
f
.
write
(
'
"
{}
"
: {}
'
.
format
(
k
,
json
.
dumps
(
v
,
sort_keys
=
True
)))
if
elem_id
!=
len
(
content
)
-
1
:
f
.
write
(
"
,
"
)
f
.
write
(
"
\n
"
)
f
.
write
(
"
}
"
)
elif
isinstance
(
content
,
list
):
f
.
write
(
"
[
\n
"
)
for
elem_id
,
elem
in
enumerate
(
content
):
f
.
write
(
"
{}
"
.
format
(
json
.
dumps
(
elem
,
sort_keys
=
True
)))
if
elem_id
!=
len
(
content
)
-
1
:
f
.
write
(
"
,
"
)
f
.
write
(
"
\n
"
)
f
.
write
(
"
]
"
)
else
:
json
.
dump
(
content
,
f
,
sort_keys
=
True
)
if
__name__
==
"
__main__
"
:
json_files
=
sorted
(
os
.
listdir
(
args
.
idir
))
for
json_file
in
json_files
:
for
dset
in
dataset_names
:
if
dset
in
json_file
:
break
ipath
=
os
.
path
.
join
(
args
.
idir
,
json_file
)
odir
=
os
.
path
.
join
(
args
.
odir
,
dset
,
"
test/test_bboxes
"
)
mmcv
.
mkdir_or_exist
(
odir
)
opath
=
os
.
path
.
join
(
odir
,
json_file
)
convert_format
(
ipath
,
opath
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment