3

I want to generate a figure using tikz similar to the following picture. Here is so far my attempt. I don't know how to generate these transparent sheets on top of each other and align nodes properly with arrows: enter image description here

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning,fit, calc, backgrounds,shapes.arrows}

\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}[trap/.style={
  trapezium, trapezium angle=67.5, draw,
  inner ysep=5pt, outer sep=0pt,
  minimum height=1.81mm, minimum width=0pt, fill=pink!20
},
    node distance=1cm and 1.5cm,
    every node/.style={align=center},
    box/.style={draw, rounded corners, fill=blue!20, minimum height=1cm, minimum width=1.5cm},
    features/.style={draw, fill=purple!10, minimum height=2cm, minimum width=0.5cm},
    slots/.style={draw, fill=green!10, minimum height=0.5cm, minimum width=1.5cm},
    attention/.style={draw, rounded corners, fill=blue!10, minimum height=4cm, minimum width=2cm},
    arrow/.style={-Stealth, thick}
]

% Input Image
\node[inner sep=0pt] (inputimage) at (0,0) {\includegraphics[width=2cm]{slot_SQA_original.png}};
\node[below=0.2cm of inputimage] {Input Image};

% Encoder
\node[trap, rotate=270,right=1.5cm of inputimage] (encoder) {Enc};
\node[below=0.2cm of encoder] {Features};

% Features
\foreach \i in {0,0.2,...,1}
    \node[features, right=of encoder, xshift=-\i cm, yshift=-\i cm] {};

% Slot Attention
\node[attention, right=1.5cm of encoder] (slotattention) {Slot Attention};

% Initialization Queries
\node[slots, above=0.5cm of slotattention, yshift=1cm] (init1) {};
\node[slots, above=0.1cm of slotattention, yshift=0.8cm] (init2) {};
\node[slots, above=-0.3cm of slotattention, yshift=0.6cm] (init3) {};
\node[above=0.2cm of init1] {Initialization Queries};

% Learned Slots
\node[slots, right=1.5cm of slotattention, yshift=0.6cm] (learned1) {};
\node[slots, right=1.5cm of slotattention, yshift=0.2cm] (learned2) {};
\node[slots, right=1.5cm of slotattention, yshift=-0.2cm] (learned3) {};
\node[right=0.2cm of learned1] {Learned Slots};

% Decoder
\node[trap, rotate=90, right=1.5cm of slotattention] (decoder) {Dec};


% Output Image
\node[inner sep=0pt, right=1.5cm of decoder] (outputimage) {\includegraphics[width=2cm]{slot_SQA_reconstruct.png}};
\node[below=0.2cm of outputimage] {Reconstruction};

% Arrows
\path (inputimage.east) -- (encoder.south) node[midway, single arrow, draw=black!40, fill=blue!5,minimum width=5mm, minimum height=11mm, inner sep=0mm, single arrow head extend=0.25mm] {};

\draw[arrow] (encoder.east) -- ++(0.5,0) -- ++(0.5,0) |- (slotattention.west);
\draw[arrow] (init2.south) -- (slotattention.north);
\draw[arrow] (slotattention.east) -- (decoder.west);
\draw[arrow] (decoder.east) -- (outputimage.west);
\draw[arrow] (slotattention.east) -- (learned1.west);
\draw[arrow] (slotattention.east) -- (learned2.west);
\draw[arrow] (slotattention.east) -- (learned3.west);
    
\end{tikzpicture}
\end{document}
1
  • @cfr I fixed \[...\].
    – Dalek
    Commented Jun 22 at 2:08

1 Answer 1

4

Prerequisites (ought to be done before posting the question)

In order to make you code compile, I replaced two custom images with common ones.

Standard images such as example-image-a are provided by the mwe package (which does not require loading). A couple of choices of cow and a windmill are other options. Alternatively, pass draft to graphicx.

Substantive answer

The shadows library provides double copy shadow which can be combined with opacity=<value> to obtain the effect of the overlaid sheets.

Keep positioning simple and avoid hard-coding as much as possible. For example, position the central learned layer to the right of the previous node, but the remaining two above and below the central one, and use label to position labels. Use anchors when needed to further fine-tune placement.

I reduced the spacing a bit because the diagram was getting too wide for A4 even in landscape mode. If you are printing on A3 or not printing at all, you may wish to revert these changes, which include reducing the size of the arrows.

Anyway, here's a bovine version. (I tried to combine the windmill with a cow, but the mill didn't fit very well and I thought a lone cow might get lonely.)

bovine image processing

Code

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,shadows,positioning,shapes.arrows}

\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}[trap/.style={
    trapezium, trapezium angle=67.5, draw,
    inner ysep=5pt, outer sep=0pt,
    minimum height=1.81mm, minimum width=0pt, fill=pink!20
  },
  every node/.style={align=center,font=\sffamily},
  every label/.append style={font=\sffamily},
  box/.style={draw, rounded corners, fill=blue!20, minimum height=1cm, minimum width=1.5cm},
  features/.style={draw, fill=purple, opacity=.1,draw opacity=1, minimum height=2cm, minimum width=0.5cm},
  slots/.style={draw, fill=green!10, minimum height=0.5cm, minimum width=1.5cm},
  attention/.style={draw, rounded corners, fill=blue!10, minimum height=4cm, minimum width=2cm},
  ]
  
  \node[inner sep=0pt,label={[name=lii]below:Input Image}] (inputimage) at (0,0) {\includegraphics[width=2cm]{cow}};
  
  \node[trap, rotate=270,right=of inputimage, anchor=south] (encoder) {Enc};
  \node [anchor=base] at (encoder |- lii.base) {Features};
  
  \node (feat) [features, right=of encoder.north, double copy shadow,anchor=west] {};
  
  \node[attention, right=of feat] (slotattention) {Slot\\Attention};
  
  \node[slots, above=of slotattention] (init3) {};
  \node[slots, above=1mm of init3] (init2) {};
  \node[slots, above=1mm of init2,label=above:initialisation Queries] (init1) {};
  
  \node[slots, right=of slotattention.east,anchor=west] (learned2) {};
  \node[slots, above=1mm of learned2] (learned1) {};
  \node[slots, below=1mm of learned2,label=below:Learned Slots] (learned3) {};
  
  \node[trap, rotate=90, right=of learned2.east,anchor=north] (decoder) {Dec};
  
  \node[inner sep=0pt, right=of decoder.south,anchor=west,label=below:Reconstruction] (outputimage) {\includegraphics[width=2cm]{cow-brown}};
  
  \foreach \i/\j in {%
    inputimage.east/encoder.south,
    encoder.north/feat.west,
    feat.east/slotattention.west,
    slotattention.east/learned2.west,
    learned2.east/decoder.north,
    decoder.south/outputimage.west%
  }
  \path [shorten >=2.5mm,shorten <=2.5mm] (\i) -- (\j) node[midway, single arrow, draw=black!40, fill=blue!5,minimum width=5mm, minimum height=6mm, inner sep=0mm, single arrow head extend=0.25mm] {};
  \path [shorten >=2.5mm,shorten <=2.5mm] (init3.south) -- (slotattention.north) node[midway, single arrow, draw=black!40, fill=blue!5,minimum width=5mm, minimum height=6mm, inner sep=0mm, single arrow head extend=0.25mm,rotate=-90] {};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .