Horizontal neural network architecture flow chart

diagramsneuralnetworktikz-arrowstikz-pgf

I am trying to do draw the below image using LatexDraw but was having difficulty rendering it. It would be really helpful to get pointers on how to use TikZ to generate the following figure.

enter image description here

Below is the code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows,arrows}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command

\begin{document}
\begin{tikzpicture}

% Method 2 overlapping nodes
\node[rotate=90, fill=gray!20, 
    minimum height=2em,  text width=6em,rounded corners, drop shadow] at (3,1.5) { \hspace{0.5em}Input Layer};
\node[rotate=90, fill=red!20, 
    minimum height=2em,  text width=8em,rounded corners, drop shadow] at (5,1.5) { \hspace{1em}Shared Layer};
\node[draw, minimum size=0.5cm, fill=blue!20] at (7,0.5) {};
\node[draw, minimum size=0.5cm, fill=green!20] at (7,1.5) {};
\node[draw, minimum size=0.5cm, fill=yellow!20] at (7,2.5) {};
\node[text width=8em] at (7.5,3.5) {Task Specific \\ \hspace{0.6em} Layer};
\node(n1)[draw, minimum size=0.5cm, fill=blue!20] at (9,0.5) {} ;
\node(n2)[draw, minimum size=0.5cm, fill=green!20] at (9,1.5) {} ;
\node(n3)[draw, minimum size=0.5cm, fill=yellow!20] at (9,2.5) {} ;
\node[text width=8em] at (10,3.5) {Output \\ \hspace{0.1em} Layer};

\node (1)        [right = of n1]  {Task 3};
\draw [->] (n1) -- (1);
\node (1)        [right = of n2]  {Task 2};
\draw [->] (n2) -- (1);
\node (1)        [right = of n3]  {Task 1};
\draw [->] (n3) -- (1);
\end{tikzpicture}
\end{document}

and the output is

enter image description here

How do I add dotted crossed lines?

Best Answer

As starting point:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, 
                positioning,
                shadows}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command

\begin{document}
    \begin{tikzpicture}[
node distance = 5mm and 11mm,
R/.style = {fill=#1, rounded corners, 
            minimum height=2em, inner xsep=2em,
            rotate=90, anchor=center, 
            drop shadow},
N/.style = {draw, fill=#1, minimum size=2em}
                        ]
% 
\node (r1) [R=gray]                          {Input Layer};
\node (r2) [right=22mm of r1.south,R=red!20]    {Shared Layer};
%
\node (n12) [N=green!30,  right=of r2.south]    {};
\node (n11) [N=blue!30,   above=of n12] {};
\node (n13) [N=yellow!20, below=of n12] {};
%
\node (n21) [N=blue!30,   right=of n11] {};
\node (n22) [N=green!30,  right=of n12] {};
\node (n23) [N=yellow!20, right=of n13] {};
%
\draw [->] (n21) -- ++ (1.1,0) node[right] {Task 2};
\draw [->] (n22) -- ++ (1.1,0) node[right] {Task 2};
\draw [->] (n23) -- ++ (1.1,0) node[right] {Task 2};
%
\node [align=center, above=of n11]  {Task Specific \\ Layer};
\node [align=center, above=of n21]  {Output \\ Layer};
% dashed lines
\draw[dashed, gray] 
    (r1.south east) -- (r2.north east)
    (r1.south west) -- (r2.north west)
    ([shift={(1ex,-1ex)}] r1.south east) -- ([shift={(-.5ex,+1ex)}] r2.north west)
    ([shift={(1ex,+1ex)}] r1.south west) -- ([shift={(-.5ex,-1ex)}] r2.north east)
    ([shift={(1ex,-3ex)}] r1.south) -- ([shift={(-.5ex,+3ex)}] r2.north)
    ([shift={(1ex,+3ex)}] r1.south) -- ([shift={(-.5ex,-3ex)}] r2.north)
%
                    ;
    \end{tikzpicture}
\end{document}

enter image description here