3D 网络视角

3D 网络视角

我想创建一个具有如下所示的 3D 侧视图风格的图像。

我的目标是通过示例输入和示例输出图像来演示网络架构。如何获得侧面透视图来绘制图像和块?

图像创建风格

使用公认的解决方案代码,我做了一个非常不雅的例子:

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d}

\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
    \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
    \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
    \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
    \tikz@canvas@is@plane
}
\makeatother

\tikzset{pics/fake box/.style args={% #1=color, #2=x dimension, #3=y dimension, #4=z dimension
        #1 with dimensions #2 and #3 and #4}{
        code={
            \draw[black,ultra thin,fill=#1]  (0,0,0) coordinate(-front-bottom-left) to
            ++ (0,#3,0) coordinate(-front-top-right) --++
            (#2,0,0) coordinate(-front-top-right) --++ (0,-#3,0) 
            coordinate(-front-bottom-right) -- cycle;
            \draw[black,ultra thin,fill=#1] (0,#3,0)  --++ 
            (0,0,#4) coordinate(-back-top-left) --++ (#2,0,0) 
            coordinate(-back-top-right) --++ (0,0,-#4)  -- cycle;
            \draw[black,ultra thin,fill=#1!40!black] (#2,0,0) --++ (0,0,#4) coordinate(-back-bottom-right)
            --++ (0,#3,0) --++ (0,0,-#4) -- cycle;
        }
}}


\begin{document}

\begin{tikzpicture}[x={(1,0)},y={(0,1)},z={({cos(45)},{sin(45)})},
font=\sffamily\tiny,scale=2]

    \node[canvas is zy plane at x = 0.4, transform shape,anchor=south] at (0,0.2)
    {\includegraphics[width=1cm,height=2cm]{{grains}}};
    \path (0.1,0) -- (0.4,0)  
    node[midway,below,text width=8mm]{Grain angle map};

    \path[circle, draw, line width=0.25mm, green] (2.0, 2.4) edge[bend right] node [right] {Encoder} (3.8, 1.0);
    \path[circle, draw, line width=0.25mm, blue] (4.6, 1.0) edge[bend right] node [right] {Generator} (7.2, 2.4);

    \draw pic (box1-1) at (1.0,0,0) {fake box={green} with dimensions 0.1 and 4 and 2};
    \path (box1-1-front-bottom-left) -- (box1-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H\times W\times8$}};
    %
    \draw pic (box2-1) at (1.4,0,0) {fake box={green} with dimensions 0.15 and 2 and 1};
    \path (box2-1-front-bottom-left) -- (box2-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/2\times W/2\times16$}};
    %
    \draw pic (box3-1) at (1.8,0,0) {fake box={green} with dimensions 0.2 and 1.5 and .75};
    \path (box3-1-front-bottom-left) -- (box3-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/4\times W/4\times32$}};
    %
    \draw pic (box4-1) at (2.2,0,0) {fake box={green} with dimensions 0.25 and 1.5*3/4 and 0.75*3/4};
    \path (box4-1-front-bottom-left) -- (box4-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/8\times W/8\times64$}};
    %
    \draw pic (box5-1) at (2.6,0,0) {fake box={green} with dimensions 0.25 and 1.5*9/16 and 0.75*9/16};
    \path (box5-1-front-bottom-left) -- (box5-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/16\times W/16\times128$}};
    %
    \draw pic (box6-1) at (3.0,0,0) {fake box={green} with dimensions 0.25 and 1.5*27/64 and 0.75*27/64};
    \path (box6-1-front-bottom-left) -- (box6-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/32\times W/32\times256$}};
    %
    \draw pic (box7-1) at (3.4,0,0) {fake box={green} with dimensions 0.25 and 0.5 and 0.25};
    \path (box7-1-front-bottom-left) -- (box7-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/64\times W/64\times512$}};
    %
    \draw pic (box8-1) at (4.0,0,0) {fake box={red} with dimensions 0.75 and 0.1 and 0.1};
    \draw pic (box8-2) at (4.375,0,0) {fake box={yellow} with dimensions 0.2 and 0.1 and 0.1};
    \path (box8-1-front-bottom-left) -- (box8-1-front-bottom-right)
    node[midway,below,text width=8mm]{Latent vector};
    \draw[canvas is xy plane at z = 0,black,<-] (4.445, .1) -- (4.445, .5);
    \path (4.445, .5) -- (4.475, .5)  
    node[midway,above,text width=20mm]{Grain Boundary Transition Temp};

    % lots of boxes in different colors and sizes
    \draw pic (box1-1) at (4.8,0,0) {fake box={blue} with dimensions 0.25 and 0.5 and 0.25 };
    \path (box1-1-front-bottom-left) -- (box1-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/64\times W/64\times512$}};
    %
    \draw pic (box2-1) at (5.2,0,0) {fake box={blue} with dimensions 0.25 and 1.5*27/64 and 0.75*27/64};
    \path (box2-1-front-bottom-left) -- (box2-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/32\times W/32\times256$}};
    %
    \draw pic (box3-1) at (5.6,0,0) {fake box={blue} with dimensions 0.25 and 1.5*9/16 and 0.75*9/16};
    \path (box3-1-front-bottom-left) -- (box3-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/16\times W/16\times128$}};
    %
    \draw pic (box4-1) at (6.0,0,0) {fake box={blue} with dimensions 0.25 and 1.5*3/4 and 0.75*3/4};
    \path (box4-1-front-bottom-left) -- (box4-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/8\times W/8\times64$}};
    %
    \draw pic (box5-1) at (6.4,0,0) {fake box={blue} with dimensions 0.2 and 1.5 and .75};
    \path (box5-1-front-bottom-left) -- (box5-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/4\times W/4\times32$}};
    %
    \draw pic (box6-1) at (6.8,0,0) {fake box={blue} with dimensions 0.15 and 2 and 1};
    \path (box6-1-front-bottom-left) -- (box6-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H/2\times W/2\times16$}};
    %
    \draw pic (box7-1) at (7.2,0,0) {fake box={blue} with dimensions 0.1 and 4 and 2};
    \path (box7-1-front-bottom-left) -- (box7-1-front-bottom-right)
    node[below,text width=3mm]{\rotatebox{90}{$H\times W\times8$}};
    %
    \path (7.4, 0) -- (7.5, 0)
    node[xshift=8,below,text width=8mm]{\rotatebox{90}{$H\times W \times2$}};

    \node[canvas is zy plane at x = 0, transform shape,anchor=south] at (7.8,0.2)
    {\includegraphics[width=1cm,height=2cm]{{252-input}}};
    \path (8.2-0.5,.2) -- (8.5,0.4)  
    node[midway,below,text width=12mm]{Domain Structure};

\end{tikzpicture}

\end{document}

如何不制作图像

答案1

先给你一个开始。你可以通过调整角度 60 度来改变视角,对于高级选项,请考虑使用tikz-3dplot。这是一个pic在给定点绘制假框的对象,坐标指的是其前左下角。

\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{3d}
\tikzset{pics/fake box/.style args={% #1=color, #2=x dimension, #3=y dimension, #4=z dimension
#1 with dimensions #2 and #3 and #4}{
code={
\draw[gray,ultra thin,fill=#1]  (0,0,0) coordinate(-front-bottom-left) to
++ (0,#3,0) coordinate(-front-top-right) --++
(#2,0,0) coordinate(-front-top-right) --++ (0,-#3,0) 
coordinate(-front-bottom-right) -- cycle;
\draw[gray,ultra thin,fill=#1] (0,#3,0)  --++ 
 (0,0,#4) coordinate(-back-top-left) --++ (#2,0,0) 
 coordinate(-back-top-right) --++ (0,0,-#4)  -- cycle;
\draw[gray,ultra thin,fill=#1!40!black] (#2,0,0) --++ (0,0,#4) coordinate(-back-bottom-right)
--++ (0,#3,0) --++ (0,0,-#4) -- cycle;
}
}}
\begin{document}

\begin{tikzpicture}[x={(1,0)},y={(0,1)},z={({cos(60)},{sin(60)})},
font=\sffamily\small,scale=2]
%
% comment these out if you want to see where the axes point to
% \draw[-latex] (0,0,0) -- (3,0,0) node[below]{$x$};
% \draw[-latex] (0,0,0) -- (0,3,0) node[left]{$y$};
% \draw[-latex] (0,0,0) -- (0,0,3) node[below]{$z$};
% a plane
\draw[canvas is yz plane at x = 0, transform shape, draw = red, fill =
red!50!black, opacity = 0.5] (0,1) rectangle (3,-2);
%
\draw[canvas is xy plane at z = 0,blue]  plot[variable=\x,domain=2:5]
({\x},{3*exp(-0.3*\x)});

% lots of boxes in different colors and sizes
\foreach \Col/\X [count=\Y] in {green/1.6,green/1.8}
{
\draw pic (box1-\Y) at (\X,0,0) {fake box={\Col} with dimensions 0.1 and 2 and 1};
}
\path (box1-1-front-bottom-left) -- (box1-2-front-bottom-right)
node[midway,below,text width=3mm]{$H\times W\times64$};
\foreach \Col/\X [count=\Y] in {red/2.2,green/2.45,green/2.7}
{
\draw pic (box2-\Y) at (\X,0,0) {fake box={\Col} with dimensions 0.15 and 1 and 0.5};
}
\path (box2-1-front-bottom-left) -- (box2-3-front-bottom-right)
node[midway,below,text width=3mm]{$H/2\times W/2\times128$};
%
\foreach \Col/\X [count=\Y] in {red/3,green/3.25,green/3.5,green/3.75}
{\draw pic (box3-\Y) at (\X,0,0) {fake box={\Col} with dimensions 0.2 and 0.5 and 0.25};
}
\path (box3-1-front-bottom-left) -- (box3-4-front-bottom-right)
node[midway,below,text width=3mm]{$H/4\times W/4\times256$};
\end{tikzpicture}
\end{document}

您需要从左到右放置对象,因为 TiZ 没有真正的 3D 引擎。

在此处输入图片描述

相关内容