From f4f4bd4120c1ef5496fd4a0cd67f401648452c46 Mon Sep 17 00:00:00 2001 From: mariana-gferreira Date: Wed, 25 Sep 2024 15:00:44 +0100 Subject: [PATCH] export bug fixes --- .../U-Net_2D_Multilabel_ZeroCostDL4Mic.ipynb | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Colab_notebooks/U-Net_2D_Multilabel_ZeroCostDL4Mic.ipynb b/Colab_notebooks/U-Net_2D_Multilabel_ZeroCostDL4Mic.ipynb index f19e99c4..9546e9a8 100644 --- a/Colab_notebooks/U-Net_2D_Multilabel_ZeroCostDL4Mic.ipynb +++ b/Colab_notebooks/U-Net_2D_Multilabel_ZeroCostDL4Mic.ipynb @@ -2195,7 +2195,7 @@ "Trained_model_author_1 = \"Author 1 name, *Author 1 affiliation, *Author 1 email, *Author 1 ORCID, *Author 1 Github User\" #@param {type:\"string\"}\n", "Trained_model_author_2 = \"Author 2 name, *Author 2 affiliation, *Author 2 email, *Author 2 ORCID, *Author 2 Github User\" #@param {type:\"string\"}\n", "\n", - "# @markdown - ###Model Packager:\n", + "# @markdown ###Model Packager:\n", "packager_same_as_author = True #@param {type:\"boolean\"}\n", "#@markdown - If not, please, provide the following information:\n", "Trained_model_packager = \"Packager name, *Packager affiliation, *Packager email, *Packager ORCID, *Packager Github User\" #@param {type:\"string\"}\n", @@ -2205,7 +2205,7 @@ "#@markdown - If not, please, provide the following information:\n", "Trained_model_maintainer = \"Maintainer Github User, *Maintainer name, *Maintainer affiliation, *Maintainer email, *Maintainer ORCID\" #@param {type:\"string\"}\n", "\n", - "#@markdown - License:\n", + "# @markdown ###License:\n", "Trained_model_license = 'CC-BY-4.0' #@param {type:\"string\"}\n", "\n", "Trained_model_references = [\"Falk et al. Nature Methods 2019\", \"Ronneberger et al. arXiv in 2015\", \"Lucas von Chamier et al. biorXiv 2020\"]\n", @@ -2214,9 +2214,9 @@ "# Training data\n", "# ---------------------------------------\n", "#@markdown ##Include information about training data (optional):\n", - "include_training_data = True #@param {type: \"boolean\"}\n", + "include_training_data = False #@param {type: \"boolean\"}\n", "#@markdown ### - If it is published in the BioImage Model Zoo, please, provide the ID\n", - "data_from_bioimage_model_zoo = True #@param {type: \"boolean\"}\n", + "data_from_bioimage_model_zoo = False #@param {type: \"boolean\"}\n", "training_data_ID = ''#@param {type:\"string\"}\n", "#@markdown ### - If not, please provide the URL to the data and a short description to be added to the README.md file\n", "training_data_source = ''#@param {type:\"string\"}\n", @@ -2256,12 +2256,12 @@ "\n", "# create the author/maintainer/packager spec input\n", "author_1_spec = make_author(Trained_model_author_1)\n", - "author_2_spec = make_author(Trained_model_author_2)\n", - "\n", "authors = [author_1_spec]\n", + "\n", "# check if author 2 was filled\n", - "if author_2_spec.name != 'Author 2 name' and author_2_spec.name != '':\n", - " authors.append(author_2_spec)\n", + "if 'Author 2 name' not in Trained_model_author_2:\n", + " author_2_spec = make_author(Trained_model_author_2)\n", + " authors.append(author_2_spec)\n", "\n", "if packager_same_as_author:\n", " packager_spec = author_1_spec\n", @@ -2337,7 +2337,9 @@ "np.save(test_input_path, test_img[None, ..., None])\n", "\n", "# run prediction on the input image and save the result as expected output\n", - "test_prediction = unet.predict(test_img[None,...,None])\n", + "test_img = normalizePercentile(test_img)\n", + "test_img = test_img[None, ..., None]\n", + "test_prediction = unet.predict(test_img)\n", "test_prediction = np.squeeze(test_prediction)\n", "assert test_prediction.ndim == 3\n", "\n", @@ -2363,7 +2365,9 @@ " bioimageio_spec.SpaceInputAxis(size=bioimageio_spec.ParameterizedSize(min=min_size, step=step_size), id='x', description='', type='space', unit=None, scale=1.0, concatenable=False), \n", " bioimageio_spec.ChannelAxis(id='channel', description='', type='channel', channel_names=['channel0'])],\n", " test_tensor = bioimageio_spec.FileDescr(source = test_input_path), \n", - " )\n", + " preprocessing = [bioimageio_spec.ScaleRangeDescr(kwargs=bioimageio_spec.ScaleRangeKwargs(axes = ['x','y'], min_percentile = 1.0 , max_percentile = 99.8) )],\n", + " )\n", + " \n", "\n", "\n", "# create the output tensor\n", @@ -2392,10 +2396,10 @@ "attachments.append(FileDescr(source = path))\n", "\n", "# make cover image\n", - "cover = test_img\n", + "cover = np.squeeze(test_img)\n", "pred_cover = np.squeeze(test_prediction)\n", "\n", - "for idx in range(n_channels):\n", + "for idx in range(1, n_channels):\n", " if channel_pred_idx == 0:\n", " cover = np.concatenate((cover, pred_cover[idx,:,:]), axis=1)\n", " elif channel_pred_idx == 1:\n", @@ -2404,7 +2408,7 @@ " cover = np.concatenate((cover, pred_cover[:,:,idx]), axis=1)\n", "\n", "cover_path = os.path.join(output_root, \"cover.png\")\n", - "plt.imsave(cover_path, cover)\n", + "plt.imsave(cover_path, cover, cmap='gray')\n", "\n", "# make weights description\n", "unet_tf_weights = bioimageio_spec.KerasHdf5WeightsDescr(source=weight_path, tensorflow_version=tf.__version__)\n",