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
dcnv3
Commits
41b18fd8
Commit
41b18fd8
authored
Jan 06, 2025
by
zhe chen
Browse files
Use pre-commit to reformat code
Use pre-commit to reformat code
parent
ff20ea39
Changes
390
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
751 additions
and
760 deletions
+751
-760
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/datasets/samplers/distributed_sampler.py
...s/mmdet3d_plugin/datasets/samplers/distributed_sampler.py
+3
-2
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/datasets/samplers/group_sampler.py
...rojects/mmdet3d_plugin/datasets/samplers/group_sampler.py
+1
-4
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/datasets/samplers/sampler.py
...tion/projects/mmdet3d_plugin/datasets/samplers/sampler.py
+7
-7
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/backbones/__init__.py
...tion/projects/mmdet3d_plugin/models/backbones/__init__.py
+1
-1
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/backbones/vovnet.py
...iction/projects/mmdet3d_plugin/models/backbones/vovnet.py
+77
-78
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/hooks/__init__.py
...ediction/projects/mmdet3d_plugin/models/hooks/__init__.py
+1
-1
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/hooks/hooks.py
..._prediction/projects/mmdet3d_plugin/models/hooks/hooks.py
+1
-4
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/opt/__init__.py
...prediction/projects/mmdet3d_plugin/models/opt/__init__.py
+1
-1
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/opt/adamw.py
...cy_prediction/projects/mmdet3d_plugin/models/opt/adamw.py
+8
-8
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/__init__.py
...ediction/projects/mmdet3d_plugin/models/utils/__init__.py
+1
-2
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/bricks.py
...prediction/projects/mmdet3d_plugin/models/utils/bricks.py
+12
-7
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/grid_mask.py
...diction/projects/mmdet3d_plugin/models/utils/grid_mask.py
+45
-42
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/position_embedding.py
...rojects/mmdet3d_plugin/models/utils/position_embedding.py
+14
-11
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/positional_encoding.py
...ojects/mmdet3d_plugin/models/utils/positional_encoding.py
+70
-71
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/visual.py
...prediction/projects/mmdet3d_plugin/models/utils/visual.py
+5
-5
autonomous_driving/occupancy_prediction/tools/.ipynb_checkpoints/train-checkpoint.py
...y_prediction/tools/.ipynb_checkpoints/train-checkpoint.py
+19
-19
autonomous_driving/occupancy_prediction/tools/analysis_tools/analyze_logs.py
...occupancy_prediction/tools/analysis_tools/analyze_logs.py
+5
-4
autonomous_driving/occupancy_prediction/tools/analysis_tools/benchmark.py
...ng/occupancy_prediction/tools/analysis_tools/benchmark.py
+9
-6
autonomous_driving/occupancy_prediction/tools/analysis_tools/get_params.py
...g/occupancy_prediction/tools/analysis_tools/get_params.py
+11
-10
autonomous_driving/occupancy_prediction/tools/analysis_tools/visual.py
...iving/occupancy_prediction/tools/analysis_tools/visual.py
+460
-477
No files found.
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/datasets/samplers/distributed_sampler.py
View file @
41b18fd8
...
...
@@ -2,6 +2,7 @@ import math
import
torch
from
torch.utils.data
import
DistributedSampler
as
_DistributedSampler
from
.sampler
import
SAMPLER
...
...
@@ -33,9 +34,9 @@ class DistributedSampler(_DistributedSampler):
assert
len
(
indices
)
==
self
.
total_size
# subsample
per_replicas
=
self
.
total_size
//
self
.
num_replicas
per_replicas
=
self
.
total_size
//
self
.
num_replicas
# indices = indices[self.rank:self.total_size:self.num_replicas]
indices
=
indices
[
self
.
rank
*
per_replicas
:(
self
.
rank
+
1
)
*
per_replicas
]
indices
=
indices
[
self
.
rank
*
per_replicas
:(
self
.
rank
+
1
)
*
per_replicas
]
assert
len
(
indices
)
==
self
.
num_samples
return
iter
(
indices
)
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/datasets/samplers/group_sampler.py
View file @
41b18fd8
# Copyright (c) OpenMMLab. All rights reserved.
import
math
...
...
@@ -6,9 +5,8 @@ import numpy as np
import
torch
from
mmcv.runner
import
get_dist_info
from
torch.utils.data
import
Sampler
from
.sampler
import
SAMPLER
import
random
from
IPython
import
embed
@
SAMPLER
.
register_module
()
...
...
@@ -107,4 +105,3 @@ class DistributedGroupSampler(Sampler):
def
set_epoch
(
self
,
epoch
):
self
.
epoch
=
epoch
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/datasets/samplers/sampler.py
View file @
41b18fd8
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/backbones/__init__.py
View file @
41b18fd8
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/backbones/vovnet.py
View file @
41b18fd8
from
collections
import
OrderedDict
from
mmcv.runner
import
BaseModule
from
mmdet.models.builder
import
BACKBONES
import
torch
import
torch.nn
as
nn
import
torch.nn.functional
as
F
from
mmcv.runner
import
BaseModule
from
mmdet.models.builder
import
BACKBONES
from
torch.nn.modules.batchnorm
import
_BatchNorm
VoVNet19_slim_dw_eSE
=
{
'stem'
:
[
64
,
64
,
64
],
'stage_conv_ch'
:
[
64
,
80
,
96
,
112
],
'stage_out_ch'
:
[
112
,
256
,
384
,
512
],
"
layer_per_block
"
:
3
,
"
block_per_stage
"
:
[
1
,
1
,
1
,
1
],
"
eSE
"
:
True
,
"
dw
"
:
True
'
layer_per_block
'
:
3
,
'
block_per_stage
'
:
[
1
,
1
,
1
,
1
],
'
eSE
'
:
True
,
'
dw
'
:
True
}
VoVNet19_dw_eSE
=
{
'stem'
:
[
64
,
64
,
64
],
"
stage_conv_ch
"
:
[
128
,
160
,
192
,
224
],
"
stage_out_ch
"
:
[
256
,
512
,
768
,
1024
],
"
layer_per_block
"
:
3
,
"
block_per_stage
"
:
[
1
,
1
,
1
,
1
],
"
eSE
"
:
True
,
"
dw
"
:
True
'
stage_conv_ch
'
:
[
128
,
160
,
192
,
224
],
'
stage_out_ch
'
:
[
256
,
512
,
768
,
1024
],
'
layer_per_block
'
:
3
,
'
block_per_stage
'
:
[
1
,
1
,
1
,
1
],
'
eSE
'
:
True
,
'
dw
'
:
True
}
VoVNet19_slim_eSE
=
{
...
...
@@ -35,57 +34,57 @@ VoVNet19_slim_eSE = {
'layer_per_block'
:
3
,
'block_per_stage'
:
[
1
,
1
,
1
,
1
],
'eSE'
:
True
,
"
dw
"
:
False
'
dw
'
:
False
}
VoVNet19_eSE
=
{
'stem'
:
[
64
,
64
,
128
],
"
stage_conv_ch
"
:
[
128
,
160
,
192
,
224
],
"
stage_out_ch
"
:
[
256
,
512
,
768
,
1024
],
"
layer_per_block
"
:
3
,
"
block_per_stage
"
:
[
1
,
1
,
1
,
1
],
"
eSE
"
:
True
,
"
dw
"
:
False
'
stage_conv_ch
'
:
[
128
,
160
,
192
,
224
],
'
stage_out_ch
'
:
[
256
,
512
,
768
,
1024
],
'
layer_per_block
'
:
3
,
'
block_per_stage
'
:
[
1
,
1
,
1
,
1
],
'
eSE
'
:
True
,
'
dw
'
:
False
}
VoVNet39_eSE
=
{
'stem'
:
[
64
,
64
,
128
],
"
stage_conv_ch
"
:
[
128
,
160
,
192
,
224
],
"
stage_out_ch
"
:
[
256
,
512
,
768
,
1024
],
"
layer_per_block
"
:
5
,
"
block_per_stage
"
:
[
1
,
1
,
2
,
2
],
"
eSE
"
:
True
,
"
dw
"
:
False
'
stage_conv_ch
'
:
[
128
,
160
,
192
,
224
],
'
stage_out_ch
'
:
[
256
,
512
,
768
,
1024
],
'
layer_per_block
'
:
5
,
'
block_per_stage
'
:
[
1
,
1
,
2
,
2
],
'
eSE
'
:
True
,
'
dw
'
:
False
}
VoVNet57_eSE
=
{
'stem'
:
[
64
,
64
,
128
],
"
stage_conv_ch
"
:
[
128
,
160
,
192
,
224
],
"
stage_out_ch
"
:
[
256
,
512
,
768
,
1024
],
"
layer_per_block
"
:
5
,
"
block_per_stage
"
:
[
1
,
1
,
4
,
3
],
"
eSE
"
:
True
,
"
dw
"
:
False
'
stage_conv_ch
'
:
[
128
,
160
,
192
,
224
],
'
stage_out_ch
'
:
[
256
,
512
,
768
,
1024
],
'
layer_per_block
'
:
5
,
'
block_per_stage
'
:
[
1
,
1
,
4
,
3
],
'
eSE
'
:
True
,
'
dw
'
:
False
}
VoVNet99_eSE
=
{
'stem'
:
[
64
,
64
,
128
],
"
stage_conv_ch
"
:
[
128
,
160
,
192
,
224
],
"
stage_out_ch
"
:
[
256
,
512
,
768
,
1024
],
"
layer_per_block
"
:
5
,
"
block_per_stage
"
:
[
1
,
3
,
9
,
3
],
"
eSE
"
:
True
,
"
dw
"
:
False
'
stage_conv_ch
'
:
[
128
,
160
,
192
,
224
],
'
stage_out_ch
'
:
[
256
,
512
,
768
,
1024
],
'
layer_per_block
'
:
5
,
'
block_per_stage
'
:
[
1
,
3
,
9
,
3
],
'
eSE
'
:
True
,
'
dw
'
:
False
}
_STAGE_SPECS
=
{
"
V-19-slim-dw-eSE
"
:
VoVNet19_slim_dw_eSE
,
"
V-19-dw-eSE
"
:
VoVNet19_dw_eSE
,
"
V-19-slim-eSE
"
:
VoVNet19_slim_eSE
,
"
V-19-eSE
"
:
VoVNet19_eSE
,
"
V-39-eSE
"
:
VoVNet39_eSE
,
"
V-57-eSE
"
:
VoVNet57_eSE
,
"
V-99-eSE
"
:
VoVNet99_eSE
,
'
V-19-slim-dw-eSE
'
:
VoVNet19_slim_dw_eSE
,
'
V-19-dw-eSE
'
:
VoVNet19_dw_eSE
,
'
V-19-slim-eSE
'
:
VoVNet19_slim_eSE
,
'
V-19-eSE
'
:
VoVNet19_eSE
,
'
V-39-eSE
'
:
VoVNet39_eSE
,
'
V-57-eSE
'
:
VoVNet57_eSE
,
'
V-99-eSE
'
:
VoVNet99_eSE
,
}
...
...
@@ -117,7 +116,7 @@ def conv3x3(in_channels, out_channels, module_name, postfix, stride=1, groups=1,
"""3x3 convolution with padding"""
return
[
(
f
"
{
module_name
}
_
{
postfix
}
/conv
"
,
f
'
{
module_name
}
_
{
postfix
}
/conv
'
,
nn
.
Conv2d
(
in_channels
,
out_channels
,
...
...
@@ -128,8 +127,8 @@ def conv3x3(in_channels, out_channels, module_name, postfix, stride=1, groups=1,
bias
=
False
,
),
),
(
f
"
{
module_name
}
_
{
postfix
}
/norm
"
,
nn
.
BatchNorm2d
(
out_channels
)),
(
f
"
{
module_name
}
_
{
postfix
}
/relu
"
,
nn
.
ReLU
(
inplace
=
True
)),
(
f
'
{
module_name
}
_
{
postfix
}
/norm
'
,
nn
.
BatchNorm2d
(
out_channels
)),
(
f
'
{
module_name
}
_
{
postfix
}
/relu
'
,
nn
.
ReLU
(
inplace
=
True
)),
]
...
...
@@ -137,7 +136,7 @@ def conv1x1(in_channels, out_channels, module_name, postfix, stride=1, groups=1,
"""1x1 convolution with padding"""
return
[
(
f
"
{
module_name
}
_
{
postfix
}
/conv
"
,
f
'
{
module_name
}
_
{
postfix
}
/conv
'
,
nn
.
Conv2d
(
in_channels
,
out_channels
,
...
...
@@ -148,8 +147,8 @@ def conv1x1(in_channels, out_channels, module_name, postfix, stride=1, groups=1,
bias
=
False
,
),
),
(
f
"
{
module_name
}
_
{
postfix
}
/norm
"
,
nn
.
BatchNorm2d
(
out_channels
)),
(
f
"
{
module_name
}
_
{
postfix
}
/relu
"
,
nn
.
ReLU
(
inplace
=
True
)),
(
f
'
{
module_name
}
_
{
postfix
}
/norm
'
,
nn
.
BatchNorm2d
(
out_channels
)),
(
f
'
{
module_name
}
_
{
postfix
}
/relu
'
,
nn
.
ReLU
(
inplace
=
True
)),
]
...
...
@@ -192,7 +191,7 @@ class _OSA_module(nn.Module):
if
self
.
depthwise
and
in_channel
!=
stage_ch
:
self
.
isReduced
=
True
self
.
conv_reduction
=
nn
.
Sequential
(
OrderedDict
(
conv1x1
(
in_channel
,
stage_ch
,
"
{}_reduction
"
.
format
(
module_name
),
"0"
))
OrderedDict
(
conv1x1
(
in_channel
,
stage_ch
,
'
{}_reduction
'
.
format
(
module_name
),
'0'
))
)
for
i
in
range
(
layer_per_block
):
if
self
.
depthwise
:
...
...
@@ -203,7 +202,7 @@ class _OSA_module(nn.Module):
# feature aggregation
in_channel
=
in_ch
+
layer_per_block
*
stage_ch
self
.
concat
=
nn
.
Sequential
(
OrderedDict
(
conv1x1
(
in_channel
,
concat_ch
,
module_name
,
"
concat
"
)))
self
.
concat
=
nn
.
Sequential
(
OrderedDict
(
conv1x1
(
in_channel
,
concat_ch
,
module_name
,
'
concat
'
)))
self
.
ese
=
eSEModule
(
concat_ch
)
...
...
@@ -238,18 +237,18 @@ class _OSA_stage(nn.Sequential):
super
(
_OSA_stage
,
self
).
__init__
()
if
not
stage_num
==
2
:
self
.
add_module
(
"
Pooling
"
,
nn
.
MaxPool2d
(
kernel_size
=
3
,
stride
=
2
,
ceil_mode
=
True
))
self
.
add_module
(
'
Pooling
'
,
nn
.
MaxPool2d
(
kernel_size
=
3
,
stride
=
2
,
ceil_mode
=
True
))
if
block_per_stage
!=
1
:
SE
=
False
module_name
=
f
"
OSA
{
stage_num
}
_1
"
module_name
=
f
'
OSA
{
stage_num
}
_1
'
self
.
add_module
(
module_name
,
_OSA_module
(
in_ch
,
stage_ch
,
concat_ch
,
layer_per_block
,
module_name
,
SE
,
depthwise
=
depthwise
)
)
for
i
in
range
(
block_per_stage
-
1
):
if
i
!=
block_per_stage
-
2
:
# last block
SE
=
False
module_name
=
f
"
OSA
{
stage_num
}
_
{
i
+
2
}
"
module_name
=
f
'
OSA
{
stage_num
}
_
{
i
+
2
}
'
self
.
add_module
(
module_name
,
_OSA_module
(
...
...
@@ -285,32 +284,32 @@ class VoVNet(BaseModule):
self
.
init_cfg
=
dict
(
type
=
'Pretrained'
,
checkpoint
=
pretrained
)
stage_specs
=
_STAGE_SPECS
[
spec_name
]
stem_ch
=
stage_specs
[
"
stem
"
]
config_stage_ch
=
stage_specs
[
"
stage_conv_ch
"
]
config_concat_ch
=
stage_specs
[
"
stage_out_ch
"
]
block_per_stage
=
stage_specs
[
"
block_per_stage
"
]
layer_per_block
=
stage_specs
[
"
layer_per_block
"
]
SE
=
stage_specs
[
"
eSE
"
]
depthwise
=
stage_specs
[
"
dw
"
]
stem_ch
=
stage_specs
[
'
stem
'
]
config_stage_ch
=
stage_specs
[
'
stage_conv_ch
'
]
config_concat_ch
=
stage_specs
[
'
stage_out_ch
'
]
block_per_stage
=
stage_specs
[
'
block_per_stage
'
]
layer_per_block
=
stage_specs
[
'
layer_per_block
'
]
SE
=
stage_specs
[
'
eSE
'
]
depthwise
=
stage_specs
[
'
dw
'
]
self
.
_out_features
=
out_features
# Stem module
conv_type
=
dw_conv3x3
if
depthwise
else
conv3x3
stem
=
conv3x3
(
input_ch
,
stem_ch
[
0
],
"
stem
"
,
"1"
,
2
)
stem
+=
conv_type
(
stem_ch
[
0
],
stem_ch
[
1
],
"
stem
"
,
"2"
,
1
)
stem
+=
conv_type
(
stem_ch
[
1
],
stem_ch
[
2
],
"
stem
"
,
"3"
,
2
)
self
.
add_module
(
"
stem
"
,
nn
.
Sequential
((
OrderedDict
(
stem
))))
stem
=
conv3x3
(
input_ch
,
stem_ch
[
0
],
'
stem
'
,
'1'
,
2
)
stem
+=
conv_type
(
stem_ch
[
0
],
stem_ch
[
1
],
'
stem
'
,
'2'
,
1
)
stem
+=
conv_type
(
stem_ch
[
1
],
stem_ch
[
2
],
'
stem
'
,
'3'
,
2
)
self
.
add_module
(
'
stem
'
,
nn
.
Sequential
((
OrderedDict
(
stem
))))
current_stirde
=
4
self
.
_out_feature_strides
=
{
"
stem
"
:
current_stirde
,
"
stage2
"
:
current_stirde
}
self
.
_out_feature_channels
=
{
"
stem
"
:
stem_ch
[
2
]}
self
.
_out_feature_strides
=
{
'
stem
'
:
current_stirde
,
'
stage2
'
:
current_stirde
}
self
.
_out_feature_channels
=
{
'
stem
'
:
stem_ch
[
2
]}
stem_out_ch
=
[
stem_ch
[
2
]]
in_ch_list
=
stem_out_ch
+
config_concat_ch
[:
-
1
]
# OSA stages
self
.
stage_names
=
[]
for
i
in
range
(
4
):
# num_stages
name
=
"
stage%d
"
%
(
i
+
2
)
# stage 2 ... stage 5
name
=
'
stage%d
'
%
(
i
+
2
)
# stage 2 ... stage 5
self
.
stage_names
.
append
(
name
)
self
.
add_module
(
name
,
...
...
@@ -341,8 +340,8 @@ class VoVNet(BaseModule):
def
forward
(
self
,
x
):
outputs
=
{}
x
=
self
.
stem
(
x
)
if
"
stem
"
in
self
.
_out_features
:
outputs
[
"
stem
"
]
=
x
if
'
stem
'
in
self
.
_out_features
:
outputs
[
'
stem
'
]
=
x
for
name
in
self
.
stage_names
:
x
=
getattr
(
self
,
name
)(
x
)
if
name
in
self
.
_out_features
:
...
...
@@ -358,7 +357,7 @@ class VoVNet(BaseModule):
param
.
requires_grad
=
False
for
i
in
range
(
1
,
self
.
frozen_stages
+
1
):
m
=
getattr
(
self
,
f
'stage
{
i
+
1
}
'
)
m
=
getattr
(
self
,
f
'stage
{
i
+
1
}
'
)
m
.
eval
()
for
param
in
m
.
parameters
():
param
.
requires_grad
=
False
...
...
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/hooks/__init__.py
View file @
41b18fd8
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/hooks/hooks.py
View file @
41b18fd8
from
mmcv.runner.hooks.hook
import
HOOKS
,
Hook
from
projects.mmdet3d_plugin.models.utils
import
run_time
@
HOOKS
.
register_module
()
...
...
@@ -7,7 +6,5 @@ class GradChecker(Hook):
def
after_train_iter
(
self
,
runner
):
for
key
,
val
in
runner
.
model
.
named_parameters
():
if
val
.
grad
==
None
and
val
.
requires_grad
:
if
val
.
grad
is
None
and
val
.
requires_grad
:
print
(
'WARNNING: {key}
\'
s parameters are not be used!!!!'
.
format
(
key
=
key
))
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/opt/__init__.py
View file @
41b18fd8
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/opt/adamw.py
View file @
41b18fd8
...
...
@@ -4,8 +4,9 @@ except:
print
(
'WARNING!!!, I recommend using torch>=1.8'
)
import
torch
from
torch.optim.optimizer
import
Optimizer
from
mmcv.runner.optimizer.builder
import
OPTIMIZERS
from
torch.optim.optimizer
import
Optimizer
@
OPTIMIZERS
.
register_module
()
class
AdamW2
(
Optimizer
):
...
...
@@ -38,15 +39,15 @@ class AdamW2(Optimizer):
def
__init__
(
self
,
params
,
lr
=
1e-3
,
betas
=
(
0.9
,
0.999
),
eps
=
1e-8
,
weight_decay
=
1e-2
,
amsgrad
=
False
):
if
not
0.0
<=
lr
:
raise
ValueError
(
"
Invalid learning rate: {}
"
.
format
(
lr
))
raise
ValueError
(
'
Invalid learning rate: {}
'
.
format
(
lr
))
if
not
0.0
<=
eps
:
raise
ValueError
(
"
Invalid epsilon value: {}
"
.
format
(
eps
))
raise
ValueError
(
'
Invalid epsilon value: {}
'
.
format
(
eps
))
if
not
0.0
<=
betas
[
0
]
<
1.0
:
raise
ValueError
(
"
Invalid beta parameter at index 0: {}
"
.
format
(
betas
[
0
]))
raise
ValueError
(
'
Invalid beta parameter at index 0: {}
'
.
format
(
betas
[
0
]))
if
not
0.0
<=
betas
[
1
]
<
1.0
:
raise
ValueError
(
"
Invalid beta parameter at index 1: {}
"
.
format
(
betas
[
1
]))
raise
ValueError
(
'
Invalid beta parameter at index 1: {}
'
.
format
(
betas
[
1
]))
if
not
0.0
<=
weight_decay
:
raise
ValueError
(
"
Invalid weight_decay value: {}
"
.
format
(
weight_decay
))
raise
ValueError
(
'
Invalid weight_decay value: {}
'
.
format
(
weight_decay
))
defaults
=
dict
(
lr
=
lr
,
betas
=
betas
,
eps
=
eps
,
weight_decay
=
weight_decay
,
amsgrad
=
amsgrad
)
super
(
AdamW2
,
self
).
__init__
(
params
,
defaults
)
...
...
@@ -109,7 +110,6 @@ class AdamW2(Optimizer):
if
amsgrad
:
max_exp_avg_sqs
.
append
(
state
[
'max_exp_avg_sq'
])
# update the steps for each param group update
state
[
'step'
]
+=
1
# record the step after step update
...
...
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/__init__.py
View file @
41b18fd8
from
.bricks
import
run_time
from
.grid_mask
import
GridMask
from
.position_embedding
import
RelPositionEmbedding
from
.visual
import
save_tensor
from
.positional_encoding
import
LearnedPositionalEncoding3D
from
.visual
import
save_tensor
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/bricks.py
View file @
41b18fd8
import
functools
import
time
from
collections
import
defaultdict
import
torch
time_maps
=
defaultdict
(
lambda
:
0.
)
count_maps
=
defaultdict
(
lambda
:
0.
)
time_maps
=
defaultdict
(
lambda
:
0.
)
count_maps
=
defaultdict
(
lambda
:
0.
)
def
run_time
(
name
):
def
middle
(
fn
):
def
wrapper
(
*
args
,
**
kwargs
):
...
...
@@ -11,10 +14,12 @@ def run_time(name):
start
=
time
.
time
()
res
=
fn
(
*
args
,
**
kwargs
)
torch
.
cuda
.
synchronize
()
time_maps
[
'%s : %s'
%
(
name
,
fn
.
__name__
)
]
+=
time
.
time
()
-
start
count_maps
[
'%s : %s'
%
(
name
,
fn
.
__name__
)
]
+=
1
print
(
"%s : %s takes up %f "
%
(
name
,
fn
.
__name__
,
time_maps
[
'%s : %s'
%
(
name
,
fn
.
__name__
)
]
/
count_maps
[
'%s : %s'
%
(
name
,
fn
.
__name__
)
]
))
time_maps
[
'%s : %s'
%
(
name
,
fn
.
__name__
)]
+=
time
.
time
()
-
start
count_maps
[
'%s : %s'
%
(
name
,
fn
.
__name__
)]
+=
1
print
(
'%s : %s takes up %f '
%
(
name
,
fn
.
__name__
,
time_maps
[
'%s : %s'
%
(
name
,
fn
.
__name__
)]
/
count_maps
[
'%s : %s'
%
(
name
,
fn
.
__name__
)]))
return
res
return
wrapper
return
middle
return
middle
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/grid_mask.py
View file @
41b18fd8
import
numpy
as
np
import
torch
import
torch.nn
as
nn
import
numpy
as
np
from
mmcv.runner
import
auto_fp16
from
PIL
import
Image
from
mmcv.runner
import
force_fp32
,
auto_fp16
class
Grid
(
object
):
def
__init__
(
self
,
use_h
,
use_w
,
rotate
=
1
,
offset
=
False
,
ratio
=
0.5
,
mode
=
0
,
prob
=
1.
):
def
__init__
(
self
,
use_h
,
use_w
,
rotate
=
1
,
offset
=
False
,
ratio
=
0.5
,
mode
=
0
,
prob
=
1.
):
self
.
use_h
=
use_h
self
.
use_w
=
use_w
self
.
rotate
=
rotate
self
.
offset
=
offset
self
.
ratio
=
ratio
self
.
mode
=
mode
self
.
mode
=
mode
self
.
st_prob
=
prob
self
.
prob
=
prob
...
...
@@ -25,40 +26,40 @@ class Grid(object):
w
=
img
.
size
(
2
)
self
.
d1
=
2
self
.
d2
=
min
(
h
,
w
)
hh
=
int
(
1.5
*
h
)
ww
=
int
(
1.5
*
w
)
hh
=
int
(
1.5
*
h
)
ww
=
int
(
1.5
*
w
)
d
=
np
.
random
.
randint
(
self
.
d1
,
self
.
d2
)
if
self
.
ratio
==
1
:
self
.
l
=
np
.
random
.
randint
(
1
,
d
)
else
:
self
.
l
=
min
(
max
(
int
(
d
*
self
.
ratio
+
0.5
),
1
),
d
-
1
)
self
.
l
=
min
(
max
(
int
(
d
*
self
.
ratio
+
0.5
),
1
),
d
-
1
)
mask
=
np
.
ones
((
hh
,
ww
),
np
.
float32
)
st_h
=
np
.
random
.
randint
(
d
)
st_w
=
np
.
random
.
randint
(
d
)
if
self
.
use_h
:
for
i
in
range
(
hh
//
d
):
s
=
d
*
i
+
st_h
t
=
min
(
s
+
self
.
l
,
hh
)
mask
[
s
:
t
,:]
*=
0
for
i
in
range
(
hh
//
d
):
s
=
d
*
i
+
st_h
t
=
min
(
s
+
self
.
l
,
hh
)
mask
[
s
:
t
,
:]
*=
0
if
self
.
use_w
:
for
i
in
range
(
ww
//
d
):
s
=
d
*
i
+
st_w
t
=
min
(
s
+
self
.
l
,
ww
)
mask
[:,
s
:
t
]
*=
0
for
i
in
range
(
ww
//
d
):
s
=
d
*
i
+
st_w
t
=
min
(
s
+
self
.
l
,
ww
)
mask
[:,
s
:
t
]
*=
0
r
=
np
.
random
.
randint
(
self
.
rotate
)
mask
=
Image
.
fromarray
(
np
.
uint8
(
mask
))
mask
=
mask
.
rotate
(
r
)
mask
=
np
.
asarray
(
mask
)
mask
=
mask
[(
hh
-
h
)
//
2
:(
hh
-
h
)
//
2
+
h
,
(
ww
-
w
)
//
2
:(
ww
-
w
)
//
2
+
w
]
mask
=
mask
[(
hh
-
h
)
//
2
:(
hh
-
h
)
//
2
+
h
,
(
ww
-
w
)
//
2
:(
ww
-
w
)
//
2
+
w
]
mask
=
torch
.
from_numpy
(
mask
).
float
()
if
self
.
mode
==
1
:
mask
=
1
-
mask
mask
=
1
-
mask
mask
=
mask
.
expand_as
(
img
)
if
self
.
offset
:
offset
=
torch
.
from_numpy
(
2
*
(
np
.
random
.
rand
(
h
,
w
)
-
0.5
)).
float
()
offset
=
torch
.
from_numpy
(
2
*
(
np
.
random
.
rand
(
h
,
w
)
-
0.5
)).
float
()
offset
=
(
1
-
mask
)
*
offset
img
=
img
*
mask
+
offset
else
:
...
...
@@ -68,7 +69,7 @@ class Grid(object):
class
GridMask
(
nn
.
Module
):
def
__init__
(
self
,
use_h
,
use_w
,
rotate
=
1
,
offset
=
False
,
ratio
=
0.5
,
mode
=
0
,
prob
=
1.
):
def
__init__
(
self
,
use_h
,
use_w
,
rotate
=
1
,
offset
=
False
,
ratio
=
0.5
,
mode
=
0
,
prob
=
1.
):
super
(
GridMask
,
self
).
__init__
()
self
.
use_h
=
use_h
self
.
use_w
=
use_w
...
...
@@ -79,46 +80,48 @@ class GridMask(nn.Module):
self
.
st_prob
=
prob
self
.
prob
=
prob
self
.
fp16_enable
=
False
def
set_prob
(
self
,
epoch
,
max_epoch
):
self
.
prob
=
self
.
st_prob
*
epoch
/
max_epoch
#+ 1.#0.5
self
.
prob
=
self
.
st_prob
*
epoch
/
max_epoch
# + 1.#0.5
@
auto_fp16
()
def
forward
(
self
,
x
):
if
np
.
random
.
rand
()
>
self
.
prob
or
not
self
.
training
:
return
x
n
,
c
,
h
,
w
=
x
.
size
()
x
=
x
.
view
(
-
1
,
h
,
w
)
hh
=
int
(
1.5
*
h
)
ww
=
int
(
1.5
*
w
)
n
,
c
,
h
,
w
=
x
.
size
()
x
=
x
.
view
(
-
1
,
h
,
w
)
hh
=
int
(
1.5
*
h
)
ww
=
int
(
1.5
*
w
)
d
=
np
.
random
.
randint
(
2
,
h
)
self
.
l
=
min
(
max
(
int
(
d
*
self
.
ratio
+
0.5
),
1
),
d
-
1
)
self
.
l
=
min
(
max
(
int
(
d
*
self
.
ratio
+
0.5
),
1
),
d
-
1
)
mask
=
np
.
ones
((
hh
,
ww
),
np
.
float32
)
st_h
=
np
.
random
.
randint
(
d
)
st_w
=
np
.
random
.
randint
(
d
)
if
self
.
use_h
:
for
i
in
range
(
hh
//
d
):
s
=
d
*
i
+
st_h
t
=
min
(
s
+
self
.
l
,
hh
)
mask
[
s
:
t
,:]
*=
0
for
i
in
range
(
hh
//
d
):
s
=
d
*
i
+
st_h
t
=
min
(
s
+
self
.
l
,
hh
)
mask
[
s
:
t
,
:]
*=
0
if
self
.
use_w
:
for
i
in
range
(
ww
//
d
):
s
=
d
*
i
+
st_w
t
=
min
(
s
+
self
.
l
,
ww
)
mask
[:,
s
:
t
]
*=
0
for
i
in
range
(
ww
//
d
):
s
=
d
*
i
+
st_w
t
=
min
(
s
+
self
.
l
,
ww
)
mask
[:,
s
:
t
]
*=
0
r
=
np
.
random
.
randint
(
self
.
rotate
)
mask
=
Image
.
fromarray
(
np
.
uint8
(
mask
))
mask
=
mask
.
rotate
(
r
)
mask
=
np
.
asarray
(
mask
)
mask
=
mask
[(
hh
-
h
)
//
2
:(
hh
-
h
)
//
2
+
h
,
(
ww
-
w
)
//
2
:(
ww
-
w
)
//
2
+
w
]
mask
=
mask
[(
hh
-
h
)
//
2
:(
hh
-
h
)
//
2
+
h
,
(
ww
-
w
)
//
2
:(
ww
-
w
)
//
2
+
w
]
mask
=
torch
.
from_numpy
(
mask
).
to
(
x
.
dtype
).
cuda
()
if
self
.
mode
==
1
:
mask
=
1
-
mask
mask
=
1
-
mask
mask
=
mask
.
expand_as
(
x
)
if
self
.
offset
:
offset
=
torch
.
from_numpy
(
2
*
(
np
.
random
.
rand
(
h
,
w
)
-
0.5
)).
to
(
x
.
dtype
).
cuda
()
offset
=
torch
.
from_numpy
(
2
*
(
np
.
random
.
rand
(
h
,
w
)
-
0.5
)).
to
(
x
.
dtype
).
cuda
()
x
=
x
*
mask
+
offset
*
(
1
-
mask
)
else
:
x
=
x
*
mask
return
x
.
view
(
n
,
c
,
h
,
w
)
\ No newline at end of file
return
x
.
view
(
n
,
c
,
h
,
w
)
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/position_embedding.py
View file @
41b18fd8
import
math
import
torch
import
torch.nn
as
nn
import
math
class
RelPositionEmbedding
(
nn
.
Module
):
def
__init__
(
self
,
num_pos_feats
=
64
,
pos_norm
=
True
):
super
().
__init__
()
self
.
num_pos_feats
=
num_pos_feats
self
.
fc
=
nn
.
Linear
(
4
,
self
.
num_pos_feats
,
bias
=
False
)
#nn.init.orthogonal_(self.fc.weight)
#self.fc.weight.requires_grad = False
self
.
fc
=
nn
.
Linear
(
4
,
self
.
num_pos_feats
,
bias
=
False
)
#
nn.init.orthogonal_(self.fc.weight)
#
self.fc.weight.requires_grad = False
self
.
pos_norm
=
pos_norm
if
self
.
pos_norm
:
self
.
norm
=
nn
.
LayerNorm
(
self
.
num_pos_feats
)
def
forward
(
self
,
tensor
):
#mask = nesttensor.mask
B
,
C
,
H
,
W
=
tensor
.
shape
#print('tensor.shape', tensor.shape)
#
mask = nesttensor.mask
B
,
C
,
H
,
W
=
tensor
.
shape
#
print('tensor.shape', tensor.shape)
y_range
=
(
torch
.
arange
(
H
)
/
float
(
H
-
1
)).
to
(
tensor
.
device
)
#y_axis = torch.stack((y_range, 1-y_range),dim=1)
#
y_axis = torch.stack((y_range, 1-y_range),dim=1)
y_axis
=
torch
.
stack
((
torch
.
cos
(
y_range
*
math
.
pi
),
torch
.
sin
(
y_range
*
math
.
pi
)),
dim
=
1
)
y_axis
=
y_axis
.
reshape
(
H
,
1
,
2
).
repeat
(
1
,
W
,
1
).
reshape
(
H
*
W
,
2
)
x_range
=
(
torch
.
arange
(
W
)
/
float
(
W
-
1
)).
to
(
tensor
.
device
)
#x_axis =torch.stack((x_range,1-x_range),dim=1)
#
x_axis =torch.stack((x_range,1-x_range),dim=1)
x_axis
=
torch
.
stack
((
torch
.
cos
(
x_range
*
math
.
pi
),
torch
.
sin
(
x_range
*
math
.
pi
)),
dim
=
1
)
x_axis
=
x_axis
.
reshape
(
1
,
W
,
2
).
repeat
(
H
,
1
,
1
).
reshape
(
H
*
W
,
2
)
x_pos
=
torch
.
cat
((
y_axis
,
x_axis
),
dim
=
1
)
...
...
@@ -30,5 +33,5 @@ class RelPositionEmbedding(nn.Module):
if
self
.
pos_norm
:
x_pos
=
self
.
norm
(
x_pos
)
#print('xpos,', x_pos.max(),x_pos.min())
#
print('xpos,', x_pos.max(),x_pos.min())
return
x_pos
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/positional_encoding.py
View file @
41b18fd8
import
math
import
torch
import
torch.nn
as
nn
from
mmcv.cnn.bricks.transformer
import
POSITIONAL_ENCODING
...
...
@@ -58,7 +56,8 @@ class LearnedPositionalEncoding3D(BaseModule):
pos
=
torch
.
cat
(
(
x_embed
.
unsqueeze
(
0
).
unsqueeze
(
0
).
repeat
(
l
,
h
,
1
,
1
),
y_embed
.
unsqueeze
(
1
).
unsqueeze
(
0
).
repeat
(
l
,
1
,
w
,
1
),
z_embed
.
unsqueeze
(
1
).
unsqueeze
(
1
).
repeat
(
1
,
h
,
w
,
1
)),
dim
=-
1
).
permute
(
3
,
0
,
1
,
2
).
unsqueeze
(
0
).
repeat
(
mask
.
shape
[
0
],
1
,
1
,
1
,
1
)
z_embed
.
unsqueeze
(
1
).
unsqueeze
(
1
).
repeat
(
1
,
h
,
w
,
1
)),
dim
=-
1
).
permute
(
3
,
0
,
1
,
2
).
unsqueeze
(
0
).
repeat
(
mask
.
shape
[
0
],
1
,
1
,
1
,
1
)
return
pos
def
__repr__
(
self
):
...
...
autonomous_driving/occupancy_prediction/projects/mmdet3d_plugin/models/utils/visual.py
View file @
41b18fd8
import
cv2
import
matplotlib.pyplot
as
plt
import
torch
from
torchvision.utils
import
make_grid
import
torchvision
import
matplotlib.pyplot
as
plt
import
cv2
from
torchvision.utils
import
make_grid
def
convert_color
(
img_path
):
...
...
@@ -12,11 +12,11 @@ def convert_color(img_path):
plt
.
close
()
def
save_tensor
(
tensor
,
path
,
pad_value
=
254.0
,):
def
save_tensor
(
tensor
,
path
,
pad_value
=
254.0
,
):
print
(
'save_tensor'
,
path
)
tensor
=
tensor
.
to
(
torch
.
float
).
detach
().
cpu
()
if
tensor
.
type
()
==
'torch.BoolTensor'
:
tensor
=
tensor
*
255
tensor
=
tensor
*
255
if
len
(
tensor
.
shape
)
==
3
:
tensor
=
tensor
.
unsqueeze
(
1
)
tensor
=
make_grid
(
tensor
,
pad_value
=
pad_value
,
normalize
=
False
).
permute
(
1
,
2
,
0
).
numpy
().
copy
()
...
...
autonomous_driving/occupancy_prediction/tools/.ipynb_checkpoints/train-checkpoint.py
View file @
41b18fd8
...
...
@@ -8,26 +8,25 @@ from __future__ import division
import
argparse
import
copy
import
mmcv
import
os
import
time
import
torch
import
warnings
from
mmcv
import
Config
,
DictAction
from
mmcv.runner
import
get_dist_info
,
init_dist
from
os
import
path
as
osp
import
mmcv
import
torch
from
mmcv
import
Config
,
DictAction
from
mmcv.runner
import
get_dist_info
,
init_dist
from
mmcv.utils
import
TORCH_VERSION
,
digit_version
from
mmdet
import
__version__
as
mmdet_version
from
mmdet3d
import
__version__
as
mmdet3d_version
#from mmdet3d.apis import train_model
from
mmdet3d.datasets
import
build_dataset
from
mmdet3d.models
import
build_model
from
mmdet3d.utils
import
collect_env
,
get_root_logger
from
mmdet.apis
import
set_random_seed
from
mmseg
import
__version__
as
mmseg_version
from
mm
cv.utils
import
TORCH_VERSION
,
digit_version
#
from mm
det3d.apis import train_model
def
parse_args
():
...
...
@@ -134,7 +133,8 @@ def main():
print
(
_module_path
)
plg_lib
=
importlib
.
import_module
(
_module_path
)
from
projects.mmdet3d_plugin.bevformer.apis.train
import
custom_train_model
from
projects.mmdet3d_plugin.bevformer.apis.train
import
\
custom_train_model
# set cudnn_benchmark
if
cfg
.
get
(
'cudnn_benchmark'
,
False
):
torch
.
backends
.
cudnn
.
benchmark
=
True
...
...
autonomous_driving/occupancy_prediction/tools/analysis_tools/analyze_logs.py
View file @
41b18fd8
# Copyright (c) OpenMMLab. All rights reserved.
import
argparse
import
json
from
collections
import
defaultdict
import
numpy
as
np
import
seaborn
as
sns
from
collections
import
defaultdict
from
matplotlib
import
pyplot
as
plt
...
...
@@ -85,7 +86,7 @@ def plot_curve(log_dicts, args):
xs
=
[]
ys
=
[]
num_iters_per_epoch
=
\
log_dict
[
epochs
[
args
.
interval
-
1
]][
'iter'
][
-
1
]
log_dict
[
epochs
[
args
.
interval
-
1
]][
'iter'
][
-
1
]
for
epoch
in
epochs
[
args
.
interval
-
1
::
args
.
interval
]:
iters
=
log_dict
[
epoch
][
'iter'
]
if
log_dict
[
epoch
][
'mode'
][
-
1
]
==
'val'
:
...
...
autonomous_driving/occupancy_prediction/tools/analysis_tools/benchmark.py
View file @
41b18fd8
# Copyright (c) OpenMMLab. All rights reserved.
import
argparse
import
sys
import
time
import
torch
from
mmcv
import
Config
from
mmcv.parallel
import
MMDataParallel
from
mmcv.runner
import
load_checkpoint
,
wrap_fp16_model
import
sys
sys
.
path
.
append
(
'.'
)
from
projects.mmdet3d_plugin.datasets.builder
import
build_dataloader
from
projects.mmdet3d_plugin.datasets
import
custom_build_dataset
# from mmdet3d.datasets import build_dataloader, build_dataset
from
mmdet3d.models
import
build_detector
#from tools.misc.fuse_conv_bn import fuse_module
from
projects.mmdet3d_plugin.datasets
import
custom_build_dataset
from
projects.mmdet3d_plugin.datasets.builder
import
build_dataloader
# from tools.misc.fuse_conv_bn import fuse_module
def
parse_args
():
...
...
@@ -59,7 +62,7 @@ def main():
wrap_fp16_model
(
model
)
if
args
.
checkpoint
is
not
None
:
load_checkpoint
(
model
,
args
.
checkpoint
,
map_location
=
'cpu'
)
#if args.fuse_conv_bn:
#
if args.fuse_conv_bn:
# model = fuse_module(model)
model
=
MMDataParallel
(
model
,
device_ids
=
[
0
])
...
...
autonomous_driving/occupancy_prediction/tools/analysis_tools/get_params.py
View file @
41b18fd8
import
torch
file_path
=
'./ckpts/bevformer_v4.pth'
model
=
torch
.
load
(
file_path
,
map_location
=
'cpu'
)
all
=
0
...
...
autonomous_driving/occupancy_prediction/tools/analysis_tools/visual.py
View file @
41b18fd8
...
...
@@ -4,30 +4,15 @@
# ---------------------------------------------
import
mmcv
from
nuscenes.eval.common.data_classes
import
EvalBoxes
from
nuscenes.eval.detection.data_classes
import
DetectionBox
from
nuscenes.eval.detection.render
import
visualize_sample
from
nuscenes.eval.detection.utils
import
category_to_detection_name
from
nuscenes.nuscenes
import
NuScenes
from
nuscenes.utils.geometry_utils
import
(
BoxVisibility
,
box_in_image
,
view_points
)
from
PIL
import
Image
from
nuscenes.utils.geometry_utils
import
view_points
,
box_in_image
,
BoxVisibility
,
transform_matrix
from
typing
import
Tuple
,
List
,
Iterable
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
PIL
import
Image
from
matplotlib
import
rcParams
from
matplotlib.axes
import
Axes
from
pyquaternion
import
Quaternion
from
PIL
import
Image
from
matplotlib
import
rcParams
from
matplotlib.axes
import
Axes
from
pyquaternion
import
Quaternion
from
tqdm
import
tqdm
from
nuscenes.utils.data_classes
import
LidarPointCloud
,
RadarPointCloud
,
Box
from
nuscenes.utils.geometry_utils
import
view_points
,
box_in_image
,
BoxVisibility
,
transform_matrix
from
nuscenes.eval.common.data_classes
import
EvalBoxes
,
EvalBox
from
nuscenes.eval.detection.data_classes
import
DetectionBox
from
nuscenes.eval.detection.utils
import
category_to_detection_name
from
nuscenes.eval.detection.render
import
visualize_sample
cams
=
[
'CAM_FRONT'
,
'CAM_FRONT_RIGHT'
,
...
...
@@ -36,11 +21,11 @@ cams = ['CAM_FRONT',
'CAM_BACK_LEFT'
,
'CAM_FRONT_LEFT'
]
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
nuscenes.utils.data_classes
import
LidarPointCloud
,
RadarPointCloud
,
Box
from
PIL
import
Image
import
numpy
as
np
from
matplotlib
import
rcParams
from
nuscenes.utils.data_classes
import
Box
,
LidarPointCloud
from
PIL
import
Image
def
render_annotation
(
...
...
@@ -143,7 +128,6 @@ def render_annotation(
plt
.
savefig
(
out_path
)
def
get_sample_data
(
sample_data_token
:
str
,
box_vis_level
:
BoxVisibility
=
BoxVisibility
.
ANY
,
selected_anntokens
=
None
,
...
...
@@ -206,7 +190,6 @@ def get_sample_data(sample_data_token: str,
return
data_path
,
box_list
,
cam_intrinsic
def
get_predicted_data
(
sample_data_token
:
str
,
box_vis_level
:
BoxVisibility
=
BoxVisibility
.
ANY
,
selected_anntokens
=
None
,
...
...
@@ -270,9 +253,7 @@ def get_predicted_data(sample_data_token: str,
return
data_path
,
box_list
,
cam_intrinsic
def
lidiar_render
(
sample_token
,
data
,
out_path
=
None
):
def
lidiar_render
(
sample_token
,
data
,
out_path
=
None
):
bbox_gt_list
=
[]
bbox_pred_list
=
[]
anns
=
nusc
.
get
(
'sample'
,
sample_token
)[
'anns'
]
...
...
@@ -314,7 +295,7 @@ def lidiar_render(sample_token, data,out_path=None):
pred_annotations
.
add_boxes
(
sample_token
,
bbox_pred_list
)
print
(
'green is ground truth'
)
print
(
'blue is the predited result'
)
visualize_sample
(
nusc
,
sample_token
,
gt_annotations
,
pred_annotations
,
savepath
=
out_path
+
'_bev'
)
visualize_sample
(
nusc
,
sample_token
,
gt_annotations
,
pred_annotations
,
savepath
=
out_path
+
'_bev'
)
def
get_color
(
category_name
:
str
):
...
...
@@ -325,7 +306,8 @@ def get_color(category_name: str):
a
=
[
'noise'
,
'animal'
,
'human.pedestrian.adult'
,
'human.pedestrian.child'
,
'human.pedestrian.construction_worker'
,
'human.pedestrian.personal_mobility'
,
'human.pedestrian.police_officer'
,
'human.pedestrian.stroller'
,
'human.pedestrian.wheelchair'
,
'movable_object.barrier'
,
'movable_object.debris'
,
'movable_object.pushable_pullable'
,
'movable_object.trafficcone'
,
'static_object.bicycle_rack'
,
'vehicle.bicycle'
,
'movable_object.pushable_pullable'
,
'movable_object.trafficcone'
,
'static_object.bicycle_rack'
,
'vehicle.bicycle'
,
'vehicle.bus.bendy'
,
'vehicle.bus.rigid'
,
'vehicle.car'
,
'vehicle.construction'
,
'vehicle.emergency.ambulance'
,
'vehicle.emergency.police'
,
'vehicle.motorcycle'
,
'vehicle.trailer'
,
'vehicle.truck'
,
'flat.driveable_surface'
,
'flat.other'
,
'flat.sidewalk'
,
'flat.terrain'
,
'static.manmade'
,
'static.other'
,
'static.vegetation'
,
...
...
@@ -334,7 +316,7 @@ def get_color(category_name: str):
'car'
,
'truck'
,
'construction_vehicle'
,
'bus'
,
'trailer'
,
'barrier'
,
'motorcycle'
,
'bicycle'
,
'pedestrian'
,
'traffic_cone'
]
#print(category_name)
#
print(category_name)
if
category_name
==
'bicycle'
:
return
nusc
.
colormap
[
'vehicle.bicycle'
]
elif
category_name
==
'construction_vehicle'
:
...
...
@@ -365,7 +347,7 @@ def render_sample_data(
verbose
:
bool
=
True
,
show_panoptic
:
bool
=
False
,
pred_data
=
None
,
)
->
None
:
)
->
None
:
"""
Render sample data onto axis.
:param sample_data_token: Sample_data token.
...
...
@@ -450,7 +432,7 @@ def render_sample_data(
ax
[
j
+
2
,
ind
].
set_ylim
(
data
.
size
[
1
],
0
)
else
:
raise
ValueError
(
"
Error: Unknown sensor modality!
"
)
raise
ValueError
(
'
Error: Unknown sensor modality!
'
)
ax
[
j
,
ind
].
axis
(
'off'
)
ax
[
j
,
ind
].
set_title
(
'PRED: {} {labels_type}'
.
format
(
...
...
@@ -463,11 +445,12 @@ def render_sample_data(
ax
[
j
+
2
,
ind
].
set_aspect
(
'equal'
)
if
out_path
is
not
None
:
plt
.
savefig
(
out_path
+
'_camera'
,
bbox_inches
=
'tight'
,
pad_inches
=
0
,
dpi
=
200
)
plt
.
savefig
(
out_path
+
'_camera'
,
bbox_inches
=
'tight'
,
pad_inches
=
0
,
dpi
=
200
)
if
verbose
:
plt
.
show
()
plt
.
close
()
if
__name__
==
'__main__'
:
nusc
=
NuScenes
(
version
=
'v1.0-trainval'
,
dataroot
=
'./data/nuscenes'
,
verbose
=
True
)
# render_annotation('7603b030b42a4b1caa8c443ccc1a7d52')
...
...
Prev
1
…
3
4
5
6
7
8
9
10
11
…
20
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