Skip to content

Commit

Permalink
export bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mariana-gferreira committed Sep 25, 2024
1 parent 289ab10 commit f4f4bd4
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions Colab_notebooks/U-Net_2D_Multilabel_ZeroCostDL4Mic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit f4f4bd4

Please sign in to comment.