Skip to content

Commit

Permalink
fix dep
Browse files Browse the repository at this point in the history
  • Loading branch information
mzouink committed Oct 23, 2024
1 parent b9d150f commit 86a6a18
Showing 1 changed file with 68 additions and 68 deletions.
136 changes: 68 additions & 68 deletions docs/source/notebooks/minimal_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

# This line is mostly for MacOS users to avoid a bug in multiprocessing
multiprocessing.set_start_method("fork", force=True)
from dacapo.store.create_store import create_config_store
from dacapo.store.create_store import create_config_store, create_stats_store

config_store = create_config_store()

Expand Down Expand Up @@ -149,7 +149,7 @@
# %% [markdown]
# Here we show a slice of the raw data:
# %%
# Create a custom label color map for showing instances
# a custom label color map for showing instances
import matplotlib.pyplot as plt

fig, axes = plt.subplots(1, 2, figsize=(12, 6))
Expand Down Expand Up @@ -356,69 +356,69 @@
plt.show()

# %%
import zarr
from matplotlib.colors import ListedColormap

np.random.seed(1)
colors = [[0, 0, 0]] + [list(np.random.choice(range(256), size=3)) for _ in range(254)]
label_cmap = ListedColormap(colors)
run_path = config_store.path / run_config.name

num_snapshots = run_config.num_iterations // run_config.trainer_config.snapshot_interval
fig, ax = plt.subplots(num_snapshots, 3, figsize=(10, 2 * num_snapshots))

# Set column titles
column_titles = ["Raw", "Target", "Prediction"]
for col in range(3):
ax[0, col].set_title(column_titles[col])

for snapshot in range(num_snapshots):
snapshot_it = snapshot * run_config.trainer_config.snapshot_interval
# break
raw = zarr.open(f"{run_path}/snapshot.zarr/{snapshot_it}/volumes/raw")[:]
target = zarr.open(f"{run_path}/snapshot.zarr/{snapshot_it}/volumes/target")[0]
prediction = zarr.open(
f"{run_path}/snapshot.zarr/{snapshot_it}/volumes/prediction"
)[0]
c = (raw.shape[1] - target.shape[1]) // 2
ax[snapshot, 0].imshow(raw[raw.shape[0] // 2, c:-c, c:-c])
ax[snapshot, 1].imshow(target[target.shape[0] // 2])
ax[snapshot, 2].imshow(prediction[prediction.shape[0] // 2])
ax[snapshot, 0].set_ylabel(f"Snapshot {snapshot_it}")
plt.show()

# %%
# Visualize validations
import zarr

num_validations = run_config.num_iterations // run_config.validation_interval
fig, ax = plt.subplots(num_validations, 4, figsize=(10, 2 * num_validations))

# Set column titles
column_titles = ["Raw", "Ground Truth", "Prediction", "Segmentation"]
for col in range(len(column_titles)):
ax[0, col].set_title(column_titles[col])

for validation in range(1, num_validations + 1):
dataset = run.datasplit.validate[0].name
validation_it = validation * run_config.validation_interval
# break
raw = zarr.open(f"{run_path}/validation.zarr/inputs/{dataset}/raw")[:]
gt = zarr.open(f"{run_path}/validation.zarr/inputs/{dataset}/gt")[0]
pred_path = f"{run_path}/validation.zarr/{validation_it}/ds_{dataset}/prediction"
out_path = f"{run_path}/validation.zarr/{validation_it}/ds_{dataset}/output/WatershedPostProcessorParameters(id=2, bias=0.5, context=(32, 32, 32))"
output = zarr.open(out_path)[:]
prediction = zarr.open(pred_path)[0]
c = (raw.shape[1] - gt.shape[1]) // 2
if c != 0:
raw = raw[:, c:-c, c:-c]
ax[validation - 1, 0].imshow(raw[raw.shape[0] // 2])
ax[validation - 1, 1].imshow(
gt[gt.shape[0] // 2], cmap=label_cmap, interpolation="none"
)
ax[validation - 1, 2].imshow(prediction[prediction.shape[0] // 2])
ax[validation - 1, 3].imshow(
output[output.shape[0] // 2], cmap=label_cmap, interpolation="none"
)
ax[validation - 1, 0].set_ylabel(f"Validation {validation_it}")
plt.show()
# import zarr
# from matplotlib.colors import ListedColormap

# np.random.seed(1)
# colors = [[0, 0, 0]] + [list(np.random.choice(range(256), size=3)) for _ in range(254)]
# label_cmap = ListedColormap(colors)
# run_path = config_store.path / run_config.name

# num_snapshots = run_config.num_iterations // run_config.trainer_config.snapshot_interval
# fig, ax = plt.subplots(num_snapshots, 3, figsize=(10, 2 * num_snapshots))

# # Set column titles
# column_titles = ["Raw", "Target", "Prediction"]
# for col in range(3):
# ax[0, col].set_title(column_titles[col])

# for snapshot in range(num_snapshots):
# snapshot_it = snapshot * run_config.trainer_config.snapshot_interval
# # break
# raw = zarr.open(f"{run_path}/snapshot.zarr/{snapshot_it}/volumes/raw")[:]
# target = zarr.open(f"{run_path}/snapshot.zarr/{snapshot_it}/volumes/target")[0]
# prediction = zarr.open(
# f"{run_path}/snapshot.zarr/{snapshot_it}/volumes/prediction"
# )[0]
# c = (raw.shape[1] - target.shape[1]) // 2
# ax[snapshot, 0].imshow(raw[raw.shape[0] // 2, c:-c, c:-c])
# ax[snapshot, 1].imshow(target[target.shape[0] // 2])
# ax[snapshot, 2].imshow(prediction[prediction.shape[0] // 2])
# ax[snapshot, 0].set_ylabel(f"Snapshot {snapshot_it}")
# plt.show()

# # %%
# # Visualize validations
# import zarr

# num_validations = run_config.num_iterations // run_config.validation_interval
# fig, ax = plt.subplots(num_validations, 4, figsize=(10, 2 * num_validations))

# # Set column titles
# column_titles = ["Raw", "Ground Truth", "Prediction", "Segmentation"]
# for col in range(len(column_titles)):
# ax[0, col].set_title(column_titles[col])

# for validation in range(1, num_validations + 1):
# dataset = run.datasplit.validate[0].name
# validation_it = validation * run_config.validation_interval
# # break
# raw = zarr.open(f"{run_path}/validation.zarr/inputs/{dataset}/raw")[:]
# gt = zarr.open(f"{run_path}/validation.zarr/inputs/{dataset}/gt")[0]
# pred_path = f"{run_path}/validation.zarr/{validation_it}/ds_{dataset}/prediction"
# out_path = f"{run_path}/validation.zarr/{validation_it}/ds_{dataset}/output/WatershedPostProcessorParameters(id=2, bias=0.5, context=(32, 32, 32))"
# output = zarr.open(out_path)[:]
# prediction = zarr.open(pred_path)[0]
# c = (raw.shape[1] - gt.shape[1]) // 2
# if c != 0:
# raw = raw[:, c:-c, c:-c]
# ax[validation - 1, 0].imshow(raw[raw.shape[0] // 2])
# ax[validation - 1, 1].imshow(
# gt[gt.shape[0] // 2], cmap=label_cmap, interpolation="none"
# )
# ax[validation - 1, 2].imshow(prediction[prediction.shape[0] // 2])
# ax[validation - 1, 3].imshow(
# output[output.shape[0] // 2], cmap=label_cmap, interpolation="none"
# )
# ax[validation - 1, 0].set_ylabel(f"Validation {validation_it}")
# plt.show()

0 comments on commit 86a6a18

Please sign in to comment.