(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 13.1' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 8207227, 135963] NotebookOptionsPosition[ 8051282, 133011] NotebookOutlinePosition[ 8193716, 135678] CellTagsIndexPosition[ 8191769, 135628] WindowTitle->DeepDreamAlpha | Definition Notebook WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["DeepDreamAlpha", "Title", CellTags->{"Name", "TemplateCell", "Title"}, CellID->711842442], Cell["Render the image using the DeepDream-\[Alpha] algorithm", "Text", CellTags->{"Description", "TemplateCell"}, CellID->930935326], Cell[CellGroupData[{ Cell[TextData[{ "Definition", Cell[BoxData[ PaneSelectorBox[{True-> TemplateBox[{"Function", Cell[ BoxData[ FrameBox[ Cell[ "Define your function using the name you gave in the Title line \ above. You can add input cells and extra code to define additional input \ cases or prerequisites. All definitions, including dependencies, will be \ included in the generated resource function.\n\nThis section should be \ evaluated before creating the Examples section below.", "MoreInfoText"], Background -> GrayLevel[0.95], FrameMargins -> 20, FrameStyle -> GrayLevel[0.9], RoundingRadius -> 5, ImageSize -> { Scaled[0.65], Automatic}]], "MoreInfoText", Deletable -> True, CellTags -> {"SectionMoreInfoFunction"}, CellMargins -> {{66, 66}, {15, 15}}]}, "MoreInfoOpenerButtonTemplate"]}, Dynamic[ CurrentValue[ EvaluationNotebook[], {TaggingRules, "ResourceCreateNotebook"}]], ImageSize->Automatic]]] }], "Section", Editable->False, Deletable->False, TaggingRules->{"TemplateGroupName" -> "Function"}, DefaultNewCellStyle->"Input", CellTags->{"Definition", "Function", "TemplateCellGroup"}, CellID->72845326], Cell[CellGroupData[{ Cell["Initialization", "Subsubsection", TaggingRules->{}, CellChangeTimes->{{3.7792420169109917`*^9, 3.779242018912635*^9}}, CellLabel->"In[3]:=", CellID->578260865], Cell[BoxData[ RowBox[{ RowBox[{"ClearAll", "[", "\"\<`*\>\"", "]"}], ";"}]], "Code", CellLabel->"In[1]:=", CellID->377245649] }, Open ]], Cell["Wrap Function", "Subsubsection", CellLabel->"In[2]:=", CellID->979036986], Cell[CellGroupData[{ Cell["Main Function", "Subsubsection", CellLabel->"In[1]:=", CellID->867070350], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Options", "[", "DeepDreamAlpha", "]"}], " ", "=", " ", RowBox[{"{", "\n", "\t", RowBox[{ RowBox[{"\"\\"", " ", "->", " ", "24"}], ",", "\n", "\t", RowBox[{"\"\\"", " ", "->", " ", "1"}], ",", "\n", "\t", RowBox[{"TargetDevice", " ", "->", " ", "\"\\""}], ",", "\n", "\t", RowBox[{"WorkingPrecision", " ", "->", " ", "\"\\""}]}], "\n", "}"}]}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{"DeepDreamAlpha", "[", RowBox[{"img_Image", ",", " ", RowBox[{"steps_Integer", " ", ":", " ", "10"}], ",", " ", RowBox[{"o", " ", ":", " ", RowBox[{"OptionsPattern", "[", "]"}]}]}], "]"}], " ", ":=", " ", RowBox[{"Module", "[", "\n", "\t", RowBox[{ RowBox[{"{", "\n", "\t\t", RowBox[{ "VGG", ",", " ", "net", ",", " ", "res", ",", " ", "i", ",", " ", "$save", ",", "pt", ",", "\n", "\t\t", RowBox[{"step", " ", "=", " ", RowBox[{"OptionValue", "[", "\"\\"", "]"}]}], ",", " ", RowBox[{"$start", " ", "=", " ", RowBox[{"AbsoluteTime", "[", "]"}]}]}], "\n", "\t", "}"}], ",", "\n", "\t", RowBox[{ RowBox[{"VGG", " ", "=", " ", RowBox[{"NetModel", "[", "\"\\"", "]"}]}], ";", "\n", "\t", RowBox[{"net", " ", "=", " ", RowBox[{"NetFlatten", "@", RowBox[{"NetChain", "[", RowBox[{"{", RowBox[{"VGG", ",", " ", RowBox[{"SummationLayer", "[", "]"}]}], "}"}], "]"}]}]}], ";", "\n", "\t", RowBox[{"If", "[", "\n", "\t\t", RowBox[{ RowBox[{"0", " ", "<", " ", RowBox[{"OptionValue", "[", "Depth", "]"}], " ", "<", " ", "31"}], ",", "\n", "\t\t", RowBox[{"net", " ", "=", " ", RowBox[{"NetTake", "[", RowBox[{"net", ",", " ", RowBox[{"{", RowBox[{"1", ",", " ", RowBox[{"OptionValue", "[", "Depth", "]"}]}], "}"}]}], "]"}]}], ",", "\n", "\t\t", RowBox[{"Return", "[", "]"}]}], "\n", "\t", "]"}], ";", "\n", "\t", RowBox[{"net", " ", "=", " ", RowBox[{"NetReplacePart", "[", RowBox[{"net", ",", " ", RowBox[{"\"\\"", " ", "->", " ", RowBox[{"NetEncoder", "[", RowBox[{"{", RowBox[{"\"\\"", ",", " ", RowBox[{"ImageDimensions", "@", "img"}]}], "}"}], "]"}]}]}], "]"}]}], ";", "\n", "\n", "\t", RowBox[{"i", " ", "=", " ", "1"}], ";", "\n", "\t", RowBox[{"$save", " ", "=", " ", "img"}], ";", "\n", "\t", RowBox[{"CheckAbort", "[", "\n", "\t\t", RowBox[{ RowBox[{ RowBox[{"pt", "=", RowBox[{"PrintTemporary", "@", RowBox[{"GeneralUtilities`InformationPanel", "[", "\n", "\t\t\t", RowBox[{ "\"\\"", ",", "\n", "\t\t\t", RowBox[{"{", "\n", "\t\t\t\t", RowBox[{ RowBox[{"Center", " ", ":>", " ", RowBox[{"ProgressIndicator", "[", RowBox[{"i", " ", "/", " ", RowBox[{"Floor", "[", RowBox[{"steps", " ", "/", " ", "step"}], "]"}]}], "]"}]}], ",", "\n", "\t\t\t\t", RowBox[{"\"\