我想使用 Ti 繪製 3D 塊體來表示卷積網路 (CNN)kZ. 下面是我試圖重新建立的圖片:
我已經努力創建這個區塊好幾天了,但仍然沒有太大進展:(。TikZ忍者能幫我解決這個問題嗎?
請注意,不需要第二塊板下方的水平線(它在裁剪時出現)。謝謝!
以下是我迄今為止嘗試過的(基於以下解決方案)使用 TikZ 繪製 CNN)
\documentclass{article}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{3d,decorations.text,shapes.arrows,positioning,fit,backgrounds}
\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!80!black] (#2,0,0) --++ (0,0,#4) coordinate(-back-bottom-right)
--++ (0,#3,0) --++ (0,0,-#4) -- cycle;
\path[gray,decorate,decoration={text effects along path,text={CONV}}] (#2/2,{2+(#3-2)/2},0) -- (#2/2,0,0);
}
}}
\tikzset{circle dotted/.style={dash pattern=on .05mm off 2mm,
line cap=round}}
\begin{document}
\begin{tikzpicture}[x={(1,0)},y={(0,1)},z={({cos(60)},{sin(60)})},
font=\sffamily\small,scale=2]
\foreach \X [count=\Y] in {1.6,1.4,1.2,1.2,1}
{
\draw pic (box1-\Y) at (\Y,-\X/2,0) {fake box=white!70!gray with dimensions 0.5 and {2*\X} and 1*\X};
}
\end{tikzpicture}
\end{document}
透過上面的程式碼,我可以得到下圖:
但是,我不想在所有區塊上顯示文本,而只希望在第一個區塊上顯示文字(如橙色圖中所示)。我想調整程式碼以產生橙色圖形。
答案1
像這樣的東西嗎?
\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{3d,decorations.text,shapes.arrows,positioning,fit,backgrounds}
\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[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[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[ultra thin,fill=#1!80!black] (#2,0,0) --++ (0,0,#4) coordinate(-back-bottom-right)
--++ (0,#3,0) --++ (0,0,-#4) -- cycle;
\path[decorate,decoration={text effects along path,text={CONV}}] (#2/2,{2+(#3-2)/2},0) -- (#2/2,0,0);
}
}}
\tikzset{pics/empty 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[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[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[ultra thin,fill=#1!80!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
\foreach \X/\Y [count=\Z] in {0/0.8,0.4/0.6,0.7/0.4,0.9/0.2,1.0/0.2}
{\ifnum\Z=1
\draw pic (box1-\Z) at (\X,-\Y,-\Y/2)
{fake box=orange!90!black with dimensions {\Y} and {4*\Y} and 2*\Y};
\else
\draw pic (box1-\Z) at (\X,-\Y,-\Y/2)
{empty fake box=orange!90!black with dimensions {\Y} and {4*\Y} and 2*\Y};
\fi
}
\end{tikzpicture}
\end{document}