Skip to content
Snippets Groups Projects
Commit cb5df5e1 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Commit random stuff that I wrote months ago

parent a59323a1
Branches
No related tags found
No related merge requests found
Pipeline #23460 failed
...@@ -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]')
......
...@@ -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_3x3(e1_field, e2_field, e3_field, xx, xy, xz, yy, yz, zz) assignments = eigenvalues_3d(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')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment