|
74 | 74 | }, |
75 | 75 | { |
76 | 76 | "cell_type": "code", |
77 | | - "execution_count": null, |
| 77 | + "execution_count": 36, |
78 | 78 | "metadata": {}, |
79 | 79 | "outputs": [], |
80 | 80 | "source": [ |
|
248 | 248 | "\n", |
249 | 249 | "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", |
250 | 250 | "\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." |
252 | 252 | ] |
253 | 253 | }, |
254 | 254 | { |
|
403 | 403 | "cell_type": "markdown", |
404 | 404 | "metadata": {}, |
405 | 405 | "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", |
407 | 407 | "\n", |
408 | 408 | "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." |
409 | 409 | ] |
|
439 | 439 | }, |
440 | 440 | { |
441 | 441 | "cell_type": "code", |
442 | | - "execution_count": 17, |
| 442 | + "execution_count": 37, |
443 | 443 | "metadata": {}, |
444 | 444 | "outputs": [ |
445 | 445 | { |
446 | 446 | "data": { |
447 | 447 | "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')" |
449 | 449 | ] |
450 | 450 | }, |
451 | | - "execution_count": 17, |
| 451 | + "execution_count": 37, |
452 | 452 | "metadata": {}, |
453 | 453 | "output_type": "execute_result" |
454 | 454 | } |
455 | 455 | ], |
456 | 456 | "source": [ |
457 | 457 | "from bioimageio.core import Sample\n", |
| 458 | + "from bioimageio.core.stat_measures import DatasetMean\n", |
458 | 459 | "\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", |
460 | 465 | "\n", |
461 | 466 | "sample" |
462 | 467 | ] |
|
626 | 631 | "cell_type": "markdown", |
627 | 632 | "metadata": {}, |
628 | 633 | "source": [ |
629 | | - "### prediciton pipeline (Advanced)\n", |
| 634 | + "### Prediciton pipeline (Advanced)\n", |
630 | 635 | "\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", |
632 | 637 | "\n", |
633 | 638 | "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", |
634 | 639 | "\n", |
|
707 | 712 | }, |
708 | 713 | { |
709 | 714 | "cell_type": "code", |
710 | | - "execution_count": 29, |
| 715 | + "execution_count": 30, |
711 | 716 | "metadata": {}, |
712 | 717 | "outputs": [ |
713 | 718 | { |
|
748 | 753 | "\n", |
749 | 754 | " np_output_list.append(output_array)\n", |
750 | 755 | "\n", |
751 | | - "plt.imshow(np_input_list[0])\n", |
| 756 | + "_ = plt.imshow(np_input_list[0])\n", |
752 | 757 | "plt.show()" |
753 | 758 | ] |
754 | | - }, |
755 | | - { |
756 | | - "cell_type": "code", |
757 | | - "execution_count": null, |
758 | | - "metadata": {}, |
759 | | - "outputs": [], |
760 | | - "source": [] |
761 | 759 | } |
762 | 760 | ], |
763 | 761 | "metadata": { |
|
0 commit comments