使用 TikZ 绘制自动编码器结构

使用 TikZ 绘制自动编码器结构

我正在尝试使用 TikZ 绘制一个去噪自动编码器。我不需要不同层之间的所有连接。每层一个块表示之类的简单东西就足够了。我理想情况下希望有两个大块,它们有编码器层和解码器层。到目前为止,我只做到了这一点。

    \begin{tikzpicture}
    [title/.style={font=\fontsize{18}{18}\color{black!45}},
    En/.style={rectangle, draw, fill=blue!23, rounded corners, minimum height=9em},
    De/.style={rectangle, draw, fill=blue!23, rounded corners, minimum height=9em}]
    % Place nodes
    \node [En, outer sep=8pt, align=center] (s1) at (5,8.3) {In};
    \node [En, outer sep=8pt, align=center] (s2) at (7.65,8.3) {E1};
    \node [En, outer sep=8pt] (s3) at (10.3,8.3) {E2};
    \node [draw=black!50, fit={(s1) (s2) (s3)}] (back) {};

    \node [De, outer sep=8pt, align=center] (s4) at (12.95,8.3) {D1};
    \node [De, outer sep=8pt, align=center] (s5) at (15.6,8.3) {D5};
    \node [De, outer sep=8pt] (s6) at (18.3,8.3) {Ot};
    \node [draw=black!50, fit={(s4) (s5) (s6)}] (back) {};
\end{tikzpicture}

这让我 在此处输入图片描述

我想要的是 在此处输入图片描述

抱歉,我是在 MS 画图时这样做的。

答案1

只是为了好玩:

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.misc, fit}

\begin{document}
\begin{tikzpicture}[
    circ/.style={circle, minimum size=1cm, 
        draw=black!70, fill=red!80!black},
    cross/.style={circle, minimum size=1cm,
        draw=black!70, fill=white,
        path picture={\node[cross out, draw, ultra thick, red, minimum size=5mm]{};}},
    H/.style={rounded corners, fill=black!20, row sep=2mm},
    column/.pic={
        \matrix (#1) [H, label={[name=l#1]#1}]
        {\node[circ]{};\\
        \node[cross]{};\\
        \node[circ]{};\\
        \node[cross]{};\\
        \node[cross]{};\\
        \node[circ]{};\\};
        }
    ]

    \path (0,0) pic{column=Input};
    \path (1.5,0) pic{column=H1};
    \path (3,0) pic{column=H2};

    \node[fit=(Input) (lInput) (H2), draw, label=Encoder]{};

    \begin{scope}[xshift=5cm]
    \path (0,0) pic{column=H3};
    \path (1.5,0) pic{column=H4};
    \path (3,0) pic{column=Output};

    \node[fit=(H3) (lOutput) (Output), draw, label=Decoder]{};
    \end{scope}

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容