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
Stephan Seitz
pystencil_reco
Commits
cb5df5e1
Commit
cb5df5e1
authored
Apr 23, 2020
by
Stephan Seitz
Browse files
Commit random stuff that I wrote months ago
parent
a59323a1
Pipeline
#23460
failed with stage
in 60 minutes
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/test_superresolution.py
View file @
cb5df5e1
...
...
@@ -8,6 +8,7 @@
"""
from
os.path
import
dirname
,
join
from
time
import
sleep
import
numpy
as
np
import
pytest
...
...
@@ -119,17 +120,50 @@ def test_warp():
lenna_file
=
join
(
dirname
(
__file__
),
"test_data"
,
"lenna.png"
)
lenna
=
skimage
.
io
.
imread
(
lenna_file
,
as_gray
=
True
).
astype
(
np
.
float32
)
lenna
=
torch
.
Tensor
(
lenna
).
cuda
()
warp_vectors
=
list
(
perturbation
*
torch
.
randn
(
lenna
.
shape
+
(
2
,))
for
_
in
range
(
NUM_LENNAS
))
lr_warp_vectors
=
list
(
perturbation
*
torch
.
randn
(
tuple
(
s
//
10
for
s
in
lenna
.
shape
)
+
(
2
,)).
cuda
()
for
_
in
range
(
NUM_LENNAS
))
warped
=
[
torch
.
zeros
(
lenna
.
shape
)
for
_
in
range
(
NUM_LENNAS
)]
warp_vectors
=
list
(
torch
.
Tensor
(
lenna
.
shape
+
(
2
,)).
cuda
()
for
_
in
range
(
NUM_LENNAS
))
scale_transform
(
lr_warp_vectors
[
0
],
warp_vectors
[
0
],
10
).
compile
()().
forward
(
input_field
=
lr_warp_vectors
[
0
],
output_field
=
warp_vectors
[
0
])
# for i in range(len(warp_vectors)):
# scale(lr_warp_vectors[i], warp_vectors[i], 10)
warped
=
[
torch
.
zeros
(
lenna
.
shape
).
cuda
()
for
_
in
range
(
NUM_LENNAS
)]
warp_kernel
=
translate
(
lenna
,
warped
[
0
],
pystencils
.
autodiff
.
ArrayWrapper
(
warp_vectors
[
0
],
index_dimensions
=
1
),
interpolation_mode
=
'linear'
).
compile
()
warp_vectors
[
0
],
index_dimensions
=
1
)).
compile
()().
forward
(
lenna
,
warped
[
0
],
warp_vectors
[
0
])
# for i in range(len(warped)):
# warp_kernel(lenna[i], warped[i], warp_vectors[i])
pyconrad
.
imshow
(
warp_vectors
[
0
][...,
1
])
pyconrad
.
imshow
(
lr_warp_vectors
[
0
][...,
1
])
pyconrad
.
imshow
(
warped
[
0
])
while
True
:
sleep
(
20
)
def
test_to_polar
():
import
torch
NUM_LENNAS
=
5
perturbation
=
0.1
lenna_file
=
join
(
dirname
(
__file__
),
"test_data"
,
"lenna.png"
)
lenna
=
skimage
.
io
.
imread
(
lenna_file
,
as_gray
=
True
).
astype
(
np
.
float32
)
hr
,
lr
=
pystencils
.
fields
(
'hr, lr: float32[2d]'
)
for
i
in
range
(
len
(
warped
)):
warp_kernel
(
lenna
[
i
],
warped
[
i
],
warp_vectors
[
i
]
)
hr
.
set_coordinate_origin_to_field_center
()
lr
.
set_coordinate_origin_to_field_center
(
)
lr
.
coordinate_transform
=
lambda
x
:
sympy
.
Matrix
((
x
.
norm
(),
sympy
.
atan2
(
*
x
)
/
sympy
.
pi
*
500
))
def
test_polar_transform
():
x
,
y
=
pystencils
.
fields
(
'x, y: float32[2d]'
)
...
...
tests/test_vesselness.py
View file @
cb5df5e1
...
...
@@ -19,7 +19,7 @@ import pytest
import
sympy
from
pystencils_autodiff.field_tensor_conversion
import
create_field_from_array_like
from
pystencils_reco.vesselness
import
eigenvalues_3x3
from
pystencils_reco.vesselness
import
eigenvalues_3d
,
eigenvalues_3x3
pytest
.
importorskip
(
'tensorflow'
)
...
...
@@ -42,6 +42,10 @@ def test_3x3(target):
print
(
assignments
)
kernel
=
assignments
.
compile
(
use_auto_for_assignments
=
True
,
target
=
target
)
eig1
,
eig2
,
eig3
=
kernel
(
xx
=
xx
,
xy
=
xy
,
yy
=
yy
,
xz
=
xz
,
zz
=
zz
,
yz
=
yz
)
assignments
=
eigenvalues_3d
(
eig1
,
eig2
,
eig3
,
xx
,
xy
,
xz
,
yy
,
yz
,
zz
)
print
(
assignments
)
kernel
=
assignments
.
compile
(
use_auto_for_assignments
=
True
,
target
=
target
)
eig1
,
eig2
,
eig3
=
kernel
(
xx
=
xx
,
xy
=
xy
,
yy
=
yy
,
xz
=
xz
,
zz
=
zz
,
yz
=
yz
)
@
pytest
.
mark
.
parametrize
(
'target'
,
(
'cpu'
,))
...
...
@@ -237,8 +241,11 @@ def test_check_forward_pycuda():
e2_field
=
to_gpu
(
np
.
ones
(
shape
))
e3_field
=
to_gpu
(
np
.
ones
(
shape
))
assignments
=
eigenvalues_3
x3
(
e1_field
,
e2_field
,
e3_field
,
xx
,
xy
,
xz
,
yy
,
yz
,
zz
)
assignments
=
eigenvalues_3
d
(
e1_field
,
e2_field
,
e3_field
,
xx
,
xy
,
xz
,
yy
,
yz
,
zz
)
# assignments = eigenvalues_3x3(e1_field, e2_field, e3_field, xx, xy, xz, yy, yz, zz)
kernel
=
assignments
.
compile
()
kernel
()
test_3x3
(
'cpu'
)
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