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
torch-spline-conv
Commits
5ed79df4
"vscode:/vscode.git/clone" did not exist on "5f87abc2695e84671b2296b194a11aece874fdb9"
Commit
5ed79df4
authored
Feb 14, 2018
by
Jan Eric Lenssen
Browse files
deeper shapenet architecture
parent
c252df3a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
1 deletion
+22
-1
spline_conv.py
spline_conv.py
+22
-1
No files found.
spline_conv.py
View file @
5ed79df4
import
torch
import
torch
from
torch.autograd
import
Variable
from
torch.autograd
import
Variable
import
time
from
.spline
import
spline
from
.spline
import
spline
...
@@ -18,7 +19,7 @@ def spline_conv(
...
@@ -18,7 +19,7 @@ def spline_conv(
basis_kernel
,
basis_kernel
,
degree
=
1
,
degree
=
1
,
bias
=
None
,):
bias
=
None
,):
t_forward
=
time
.
process_time
()
if
input
.
dim
()
==
1
:
if
input
.
dim
()
==
1
:
input
=
input
.
unsqueeze
(
1
)
input
=
input
.
unsqueeze
(
1
)
...
@@ -26,29 +27,49 @@ def spline_conv(
...
@@ -26,29 +27,49 @@ def spline_conv(
row
,
col
=
adj
.
_indices
()
row
,
col
=
adj
.
_indices
()
# Get features for every end vertex with shape [|E| x M_in].
# Get features for every end vertex with shape [|E| x M_in].
t_gather
=
time
.
process_time
()
output
=
input
[
col
]
output
=
input
[
col
]
t_gather
=
time
.
process_time
()
-
t_gather
# Convert to [|E| x M_in] feature matrix and calculate [|E| x M_out].
# Convert to [|E| x M_in] feature matrix and calculate [|E| x M_out].
t_basis
=
time
.
process_time
()
amount
,
index
=
spline
(
values
,
kernel_size
,
is_open_spline
,
K
,
degree
,
basis_kernel
)
amount
,
index
=
spline
(
values
,
kernel_size
,
is_open_spline
,
K
,
degree
,
basis_kernel
)
t_basis
=
time
.
process_time
()
-
t_basis
t_conv
=
time
.
process_time
()
output
=
edgewise_spline_weighting
(
output
,
weight
[:
-
1
],
amount
,
index
,
forward_kernel
,
backward_kernel
)
output
=
edgewise_spline_weighting
(
output
,
weight
[:
-
1
],
amount
,
index
,
forward_kernel
,
backward_kernel
)
t_conv
=
time
.
process_time
()
-
t_conv
print
(
't_gather'
,
t_gather
,
'time_basis:'
,
t_basis
,
'time_conv:'
,
t_conv
)
# Convolution via `scatter_add`. Converts [|E| x M_out] feature matrix to
# Convolution via `scatter_add`. Converts [|E| x M_out] feature matrix to
# [n x M_out] feature matrix.
# [n x M_out] feature matrix.
t_scatter_add
=
time
.
process_time
()
zero
=
output
.
data
.
new
(
adj
.
size
(
1
),
output
.
size
(
1
)).
fill_
(
0.0
)
zero
=
output
.
data
.
new
(
adj
.
size
(
1
),
output
.
size
(
1
)).
fill_
(
0.0
)
zero
=
Variable
(
zero
)
if
not
torch
.
is_tensor
(
output
)
else
zero
zero
=
Variable
(
zero
)
if
not
torch
.
is_tensor
(
output
)
else
zero
r
=
row
.
view
(
-
1
,
1
).
expand
(
row
.
size
(
0
),
output
.
size
(
1
))
r
=
row
.
view
(
-
1
,
1
).
expand
(
row
.
size
(
0
),
output
.
size
(
1
))
output
=
zero
.
scatter_add_
(
0
,
Variable
(
r
),
output
)
output
=
zero
.
scatter_add_
(
0
,
Variable
(
r
),
output
)
t_scatter_add
=
time
.
process_time
()
-
t_scatter_add
# Weighten root node features by multiplying with root weight.
# Weighten root node features by multiplying with root weight.
t_root_weight
=
time
.
process_time
()
output
+=
torch
.
mm
(
input
,
weight
[
-
1
])
output
+=
torch
.
mm
(
input
,
weight
[
-
1
])
t_root_weight
=
time
.
process_time
()
-
t_root_weight
# Normalize output by degree.
# Normalize output by degree.
t_normalize
=
time
.
process_time
()
ones
=
values
.
new
(
values
.
size
(
0
)).
fill_
(
1
)
ones
=
values
.
new
(
values
.
size
(
0
)).
fill_
(
1
)
zero
=
values
.
new
(
output
.
size
(
0
)).
fill_
(
0
)
zero
=
values
.
new
(
output
.
size
(
0
)).
fill_
(
0
)
degree
=
zero
.
scatter_add_
(
0
,
row
,
ones
)
degree
=
zero
.
scatter_add_
(
0
,
row
,
ones
)
degree
=
torch
.
clamp
(
degree
,
min
=
1
)
degree
=
torch
.
clamp
(
degree
,
min
=
1
)
output
=
output
/
Variable
(
degree
.
view
(
-
1
,
1
))
output
=
output
/
Variable
(
degree
.
view
(
-
1
,
1
))
t_normalize
=
time
.
process_time
()
-
t_normalize
print
(
't_scatter_add:'
,
t_scatter_add
,
't_root_weight:'
,
t_root_weight
,
't_normalize:'
,
t_normalize
)
if
bias
is
not
None
:
if
bias
is
not
None
:
output
+=
bias
output
+=
bias
t_forward
=
time
.
process_time
()
-
t_forward
print
(
't_forward'
,
t_forward
)
return
output
return
output
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