Skip to content

Commit a42845c

Browse files
committed
update explanations
1 parent 9ded8bb commit a42845c

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

example/model_usage.ipynb

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
{
7676
"cell_type": "code",
77-
"execution_count": null,
77+
"execution_count": 36,
7878
"metadata": {},
7979
"outputs": [],
8080
"source": [
@@ -248,7 +248,7 @@
248248
"\n",
249249
"The most direct way to run a model prediction is using the `bioimageio.core.predict` function, to which you pass the model you want to predict with and the input you want to predict on, along with optional keyword arguments. The input can be given as a `numpy.ndarray`, `xarray.DataArray`, bioimageio `Tensor` or `pathlib.Path` to an image (`TensorSource`).\n",
250250
"\n",
251-
"`bioimageio.core.Tensors/xarray.DataArrays` are like numpy arrays, but they have annotated axes. The axes are used to validate that the axes of the input image match the axes expected by the model."
251+
"`bioimageio.core.Tensors/xarray.DataArrays` are like numpy arrays, but they have annotated axes. The axes are used to match the input image to what the model expects. You can create a Tensor instance explicitly if you want to assign a specific axis order."
252252
]
253253
},
254254
{
@@ -403,7 +403,7 @@
403403
"cell_type": "markdown",
404404
"metadata": {},
405405
"source": [
406-
"Alternatively, instead of directly setting input as a Mapping[TensorId, TensorSource] we can set input to be a `Sample` instance. Conceptually a `Sample` is similar but provides the additional functionality of having precomputed sample statistics along with helper functions to automatically create a `Sample` for a given model.\n",
406+
"Alternatively, instead of directly setting input as a Mapping[TensorId, TensorSource] we can set input to be a `Sample` instance. Inside `predict` a `Sample` will actually be created no matter the given input type. The `Sample` instance can be created explicitly for a given model using the helper function `create_sample_for_model`. Another useful functionality of `Sample` is that it can keep track of precomputed sample and dataset statistics, which certain preprocessing steps require.\n",
407407
"\n",
408408
"In order to create a `Sample` we first create a `Tensor` (light wrapper around an `xarray.DataArray`) from the test input image, adding annotated axes."
409409
]
@@ -439,24 +439,29 @@
439439
},
440440
{
441441
"cell_type": "code",
442-
"execution_count": 17,
442+
"execution_count": 37,
443443
"metadata": {},
444444
"outputs": [
445445
{
446446
"data": {
447447
"text/plain": [
448-
"Sample(members={'raw': <bioimageio.core.tensor.Tensor object at 0x312674c80>}, stat={}, id='sample-from-numpy')"
448+
"Sample(members={'raw': <bioimageio.core.tensor.Tensor object at 0x312675dc0>}, stat={DatasetMean(member_id='raw', scope='dataset', name='mean', axes=None): 123.456}, id='sample-from-numpy')"
449449
]
450450
},
451-
"execution_count": 17,
451+
"execution_count": 37,
452452
"metadata": {},
453453
"output_type": "execute_result"
454454
}
455455
],
456456
"source": [
457457
"from bioimageio.core import Sample\n",
458+
"from bioimageio.core.stat_measures import DatasetMean\n",
458459
"\n",
459-
"sample = Sample(members={\"raw\": test_input_tensor}, stat={}, id=\"sample-from-numpy\")\n",
460+
"sample = Sample(\n",
461+
" members={\"raw\": test_input_tensor}, \n",
462+
" stat={DatasetMean(member_id=TensorId(\"raw\")): 123.456}, # Example mean value\n",
463+
" id=\"sample-from-numpy\"\n",
464+
")\n",
460465
"\n",
461466
"sample"
462467
]
@@ -626,9 +631,9 @@
626631
"cell_type": "markdown",
627632
"metadata": {},
628633
"source": [
629-
"### prediciton pipeline (Advanced)\n",
634+
"### Prediciton pipeline (Advanced)\n",
630635
"\n",
631-
"The `prediction_pipeline` function is used to run a prediction with a given model.\n",
636+
"The `prediction_pipeline` function is used to run a prediction with a given model and provides more finegrained control for model prediction.\n",
632637
"\n",
633638
"It applies the __pre-processing__, if indicated in the model rdf.yaml, runs __inference__ with the model and applies the __post-processing__, again if specified in the model rdf.yaml.\n",
634639
"\n",
@@ -707,7 +712,7 @@
707712
},
708713
{
709714
"cell_type": "code",
710-
"execution_count": 29,
715+
"execution_count": 30,
711716
"metadata": {},
712717
"outputs": [
713718
{
@@ -748,16 +753,9 @@
748753
"\n",
749754
" np_output_list.append(output_array)\n",
750755
"\n",
751-
"plt.imshow(np_input_list[0])\n",
756+
"_ = plt.imshow(np_input_list[0])\n",
752757
"plt.show()"
753758
]
754-
},
755-
{
756-
"cell_type": "code",
757-
"execution_count": null,
758-
"metadata": {},
759-
"outputs": [],
760-
"source": []
761759
}
762760
],
763761
"metadata": {

0 commit comments

Comments
 (0)