mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-11-28 07:57:48 +01:00
First pass at models, including the model for classic Ptychography
This commit is contained in:
1 parent
d0897f1dff
commit
63c55582ec
14 files changed
+358
-106
No files matched your search
@@ -0,0 +1,34 @@
|
||||
from __future__ import division, print_function, absolute_import
|
||||
|
||||
import CDTools
|
||||
from CDTools.tools import cmath
|
||||
import h5py
|
||||
import torch as t
|
||||
import numpy as np
|
||||
|
||||
with h5py.File('../example_data/NiCr.cxi','r') as f:
|
||||
dataset = CDTools.datasets.Ptycho_2D_Dataset.from_cxi(f)
|
||||
|
||||
model = CDTools.models.SimplePtycho.from_dataset(dataset)
|
||||
|
||||
# Uncomment these to use on the CPU
|
||||
# default is CPU with 32-bit floats
|
||||
model.to(device='cuda')
|
||||
dataset.to(device='cuda')
|
||||
dataset.get_as(device='cuda')
|
||||
|
||||
for loss in model.Adam_optimize(500, dataset):
|
||||
print(loss)
|
||||
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
probe = cmath.torch_to_complex(model.probe.detach().cpu())
|
||||
obj = cmath.torch_to_complex(model.obj.detach().cpu())
|
||||
|
||||
plt.imshow(np.abs(probe))
|
||||
plt.colorbar()
|
||||
plt.figure()
|
||||
plt.imshow(np.abs(obj))
|
||||
plt.colorbar()
|
||||
plt.show()
|
||||
|
||||
Reference in new issue
Block a user