diff --git a/.gitignore b/.gitignore index 15f54f5..fd65eb6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ *.log *.lot *.out -*.pdf *.run.xml *.synctex.gz *.toc diff --git a/thesis/Main.pdf b/thesis/Main.pdf new file mode 100644 index 0000000..2f717e8 Binary files /dev/null and b/thesis/Main.pdf differ diff --git a/thesis/Main.tex b/thesis/Main.tex index 78de50d..56a8300 100755 --- a/thesis/Main.tex +++ b/thesis/Main.tex @@ -1004,6 +1004,12 @@ Since the neural network architecture trained in the deepsad method is not fixed \newsubsubsectionNoTOC{Network architectures (LeNet variant, custom encoder) and how they suit the point‑cloud input} +\fig{setup_arch_lenet_encoder}{diagrams/arch_lenet_encoder}{UNFINISHED - Visualization of the original LeNet-inspired encoder architecture.} +\fig{setup_arch_lenet_decoder}{diagrams/arch_lenet_decoder}{UNFINISHED - Visualization of the original LeNet-inspired decoder architecture.} +\fig{setup_arch_ef_encoder}{diagrams/arch_ef_encoder}{UNFINISHED - Visualization of the efficient encoder architecture.} +\fig{setup_arch_ef_decoder}{diagrams/arch_ef_decoder}{UNFINISHED - Visualization of the efficient decoder architecture.} + + \threadtodo {how was training/testing adapted (networks overview), inference, ae tuning} {data has been loaded, how is it processed} diff --git a/thesis/diagrams/arch_ef.pdf b/thesis/diagrams/arch_ef.pdf new file mode 100644 index 0000000..3faab2d Binary files /dev/null and b/thesis/diagrams/arch_ef.pdf differ diff --git a/thesis/diagrams/arch_ef_decoder.pdf b/thesis/diagrams/arch_ef_decoder.pdf new file mode 100644 index 0000000..b1fe401 Binary files /dev/null and b/thesis/diagrams/arch_ef_decoder.pdf differ diff --git a/thesis/diagrams/arch_ef_encoder.pdf b/thesis/diagrams/arch_ef_encoder.pdf new file mode 100644 index 0000000..bbc4d1b Binary files /dev/null and b/thesis/diagrams/arch_ef_encoder.pdf differ diff --git a/thesis/diagrams/arch_lenet.pdf b/thesis/diagrams/arch_lenet.pdf new file mode 100644 index 0000000..52ca182 Binary files /dev/null and b/thesis/diagrams/arch_lenet.pdf differ diff --git a/thesis/diagrams/arch_lenet_decoder.pdf b/thesis/diagrams/arch_lenet_decoder.pdf new file mode 100644 index 0000000..7040cd8 Binary files /dev/null and b/thesis/diagrams/arch_lenet_decoder.pdf differ diff --git a/thesis/diagrams/arch_lenet_encoder.pdf b/thesis/diagrams/arch_lenet_encoder.pdf new file mode 100644 index 0000000..8be2335 Binary files /dev/null and b/thesis/diagrams/arch_lenet_encoder.pdf differ diff --git a/thesis/diagrams/deepsad_procedure/deepsad_procedure.pdf b/thesis/diagrams/deepsad_procedure/deepsad_procedure.pdf new file mode 100644 index 0000000..764a98d Binary files /dev/null and b/thesis/diagrams/deepsad_procedure/deepsad_procedure.pdf differ diff --git a/thesis/diagrams/deepsad_procedure/deepsad_procedure.tex b/thesis/diagrams/deepsad_procedure/deepsad_procedure.tex new file mode 100644 index 0000000..5b81638 --- /dev/null +++ b/thesis/diagrams/deepsad_procedure/deepsad_procedure.tex @@ -0,0 +1,146 @@ +\documentclass[tikz,border=10pt]{standalone} +\usepackage{tikz} +\usetikzlibrary{positioning, shapes.geometric, fit, arrows, arrows.meta, backgrounds} + +% Define box styles +\tikzset{ + databox/.style={rectangle, align=center, draw=black, fill=blue!50, thick, rounded corners},%, inner sep=4}, + procbox/.style={rectangle, align=center, draw=black, fill=orange!30, thick, rounded corners}, + hyperbox/.style={rectangle, align=center, draw=black, fill=green!30, thick, rounded corners}, + stepsbox/.style={rectangle, align=left, draw=black,fill=white, rounded corners, minimum width=6cm, minimum height=1.5cm, font=\small}, + outputbox/.style={rectangle, align=center, draw=red!80, fill=red!20, rounded corners, minimum width=6cm, minimum height=1.5cm, font=\small}, + hlabelbox/.style={rectangle, align=center, draw=black,fill=white, rounded corners, minimum width=6cm, minimum height=1.5cm, font=\small}, + vlabelbox/.style={rectangle, align=center, draw=black,fill=white, rounded corners, minimum width=3cm, minimum height=1.8cm, font=\small}, + arrow/.style={-{Latex[length=3mm]}}, + arrowlabel/.style={fill=white,inner sep=2pt,midway} +} + +\newcommand{\boxtitle}[1]{\textbf{#1}\\[.4em]} + +\pgfdeclarelayer{background} +\pgfdeclarelayer{foreground} +\pgfsetlayers{background,main,foreground} + +\begin{document} +\begin{tikzpicture}[node distance=1cm and 2cm] + + \node (data) {Data}; + \node[right=7 of data] (process) {Procedure}; + \node[right=7 of process] (hyper) {Hyperparameters}; + + \begin{pgfonlayer}{foreground} + \node[hlabelbox, below=of data] (unlabeled) {\boxtitle{Unlabeled Data} More normal than \\ anomalous samples required}; + \node[hlabelbox, below=.1 of unlabeled] (labeled) {\boxtitle{Labeled Data} No requirement regarding ratio \\ +1 = normal, -1 = anomalous}; + \end{pgfonlayer} + \begin{pgfonlayer}{background} + \node[databox, fit=(unlabeled) (labeled), label={[label distance = 1, name=traindatalabel]above:{\textbf{Training Data}}}] (traindata) {}; + \end{pgfonlayer} + + %\draw[arrow] (latent.east) -- node{} (autoenc.west); + + \begin{pgfonlayer}{foreground} + \node[stepsbox, below=of process] (pretrainproc) {Train Autoencoder for $E_A$ Epochs \\ with $L_A$ Learning Rate \\ No Labels Used}; + \node[outputbox, below=.1 of pretrainproc] (pretrainout) {\boxtitle{Outputs} Encoder Network \\ $\mathbf{w}$: Network Weights}; + \end{pgfonlayer} + \begin{pgfonlayer}{background} + \node[procbox, fit=(pretrainproc) (pretrainout), label={[label distance = 1, name=pretrainlab]above:{\textbf{Pre-Training of Autoencoder}}}] (pretrain) {}; + \end{pgfonlayer} + + \begin{pgfonlayer}{foreground} + \node[hlabelbox, below=of hyper] (autoencarch) {\boxtitle{Autoencoder Architecture} Choose based on data type \\ Latent Space Size (based on complexity)}; + \node[hlabelbox, below=.1 of autoencarch] (pretrainhyper) {\boxtitle{Hyperparameters} $E_A$: Number of Epochs \\ $L_A$: Learning Rate}; + \end{pgfonlayer} + \begin{pgfonlayer}{background} + \node[hyperbox, fit=(autoencarch) (pretrainhyper), label={[label distance = 1, name=autoenclabel]above:{\textbf{Pre-Training Hyperparameters}}}] (pretrainhyp) {}; + \end{pgfonlayer} + + \draw[arrow] (pretrainhyp.west) -- (pretrain.east); + + %\draw[arrow] (node cs:name=traindata,angle=10) -- node[arrowlabel]{data type} (node cs:name=autoenc,angle=177); + + % \draw[arrow] (node cs:name=autoenc,angle=196) |- (node cs:name=pretrain,angle=5); + + \begin{pgfonlayer}{foreground} + \node[stepsbox, below=1.4 of pretrain] (calccproc) {1. Init Encoder with $\mathbf{w}$ \\ 2. Forward Pass on all data \\ 3. $\mathbf{c}$ = Mean Latent Representation}; + \node[outputbox, below=.1 of calccproc] (calccout) {\boxtitle{Outputs} $\mathbf{c}$: Hypersphere Center}; + \end{pgfonlayer} + \begin{pgfonlayer}{background} + \node[procbox, fit=(calccproc) (calccout), label={[label distance = 1, name=calcclab]above:{\textbf{Calculate Hypersphere Center}}}] (calcc) {}; + \end{pgfonlayer} + + \draw[arrow] (pretrain.south) -- (calcclab.north); + \draw[arrow] (traindata.east) -- (pretrain.west); + \draw[arrow] (traindata.south) |- (calcc.west); + + %\draw[arrow] (node cs:name=traindata,angle=45) |- node[arrowlabel]{all training data, labels removed} (node cs:name=pretrain,angle=160); + %\draw[arrow] (node cs:name=traindata,angle=-45) |- node[arrowlabel]{all training data, labels removed} (node cs:name=calcc,angle=200); + + \begin{pgfonlayer}{foreground} + \node[stepsbox, below=1.4 of calcc] (maintrainproc) {Train Network for $E_M$ Epochs \\ with $L_M$ Learning Rate \\ Considers Labels with $\eta$ strength}; + \node[outputbox, below=.1 of maintrainproc] (maintrainout) {\boxtitle{Outputs} Encoder Network \\ $\mathbf{w}$: Network Weights \\ $\mathbf{c}$: Hypersphere Center}; + \end{pgfonlayer} + \begin{pgfonlayer}{background} + \node[procbox, fit=(maintrainproc) (maintrainout), label={[label distance = 1, name=maintrainlab]above:{\textbf{Main Training}}}] (maintrain) {}; + \end{pgfonlayer} + + \begin{pgfonlayer}{foreground} + \node[hlabelbox, below=11.25 of hyper] (maintrainhyper) {$E_M$: Number of Epochs \\ $L_M$: Learning Rate \\ $\eta$: Strength Labeled/Unlabeled}; + \end{pgfonlayer} + \begin{pgfonlayer}{background} + \node[hyperbox, fit=(maintrainhyper), label={[label distance = 1, name=autoenclabel]above:{\textbf{Main-Training Hyperparameters}}}] (maintrainhyp) {}; + \end{pgfonlayer} + + \draw[arrow] (node cs:name=pretrain,angle=-20) -- +(1, 0) |- (node cs:name=maintrain,angle=20); + + + %\draw[arrow] (pretrainoutput.south) -- (node cs:name=maintrain,angle=22); + \draw[arrow] (calcc.south) -- (maintrainlab.north); + \draw[arrow] (traindata.south) |- (maintrain.west); + %\draw[arrow] (node cs:name=traindata,angle=-135) |- node[arrowlabel]{all training data, including labels} (maintrain.west); + \draw[arrow] (maintrainhyp.west) -- (maintrain.east); + + + \begin{pgfonlayer}{foreground} + \node[stepsbox, below=1.4 of maintrain] (inferenceproc) {Forward Pass through Network = $\mathbf{p}$ \\ Calculate Geometric Distance $\mathbf{p} \rightarrow \mathbf{c}$ \\ Anomaly Score = Geometric Distance}; + \node[outputbox, below=.1 of inferenceproc] (inferenceout) {\boxtitle{Outputs} Anomaly Score (Analog Value) \\ Higher for Anomalies}; + \end{pgfonlayer} + \begin{pgfonlayer}{background} + \node[procbox, fit=(inferenceproc) (inferenceout), label={[label distance = 1, name=inferencelab]above:{\textbf{Inference}}}] (inference) {}; + \end{pgfonlayer} + + \begin{pgfonlayer}{foreground} + \node[hlabelbox, below=11.8 of traindata] (newdatasample) {\boxtitle{New Data Sample} Same data type as training data}; + \end{pgfonlayer} + \begin{pgfonlayer}{background} + \node[databox, fit=(newdatasample), label={[label distance = 1] above:{\textbf{Unseen Data}}}] (newdata) {}; + \end{pgfonlayer} + + \draw[arrow] (maintrain.south) -- (inferencelab.north); + \draw[arrow] (newdata.east) -- (inference.west); + +\end{tikzpicture} +\end{document} + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/thesis/third_party/PlotNeuralNet/deepsad/Makefile b/thesis/third_party/PlotNeuralNet/deepsad/Makefile index b6a006c..1efed0a 100644 --- a/thesis/third_party/PlotNeuralNet/deepsad/Makefile +++ b/thesis/third_party/PlotNeuralNet/deepsad/Makefile @@ -1,6 +1,6 @@ # ====== CONFIG ====== # Add names (without extension). Example: NAMES = report thesis notes -NAMES = subter_lenet_arch subter_ef_arch +NAMES = subter_lenet_arch subter_ef_arch arch_ef_encoder arch_ef_decoder arch_lenet_encoder arch_lenet_decoder TEX = $(NAMES:%=%.tex) PDF = $(NAMES:%=%.pdf) diff --git a/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_decoder.py b/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_decoder.py new file mode 100644 index 0000000..cb44f02 --- /dev/null +++ b/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_decoder.py @@ -0,0 +1,189 @@ +# subter_lenet_arch.py +# Requires running from inside the PlotNeuralNet repo, like: python3 ../subter_lenet_arch.py +import sys, argparse + +sys.path.append("../") # import pycore from repo root + +from pycore.tikzeng import * + +parser = argparse.ArgumentParser() +parser.add_argument("--rep_dim", type=int, default=1024, help="latent size for FC") +args = parser.parse_args() +REP = int(args.rep_dim) + +# Visual scales so the huge width doesn't dominate the figure +H32, H16, H8, H1 = 26, 18, 12, 1 +D2048, D1024, D512, D256, D128, D1 = 52, 36, 24, 12, 6, 1 +W1, W4, W8, W16, W32 = 1, 2, 2, 4, 8 + + +arch = [ + to_head(".."), + to_cor(), + to_begin(), + to_Conv( + "latent", + n_filer="", + s_filer="latent dim", + offset="(2,0,0)", + to="(0,0,0)", + height=H8 * 1.6, + depth=D1, + width=W1, + caption=f"Latent Space", + ), + # to_connection("fc1", "latent"), + # --------------------------- DECODER --------------------------- + # FC back to 16384 + to_fc( + "fc3", + n_filer="{{8×128×8}}", + offset="(2,0,0)", + to="(latent-east)", + height=H1, + depth=D512, + width=W1, + caption=f"FC", + ), + to_Conv( + "unsqueeze", + s_filer="", + n_filer=32, + offset="(2,0,0)", + to="(fc3-east)", + height=H8, + depth=D128, + width=W32, + caption="unsqueeze", + ), + # to_connection("latent", "fc3"), + # Reshape to 4×8×512 + to_UnPool( + "up1", + offset="(2,0,0)", + to="(unsqueeze-east)", + height=H16, + depth=D256, + width=W32, + caption="", + ), + to_Conv( + "dwdeconv1", + s_filer="", + n_filer=1, + offset="(0,0,0)", + to="(up1-east)", + height=H16, + depth=D256, + width=W1, + caption="deconv1", + ), + to_Conv( + "dwdeconv2", + s_filer="{{256×16}}", + n_filer=32, + offset="(0,0,0)", + to="(dwdeconv1-east)", + height=H16, + depth=D256, + width=W32, + caption="", + ), + to_UnPool( + "up2", + offset="(2,0,0)", + to="(dwdeconv2-east)", + height=H16, + depth=D1024, + width=W32, + caption="", + ), + to_Conv( + "dwdeconv3", + s_filer="", + n_filer=1, + offset="(0,0,0)", + to="(up2-east)", + height=H16, + depth=D1024, + width=W1, + caption="deconv2", + ), + to_Conv( + "dwdeconv4", + s_filer="{{1024×16}}", + n_filer=16, + offset="(0,0,0)", + to="(dwdeconv3-east)", + height=H16, + depth=D1024, + width=W16, + caption="", + ), + to_UnPool( + "up3", + offset="(2,0,0)", + to="(dwdeconv4-east)", + height=H32, + depth=D2048, + width=W16, + caption="", + ), + to_Conv( + "dwdeconv5", + s_filer="", + n_filer=1, + offset="(0,0,0)", + to="(up3-east)", + height=H32, + depth=D2048, + width=W1, + caption="deconv3", + ), + to_Conv( + "dwdeconv6", + s_filer="{{2048×32}}", + n_filer=8, + offset="(0,0,0)", + to="(dwdeconv5-east)", + height=H32, + depth=D2048, + width=W8, + caption="", + ), + to_Conv( + "outconv", + s_filer="{{2048×32}}", + n_filer=1, + offset="(2,0,0)", + to="(dwdeconv6-east)", + height=H32, + depth=D2048, + width=W1, + caption="deconv4", + ), + # to_connection("up2", "deconv2"), + # Output + to_Conv( + "out", + s_filer="{{2048×32}}", + n_filer=1, + offset="(2,0,0)", + to="(outconv-east)", + height=H32, + depth=D2048, + width=W1, + caption="output", + ), + # to_connection("deconv2", "out"), + to_end(), +] + + +def main(): + name = "subter_lenet_arch" + to_generate(arch, name + ".tex") + + +if __name__ == "__main__": + main() diff --git a/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_decoder.tex b/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_decoder.tex new file mode 100644 index 0000000..254c5ba --- /dev/null +++ b/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_decoder.tex @@ -0,0 +1,223 @@ + +\documentclass[border=8pt, multi, tikz]{standalone} +\usepackage{import} +\subimport{../layers/}{init} +\usetikzlibrary{positioning} +\usetikzlibrary{3d} %for including external image + + +\def\ConvColor{rgb:yellow,5;red,2.5;white,5} +\def\ConvReluColor{rgb:yellow,5;red,5;white,5} +\def\PoolColor{rgb:red,1;black,0.3} +\def\UnpoolColor{rgb:blue,2;green,1;black,0.3} +\def\FcColor{rgb:blue,5;red,2.5;white,5} +\def\FcReluColor{rgb:blue,5;red,5;white,4} +\def\SoftmaxColor{rgb:magenta,5;black,7} +\def\SumColor{rgb:blue,5;green,15} + + +\newcommand{\copymidarrow}{\tikz \draw[-Stealth,line width=0.8mm,draw={rgb:blue,4;red,1;green,1;black,3}] (-0.3,0) -- ++(0.3,0);} + +\begin{document} +\begin{tikzpicture} +\tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7] +\tikzstyle{copyconnection}=[ultra thick,every node/.style={sloped,allow upside down},draw={rgb:blue,4;red,1;green,1;black,3},opacity=0.7] + + +\pic[shift={(2,0,0)}] at (0,0,0) + {Box={ + name=latent, + caption=Latent Space, + xlabel={{, }}, + zlabel=latent dim, + fill=\ConvColor, + height=19.200000000000003, + width=1, + depth=1 + } + }; + + +\pic[shift={(2,0,0)}] at (latent-east) + {Box={ + name=fc3, + caption=FC, + xlabel={{" ","dummy"}}, + zlabel={{8×128×8}}, + fill=\FcColor, + opacity=0.8, + height=1, + width=1, + depth=24 + } + }; + + +\pic[shift={(2,0,0)}] at (fc3-east) + {Box={ + name=unsqueeze, + caption=unsqueeze, + xlabel={{32, }}, + zlabel=, + fill=\ConvColor, + height=12, + width=8, + depth=6 + } + }; + + +\pic[shift={ (2,0,0) }] at (unsqueeze-east) + {Box={ + name=up1, + caption=, + fill=\UnpoolColor, + opacity=0.5, + height=18, + width=8, + depth=12 + } + }; + + +\pic[shift={(0,0,0)}] at (up1-east) + {Box={ + name=dwdeconv1, + caption=deconv1, + xlabel={{1, }}, + zlabel=, + fill=\ConvColor, + height=18, + width=1, + depth=12 + } + }; + + +\pic[shift={(0,0,0)}] at (dwdeconv1-east) + {Box={ + name=dwdeconv2, + caption=, + xlabel={{32, }}, + zlabel={{256×16}}, + fill=\ConvColor, + height=18, + width=8, + depth=12 + } + }; + + +\pic[shift={ (2,0,0) }] at (dwdeconv2-east) + {Box={ + name=up2, + caption=, + fill=\UnpoolColor, + opacity=0.5, + height=18, + width=8, + depth=36 + } + }; + + +\pic[shift={(0,0,0)}] at (up2-east) + {Box={ + name=dwdeconv3, + caption=deconv2, + xlabel={{1, }}, + zlabel=, + fill=\ConvColor, + height=18, + width=1, + depth=36 + } + }; + + +\pic[shift={(0,0,0)}] at (dwdeconv3-east) + {Box={ + name=dwdeconv4, + caption=, + xlabel={{16, }}, + zlabel={{1024×16}}, + fill=\ConvColor, + height=18, + width=4, + depth=36 + } + }; + + +\pic[shift={ (2,0,0) }] at (dwdeconv4-east) + {Box={ + name=up3, + caption=, + fill=\UnpoolColor, + opacity=0.5, + height=26, + width=4, + depth=52 + } + }; + + +\pic[shift={(0,0,0)}] at (up3-east) + {Box={ + name=dwdeconv5, + caption=deconv3, + xlabel={{1, }}, + zlabel=, + fill=\ConvColor, + height=26, + width=1, + depth=52 + } + }; + + +\pic[shift={(0,0,0)}] at (dwdeconv5-east) + {Box={ + name=dwdeconv6, + caption=, + xlabel={{8, }}, + zlabel={{2048×32}}, + fill=\ConvColor, + height=26, + width=2, + depth=52 + } + }; + + +\pic[shift={(2,0,0)}] at (dwdeconv6-east) + {Box={ + name=outconv, + caption=deconv4, + xlabel={{1, }}, + zlabel={{2048×32}}, + fill=\ConvColor, + height=26, + width=1, + depth=52 + } + }; + + +\pic[shift={(2,0,0)}] at (outconv-east) + {Box={ + name=out, + caption=output, + xlabel={{1, }}, + zlabel={{2048×32}}, + fill=\ConvColor, + height=26, + width=1, + depth=52 + } + }; + + +\end{tikzpicture} +\end{document} + diff --git a/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_encoder.py b/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_encoder.py new file mode 100644 index 0000000..1bb7b26 --- /dev/null +++ b/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_encoder.py @@ -0,0 +1,159 @@ +# subter_lenet_arch.py +# Requires running from inside the PlotNeuralNet repo, like: python3 ../subter_lenet_arch.py +import sys, argparse + +sys.path.append("../") # import pycore from repo root + +from pycore.tikzeng import * + +parser = argparse.ArgumentParser() +parser.add_argument("--rep_dim", type=int, default=1024, help="latent size for FC") +args = parser.parse_args() +REP = int(args.rep_dim) + +# Visual scales so the huge width doesn't dominate the figure +H32, H16, H8, H1 = 26, 18, 12, 1 +D2048, D1024, D512, D256, D128, D1 = 52, 36, 24, 12, 6, 1 +W1, W4, W8, W16, W32 = 1, 2, 2, 4, 8 + + +arch = [ + to_head(".."), + to_cor(), + to_begin(), + # --------------------------- ENCODER --------------------------- + # Input 1×32×2048 (caption carries H×W; s_filer is numeric) + to_Conv( + "input", + s_filer="{{2048×32}}", + n_filer=1, + offset="(0,0,0)", + to="(0,0,0)", + height=H32, + depth=D2048, + width=W1, + caption="input", + ), + # Conv1 (5x5, same): 1->8, 32×2048 + to_Conv( + "dwconv1", + s_filer="", + n_filer=1, + offset="(2,0,0)", + to="(input-east)", + height=H32, + depth=D2048, + width=W1, + caption="", + ), + to_Conv( + "dwconv2", + s_filer="", + n_filer=16, + offset="(0,0,0)", + to="(dwconv1-east)", + height=H32, + depth=D2048, + width=W16, + caption="conv1", + ), + # Pool1 2×2: 32×2048 -> 16×1024 + # to_connection("input", "conv1"), + to_Pool( + "pool1", + offset="(0,0,0)", + to="(dwconv2-east)", + height=H32, + depth=D512, + width=W16, + caption="", + ), + # Conv2 (5x5, same): 8->4, stays 16×1024 + to_Conv( + "dwconv3", + s_filer="", + n_filer=1, + offset="(2,0,0)", + to="(pool1-east)", + height=H32, + depth=D512, + width=W1, + caption="", + ), + to_Conv( + "dwconv4", + s_filer="", + n_filer=32, + offset="(0,0,0)", + to="(dwconv3-east)", + height=H32, + depth=D512, + width=W32, + caption="conv2", + ), + # Pool2 2×2: 16×1024 -> 8×512 + # to_connection("pool1", "conv2"), + to_Pool( + "pool2", + offset="(0,0,0)", + to="(dwconv4-east)", + height=H16, + depth=D256, + width=W32, + caption="", + ), + to_Pool( + "pool3", + offset="(0,0,0)", + to="(pool2-east)", + height=H8, + depth=D128, + width=W32, + caption="", + ), + to_Conv( + "squeeze", + s_filer="", + n_filer=8, + offset="(2,0,0)", + to="(pool3-east)", + height=H8, + depth=D128, + width=W8, + caption="squeeze", + ), + # FC -> rep_dim (use numeric n_filer) + to_fc( + "fc1", + n_filer="{{8×128×8}}", + offset="(2,0,0)", + to="(squeeze-east)", + height=H1, + depth=D512, + width=W1, + caption=f"FC", + ), + # to_connection("pool2", "fc1"), + # --------------------------- LATENT --------------------------- + to_Conv( + "latent", + n_filer="", + s_filer="latent dim", + offset="(2,0,0)", + to="(fc1-east)", + height=H8 * 1.6, + depth=D1, + width=W1, + caption=f"Latent Space", + ), + to_end(), +] + + +def main(): + name = "subter_lenet_arch" + to_generate(arch, name + ".tex") + + +if __name__ == "__main__": + main() diff --git a/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_encoder.tex b/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_encoder.tex new file mode 100644 index 0000000..7f84007 --- /dev/null +++ b/thesis/third_party/PlotNeuralNet/deepsad/arch_ef_encoder.tex @@ -0,0 +1,181 @@ + +\documentclass[border=8pt, multi, tikz]{standalone} +\usepackage{import} +\subimport{../layers/}{init} +\usetikzlibrary{positioning} +\usetikzlibrary{3d} %for including external image + + +\def\ConvColor{rgb:yellow,5;red,2.5;white,5} +\def\ConvReluColor{rgb:yellow,5;red,5;white,5} +\def\PoolColor{rgb:red,1;black,0.3} +\def\UnpoolColor{rgb:blue,2;green,1;black,0.3} +\def\FcColor{rgb:blue,5;red,2.5;white,5} +\def\FcReluColor{rgb:blue,5;red,5;white,4} +\def\SoftmaxColor{rgb:magenta,5;black,7} +\def\SumColor{rgb:blue,5;green,15} + + +\newcommand{\copymidarrow}{\tikz \draw[-Stealth,line width=0.8mm,draw={rgb:blue,4;red,1;green,1;black,3}] (-0.3,0) -- ++(0.3,0);} + +\begin{document} +\begin{tikzpicture} +\tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7] +\tikzstyle{copyconnection}=[ultra thick,every node/.style={sloped,allow upside down},draw={rgb:blue,4;red,1;green,1;black,3},opacity=0.7] + + +\pic[shift={(0,0,0)}] at (0,0,0) + {Box={ + name=input, + caption=input, + xlabel={{1, }}, + zlabel={{2048×32}}, + fill=\ConvColor, + height=26, + width=1, + depth=52 + } + }; + + +\pic[shift={(2,0,0)}] at (input-east) + {Box={ + name=dwconv1, + caption=, + xlabel={{1, }}, + zlabel=, + fill=\ConvColor, + height=26, + width=1, + depth=52 + } + }; + + +\pic[shift={(0,0,0)}] at (dwconv1-east) + {Box={ + name=dwconv2, + caption=conv1, + xlabel={{16, }}, + zlabel=, + fill=\ConvColor, + height=26, + width=4, + depth=52 + } + }; + + +\pic[shift={ (0,0,0) }] at (dwconv2-east) + {Box={ + name=pool1, + caption=, + fill=\PoolColor, + opacity=0.5, + height=26, + width=4, + depth=24 + } + }; + + +\pic[shift={(2,0,0)}] at (pool1-east) + {Box={ + name=dwconv3, + caption=, + xlabel={{1, }}, + zlabel=, + fill=\ConvColor, + height=26, + width=1, + depth=24 + } + }; + + +\pic[shift={(0,0,0)}] at (dwconv3-east) + {Box={ + name=dwconv4, + caption=conv2, + xlabel={{32, }}, + zlabel=, + fill=\ConvColor, + height=26, + width=8, + depth=24 + } + }; + + +\pic[shift={ (0,0,0) }] at (dwconv4-east) + {Box={ + name=pool2, + caption=, + fill=\PoolColor, + opacity=0.5, + height=18, + width=8, + depth=12 + } + }; + + +\pic[shift={ (0,0,0) }] at (pool2-east) + {Box={ + name=pool3, + caption=, + fill=\PoolColor, + opacity=0.5, + height=12, + width=8, + depth=6 + } + }; + + +\pic[shift={(2,0,0)}] at (pool3-east) + {Box={ + name=squeeze, + caption=squeeze, + xlabel={{8, }}, + zlabel=, + fill=\ConvColor, + height=12, + width=2, + depth=6 + } + }; + + +\pic[shift={(2,0,0)}] at (squeeze-east) + {Box={ + name=fc1, + caption=FC, + xlabel={{" ","dummy"}}, + zlabel={{8×128×8}}, + fill=\FcColor, + opacity=0.8, + height=1, + width=1, + depth=24 + } + }; + + +\pic[shift={(2,0,0)}] at (fc1-east) + {Box={ + name=latent, + caption=Latent Space, + xlabel={{, }}, + zlabel=latent dim, + fill=\ConvColor, + height=19.200000000000003, + width=1, + depth=1 + } + }; + + +\end{tikzpicture} +\end{document} + diff --git a/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_decoder.py b/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_decoder.py new file mode 100644 index 0000000..9e84625 --- /dev/null +++ b/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_decoder.py @@ -0,0 +1,120 @@ +# subter_lenet_arch.py +# Requires running from inside the PlotNeuralNet repo, like: python3 ../subter_lenet_arch.py +import sys, argparse + +sys.path.append("../") # import pycore from repo root + +from pycore.tikzeng import * + +parser = argparse.ArgumentParser() +parser.add_argument("--rep_dim", type=int, default=1024, help="latent size for FC") +args = parser.parse_args() +REP = int(args.rep_dim) + +# Visual scales so the huge width doesn't dominate the figure +H32, H16, H8 = 26, 18, 12 +D2048, D1024, D512 = 52, 36, 24 +W1, W4, W8 = 1, 2, 4 + + +arch = [ + to_head(".."), + to_cor(), + to_begin(), + to_Conv( + "latent", + n_filer="", + s_filer="latent dim", + offset="(2,0,0)", + to="(0,0,0)", + height=H8 * 1.6, + depth=1.3, + width=W1, + caption=f"Latent Space", + ), + # to_connection("fc1", "latent"), + # --------------------------- DECODER --------------------------- + # FC back to 16384 + to_fc( + "fc3", + n_filer="{{4×512×8}}", + offset="(2,0,0)", + to="(latent-east)", + height=1.3, + depth=D512, + width=W1, + caption=f"FC", + ), + # to_connection("latent", "fc3"), + # Reshape to 4×8×512 + to_UnPool( + "up1", + offset="(2,0,0)", + to="(fc3-east)", + height=H16, + depth=D1024, + width=W4, + caption="", + ), + # Up ×2: 8×512 -> 16×1024 (we just draw a labeled box) + # DeConv1 (5×5, same): 4->8, 16×1024 + to_Conv( + "deconv1", + s_filer="{{1024×16}}", + n_filer=8, + offset="(0,0,0)", + to="(up1-east)", + height=H16, + depth=D1024, + width=W8, + caption="deconv1", + ), + # to_connection("fc3", "up1"), + # Up ×2: 16×1024 -> 32×2048 + to_UnPool( + "up2", + offset="(2,0,0)", + to="(deconv1-east)", + height=H32, + depth=D2048, + width=W8, + caption="", + ), + # to_connection("deconv1", "up2"), + # DeConv2 (5×5, same): 8->1, 32×2048 + to_Conv( + "deconv2", + s_filer="{{2048×32}}", + n_filer=1, + offset="(0,0,0)", + to="(up2-east)", + height=H32, + depth=D2048, + width=W1, + caption="deconv2", + ), + # to_connection("up2", "deconv2"), + # Output + to_Conv( + "out", + s_filer="{{2048×32}}", + n_filer=1, + offset="(2,0,0)", + to="(deconv2-east)", + height=H32, + depth=D2048, + width=1.0, + caption="output", + ), + # to_connection("deconv2", "out"), + to_end(), +] + + +def main(): + name = "subter_lenet_arch" + to_generate(arch, name + ".tex") + + +if __name__ == "__main__": + main() diff --git a/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_decoder.tex b/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_decoder.tex new file mode 100644 index 0000000..eca70fb --- /dev/null +++ b/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_decoder.tex @@ -0,0 +1,126 @@ + +\documentclass[border=8pt, multi, tikz]{standalone} +\usepackage{import} +\subimport{../layers/}{init} +\usetikzlibrary{positioning} +\usetikzlibrary{3d} %for including external image + + +\def\ConvColor{rgb:yellow,5;red,2.5;white,5} +\def\ConvReluColor{rgb:yellow,5;red,5;white,5} +\def\PoolColor{rgb:red,1;black,0.3} +\def\UnpoolColor{rgb:blue,2;green,1;black,0.3} +\def\FcColor{rgb:blue,5;red,2.5;white,5} +\def\FcReluColor{rgb:blue,5;red,5;white,4} +\def\SoftmaxColor{rgb:magenta,5;black,7} +\def\SumColor{rgb:blue,5;green,15} + + +\newcommand{\copymidarrow}{\tikz \draw[-Stealth,line width=0.8mm,draw={rgb:blue,4;red,1;green,1;black,3}] (-0.3,0) -- ++(0.3,0);} + +\begin{document} +\begin{tikzpicture} +\tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7] +\tikzstyle{copyconnection}=[ultra thick,every node/.style={sloped,allow upside down},draw={rgb:blue,4;red,1;green,1;black,3},opacity=0.7] + + +\pic[shift={(2,0,0)}] at (0,0,0) + {Box={ + name=latent, + caption=Latent Space, + xlabel={{, }}, + zlabel=latent dim, + fill=\ConvColor, + height=19.200000000000003, + width=1, + depth=1.3 + } + }; + + +\pic[shift={(2,0,0)}] at (latent-east) + {Box={ + name=fc3, + caption=FC, + xlabel={{" ","dummy"}}, + zlabel={{4×512×8}}, + fill=\FcColor, + opacity=0.8, + height=1.3, + width=1, + depth=24 + } + }; + + +\pic[shift={ (2,0,0) }] at (fc3-east) + {Box={ + name=up1, + caption=, + fill=\UnpoolColor, + opacity=0.5, + height=18, + width=2, + depth=36 + } + }; + + +\pic[shift={(0,0,0)}] at (up1-east) + {Box={ + name=deconv1, + caption=deconv1, + xlabel={{8, }}, + zlabel={{1024×16}}, + fill=\ConvColor, + height=18, + width=4, + depth=36 + } + }; + + +\pic[shift={ (2,0,0) }] at (deconv1-east) + {Box={ + name=up2, + caption=, + fill=\UnpoolColor, + opacity=0.5, + height=26, + width=4, + depth=52 + } + }; + + +\pic[shift={(0,0,0)}] at (up2-east) + {Box={ + name=deconv2, + caption=deconv2, + xlabel={{1, }}, + zlabel={{2048×32}}, + fill=\ConvColor, + height=26, + width=1, + depth=52 + } + }; + + +\pic[shift={(2,0,0)}] at (deconv2-east) + {Box={ + name=out, + caption=output, + xlabel={{1, }}, + zlabel={{2048×32}}, + fill=\ConvColor, + height=26, + width=1.0, + depth=52 + } + }; + + +\end{tikzpicture} +\end{document} + diff --git a/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_encoder.py b/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_encoder.py new file mode 100644 index 0000000..d481edf --- /dev/null +++ b/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_encoder.py @@ -0,0 +1,117 @@ +# subter_lenet_arch.py +# Requires running from inside the PlotNeuralNet repo, like: python3 ../subter_lenet_arch.py +import sys, argparse + +sys.path.append("../") # import pycore from repo root + +from pycore.tikzeng import * + +parser = argparse.ArgumentParser() +parser.add_argument("--rep_dim", type=int, default=1024, help="latent size for FC") +args = parser.parse_args() +REP = int(args.rep_dim) + +# Visual scales so the huge width doesn't dominate the figure +H32, H16, H8 = 26, 18, 12 +D2048, D1024, D512 = 52, 36, 24 +W1, W4, W8 = 1, 2, 4 + + +arch = [ + to_head(".."), + to_cor(), + to_begin(), + # --------------------------- ENCODER --------------------------- + # Input 1×32×2048 (caption carries H×W; s_filer is numeric) + to_Conv( + "input", + s_filer="{{2048×32}}", + n_filer=1, + offset="(0,0,0)", + to="(0,0,0)", + height=H32, + depth=D2048, + width=W1, + caption="input", + ), + # Conv1 (5x5, same): 1->8, 32×2048 + to_Conv( + "conv1", + s_filer="{{1024×16}}", + n_filer=8, + offset="(2,0,0)", + to="(input-east)", + height=H32, + depth=D2048, + width=W8, + caption="conv1", + ), + # Pool1 2×2: 32×2048 -> 16×1024 + # to_connection("input", "conv1"), + to_Pool( + "pool1", + offset="(0,0,0)", + to="(conv1-east)", + height=H16, + depth=D1024, + width=W8, + caption="", + ), + # Conv2 (5x5, same): 8->4, stays 16×1024 + to_Conv( + "conv2", + s_filer="{{512×8}}", + n_filer=4, + offset="(2,0,0)", + to="(pool1-east)", + height=H16, + depth=D1024, + width=W4, + caption="conv2", + ), + # Pool2 2×2: 16×1024 -> 8×512 + # to_connection("pool1", "conv2"), + to_Pool( + "pool2", + offset="(0,0,0)", + to="(conv2-east)", + height=H8, + depth=D512, + width=W4, + caption="", + ), + # FC -> rep_dim (use numeric n_filer) + to_fc( + "fc1", + n_filer="{{4×512×8}}", + offset="(2,0,0)", + to="(pool2-east)", + height=1.3, + depth=D512, + width=W1, + caption=f"FC", + ), + # to_connection("pool2", "fc1"), + # --------------------------- LATENT --------------------------- + to_Conv( + "latent", + n_filer="", + s_filer="latent dim", + offset="(2,0,0)", + to="(fc1-east)", + height=H8 * 1.6, + depth=1.3, + width=W1, + caption=f"Latent Space", + ), + to_end(), +] + + +def main(): + name = "subter_lenet_arch" + to_generate(arch, name + ".tex") + + +if __name__ == "__main__": + main() diff --git a/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_encoder.tex b/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_encoder.tex new file mode 100644 index 0000000..e631f4b --- /dev/null +++ b/thesis/third_party/PlotNeuralNet/deepsad/arch_lenet_encoder.tex @@ -0,0 +1,126 @@ + +\documentclass[border=8pt, multi, tikz]{standalone} +\usepackage{import} +\subimport{../layers/}{init} +\usetikzlibrary{positioning} +\usetikzlibrary{3d} %for including external image + + +\def\ConvColor{rgb:yellow,5;red,2.5;white,5} +\def\ConvReluColor{rgb:yellow,5;red,5;white,5} +\def\PoolColor{rgb:red,1;black,0.3} +\def\UnpoolColor{rgb:blue,2;green,1;black,0.3} +\def\FcColor{rgb:blue,5;red,2.5;white,5} +\def\FcReluColor{rgb:blue,5;red,5;white,4} +\def\SoftmaxColor{rgb:magenta,5;black,7} +\def\SumColor{rgb:blue,5;green,15} + + +\newcommand{\copymidarrow}{\tikz \draw[-Stealth,line width=0.8mm,draw={rgb:blue,4;red,1;green,1;black,3}] (-0.3,0) -- ++(0.3,0);} + +\begin{document} +\begin{tikzpicture} +\tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7] +\tikzstyle{copyconnection}=[ultra thick,every node/.style={sloped,allow upside down},draw={rgb:blue,4;red,1;green,1;black,3},opacity=0.7] + + +\pic[shift={(0,0,0)}] at (0,0,0) + {Box={ + name=input, + caption=input, + xlabel={{1, }}, + zlabel={{2048×32}}, + fill=\ConvColor, + height=26, + width=1, + depth=52 + } + }; + + +\pic[shift={(2,0,0)}] at (input-east) + {Box={ + name=conv1, + caption=conv1, + xlabel={{8, }}, + zlabel={{1024×16}}, + fill=\ConvColor, + height=26, + width=4, + depth=52 + } + }; + + +\pic[shift={ (0,0,0) }] at (conv1-east) + {Box={ + name=pool1, + caption=, + fill=\PoolColor, + opacity=0.5, + height=18, + width=4, + depth=36 + } + }; + + +\pic[shift={(2,0,0)}] at (pool1-east) + {Box={ + name=conv2, + caption=conv2, + xlabel={{4, }}, + zlabel={{512×8}}, + fill=\ConvColor, + height=18, + width=2, + depth=36 + } + }; + + +\pic[shift={ (0,0,0) }] at (conv2-east) + {Box={ + name=pool2, + caption=, + fill=\PoolColor, + opacity=0.5, + height=12, + width=2, + depth=24 + } + }; + + +\pic[shift={(2,0,0)}] at (pool2-east) + {Box={ + name=fc1, + caption=FC, + xlabel={{" ","dummy"}}, + zlabel={{4×512×8}}, + fill=\FcColor, + opacity=0.8, + height=1.3, + width=1, + depth=24 + } + }; + + +\pic[shift={(2,0,0)}] at (fc1-east) + {Box={ + name=latent, + caption=Latent Space, + xlabel={{, }}, + zlabel=latent dim, + fill=\ConvColor, + height=19.200000000000003, + width=1, + depth=1.3 + } + }; + + +\end{tikzpicture} +\end{document} + diff --git a/thesis/third_party/PlotNeuralNet/deepsad/subter_lenet_arch.tex b/thesis/third_party/PlotNeuralNet/deepsad/subter_lenet_arch.tex index beff65d..8ae899e 100644 --- a/thesis/third_party/PlotNeuralNet/deepsad/subter_lenet_arch.tex +++ b/thesis/third_party/PlotNeuralNet/deepsad/subter_lenet_arch.tex @@ -5,7 +5,6 @@ \usetikzlibrary{positioning} \usetikzlibrary{3d} %for including external image - \def\ConvColor{rgb:yellow,5;red,2.5;white,5} \def\ConvReluColor{rgb:yellow,5;red,5;white,5} \def\PoolColor{rgb:red,1;black,0.3} @@ -15,7 +14,6 @@ \def\SoftmaxColor{rgb:magenta,5;black,7} \def\SumColor{rgb:blue,5;green,15} - \newcommand{\copymidarrow}{\tikz \draw[-Stealth,line width=0.8mm,draw={rgb:blue,4;red,1;green,1;black,3}] (-0.3,0) -- ++(0.3,0);} \begin{document} @@ -23,91 +21,7 @@ \tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7] \tikzstyle{copyconnection}=[ultra thick,every node/.style={sloped,allow upside down},draw={rgb:blue,4;red,1;green,1;black,3},opacity=0.7] - -\pic[shift={(0,0,0)}] at (0,0,0) - {Box={ - name=input, - caption=input, - xlabel={{1, }}, - zlabel={{2048×32}}, - fill=\ConvColor, - height=26, - width=1, - depth=52 - } - }; - - -\pic[shift={(2,0,0)}] at (input-east) - {Box={ - name=conv1, - caption=conv1, - xlabel={{8, }}, - zlabel={{1024×16}}, - fill=\ConvColor, - height=26, - width=4, - depth=52 - } - }; - - -\pic[shift={ (0,0,0) }] at (conv1-east) - {Box={ - name=pool1, - caption=, - fill=\PoolColor, - opacity=0.5, - height=18, - width=4, - depth=36 - } - }; - - -\pic[shift={(2,0,0)}] at (pool1-east) - {Box={ - name=conv2, - caption=conv2, - xlabel={{4, }}, - zlabel={{512×8}}, - fill=\ConvColor, - height=18, - width=2, - depth=36 - } - }; - - -\pic[shift={ (0,0,0) }] at (conv2-east) - {Box={ - name=pool2, - caption=, - fill=\PoolColor, - opacity=0.5, - height=12, - width=2, - depth=24 - } - }; - - -\pic[shift={(2,0,0)}] at (pool2-east) - {Box={ - name=fc1, - caption=FC, - xlabel={{" ","dummy"}}, - zlabel={{4×512×8}}, - fill=\FcColor, - opacity=0.8, - height=1.3, - width=1, - depth=24 - } - }; - - -\pic[shift={(2,0,0)}] at (fc1-east) +\pic[shift={(2,0,0)}] at (0,0,0) {Box={ name=latent, caption=Latent Space, @@ -120,7 +34,6 @@ } }; - \pic[shift={(2,0,0)}] at (latent-east) {Box={ name=fc3, @@ -135,7 +48,6 @@ } }; - \pic[shift={ (2,0,0) }] at (fc3-east) {Box={ name=up1, @@ -148,7 +60,6 @@ } }; - \pic[shift={(0,0,0)}] at (up1-east) {Box={ name=deconv1, @@ -162,7 +73,6 @@ } }; - \pic[shift={ (2,0,0) }] at (deconv1-east) {Box={ name=up2, @@ -175,7 +85,6 @@ } }; - \pic[shift={(0,0,0)}] at (up2-east) {Box={ name=deconv2, @@ -189,7 +98,6 @@ } }; - \pic[shift={(2,0,0)}] at (deconv2-east) {Box={ name=out, @@ -203,7 +111,5 @@ } }; - \end{tikzpicture} \end{document} -