(*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 0, 0] NotebookDataLength[ 32227, 805] NotebookOptionsPosition[ 29236, 737] NotebookOutlinePosition[ 29574, 752] CellTagsIndexPosition[ 29531, 749] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Construction Notebook for:", FontSize->24], "\nU-Net Trained on Glioblastoma-Astrocytoma U373 Cells on a Polyacrylamide \ Substrate Data" }], "Title", CellChangeTimes->{{3.7639214788955383`*^9, 3.7639214790542717`*^9}, { 3.763980104760891*^9, 3.763980124163262*^9}, 3.763999301921772*^9},ExpressionUUID->"6afa5315-6d82-4107-b4f6-\ 3af64bd88169"], Cell[CellGroupData[{ Cell["NetModel Access", "Section",ExpressionUUID->"bfc67e4f-2875-48e5-9dd0-60fd41155137"], Cell[CellGroupData[{ Cell["This Notebook", "Subsubsection",ExpressionUUID->"0e363198-7ca2-4e16-a32c-8826a62a5994"], Cell[BoxData[ RowBox[{"NetModel", "[", RowBox[{ "\"\\"", ",", " ", "\"\\""}], "]"}]], "Input", CellChangeTimes->{{3.763921458289668*^9, 3.763921473858554*^9}, 3.763980130436193*^9, 3.7639993019245872`*^9},ExpressionUUID->"74f87ecf-4d64-4eb1-965a-\ 41c45a22c306"] }, Open ]], Cell[CellGroupData[{ Cell["Untrained Net", "Subsubsection",ExpressionUUID->"06d685fc-cd55-465f-9334-d6b28036363f"], Cell[BoxData[ RowBox[{"NetModel", "[", RowBox[{ "\"\\"", ",", "\"\\""}], "]"}]], "Input", CellChangeTimes->{3.7639214723585787`*^9, 3.76398013680573*^9, 3.7639993019253063`*^9},ExpressionUUID->"bb286d57-aee7-4555-b91d-\ 5dcf7b6d7c00"] }, Open ]], Cell[CellGroupData[{ Cell["Trained Net", "Subsubsection",ExpressionUUID->"9a7fc7c6-da01-4287-b48c-b87a974a9c85"], Cell[BoxData[ RowBox[{"NetModel", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{3.7639214723595257`*^9, 3.7639801425027*^9, 3.763999301925996*^9}, CellLabel->"",ExpressionUUID->"c5e29ec1-7bd0-4e50-b430-61f4969b003e"] }, Open ]], Cell[CellGroupData[{ Cell["Notes", "Subsection",ExpressionUUID->"dde306a0-7510-4da4-b35f-0744529a306a"], Cell[TextData[{ "The network exhibits input constraints. For a network with L levels, the \ image dimensions w (or h) and padding p are required to be the following:\n", Cell[BoxData[ RowBox[{"w", "\[Equal]", RowBox[{ RowBox[{ SuperscriptBox["2", "L"], " ", RowBox[{"(", RowBox[{"n", "-", "8"}], ")"}]}], "+", "4"}]}]], CellChangeTimes->{{3.760253990229681*^9, 3.7602539913655367`*^9}, { 3.760254051183441*^9, 3.760254053006033*^9}, {3.7602541198416967`*^9, 3.760254123182726*^9}, {3.7602541569699287`*^9, 3.760254168137928*^9}, 3.760254843107626*^9, {3.760255003894662*^9, 3.760255013286009*^9}, 3.760257785997137*^9},ExpressionUUID-> "ed22aa13-1886-4aff-b837-1827de76c0ad"], " and ", Cell[BoxData[ RowBox[{"p", "\[Equal]", RowBox[{ RowBox[{"3", " ", SuperscriptBox["2", RowBox[{"2", "+", "L"}]]}], "-", "8"}]}]], CellChangeTimes->{{3.760254011334791*^9, 3.760254049416623*^9}, { 3.760254894644177*^9, 3.760254900717259*^9}, 3.7602577881121492`*^9}, ExpressionUUID->"022970a1-8ef1-44e7-805a-562463320a9e"], " for any integer ", Cell[BoxData[ RowBox[{"n", "\[GreaterEqual]", " ", RowBox[{"Ceiling", "[", RowBox[{"8", "-", RowBox[{"3", " ", SuperscriptBox["2", RowBox[{"-", "L"}]]}]}], "]"}]}]], CellChangeTimes->{{3.760253961100933*^9, 3.7602539619678917`*^9}, 3.760254826478014*^9, 3.760257781497055*^9, {3.760266849695139*^9, 3.760266852553946*^9}},ExpressionUUID-> "5a1770dc-8adf-4e7c-9800-eb1fd6fa3362"], "." }], "Text",ExpressionUUID->"986a6a4c-43b6-40ce-a689-d02cf2ef1412"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Net Construction", "Section",ExpressionUUID->"7359030f-8aed-4aef-bc87-4a5da7e0e003"], Cell[CellGroupData[{ Cell["Internal Functions", "Subsection",ExpressionUUID->"1aee3b33-7519-4af6-ada1-9cef4aa7b9d4"], Cell[CellGroupData[{ Cell["uNetContract", "Subsubsection",ExpressionUUID->"b63d2f30-0dbd-4a7a-b971-6164b2ac1241"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Clear", "[", "uNetContract", "]"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"uNetContract", "[", RowBox[{ RowBox[{"chn1_Integer", "?", "Positive"}], ",", RowBox[{"crop_Integer", "?", "Positive"}], ",", RowBox[{"dropout_Real:", "1.0"}], ",", RowBox[{"opts", ":", RowBox[{"OptionsPattern", "[", "NetGraph", "]"}]}]}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"uNetContract", "[", RowBox[{"chn1", ",", "chn1", ",", "crop", ",", "dropout", ",", "opts"}], "]"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"uNetContract", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"chn1_Integer", "?", "Positive"}], ",", RowBox[{"chn2_Integer", "?", "Positive"}], ",", " ", RowBox[{"crop_Integer", "?", "Positive"}], ",", RowBox[{"dropout_Real:", "0.5"}], ",", RowBox[{"opts", ":", RowBox[{"OptionsPattern", "[", "NetGraph", "]"}]}]}], "\[IndentingNewLine]", "]"}], ":=", "\[IndentingNewLine]", RowBox[{ RowBox[{"NetGraph", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"<|", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn1", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn2", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"DropoutLayer", "[", "dropout", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"PoolingLayer", "[", RowBox[{ RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"PartLayer", "[", RowBox[{"{", RowBox[{"All", ",", RowBox[{"crop", ";;", RowBox[{"-", "crop"}]}], ",", RowBox[{"crop", ";;", RowBox[{"-", "crop"}]}]}], "}"}], "]"}]}]}], "\[IndentingNewLine]", "|>"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"NetPort", "[", "\"\\"", "]"}], "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}]}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"NetPort", "[", "\"\\"", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"\"\\"", "\[Rule]", RowBox[{"NetPort", "[", "\"\\"", "]"}]}]}]}], "}"}], ",", "\[IndentingNewLine]", "opts"}], "\[IndentingNewLine]", "]"}], "/;", " ", RowBox[{"0", "<", "dropout", "<", "1"}]}]}], "\[IndentingNewLine]"}], "\n", RowBox[{ RowBox[{"uNetContract", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"chn1_Integer", "?", "Positive"}], ",", RowBox[{"chn2_Integer", "?", "Positive"}], ",", " ", RowBox[{"crop_Integer", "?", "Positive"}], ",", RowBox[{"1", "|", "1.0"}], ",", RowBox[{"opts", ":", RowBox[{"OptionsPattern", "[", "NetGraph", "]"}]}]}], "\[IndentingNewLine]", "]"}], ":=", "\[IndentingNewLine]", RowBox[{"NetGraph", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"<|", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn1", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn2", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"PoolingLayer", "[", RowBox[{ RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"PartLayer", "[", RowBox[{"{", RowBox[{"All", ",", RowBox[{"crop", ";;", RowBox[{"-", "crop"}]}], ",", RowBox[{"crop", ";;", RowBox[{"-", "crop"}]}]}], "}"}], "]"}]}]}], "\[IndentingNewLine]", "|>"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"NetPort", "[", "\"\\"", "]"}], "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}]}]}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"NetPort", "[", "\"\\"", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"\"\\"", "\[Rule]", RowBox[{"NetPort", "[", "\"\\"", "]"}]}]}]}], "}"}], ",", "\[IndentingNewLine]", "opts"}], "\[IndentingNewLine]", "]"}]}]}], "Input", CellChangeTimes->{{3.7639005256280193`*^9, 3.763900539801468*^9}, { 3.7639005923526583`*^9, 3.7639006382071867`*^9}, {3.763900990813182*^9, 3.763901037613611*^9}, {3.7639012318395023`*^9, 3.763901271815878*^9}, { 3.763901317246357*^9, 3.7639014062226562`*^9}, {3.763901509844*^9, 3.763901512053727*^9}, {3.763901624749227*^9, 3.763901701223587*^9}, { 3.763903186877253*^9, 3.763903195503686*^9}}, CellLabel->"In[57]:=",ExpressionUUID->"de724ae1-4c6e-4a98-9ad4-ddab6b483969"] }, Open ]], Cell[CellGroupData[{ Cell["uNetExpand", "Subsubsection",ExpressionUUID->"577d16f7-4f5a-4c0b-9711-d9f2411a56e6"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Clear", "[", "uNetExpand", "]"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"uNetExpand", "[", RowBox[{ RowBox[{"chn1_Integer", "?", "Positive"}], ",", RowBox[{"opts", ":", RowBox[{"OptionsPattern", "[", "NetGraph", "]"}]}]}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"uNetExpand", "[", RowBox[{"chn1", ",", "chn1", ",", "chn1", ",", "opts"}], "]"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"uNetExpand", "[", RowBox[{ RowBox[{"chn1_Integer", "?", "Positive"}], ",", RowBox[{"chn2_Integer", "?", "Positive"}], ",", " ", RowBox[{"opts", ":", RowBox[{"OptionsPattern", "[", "NetGraph", "]"}]}]}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"uNetExpand", "[", RowBox[{"chn1", ",", "chn2", ",", "chn2", ",", "opts"}], "]"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"uNetExpand", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"chn1_Integer", "?", "Positive"}], ",", RowBox[{"chn2_Integer", "?", "Positive"}], ",", " ", RowBox[{"chn3_Integer", "?", "Positive"}], ",", RowBox[{"opts", ":", RowBox[{"OptionsPattern", "[", "NetGraph", "]"}]}]}], "\[IndentingNewLine]", "]"}], ":=", "\[IndentingNewLine]", RowBox[{"NetGraph", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"<|", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"DeconvolutionLayer", "[", RowBox[{"chn1", ",", RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}], ",", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}]}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"CatenateLayer", "[", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn2", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn3", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}]}], "\[IndentingNewLine]", "|>"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"NetPort", "[", "\"\\"", "]"}], "\[Rule]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"\"\\"", ",", RowBox[{"NetPort", "[", "\"\\"", "]"}]}], "}"}], "\[Rule]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"NetPort", "[", "\"\\"", "]"}]}]}]}]}]}]}]}], "}"}], ",", "\[IndentingNewLine]", "opts"}], "\[IndentingNewLine]", "]"}]}]}], "Input", CellChangeTimes->{{3.7639027682971983`*^9, 3.763902851671884*^9}, { 3.7639753267705307`*^9, 3.7639753686747513`*^9}}, CellLabel->"In[79]:=",ExpressionUUID->"040bb062-69fa-4d51-b685-e7f39a48cc04"] }, Open ]], Cell[CellGroupData[{ Cell["uNetBase", "Subsubsection",ExpressionUUID->"c274552b-29df-4e4c-82e6-ba15cbd8630c"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Clear", "[", "uNetBase", "]"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"uNetBase", "[", RowBox[{ RowBox[{"chn_Integer", "?", "Positive"}], ",", RowBox[{"dropout_Real:", "1.0"}], ",", RowBox[{"opts", ":", RowBox[{"OptionsPattern", "[", "NetChain", "]"}]}]}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"If", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"dropout", "\[GreaterEqual]", "1"}], ",", "\[IndentingNewLine]", RowBox[{"NetGraph", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"<|", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}]}], "\[IndentingNewLine]", "|>"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", "\"\\""}]}]}], "}"}], ",", "\[IndentingNewLine]", "opts"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"NetGraph", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"<|", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ConvolutionLayer", "[", RowBox[{"chn", ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"ElementwiseLayer", "[", "Ramp", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"DropoutLayer", "[", "dropout", "]"}]}]}], "\[IndentingNewLine]", "|>"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"\"\\"", "\[Rule]", " ", "\"\\""}]}]}]}], "}"}], ",", "\[IndentingNewLine]", "opts"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "Input", CellChangeTimes->{{3.76390174839812*^9, 3.76390189094832*^9}, { 3.763903015286454*^9, 3.7639030175773497`*^9}, {3.763903088817094*^9, 3.763903136460126*^9}}, CellLabel->"In[65]:=",ExpressionUUID->"0b9eed5f-b591-48f0-b7a7-8ba25f0a4c2f"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Final Net", "Subsection",ExpressionUUID->"5db07900-ff22-42b9-ac5b-2931697ab2b2"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Clear", "[", "uNet", "]"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Options", "[", "uNet", "]"}], "=", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"(", RowBox[{ RowBox[{"{", RowBox[{"chn", ",", "level"}], "}"}], "\[Function]", RowBox[{"chn", " ", SuperscriptBox["2", RowBox[{"level", "-", "1"}]]}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"(", RowBox[{ RowBox[{"{", RowBox[{"chn", ",", "level"}], "}"}], "\[Function]", RowBox[{"chn", " ", SuperscriptBox["2", RowBox[{"level", "-", "1"}]]}]}], ")"}]}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"uNet", "[", RowBox[{ RowBox[{"chn_Integer:", "64"}], ",", RowBox[{"levels_Integer:", "5"}], ",", RowBox[{"classes_Integer:", "2"}], ",", RowBox[{"dropout_Real:", "0.5"}], ",", RowBox[{"opts", ":", RowBox[{"OptionsPattern", "[", "uNet", "]"}]}]}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{ RowBox[{"With", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"contractChn", "=", RowBox[{"OptionValue", "[", "\"\\"", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"expandChn", "=", RowBox[{"OptionValue", "[", "\"\\"", "]"}]}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"NetGraph", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Association", "@", RowBox[{"Join", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Table", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "l", "]"}]}], "\[Rule]", " ", RowBox[{"uNetContract", "[", RowBox[{ RowBox[{"contractChn", "[", RowBox[{"chn", ",", "l"}], "]"}], ",", RowBox[{ RowBox[{"3", " ", SuperscriptBox["2", RowBox[{"levels", "+", "1", "-", "l"}]]}], "-", "7"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"l", "+", "1"}], "==", "levels"}], ",", "dropout", ",", "1.0"}], "]"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"l", ",", "1", ",", RowBox[{"levels", "-", "1"}]}], "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"\"\\"", "\[Rule]", RowBox[{"uNetBase", "[", RowBox[{ RowBox[{"chn", " ", SuperscriptBox["2", RowBox[{"levels", "-", "1"}]]}], ",", "dropout"}], "]"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"Table", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "l", "]"}]}], "\[Rule]", " ", RowBox[{"uNetExpand", "[", RowBox[{ RowBox[{"expandChn", "[", RowBox[{"chn", ",", "l"}], "]"}], ",", RowBox[{"chn", " ", SuperscriptBox["2", RowBox[{"l", "-", "1"}]]}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"l", ",", RowBox[{"levels", "-", "1"}], ",", "1", ",", RowBox[{"-", "1"}]}], "}"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"\"\\"", "\[Rule]", RowBox[{"NetChain", "@", RowBox[{"{", RowBox[{ RowBox[{"ConvolutionLayer", "[", RowBox[{"classes", ",", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}], "]"}], ",", RowBox[{"TransposeLayer", "[", RowBox[{"{", RowBox[{ RowBox[{"1", "\[TwoWayRule]", "3"}], ",", RowBox[{"1", "\[TwoWayRule]", "2"}]}], "}"}], "]"}], ",", RowBox[{"SoftmaxLayer", "[", RowBox[{"-", "1"}], "]"}]}], "}"}]}]}], "}"}]}], "\[IndentingNewLine]", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"Flatten", "@", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"NetPort", "[", "\"\\"", "]"}], "\[Rule]", " ", RowBox[{"NetPort", "[", RowBox[{"\"\\"", ",", "\"\\""}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"NetPort", "[", RowBox[{"\"\\"", ",", "\"\\""}], "]"}], "\[Rule]", " ", RowBox[{"NetPort", "[", RowBox[{"\"\\"", ",", "\"\\""}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"NetPort", "[", RowBox[{"\"\\"", ",", "\"\\""}], "]"}], "\[Rule]", RowBox[{"\"\\"", "\[Rule]", " ", RowBox[{"NetPort", "[", "\"\\"", "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"NetPort", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", RowBox[{"levels", "-", "1"}], "]"}]}], ",", "\"\\""}], "]"}], "\[Rule]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"NetPort", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", RowBox[{"levels", "-", "1"}], "]"}]}], ",", "\"\\""}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"Table", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"NetPort", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "l", "]"}]}], ",", "\"\\""}], "]"}], "\[Rule]", " ", RowBox[{"NetPort", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "l", "]"}]}], ",", "\"\\""}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"NetPort", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", RowBox[{"l", "-", "1"}], "]"}]}], ",", "\"\\""}], "]"}], "\[Rule]", " ", RowBox[{"NetPort", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "l", "]"}]}], ",", "\"\\""}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"NetPort", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "l", "]"}]}], ",", "\"\\""}], "]"}], "\[Rule]", " ", RowBox[{"NetPort", "[", RowBox[{ RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", RowBox[{"l", "-", "1"}], "]"}]}], ",", "\"\\""}], "]"}]}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"l", ",", "2", ",", RowBox[{"levels", "-", "1"}]}], "}"}]}], "\[IndentingNewLine]", "]"}]}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"NetEncoder", "[", RowBox[{"{", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"572", ",", "572"}], "}"}], ",", RowBox[{"ColorSpace", "\[Rule]", "\"\\""}]}], "}"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{"NetDecoder", "[", RowBox[{"{", RowBox[{"\"\\"", ",", RowBox[{"Range", "[", "classes", "]"}], ",", RowBox[{"\"\\"", "\[Rule]", "3"}]}], "}"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], "/;", RowBox[{ RowBox[{"chn", "\[GreaterEqual]", "1"}], "\[And]", RowBox[{"levels", "\[GreaterEqual]", "2"}], "\[And]", RowBox[{"classes", "\[GreaterEqual]", "2"}], "\[And]", RowBox[{"0", "<", "dropout", "\[LessEqual]", "1"}]}]}]}]}], "Input", CellChangeTimes->{{3.763902877788542*^9, 3.763902927241437*^9}}, CellLabel->"In[88]:=",ExpressionUUID->"df8ea2c0-eddd-4e27-9d81-60951b36de04"], Cell[BoxData[ RowBox[{"unet", "=", RowBox[{"uNet", "[", "]"}]}]], "Input", CellLabel->"In[91]:=",ExpressionUUID->"bf0715d0-c917-4642-9420-945107de6446"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Training", "Section",ExpressionUUID->"3b52d656-aec1-4acc-81f5-6be165d3cc59"], Cell["(Performed separately)", "Text", CellChangeTimes->{{3.761984620887041*^9, 3.761984622395624*^9}, { 3.763906557534101*^9, 3.763906558152523*^9}},ExpressionUUID->"22fb35b4-036c-4a33-a90b-\ 501c758985bc"] }, Open ]] }, Open ]] }, WindowSize->{1313, 1363}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, FrontEndVersion->"12.0 for Mac OS X x86 (64-bit) (March 30, 2019)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[422, 15, 383, 9, 195, "Title",ExpressionUUID->"6afa5315-6d82-4107-b4f6-3af64bd88169"], Cell[CellGroupData[{ Cell[830, 28, 89, 0, 67, "Section",ExpressionUUID->"bfc67e4f-2875-48e5-9dd0-60fd41155137"], Cell[CellGroupData[{ Cell[944, 32, 93, 0, 45, "Subsubsection",ExpressionUUID->"0e363198-7ca2-4e16-a32c-8826a62a5994"], Cell[1040, 34, 396, 9, 30, "Input",ExpressionUUID->"74f87ecf-4d64-4eb1-965a-41c45a22c306"] }, Open ]], Cell[CellGroupData[{ Cell[1473, 48, 93, 0, 45, "Subsubsection",ExpressionUUID->"06d685fc-cd55-465f-9334-d6b28036363f"], Cell[1569, 50, 369, 8, 30, "Input",ExpressionUUID->"bb286d57-aee7-4555-b91d-5dcf7b6d7c00"] }, Open ]], Cell[CellGroupData[{ Cell[1975, 63, 91, 0, 45, "Subsubsection",ExpressionUUID->"9a7fc7c6-da01-4287-b48c-b87a974a9c85"], Cell[2069, 65, 320, 6, 30, "Input",ExpressionUUID->"c5e29ec1-7bd0-4e50-b430-61f4969b003e"] }, Open ]], Cell[CellGroupData[{ Cell[2426, 76, 82, 0, 54, "Subsection",ExpressionUUID->"dde306a0-7510-4da4-b35f-0744529a306a"], Cell[2511, 78, 1619, 39, 60, "Text",ExpressionUUID->"986a6a4c-43b6-40ce-a689-d02cf2ef1412"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[4179, 123, 90, 0, 67, "Section",ExpressionUUID->"7359030f-8aed-4aef-bc87-4a5da7e0e003"], Cell[CellGroupData[{ Cell[4294, 127, 95, 0, 54, "Subsection",ExpressionUUID->"1aee3b33-7519-4af6-ada1-9cef4aa7b9d4"], Cell[CellGroupData[{ Cell[4414, 131, 92, 0, 45, "Subsubsection",ExpressionUUID->"b63d2f30-0dbd-4a7a-b971-6164b2ac1241"], Cell[4509, 133, 6987, 165, 871, "Input",ExpressionUUID->"de724ae1-4c6e-4a98-9ad4-ddab6b483969"] }, Open ]], Cell[CellGroupData[{ Cell[11533, 303, 90, 0, 45, "Subsubsection",ExpressionUUID->"577d16f7-4f5a-4c0b-9711-d9f2411a56e6"], Cell[11626, 305, 3924, 95, 535, "Input",ExpressionUUID->"040bb062-69fa-4d51-b685-e7f39a48cc04"] }, Open ]], Cell[CellGroupData[{ Cell[15587, 405, 88, 0, 45, "Subsubsection",ExpressionUUID->"c274552b-29df-4e4c-82e6-ba15cbd8630c"], Cell[15678, 407, 3434, 79, 577, "Input",ExpressionUUID->"0b9eed5f-b591-48f0-b7a7-8ba25f0a4c2f"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[19161, 492, 86, 0, 54, "Subsection",ExpressionUUID->"5db07900-ff22-42b9-ac5b-2931697ab2b2"], Cell[19250, 494, 9451, 222, 839, "Input",ExpressionUUID->"df8ea2c0-eddd-4e27-9d81-60951b36de04"], Cell[28704, 718, 157, 3, 30, "Input",ExpressionUUID->"bf0715d0-c917-4642-9420-945107de6446"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[28910, 727, 82, 0, 67, "Section",ExpressionUUID->"3b52d656-aec1-4acc-81f5-6be165d3cc59"], Cell[28995, 729, 213, 4, 35, "Text",ExpressionUUID->"22fb35b4-036c-4a33-a90b-501c758985bc"] }, Open ]] }, Open ]] } ] *)