Skip to content

Commit

Permalink
Dev/main (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoadesScholar authored Mar 20, 2024
2 parents 2938d11 + af8b671 commit 53a31f7
Show file tree
Hide file tree
Showing 17 changed files with 971 additions and 272 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.hdf
*.h5
# *.ipynb
.ipynb_checkpoints/
*.pyc
*.egg-info
*.dat
Expand Down
22 changes: 12 additions & 10 deletions dacapo/blockwise/predict_worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from pathlib import Path
from typing import Optional

import torch
from dacapo.experiments.datasplits.datasets.arrays import ZarrArray
Expand Down Expand Up @@ -45,9 +46,9 @@ def cli(log_level):
@click.option(
"-i",
"--iteration",
required=True,
type=int,
help="The training iteration of the model to use for prediction.",
default=None,
)
@click.option(
"-ic",
Expand All @@ -62,7 +63,7 @@ def cli(log_level):
@click.option("-od", "--output_dataset", required=True, type=str)
def start_worker(
run_name: str,
iteration: int,
iteration: int | None,
input_container: Path | str,
input_dataset: str,
output_container: Path | str,
Expand All @@ -76,11 +77,12 @@ def start_worker(
run_config = config_store.retrieve_run_config(run_name)
run = Run(run_config)

# create weights store
weights_store = create_weights_store()
if iteration is not None:
# create weights store
weights_store = create_weights_store()

# load weights
weights_store.retrieve_weights(run_name, iteration)
# load weights
weights_store.retrieve_weights(run_name, iteration)

# get arrays
input_array_identifier = LocalArrayIdentifier(Path(input_container), input_dataset)
Expand Down Expand Up @@ -178,15 +180,15 @@ def start_worker(

def spawn_worker(
run_name: str,
iteration: int,
iteration: int | None,
input_array_identifier: "LocalArrayIdentifier",
output_array_identifier: "LocalArrayIdentifier",
):
"""Spawn a worker to predict on a given dataset.
Args:
run_name (str): The name of the run to apply.
iteration (int): The training iteration of the model to use for prediction.
iteration (int or None): The training iteration of the model to use for prediction.
input_array_identifier (LocalArrayIdentifier): The raw data to predict on.
output_array_identifier (LocalArrayIdentifier): The identifier of the prediction array.
"""
Expand All @@ -200,8 +202,6 @@ def spawn_worker(
"start-worker",
"--run-name",
run_name,
"--iteration",
iteration,
"--input_container",
input_array_identifier.container,
"--input_dataset",
Expand All @@ -211,6 +211,8 @@ def spawn_worker(
"--output_dataset",
output_array_identifier.dataset,
]
if iteration is not None:
command.extend(["--iteration", str(iteration)])

print("Defining worker with command: ", compute_context.wrap_command(command))

Expand Down
2 changes: 1 addition & 1 deletion dacapo/examples/distance_task/cosem_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
1 change: 0 additions & 1 deletion dacapo/examples/distance_task/cosem_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# %% [markdown]
# # Dacapo
#
Expand Down
17 changes: 8 additions & 9 deletions dacapo/examples/distance_task/cosem_example_fill_in_the_blank.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
# Create the datasplit, produce the neuroglancer link and store the datasplit
datasplit = ...
viewer = ...
config_store...

config_store
# %% [markdown]
# ## Task
# What do you want to learn? An instance segmentation? If so, how? Affinities,
Expand All @@ -40,9 +39,8 @@

# Create a distance task config where the clip_distance=tol_distance=10x the output resolution,
# and scale_factor = 20x the output resolution
task_config =
config_store....

task_config = ...
config_store
# %% [markdown]
# ## Architecture
#
Expand Down Expand Up @@ -97,14 +95,14 @@
# Create a gamma augment config with range .5 to 2
...,
# Create an intensity scale shift agument config to rescale data from the range 0->1 to -1->1
...,
...,
],
snapshot_interval=10000,
min_masked=0.05,
clip_raw=True,
)
# Store the trainer
config_store....
config_store

# %% [markdown]
# ## Run
Expand All @@ -128,7 +126,7 @@
run_config = ...

print(run_config.name)
config_store...
config_store

# %% [markdown]
# ## Train
Expand All @@ -138,6 +136,7 @@
# %%
from dacapo.train import train_run
from dacapo.experiments.run import Run

# load the run and train it
run = Run(config_store...)
run = Run(config_store)
train_run(run)
30 changes: 11 additions & 19 deletions dacapo/examples/distance_task/cosem_finetune_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"from dacapo.store.create_store import create_config_store\n",
"\n",
"config_store = create_config_store()\n",
"\n",
""
"\n"
]
},
{
Expand Down Expand Up @@ -43,8 +42,7 @@
"\n",
"datasplit = datasplit_config.datasplit_type(datasplit_config)\n",
"viewer = datasplit._neuroglancer()\n",
"config_store.store_datasplit_config(datasplit_config)\n",
""
"config_store.store_datasplit_config(datasplit_config)\n"
]
},
{
Expand Down Expand Up @@ -73,8 +71,7 @@
" tol_distance=40.0,\n",
" scale_factor=80.0,\n",
")\n",
"config_store.store_task_config(task_config)\n",
""
"config_store.store_task_config(task_config)\n"
]
},
{
Expand Down Expand Up @@ -106,8 +103,7 @@
" constant_upsample=True,\n",
" upsample_factors=[(2, 2, 2)],\n",
")\n",
"config_store.store_architecture_config(architecture_config)\n",
""
"config_store.store_architecture_config(architecture_config)\n"
]
},
{
Expand Down Expand Up @@ -154,8 +150,7 @@
" min_masked=0.05,\n",
" clip_raw=True,\n",
")\n",
"config_store.store_trainer_config(trainer_config)\n",
""
"config_store.store_trainer_config(trainer_config)\n"
]
},
{
Expand All @@ -173,7 +168,6 @@
"outputs": [],
"source": [
"from dacapo.experiments import RunConfig\n",
"from dacapo.experiments.run import Run\n",
"\n",
"from dacapo.experiments.starts import CosemStartConfig\n",
"\n",
Expand All @@ -199,8 +193,7 @@
" )\n",
"\n",
" print(run_config.name)\n",
" config_store.store_run_config(run_config)\n",
""
" config_store.store_run_config(run_config)\n"
]
},
{
Expand All @@ -225,8 +218,7 @@
"config_store = create_config_store()\n",
"\n",
"run = Run(config_store.retrieve_run_config(\"cosem_distance_run_4nm_finetune\"))\n",
"train_run(run)\n",
""
"train_run(run)\n"
]
},
{
Expand All @@ -237,8 +229,6 @@
]
}
],
"nbformat": 4,
"nbformat_minor": 2,
"metadata": {
"language_info": {
"codemirror_mode": {
Expand All @@ -252,5 +242,7 @@
"pygments_lexer": "ipython3",
"version": 3
}
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 53a31f7

Please sign in to comment.