From b6feab20adbfc464739815d926eb4f6e62ff3cd8 Mon Sep 17 00:00:00 2001 From: Mackenzie Mathis Date: Wed, 15 May 2024 08:56:49 +0200 Subject: [PATCH 1/5] Created using Colab - path update --- notebooks/Colab_inference_demo.ipynb | 352 +++++++++++++++++++++++++++ 1 file changed, 352 insertions(+) create mode 100644 notebooks/Colab_inference_demo.ipynb diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb new file mode 100644 index 00000000..2432b6a0 --- /dev/null +++ b/notebooks/Colab_inference_demo.ipynb @@ -0,0 +1,352 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PoYFnmmQAm-x" + }, + "source": [ + "# **CellSeg3D : inference demo notebook**\n", + "\n", + "---\n", + "This notebook is part of the [CellSeg3D project](https://github.com/AdaptiveMotorControlLab/CellSeg3d) in the [Mathis Lab of Adaptive Intelligence](https://www.mackenziemathislab.org/).\n", + "\n", + "- 💜 The foundation of this notebook owes much to the **[ZeroCostDL4Mic](https://github.com/HenriquesLab/ZeroCostDL4Mic)** project and to the **[DeepLabCut](https://github.com/DeepLabCut/DeepLabCut)** team for bringing Colab into scientific open software." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vJLmPrWhAm-z" + }, + "source": [ + "# **1. Installing dependencies**\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CUNTOWCnAm-z" + }, + "source": [ + "## **1.1 Installing CellSeg3D**\n", + "---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "bnFKu6uFAm-z" + }, + "outputs": [], + "source": [ + "#@markdown ##Install CellSeg3D and dependencies\n", + "!git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git --branch main --single-branch ./CellSeg3D\n", + "!pip install -e CellSeg3D" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SfYAv60MAm-z" + }, + "source": [ + "## **1.2. Restart your runtime**\n", + "---\n", + "\n", + "\n", + "\n", + "** Please ignore the subsequent error message. An automatic restart of your Runtime is expected and is part of the process.**\n", + "\n", + "\"\"
" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Of85zlxzAm-z" + }, + "outputs": [], + "source": [ + "# @title Force session restart\n", + "exit(0)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "pSVZsebrAm-0" + }, + "source": [ + "## **1.3 Load key dependencies**\n", + "---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "vzm75tE_Am-0" + }, + "outputs": [], + "source": [ + "# @title Load libraries\n", + "from pathlib import Path\n", + "from tifffile import imread\n", + "from napari_cellseg3d.dev_scripts import remote_inference as cs3d\n", + "from napari_cellseg3d.utils import LOGGER as logger\n", + "import logging\n", + "\n", + "logger.setLevel(logging.INFO)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XLEJsiVNAm-0" + }, + "source": [ + "# **2. Inference**\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gjp4WL40Am-0" + }, + "source": [ + "\n", + "## **2.1. Check for GPU access**\n", + "---\n", + "\n", + "By default, this session is configured to use Python 3 and GPU acceleration. To verify or adjust these settings:\n", + "\n", + "Navigate to Runtime and select Change the Runtime type.\n", + "\n", + "For Runtime type, ensure it's set to Python 3 (the programming language this program is written in).\n", + "\n", + "Under Accelerator, choose GPU (Graphics Processing Unit).\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Fe8hNkOpAm-0" + }, + "outputs": [], + "source": [ + "#@markdown This cell verifies if GPU access is available.\n", + "\n", + "import torch\n", + "if not torch.cuda.is_available():\n", + " print('You do not have GPU access.')\n", + " print('Did you change your runtime?')\n", + " print('If the runtime setting is correct then Google did not allocate a GPU for your session')\n", + " print('Expect slow performance. To access GPU try reconnecting later')\n", + "\n", + "else:\n", + " print('You have GPU access')\n", + " !nvidia-smi\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JBCyJAGsAm-0" + }, + "source": [ + "## **2.2 Run inference**\n", + "---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "O0jLRpARAm-0" + }, + "outputs": [], + "source": [ + "demo_image_path = \"/content/CellSeg3D/examples/c5image.tif\"\n", + "demo_image = imread(demo_image_path)\n", + "inference_config = cs3d.CONFIG\n", + "post_process_config = cs3d.PostProcessConfig()\n", + "# select cle device for colab\n", + "import pyclesperanto_prototype as cle\n", + "cle.select_device(\"cupy\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hIEKoyEGAm-0" + }, + "outputs": [], + "source": [ + "result = cs3d.inference_on_images(\n", + " demo_image,\n", + " config=inference_config,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "IFbmZ3_zAm-1" + }, + "outputs": [], + "source": [ + "# @title Post-process the result\n", + "# @markdown This cell post-processes the result of the inference : thresholding, instance segmentation, and statistics.\n", + "instance_segmentation,stats = cs3d.post_processing(\n", + " result[0].semantic_segmentation,\n", + " config=post_process_config,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "TMRiQ-m4Am-1" + }, + "outputs": [], + "source": [ + "# @title Display the result\n", + "#@markdown This cell displays the result of the inference and post-processing. Use the slider to navigate through the z-stack.\n", + "# @markdown *KNOWN ISSUE* : The colormap of the labels is not consistent between the z-stacks.\n", + "import matplotlib.pyplot as plt\n", + "import ipywidgets as widgets\n", + "from IPython.display import display\n", + "import matplotlib\n", + "import colorsys\n", + "import numpy as np\n", + "\n", + "def random_label_cmap(n=2**16, h = (0,1), l = (.4,1), s =(.2,.8)):\n", + " \"\"\"FUNCTION TAKEN FROM STARDIST REPO : https://github.com/stardist/stardist/blob/c6c261081c6f9717fa9f5c47720ad2d5a9153224/stardist/plot/plot.py#L8\"\"\"\n", + " h,l,s = np.random.uniform(*h,n), np.random.uniform(*l,n), np.random.uniform(*s,n)\n", + " cols = np.stack([colorsys.hls_to_rgb(_h,_l,_s) for _h,_l,_s in zip(h,l,s)],axis=0)\n", + " cols[0] = 0\n", + " # reset the random generator to the first draw to keep the colormap consistent\n", + "\n", + " return matplotlib.colors.ListedColormap(cols)\n", + "\n", + "label_cmap = random_label_cmap(n=instance_segmentation.max()+1)\n", + "\n", + "def update_plot(z):\n", + " plt.figure(figsize=(15, 15))\n", + " plt.subplot(1, 3, 1)\n", + " plt.imshow(demo_image[z], cmap='gray')\n", + " plt.subplot(1, 3, 2)\n", + " plt.imshow(result[0].semantic_segmentation[z], cmap='turbo')\n", + " plt.subplot(1, 3, 3)\n", + " plt.imshow(instance_segmentation[z], cmap=label_cmap)\n", + " plt.show()\n", + "\n", + "# Create a slider\n", + "z_slider = widgets.IntSlider(min=0, max=demo_image.shape[0]-1, step=1, value=demo_image.shape[0] // 2)\n", + "\n", + "# Display the slider and update the plot when the slider is changed\n", + "widgets.interact(update_plot, z=z_slider)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Tw5exJ5EAm-1" + }, + "outputs": [], + "source": [ + "# @title Display the statistics\n", + "# @markdown This cell displays the statistics of the post-processed result.\n", + "import pandas as pd\n", + "data = pd.DataFrame(stats.get_dict())\n", + "display(data)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0NhZ-YksAm-1" + }, + "outputs": [], + "source": [ + "# @title Plot the a 3D view, with statistics\n", + "# @markdown This cell plots a 3D view of the cells, with the volume as the size of the points and the sphericity as the color.\n", + "import plotly.graph_objects as go\n", + "import numpy as np\n", + "\n", + "def plotly_cells_stats(data):\n", + "\n", + " x = data[\"Centroid x\"]\n", + " y = data[\"Centroid y\"]\n", + " z = data[\"Centroid z\"]\n", + "\n", + " fig = go.Figure(\n", + " data=go.Scatter3d(\n", + " x=np.floor(x),\n", + " y=np.floor(y),\n", + " z=np.floor(z),\n", + " mode=\"markers\",\n", + " marker=dict(\n", + " sizemode=\"diameter\",\n", + " sizeref=30,\n", + " sizemin=20,\n", + " size=data[\"Volume\"],\n", + " color=data[\"Sphericity (axes)\"],\n", + " colorscale=\"Turbo_r\",\n", + " colorbar_title=\"Sphericity\",\n", + " line_color=\"rgb(140, 140, 170)\",\n", + " ),\n", + " )\n", + " )\n", + "\n", + " fig.update_layout(\n", + " height=600,\n", + " width=600,\n", + " title=f'Total number of cells : {int(data[\"Number objects\"][0])}',\n", + " )\n", + "\n", + " fig.show(renderer=\"colab\")\n", + "\n", + "plotly_cells_stats(data)" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "gpuType": "T4", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file From 4bcfce191f67006a68b1fecb3a22d74dc326f4fe Mon Sep 17 00:00:00 2001 From: Mackenzie Mathis Date: Wed, 15 May 2024 08:57:23 +0200 Subject: [PATCH 2/5] Created using Colab --- notebooks/Colab_inference_demo.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index 2432b6a0..822530f0 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -21,7 +21,7 @@ "---\n", "This notebook is part of the [CellSeg3D project](https://github.com/AdaptiveMotorControlLab/CellSeg3d) in the [Mathis Lab of Adaptive Intelligence](https://www.mackenziemathislab.org/).\n", "\n", - "- 💜 The foundation of this notebook owes much to the **[ZeroCostDL4Mic](https://github.com/HenriquesLab/ZeroCostDL4Mic)** project and to the **[DeepLabCut](https://github.com/DeepLabCut/DeepLabCut)** team for bringing Colab into scientific open software." + "- 💜 The foundation of this notebook owes much to the **[ZeroCostDL4Mic](https://github.com/HenriquesLab/ZeroCostDL4Mic)** project and to the **[DeepLabCut](https://github.com/DeepLabCut/DeepLabCut)** team." ] }, { From 4b7966042f304c2cce172a5df7639889d5737a58 Mon Sep 17 00:00:00 2001 From: Mackenzie Mathis Date: Wed, 15 May 2024 09:01:11 +0200 Subject: [PATCH 3/5] Delete notebooks/colab_inference_demo.ipynb - remove --> renamed and edited --- notebooks/colab_inference_demo.ipynb | 320 --------------------------- 1 file changed, 320 deletions(-) delete mode 100644 notebooks/colab_inference_demo.ipynb diff --git a/notebooks/colab_inference_demo.ipynb b/notebooks/colab_inference_demo.ipynb deleted file mode 100644 index 84748f36..00000000 --- a/notebooks/colab_inference_demo.ipynb +++ /dev/null @@ -1,320 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "view-in-github" - }, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# **CellSeg3D : inference demo notebook**\n", - "\n", - "---\n", - "This notebook is part of the [CellSeg3D project](https://github.com/AdaptiveMotorControlLab/CellSeg3d) in the [Mathis Lab of Adaptive Intelligence](https://www.mackenziemathislab.org/).\n", - "\n", - "- 💜 The foundation of this notebook owes much to the **[ZeroCostDL4Mic](https://github.com/HenriquesLab/ZeroCostDL4Mic)** project and to the **[DeepLabCut](https://github.com/DeepLabCut/DeepLabCut)** team for bringing Colab into scientific open software." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# **1. Installing dependencies**\n", - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## **1.1 Installing CellSeg3D**\n", - "---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#@markdown ##Install CellSeg3D and dependencies\n", - "!git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git --branch main --single-branch ./CellSeg3D\n", - "!pip install -e CellSeg3D" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## **1.2. Restart your runtime**\n", - "---\n", - "\n", - "\n", - "\n", - "** Please ignore the subsequent error message. An automatic restart of your Runtime is expected and is part of the process.**\n", - "\n", - "\"\"
" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Force session restart\n", - "exit(0)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## **1.3 Load key dependencies**\n", - "---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Load libraries\n", - "from pathlib import Path\n", - "from tifffile import imread\n", - "from napari_cellseg3d.dev_scripts import remote_inference as cs3d\n", - "from napari_cellseg3d.utils import LOGGER as logger\n", - "import logging\n", - "\n", - "logger.setLevel(logging.INFO)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# **2. Inference**\n", - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "## **2.1. Check for GPU access**\n", - "---\n", - "\n", - "By default, this session is configured to use Python 3 and GPU acceleration. To verify or adjust these settings:\n", - "\n", - "Navigate to Runtime and select Change the Runtime type.\n", - "\n", - "For Runtime type, ensure it's set to Python 3 (the programming language this program is written in).\n", - "\n", - "Under Accelerator, choose GPU (Graphics Processing Unit).\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#@markdown This cell verifies if GPU access is available.\n", - "\n", - "import torch\n", - "if not torch.cuda.is_available():\n", - " print('You do not have GPU access.')\n", - " print('Did you change your runtime?')\n", - " print('If the runtime setting is correct then Google did not allocate a GPU for your session')\n", - " print('Expect slow performance. To access GPU try reconnecting later')\n", - "\n", - "else:\n", - " print('You have GPU access')\n", - " !nvidia-smi\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## **2.2 Run inference**\n", - "---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Load demo image and inference configuration\n", - "#@markdown This cell loads a demo image and load the inference configuration.\n", - "demo_image_path = \"./CellSeg3D/examples/c5image.tif\n", - "demo_image = imread(demo_image_path)\n", - "inference_config = cs3d.CONFIG\n", - "post_process_config = cs3d.PostProcessConfig()\n", - "# select cle device for colab\n", - "import pyclesperanto_prototype as cle\n", - "cle.select_device(\"cupy\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Run inference on demo image\n", - "#@markdown This cell runs the inference on the demo image.\n", - "result = cs3d.inference_on_images(\n", - " demo_image,\n", - " config=inference_config,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Post-process the result\n", - "# @markdown This cell post-processes the result of the inference : thresholding, instance segmentation, and statistics.\n", - "instance_segmentation,stats = cs3d.post_processing(\n", - " result[0].semantic_segmentation,\n", - " config=post_process_config,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Display the result\n", - "#@markdown This cell displays the result of the inference and post-processing. Use the slider to navigate through the z-stack.\n", - "# @markdown *KNOWN ISSUE* : The colormap of the labels is not consistent between the z-stacks. \n", - "import matplotlib.pyplot as plt\n", - "import ipywidgets as widgets\n", - "from IPython.display import display\n", - "import matplotlib\n", - "import colorsys\n", - "import numpy as np\n", - "\n", - "def random_label_cmap(n=2**16, h = (0,1), l = (.4,1), s =(.2,.8)):\n", - " \"\"\"FUNCTION TAKEN FROM STARDIST REPO : https://github.com/stardist/stardist/blob/c6c261081c6f9717fa9f5c47720ad2d5a9153224/stardist/plot/plot.py#L8\"\"\"\n", - " h,l,s = np.random.uniform(*h,n), np.random.uniform(*l,n), np.random.uniform(*s,n)\n", - " cols = np.stack([colorsys.hls_to_rgb(_h,_l,_s) for _h,_l,_s in zip(h,l,s)],axis=0)\n", - " cols[0] = 0\n", - " # reset the random generator to the first draw to keep the colormap consistent\n", - "\n", - " return matplotlib.colors.ListedColormap(cols)\n", - "\n", - "label_cmap = random_label_cmap(n=instance_segmentation.max()+1)\n", - "\n", - "def update_plot(z):\n", - " plt.figure(figsize=(15, 15))\n", - " plt.subplot(1, 3, 1)\n", - " plt.imshow(demo_image[z], cmap='gray')\n", - " plt.subplot(1, 3, 2)\n", - " plt.imshow(result[0].semantic_segmentation[z], cmap='turbo')\n", - " plt.subplot(1, 3, 3)\n", - " plt.imshow(instance_segmentation[z], cmap=label_cmap)\n", - " plt.show()\n", - "\n", - "# Create a slider\n", - "z_slider = widgets.IntSlider(min=0, max=demo_image.shape[0]-1, step=1, value=demo_image.shape[0] // 2)\n", - "\n", - "# Display the slider and update the plot when the slider is changed\n", - "widgets.interact(update_plot, z=z_slider)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Display the statistics\n", - "# @markdown This cell displays the statistics of the post-processed result.\n", - "import pandas as pd\n", - "data = pd.DataFrame(stats.get_dict())\n", - "display(data)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Plot the a 3D view, with statistics\n", - "# @markdown This cell plots a 3D view of the cells, with the volume as the size of the points and the sphericity as the color.\n", - "import plotly.graph_objects as go\n", - "import numpy as np\n", - "\n", - "def plotly_cells_stats(data):\n", - "\n", - " x = data[\"Centroid x\"]\n", - " y = data[\"Centroid y\"]\n", - " z = data[\"Centroid z\"]\n", - "\n", - " fig = go.Figure(\n", - " data=go.Scatter3d(\n", - " x=np.floor(x),\n", - " y=np.floor(y),\n", - " z=np.floor(z),\n", - " mode=\"markers\",\n", - " marker=dict(\n", - " sizemode=\"diameter\",\n", - " sizeref=30,\n", - " sizemin=20,\n", - " size=data[\"Volume\"],\n", - " color=data[\"Sphericity (axes)\"],\n", - " colorscale=\"Turbo_r\",\n", - " colorbar_title=\"Sphericity\",\n", - " line_color=\"rgb(140, 140, 170)\",\n", - " ),\n", - " )\n", - " )\n", - "\n", - " fig.update_layout(\n", - " height=600,\n", - " width=600,\n", - " title=f'Total number of cells : {int(data[\"Number objects\"][0])}',\n", - " )\n", - "\n", - " fig.show(renderer=\"colab\")\n", - " \n", - "plotly_cells_stats(data)" - ] - } - ], - "metadata": { - "accelerator": "GPU", - "colab": { - "gpuType": "T4", - "include_colab_link": true, - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} From 5c3542f6079d2cf35363a5574e4143b7b6b80a6b Mon Sep 17 00:00:00 2001 From: C-Achard Date: Tue, 28 May 2024 09:25:17 +0200 Subject: [PATCH 4/5] Update dataloader for tests --- .../code_models/worker_training.py | 66 +++++++++++++------ 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/napari_cellseg3d/code_models/worker_training.py b/napari_cellseg3d/code_models/worker_training.py index 90aeeba5..05c576ac 100644 --- a/napari_cellseg3d/code_models/worker_training.py +++ b/napari_cellseg3d/code_models/worker_training.py @@ -331,24 +331,40 @@ def _get_data(self): (self.data_shape, dataset) = self.get_dataset(train_transforms) logger.debug(f"Data shape : {self.data_shape}") - self.dataloader = DataLoader( - dataset, - batch_size=self.config.batch_size, - shuffle=True, - num_workers=self.config.num_workers, - collate_fn=pad_list_data_collate, - ) + try: + self.dataloader = DataLoader( + dataset, + batch_size=self.config.batch_size, + shuffle=True, + num_workers=self.config.num_workers, + collate_fn=pad_list_data_collate, + ) + except ValueError: + self.dataloader = DataLoader( + dataset, + batch_size=self.config.batch_size, + num_workers=self.config.num_workers, + collate_fn=pad_list_data_collate, + ) if self.config.eval_volume_dict is not None: eval_dataset = self.get_dataset_eval(self.config.eval_volume_dict) logger.debug(f"Eval batch size : {self.config.eval_batch_size}") - self.eval_dataloader = DataLoader( - eval_dataset, - batch_size=self.config.eval_batch_size, - shuffle=False, - num_workers=self.config.num_workers, - collate_fn=pad_list_data_collate, - ) + try: + self.eval_dataloader = DataLoader( + eval_dataset, + batch_size=self.config.eval_batch_size, + shuffle=False, + num_workers=self.config.num_workers, + collate_fn=pad_list_data_collate, + ) + except ValueError: + self.eval_dataloader = DataLoader( + eval_dataset, + batch_size=self.config.eval_batch_size, + num_workers=self.config.num_workers, + collate_fn=pad_list_data_collate, + ) else: self.eval_dataloader = None return self.dataloader, self.eval_dataloader, self.data_shape @@ -1385,13 +1401,21 @@ def get_patch_loader_func(num_samples): data=self.val_files, transform=load_whole_images ) logger.debug("Dataloader") - train_loader = DataLoader( - train_dataset, - batch_size=self.config.batch_size, - shuffle=True, - num_workers=self.config.num_workers, - collate_fn=pad_list_data_collate, - ) + try: + train_loader = DataLoader( + train_dataset, + batch_size=self.config.batch_size, + shuffle=True, + num_workers=self.config.num_workers, + collate_fn=pad_list_data_collate, + ) + except ValueError: + train_loader = DataLoader( + train_dataset, + batch_size=self.config.batch_size, + num_workers=self.config.num_workers, + collate_fn=pad_list_data_collate, + ) validation_loader = DataLoader( validation_dataset, From bd3ce988d456231f91a30cbe560c0a0b5271f65c Mon Sep 17 00:00:00 2001 From: C-Achard Date: Tue, 28 May 2024 09:36:22 +0200 Subject: [PATCH 5/5] Update URL --- notebooks/Colab_inference_demo.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index 822530f0..634695c1 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -7,7 +7,7 @@ "colab_type": "text" }, "source": [ - "\"Open" + "\"Open" ] }, { @@ -349,4 +349,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}