Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import numpy as np
import tensorflow as tf
import lme_custom_ops
import pyconrad as pyc
import matplotlib.pyplot as plt
pyc.setup_pyconrad()
from pyronn.ct_reconstruction.layers.projection_2d import parallel_projection2d
from pyronn.ct_reconstruction.layers.backprojection_2d import parallel_backprojection2d
from pyronn.ct_reconstruction.geometry.geometry_parallel_2d import GeometryParallel2D
from pyronn.ct_reconstruction.helpers.phantoms import shepp_logan
from pyronn.ct_reconstruction.helpers.trajectories import circular_trajectory
from pyronn.ct_reconstruction.helpers.filters import filters
import pyronn.ct_reconstruction.helpers.misc.generate_sinogram as generate_sinogram
def example_learning_simple():
# ------------------ Declare Parameters ------------------
# Volume Parameters:
volume_size = 200
import numpy as np
import pyconrad as pyc # TODO: get independent of pyconrad
pyc.setup_pyconrad()
def circle(shape, pos, radius, value):
# create meshgrid of coords
xx, yy = np.mgrid[:shape[1], :shape[0]]
# calc squared distance to pos
circle = (xx - pos[1]) ** 2 + (yy - pos[0]) ** 2
return (circle <= radius**2) * value
def ellipse(shape, pos, half_axes, value, theta=0):
# create meshgrid of coords
xx, yy = np.mgrid[:shape[0], :shape[1]]
sinogram = sinogram + np.random.normal(
loc=np.mean(np.abs(sinogram)), scale=np.std(sinogram), size=sinogram.shape) * 0.02
reco_filter = filters.ram_lak_3D(geometry)
sino_freq = np.fft.fft(sinogram, axis=2)
sino_filtered_freq = np.multiply(sino_freq,reco_filter)
sinogram_filtered = np.fft.ifft(sino_filtered_freq, axis=2)
result_back_proj = par_backprojection3d(sinogram_filtered,geometry)
reco = result_back_proj.eval()
import pyconrad as pyc
pyc.setup_pyconrad()
pyc.imshow(phantom)
pyc.imshow(sinogram)
pyc.imshow(reco)
a = 5
#plt.figure()
def train(self, zero_vector, acquired_sinogram):
import pyconrad as pyc
pyc.setup_pyconrad()
self.data_iterator = tf.data.Dataset.from_tensor_slices((zero_vector, acquired_sinogram)).batch(1)
last_loss = 100000000
for epoch in range(self.args.num_epochs):
for images, labels in self.data_iterator:
self.train_step(images, labels)
if epoch % 25 is 0:
pyc.imshow(self.model.reco.numpy(), 'reco')
if epoch % 100 is 0:
template = 'Epoch {}, Loss: {}'
print(template.format(epoch, self.loss_v.numpy()))
if self.loss_v.numpy() > last_loss*1.03:
print('break at epoch', epoch)
break
last_loss = self.loss_v.numpy()