Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
one
spconv
Commits
bf473de0
Commit
bf473de0
authored
May 22, 2020
by
Yan Yan
Browse files
1. change indicePairs layout to [2, KV, num]
2. working on batch indice conv
parent
6c767a51
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
12 deletions
+78
-12
test/test_conv.py
test/test_conv.py
+78
-12
No files found.
test/test_conv.py
View file @
bf473de0
...
@@ -38,7 +38,7 @@ class SparseConv3dTestTorch(nn.Module):
...
@@ -38,7 +38,7 @@ class SparseConv3dTestTorch(nn.Module):
padding
=
padding
,
padding
=
padding
,
dilation
=
dilation
,
dilation
=
dilation
,
bias
=
False
,
bias
=
False
,
use_hash
=
Tru
e
)
use_hash
=
Fals
e
)
]
]
for
i
in
range
(
1
,
num_layers
):
for
i
in
range
(
1
,
num_layers
):
layers
.
append
(
layers
.
append
(
...
@@ -48,7 +48,8 @@ class SparseConv3dTestTorch(nn.Module):
...
@@ -48,7 +48,8 @@ class SparseConv3dTestTorch(nn.Module):
stride
,
stride
,
padding
=
padding
,
padding
=
padding
,
dilation
=
dilation
,
dilation
=
dilation
,
bias
=
False
))
bias
=
False
,
use_hash
=
False
))
self
.
net
=
spconv
.
SparseSequential
(
*
layers
,
)
self
.
net
=
spconv
.
SparseSequential
(
*
layers
,
)
# self.grid = torch.full([3, *shape], -1, dtype=torch.int32).cuda()
# self.grid = torch.full([3, *shape], -1, dtype=torch.int32).cuda()
self
.
grid
=
None
self
.
grid
=
None
...
@@ -84,7 +85,8 @@ class SubMConv3dTestTorch(nn.Module):
...
@@ -84,7 +85,8 @@ class SubMConv3dTestTorch(nn.Module):
dilation
=
dilation
,
dilation
=
dilation
,
bias
=
False
))
bias
=
False
))
self
.
net
=
spconv
.
SparseSequential
(
*
layers
,
)
self
.
net
=
spconv
.
SparseSequential
(
*
layers
,
)
self
.
grid
=
torch
.
full
([
3
,
*
shape
],
-
1
,
dtype
=
torch
.
int32
).
cuda
()
# self.grid = torch.full([3, *shape], -1, dtype=torch.int32).cuda()
self
.
grid
=
None
self
.
shape
=
shape
self
.
shape
=
shape
def
forward
(
self
,
features
,
coors
,
batch_size
):
def
forward
(
self
,
features
,
coors
,
batch_size
):
...
@@ -325,7 +327,7 @@ def scatter_nd(indices, updates, shape):
...
@@ -325,7 +327,7 @@ def scatter_nd(indices, updates, shape):
class
TestSpConv
(
TestCase
):
class
TestSpConv
(
TestCase
):
def
testSpConv3d
(
self
):
def
testSpConv3d
(
self
):
np
.
random
.
seed
(
484
)
np
.
random
.
seed
(
484
)
devices
=
[
"cpu:0"
]
devices
=
[
"cuda:0"
,
"cpu:0"
]
shapes
=
[[
19
,
18
,
17
]]
shapes
=
[[
19
,
18
,
17
]]
batchsizes
=
[
1
,
2
]
batchsizes
=
[
1
,
2
]
...
@@ -523,12 +525,12 @@ class TestSpConv(TestCase):
...
@@ -523,12 +525,12 @@ class TestSpConv(TestCase):
def
testSpMaxPool3d
(
self
):
def
testSpMaxPool3d
(
self
):
np
.
random
.
seed
(
485
)
np
.
random
.
seed
(
485
)
devices
=
[
"cuda:0"
,
"cpu:0"
]
devices
=
[
"cuda:0"
]
shapes
=
[[
19
,
18
,
17
]]
shapes
=
[[
19
,
18
,
17
]]
batchsizes
=
[
1
,
2
]
batchsizes
=
[
1
,
2
]
in_channels
=
[
6
4
]
in_channels
=
[
6
2
]
out_channels
=
[
6
4
]
out_channels
=
[
6
2
]
ksizes
=
[
2
,
3
]
ksizes
=
[
2
,
3
]
strides
=
[
1
,
2
,
3
]
strides
=
[
1
,
2
,
3
]
paddings
=
[
0
,
1
]
paddings
=
[
0
,
1
]
...
@@ -566,6 +568,7 @@ class TestSpConv(TestCase):
...
@@ -566,6 +568,7 @@ class TestSpConv(TestCase):
out
=
net
(
features_t
,
indices_t
,
bs
)
out
=
net
(
features_t
,
indices_t
,
bs
)
outids
=
out
.
indices
outids
=
out
.
indices
outfeatures
=
out
.
features
outfeatures
=
out
.
features
outids_dev
=
outids
.
float
()
out_dense
=
out
.
dense
(
channels_first
=
False
)
out_dense
=
out
.
dense
(
channels_first
=
False
)
out
=
out_dense
.
permute
(
0
,
4
,
1
,
2
,
3
).
contiguous
()
out
=
out_dense
.
permute
(
0
,
4
,
1
,
2
,
3
).
contiguous
()
...
@@ -581,13 +584,13 @@ class TestSpConv(TestCase):
...
@@ -581,13 +584,13 @@ class TestSpConv(TestCase):
1
).
contiguous
()
1
).
contiguous
()
din_sparse
=
gather_nd
(
din_dense
,
indices_t
.
long
())
din_sparse
=
gather_nd
(
din_dense
,
indices_t
.
long
())
din
=
features_t
.
grad
.
detach
()
din
=
features_t
.
grad
.
detach
()
din_np
=
din
.
cpu
().
numpy
()
din_sparse_np
=
din_sparse
.
cpu
().
numpy
()
self
.
assertAllClose
(
din_np
,
din_sparse_np
,
atol
=
1e-4
)
out_np
=
out
.
detach
().
cpu
().
numpy
()
out_np
=
out
.
detach
().
cpu
().
numpy
()
out_ref_np
=
out_ref
.
detach
().
cpu
().
numpy
()
out_ref_np
=
out_ref
.
detach
().
cpu
().
numpy
()
self
.
assertAllClose
(
out_np
,
out_ref_np
,
atol
=
1e-4
)
self
.
assertAllClose
(
out_np
,
out_ref_np
,
atol
=
1e-4
)
din_np
=
din
.
cpu
().
numpy
()
din_sparse_np
=
din_sparse
.
cpu
().
numpy
()
self
.
assertAllClose
(
din_np
,
din_sparse_np
,
atol
=
1e-4
)
def
main
():
def
main
():
...
@@ -653,7 +656,70 @@ def main():
...
@@ -653,7 +656,70 @@ def main():
out_ref
.
detach
().
cpu
().
numpy
()))
out_ref
.
detach
().
cpu
().
numpy
()))
def
main_subm
():
# function for develop.
np
.
random
.
seed
(
484
)
# devices = ["cuda:0"]
devices
=
[
"cuda:0"
]
shapes
=
[[
50
,
30
,
30
]]
batchsizes
=
[
2
]
in_channels
=
[
32
]
out_channels
=
[
64
]
ksizes
=
[(
3
,
3
,
3
)]
strides
=
[
1
]
paddings
=
[
1
]
dilations
=
[
1
]
for
dev
,
shape
,
bs
,
IC
,
OC
,
k
,
s
,
p
,
d
in
params_grid
(
devices
,
shapes
,
batchsizes
,
in_channels
,
out_channels
,
ksizes
,
strides
,
paddings
,
dilations
):
if
all
([
s
>
1
,
d
>
1
]):
continue
device
=
torch
.
device
(
dev
)
num_points
=
[
500
]
*
bs
sparse_dict
=
generate_sparse_data
(
shape
,
num_points
,
IC
)
features
=
np
.
ascontiguousarray
(
sparse_dict
[
"features"
]).
astype
(
np
.
float32
)
indices
=
np
.
ascontiguousarray
(
sparse_dict
[
"indices"
][:,
[
3
,
0
,
1
,
2
]]).
astype
(
np
.
int32
)
features_dense
=
sparse_dict
[
"features_dense"
].
astype
(
np
.
float32
)
indices_t
=
torch
.
from_numpy
(
indices
)
filters
=
np
.
random
.
uniform
(
0
,
1
,
size
=
[
k
[
0
],
1
,
1
,
IC
,
OC
]).
astype
(
np
.
float32
)
indices_t
=
torch
.
from_numpy
(
indices
).
int
().
to
(
device
).
float
()
features_t
=
torch
.
from_numpy
(
features
).
to
(
device
).
float
()
features_dense_t
=
torch
.
from_numpy
(
features_dense
).
to
(
device
).
float
()
net
=
SubMConv3dTestTorch
(
1
,
3
,
shape
,
IC
,
OC
,
k
,
s
,
p
,
d
).
to
(
device
).
float
()
net_ref
=
Conv3dTestTorch
(
1
,
3
,
shape
,
IC
,
OC
,
k
,
s
,
p
,
d
).
to
(
device
).
float
()
filters_t
=
torch
.
from_numpy
(
filters
).
to
(
device
).
float
()
net_ref
.
net
[
0
].
weight
[:]
=
filters_t
.
permute
(
4
,
3
,
0
,
1
,
2
).
contiguous
()
net
.
net
[
0
].
weight
[:]
=
filters_t
out_ref
=
net_ref
(
features_dense_t
)
times
=
[]
for
i
in
range
(
100
):
t
=
time
.
time
()
out
=
net
(
features_t
,
indices_t
,
bs
)
torch
.
cuda
.
synchronize
()
times
.
append
(
time
.
time
()
-
t
)
# print((net.grid == -1).float().sum(), net.grid.numel())
# print("spconv time", time.time() - t)
print
(
"spconv time"
,
np
.
mean
(
times
[
10
:]))
out
=
net
(
features_t
,
indices_t
,
bs
)
# print(out.indices)
out
=
out
.
dense
()
print
(
np
.
linalg
.
norm
(
out
.
detach
().
cpu
().
numpy
()
-
out_ref
.
detach
().
cpu
().
numpy
()))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
#
main()
main
_subm
()
# unittest.main()
# unittest.main()
TestSpConv
().
testSp
De
Conv3d
()
#
TestSpConv().testSpConv3d()
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