From 56824a2c0a3485d31f779376fa4b6aaa03d88efe Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Thu, 12 Sep 2024 18:37:02 +0200 Subject: [PATCH 1/8] Update Readme Remove duplicated and outdated info Add minimal info and badges for available notebooks --- panoptica/README.md | 75 +++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 44 deletions(-) diff --git a/panoptica/README.md b/panoptica/README.md index 869bb44..8fbcbeb 100644 --- a/panoptica/README.md +++ b/panoptica/README.md @@ -1,61 +1,48 @@ # Panoptica Tutorials This folder contains several Jupyter notebooks to showcase different possible use cases of the [panoptica package](https://github.com/BrainLesion/panoptica). -The package allows to compute instance-wise segmentation quality metrics for 2D and 3D semantic- and instance segmentation maps by providing 3 core modules: -**1. Instance Approximator:** instance approximation algorithms in panoptic segmentation evaluation. Available now: connected components algorithm. +## Notebooks +### Semantic: Spine example +`example_spine_semantic.ipynb` -**2. Instance Matcher:** instance matching algorithm in panoptic segmentation evaluation, to align and compare predicted instances with reference instances. +[![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/BrainLesion/tutorials/blob/main/panoptica/example_spine_semantic.ipynb) + + Open In Colab + -**3. Instance Evaluator:** Evaluation of panoptic segmentation performance by evaluating matched instance pairs and calculating various metrics like true positives, Dice score, IoU, and ASSD for each instance. +### Matched Instance: Spine example +`example_spine_matched_instance.ipynb` -![workflow_figure](https://github.com/BrainLesion/panoptica/blob/main/examples/figures/workflow.png) +[![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/BrainLesion/tutorials/blob/main/panoptica/example_spine_matched_instance.ipynb) + + Open In Colab + -## Use Cases -### Semantic Segmentation Input +### Unmatched Instance: Spine example +`example_spine_unmatched_instance.ipynb` -semantic_figure +[![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/BrainLesion/tutorials/blob/main/panoptica/example_spine_unmatched_instance.ipynb) + + Open In Colab + -Although for many biomedical segmentation problems, an instance-wise evaluation is highly relevant and desirable, they are still addressed as semantic segmentation problems due to lack of appropriate instance labels. -**Modules [1-3]** can be used to obtain panoptic metrics of matched instances based on a semantic segmentation input. +### Matching: Spine example +`example_spine_matching_algorithm.ipynb` -[Jupyter Notebook Example](https://github.com/BrainLesion/tutorials/tree/main/panoptica/example_spine_semantic.ipynb) +[![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/BrainLesion/tutorials/blob/main/panoptica/example_spine_matching_algorithm.ipynb) + + Open In Colab + -### Unmatched Instances Input -unmatched_instance_figure +### Save/Load Configs example: +`example_config.ipynb` -It is a common issue that instance segementation outputs have good segmentations with mismatched labels. +[![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/BrainLesion/tutorials/blob/main/panoptica/example_config.ipynb) + + Open In Colab + -For this case **modules [2-3]** can be utilized to match the instances and report panoptic metrics. - -[Jupyter Notebook Example](https://github.com/BrainLesion/tutorials/tree/main/panoptica/example_spine_unmatched_instance.ipynb) - -### Matched Instances Input - -matched_instance_figure - -Ideally the input data already provides matched instances. - -In this case **module 3** can be used to directly report panoptic metrics without requiring any internal preprocessing. - -[Jupyter Notebook Example](https://github.com/BrainLesion/tutorials/tree/main/panoptica/example_spine_matched_instance.ipynb) - -## Citation - -If you use panoptica in your research, please cite it to support the development! - -Kofler, F., Möller, H., Buchner, J. A., de la Rosa, E., Ezhov, I., Rosier, M., Mekki, I., Shit, S., Negwer, M., Al-Maskari, R., Ertürk, A., Vinayahalingam, S., Isensee, F., Pati, S., Rueckert, D., Kirschke, J. S., Ehrlich, S. K., Reinke, A., Menze, B., Wiestler, B., & Piraud, M. (2023). _Panoptica -- instance-wise evaluation of 3D semantic and instance segmentation maps._ [arXiv preprint arXiv:2312.02608](https://arxiv.org/abs/2312.02608). - -``` -@misc{kofler2023panoptica, - title={Panoptica -- instance-wise evaluation of 3D semantic and instance segmentation maps}, - author={Florian Kofler and Hendrik Möller and Josef A. Buchner and Ezequiel de la Rosa and Ivan Ezhov and Marcel Rosier and Isra Mekki and Suprosanna Shit and Moritz Negwer and Rami Al-Maskari and Ali Ertürk and Shankeeth Vinayahalingam and Fabian Isensee and Sarthak Pati and Daniel Rueckert and Jan S. Kirschke and Stefan K. Ehrlich and Annika Reinke and Bjoern Menze and Benedikt Wiestler and Marie Piraud}, - year={2023}, - eprint={2312.02608}, - archivePrefix={arXiv}, - primaryClass={cs.CV} -} -``` From 1b06c2896a4ae3fca3280f5c2f468d5e2aa94b3e Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Thu, 12 Sep 2024 18:48:50 +0200 Subject: [PATCH 2/8] Notebook reruns Remove pip install outputs --- panoptica/example_config.ipynb | 157 +++++++++++------- .../example_spine_matched_instance.ipynb | 47 ++---- .../example_spine_matching_algorithm.ipynb | 48 ++---- panoptica/example_spine_semantic.ipynb | 77 ++++----- .../example_spine_unmatched_instance.ipynb | 55 +++--- 5 files changed, 172 insertions(+), 212 deletions(-) diff --git a/panoptica/example_config.ipynb b/panoptica/example_config.ipynb index 5734fd2..79e75d7 100644 --- a/panoptica/example_config.ipynb +++ b/panoptica/example_config.ipynb @@ -16,39 +16,11 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: panoptica in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 1)) (1.0.0.post2.dev0+2f7d01f)\n", - "Requirement already satisfied: auxiliary in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 2)) (0.0.42)\n", - "Requirement already satisfied: rich in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 3)) (13.6.0)\n", - "Requirement already satisfied: numpy in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 4)) (1.25.2)\n", - "Requirement already satisfied: connected-components-3d<4.0.0,>=3.12.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (3.12.3)\n", - "Requirement already satisfied: ruamel.yaml<0.19.0,>=0.18.6 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.18.6)\n", - "Requirement already satisfied: scikit-image<0.23.0,>=0.22.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.22.0)\n", - "Requirement already satisfied: scipy<2.0.0,>=1.7.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (1.11.2)\n", - "Requirement already satisfied: nibabel>=3.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (5.1.0)\n", - "Requirement already satisfied: path>=16.10.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (17.0.0)\n", - "Requirement already satisfied: pathlib>=1.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (1.0.1)\n", - "Requirement already satisfied: pillow>=10.0.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (10.0.0)\n", - "Requirement already satisfied: tifffile>=2023.8.25 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (2023.8.30)\n", - "Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (3.0.0)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (2.17.2)\n", - "Requirement already satisfied: mdurl~=0.1 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich->-r requirements.txt (line 3)) (0.1.2)\n", - "Requirement already satisfied: packaging>=17 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from nibabel>=3.0->auxiliary->-r requirements.txt (line 2)) (23.1)\n", - "Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from ruamel.yaml<0.19.0,>=0.18.6->panoptica->-r requirements.txt (line 1)) (0.2.8)\n", - "Requirement already satisfied: networkx>=2.8 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (3.1)\n", - "Requirement already satisfied: imageio>=2.27 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (2.31.3)\n", - "Requirement already satisfied: lazy_loader>=0.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (0.3)\n" - ] - } - ], + "outputs": [], "source": [ - "!pip install -r requirements.txt" + "!pip install -r requirements.txt > /dev/null" ] }, { @@ -60,9 +32,18 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No module named 'pandas'\n", + "OPTIONAL PACKAGE MISSING\n" + ] + } + ], "source": [ "import numpy as np\n", "from auxiliary.nifti.io import read_nifti\n", @@ -90,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -102,7 +83,7 @@ " 106, 107, 108, 202, 203, 204, 205, 206, 207, 208], dtype=uint8))" ] }, - "execution_count": 11, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -124,9 +105,74 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 4, "metadata": {}, "outputs": [ + { + "data": { + "text/html": [ + "
────────────────────────────────────────── Thank you for using panoptica ──────────────────────────────────────────\n",
+              "
\n" + ], + "text/plain": [ + "\u001b[92m────────────────────────────────────────── \u001b[0mThank you for using \u001b[1mpanoptica\u001b[0m\u001b[92m ──────────────────────────────────────────\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
                                     Please support our development by citing                                      \n",
+              "
\n" + ], + "text/plain": [ + " Please support our development by citing \n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
                          https://github.com/BrainLesion/panoptica#citation -- Thank you!                          \n",
+              "
\n" + ], + "text/plain": [ + " \u001b[4;94mhttps://github.com/BrainLesion/panoptica#citation\u001b[0m -- Thank you! \n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n",
+              "
\n" + ], + "text/plain": [ + "\u001b[92m───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n",
+              "
\n" + ], + "text/plain": [ + "\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdout", "output_type": "stream", @@ -156,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -202,14 +248,14 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Saved config into /DATA/NAS/ongoing_projects/hendrik/panoptica/repo/panoptica/test_config.yaml\n" + "Saved config into /home/marcelrosier/miniconda3/envs/tutorials/lib/python3.10/site-packages/panoptica/test_config.yaml\n" ] } ], @@ -238,14 +284,14 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n" + "\n" ] } ], @@ -256,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -267,9 +313,9 @@ "-- Got MatchedInstancePair, will evaluate instances\n", "\n", "+++ MATCHING +++\n", - "Number of instances in reference (num_ref_instances): 1\n", - "Number of instances in prediction (num_pred_instances): 1\n", - "True Positives (tp): 1\n", + "Number of instances in reference (num_ref_instances): 22\n", + "Number of instances in prediction (num_pred_instances): 22\n", + "True Positives (tp): 22\n", "False Positives (fp): 0\n", "False Negatives (fn): 0\n", "Recognition Quality / F1-Score (rq): 1.0\n", @@ -278,12 +324,12 @@ "Global Binary Dice (global_bin_dsc): 0.9744370224078394\n", "\n", "+++ INSTANCE +++\n", - "Segmentation Quality IoU (sq): 0.9501484001456879 +- 0.0\n", - "Panoptic Quality IoU (pq): 0.9501484001456879\n", - "Segmentation Quality Dsc (sq_dsc): 0.9744370224078394 +- 0.0\n", - "Panoptic Quality Dsc (pq_dsc): 0.9744370224078394\n", - "Segmentation Quality ASSD (sq_assd): 0.1499152780072207 +- 0.0\n", - "Segmentation Quality Relative Volume Difference (sq_rvd): -0.0006011763989268869 +- 0.0\n", + "Segmentation Quality IoU (sq): 0.8328184295330796 +- 0.15186064004517466\n", + "Panoptic Quality IoU (pq): 0.8328184295330796\n", + "Segmentation Quality Dsc (sq_dsc): 0.900292616009954 +- 0.10253566174957332\n", + "Panoptic Quality Dsc (pq_dsc): 0.900292616009954\n", + "Segmentation Quality ASSD (sq_assd): 0.250331887879225 +- 0.07696680402317076\n", + "Segmentation Quality Relative Volume Difference (sq_rvd): 0.0028133049062930553 +- 0.034518928495505724\n", "\n" ] } @@ -293,13 +339,6 @@ "result, debug_data = evaluator.evaluate(pred_masks, ref_masks)[\"ungrouped\"]\n", "print(result) # yields same results as the evaluator object manually constructed" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -318,7 +357,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.6" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/panoptica/example_spine_matched_instance.ipynb b/panoptica/example_spine_matched_instance.ipynb index e20a019..541511e 100644 --- a/panoptica/example_spine_matched_instance.ipynb +++ b/panoptica/example_spine_matched_instance.ipynb @@ -18,37 +18,9 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: panoptica in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 1)) (1.0.0.post2.dev0+2f7d01f)\n", - "Requirement already satisfied: auxiliary in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 2)) (0.0.42)\n", - "Requirement already satisfied: rich in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 3)) (13.6.0)\n", - "Requirement already satisfied: numpy in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 4)) (1.25.2)\n", - "Requirement already satisfied: connected-components-3d<4.0.0,>=3.12.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (3.12.3)\n", - "Requirement already satisfied: ruamel.yaml<0.19.0,>=0.18.6 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.18.6)\n", - "Requirement already satisfied: scikit-image<0.23.0,>=0.22.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.22.0)\n", - "Requirement already satisfied: scipy<2.0.0,>=1.7.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (1.11.2)\n", - "Requirement already satisfied: nibabel>=3.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (5.1.0)\n", - "Requirement already satisfied: path>=16.10.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (17.0.0)\n", - "Requirement already satisfied: pathlib>=1.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (1.0.1)\n", - "Requirement already satisfied: pillow>=10.0.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (10.0.0)\n", - "Requirement already satisfied: tifffile>=2023.8.25 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (2023.8.30)\n", - "Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (3.0.0)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (2.17.2)\n", - "Requirement already satisfied: mdurl~=0.1 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich->-r requirements.txt (line 3)) (0.1.2)\n", - "Requirement already satisfied: packaging>=17 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from nibabel>=3.0->auxiliary->-r requirements.txt (line 2)) (23.1)\n", - "Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from ruamel.yaml<0.19.0,>=0.18.6->panoptica->-r requirements.txt (line 1)) (0.2.8)\n", - "Requirement already satisfied: networkx>=2.8 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (3.1)\n", - "Requirement already satisfied: imageio>=2.27 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (2.31.3)\n", - "Requirement already satisfied: lazy_loader>=0.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (0.3)\n" - ] - } - ], + "outputs": [], "source": [ - "!pip install -r requirements.txt" + "!pip install -r requirements.txt > /dev/null" ] }, { @@ -62,7 +34,16 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No module named 'pandas'\n", + "OPTIONAL PACKAGE MISSING\n" + ] + } + ], "source": [ "import numpy as np\n", "from auxiliary.nifti.io import read_nifti\n", @@ -348,7 +329,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -397,7 +378,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.6" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/panoptica/example_spine_matching_algorithm.ipynb b/panoptica/example_spine_matching_algorithm.ipynb index b623947..11cc3c2 100644 --- a/panoptica/example_spine_matching_algorithm.ipynb +++ b/panoptica/example_spine_matching_algorithm.ipynb @@ -16,39 +16,11 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 7, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: panoptica in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 1)) (1.0.0.post2.dev0+2f7d01f)\n", - "Requirement already satisfied: auxiliary in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 2)) (0.0.42)\n", - "Requirement already satisfied: rich in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 3)) (13.6.0)\n", - "Requirement already satisfied: numpy in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 4)) (1.25.2)\n", - "Requirement already satisfied: connected-components-3d<4.0.0,>=3.12.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (3.12.3)\n", - "Requirement already satisfied: ruamel.yaml<0.19.0,>=0.18.6 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.18.6)\n", - "Requirement already satisfied: scikit-image<0.23.0,>=0.22.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.22.0)\n", - "Requirement already satisfied: scipy<2.0.0,>=1.7.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (1.11.2)\n", - "Requirement already satisfied: nibabel>=3.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (5.1.0)\n", - "Requirement already satisfied: path>=16.10.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (17.0.0)\n", - "Requirement already satisfied: pathlib>=1.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (1.0.1)\n", - "Requirement already satisfied: pillow>=10.0.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (10.0.0)\n", - "Requirement already satisfied: tifffile>=2023.8.25 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (2023.8.30)\n", - "Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (3.0.0)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (2.17.2)\n", - "Requirement already satisfied: mdurl~=0.1 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich->-r requirements.txt (line 3)) (0.1.2)\n", - "Requirement already satisfied: packaging>=17 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from nibabel>=3.0->auxiliary->-r requirements.txt (line 2)) (23.1)\n", - "Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from ruamel.yaml<0.19.0,>=0.18.6->panoptica->-r requirements.txt (line 1)) (0.2.8)\n", - "Requirement already satisfied: networkx>=2.8 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (3.1)\n", - "Requirement already satisfied: imageio>=2.27 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (2.31.3)\n", - "Requirement already satisfied: lazy_loader>=0.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (0.3)\n" - ] - } - ], + "outputs": [], "source": [ - "!pip install -r requirements.txt" + "!pip install -r requirements.txt > /dev/null" ] }, { @@ -60,7 +32,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -90,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -102,7 +74,7 @@ " 107, 108, 109, 203, 204, 205, 206, 207, 208, 209], dtype=uint8))" ] }, - "execution_count": 3, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -125,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -152,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -197,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -253,7 +225,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.6" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/panoptica/example_spine_semantic.ipynb b/panoptica/example_spine_semantic.ipynb index 44bafff..df7979f 100644 --- a/panoptica/example_spine_semantic.ipynb +++ b/panoptica/example_spine_semantic.ipynb @@ -18,37 +18,9 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: panoptica in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 1)) (1.0.0.post2.dev0+2f7d01f)\n", - "Requirement already satisfied: auxiliary in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 2)) (0.0.42)\n", - "Requirement already satisfied: rich in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 3)) (13.6.0)\n", - "Requirement already satisfied: numpy in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 4)) (1.25.2)\n", - "Requirement already satisfied: connected-components-3d<4.0.0,>=3.12.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (3.12.3)\n", - "Requirement already satisfied: ruamel.yaml<0.19.0,>=0.18.6 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.18.6)\n", - "Requirement already satisfied: scikit-image<0.23.0,>=0.22.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.22.0)\n", - "Requirement already satisfied: scipy<2.0.0,>=1.7.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (1.11.2)\n", - "Requirement already satisfied: nibabel>=3.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (5.1.0)\n", - "Requirement already satisfied: path>=16.10.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (17.0.0)\n", - "Requirement already satisfied: pathlib>=1.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (1.0.1)\n", - "Requirement already satisfied: pillow>=10.0.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (10.0.0)\n", - "Requirement already satisfied: tifffile>=2023.8.25 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (2023.8.30)\n", - "Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (3.0.0)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (2.17.2)\n", - "Requirement already satisfied: mdurl~=0.1 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich->-r requirements.txt (line 3)) (0.1.2)\n", - "Requirement already satisfied: packaging>=17 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from nibabel>=3.0->auxiliary->-r requirements.txt (line 2)) (23.1)\n", - "Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from ruamel.yaml<0.19.0,>=0.18.6->panoptica->-r requirements.txt (line 1)) (0.2.8)\n", - "Requirement already satisfied: networkx>=2.8 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (3.1)\n", - "Requirement already satisfied: imageio>=2.27 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (2.31.3)\n", - "Requirement already satisfied: lazy_loader>=0.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (0.3)\n" - ] - } - ], + "outputs": [], "source": [ - "!pip install -r requirements.txt" + "!pip install -r requirements.txt > /dev/null" ] }, { @@ -62,7 +34,16 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No module named 'pandas'\n", + "OPTIONAL PACKAGE MISSING\n" + ] + } + ], "source": [ "from auxiliary.nifti.io import read_nifti\n", "from rich import print as pprint\n", @@ -231,10 +212,10 @@ "+++ INSTANCE +++\n", "Segmentation Quality IoU (sq): 0.7940127477906024 +- 0.11547745015679488\n", "Panoptic Quality IoU (pq): 0.6586696657808406\n", - "Segmentation Quality Dsc (sq_dsc): 0.8802182546605446 +- 0.07728416427007168\n", + "Segmentation Quality Dsc (sq_dsc): 0.8802182546605446 +- 0.07728416427007166\n", "Panoptic Quality Dsc (pq_dsc): 0.7301810521615881\n", - "Segmentation Quality ASSD (sq_assd): 0.2057371092494465 +- 0.1398348236766068\n", - "Segmentation Quality Relative Volume Difference (sq_rvd): 0.011340219860617232 +- 0.1217805112447998\n", + "Segmentation Quality ASSD (sq_assd): 0.20573710924944655 +- 0.13983482367660682\n", + "Segmentation Quality Relative Volume Difference (sq_rvd): 0.01134021986061723 +- 0.1217805112447998\n", "\n" ] } @@ -293,11 +274,11 @@ " 'sq_std': 0.11547745015679488,\n", " 'pq': 0.6586696657808406,\n", " 'sq_dsc': 0.8802182546605446,\n", - " 'sq_dsc_std': 0.07728416427007168,\n", + " 'sq_dsc_std': 0.07728416427007166,\n", " 'pq_dsc': 0.7301810521615881,\n", - " 'sq_assd': 0.2057371092494465,\n", - " 'sq_assd_std': 0.1398348236766068,\n", - " 'sq_rvd': 0.011340219860617232,\n", + " 'sq_assd': 0.20573710924944655,\n", + " 'sq_assd_std': 0.13983482367660682,\n", + " 'sq_rvd': 0.01134021986061723,\n", " 'sq_rvd_std': 0.1217805112447998,\n", " 'global_bin_dsc': 0.9731641527805414\n", "}\n", @@ -318,11 +299,11 @@ " \u001b[32m'sq_std'\u001b[0m: \u001b[1;36m0.11547745015679488\u001b[0m,\n", " \u001b[32m'pq'\u001b[0m: \u001b[1;36m0.6586696657808406\u001b[0m,\n", " \u001b[32m'sq_dsc'\u001b[0m: \u001b[1;36m0.8802182546605446\u001b[0m,\n", - " \u001b[32m'sq_dsc_std'\u001b[0m: \u001b[1;36m0.07728416427007168\u001b[0m,\n", + " \u001b[32m'sq_dsc_std'\u001b[0m: \u001b[1;36m0.07728416427007166\u001b[0m,\n", " \u001b[32m'pq_dsc'\u001b[0m: \u001b[1;36m0.7301810521615881\u001b[0m,\n", - " \u001b[32m'sq_assd'\u001b[0m: \u001b[1;36m0.2057371092494465\u001b[0m,\n", - " \u001b[32m'sq_assd_std'\u001b[0m: \u001b[1;36m0.1398348236766068\u001b[0m,\n", - " \u001b[32m'sq_rvd'\u001b[0m: \u001b[1;36m0.011340219860617232\u001b[0m,\n", + " \u001b[32m'sq_assd'\u001b[0m: \u001b[1;36m0.20573710924944655\u001b[0m,\n", + " \u001b[32m'sq_assd_std'\u001b[0m: \u001b[1;36m0.13983482367660682\u001b[0m,\n", + " \u001b[32m'sq_rvd'\u001b[0m: \u001b[1;36m0.01134021986061723\u001b[0m,\n", " \u001b[32m'sq_rvd_std'\u001b[0m: \u001b[1;36m0.1217805112447998\u001b[0m,\n", " \u001b[32m'global_bin_dsc'\u001b[0m: \u001b[1;36m0.9731641527805414\u001b[0m\n", "\u001b[1m}\u001b[0m\n" @@ -361,11 +342,11 @@ " 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87]\n", "\n", "InputType.MATCHED_INSTANCE\n", - "Prediction array shape = (170, 512, 17) unique_values= [ 0 1 2 4 5 6 9 10 12 13 14 15 16 17 18 19 20 21\n", - " 22 23 24 25 26 27 28 29 30 32 33 34 35 36 37 38 39 41\n", - " 42 43 44 45 49 50 51 52 54 55 56 57 58 60 61 62 63 64\n", - " 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82\n", - " 83 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103]\n", + "Prediction array shape = (170, 512, 17) unique_values= [ 0 1 2 3 4 6 7 8 9 10 12 13 14 15 16 17 18 19\n", + " 20 22 23 25 26 31 33 34 35 38 40 41 42 44 45 46 47 48\n", + " 49 50 51 52 53 54 55 56 57 58 59 60 61 63 64 65 66 67\n", + " 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85\n", + " 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103]\n", "Reference array shape = (170, 512, 17) unique_values= [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n", " 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47\n", " 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71\n", @@ -416,7 +397,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.6" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/panoptica/example_spine_unmatched_instance.ipynb b/panoptica/example_spine_unmatched_instance.ipynb index d994a5a..01ce608 100644 --- a/panoptica/example_spine_unmatched_instance.ipynb +++ b/panoptica/example_spine_unmatched_instance.ipynb @@ -18,37 +18,9 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: panoptica in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 1)) (1.0.0.post2.dev0+2f7d01f)\n", - "Requirement already satisfied: auxiliary in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 2)) (0.0.42)\n", - "Requirement already satisfied: rich in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 3)) (13.6.0)\n", - "Requirement already satisfied: numpy in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from -r requirements.txt (line 4)) (1.25.2)\n", - "Requirement already satisfied: connected-components-3d<4.0.0,>=3.12.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (3.12.3)\n", - "Requirement already satisfied: ruamel.yaml<0.19.0,>=0.18.6 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.18.6)\n", - "Requirement already satisfied: scikit-image<0.23.0,>=0.22.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (0.22.0)\n", - "Requirement already satisfied: scipy<2.0.0,>=1.7.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from panoptica->-r requirements.txt (line 1)) (1.11.2)\n", - "Requirement already satisfied: nibabel>=3.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (5.1.0)\n", - "Requirement already satisfied: path>=16.10.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (17.0.0)\n", - "Requirement already satisfied: pathlib>=1.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (1.0.1)\n", - "Requirement already satisfied: pillow>=10.0.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (10.0.0)\n", - "Requirement already satisfied: tifffile>=2023.8.25 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from auxiliary->-r requirements.txt (line 2)) (2023.8.30)\n", - "Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (3.0.0)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from rich->-r requirements.txt (line 3)) (2.17.2)\n", - "Requirement already satisfied: mdurl~=0.1 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich->-r requirements.txt (line 3)) (0.1.2)\n", - "Requirement already satisfied: packaging>=17 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from nibabel>=3.0->auxiliary->-r requirements.txt (line 2)) (23.1)\n", - "Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from ruamel.yaml<0.19.0,>=0.18.6->panoptica->-r requirements.txt (line 1)) (0.2.8)\n", - "Requirement already satisfied: networkx>=2.8 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (3.1)\n", - "Requirement already satisfied: imageio>=2.27 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (2.31.3)\n", - "Requirement already satisfied: lazy_loader>=0.3 in /opt/anaconda3/envs/seg11panoptdev/lib/python3.11/site-packages (from scikit-image<0.23.0,>=0.22.0->panoptica->-r requirements.txt (line 1)) (0.3)\n" - ] - } - ], + "outputs": [], "source": [ - "!pip install -r requirements.txt" + "!pip install -r requirements.txt > /dev/null" ] }, { @@ -62,7 +34,16 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No module named 'pandas'\n", + "OPTIONAL PACKAGE MISSING\n" + ] + } + ], "source": [ "import numpy as np\n", "from auxiliary.nifti.io import read_nifti\n", @@ -425,7 +406,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -449,7 +430,13 @@ "Reference array shape = (96, 406, 17) unique_values= [ 0 102 103 104 105 106 107 108]\n", "\n", "InputType.MATCHED_INSTANCE\n", - "Prediction array shape = (96, 406, 17) unique_values= [ 0 102 103 104 105 106 107 108]\n", + "Prediction array shape = (96, 406, 17) unique_values= [ 0 102 103 104 105 106 107 108]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "Reference array shape = (96, 406, 17) unique_values= [ 0 102 103 104 105 106 107 108]\n", "\n", "\n", @@ -522,7 +509,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.6" + "version": "3.10.14" } }, "nbformat": 4, From a4f9d06c283fca38dd3db1a600c14af66837ae59 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Fri, 13 Sep 2024 14:45:17 +0200 Subject: [PATCH 3/8] Add example images to readme --- panoptica/README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/panoptica/README.md b/panoptica/README.md index 8fbcbeb..57f1867 100644 --- a/panoptica/README.md +++ b/panoptica/README.md @@ -1,9 +1,13 @@ # Panoptica Tutorials -This folder contains several Jupyter notebooks to showcase different possible use cases of the [panoptica package](https://github.com/BrainLesion/panoptica). +This folder contains several Jupyter notebooks to showcase different possible use cases of the [panoptica package](https://github.com/BrainLesion/panoptica). +The package allows to compute instance-wise segmentation quality metrics for 2D and 3D semantic- and instance segmentation maps. ## Notebooks ### Semantic: Spine example + +semantic_figure + `example_spine_semantic.ipynb` [![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/BrainLesion/tutorials/blob/main/panoptica/example_spine_semantic.ipynb) @@ -12,6 +16,10 @@ This folder contains several Jupyter notebooks to showcase different possible us ### Matched Instance: Spine example + +matched_instance_figure + + `example_spine_matched_instance.ipynb` [![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/BrainLesion/tutorials/blob/main/panoptica/example_spine_matched_instance.ipynb) @@ -19,8 +27,10 @@ This folder contains several Jupyter notebooks to showcase different possible us Open In Colab - ### Unmatched Instance: Spine example + +unmatched_instance_figure + `example_spine_unmatched_instance.ipynb` [![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.jupyter.org/github/BrainLesion/tutorials/blob/main/panoptica/example_spine_unmatched_instance.ipynb) @@ -29,6 +39,7 @@ This folder contains several Jupyter notebooks to showcase different possible us + ### Matching: Spine example `example_spine_matching_algorithm.ipynb` From 89f635416b14ec89ce70a2fa17b4980f419a4bd9 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Fri, 13 Sep 2024 14:52:09 +0200 Subject: [PATCH 4/8] WIP: Setup for colab usage --- panoptica/example_spine_semantic.ipynb | 82 +++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 9 deletions(-) diff --git a/panoptica/example_spine_semantic.ipynb b/panoptica/example_spine_semantic.ipynb index df7979f..fbdd292 100644 --- a/panoptica/example_spine_semantic.ipynb +++ b/panoptica/example_spine_semantic.ipynb @@ -27,13 +27,77 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Setup Imports" + "If you installed the packages and requirements on your own machine, you can skip this section and start from the import section.\n", + "\n", + "### Setup Colab environment (optional) \n", + "Otherwise you can follow and execute the tutorial on your browser.\n", + "In order to start working on the notebook, click on the following button, this will open this page in the Colab environment and you will be able to execute the code on your own (*Google account required*).\n", + "\n", + "\n", + " \"Open\n", + "\n", + "\n", + "Now that you are visualizing the notebook in Colab, run the next cell to install the packages we will use. There are few things you should follow in order to properly set the notebook up:\n", + "1. Warning: This notebook was not authored by Google. Click on 'Run anyway'.\n", + "1. When the installation commands are done, there might be \"Restart runtime\" button at the end of the output. Please, click it." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you run the next cell in a Google Colab environment, it will **clone the 'tutorials' repository** in your google drive. This will create a **new folder** called \"tutorials\" in **your Google Drive**.\n", + "All generated file will be created/uploaded to your Google Drive respectively.\n", + "\n", + "After the first execution of the next cell, you might receive some warnings and notifications, please follow these instructions:\n", + " - 'Permit this notebook to access your Google Drive files?' Click on 'Yes', and select your account.\n", + " - Google Drive for desktop wants to access your Google Account. Click on 'Allow'.\n", + "\n", + "Afterwards the \"tutorials\" folder has been created. You can navigate it through the lefthand panel in Colab. You might also have received an email that informs you about the access on your Google Drive." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "# Check if we are in google colab currently\n", + "try:\n", + " import google.colab\n", + "\n", + " colabFlag = True\n", + "except ImportError as r:\n", + " colabFlag = False\n", + "\n", + "# Execute certain steps only if we are in a colab environment\n", + "if colabFlag:\n", + " # Create a folder in your Google Drive\n", + " from google.colab import drive\n", + "\n", + " drive.mount(\"/content/drive\")\n", + " # clone repository and set path\n", + " !git clone https://github.com/BrainLesion/tutorials.git /content/drive/MyDrive/tutorials\n", + " BASE_PATH = \"/content/drive/MyDrive/tutorials/panoptica\"\n", + " sys.path.insert(0, BASE_PATH)\n", + "\n", + "else: # normal jupyter notebook environment\n", + " BASE_PATH = \".\" # current working directory would be BraTs-Toolkit anyways if you are not in colab" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -73,12 +137,12 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "ref_masks = read_nifti(\"./spine_seg/semantic/ref.nii.gz\")\n", - "pred_masks = read_nifti(\"./spine_seg/semantic/pred.nii.gz\")" + "ref_masks = read_nifti(f\"{BASE_PATH}/spine_seg/semantic/ref.nii.gz\")\n", + "pred_masks = read_nifti(f\"{BASE_PATH}/spine_seg/semantic/pred.nii.gz\")" ] }, { @@ -104,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -125,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -230,7 +294,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -254,7 +318,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -320,7 +384,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { From 114bb31f56e046ab29ebe44d2a58fe32f427298c Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Fri, 13 Sep 2024 14:55:39 +0200 Subject: [PATCH 5/8] Fix colab link --- panoptica/example_spine_semantic.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panoptica/example_spine_semantic.ipynb b/panoptica/example_spine_semantic.ipynb index fbdd292..8261a72 100644 --- a/panoptica/example_spine_semantic.ipynb +++ b/panoptica/example_spine_semantic.ipynb @@ -33,7 +33,7 @@ "Otherwise you can follow and execute the tutorial on your browser.\n", "In order to start working on the notebook, click on the following button, this will open this page in the Colab environment and you will be able to execute the code on your own (*Google account required*).\n", "\n", - "\n", + "\n", " \"Open\n", "\n", "\n", From 233b3f94e20d223e65ce7b1d735acb3dcc4a6f47 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Fri, 13 Sep 2024 15:00:04 +0200 Subject: [PATCH 6/8] Replace requirements file with direct pip install --- panoptica/example_config.ipynb | 2 +- panoptica/example_spine_matched_instance.ipynb | 2 +- panoptica/example_spine_matching_algorithm.ipynb | 2 +- panoptica/example_spine_semantic.ipynb | 4 ++-- panoptica/example_spine_unmatched_instance.ipynb | 2 +- panoptica/requirements.txt | 4 ---- 6 files changed, 6 insertions(+), 10 deletions(-) delete mode 100644 panoptica/requirements.txt diff --git a/panoptica/example_config.ipynb b/panoptica/example_config.ipynb index 79e75d7..51a02a5 100644 --- a/panoptica/example_config.ipynb +++ b/panoptica/example_config.ipynb @@ -20,7 +20,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -r requirements.txt > /dev/null" + "!pip install panoptica auxiliary rich numpy > /dev/null" ] }, { diff --git a/panoptica/example_spine_matched_instance.ipynb b/panoptica/example_spine_matched_instance.ipynb index 541511e..67316b1 100644 --- a/panoptica/example_spine_matched_instance.ipynb +++ b/panoptica/example_spine_matched_instance.ipynb @@ -20,7 +20,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -r requirements.txt > /dev/null" + "!pip install panoptica auxiliary rich numpy > /dev/null" ] }, { diff --git a/panoptica/example_spine_matching_algorithm.ipynb b/panoptica/example_spine_matching_algorithm.ipynb index 11cc3c2..ed79a33 100644 --- a/panoptica/example_spine_matching_algorithm.ipynb +++ b/panoptica/example_spine_matching_algorithm.ipynb @@ -20,7 +20,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -r requirements.txt > /dev/null" + "!pip install panoptica auxiliary rich numpy > /dev/null" ] }, { diff --git a/panoptica/example_spine_semantic.ipynb b/panoptica/example_spine_semantic.ipynb index 8261a72..57db7ec 100644 --- a/panoptica/example_spine_semantic.ipynb +++ b/panoptica/example_spine_semantic.ipynb @@ -16,11 +16,11 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "!pip install -r requirements.txt > /dev/null" + "!pip install panoptica auxiliary rich numpy > /dev/null" ] }, { diff --git a/panoptica/example_spine_unmatched_instance.ipynb b/panoptica/example_spine_unmatched_instance.ipynb index 01ce608..ef6020f 100644 --- a/panoptica/example_spine_unmatched_instance.ipynb +++ b/panoptica/example_spine_unmatched_instance.ipynb @@ -20,7 +20,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -r requirements.txt > /dev/null" + "!pip install panoptica auxiliary rich numpy > /dev/null" ] }, { diff --git a/panoptica/requirements.txt b/panoptica/requirements.txt deleted file mode 100644 index 21d8918..0000000 --- a/panoptica/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -panoptica -auxiliary -rich -numpy \ No newline at end of file From 4b4362ad3f25daf5d7093176d4a055533b573d36 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Fri, 13 Sep 2024 15:26:28 +0200 Subject: [PATCH 7/8] Add colab setup section Merge cells --- panoptica/example_config.ipynb | 76 +++++++++++++++-- .../example_spine_matched_instance.ipynb | 74 +++++++++++++++-- .../example_spine_matching_algorithm.ipynb | 83 +++++++++++++++++-- panoptica/example_spine_semantic.ipynb | 8 +- .../example_spine_unmatched_instance.ipynb | 82 ++++++++++++++---- 5 files changed, 276 insertions(+), 47 deletions(-) diff --git a/panoptica/example_config.ipynb b/panoptica/example_config.ipynb index 51a02a5..fddeb67 100644 --- a/panoptica/example_config.ipynb +++ b/panoptica/example_config.ipynb @@ -27,13 +27,71 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Setup Imports" + "If you installed the packages and requirements on your own machine, you can skip this section and start from the import section.\n", + "\n", + "### Setup Colab environment (optional) \n", + "Otherwise you can follow and execute the tutorial on your browser.\n", + "In order to start working on the notebook, click on the following button, this will open this page in the Colab environment and you will be able to execute the code on your own (*Google account required*).\n", + "\n", + "\n", + " \"Open\n", + "\n", + "\n", + "Now that you are visualizing the notebook in Colab, run the next cell to install the packages we will use. There are few things you should follow in order to properly set the notebook up:\n", + "1. Warning: This notebook was not authored by Google. Click on 'Run anyway'.\n", + "1. When the installation commands are done, there might be \"Restart runtime\" button at the end of the output. Please, click it.\n", + "If you run the next cell in a Google Colab environment, it will **clone the 'tutorials' repository** in your google drive. This will create a **new folder** called \"tutorials\" in **your Google Drive**.\n", + "All generated file will be created/uploaded to your Google Drive respectively.\n", + "\n", + "After the first execution of the next cell, you might receive some warnings and notifications, please follow these instructions:\n", + " - 'Permit this notebook to access your Google Drive files?' Click on 'Yes', and select your account.\n", + " - Google Drive for desktop wants to access your Google Account. Click on 'Allow'.\n", + "\n", + "Afterwards the \"tutorials\" folder has been created. You can navigate it through the lefthand panel in Colab. You might also have received an email that informs you about the access on your Google Drive." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "# Check if we are in google colab currently\n", + "try:\n", + " import google.colab\n", + "\n", + " colabFlag = True\n", + "except ImportError as r:\n", + " colabFlag = False\n", + "\n", + "# Execute certain steps only if we are in a colab environment\n", + "if colabFlag:\n", + " # Create a folder in your Google Drive\n", + " from google.colab import drive\n", + "\n", + " drive.mount(\"/content/drive\")\n", + " # clone repository and set path\n", + " !git clone https://github.com/BrainLesion/tutorials.git /content/drive/MyDrive/tutorials\n", + " BASE_PATH = \"/content/drive/MyDrive/tutorials/panoptica\"\n", + " sys.path.insert(0, BASE_PATH)\n", + "\n", + "else: # normal jupyter notebook environment\n", + " BASE_PATH = \".\" # current working directory would be BraTs-Toolkit anyways if you are not in colab" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -71,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -83,7 +141,7 @@ " 106, 107, 108, 202, 203, 204, 205, 206, 207, 208], dtype=uint8))" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -105,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -202,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -248,7 +306,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -284,14 +342,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n" + "\n" ] } ], @@ -302,7 +360,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { diff --git a/panoptica/example_spine_matched_instance.ipynb b/panoptica/example_spine_matched_instance.ipynb index 67316b1..7dbc285 100644 --- a/panoptica/example_spine_matched_instance.ipynb +++ b/panoptica/example_spine_matched_instance.ipynb @@ -27,13 +27,71 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Setup Imports" + "If you installed the packages and requirements on your own machine, you can skip this section and start from the import section.\n", + "\n", + "### Setup Colab environment (optional) \n", + "Otherwise you can follow and execute the tutorial on your browser.\n", + "In order to start working on the notebook, click on the following button, this will open this page in the Colab environment and you will be able to execute the code on your own (*Google account required*).\n", + "\n", + "\n", + " \"Open\n", + "\n", + "\n", + "Now that you are visualizing the notebook in Colab, run the next cell to install the packages we will use. There are few things you should follow in order to properly set the notebook up:\n", + "1. Warning: This notebook was not authored by Google. Click on 'Run anyway'.\n", + "1. When the installation commands are done, there might be \"Restart runtime\" button at the end of the output. Please, click it.\n", + "If you run the next cell in a Google Colab environment, it will **clone the 'tutorials' repository** in your google drive. This will create a **new folder** called \"tutorials\" in **your Google Drive**.\n", + "All generated file will be created/uploaded to your Google Drive respectively.\n", + "\n", + "After the first execution of the next cell, you might receive some warnings and notifications, please follow these instructions:\n", + " - 'Permit this notebook to access your Google Drive files?' Click on 'Yes', and select your account.\n", + " - Google Drive for desktop wants to access your Google Account. Click on 'Allow'.\n", + "\n", + "Afterwards the \"tutorials\" folder has been created. You can navigate it through the lefthand panel in Colab. You might also have received an email that informs you about the access on your Google Drive." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "# Check if we are in google colab currently\n", + "try:\n", + " import google.colab\n", + "\n", + " colabFlag = True\n", + "except ImportError as r:\n", + " colabFlag = False\n", + "\n", + "# Execute certain steps only if we are in a colab environment\n", + "if colabFlag:\n", + " # Create a folder in your Google Drive\n", + " from google.colab import drive\n", + "\n", + " drive.mount(\"/content/drive\")\n", + " # clone repository and set path\n", + " !git clone https://github.com/BrainLesion/tutorials.git /content/drive/MyDrive/tutorials\n", + " BASE_PATH = \"/content/drive/MyDrive/tutorials/panoptica\"\n", + " sys.path.insert(0, BASE_PATH)\n", + "\n", + "else: # normal jupyter notebook environment\n", + " BASE_PATH = \".\" # current working directory would be BraTs-Toolkit anyways if you are not in colab" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -71,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -83,7 +141,7 @@ " 106, 107, 108, 202, 203, 204, 205, 206, 207, 208], dtype=uint8))" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -105,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -202,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -239,7 +297,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -263,7 +321,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -329,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { diff --git a/panoptica/example_spine_matching_algorithm.ipynb b/panoptica/example_spine_matching_algorithm.ipynb index ed79a33..f0b081c 100644 --- a/panoptica/example_spine_matching_algorithm.ipynb +++ b/panoptica/example_spine_matching_algorithm.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -27,14 +27,81 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Setup Imports" + "If you installed the packages and requirements on your own machine, you can skip this section and start from the import section.\n", + "\n", + "### Setup Colab environment (optional) \n", + "Otherwise you can follow and execute the tutorial on your browser.\n", + "In order to start working on the notebook, click on the following button, this will open this page in the Colab environment and you will be able to execute the code on your own (*Google account required*).\n", + "\n", + "\n", + " \"Open\n", + "\n", + "\n", + "Now that you are visualizing the notebook in Colab, run the next cell to install the packages we will use. There are few things you should follow in order to properly set the notebook up:\n", + "1. Warning: This notebook was not authored by Google. Click on 'Run anyway'.\n", + "1. When the installation commands are done, there might be \"Restart runtime\" button at the end of the output. Please, click it.\n", + "If you run the next cell in a Google Colab environment, it will **clone the 'tutorials' repository** in your google drive. This will create a **new folder** called \"tutorials\" in **your Google Drive**.\n", + "All generated file will be created/uploaded to your Google Drive respectively.\n", + "\n", + "After the first execution of the next cell, you might receive some warnings and notifications, please follow these instructions:\n", + " - 'Permit this notebook to access your Google Drive files?' Click on 'Yes', and select your account.\n", + " - Google Drive for desktop wants to access your Google Account. Click on 'Allow'.\n", + "\n", + "Afterwards the \"tutorials\" folder has been created. You can navigate it through the lefthand panel in Colab. You might also have received an email that informs you about the access on your Google Drive." ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 2, "metadata": {}, "outputs": [], + "source": [ + "import sys\n", + "\n", + "# Check if we are in google colab currently\n", + "try:\n", + " import google.colab\n", + "\n", + " colabFlag = True\n", + "except ImportError as r:\n", + " colabFlag = False\n", + "\n", + "# Execute certain steps only if we are in a colab environment\n", + "if colabFlag:\n", + " # Create a folder in your Google Drive\n", + " from google.colab import drive\n", + "\n", + " drive.mount(\"/content/drive\")\n", + " # clone repository and set path\n", + " !git clone https://github.com/BrainLesion/tutorials.git /content/drive/MyDrive/tutorials\n", + " BASE_PATH = \"/content/drive/MyDrive/tutorials/panoptica\"\n", + " sys.path.insert(0, BASE_PATH)\n", + "\n", + "else: # normal jupyter notebook environment\n", + " BASE_PATH = \".\" # current working directory would be BraTs-Toolkit anyways if you are not in colab" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No module named 'pandas'\n", + "OPTIONAL PACKAGE MISSING\n" + ] + } + ], "source": [ "import numpy as np\n", "from auxiliary.nifti.io import read_nifti\n", @@ -62,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -74,7 +141,7 @@ " 107, 108, 109, 203, 204, 205, 206, 207, 208, 209], dtype=uint8))" ] }, - "execution_count": 9, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -97,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -124,7 +191,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -169,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 7, "metadata": {}, "outputs": [ { diff --git a/panoptica/example_spine_semantic.ipynb b/panoptica/example_spine_semantic.ipynb index 57db7ec..7015c3c 100644 --- a/panoptica/example_spine_semantic.ipynb +++ b/panoptica/example_spine_semantic.ipynb @@ -39,13 +39,7 @@ "\n", "Now that you are visualizing the notebook in Colab, run the next cell to install the packages we will use. There are few things you should follow in order to properly set the notebook up:\n", "1. Warning: This notebook was not authored by Google. Click on 'Run anyway'.\n", - "1. When the installation commands are done, there might be \"Restart runtime\" button at the end of the output. Please, click it." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "1. When the installation commands are done, there might be \"Restart runtime\" button at the end of the output. Please, click it.\n", "If you run the next cell in a Google Colab environment, it will **clone the 'tutorials' repository** in your google drive. This will create a **new folder** called \"tutorials\" in **your Google Drive**.\n", "All generated file will be created/uploaded to your Google Drive respectively.\n", "\n", diff --git a/panoptica/example_spine_unmatched_instance.ipynb b/panoptica/example_spine_unmatched_instance.ipynb index ef6020f..52f62db 100644 --- a/panoptica/example_spine_unmatched_instance.ipynb +++ b/panoptica/example_spine_unmatched_instance.ipynb @@ -27,13 +27,71 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Setup Imports" + "If you installed the packages and requirements on your own machine, you can skip this section and start from the import section.\n", + "\n", + "### Setup Colab environment (optional) \n", + "Otherwise you can follow and execute the tutorial on your browser.\n", + "In order to start working on the notebook, click on the following button, this will open this page in the Colab environment and you will be able to execute the code on your own (*Google account required*).\n", + "\n", + "\n", + " \"Open\n", + "\n", + "\n", + "Now that you are visualizing the notebook in Colab, run the next cell to install the packages we will use. There are few things you should follow in order to properly set the notebook up:\n", + "1. Warning: This notebook was not authored by Google. Click on 'Run anyway'.\n", + "1. When the installation commands are done, there might be \"Restart runtime\" button at the end of the output. Please, click it.\n", + "If you run the next cell in a Google Colab environment, it will **clone the 'tutorials' repository** in your google drive. This will create a **new folder** called \"tutorials\" in **your Google Drive**.\n", + "All generated file will be created/uploaded to your Google Drive respectively.\n", + "\n", + "After the first execution of the next cell, you might receive some warnings and notifications, please follow these instructions:\n", + " - 'Permit this notebook to access your Google Drive files?' Click on 'Yes', and select your account.\n", + " - Google Drive for desktop wants to access your Google Account. Click on 'Allow'.\n", + "\n", + "Afterwards the \"tutorials\" folder has been created. You can navigate it through the lefthand panel in Colab. You might also have received an email that informs you about the access on your Google Drive." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "# Check if we are in google colab currently\n", + "try:\n", + " import google.colab\n", + "\n", + " colabFlag = True\n", + "except ImportError as r:\n", + " colabFlag = False\n", + "\n", + "# Execute certain steps only if we are in a colab environment\n", + "if colabFlag:\n", + " # Create a folder in your Google Drive\n", + " from google.colab import drive\n", + "\n", + " drive.mount(\"/content/drive\")\n", + " # clone repository and set path\n", + " !git clone https://github.com/BrainLesion/tutorials.git /content/drive/MyDrive/tutorials\n", + " BASE_PATH = \"/content/drive/MyDrive/tutorials/panoptica\"\n", + " sys.path.insert(0, BASE_PATH)\n", + "\n", + "else: # normal jupyter notebook environment\n", + " BASE_PATH = \".\" # current working directory would be BraTs-Toolkit anyways if you are not in colab" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -71,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -83,7 +141,7 @@ " 107, 108, 109, 203, 204, 205, 206, 207, 208, 209], dtype=uint8))" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -106,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -140,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -315,7 +373,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -340,7 +398,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -406,7 +464,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -430,13 +488,7 @@ "Reference array shape = (96, 406, 17) unique_values= [ 0 102 103 104 105 106 107 108]\n", "\n", "InputType.MATCHED_INSTANCE\n", - "Prediction array shape = (96, 406, 17) unique_values= [ 0 102 103 104 105 106 107 108]\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + "Prediction array shape = (96, 406, 17) unique_values= [ 0 102 103 104 105 106 107 108]\n", "Reference array shape = (96, 406, 17) unique_values= [ 0 102 103 104 105 106 107 108]\n", "\n", "\n", From db33c672d16645892b675c8bd42666518028c688 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Fri, 13 Sep 2024 15:33:09 +0200 Subject: [PATCH 8/8] Fix paths in colab env --- panoptica/example_config.ipynb | 102 +++--------------- .../example_spine_matched_instance.ipynb | 100 +++-------------- .../example_spine_matching_algorithm.ipynb | 4 +- .../example_spine_unmatched_instance.ipynb | 100 +++-------------- 4 files changed, 42 insertions(+), 264 deletions(-) diff --git a/panoptica/example_config.ipynb b/panoptica/example_config.ipynb index fddeb67..296b684 100644 --- a/panoptica/example_config.ipynb +++ b/panoptica/example_config.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -90,18 +90,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "No module named 'pandas'\n", - "OPTIONAL PACKAGE MISSING\n" - ] - } - ], + "outputs": [], "source": [ "import numpy as np\n", "from auxiliary.nifti.io import read_nifti\n", @@ -129,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -141,14 +132,14 @@ " 106, 107, 108, 202, 203, 204, 205, 206, 207, 208], dtype=uint8))" ] }, - "execution_count": 4, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ref_masks = read_nifti(\"./spine_seg/matched_instance/ref.nii.gz\")\n", - "pred_masks = read_nifti(\"./spine_seg/matched_instance/pred.nii.gz\")\n", + "ref_masks = read_nifti(f\"{BASE_PATH}/spine_seg/matched_instance/ref.nii.gz\")\n", + "pred_masks = read_nifti(f\"{BASE_PATH}/spine_seg/matched_instance/pred.nii.gz\")\n", "\n", "# labels are matching\n", "np.unique(ref_masks), np.unique(pred_masks)" @@ -163,74 +154,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "metadata": {}, "outputs": [ - { - "data": { - "text/html": [ - "
────────────────────────────────────────── Thank you for using panoptica ──────────────────────────────────────────\n",
-              "
\n" - ], - "text/plain": [ - "\u001b[92m────────────────────────────────────────── \u001b[0mThank you for using \u001b[1mpanoptica\u001b[0m\u001b[92m ──────────────────────────────────────────\u001b[0m\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
                                     Please support our development by citing                                      \n",
-              "
\n" - ], - "text/plain": [ - " Please support our development by citing \n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
                          https://github.com/BrainLesion/panoptica#citation -- Thank you!                          \n",
-              "
\n" - ], - "text/plain": [ - " \u001b[4;94mhttps://github.com/BrainLesion/panoptica#citation\u001b[0m -- Thank you! \n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n",
-              "
\n" - ], - "text/plain": [ - "\u001b[92m───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
\n",
-              "
\n" - ], - "text/plain": [ - "\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, { "name": "stdout", "output_type": "stream", @@ -260,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -306,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -342,14 +268,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n" + "\n" ] } ], @@ -360,7 +286,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 18, "metadata": {}, "outputs": [ { diff --git a/panoptica/example_spine_matched_instance.ipynb b/panoptica/example_spine_matched_instance.ipynb index 7dbc285..8c8be35 100644 --- a/panoptica/example_spine_matched_instance.ipynb +++ b/panoptica/example_spine_matched_instance.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -90,18 +90,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "No module named 'pandas'\n", - "OPTIONAL PACKAGE MISSING\n" - ] - } - ], + "outputs": [], "source": [ "import numpy as np\n", "from auxiliary.nifti.io import read_nifti\n", @@ -129,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -141,14 +132,14 @@ " 106, 107, 108, 202, 203, 204, 205, 206, 207, 208], dtype=uint8))" ] }, - "execution_count": 4, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ref_masks = read_nifti(\"./spine_seg/matched_instance/ref.nii.gz\")\n", - "pred_masks = read_nifti(\"./spine_seg/matched_instance/pred.nii.gz\")\n", + "ref_masks = read_nifti(f\"{BASE_PATH}/spine_seg/matched_instance/ref.nii.gz\")\n", + "pred_masks = read_nifti(f\"{BASE_PATH}/spine_seg/matched_instance/pred.nii.gz\")\n", "\n", "# labels are matching\n", "np.unique(ref_masks), np.unique(pred_masks)" @@ -163,74 +154,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "metadata": {}, "outputs": [ - { - "data": { - "text/html": [ - "
────────────────────────────────────────── Thank you for using panoptica ──────────────────────────────────────────\n",
-       "
\n" - ], - "text/plain": [ - "\u001b[92m────────────────────────────────────────── \u001b[0mThank you for using \u001b[1mpanoptica\u001b[0m\u001b[92m ──────────────────────────────────────────\u001b[0m\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
                                     Please support our development by citing                                      \n",
-       "
\n" - ], - "text/plain": [ - " Please support our development by citing \n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
                          https://github.com/BrainLesion/panoptica#citation -- Thank you!                          \n",
-       "
\n" - ], - "text/plain": [ - " \u001b[4;94mhttps://github.com/BrainLesion/panoptica#citation\u001b[0m -- Thank you! \n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n",
-       "
\n" - ], - "text/plain": [ - "\u001b[92m───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
\n",
-       "
\n" - ], - "text/plain": [ - "\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, { "name": "stdout", "output_type": "stream", @@ -260,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -297,7 +223,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -321,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -387,7 +313,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 18, "metadata": {}, "outputs": [ { diff --git a/panoptica/example_spine_matching_algorithm.ipynb b/panoptica/example_spine_matching_algorithm.ipynb index f0b081c..7f89851 100644 --- a/panoptica/example_spine_matching_algorithm.ipynb +++ b/panoptica/example_spine_matching_algorithm.ipynb @@ -147,8 +147,8 @@ } ], "source": [ - "ref_masks = read_nifti(\"./spine_seg/unmatched_instance/ref.nii.gz\")\n", - "pred_masks = read_nifti(\"./spine_seg/unmatched_instance/pred.nii.gz\")\n", + "ref_masks = read_nifti(f\"{BASE_PATH}/spine_seg/unmatched_instance/ref.nii.gz\")\n", + "pred_masks = read_nifti(f\"{BASE_PATH}/spine_seg/unmatched_instance/pred.nii.gz\")\n", "\n", "# labels are unmatched instances\n", "pred_masks[pred_masks == 27] = 26 # For later\n", diff --git a/panoptica/example_spine_unmatched_instance.ipynb b/panoptica/example_spine_unmatched_instance.ipynb index 52f62db..b385bda 100644 --- a/panoptica/example_spine_unmatched_instance.ipynb +++ b/panoptica/example_spine_unmatched_instance.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -90,18 +90,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "No module named 'pandas'\n", - "OPTIONAL PACKAGE MISSING\n" - ] - } - ], + "outputs": [], "source": [ "import numpy as np\n", "from auxiliary.nifti.io import read_nifti\n", @@ -129,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -141,14 +132,14 @@ " 107, 108, 109, 203, 204, 205, 206, 207, 208, 209], dtype=uint8))" ] }, - "execution_count": 4, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ref_masks = read_nifti(\"./spine_seg/unmatched_instance/ref.nii.gz\")\n", - "pred_masks = read_nifti(\"./spine_seg/unmatched_instance/pred.nii.gz\")\n", + "ref_masks = read_nifti(f\"{BASE_PATH}/spine_seg/unmatched_instance/ref.nii.gz\")\n", + "pred_masks = read_nifti(f\"{BASE_PATH}/spine_seg/unmatched_instance/pred.nii.gz\")\n", "\n", "# labels are unmatching\n", "pred_masks[pred_masks == 27] = 26 # For later\n", @@ -164,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -198,74 +189,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 15, "metadata": {}, "outputs": [ - { - "data": { - "text/html": [ - "
────────────────────────────────────────── Thank you for using panoptica ──────────────────────────────────────────\n",
-       "
\n" - ], - "text/plain": [ - "\u001b[92m────────────────────────────────────────── \u001b[0mThank you for using \u001b[1mpanoptica\u001b[0m\u001b[92m ──────────────────────────────────────────\u001b[0m\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
                                     Please support our development by citing                                      \n",
-       "
\n" - ], - "text/plain": [ - " Please support our development by citing \n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
                          https://github.com/BrainLesion/panoptica#citation -- Thank you!                          \n",
-       "
\n" - ], - "text/plain": [ - " \u001b[4;94mhttps://github.com/BrainLesion/panoptica#citation\u001b[0m -- Thank you! \n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n",
-       "
\n" - ], - "text/plain": [ - "\u001b[92m───────────────────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
\n",
-       "
\n" - ], - "text/plain": [ - "\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, { "name": "stdout", "output_type": "stream", @@ -373,7 +299,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -398,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -464,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 18, "metadata": {}, "outputs": [ {