|
286 | 286 | } |
287 | 287 | ], |
288 | 288 | "source": [ |
289 | | - "print(f\"\\nFurther model specific documentation can be found here:\\n{model.documentation.absolute()}\")\n", |
| 289 | + "print(\n", |
| 290 | + " f\"\\nFurther model specific documentation can be found here:\\n{model.documentation.absolute()}\"\n", |
| 291 | + ")\n", |
290 | 292 | "\n", |
291 | 293 | "if model.git_repo is None:\n", |
292 | 294 | " print(\"\\nThere is no associated GitHub repository.\")\n", |
|
632 | 634 | "\n", |
633 | 635 | "data_root = \"https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/affable-shark/1.2/files/\"\n", |
634 | 636 | "\n", |
635 | | - "my_model_inputs = [InputTensorDescr(\n", |
636 | | - " id=TensorId(\"raw\"),\n", |
637 | | - " axes = [BatchAxis(), ChannelAxis(channel_names=[Identifier(\"raw\")]),\n", |
638 | | - " SpaceInputAxis(id=AxisId(\"y\"), size=ParameterizedSize(min=64, step=16)),\n", |
639 | | - " SpaceInputAxis(id=AxisId(\"x\"), size=ParameterizedSize(min=64, step=16)),\n", |
640 | | - " ],\n", |
641 | | - " data = IntervalOrRatioDataDescr(type=\"float32\"),\n", |
642 | | - " test_tensor=FileDescr(source=HttpUrl(data_root + \"test_input_0.npy\")),\n", |
643 | | - " sample_tensor=FileDescr(source=HttpUrl(data_root + \"sample_input_0.tif\")),\n", |
644 | | - ")]" |
| 637 | + "my_model_inputs = [\n", |
| 638 | + " InputTensorDescr(\n", |
| 639 | + " id=TensorId(\"raw\"),\n", |
| 640 | + " axes=[\n", |
| 641 | + " BatchAxis(),\n", |
| 642 | + " ChannelAxis(channel_names=[Identifier(\"raw\")]),\n", |
| 643 | + " SpaceInputAxis(id=AxisId(\"y\"), size=ParameterizedSize(min=64, step=16)),\n", |
| 644 | + " SpaceInputAxis(id=AxisId(\"x\"), size=ParameterizedSize(min=64, step=16)),\n", |
| 645 | + " ],\n", |
| 646 | + " data=IntervalOrRatioDataDescr(type=\"float32\"),\n", |
| 647 | + " test_tensor=FileDescr(source=HttpUrl(data_root + \"test_input_0.npy\")),\n", |
| 648 | + " sample_tensor=FileDescr(source=HttpUrl(data_root + \"sample_input_0.tif\")),\n", |
| 649 | + " )\n", |
| 650 | + "]" |
645 | 651 | ] |
646 | 652 | }, |
647 | 653 | { |
|
682 | 688 | "metadata": {}, |
683 | 689 | "outputs": [], |
684 | 690 | "source": [ |
685 | | - "from bioimageio.spec.model.v0_5 import OutputTensorDescr, SizeReference, SpaceOutputAxisWithHalo\n", |
| 691 | + "from bioimageio.spec.model.v0_5 import (\n", |
| 692 | + " OutputTensorDescr,\n", |
| 693 | + " SizeReference,\n", |
| 694 | + " SpaceOutputAxisWithHalo,\n", |
| 695 | + ")\n", |
686 | 696 | "\n", |
687 | 697 | "assert isinstance(model.outputs[0].axes[1], ChannelAxis)\n", |
688 | 698 | "my_model_outputs = [\n", |
689 | | - "OutputTensorDescr(\n", |
690 | | - " id=TensorId(\"predictions\"),\n", |
691 | | - " axes=[\n", |
692 | | - " BatchAxis(),\n", |
693 | | - " ChannelAxis(\n", |
694 | | - " channel_names=[\n", |
695 | | - " Identifier(\"nuclei_probability\"),\n", |
696 | | - " Identifier(\"membrane_probability\"),\n", |
697 | | - " ]\n", |
698 | | - " ), SpaceOutputAxisWithHalo(\n", |
699 | | - " id=AxisId(\"y\"),\n", |
700 | | - " halo=16,\n", |
701 | | - " size=SizeReference(tensor_id=TensorId(\"raw\"), axis_id=AxisId(\"y\")),\n", |
702 | | - " ), # same size as input (tensor `raw`) axis `y`\n", |
703 | | - " SpaceOutputAxisWithHalo(\n", |
704 | | - " id=AxisId(\"x\"),\n", |
705 | | - " halo=16,\n", |
706 | | - " size=SizeReference(tensor_id=TensorId(\"raw\"), axis_id=AxisId(\"x\")),\n", |
707 | | - " ),\n", |
708 | | - " ],\n", |
709 | | - " test_tensor=FileDescr(source=HttpUrl(data_root + \"test_output_0.npy\")),\n", |
710 | | - " sample_tensor=FileDescr(source=HttpUrl(data_root + \"sample_output_0.tif\")),\n", |
711 | | - ")]" |
| 699 | + " OutputTensorDescr(\n", |
| 700 | + " id=TensorId(\"predictions\"),\n", |
| 701 | + " axes=[\n", |
| 702 | + " BatchAxis(),\n", |
| 703 | + " ChannelAxis(\n", |
| 704 | + " channel_names=[\n", |
| 705 | + " Identifier(\"nuclei_probability\"),\n", |
| 706 | + " Identifier(\"membrane_probability\"),\n", |
| 707 | + " ]\n", |
| 708 | + " ),\n", |
| 709 | + " SpaceOutputAxisWithHalo(\n", |
| 710 | + " id=AxisId(\"y\"),\n", |
| 711 | + " halo=16,\n", |
| 712 | + " size=SizeReference(tensor_id=TensorId(\"raw\"), axis_id=AxisId(\"y\")),\n", |
| 713 | + " ), # same size as input (tensor `raw`) axis `y`\n", |
| 714 | + " SpaceOutputAxisWithHalo(\n", |
| 715 | + " id=AxisId(\"x\"),\n", |
| 716 | + " halo=16,\n", |
| 717 | + " size=SizeReference(tensor_id=TensorId(\"raw\"), axis_id=AxisId(\"x\")),\n", |
| 718 | + " ),\n", |
| 719 | + " ],\n", |
| 720 | + " test_tensor=FileDescr(source=HttpUrl(data_root + \"test_output_0.npy\")),\n", |
| 721 | + " sample_tensor=FileDescr(source=HttpUrl(data_root + \"sample_output_0.tif\")),\n", |
| 722 | + " )\n", |
| 723 | + "]" |
712 | 724 | ] |
713 | 725 | }, |
714 | 726 | { |
|
776 | 788 | ")\n", |
777 | 789 | "\n", |
778 | 790 | "my_architecture = ArchitectureFromFileDescr(\n", |
779 | | - " source=HttpUrl(data_root + \"unet.py\"),\n", |
780 | | - " sha256=Sha256(\"7f5b15948e8e2c91f78dcff34fbf30af517073e91ba487f3edb982b948d099b3\"),\n", |
781 | | - " callable=Identifier(\"UNet2d\"),\n", |
782 | | - " kwargs=dict(\n", |
| 791 | + " source=HttpUrl(data_root + \"unet.py\"),\n", |
| 792 | + " sha256=Sha256(\"7f5b15948e8e2c91f78dcff34fbf30af517073e91ba487f3edb982b948d099b3\"),\n", |
| 793 | + " callable=Identifier(\"UNet2d\"),\n", |
| 794 | + " kwargs=dict(\n", |
783 | 795 | " depth=4,\n", |
784 | 796 | " final_activation=\"Sigmoid\",\n", |
785 | 797 | " gain=2,\n", |
|
788 | 800 | " out_channels=2,\n", |
789 | 801 | " postprocessing=None,\n", |
790 | 802 | " return_side_outputs=False,\n", |
791 | | - " ),\n", |
792 | | - " )" |
| 803 | + " ),\n", |
| 804 | + ")" |
793 | 805 | ] |
794 | 806 | }, |
795 | 807 | { |
|
805 | 817 | "metadata": {}, |
806 | 818 | "outputs": [], |
807 | 819 | "source": [ |
| 820 | + "from bioimageio.spec.model.v0_5 import PytorchStateDictWeightsDescr\n", |
808 | 821 | "\n", |
809 | | - "from bioimageio.spec.model.v0_5 import (\n", |
810 | | - " PytorchStateDictWeightsDescr\n", |
811 | | - ")\n", |
812 | | - "\n", |
813 | | - "my_pytorch_state_dict_weights=PytorchStateDictWeightsDescr(\n", |
| 822 | + "my_pytorch_state_dict_weights = PytorchStateDictWeightsDescr(\n", |
814 | 823 | " source=HttpUrl(data_root + \"weights.pt\"),\n", |
815 | 824 | " sha256=Sha256(\"608f52cd7f5119f7a7b8272395b0c169714e8be34536eaf159820f72a1d6a5b7\"),\n", |
816 | 825 | " architecture=my_architecture,\n", |
|
831 | 840 | "metadata": {}, |
832 | 841 | "outputs": [], |
833 | 842 | "source": [ |
834 | | - "from bioimageio.spec.model.v0_5 import TorchscriptWeightsDescr\n", |
| 843 | + "from bioimageio.spec.model.v0_5 import TorchscriptWeightsDescr\n", |
835 | 844 | "\n", |
836 | | - "my_torchscript_weights=TorchscriptWeightsDescr(\n", |
| 845 | + "my_torchscript_weights = TorchscriptWeightsDescr(\n", |
837 | 846 | " source=HttpUrl(data_root + \"weights-torchscript.pt\"),\n", |
838 | 847 | " sha256=Sha256(\"8410950508655a300793b389c815dc30b1334062fc1dadb1e15e55a93cbb99a0\"),\n", |
839 | 848 | " pytorch_version=Version(torch.__version__),\n", |
|
861 | 870 | " HttpUrl,\n", |
862 | 871 | " LicenseId,\n", |
863 | 872 | ")\n", |
| 873 | + "\n", |
864 | 874 | "my_model_name = \"My cool Model\"\n", |
865 | | - "my_model_description=\"A test model for demonstration purposes only\"\n", |
866 | | - "my_model_authors=[\n", |
| 875 | + "my_model_description = \"A test model for demonstration purposes only\"\n", |
| 876 | + "my_model_authors = [\n", |
867 | 877 | " Author(name=\"me\", affiliation=\"my institute\", github_user=\"bioimageiobot\")\n", |
868 | 878 | "] # change github_user to your GitHub account name\n", |
869 | | - "my_model_citations=[\n", |
| 879 | + "my_model_citations = [\n", |
870 | 880 | " CiteEntry(text=\"for model training see my paper\", doi=Doi(\"10.1234something\"))\n", |
871 | 881 | "]\n", |
872 | | - "my_model_license=LicenseId(\"MIT\")\n", |
873 | | - "my_model_documentation=HttpUrl(\n", |
| 882 | + "my_model_license = LicenseId(\"MIT\")\n", |
| 883 | + "my_model_documentation = HttpUrl(\n", |
874 | 884 | " \"https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/affable-shark/1.2/files/documentation.md\"\n", |
875 | 885 | ")\n", |
876 | | - "my_model_git_repo=HttpUrl(\n", |
877 | | - " \"https://github.com/constantinpape/torch-em\"\n", |
878 | | - ")" |
| 886 | + "my_model_git_repo = HttpUrl(\"https://github.com/constantinpape/torch-em\")" |
879 | 887 | ] |
880 | 888 | }, |
881 | 889 | { |
|
922 | 930 | " # inputs=[input_descr], # try out our recreated input description\n", |
923 | 931 | " outputs=my_model_outputs,\n", |
924 | 932 | " # outputs=[output_descr], # try out our recreated input description\n", |
925 | | - " weights=WeightsDescr(pytorch_state_dict=my_pytorch_state_dict_weights, torchscript=my_torchscript_weights),\n", |
| 933 | + " weights=WeightsDescr(\n", |
| 934 | + " pytorch_state_dict=my_pytorch_state_dict_weights,\n", |
| 935 | + " torchscript=my_torchscript_weights,\n", |
| 936 | + " ),\n", |
926 | 937 | ")\n", |
927 | 938 | "print(f\"created '{my_model.name}'\")" |
928 | 939 | ] |
|
0 commit comments