Added a minimum plotting interval to model.inspect(dataset) to make it easier to not plot so much without manual intervention

This commit is contained in:
allevitan committed 2026-03-20 20:01:40 +01:00
1 parent f35141dcc8
commit bef907c032
6 files changed
+34 -30

No files matched your search

+6 -6
View File
@@ -32,9 +32,9 @@ recon = cdtools.reconstructors.AdamReconstructor(model, dataset)
# The batch size sets the minibatch size
for loss in recon.optimize(50, lr=0.02, batch_size=10):
print(model.report())
# Plotting is expensive, so we only do it every tenth epoch
if model.epoch % 10 == 0:
model.inspect(dataset)
# Because plotting can be expensive, setting a minimum plotting interval
# (in seconds) can avoid excessive replots.
model.inspect(dataset, min_interval=5)
# 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())
if model.epoch % 10 == 0:
model.inspect(dataset)
model.inspect(dataset, min_interval=5)
# This orthogonalizes the recovered probe modes
model.tidy_probes()
model.inspect(dataset)
# Setting replot_all will reopen any windows which were closed earlier
model.inspect(dataset, replot_all=True)
model.compare(dataset)
plt.show()
+4 -7
View File
@@ -54,13 +54,11 @@ with model.save_on_exception(
for loss in recon.optimize(20, lr=0.005, batch_size=50):
print(model.report())
if model.epoch % 10 == 0:
model.inspect(dataset)
model.inspect(dataset, min_interval=5)
for loss in recon.optimize(50, lr=0.002, batch_size=100):
print(model.report())
if model.epoch % 10 == 0:
model.inspect(dataset)
model.inspect(dataset, 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
@@ -71,8 +69,7 @@ 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())
if model.epoch % 10 == 0:
model.inspect(dataset)
model.inspect(dataset, min_interval=5)
model.tidy_probes()
@@ -80,6 +77,6 @@ model.tidy_probes()
# This saves the final result
model.save_to_h5('example_reconstructions/gold_balls.h5', dataset)
model.inspect(dataset)
model.inspect(dataset, replot_all=True)
model.compare(dataset)
plt.show()
+3 -6
View File
@@ -40,18 +40,15 @@ recon = cdtools.reconstructors.AdamReconstructor(model, dataset)
for loss in recon.optimize(100, lr=0.04, batch_size=10):
print(model.report())
# Plotting is expensive, so we only do it every tenth epoch
if model.epoch % 10 == 0:
model.inspect(dataset)
model.inspect(dataset, min_interval=5)
for loss in recon.optimize(50, lr=0.005, batch_size=50):
print(model.report())
if model.epoch % 10 == 0:
model.inspect(dataset)
model.inspect(dataset, min_interval=5)
# This orthogonalizes the recovered probe modes
model.tidy_probes()
model.inspect(dataset)
model.inspect(dataset, replot_all=True)
model.compare(dataset)
plt.show()
+2 -4
View File
@@ -30,10 +30,8 @@ for loss in model.Adam_optimize(30, 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
if model.epoch % 10 == 0:
model.inspect(dataset)
model.inspect(dataset)
# We study the results
model.inspect(dataset, replot_all=True)
# We open a comparison of the simulated and measured data
model.compare(dataset)
plt.show()
+6 -6
View File
@@ -30,20 +30,20 @@ if t.cuda.is_available():
# Note that the inspect step takes the vast majority of the time
# The regularization is an L2 regularizer that empirically helps accelerate
# convergence
for loss in model.Adam_optimize(30, dataset, lr=0.4, regularization_factor=[0.05,0.05]):
model.inspect(dataset)
for loss in model.LBFGS_optimize(30, dataset, lr=0.4, regularization_factor=[0.05,0.05]):
model.inspect(dataset, 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)
model.inspect(dataset, min_interval=5)
print(model.report())
# Save results to a python dictionary
results = model.save_results()
# Save results to an h5 file
model.save_to_h5('example_reconstructions/transmission_RPI.h5', dataset)
# Finally, we plot the results
model.inspect(dataset)
model.inspect(dataset, replot_all=True)
model.compare(dataset)
plt.show()