Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bioimage-io/BioEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Aug 16, 2024
2 parents 4b81325 + 23783ba commit 747784b
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions notebooks/bioengine-tutorial-embl-2024.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"trusted": true
},
"outputs": [],
"execution_count": 4
"execution_count": 3
},
{
"cell_type": "code",
Expand All @@ -42,7 +42,7 @@
"trusted": true
},
"outputs": [],
"execution_count": 9
"execution_count": 4
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -70,7 +70,7 @@
"metadata": {}
}
],
"execution_count": 10
"execution_count": 5
},
{
"cell_type": "markdown",
Expand All @@ -85,7 +85,7 @@
"trusted": true
},
"outputs": [],
"execution_count": 11
"execution_count": 7
},
{
"cell_type": "markdown",
Expand All @@ -94,18 +94,38 @@
},
{
"cell_type": "code",
"source": "ret = await triton.execute(inputs=[{'inputs': None, \"model_id\": \"creative-panda\", 'return_rdf':True}],\n model_name=\"bioengine-model-runner\",\n serialization=\"imjoy\",\n )\nprint(ret['result']['rdf'])",
"source": "import json\nret = await triton.execute(inputs=[{'inputs': None, \"model_id\": \"creative-panda\", 'return_rdf':True}],\n model_name=\"bioengine-model-runner\",\n serialization=\"imjoy\",\n )\nmodel_rdf = ret['result']['rdf']\nprint(json.dumps(model_rdf, indent=4))",
"metadata": {
"trusted": true
},
"outputs": [
{
"name": "stdout",
"text": "{'inputs': [{'name': 'input0', 'axes': 'bxyc', 'shape': [1, 512, 512, 1], 'data_range': [0.0, 255.0], 'data_type': 'uint8', 'preprocessing': [{'name': 'scale_range', 'kwargs': {'axes': 'xyc', 'max_percentile': 99.8, 'min_percentile': 1, 'mode': 'per_sample'}}]}], 'timestamp': '2021-12-09T15:03:20.680270', 'tags': ['zerocostdl4mic', 'deepimagej', 'segmentation', 'electron-microscopy', 'unet', 'isbi2012-challenge', 'neurons', 'brain', 'boundary-segmentation', '2d'], 'config': {'_conceptdoi': '10.5281/zenodo.5817052', '_doi': '10.5281/zenodo.5850574', 'bioimageio': {'created': '2022-01-27 14:00:17.489637', 'doi': '10.5281/zenodo.5906839', 'nickname': 'creative-panda', 'nickname_icon': '🐼', 'owners': [271523], 'status': 'accepted', 'version_id': '5906839', 'version_name': 'revision 1'}, 'deepimagej': {'allow_tiling': True, 'model_keys': None, 'prediction': {'postprocess': [{'kwargs': 'binarize.ijm', 'spec': 'ij.IJ::runMacroFile'}], 'preprocess': [{'kwargs': 'per_sample_scale_range.ijm', 'spec': 'ij.IJ::runMacroFile'}]}, 'pyramidal_model': False, 'test_information': {'inputs': [{'name': 'sample_input_0.tif', 'pixel_size': {'x': 0.0004, 'y': 0.0004, 'z': 1}, 'size': '512 x 512 x 1 x 1'}], 'memory_peak': None, 'outputs': [{'name': 'sample_output_0.tif', 'size': '512 x 512 x 1 x 1', 'type': 'image'}], 'runtime': None}}}, 'weights': {'keras_hdf5': {'sha256': 'cdc0cfcc13d01f75a93b25599167bf7cf1572c0c276ea415dccbbe1d143b1489', 'source': 'https://zenodo.org/api/records/5906839/files/keras_weights.hdf5/content', 'tensorflow_version': '1.15'}, 'tensorflow_saved_model_bundle': {'sha256': '34269e6da7caf38a604bb68f2aaa39662f306064f9a35e7cc81bc42049db87af', 'source': 'https://zenodo.org/api/records/5906839/files/tf_weights.zip/content', 'tensorflow_version': '1.15'}}, 'id': '10.5281/zenodo.5817052/5906839', 'authors': [{'name': 'ZeroCostDL4Mic team', 'affiliation': ''}, {'name': 'Constantin Pape'}, {'name': 'DeepImageJ team'}], 'type': 'model', 'sample_inputs': ['https://zenodo.org/api/records/5906839/files/sample_input_0.tif/content'], 'license': 'MIT', 'links': ['imjoy/BioImageIO-Packager', 'zero/notebook_u-net_2d_zerocostdl4mic_deepimagej', 'deepimagej/deepimagej'], 'description': '2D UNet trained using ZeroCostDL4Mic notebooks on data from ISBI Challenge for neuron segmentation in Transmission Electron Microscopy images.', 'test_outputs': ['https://zenodo.org/api/records/5906839/files/test_output.npy/content'], 'cite': [{'url': 'https://doi.org/10.1038/s41592-018-0261-2', 'text': 'Falk et al. Nature Methods 2019'}, {'url': 'https://doi.org/10.1007/978-3-319-24574-4_28', 'text': 'Ronneberger et al. arXiv in 2015'}, {'url': 'https://doi.org/10.1101/2020.03.20.000133', 'text': 'Lucas von Chamier et al. biorXiv 2020'}], 'sample_outputs': ['https://zenodo.org/api/records/5906839/files/sample_output_0.tif/content'], 'attachments': {'files': ['https://zenodo.org/api/records/5906839/files/per_sample_scale_range.ijm/content', 'https://zenodo.org/api/records/5906839/files/binarize.ijm/content']}, 'rdf_source': 'https://bioimage-io.github.io/collection-bioimage-io/rdfs/10.5281/zenodo.5817052/5906839/rdf.yaml', 'outputs': [{'name': 'output0', 'axes': 'bxyc', 'shape': [1, 512, 512, 1], 'data_range': [0.0, 1.0], 'postprocessing': [{'name': 'binarize', 'kwargs': {'threshold': 0.4}}], 'data_type': 'bool'}], 'covers': ['https://zenodo.org/api/records/5906839/files/cover.png/content'], 'version': '0.1.0', 'name': 'Neuron Segmentation in 2D EM (Membrane)', 'documentation': 'https://zenodo.org/api/records/5906839/files/README.md/content', 'test_inputs': ['https://zenodo.org/api/records/5906839/files/test_input.npy/content'], 'format_version': '0.4.9'}\n",
"text": "{\n \"outputs\": [\n {\n \"data_range\": [\n 0.0,\n 1.0\n ],\n \"data_type\": \"bool\",\n \"shape\": [\n 1,\n 512,\n 512,\n 1\n ],\n \"name\": \"output0\",\n \"postprocessing\": [\n {\n \"kwargs\": {\n \"threshold\": 0.4\n },\n \"name\": \"binarize\"\n }\n ],\n \"axes\": \"bxyc\"\n }\n ],\n \"format_version\": \"0.4.9\",\n \"sample_inputs\": [\n \"https://zenodo.org/api/records/5906839/files/sample_input_0.tif/content\"\n ],\n \"config\": {\n \"_conceptdoi\": \"10.5281/zenodo.5817052\",\n \"_doi\": \"10.5281/zenodo.5850574\",\n \"bioimageio\": {\n \"created\": \"2022-01-27 14:00:17.489637\",\n \"doi\": \"10.5281/zenodo.5906839\",\n \"nickname\": \"creative-panda\",\n \"nickname_icon\": \"\\ud83d\\udc3c\",\n \"owners\": [\n 271523\n ],\n \"status\": \"accepted\",\n \"version_id\": \"5906839\",\n \"version_name\": \"revision 1\"\n },\n \"deepimagej\": {\n \"allow_tiling\": true,\n \"model_keys\": null,\n \"prediction\": {\n \"postprocess\": [\n {\n \"kwargs\": \"binarize.ijm\",\n \"spec\": \"ij.IJ::runMacroFile\"\n }\n ],\n \"preprocess\": [\n {\n \"kwargs\": \"per_sample_scale_range.ijm\",\n \"spec\": \"ij.IJ::runMacroFile\"\n }\n ]\n },\n \"pyramidal_model\": false,\n \"test_information\": {\n \"inputs\": [\n {\n \"name\": \"sample_input_0.tif\",\n \"pixel_size\": {\n \"x\": 0.0004,\n \"y\": 0.0004,\n \"z\": 1\n },\n \"size\": \"512 x 512 x 1 x 1\"\n }\n ],\n \"memory_peak\": null,\n \"outputs\": [\n {\n \"name\": \"sample_output_0.tif\",\n \"size\": \"512 x 512 x 1 x 1\",\n \"type\": \"image\"\n }\n ],\n \"runtime\": null\n }\n }\n },\n \"links\": [\n \"imjoy/BioImageIO-Packager\",\n \"zero/notebook_u-net_2d_zerocostdl4mic_deepimagej\",\n \"deepimagej/deepimagej\"\n ],\n \"rdf_source\": \"https://bioimage-io.github.io/collection-bioimage-io/rdfs/10.5281/zenodo.5817052/5906839/rdf.yaml\",\n \"sample_outputs\": [\n \"https://zenodo.org/api/records/5906839/files/sample_output_0.tif/content\"\n ],\n \"test_inputs\": [\n \"https://zenodo.org/api/records/5906839/files/test_input.npy/content\"\n ],\n \"license\": \"MIT\",\n \"test_outputs\": [\n \"https://zenodo.org/api/records/5906839/files/test_output.npy/content\"\n ],\n \"version\": \"0.1.0\",\n \"documentation\": \"https://zenodo.org/api/records/5906839/files/README.md/content\",\n \"weights\": {\n \"keras_hdf5\": {\n \"source\": \"https://zenodo.org/api/records/5906839/files/keras_weights.hdf5/content\",\n \"tensorflow_version\": \"1.15\",\n \"sha256\": \"cdc0cfcc13d01f75a93b25599167bf7cf1572c0c276ea415dccbbe1d143b1489\"\n },\n \"tensorflow_saved_model_bundle\": {\n \"source\": \"https://zenodo.org/api/records/5906839/files/tf_weights.zip/content\",\n \"tensorflow_version\": \"1.15\",\n \"sha256\": \"34269e6da7caf38a604bb68f2aaa39662f306064f9a35e7cc81bc42049db87af\"\n }\n },\n \"tags\": [\n \"zerocostdl4mic\",\n \"deepimagej\",\n \"segmentation\",\n \"electron-microscopy\",\n \"unet\",\n \"isbi2012-challenge\",\n \"neurons\",\n \"brain\",\n \"boundary-segmentation\",\n \"2d\"\n ],\n \"attachments\": {\n \"files\": [\n \"https://zenodo.org/api/records/5906839/files/per_sample_scale_range.ijm/content\",\n \"https://zenodo.org/api/records/5906839/files/binarize.ijm/content\"\n ]\n },\n \"authors\": [\n {\n \"affiliation\": \"\",\n \"name\": \"ZeroCostDL4Mic team\"\n },\n {\n \"name\": \"Constantin Pape\"\n },\n {\n \"name\": \"DeepImageJ team\"\n }\n ],\n \"description\": \"2D UNet trained using ZeroCostDL4Mic notebooks on data from ISBI Challenge for neuron segmentation in Transmission Electron Microscopy images.\",\n \"inputs\": [\n {\n \"data_range\": [\n 0.0,\n 255.0\n ],\n \"data_type\": \"uint8\",\n \"shape\": [\n 1,\n 512,\n 512,\n 1\n ],\n \"name\": \"input0\",\n \"preprocessing\": [\n {\n \"kwargs\": {\n \"axes\": \"xyc\",\n \"max_percentile\": 99.8,\n \"min_percentile\": 1,\n \"mode\": \"per_sample\"\n },\n \"name\": \"scale_range\"\n }\n ],\n \"axes\": \"bxyc\"\n }\n ],\n \"timestamp\": \"2021-12-09T15:03:20.680270\",\n \"covers\": [\n \"https://zenodo.org/api/records/5906839/files/cover.png/content\"\n ],\n \"cite\": [\n {\n \"text\": \"Falk et al. Nature Methods 2019\",\n \"url\": \"https://doi.org/10.1038/s41592-018-0261-2\"\n },\n {\n \"text\": \"Ronneberger et al. arXiv in 2015\",\n \"url\": \"https://doi.org/10.1007/978-3-319-24574-4_28\"\n },\n {\n \"text\": \"Lucas von Chamier et al. biorXiv 2020\",\n \"url\": \"https://doi.org/10.1101/2020.03.20.000133\"\n }\n ],\n \"name\": \"Neuron Segmentation in 2D EM (Membrane)\",\n \"id\": \"10.5281/zenodo.5817052/5906839\",\n \"type\": \"model\"\n}\n",
"output_type": "stream"
}
],
"execution_count": 7
"execution_count": 8
},
{
"cell_type": "markdown",
"source": "## Make sure the input image shape is valid",
"metadata": {}
},
{
"cell_type": "code",
"source": "input_image_shape = tuple(model_rdf[\"inputs\"][0][\"shape\"][1:])\nprint(\"Input image shape\", input_image_shape)\ninput_image = image[...,None]\nassert input_image.shape == input_image_shape, f\"Wrong shape ({input_image.shape}), expected: {input_image_shape}\"\nprint(\"Valid image shape, ready to go!\")",
"metadata": {
"trusted": true
},
"outputs": [
{
"name": "stdout",
"text": "Input image shape (512, 512, 1)\nValid image shape, ready to go!\n",
"output_type": "stream"
}
],
"execution_count": 28
},
{
"cell_type": "markdown",
Expand All @@ -114,7 +134,7 @@
},
{
"cell_type": "code",
"source": "ret = await triton.execute(inputs=[{\"inputs\":[[image[...,None]]], \"model_id\": \"creative-panda\"}],\n model_name=\"bioengine-model-runner\",\n serialization=\"imjoy\",\n )\nresult = ret[\"result\"]\nmask = result['outputs'][0]\nprint('prediction: ', mask.shape)",
"source": "ret = await triton.execute(inputs=[{\"inputs\":[[input_image]], \"model_id\": \"creative-panda\"}],\n model_name=\"bioengine-model-runner\",\n serialization=\"imjoy\",\n )\nresult = ret[\"result\"]\nmask = result['outputs'][0]\nprint('prediction: ', mask.shape)",
"metadata": {
"trusted": true
},
Expand All @@ -125,7 +145,7 @@
"output_type": "stream"
}
],
"execution_count": 8
"execution_count": 27
},
{
"cell_type": "markdown",
Expand All @@ -148,7 +168,7 @@
"metadata": {}
}
],
"execution_count": 9
"execution_count": 14
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -178,7 +198,7 @@
"metadata": {}
}
],
"execution_count": 10
"execution_count": 9
},
{
"cell_type": "markdown",
Expand All @@ -189,20 +209,6 @@
"cell_type": "markdown",
"source": "## Trying more models in BioImage.IO\n\nFeel free to find more models at https://bioimage.io/, if you want to run a model, please do the following as shown above:\n - Copy the animal nickname id in the model card\n - Print the RDF information so you know what's the expected input shape\n - Load your image, and make sure you reshape or resize it according to the expected input shape using numpy or scikit-image etc.\n - Run the model via `execute`, by passing the model id, image\n - Get the result, extract the image for display according to the output shape according to the RDF.\n\n\n## Hosting your own BioEngine\n\nWhile the above demos uses our public free BioEngine server, you can also launch your own bioengine server on a GPU workstation or HPC, and connect to your own BioEngine instance by switching the server URL. If you are interested please following the instructions here: https://bioimage-io.github.io/bioengine/#/bioengine-hpc-worker\n\nPlease note that the deployment is in early stage, so please if you have any issue or trouble in setting it up, please don't hesitate to reach out via email, forum, web form or github issues: https://github.com/bioimage-io/bioengine/issues\n\n",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "",
"metadata": {}
},
{
"cell_type": "code",
"source": "",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
}
]
}

0 comments on commit 747784b

Please sign in to comment.