Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pystencil_reco
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephan Seitz
pystencil_reco
Commits
cb5df5e1
Commit
cb5df5e1
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Commit random stuff that I wrote months ago
parent
a59323a1
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#23460
failed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_superresolution.py
+39
-5
39 additions, 5 deletions
tests/test_superresolution.py
tests/test_vesselness.py
+9
-2
9 additions, 2 deletions
tests/test_vesselness.py
with
48 additions
and
7 deletions
tests/test_superresolution.py
+
39
−
5
View file @
cb5df5e1
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
"""
"""
from
os.path
import
dirname
,
join
from
os.path
import
dirname
,
join
from
time
import
sleep
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
...
@@ -119,17 +120,50 @@ def test_warp():
...
@@ -119,17 +120,50 @@ def test_warp():
lenna_file
=
join
(
dirname
(
__file__
),
"
test_data
"
,
"
lenna.png
"
)
lenna_file
=
join
(
dirname
(
__file__
),
"
test_data
"
,
"
lenna.png
"
)
lenna
=
skimage
.
io
.
imread
(
lenna_file
,
as_gray
=
True
).
astype
(
np
.
float32
)
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_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
)):
hr
.
set_coordinate_origin_to_field_center
()
warp_kernel
(
lenna
[
i
],
warped
[
i
],
warp_vectors
[
i
]
)
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
():
def
test_polar_transform
():
x
,
y
=
pystencils
.
fields
(
'
x, y: float32[2d]
'
)
x
,
y
=
pystencils
.
fields
(
'
x, y: float32[2d]
'
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_vesselness.py
+
9
−
2
View file @
cb5df5e1
...
@@ -19,7 +19,7 @@ import pytest
...
@@ -19,7 +19,7 @@ import pytest
import
sympy
import
sympy
from
pystencils_autodiff.field_tensor_conversion
import
create_field_from_array_like
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
'
)
pytest
.
importorskip
(
'
tensorflow
'
)
...
@@ -42,6 +42,10 @@ def test_3x3(target):
...
@@ -42,6 +42,10 @@ def test_3x3(target):
print
(
assignments
)
print
(
assignments
)
kernel
=
assignments
.
compile
(
use_auto_for_assignments
=
True
,
target
=
target
)
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
)
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
'
,))
@pytest.mark.parametrize
(
'
target
'
,
(
'
cpu
'
,))
...
@@ -237,8 +241,11 @@ def test_check_forward_pycuda():
...
@@ -237,8 +241,11 @@ def test_check_forward_pycuda():
e2_field
=
to_gpu
(
np
.
ones
(
shape
))
e2_field
=
to_gpu
(
np
.
ones
(
shape
))
e3_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)
# assignments = eigenvalues_3x3(e1_field, e2_field, e3_field, xx, xy, xz, yy, yz, zz)
kernel
=
assignments
.
compile
()
kernel
=
assignments
.
compile
()
kernel
()
kernel
()
test_3x3
(
'
cpu
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment