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
c66197c7
Commit
c66197c7
authored
Jul 17, 2022
by
ZCMax
Committed by
ChaimZhu
Jul 20, 2022
Browse files
[Refactor] 3D Segmentor and EncoderDecoder3D
parent
522cc20d
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
0 deletions
+132
-0
tests/test_models/test_decode_heads/test_paconv_head.py
tests/test_models/test_decode_heads/test_paconv_head.py
+66
-0
tests/test_models/test_decode_heads/test_pointnet2_head.py
tests/test_models/test_decode_heads/test_pointnet2_head.py
+66
-0
No files found.
tests/test_models/test_decode_heads/test_paconv_head.py
0 → 100644
View file @
c66197c7
# Copyright (c) OpenMMLab. All rights reserved.
from
unittest
import
TestCase
import
torch
from
mmdet3d.core
import
Det3DDataSample
,
PointData
from
mmdet3d.models.decode_heads
import
PAConvHead
class
TestPAConvHead
(
TestCase
):
def
test_paconv_head_loss
(
self
):
"""Tests PAConv head loss."""
paconv_head
=
PAConvHead
(
fp_channels
=
((
768
,
256
,
256
),
(
384
,
256
,
256
),
(
320
,
256
,
128
),
(
128
+
6
,
128
,
128
,
128
)),
channels
=
128
,
num_classes
=
20
,
dropout_ratio
=
0.5
,
conv_cfg
=
dict
(
type
=
'Conv1d'
),
norm_cfg
=
dict
(
type
=
'BN1d'
),
act_cfg
=
dict
(
type
=
'ReLU'
),
loss_decode
=
dict
(
type
=
'mmdet.CrossEntropyLoss'
,
use_sigmoid
=
False
,
class_weight
=
None
,
loss_weight
=
1.0
),
ignore_index
=
20
)
# PAConv head expects dict format features
sa_xyz
=
[
torch
.
rand
(
1
,
4096
,
3
).
float
(),
torch
.
rand
(
1
,
1024
,
3
).
float
(),
torch
.
rand
(
1
,
256
,
3
).
float
(),
torch
.
rand
(
1
,
64
,
3
).
float
(),
torch
.
rand
(
1
,
16
,
3
).
float
(),
]
sa_features
=
[
torch
.
rand
(
1
,
6
,
4096
).
float
(),
torch
.
rand
(
1
,
64
,
1024
).
float
(),
torch
.
rand
(
1
,
128
,
256
).
float
(),
torch
.
rand
(
1
,
256
,
64
).
float
(),
torch
.
rand
(
1
,
512
,
16
).
float
(),
]
feat_dict
=
dict
(
sa_xyz
=
sa_xyz
,
sa_features
=
sa_features
)
# Test forward
seg_logits
=
paconv_head
.
forward
(
feat_dict
)
self
.
assertEqual
(
seg_logits
,
torch
.
Size
([
1
,
20
,
4096
]))
# When truth is non-empty then losses
# should be nonzero for random inputs
pts_semantic_mask
=
torch
.
randint
(
0
,
20
,
(
4096
)).
long
()
gt_pts_seg
=
PointData
(
pts_semantic_mask
=
pts_semantic_mask
)
datasample
=
Det3DDataSample
()
datasample
.
gt_pts_seg
=
gt_pts_seg
gt_losses
=
paconv_head
.
loss
(
seg_logits
,
[
datasample
])
gt_sem_seg_loss
=
gt_losses
[
'loss_sem_seg'
].
item
()
self
.
assertGreater
(
gt_sem_seg_loss
,
0
,
'semantic seg loss should be positive'
)
tests/test_models/test_decode_heads/test_pointnet2_head.py
0 → 100644
View file @
c66197c7
# Copyright (c) OpenMMLab. All rights reserved.
from
unittest
import
TestCase
import
torch
from
mmdet3d.core
import
Det3DDataSample
,
PointData
from
mmdet3d.models.decode_heads
import
PointNet2Head
class
TestPointNet2Head
(
TestCase
):
def
test_paconv_head_loss
(
self
):
"""Tests PAConv head loss."""
pointnet2_head
=
PointNet2Head
(
fp_channels
=
((
768
,
256
,
256
),
(
384
,
256
,
256
),
(
320
,
256
,
128
),
(
128
,
128
,
128
,
128
)),
channels
=
128
,
num_classes
=
20
,
dropout_ratio
=
0.5
,
conv_cfg
=
dict
(
type
=
'Conv1d'
),
norm_cfg
=
dict
(
type
=
'BN1d'
),
act_cfg
=
dict
(
type
=
'ReLU'
),
loss_decode
=
dict
(
type
=
'mmdet.CrossEntropyLoss'
,
use_sigmoid
=
False
,
class_weight
=
None
,
loss_weight
=
1.0
),
ignore_index
=
20
)
# DGCNN head expects dict format features
sa_xyz
=
[
torch
.
rand
(
1
,
4096
,
3
).
float
(),
torch
.
rand
(
1
,
1024
,
3
).
float
(),
torch
.
rand
(
1
,
256
,
3
).
float
(),
torch
.
rand
(
1
,
64
,
3
).
float
(),
torch
.
rand
(
1
,
16
,
3
).
float
(),
]
sa_features
=
[
torch
.
rand
(
1
,
6
,
4096
).
float
(),
torch
.
rand
(
1
,
64
,
1024
).
float
(),
torch
.
rand
(
1
,
128
,
256
).
float
(),
torch
.
rand
(
1
,
256
,
64
).
float
(),
torch
.
rand
(
1
,
512
,
16
).
float
(),
]
feat_dict
=
dict
(
sa_xyz
=
sa_xyz
,
sa_features
=
sa_features
)
# Test forward
seg_logits
=
pointnet2_head
.
forward
(
feat_dict
)
self
.
assertEqual
(
seg_logits
,
torch
.
Size
([
1
,
20
,
4096
]))
# When truth is non-empty then losses
# should be nonzero for random inputs
pts_semantic_mask
=
torch
.
randint
(
0
,
20
,
(
4096
)).
long
()
gt_pts_seg
=
PointData
(
pts_semantic_mask
=
pts_semantic_mask
)
datasample
=
Det3DDataSample
()
datasample
.
gt_pts_seg
=
gt_pts_seg
gt_losses
=
pointnet2_head
.
loss
(
seg_logits
,
[
datasample
])
gt_sem_seg_loss
=
gt_losses
[
'loss_sem_seg'
].
item
()
self
.
assertGreater
(
gt_sem_seg_loss
,
0
,
'semantic seg loss should be positive'
)
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