diff --git a/dacapo/blockwise/predict_worker.py b/dacapo/blockwise/predict_worker.py index 05c08ae3c..59a5fbc75 100644 --- a/dacapo/blockwise/predict_worker.py +++ b/dacapo/blockwise/predict_worker.py @@ -46,7 +46,7 @@ def cli(log_level): @click.option( "-i", "--iteration", - type=Optional[int], + type=int, help="The training iteration of the model to use for prediction.", default=None, ) diff --git a/dacapo/examples/distance_task/cosem_finetune_example.ipynb b/dacapo/examples/distance_task/cosem_finetune_example.ipynb index 3517d96e4..d50dfcf90 100644 --- a/dacapo/examples/distance_task/cosem_finetune_example.ipynb +++ b/dacapo/examples/distance_task/cosem_finetune_example.ipynb @@ -10,8 +10,7 @@ "from dacapo.store.create_store import create_config_store\n", "\n", "config_store = create_config_store()\n", - "\n", - "" + "\n" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -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" ] }, { @@ -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", @@ -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" ] }, { @@ -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" ] }, { @@ -237,8 +229,6 @@ ] } ], - "nbformat": 4, - "nbformat_minor": 2, "metadata": { "language_info": { "codemirror_mode": { @@ -252,5 +242,7 @@ "pygments_lexer": "ipython3", "version": 3 } - } -} \ No newline at end of file + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/dacapo/examples/distance_task/synthetic_example.ipynb b/dacapo/examples/distance_task/synthetic_example.ipynb index 3c8d0cfe5..986cc68f1 100644 --- a/dacapo/examples/distance_task/synthetic_example.ipynb +++ b/dacapo/examples/distance_task/synthetic_example.ipynb @@ -70,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -92,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -102,7 +102,7 @@ " " + "" ] }, - "execution_count": 5, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -160,7 +160,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -170,7 +170,7 @@ " " + "" ] }, - "execution_count": 6, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -211,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -221,7 +221,7 @@ " " + "" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -273,7 +273,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -287,7 +287,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Neuroglancer link: http://rhoadesj-ws1.hhmi.org:32941/v/d893eb501d1df982c9931ec02a68ee97a11888a5/\n" + "Neuroglancer link: http://rhoadesj-ws1.hhmi.org:35653/v/4f2cdd3e9616cf79e45570c9ef61a29d7a799efb/\n" ] } ], @@ -401,7 +401,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -428,7 +428,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -462,7 +462,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -508,7 +508,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -532,7 +532,7 @@ "# )\n", "\n", "iterations = 2000\n", - "validation_interval = 200 # iterations // 2\n", + "validation_interval = iterations // 2\n", "repetitions = 1\n", "for i in range(repetitions):\n", " run_config = RunConfig(\n", @@ -579,7 +579,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -587,31 +587,142 @@ "output_type": "stream", "text": [ "Creating FileConfigStore:\n", - "\tpath: /nrs/cellmap/rhoadesj/dacapo_runs/configs\n", - "\n" + "\tpath: /nrs/cellmap/rhoadesj/dacapo_runs/configs\n" ] }, { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR:dacapo.train:Found weights for iteration 2000, but run example_synthetic_distance_run was only trained until 1600. \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Starting/resuming training for run ...\n", + "Creating FileStatsStore:\n", + "\tpath : /nrs/cellmap/rhoadesj/dacapo_runs/stats\n", + "Current state: trained until 1600/2000\n", + "Creating local weights store in directory /nrs/cellmap/rhoadesj/dacapo_runs\n", + "Retrieving weights for run , iteration 2000\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "training until 1700: 80%|████████ | 1600/2000 [00:00, iteration 2000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updating training stats of run example_synthetic_distance_run after iteration 1600\n", + "Validating run example_synthetic_distance_run on dataset example_validate_[labels]_['labels']_8nm\n", + "Trained until 2000. Finished.\n" + ] } ], "source": [ @@ -644,9 +755,325 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Validating run example_synthetic_distance_run at iteration 2000...\n", + "Creating FileConfigStore:\n", + "\tpath: /nrs/cellmap/rhoadesj/dacapo_runs/configs\n", + "Creating FileStatsStore:\n", + "\tpath : /nrs/cellmap/rhoadesj/dacapo_runs/stats\n", + "Validating run example_synthetic_distance_run on dataset example_validate_[labels]_['labels']_8nm\n", + "validation inputs already copied!\n", + "Predicting with input size (1952, 1952, 1952), output size (1216, 1216, 1216)\n", + "Total input ROI: [-368:4016, -368:4016, -368:4016] (4384, 4384, 4384), output ROI: [0:3648, 0:3648, 0:3648] (3648, 3648, 3648)\n", + "Running blockwise prediction with worker_file: /nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/predict_worker.py\n", + "Defining worker with command: ['/home/rhoadesj@hhmi.org/micromamba/envs/dacapo/bin/python', '/nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/predict_worker.py', 'start-worker', '--run-name', 'example_synthetic_distance_run', '--input_container', '/nrs/cellmap/rhoadesj/dacapo_runs/example_synthetic_distance_run/validation.zarr', '--input_dataset', \"inputs/example_validate_[labels]_['labels']_8nm/raw\", '--output_container', '/nrs/cellmap/rhoadesj/dacapo_runs/example_synthetic_distance_run/validation.zarr', '--output_dataset', \"2000/example_validate_[labels]_['labels']_8nm/prediction\", '--iteration', '2000']\n", + "Running blockwise with worker_file: /nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/predict_worker.py\n", + "Using compute context: LocalTorch(_device=None, oom_limit=5)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "validation inputs already copied!\n", + "Predicting with input size (1952, 1952, 1952), output size (1216, 1216, 1216)\n", + "Total input ROI: [-368:4016, -368:4016, -368:4016] (4384, 4384, 4384), output ROI: [0:3648, 0:3648, 0:3648] (3648, 3648, 3648)\n", + "Running blockwise prediction with worker_file: /nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/predict_worker.py\n", + "Defining worker with command: ['/home/rhoadesj@hhmi.org/micromamba/envs/dacapo/bin/python', '/nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/predict_worker.py', 'start-worker', '--run-name', 'example_synthetic_distance_run', '--input_container', '/nrs/cellmap/rhoadesj/dacapo_runs/example_synthetic_distance_run/validation.zarr', '--input_dataset', \"inputs/example_validate_[labels]_['labels']_8nm/raw\", '--output_container', '/nrs/cellmap/rhoadesj/dacapo_runs/example_synthetic_distance_run/validation.zarr', '--output_dataset', \"2000/example_validate_[labels]_['labels']_8nm/prediction\", '--iteration', '2000']\n", + "Running blockwise with worker_file: /nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/predict_worker.py\n", + "Using compute context: LocalTorch(_device=None, oom_limit=5)\n", + "\n", + "Execution Summary\n", + "-----------------\n", + "\n", + " Task predict_worker2024-03-20_17-23-01:\n", + "\n", + " num blocks : 27\n", + " completed ✔: 27 (skipped 0)\n", + " failed ✗: 0\n", + " orphaned ∅: 0\n", + "\n", + " all blocks processed successfully\n", + "Done predicting.\n", + "Predicted on dataset example_validate_[labels]_['labels']_8nm\n", + "Running blockwise with worker_file: /nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/threshold_worker.py\n", + "Using compute context: LocalTorch(_device=None, oom_limit=5)\n", + "\n", + "Execution Summary\n", + "-----------------\n", + "\n", + " Task threshold_worker2024-03-20_17-23-49:\n", + "\n", + " num blocks : 27\n", + " completed ✔: 27 (skipped 0)\n", + " failed ✗: 0\n", + " orphaned ∅: 0\n", + "\n", + " all blocks processed successfully\n", + "Evaluating binary segmentations on evaluation_data of shape: (456, 456, 456)\n", + "Running blockwise with worker_file: /nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/threshold_worker.py\n", + "Using compute context: LocalTorch(_device=None, oom_limit=5)\n", + "\n", + "Execution Summary\n", + "-----------------\n", + "\n", + " Task threshold_worker2024-03-20_17-24-44:\n", + "\n", + " num blocks : 27\n", + " completed ✔: 27 (skipped 0)\n", + " failed ✗: 0\n", + " orphaned ∅: 0\n", + "\n", + " all blocks processed successfully\n", + "Evaluating binary segmentations on evaluation_data of shape: (456, 456, 456)\n", + "Running blockwise with worker_file: /nrs/cellmap/rhoadesj/dacapo/dacapo/blockwise/threshold_worker.py\n", + "Using compute context: LocalTorch(_device=None, oom_limit=5)\n", + "\n", + "Execution Summary\n", + "-----------------\n", + "\n", + " Task threshold_worker2024-03-20_17-25-38:\n", + "\n", + " num blocks : 27\n", + " completed ✔: 27 (skipped 0)\n", + " failed ✗: 0\n", + " orphaned ∅: 0\n", + "\n", + " all blocks processed successfully\n", + "Evaluating binary segmentations on evaluation_data of shape: (456, 456, 456)\n", + "Creating FileStatsStore:\n", + "\tpath : /nrs/cellmap/rhoadesj/dacapo_runs/stats\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "88d8e80ddf214ec4a1db5d8c48c08951", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "predict_worker2024-03-20_17-23-01 ▶: 0%| | 0/27 [00:00\n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from dacapo.predict import predict\n", "\n", @@ -684,7 +1134,7 @@ ")\n", "\n", "raw_array = open_ds(str(test_data_path), \"raw\")\n", - "pred_array = open_ds(str(test_data_path), \"predictions\")\n", + "pred_array = open_ds(str(test_data_path), f\"prediction_{run_config.name}_{iterations}\")\n", "gt_array = open_ds(str(test_data_path), \"labels\")\n", "\n", "arrays = {\n",