mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-11-29 00:17:48 +01:00
Remove the need to use dataset for model.inspect() and model.save_results(), and update the examples accordingly. Docs and ipython notebooks not yet updated
This commit is contained in:
1 parent
6aa5df081b
commit
b9dcb03a93
9 files changed
+35
-34
No files matched your search
@@ -34,7 +34,7 @@ for loss in recon.optimize(50, lr=0.02, batch_size=10):
|
||||
print(model.report())
|
||||
# Because plotting can be expensive, setting a minimum plotting interval
|
||||
# (in seconds) can avoid excessive replots.
|
||||
model.inspect(dataset, min_interval=10)
|
||||
model.inspect(min_interval=10)
|
||||
|
||||
# It's common to chain several different reconstruction loops. Here, we
|
||||
# started with an aggressive refinement to find the probe in the previous
|
||||
@@ -42,12 +42,12 @@ for loss in recon.optimize(50, lr=0.02, batch_size=10):
|
||||
# and larger minibatch
|
||||
for loss in recon.optimize(50, lr=0.005, batch_size=50):
|
||||
print(model.report())
|
||||
model.inspect(dataset, min_interval=10)
|
||||
model.inspect(min_interval=10)
|
||||
|
||||
# This orthogonalizes the recovered probe modes
|
||||
model.tidy_probes()
|
||||
|
||||
# Setting replot_all will reopen any windows which were closed earlier
|
||||
model.inspect(dataset, replot_all=True)
|
||||
model.inspect(replot_all=True)
|
||||
model.compare(dataset)
|
||||
plt.show()
|
||||
@@ -54,11 +54,11 @@ with model.save_on_exception(
|
||||
|
||||
for loss in recon.optimize(20, lr=0.005, batch_size=50):
|
||||
print(model.report())
|
||||
model.inspect(dataset, min_interval=5)
|
||||
model.inspect(min_interval=5)
|
||||
|
||||
for loss in recon.optimize(50, lr=0.002, batch_size=100):
|
||||
print(model.report())
|
||||
model.inspect(dataset, min_interval=5)
|
||||
model.inspect(min_interval=5)
|
||||
|
||||
# We can often reset our guess of the probe positions once we have a
|
||||
# good guess of probe and object, but in this case it causes the
|
||||
@@ -69,14 +69,14 @@ with model.save_on_exception(
|
||||
# the loss fails to improve after 10 epochs
|
||||
for loss in recon.optimize(100, lr=0.001, batch_size=100, schedule=True):
|
||||
print(model.report())
|
||||
model.inspect(dataset, min_interval=5)
|
||||
model.inspect(min_interval=5)
|
||||
|
||||
|
||||
model.tidy_probes()
|
||||
|
||||
# This saves the final result
|
||||
model.save_to_h5('example_reconstructions/gold_balls.h5', dataset)
|
||||
model.save_to_h5('example_reconstructions/gold_balls.h5')
|
||||
|
||||
model.inspect(dataset, replot_all=True)
|
||||
model.inspect(replot_all=True)
|
||||
model.compare(dataset)
|
||||
plt.show()
|
||||
@@ -54,4 +54,4 @@ for label, dataset in zip(labels, datasets):
|
||||
|
||||
model.tidy_probes()
|
||||
|
||||
model.save_to_h5(f'example_reconstructions/gold_balls_{label}.h5', dataset)
|
||||
model.save_to_h5(f'example_reconstructions/gold_balls_{label}.h5')
|
||||
@@ -34,21 +34,21 @@ if t.cuda.is_available():
|
||||
model.to(device='cuda')
|
||||
dataset.get_as(device='cuda')
|
||||
|
||||
model.inspect(dataset)
|
||||
model.inspect()
|
||||
|
||||
recon = cdtools.reconstructors.AdamReconstructor(model, dataset)
|
||||
|
||||
for loss in recon.optimize(100, lr=0.04, batch_size=10):
|
||||
print(model.report())
|
||||
model.inspect(dataset, min_interval=5)
|
||||
model.inspect(min_interval=5)
|
||||
|
||||
for loss in recon.optimize(50, lr=0.005, batch_size=50):
|
||||
print(model.report())
|
||||
model.inspect(dataset, min_interval=5)
|
||||
model.inspect(min_interval=5)
|
||||
|
||||
# This orthogonalizes the recovered probe modes
|
||||
model.tidy_probes()
|
||||
|
||||
model.inspect(dataset, replot_all=True)
|
||||
model.inspect(replot_all=True)
|
||||
model.compare(dataset)
|
||||
plt.show()
|
||||
@@ -30,7 +30,7 @@ for loss in model.Adam_optimize(100, dataset, batch_size=10):
|
||||
# We print a quick report of the optimization status
|
||||
print(model.report())
|
||||
# And liveplot the updates to the model as they happen
|
||||
model.inspect(dataset)
|
||||
model.inspect()
|
||||
|
||||
# We open a comparison of the simulated and measured data
|
||||
model.compare(dataset)
|
||||
|
||||
@@ -31,19 +31,19 @@ if t.cuda.is_available():
|
||||
# The regularization is an L2 regularizer that empirically helps accelerate
|
||||
# convergence
|
||||
for loss in model.LBFGS_optimize(30, dataset, lr=0.4, regularization_factor=[0.05,0.05]):
|
||||
model.inspect(dataset, min_interval=5)
|
||||
model.inspect(min_interval=5)
|
||||
print(model.report())
|
||||
|
||||
|
||||
# Now we use the regularizer to damp all but the top modes
|
||||
for loss in model.LBFGS_optimize(50, dataset, lr=0.4, regularization_factor=[0.001,0.1]):
|
||||
model.inspect(dataset, min_interval=5)
|
||||
model.inspect(min_interval=5)
|
||||
print(model.report())
|
||||
|
||||
# Save results to an h5 file
|
||||
model.save_to_h5('example_reconstructions/transmission_RPI.h5', dataset)
|
||||
model.save_to_h5('example_reconstructions/transmission_RPI.h5')
|
||||
|
||||
# Finally, we plot the results
|
||||
model.inspect(dataset, replot_all=True)
|
||||
model.inspect(replot_all=True)
|
||||
model.compare(dataset)
|
||||
plt.show()
|
||||
@@ -17,7 +17,7 @@ if t.cuda.is_available():
|
||||
dataset.get_as(device='cuda')
|
||||
|
||||
for loss in model.Adam_optimize(10, dataset):
|
||||
model.inspect(dataset)
|
||||
model.inspect()
|
||||
print(model.report())
|
||||
|
||||
model.inspect(dataset)
|
||||
|
||||
@@ -130,7 +130,7 @@ class SimplePtycho(CDIModel):
|
||||
},
|
||||
]
|
||||
|
||||
def save_results(self, dataset):
|
||||
def save_results(self, dataset=None):
|
||||
# This will save out everything needed to recreate the object
|
||||
# in the same state, but it's not the best formatted.
|
||||
base_results = super().save_results()
|
||||
|
||||
Reference in new issue
Block a user