浏览代码

Add max pooling example

Martin Thoma 8 年之前
父节点
当前提交
0cf39aa80a
共有 4 个文件被更改,包括 144 次插入0 次删除
  1. 35 0
      tikz/max-pooling/Makefile
  2. 3 0
      tikz/max-pooling/README.md
  3. 二进制
      tikz/max-pooling/max-pooling.png
  4. 106 0
      tikz/max-pooling/max-pooling.tex

+ 35 - 0
tikz/max-pooling/Makefile

@@ -0,0 +1,35 @@
+SOURCE = max-pooling
+DELAY = 80
+DENSITY = 300
+WIDTH = 512
+
+make:
+	pdflatex $(SOURCE).tex -output-format=pdf
+	make clean
+
+clean:
+	rm -rf  $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot
+
+gif:
+	pdfcrop $(SOURCE).pdf
+	convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
+	make clean
+
+png:
+	make
+	make svg
+	inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
+
+transparentGif:
+	convert $(SOURCE).pdf -transparent white result.gif
+	make clean
+
+svg:
+	make
+	#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
+	pdf2svg $(SOURCE).pdf $(SOURCE).svg
+	# Necessary, as pdf2svg does not always create valid svgs:
+	inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
+	rsvg-convert -a -w $(WIDTH) -f svg $(SOURCE).svg -o $(SOURCE)2.svg
+	inkscape $(SOURCE)2.svg --export-plain-svg=$(SOURCE).svg
+	rm $(SOURCE)2.svg

+ 3 - 0
tikz/max-pooling/README.md

@@ -0,0 +1,3 @@
+Compiled example
+----------------
+![Example](max-pooling.png)

二进制
tikz/max-pooling/max-pooling.png


+ 106 - 0
tikz/max-pooling/max-pooling.tex

@@ -0,0 +1,106 @@
+\documentclass{standalone}
+\usepackage{amssymb}
+\usepackage{tikz}
+\usetikzlibrary{arrows.meta}
+\usetikzlibrary{decorations.pathreplacing}
+
+\begin{document}
+\definecolor{c1}{HTML}{9ACFC6}
+\definecolor{c2}{HTML}{DABBD6}
+\definecolor{c3}{HTML}{CBDCB9}
+\definecolor{c4}{HTML}{9AC3E1}
+\definecolor{c5}{HTML}{DEBBA5}
+\definecolor{c6}{HTML}{C4DDE5}
+\newcommand*{\xMin}{0}%
+\newcommand*{\xMax}{6}%
+\newcommand*{\yMin}{0}%
+\newcommand*{\yMax}{4}%
+
+\newcommand*{\xMinR}{9.5}%
+\newcommand*{\xMaxR}{12.5}%
+\newcommand*{\yMinR}{1}%
+\newcommand*{\yMaxR}{3}%
+
+\begin{tikzpicture}
+    \fill [c1] (0, 0) rectangle (2, 2);
+    \fill [c2]   (2, 0) rectangle (4, 2);
+    \fill [c3]  (4, 0) rectangle (6, 2);
+    \fill [c4] (0, 2) rectangle (2, 4);
+    \fill [c5]   (2, 2) rectangle (4, 4);
+    \fill [c6]   (4, 2) rectangle (6, 4);
+
+    \fill [c1]  (9.5, 1) rectangle (10.5, 2);
+    \fill [c2]   (10.5, 1) rectangle (11.5, 2);
+    \fill [c3]  (11.5, 1) rectangle (12.5, 2);
+    \fill [c4]  (9.5, 2) rectangle (10.5, 3);
+    \fill [c5]   (10.5, 2) rectangle (11.5, 3);
+    \fill [c6]   (11.5, 2) rectangle (12.5, 3);
+
+    \foreach \i in {\xMin,...,\xMax} {
+        \draw [very thin,gray] (\i,\yMin) -- (\i,\yMax)  node [below] at (\i,\yMin) {};
+    }
+    \foreach \i in {\yMin,...,\yMax} {
+        \draw [very thin,gray] (\xMin,\i) -- (\xMax,\i) node [left] at (\xMin,\i) {};
+    }
+% [7, 9, 3, 5, 9, 4,
+%  0, 7, 0, 0, 9, 0,
+%  5, 0, 9, 3, 7, 5,
+%  9, 2, 9, 6, 4, 3]
+    \foreach \i in {\xMin,2,...,\xMax} {
+        \draw [thick,gray] (\i,\yMin) -- (\i,\yMax)  node [below] at (\i,\yMin) {};
+    }
+    \foreach \i in {\yMin,2,...,\yMax} {
+        \draw [thick,gray] (\xMin,\i) -- (\xMax,\i) node [left] at (\xMin,\i) {};
+    }
+    \node at (0.5, 0.5) {7};
+    \node at (1.5, 0.5) {9};
+    \node at (2.5, 0.5) {3};
+    \node at (3.5, 0.5) {5};
+    \node at (4.5, 0.5) {9};
+    \node at (5.5, 0.5) {4};
+    %
+    \node at (0.5, 1.5) {0};
+    \node at (1.5, 1.5) {7};
+    \node at (2.5, 1.5) {0};
+    \node at (3.5, 1.5) {0};
+    \node at (4.5, 1.5) {9};
+    \node at (5.5, 1.5) {0};
+    %
+    \node at (0.5, 2.5) {5};
+    \node at (1.5, 2.5) {0};
+    \node at (2.5, 2.5) {9};
+    \node at (3.5, 2.5) {3};
+    \node at (4.5, 2.5) {7};
+    \node at (5.5, 2.5) {5};
+    %
+    \node at (0.5, 3.5) {9};
+    \node at (1.5, 3.5) {2};
+    \node at (2.5, 3.5) {9};
+    \node at (3.5, 3.5) {6};
+    \node at (4.5, 3.5) {4};
+    \node at (5.5, 3.5) {3};
+
+    \draw[draw=black,line width=12pt,-{Latex[length=9mm]}] (6.5, 2)  -- (9,2);
+    \node[font=\footnotesize\bfseries] at (7.7, 2.5) {$2\times 2$ max pooling};
+
+    \foreach \i in {\xMinR,...,\xMaxR} {
+        \draw [thick,gray] (\i,\yMinR) -- (\i,\yMaxR)  node [below] at (\i,\yMinR) {};
+    }
+    \foreach \i in {\yMinR,...,\yMaxR} {
+        \draw [thick,gray] (\xMinR,\i) -- (\xMaxR,\i) node [left] at (\xMinR,\i) {};
+    }
+
+    \node at (10, 1.5) {9};
+    \node at (11, 1.5) {5};
+    \node at (12, 1.5) {9};
+    \node at (10, 2.5) {9};
+    \node at (11, 2.5) {9};
+    \node at (12, 2.5) {7};
+
+    \draw [decorate,decoration={brace,amplitude=4pt},xshift=-2pt,yshift=0pt]
+(0,2) -- (0,4) node [black,midway,xshift=-0.3cm] {\footnotesize $2$};
+
+    \draw [decorate,decoration={brace,amplitude=4pt},xshift=0pt,yshift=2pt]
+(0,4) -- (2,4) node [black,midway,yshift=+0.3cm] {\footnotesize $2$};
+\end{tikzpicture}
+\end{document}