Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
mmdetection3d
Commits
89bda282
Commit
89bda282
authored
May 05, 2020
by
zhangwenwei
Browse files
Merge branch 'master' into fix-train-runtime
parents
ff8623e1
99db60dd
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
65 deletions
+57
-65
tools/data_converter/sunrgbd_converter.py
tools/data_converter/sunrgbd_converter.py
+0
-36
tools/data_converter/sunrgbd_data_utils.py
tools/data_converter/sunrgbd_data_utils.py
+57
-29
No files found.
tools/data_converter/sunrgbd_converter.py
deleted
100644 → 0
View file @
ff8623e1
import
os
import
pickle
from
pathlib
import
Path
from
tools.data_converter.sunrgbd_data_utils
import
SUNRGBDData
def
create_sunrgbd_info_file
(
data_path
,
pkl_prefix
=
'sunrgbd'
,
save_path
=
None
,
use_v1
=
False
):
assert
os
.
path
.
exists
(
data_path
)
if
save_path
is
None
:
save_path
=
Path
(
data_path
)
else
:
save_path
=
Path
(
save_path
)
assert
os
.
path
.
exists
(
save_path
)
train_filename
=
save_path
/
f
'
{
pkl_prefix
}
_infos_train.pkl'
val_filename
=
save_path
/
f
'
{
pkl_prefix
}
_infos_val.pkl'
train_dataset
=
SUNRGBDData
(
root_path
=
data_path
,
split
=
'train'
,
use_v1
=
use_v1
)
val_dataset
=
SUNRGBDData
(
root_path
=
data_path
,
split
=
'val'
,
use_v1
=
use_v1
)
sunrgbd_infos_train
=
train_dataset
.
get_sunrgbd_infos
(
has_label
=
True
)
with
open
(
train_filename
,
'wb'
)
as
f
:
pickle
.
dump
(
sunrgbd_infos_train
,
f
)
print
(
'Sunrgbd info train file is saved to %s'
%
train_filename
)
sunrgbd_infos_val
=
val_dataset
.
get_sunrgbd_infos
(
has_label
=
True
)
with
open
(
val_filename
,
'wb'
)
as
f
:
pickle
.
dump
(
sunrgbd_infos_val
,
f
)
print
(
'Sunrgbd info val file is saved to %s'
%
val_filename
)
if
__name__
==
'__main__'
:
create_sunrgbd_info_file
(
data_path
=
'./data/sunrgbd/sunrgbd_trainval'
,
save_path
=
'./data/sunrgbd'
)
tools/data_converter/sunrgbd_data_utils.py
View file @
89bda282
import
concurrent.futures
as
futures
import
os
import
os
import
cv
2
import
mm
cv
import
numpy
as
np
import
numpy
as
np
import
scipy.io
as
sio
import
scipy.io
as
sio
def
random_sampling
(
pc
,
num_sample
,
replace
=
None
,
return_choices
=
False
):
def
random_sampling
(
points
,
num_points
,
replace
=
None
,
return_choices
=
False
):
""" Input is NxC, output is num_samplexC
"""Random Sampling.
Sampling point cloud to a certain number of points.
Args:
points (ndarray): Point cloud.
num_points (int): The number of samples.
replace (bool): Whether the sample is with or without replacement.
return_choices (bool): Whether to return choices.
Returns:
points (ndarray): Point cloud after sampling.
"""
"""
if
replace
is
None
:
if
replace
is
None
:
replace
=
(
p
c
.
shape
[
0
]
<
num_
sample
)
replace
=
(
p
oints
.
shape
[
0
]
<
num_
points
)
choices
=
np
.
random
.
choice
(
p
c
.
shape
[
0
],
num_
sample
,
replace
=
replace
)
choices
=
np
.
random
.
choice
(
p
oints
.
shape
[
0
],
num_
points
,
replace
=
replace
)
if
return_choices
:
if
return_choices
:
return
p
c
[
choices
],
choices
return
p
oints
[
choices
],
choices
else
:
else
:
return
p
c
[
choices
]
return
p
oints
[
choices
]
class
SUNRGBDInstance
(
object
):
class
SUNRGBDInstance
(
object
):
...
@@ -44,7 +57,15 @@ class SUNRGBDInstance(object):
...
@@ -44,7 +57,15 @@ class SUNRGBDInstance(object):
class
SUNRGBDData
(
object
):
class
SUNRGBDData
(
object
):
''' Load and parse object data '''
"""SUNRGBD Data
Generate scannet infos for sunrgbd_converter
Args:
root_path (str): Root path of the raw data.
split (str): Set split type of the data. Default: 'train'.
use_v1 (bool): Whether to use v1. Default: False.
"""
def
__init__
(
self
,
root_path
,
split
=
'train'
,
use_v1
=
False
):
def
__init__
(
self
,
root_path
,
split
=
'train'
,
use_v1
=
False
):
self
.
root_dir
=
root_path
self
.
root_dir
=
root_path
...
@@ -60,11 +81,9 @@ class SUNRGBDData(object):
...
@@ -60,11 +81,9 @@ class SUNRGBDData(object):
for
label
in
range
(
len
(
self
.
classes
))
for
label
in
range
(
len
(
self
.
classes
))
}
}
assert
split
in
[
'train'
,
'val'
,
'test'
]
assert
split
in
[
'train'
,
'val'
,
'test'
]
split_dir
=
os
.
path
.
join
(
self
.
root_dir
,
'%s_data_idx.txt'
%
split
)
split_file
=
os
.
path
.
join
(
self
.
root_dir
,
f
'
{
split
}
_data_idx.txt'
)
self
.
sample_id_list
=
[
mmcv
.
check_file_exist
(
split_file
)
int
(
x
.
strip
())
for
x
in
open
(
split_dir
).
readlines
()
self
.
sample_id_list
=
map
(
int
,
mmcv
.
list_from_file
(
split_file
))
]
if
os
.
path
.
exists
(
split_dir
)
else
None
self
.
image_dir
=
os
.
path
.
join
(
self
.
split_dir
,
'image'
)
self
.
image_dir
=
os
.
path
.
join
(
self
.
split_dir
,
'image'
)
self
.
calib_dir
=
os
.
path
.
join
(
self
.
split_dir
,
'calib'
)
self
.
calib_dir
=
os
.
path
.
join
(
self
.
split_dir
,
'calib'
)
self
.
depth_dir
=
os
.
path
.
join
(
self
.
split_dir
,
'depth'
)
self
.
depth_dir
=
os
.
path
.
join
(
self
.
split_dir
,
'depth'
)
...
@@ -77,20 +96,20 @@ class SUNRGBDData(object):
...
@@ -77,20 +96,20 @@ class SUNRGBDData(object):
return
len
(
self
.
sample_id_list
)
return
len
(
self
.
sample_id_list
)
def
get_image
(
self
,
idx
):
def
get_image
(
self
,
idx
):
img_filename
=
os
.
path
.
join
(
self
.
image_dir
,
'%
06d.jpg'
%
(
idx
)
)
img_filename
=
os
.
path
.
join
(
self
.
image_dir
,
f
'
{
idx
:
06
d
}
.jpg'
)
return
cv
2
.
imread
(
img_filename
)
return
mm
cv
.
imread
(
img_filename
)
def
get_image_shape
(
self
,
idx
):
def
get_image_shape
(
self
,
idx
):
image
=
self
.
get_image
(
idx
)
image
=
self
.
get_image
(
idx
)
return
np
.
array
(
image
.
shape
[:
2
],
dtype
=
np
.
int32
)
return
np
.
array
(
image
.
shape
[:
2
],
dtype
=
np
.
int32
)
def
get_depth
(
self
,
idx
):
def
get_depth
(
self
,
idx
):
depth_filename
=
os
.
path
.
join
(
self
.
depth_dir
,
'%
06d.mat'
%
(
idx
)
)
depth_filename
=
os
.
path
.
join
(
self
.
depth_dir
,
f
'
{
idx
:
06
d
}
.mat'
)
depth
=
sio
.
loadmat
(
depth_filename
)[
'instance'
]
depth
=
sio
.
loadmat
(
depth_filename
)[
'instance'
]
return
depth
return
depth
def
get_calibration
(
self
,
idx
):
def
get_calibration
(
self
,
idx
):
calib_filepath
=
os
.
path
.
join
(
self
.
calib_dir
,
'%
06d.txt'
%
(
idx
)
)
calib_filepath
=
os
.
path
.
join
(
self
.
calib_dir
,
f
'
{
idx
:
06
d
}
.txt'
)
lines
=
[
line
.
rstrip
()
for
line
in
open
(
calib_filepath
)]
lines
=
[
line
.
rstrip
()
for
line
in
open
(
calib_filepath
)]
Rt
=
np
.
array
([
float
(
x
)
for
x
in
lines
[
0
].
split
(
' '
)])
Rt
=
np
.
array
([
float
(
x
)
for
x
in
lines
[
0
].
split
(
' '
)])
Rt
=
np
.
reshape
(
Rt
,
(
3
,
3
),
order
=
'F'
)
Rt
=
np
.
reshape
(
Rt
,
(
3
,
3
),
order
=
'F'
)
...
@@ -98,33 +117,43 @@ class SUNRGBDData(object):
...
@@ -98,33 +117,43 @@ class SUNRGBDData(object):
return
K
,
Rt
return
K
,
Rt
def
get_label_objects
(
self
,
idx
):
def
get_label_objects
(
self
,
idx
):
label_filename
=
os
.
path
.
join
(
self
.
label_dir
,
'%
06d.txt'
%
(
idx
)
)
label_filename
=
os
.
path
.
join
(
self
.
label_dir
,
f
'
{
idx
:
06
d
}
.txt'
)
lines
=
[
line
.
rstrip
()
for
line
in
open
(
label_filename
)]
lines
=
[
line
.
rstrip
()
for
line
in
open
(
label_filename
)]
objects
=
[
SUNRGBDInstance
(
line
)
for
line
in
lines
]
objects
=
[
SUNRGBDInstance
(
line
)
for
line
in
lines
]
return
objects
return
objects
def
get_sunrgbd_infos
(
self
,
def
get_infos
(
self
,
num_workers
=
4
,
has_label
=
True
,
sample_id_list
=
None
):
num_workers
=
4
,
"""Get data infos.
has_label
=
True
,
sample_id_list
=
None
):
This method gets information from the raw data.
import
concurrent.futures
as
futures
Args:
num_workers (int): Number of threads to be used. Default: 4.
has_label (bool): Whether the data has label. Default: True.
sample_id_list (List[int]): Index list of the sample.
Default: None.
Returns:
infos (List[dict]): Information of the raw data.
"""
def
process_single_scene
(
sample_idx
):
def
process_single_scene
(
sample_idx
):
print
(
'%s sample_idx: %s'
%
(
self
.
split
,
sample_idx
)
)
print
(
f
'
{
self
.
split
}
sample_idx:
{
sample_idx
}
'
)
# convert depth to points
# convert depth to points
SAMPLE_NUM
=
50000
SAMPLE_NUM
=
50000
# TODO: Check whether can move the point
# sampling process during training.
pc_upright_depth
=
self
.
get_depth
(
sample_idx
)
pc_upright_depth
=
self
.
get_depth
(
sample_idx
)
# TODO : sample points in loading process and test
pc_upright_depth_subsampled
=
random_sampling
(
pc_upright_depth_subsampled
=
random_sampling
(
pc_upright_depth
,
SAMPLE_NUM
)
pc_upright_depth
,
SAMPLE_NUM
)
np
.
savez_compressed
(
np
.
savez_compressed
(
os
.
path
.
join
(
self
.
root_dir
,
'lidar'
,
'%06d.npz'
%
sample_idx
),
os
.
path
.
join
(
self
.
root_dir
,
'lidar'
,
f
'
{
sample_idx
:
06
d
}
.npz'
),
pc
=
pc_upright_depth_subsampled
)
pc
=
pc_upright_depth_subsampled
)
info
=
dict
()
info
=
dict
()
pc_info
=
{
'num_features'
:
6
,
'lidar_idx'
:
sample_idx
}
pc_info
=
{
'num_features'
:
6
,
'lidar_idx'
:
sample_idx
}
info
[
'point_cloud'
]
=
pc_info
info
[
'point_cloud'
]
=
pc_info
img_name
=
os
.
path
.
join
(
self
.
image_dir
,
'%06d.jpg'
%
(
sample_idx
)
)
img_name
=
os
.
path
.
join
(
self
.
image_dir
,
f
'
{
sample_idx
:
06
d
}
'
)
img_path
=
os
.
path
.
join
(
self
.
image_dir
,
img_name
)
img_path
=
os
.
path
.
join
(
self
.
image_dir
,
img_name
)
image_info
=
{
image_info
=
{
'image_idx'
:
sample_idx
,
'image_idx'
:
sample_idx
,
...
@@ -183,8 +212,7 @@ class SUNRGBDData(object):
...
@@ -183,8 +212,7 @@ class SUNRGBDData(object):
return
info
return
info
lidar_save_dir
=
os
.
path
.
join
(
self
.
root_dir
,
'lidar'
)
lidar_save_dir
=
os
.
path
.
join
(
self
.
root_dir
,
'lidar'
)
if
not
os
.
path
.
exists
(
lidar_save_dir
):
mmcv
.
mkdir_or_exist
(
lidar_save_dir
)
os
.
mkdir
(
lidar_save_dir
)
sample_id_list
=
sample_id_list
if
\
sample_id_list
=
sample_id_list
if
\
sample_id_list
is
not
None
else
self
.
sample_id_list
sample_id_list
is
not
None
else
self
.
sample_id_list
with
futures
.
ThreadPoolExecutor
(
num_workers
)
as
executor
:
with
futures
.
ThreadPoolExecutor
(
num_workers
)
as
executor
:
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment