Skip to content

Commit

Permalink
Dev/main (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoadesScholar authored Mar 15, 2024
2 parents 2298ee4 + e4266b9 commit eaba59c
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 31 deletions.
51 changes: 29 additions & 22 deletions dacapo/experiments/datasplits/datasets/arrays/zarr_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def axes(self):
logger.debug(
"DaCapo expects Zarr datasets to have an 'axes' attribute!\n"
f"Zarr {self.file_name} and dataset {self.dataset} has attributes: {list(self._attributes.items())}\n"
f"Using default {['c', 'z', 'y', 'x'][-self.dims::]}",
f"Using default {['s', 'c', 'z', 'y', 'x'][-self.dims::]}",
)
return ["c", "z", "y", "x"][-self.dims : :]
return ["s", "c", "z", "y", "x"][-self.dims : :]

@property
def dims(self) -> int:
Expand Down Expand Up @@ -149,26 +149,33 @@ def create_from_array_identifier(
delete=overwrite,
)
zarr_dataset = zarr_container[array_identifier.dataset]
zarr_dataset.attrs["offset"] = (
roi.offset[::-1]
if array_identifier.container.name.endswith("n5")
else roi.offset
)
zarr_dataset.attrs["resolution"] = (
voxel_size[::-1]
if array_identifier.container.name.endswith("n5")
else voxel_size
)
zarr_dataset.attrs["axes"] = (
axes[::-1] if array_identifier.container.name.endswith("n5") else axes
)
# to make display right in neuroglancer: TODO
zarr_dataset.attrs["dimension_units"] = [
f"{size} nm" for size in zarr_dataset.attrs["resolution"]
]
zarr_dataset.attrs["_ARRAY_DIMENSIONS"] = (
axes[::-1] if array_identifier.container.name.endswith("n5") else axes
)
if array_identifier.container.name.endswith("n5"):
zarr_dataset.attrs["offset"] = roi.offset[::-1]
zarr_dataset.attrs["resolution"] = voxel_size[::-1]
zarr_dataset.attrs["axes"] = axes[::-1]
# to make display right in neuroglancer: TODO ADD CHANNELS
zarr_dataset.attrs["dimension_units"] = [
f"{size} nm" for size in voxel_size[::-1]
]
zarr_dataset.attrs["_ARRAY_DIMENSIONS"] = axes[::-1]
else:
zarr_dataset.attrs["offset"] = roi.offset
zarr_dataset.attrs["resolution"] = voxel_size
zarr_dataset.attrs["axes"] = axes
# to make display right in neuroglancer: TODO ADD CHANNELS
zarr_dataset.attrs["dimension_units"] = [
f"{size} nm" for size in voxel_size
]
zarr_dataset.attrs["_ARRAY_DIMENSIONS"] = axes
if num_channels is not None:
if axes.index("c") == 0:
zarr_dataset.attrs["dimension_units"] = [
num_channels
] + zarr_dataset.attrs["dimension_units"]
else:
zarr_dataset.attrs["dimension_units"] = zarr_dataset.attrs[
"dimension_units"
] + [num_channels]
except zarr.errors.ContainsArrayError:
zarr_dataset = zarr_container[array_identifier.dataset]
assert (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def process(
None,
self.prediction_array.voxel_size,
np.uint8,
block_size,
)

read_roi = Roi((0, 0, 0), self.prediction_array.voxel_size * block_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def process(
self.prediction_array.num_channels,
self.prediction_array.voxel_size,
np.uint8,
block_size,
)

read_roi = Roi((0, 0, 0), self.prediction_array.voxel_size * block_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def process(
None,
self.prediction_array.voxel_size,
np.uint64,
block_size,
)

read_roi = Roi((0, 0, 0), self.prediction_array.voxel_size * block_size)
Expand Down
1 change: 1 addition & 0 deletions dacapo/experiments/trainers/gunpowder_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def iterate(self, num_iterations, model, optimizer, device):
v.num_channels,
v.voxel_size,
v.dtype if not v.dtype == bool else np.float32,
model.output_shape,
)
dataset = snapshot_zarr[k]
else:
Expand Down
1 change: 1 addition & 0 deletions dacapo/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def predict(
output_voxel_size,
output_dtype,
overwrite=overwrite,
write_size=output_size,
)

# run blockwise prediction
Expand Down
8 changes: 0 additions & 8 deletions dacapo/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ def train_run(run: Run):
stats_store.store_training_stats(run.name, run.training_stats)
continue

run.model.eval()
# free up optimizer memory to allow larger validation blocks
run.move_optimizer(torch.device("cpu"), empty_cuda_cache=True)

stats_store.store_training_stats(run.name, run.training_stats)
weights_store.store_weights(run, iteration_stats.iteration + 1)
try:
Expand All @@ -200,8 +196,4 @@ def train_run(run: Run):
exc_info=e,
)

# make sure to move optimizer back to the correct device
run.move_optimizer(compute_context.device)
run.model.train()

print("Trained until %d, finished.", trained_until)
1 change: 1 addition & 0 deletions dacapo/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def validate_run(
post_processed_array.num_channels,
post_processed_array.voxel_size,
post_processed_array.dtype,
output_size,
)
best_array[best_array.roi] = post_processed_array[
post_processed_array.roi
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ examples = [
]
pretrained = [
"pyqt5",
"empanada-napari",
"empanada-napari",
"cellmap-models",
]
all = ["dacapo-ml[test,dev,docs,examples,pretrained]"]

Expand Down

0 comments on commit eaba59c

Please sign in to comment.