Skip to content

Commit 098bbd3

Browse files
committed
black
1 parent fa62499 commit 098bbd3

File tree

1 file changed

+68
-57
lines changed

1 file changed

+68
-57
lines changed

example/load_model_and_create_your_own.ipynb

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@
286286
}
287287
],
288288
"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",
290292
"\n",
291293
"if model.git_repo is None:\n",
292294
" print(\"\\nThere is no associated GitHub repository.\")\n",
@@ -632,16 +634,20 @@
632634
"\n",
633635
"data_root = \"https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/affable-shark/1.2/files/\"\n",
634636
"\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+
"]"
645651
]
646652
},
647653
{
@@ -682,33 +688,39 @@
682688
"metadata": {},
683689
"outputs": [],
684690
"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",
686696
"\n",
687697
"assert isinstance(model.outputs[0].axes[1], ChannelAxis)\n",
688698
"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+
"]"
712724
]
713725
},
714726
{
@@ -776,10 +788,10 @@
776788
")\n",
777789
"\n",
778790
"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",
783795
" depth=4,\n",
784796
" final_activation=\"Sigmoid\",\n",
785797
" gain=2,\n",
@@ -788,8 +800,8 @@
788800
" out_channels=2,\n",
789801
" postprocessing=None,\n",
790802
" return_side_outputs=False,\n",
791-
" ),\n",
792-
" )"
803+
" ),\n",
804+
")"
793805
]
794806
},
795807
{
@@ -805,12 +817,9 @@
805817
"metadata": {},
806818
"outputs": [],
807819
"source": [
820+
"from bioimageio.spec.model.v0_5 import PytorchStateDictWeightsDescr\n",
808821
"\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",
814823
" source=HttpUrl(data_root + \"weights.pt\"),\n",
815824
" sha256=Sha256(\"608f52cd7f5119f7a7b8272395b0c169714e8be34536eaf159820f72a1d6a5b7\"),\n",
816825
" architecture=my_architecture,\n",
@@ -831,9 +840,9 @@
831840
"metadata": {},
832841
"outputs": [],
833842
"source": [
834-
"from bioimageio.spec.model.v0_5 import TorchscriptWeightsDescr\n",
843+
"from bioimageio.spec.model.v0_5 import TorchscriptWeightsDescr\n",
835844
"\n",
836-
"my_torchscript_weights=TorchscriptWeightsDescr(\n",
845+
"my_torchscript_weights = TorchscriptWeightsDescr(\n",
837846
" source=HttpUrl(data_root + \"weights-torchscript.pt\"),\n",
838847
" sha256=Sha256(\"8410950508655a300793b389c815dc30b1334062fc1dadb1e15e55a93cbb99a0\"),\n",
839848
" pytorch_version=Version(torch.__version__),\n",
@@ -861,21 +870,20 @@
861870
" HttpUrl,\n",
862871
" LicenseId,\n",
863872
")\n",
873+
"\n",
864874
"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",
867877
" Author(name=\"me\", affiliation=\"my institute\", github_user=\"bioimageiobot\")\n",
868878
"] # change github_user to your GitHub account name\n",
869-
"my_model_citations=[\n",
879+
"my_model_citations = [\n",
870880
" CiteEntry(text=\"for model training see my paper\", doi=Doi(\"10.1234something\"))\n",
871881
"]\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",
874884
" \"https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/affable-shark/1.2/files/documentation.md\"\n",
875885
")\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\")"
879887
]
880888
},
881889
{
@@ -922,7 +930,10 @@
922930
" # inputs=[input_descr], # try out our recreated input description\n",
923931
" outputs=my_model_outputs,\n",
924932
" # 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",
926937
")\n",
927938
"print(f\"created '{my_model.name}'\")"
928939
]

0 commit comments

Comments
 (0)