From 75988b01443c0dc23dff9d5672ab86d2a8dd954f Mon Sep 17 00:00:00 2001 From: Mehdi Seifi Date: Thu, 24 Oct 2024 12:40:00 +0200 Subject: [PATCH] updated notebook --- run_pipeline.ipynb | 19 +++++++++++++------ src/featureforest/utils/extract.py | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/run_pipeline.ipynb b/run_pipeline.ipynb index 868a5b3..4a47619 100755 --- a/run_pipeline.ipynb +++ b/run_pipeline.ipynb @@ -201,17 +201,17 @@ "outputs": [], "source": [ "# input image\n", - "data_path = \"../datasets/Johan/dino_host/test_substacks/Stack02_bin4_(1-3598-3).tif\"\n", + "data_path = \"../datasets/data.tif\"\n", "data_path = Path(data_path)\n", "print(f\"data_path exists: {data_path.exists()}\")\n", "\n", "# random forest model\n", - "rf_model_path = \"../datasets/Johan/dino_host/mito/host/rf_model.bin\"\n", + "rf_model_path = \"../datasets/rf_model.bin\"\n", "rf_model_path = Path(rf_model_path)\n", "print(f\"rf_model_path exists: {rf_model_path.exists()}\")\n", "\n", "# result folder\n", - "segmentation_dir = Path(\"../datasets/Johan/dino_host/mito/host/segmentation_result\")\n", + "segmentation_dir = Path(\"../datasets/segmentation_result\")\n", "segmentation_dir.mkdir(parents=True, exist_ok=True)\n", "\n", "# temporary storage path for saving extracted embeddings patches\n", @@ -249,9 +249,16 @@ "outputs": [], "source": [ "with open(rf_model_path, mode=\"rb\") as f:\n", - " rf_model = pickle.load(f)\n", - " rf_model.set_params(verbose=0)\n", - "\n", + " model_data = pickle.load(f)\n", + "# compatibility check for old format rf model\n", + "if isinstance(model_data, dict): # noqa: SIM108\n", + " # new format\n", + " rf_model = model_data[\"rf_model\"]\n", + "else:\n", + " # old format\n", + " rf_model = model_data\n", + "\n", + "rf_model.set_params(verbose=0)\n", "rf_model" ] }, diff --git a/src/featureforest/utils/extract.py b/src/featureforest/utils/extract.py index dbf37ee..3aa6e51 100644 --- a/src/featureforest/utils/extract.py +++ b/src/featureforest/utils/extract.py @@ -66,7 +66,7 @@ def get_slice_features( # get sam encoder output for image patches print("extracting features:") - for b_idx in np_progress(range(num_batches), desc="extracting feature:"): + for b_idx in np_progress(range(num_batches), desc="extracting feature"): print(f"batch #{b_idx + 1} of {num_batches}") start = b_idx * batch_size end = start + batch_size