SHARE
TWEET

Untitled

a guest Apr 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "markdown",
  5.    "metadata": {},
  6.    "source": [
  7.     "## Compositional symbols dataset\n",
  8.     "Script to generate a dataset of compostional symbols. Each symbol is composed of a set of strokes. Each stroke can be in three different colors to increase the complexity. The symbols in the training and test set are different but are built from the same underlying strokes. "
  9.    ]
  10.   },
  11.   {
  12.    "cell_type": "code",
  13.    "execution_count": 1,
  14.    "metadata": {
  15.     "collapsed": true
  16.    },
  17.    "outputs": [],
  18.    "source": [
  19.     "import numpy as np\n",
  20.     "import matplotlib.pyplot as plt\n",
  21.     "import pickle"
  22.    ]
  23.   },
  24.   {
  25.    "cell_type": "code",
  26.    "execution_count": 2,
  27.    "metadata": {
  28.     "collapsed": true
  29.    },
  30.    "outputs": [],
  31.    "source": [
  32.     "# functions to create different strokes\n",
  33.     "def left(img, color):\n",
  34.     "    new = img.copy()\n",
  35.     "    new[1:-1,0] = color\n",
  36.     "    return new\n",
  37.     "\n",
  38.     "def top(img, color):\n",
  39.     "    new = img.copy()\n",
  40.     "    new[0,1:-1] = color\n",
  41.     "    return new\n",
  42.     "\n",
  43.     "def right(img, color):\n",
  44.     "    new = img.copy()\n",
  45.     "    new[1:-1,-1] = color\n",
  46.     "    return new\n",
  47.     "\n",
  48.     "def bottom(img, color):\n",
  49.     "    new = img.copy()\n",
  50.     "    new[-1,1:-1] = color\n",
  51.     "    return new\n",
  52.     "\n",
  53.     "def diag_l(img, color):\n",
  54.     "    new = img.copy()\n",
  55.     "    for i in range(1,new.shape[0]-1):\n",
  56.     "        new[i,i] = color\n",
  57.     "    return new\n",
  58.     "\n",
  59.     "def diag_r(img, color):\n",
  60.     "    new = img.copy()\n",
  61.     "    for i in range(1,img.shape[0]-1):\n",
  62.     "        new[i,new.shape[0]-1-i] = color\n",
  63.     "    return new"
  64.    ]
  65.   },
  66.   {
  67.    "cell_type": "code",
  68.    "execution_count": 3,
  69.    "metadata": {},
  70.    "outputs": [
  71.     {
  72.      "data": {
  73.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAAD8CAYAAABaQGkdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAACj9JREFUeJzt3V2IXPUdxvHnaaJYX4LQpG1IQldB\nAtIL4y6C2Ja2tiViUC96oaAXUsiVEilFUq/ai9KbUuxFESTVCrVK6wuIBK1QWy1U626MaEwsaUjJ\nVm02WPGlF5L69GInEEzcOZs5Z15++/3AQmZ2dvY3JN+cM7M7/7+TCEBNnxn1AAC6Q+BAYQQOFEbg\nQGEEDhRG4EBhBA4URuBAYQQOFLa6iztdu3ZtpqamurjrU8zNzQ3l+wBNTE9PD+X7HD58WMeOHXO/\n23US+NTUlGZnZ7u461PYfR8jMDTD+nc/MzPT6HacogOFEThQGIEDhRE4UBiBA4UROFAYgQOFEThQ\nWKPAbW+1/Ybtg7Z3dj0UgHb0Ddz2Kkm/lHSNpEsl3WT70q4HAzC4JkfwKyQdTHIoyUeSHpZ0fbdj\nAWhDk8A3SDpy0uX53nUAxlyTwE/3bo5TFlO3vd32rO3ZhYWFwScDMLAmgc9L2nTS5Y2S3vzkjZLc\nm2Qmycy6devamg/AAJoE/pKkS2xfZPtsSTdKeqLbsQC0oe/7wZMct32bpKclrZJ0X5J9nU8GYGCN\nFnxIslvS7o5nAdAyfpMNKIzAgcIIHCiMwIHCCBwojMCBwggcKIzAgcKcnPK+kcHv1G7/Tj9FF/MD\nZ2qYO+0k6fvNOIIDhRE4UBiBA4UROFAYgQOFEThQGIEDhRE4UBiBA4U12dnkPttHbb82jIEAtKfJ\nEfzXkrZ2PAeADvQNPMlzkt4ZwiwAWsZzcKCwRssmN2F7u6Ttbd0fgME1e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PtC24/YPtD7u7ty1DMNYuSn6L211v+uxRVj5iW9JOmmJK+P\ndLAB2V4vaX2SPbYvkDQn6YZJf1wn2P6+pBlJa5JsG/U8bbH9gKTnk+zqLTR6bpJ3Rz3XmRqHI/gV\nkg4mOZTkI0kPS7p+xDMNLMlbSfb0/vy+pP2SNox2qnbY3ijpWkm7Rj1Lm2yvkfQ1Sb+SpCQfTXLc\n0ngEvkHSkZMuz6tICCfYnpK0RdKLo52kNXdLulPSx6MepGUXS1qQdH/v6ccu2+eNeqhBjEPgPs11\nZV7at32+pEcl3ZHkvVHPMyjb2yQdTTI36lk6sFrS5ZLuSbJF0oeSJvo1oXEIfF7SppMub5T05ohm\naZXts7QY94NJqqxIe5Wk62wf1uLTqW/a/s1oR2rNvKT5JCfOtB7RYvATaxwCf0nSJbYv6r2ocaOk\nJ0Y808BsW4vP5fYn+fmo52lLkh8m2ZhkSot/V39McvOIx2pFkrclHbG9uXfV1ZIm+kXRRssmdynJ\ncdu3SXpa0ipJ9yXZN+Kx2nCVpFskvWp7b++6u5LsHuFM6O92SQ/2DjaHJN064nkGMvIfkwHozjic\nogPoCIEDhRE4UBiBA4UROFAYgQOFEThQGIEDhf0fGY1vEp13lsoAAAAASUVORK5CYII=\n",
  74.       "text/plain": [
  75.        "<matplotlib.figure.Figure at 0x110a4e860>"
  76.       ]
  77.      },
  78.      "metadata": {},
  79.      "output_type": "display_data"
  80.     }
  81.    ],
  82.    "source": [
  83.     "# test functions\n",
  84.     "img = np.zeros([8,8],dtype=np.uint8)\n",
  85.     "img = right(img,1)\n",
  86.     "img = left(img,1)\n",
  87.     "img = top(img,1)\n",
  88.     "plt.imshow(img, cmap='gray_r')\n",
  89.     "plt.show()"
  90.    ]
  91.   },
  92.   {
  93.    "cell_type": "code",
  94.    "execution_count": 4,
  95.    "metadata": {
  96.     "collapsed": true
  97.    },
  98.    "outputs": [],
  99.    "source": [
  100.     "# compose one subgrid\n",
  101.     "def compose_sub(lst_strokes, size_h, size_w):\n",
  102.     "    img = np.zeros([size_h,size_w],dtype=np.uint8)\n",
  103.     "    if lst_strokes[0]:\n",
  104.     "        img = left(img, lst_strokes[0])\n",
  105.     "    if lst_strokes[1]:\n",
  106.     "        img = right(img, lst_strokes[1])\n",
  107.     "    if lst_strokes[2]:\n",
  108.     "        img = top(img, lst_strokes[2])\n",
  109.     "    if lst_strokes[3]:\n",
  110.     "        img = bottom(img, lst_strokes[3])\n",
  111.     "    if lst_strokes[4]:\n",
  112.     "        img = diag_l(img, lst_strokes[4])\n",
  113.     "    if lst_strokes[5]:\n",
  114.     "        img = diag_r(img, lst_strokes[5])\n",
  115.     "    return img  "
  116.    ]
  117.   },
  118.   {
  119.    "cell_type": "code",
  120.    "execution_count": 76,
  121.    "metadata": {
  122.     "collapsed": true
  123.    },
  124.    "outputs": [],
  125.    "source": [
  126.     "# arrange subgrids\n",
  127.     "def compose_two_grid(subgrid_size, stroke ):\n",
  128.     "    size_h, size_w = subgrid_size[0], subgrid_size[1]\n",
  129.     "    assert(size_h >2)\n",
  130.     "    assert(size_w >2)\n",
  131.     "    a = compose_sub(stroke[0],size_h, size_w)\n",
  132.     "    b = compose_sub(stroke[1],size_h, size_w)\n",
  133.     "    img = np.concatenate((a,b),0)\n",
  134.     "    color_img = np.ones((img.shape[0], img.shape[1],3))\n",
  135.     "    color_img[:,:,0] = (img==1)\n",
  136.     "    color_img[:,:,1] = (img==2)\n",
  137.     "    color_img[:,:,2] = (img==3)\n",
  138.     "    return color_img\n",
  139.     "\n",
  140.     "def compose_one_grid(subgrid_size, stroke ):\n",
  141.     "    size_h, size_w = subgrid_size[0], subgrid_size[1]\n",
  142.     "    assert(size_h >2)\n",
  143.     "    assert(size_w >2)\n",
  144.     "    img = compose_sub(stroke,size_h, size_w)\n",
  145.     "    color_img = np.ones((img.shape[0], img.shape[1],3))\n",
  146.     "    color_img[:,:,0] = (img==1)\n",
  147.     "    color_img[:,:,1] = (img==2)\n",
  148.     "    color_img[:,:,2] = (img==3)\n",
  149.     "    return color_img"
  150.    ]
  151.   },
  152.   {
  153.    "cell_type": "code",
  154.    "execution_count": 67,
  155.    "metadata": {
  156.     "collapsed": true
  157.    },
  158.    "outputs": [],
  159.    "source": [
  160.     "#  create sets of strokes that a symbol can be composed of\n",
  161.     "def create_strokes(alphabet_size, num_strokes, ref=[], colors=4, mini=0, maxi=6):\n",
  162.     "    symbols = []\n",
  163.     "    while len(symbols) < alphabet_size:\n",
  164.     "        # new symbol\n",
  165.     "        symb = list(np.zeros(6,dtype=np.uint8))\n",
  166.     "        # generate random strokes\n",
  167.     "        rand_vec = np.random.randint(colors, size=num_strokes)\n",
  168.     "        # fill stroke\n",
  169.     "        symb[:len(rand_vec)] = rand_vec\n",
  170.     "        # check that stroke is neither in the current alphabet nor in the ref alphabet\n",
  171.     "        if (symb not in symbols) and (symb not in ref) and sum(np.array(symb)==0) > 5-maxi and sum(np.array(symb)==0) >= 5-mini :\n",
  172.     "            symbols.append(symb)\n",
  173.     "    return symbols"
  174.    ]
  175.   },
  176.   {
  177.    "cell_type": "code",
  178.    "execution_count": 68,
  179.    "metadata": {},
  180.    "outputs": [],
  181.    "source": [
  182.     "alphabet_size_train = 3\n",
  183.     "alphabet_size_test = 3\n",
  184.     "num_strokes = 6\n",
  185.     "colors = 4\n",
  186.     "subgrid_size=(8,8)\n",
  187.     "# generate sets of symbols for train\n",
  188.     "alphabet_train = create_strokes(alphabet_size=alphabet_size_train, num_strokes=num_strokes, colors=colors, mini=2, maxi=6)\n",
  189.     "# generate a different set of symbols for the test\n",
  190.     "alphabet_test = create_strokes(alphabet_size=alphabet_size_test, num_strokes=num_strokes, ref=alphabet_train, colors=colors, mini=1, maxi=1)\n"
  191.    ]
  192.   },
  193.   {
  194.    "cell_type": "markdown",
  195.    "metadata": {},
  196.    "source": [
  197.     "## plot sets of strokes that symbols can be composed of"
  198.    ]
  199.   },
  200.   {
  201.    "cell_type": "code",
  202.    "execution_count": 69,
  203.    "metadata": {},
  204.    "outputs": [
  205.     {
  206.      "name": "stdout",
  207.      "output_type": "stream",
  208.      "text": [
  209.       "Train set of strokes\n"
  210.      ]
  211.     },
  212.     {
  213.      "data": {
  214.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFUAAABZCAYAAABPN2ghAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAAxBJREFUeJztnD1PFFEUhp9XCI2xM1qoMZjYaEts\nrCw0dLb6B6j8AZT+AH8BhaWxI7Hyo7MFE40fEYMEA6EwdFoZzLHYJazCzl6WeWfW3fMkE3aXu9yT\nh3vnnrlzMooIkno51XYA40hKNZBSDaRUAynVQEo1kFINpFQDKdVBRAw8gHlgDVgHFgvax7geRb4K\nBE0BX4ErwAzwDriWUvsfJdP/BrAeERsR8Qt4Ctwt+N7EUiL1ArDV8367+1nSh+mCNjris0NbW5IW\ngIUTRzQGlEjdBi71vL8I7PzbKCKWgCUASZO9n1iwUE0DG8AsBwvV9Vyo+h8DR2pE7El6ALygkwk8\njoiPg/9dff9ixe+OOtOYMIYhx85/9fT/v6VGxMAg84rKQEo1kFINpFQDKdVASfJfM1WLZ82ZQUuJ\nRo5UAynVQEo1kFINpFQDKdVACylVFUOkW1X7Gw3uz/SSI9VASjWQUg2kVAMp1cCIrf4V9FvlK2/c\ntrP850g1kFINpFQDKdVASjWQUg0UpVSSNoEfwG9gLyLmLNEMlR01eM+rkOPkqbciYtcWyRiR099A\nqdQAXkp60y3uTSoonf43I2JH0jnglaTPEfG6t0FWUh9w7FJKSQ+BnxHxqKLNcPWZta8r9S9UtZRS\nSjot6cz+a+AO8GGoiCaEkul/HliWtN/+SUQ8H7rHRrOcdtKt5iupR2anbrhAspK6JVKqgZRqIKUa\nSKkGmr/x11IpzmF8geRINZBSDaRUAynVQEo1kFINuFKqXeBb9/XZ7vu2qSOOyyWNLLtUf3Ugrdru\nvo5oHDn9DaRUA01IXWqgjxIai8N+Tp1EcvobsEmVNC9pTdK6pEVXP4WxbEp6L+mtpFV7f6Ybf1PA\nF+A2nSewrQD3I+JT7Z2VxbMJzDVVC+YaqRP9JEuX1FF7kmWjtWCuy9SiJ1k2yMBasDpxjdSiJ1k2\nRUTsdH9+B5bpnJ5suKSuAFclzUqaAe4Bz0x9VdJGLZhl+tf/JMsTUW8tWAF5RWUgr6gMpFQDKdVA\nSjWQUg2kVAMp1UBKNfAH9MdWS3YzQ+MAAAAASUVORK5CYII=\n",
  215.       "text/plain": [
  216.        "<matplotlib.figure.Figure at 0x117ef7710>"
  217.       ]
  218.      },
  219.      "metadata": {},
  220.      "output_type": "display_data"
  221.     },
  222.     {
  223.      "data": {
  224.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFUAAABZCAYAAABPN2ghAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAAvZJREFUeJztnDtrVFEYRddngo3Y+Sh8oWCjhYXB\nxspCsbPVP5DKH+BvSWEpYiNYiI/OVgXFt8QQMaSQdHYS2RaZYKJm5kRnX52ZveAyc2fO5WwW98x9\nzHdPSSIMlx3/OsA4EqkGItVApBqIVAORaiBSDUSqgUh1IGngAlwE3gHzwLWG9hrXpclXg6Ap4ANw\nDNgJPAdOROrWS8vwPwPMS1qQ9BW4CVxq2G5iaZF6APi0YX2p91nYgumGNvWbz365tVVVs8DsXyca\nA1qkLgGHNqwfBJZ/biRpDpgDqKrJvp/YcKCaBhaAo/w4UJ3MgeovDlSSVoGrwH3gDXBL0qu+G53u\nE2sE2Cr66cbtW4Y/ku4Cd/8k4CSSKyoDkWogUg1EqoFINRCpBiLVQKQaiFQDkWogUg1EqoFINRCp\nBiLVQKQaiFQDkWogUg1EqoFINRCpBiLVQKQaiFQDTRUqVbUIfAG+AauSZpyhRp0mqT3OSVqxJRkj\nMvwNtEoV8KCqnvaKe0MfWof/WUnLVbUPeFhVbyU92thgUyX14eGGHDWa9lRJy73Xz8Bt1h6u+LnN\nnKQZSTPsHW7IUWOg1KraVVW7198DF4CX7mCjTMvw3w/crqr19jck3bOmGnEGSpW0AJzqIMvYkFMq\nA5FqIFINRKqBSDVQjhnU+j5GOQoPqP3uadwekvp8u0b2VAORaiBSDUSqgUg1EKkGtvMf1XZYAT72\n3u/pra8x8ITExuYcf8aRlkaW89RNHVQ9+R/+fe0yR4a/gUg10IXUuQ76aKGzHPbf1Ekkw9+ATWpV\nXayqd1U1X1XXXP00ZlmsqhdV9ayqntj7M936mwLeA+dZm4HtMXBF0uuhd9aWZxGY6aoWzLWnTvRM\nli6p/9tMlp3WgrkuU5tmsuyQgbVgw8S1pzbNZNkVLbVgw8Ql9TFwvKqOVtVO4DJwx9RXX/5FLZhl\n+Etarar1mSyngOsDZ7L00XktWK6oDOSKykCkGohUA5FqIFINRKqBSDUQqQa+AyHKWsxUPpc1AAAA\nAElFTkSuQmCC\n",
  225.       "text/plain": [
  226.        "<matplotlib.figure.Figure at 0x110f24eb8>"
  227.       ]
  228.      },
  229.      "metadata": {},
  230.      "output_type": "display_data"
  231.     },
  232.     {
  233.      "data": {
  234.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFUAAABZCAYAAABPN2ghAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAAxJJREFUeJztnLtrFFEYxc8xkkbsRAtfKNjYWCTY\nWFko6Wz1H0jlH2BpaWFjG8RS7AJWPjrbJKD4QCWGiCGFpNNKIsdiN7g+dvZmd87s6/xgyE72zt6P\nH/feuTPzzaUkhHo5MOwAJpFINRCpBiLVQKQaiFQDkWogUg1EqoGDJYVILgC4B2AGwH1Jd3qU73qZ\nNrev8IbDWsV3ktjzByRVbmiJ/ATgLIBZAK8AnO9xjLptGoOtMv4eviQVdf+LANYlbUj6AeARgGsF\nx00tJVKPA/jSsb/V/l/oQsmY+r8x5J8xk+QigMWBI5oASqRuATjZsX8CwPbfhSQtAVgCqk9U00BJ\n918BcI7kGZKzAK4DeOwNa7zp2VIl7ZK8CeApWjOBB5LeVh0zB2C1y3e95yMNUdWXBgySjjv/86Qm\nVWrJPDVXVAYi1UCkGohUA5FqoOgu1dhinDZVkZZqIFINRKqBSDUQqQYi1cD4T6mGNG2qIi3VQKQa\niFQDkWogUg2Mz9m/21l+ZJ7P/CYt1UCkGohUA5FqIFINRKqB0kzqTQDfAPwEsCtp3hLNCN4c6Yf9\nzFMvS9qxRTJBpPsbKJUqAM9IrrWTe0MFpd3/kqRtkkcBPCf5XtKLzgKdmdSnag5y3Nh3KiXJ2wC+\nS7rbrUzfqZRjcKKqJZWS5CGSh/c+A7gK4M3g4U0uJd3/GIBlknvlH0p60neNY9AaB6UkPX0DwIUG\nYpkYMqUyEKkGItVApBqIVAOW96gm+TXKvEc1JCLVQKQaiFQDkWogUg24cql2AHxufz7S3h82dcRx\nuqSQZZ76RwXkqu3p64jGke5vIFINNCF1qYE6SmgsDvuYOo2k+xuwSSW5QPIDyXWSt1z1FMaySfI1\nyZckuz09r68+062/GQAfAVxBawW2FQA3JL2rvbKyeDYBzDeVC+ZqqVO9kqVL6qitZNloLpjrMrVo\nJcsG6ZkLVieullq0kmVTSNpu//0KYBmt4cmGS+rIrGQ5jFwwS/fvZyVLI/XmghWQKyoDuaIyEKkG\nItVApBqIVAORaiBSDUSqgV9R0YDr9GBwVwAAAABJRU5ErkJggg==\n",
  235.       "text/plain": [
  236.        "<matplotlib.figure.Figure at 0x118030eb8>"
  237.       ]
  238.      },
  239.      "metadata": {},
  240.      "output_type": "display_data"
  241.     },
  242.     {
  243.      "name": "stdout",
  244.      "output_type": "stream",
  245.      "text": [
  246.       "Test set of strokes\n"
  247.      ]
  248.     },
  249.     {
  250.      "data": {
  251.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFUAAABZCAYAAABPN2ghAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAAwxJREFUeJztnD1PVEEUhp9XCI2xM5j4EYOJjbbE\nxsTEQkNnq3+Ayh9A6Q/wF1BYGjsSKz86WzDR+BExSCASCkOnlcEci10iKnt3gPvevbt7HnKze5eB\nOXmYuTN37mEUEST1cmLQAYwiKdVASjWQUg2kVAMp1UBKNZBSDaRUBxHR9wDmgFVgDVgoKB+jehT5\nKhA0AXwBLgFTwFvgSkrtfZR0/2vAWkSsR8RP4Alwp+DnxpYSqeeAr/vOt7qfJT2YLCijAz77b2lL\n0jwwf+yIRoASqVvAhX3n54HtfwtFxCKwCCBpvNcTCwaqSWAdmOHPQHU1B6reR9+WGhG7ku4Dz+nM\nBB5FxIf+f65ev7DiewddaIYQOVb+K7v/kEuNiL5R5h2VgZRqIKUaSKkGUqqBksl/vVSNnUM+M9gj\nW6qBlGogpRpIqQZSqoGUaqD5KVUVR5lutXCqlS3VQEo1kFINpFQDKdVAu0b/KnqN8i1chMmWaiCl\nGkipBlKqgZRqIKUaKJpSSdoAvgO/gN2ImHUGdSha+MzrMPPUmxGxY4tkhMjub6BUagAvJL3uJvcm\nVRT+d8rZ7us0nfzUGweUmQdWusfA80iBqPwy5qceOpVS0gPgR0Q8rCjTjkxqw0BVSyqlpJOSTu29\nB24D748W0nhQMvqfAZYk7ZV/HBHPrFHVxYCmW81nUreFI0rNTOoBkVINpFQDKdVASjUwPA/+6sa4\nSpUt1UBKNZBSDaRUAynVQEo14JpS7QCb3fenu+eDpo44LpYUsqxS/VWBtNKGp69NxpHd30BKNdCE\n1MUG6iihsTjs19RxJLu/AZtUSXOSViWtSVpw1VMYy4akd5LeSFqx12d68DcBfAZu0dmBbRm4FxEf\na6+sLJ4NYLapXDBXSx3rnSxdUtu2k2WjuWCu29SinSwb5HpEbEuaBl5K+hQRr1yVuVpq0U6WTRER\n293Xb8ASncuTDZfUZeCypBlJU8Bd4KmprkoGkQtm6f6172R5PBrPBcs7KgN5R2UgpRpIqQZSqoGU\naiClGkipBlKqgd9U38ilEo//iAAAAABJRU5ErkJggg==\n",
  252.       "text/plain": [
  253.        "<matplotlib.figure.Figure at 0x110aff128>"
  254.       ]
  255.      },
  256.      "metadata": {},
  257.      "output_type": "display_data"
  258.     },
  259.     {
  260.      "data": {
  261.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFUAAABZCAYAAABPN2ghAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAAuNJREFUeJztnD2LE1EYhc9xZRuxkxX8QBRsbF1s\nBMFC2c5W/0Aqf4ClpYWNbRBLsVuw8qOz3V1Q/EBllYjLFrKdVrJyLDILq24mNyZnsknOA5fMJDe5\nLw9zb+bOvHMpCWG0HBh3ANNIpBqIVAORaiBSDUSqgUg1EKkGItXAwZJKJJcA3AMwB+C+pDt96vec\npp0fKLzxsFbzmST2/QFJtQVdkZ8AnAEwD+AVgHN9vqNeRRNQauPv40tSUfe/AGBd0mdJPwE8AnCt\n4HszS4nU4wC+7trfqN4LPSgZU/caQ/4ZM0m2ALSGjmgKKJG6AeDkrv0TADb/riSpDaAN1P9RzQIl\n3X8FwFmSp0nOA7gO4LE3rMmm75EqaZvkTQBP0T0TeCDp7f822P98ZPKh48r/NHf/kvPUzKgMRKqB\nSDUQqQYi1UCkGohUA5FqIFINRKqBSDUQqQYi1UCkGohUA5FqIFINRKqBSDUQqQYi1UCkGohUA5Fq\nIFINlGZSdwB8B/ALwLakRWdQk06R1IrLkrZskUwR6f4GSqUKwDOSa1Vyb6ij5MEAAMeq1wV0H6S4\ntEedFoDVqtQ+jDDJpcTXwKmUJG8D+CHpbk2dpFLWQfIQycM72wCuAngzfHjTS8m//1EAyyR36j+U\n9MQa1YSTTOoBSSb1mIhUA5FqIFINRKqBSDUQqQYi1UCkGohUA5FqIFINDHKPahC2AHypto9U++Nm\nFHGcKqlkuUr1RwPk6n64+9pkHOn+BiLVQBNS2w20UUJjcdjH1Fkk3d+ATSrJJZIfSK6TvOVqpzCW\nDsnXJF+SXLW3Z7rxNwfgI4Ar6K7AtgLghqR3I2+sLJ4OgMWmcsFcR+pMr2TpkrrfVrJsNBfMNU0t\nWsmyQS5K2iS5AOA5yfeSXrgacx2pRStZNoWkzer1G4BldIcnGy6p+2Yly3Hkglm6/6hXshySxnPB\nMqMykBmVgUg1EKkGItVApBqIVAORaiBSDfwGctDmHj02YrAAAAAASUVORK5CYII=\n",
  262.       "text/plain": [
  263.        "<matplotlib.figure.Figure at 0x110ae2a90>"
  264.       ]
  265.      },
  266.      "metadata": {},
  267.      "output_type": "display_data"
  268.     },
  269.     {
  270.      "data": {
  271.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFUAAABZCAYAAABPN2ghAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAAw1JREFUeJztnD1rFFEUhp/XhDRiJxH8QCLYaBts\nBMFCSWerfyCVPyClP8BfkMJS7AJWfnS2iaD4gZEoEUMKSaeVRI7FbjBqdvYmmXdmNnseuOzO5m7u\n4cm9c+/cORlFBEm9HGs7gKNISjWQUg2kVAMp1UBKNZBSDaRUAynVQUQMLcAcsAqsAQsF9eOoliJf\nBYImgE/ABWAKeA1cSqmDS8nwvwKsRcTniPgJPAJuFXxvbCmRegb4uut4o/9ZMoDJgjra47P/trYk\nzQPzh47oCFAidQM4t+v4LLD5b6WIWAQWASSN935iwUQ1CXwGZvgzUV3OiWpwGdpTI2Jb0l3gKb2V\nwIOIeDf8zzXwN1b8bK8zzeghx85/9fAfbakRMTTIvKIykFINpFQDKdVASjVQsvivmarJc7RXBjtk\nTzWQUg2kVAMp1UBKNZBSDbSwpKriIMut7i21sqcaSKkGUqqBlGogpRro2OxfxaBZvnubMNlTDaRU\nAynVQEo1kFINpFQDRUsqSevAd+AXsB0Rs86g9kf37nntZ516PSK2bJEcIXL4GyiVGsAzSS/7yb1J\nFYX/nXK6/zpNLz/12h515oGVfmk9j7RXoqL48lP3nUop6R7wIyLuV9TpSCZ1/RNVLamUko5LOrHz\nHrgJvD1QRGNCyex/CliStFP/YUQ8sUZVG+0st1rIpO4KB5OamdQtkVINpFQDKdVASjUwQjf+6sa3\nS5U91UBKNZBSDaRUAynVQEo14FpSbQFf+u9P9o/bpo44zpdUsuxS/dWAtNKFu69NxpHD30BKNdCE\n1MUG2iihsTjs59RxJIe/AZtUSXOSViWtSVpwtVMYy7qkN5JeSVqxt2e68TcBfARu0HsC2zJwJyLe\n195YWTzrwGxTuWCunjrWT7J0Se3akywbzQVzXaYWPcmyQa5GxKakaeC5pA8R8cLVmKunFj3Jsiki\nYrP/+g1Yond6suGSugxclDQjaQq4DTw2tVVJG7lgluFf/5MsD0XjuWB5RWUgr6gMpFQDKdVASjWQ\nUg2kVAMp1UBKNfAbRODIpe72tEcAAAAASUVORK5CYII=\n",
  272.       "text/plain": [
  273.        "<matplotlib.figure.Figure at 0x110f51940>"
  274.       ]
  275.      },
  276.      "metadata": {},
  277.      "output_type": "display_data"
  278.     }
  279.    ],
  280.    "source": [
  281.     "print('Train set of strokes')\n",
  282.     "for stroke in alphabet_train:\n",
  283.     "    img = compose_one_grid(subgrid_size, stroke)\n",
  284.     "    plt.figure(figsize=(1,1))\n",
  285.     "    plt.imshow(img)\n",
  286.     "    plt.show()\n",
  287.     "    \n",
  288.     "print('Test set of strokes')\n",
  289.     "for stroke in alphabet_test:\n",
  290.     "    img = compose_one_grid(subgrid_size, stroke)\n",
  291.     "    plt.figure(figsize=(1,1))\n",
  292.     "    plt.imshow(img)\n",
  293.     "    plt.show()"
  294.    ]
  295.   },
  296.   {
  297.    "cell_type": "markdown",
  298.    "metadata": {},
  299.    "source": [
  300.     "# plot examples of symbols"
  301.    ]
  302.   },
  303.   {
  304.    "cell_type": "code",
  305.    "execution_count": 70,
  306.    "metadata": {
  307.     "scrolled": true
  308.    },
  309.    "outputs": [
  310.     {
  311.      "name": "stdout",
  312.      "output_type": "stream",
  313.      "text": [
  314.       "Train:\n"
  315.      ]
  316.     },
  317.     {
  318.      "data": {
  319.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFwAAACPCAYAAAB3RbzZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAABTJJREFUeJztnc1vFWUUh5+fNWyMCxEhCEQxYWNc\nkLRhY2IwRtO4QXewItEEN/wB7jRx4864rYbIRtgRiTEiYeO2JfEDjEolGGoJ2Lhxh+BxMYNpS++9\n05m5v7m99zzNZD46d+b0yZvTd+bOmVcRQeLjka4DmDRSuJkUbiaFm0nhZlK4mRRuJoWbSeFmHm3y\nYUmzwMfAFPBpRHw4YP+xvayNCFXdsdZEIfk34DlgG/A98PyAz8S4TlW9NUkph4DFiLgeEXeBs8CR\nBsebCJoI3wPcXLW+VG5bg6QTkhYkLTQ419jQJIdvlLMeytERMQfMwXjn8Ko0aeFLwL5V63uB5Wbh\njD9NhM8DByTtl7QNOAqcbyes8aV2SomIe5JOAhcoeiynIuJq/VD6ZZtqPa5WGHIY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Mez1Td0ToGxJoTSwtDG7tthOPIK00z\nKdxMl8LnOjz3aqxxdJbDJ5VMKWY6ES5pVtIvkhYldfbqD0k3JP1Y3vG03HqwpxRJU8CvwKsUlc3z\nwLGI+MkaCP8PMTzjHPG2ixZ+CFiMiOsRcRc4S/H+lYmgC+F7gJur1pfKbV0QDBjxtm26GMdno4v4\nrrpKL0bEsqSdwEVJP5f3/4dGFy18Cdi3an0vsNxBHJ2MeNuF8HnggKT9krYBRynev2KlqxFv7Skl\nIu5JOglcAKaAUxFx1R0HbY94W5G80jSTV5pmUriZFG4mhZtJ4WZSuJkUbiaFm/kP+8NKHwcUZOAA\nAAAASUVORK5CYII=\n",
  320.       "text/plain": [
  321.        "<matplotlib.figure.Figure at 0x110fbc630>"
  322.       ]
  323.      },
  324.      "metadata": {},
  325.      "output_type": "display_data"
  326.     },
  327.     {
  328.      "data": {
  329.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFwAAACPCAYAAAB3RbzZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAABTFJREFUeJztnb+LHWUUhp/XlW3EwhgS1iSYCGnE\nIkVII0gslGAT7GIVUIjN/gF2CjZ2YrvKYmXShQQRY0hjmxX8sRFjYohk3SXLYmMXNx6LOyt3N7uz\n48zcdyb3nicMc+cyO/fw5OObMzPfmU8RQeLjia4DmDRSuJkUbiaFm0nhZlK4mRRuJoWbSeFmnmzy\nx5JOAZ8AU8BnEfHRLvuP7WVtRKjqjrUWBpJ/A14ApoEfgBd3+ZsY16WqtyZdygngdkTciYgHwAXg\ndIPjTQRNhB8A7g1tLxXfbULSOUkLkhYa/NbY0KQP367PeqSPjog5YA7Guw+vSpMWvgQcGto+CCw3\nC2f8aSL8OnBU0hFJ08AZ4HI7YY0vtbuUiFiXNAtcY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5S7wbsXfWwN+Lz7vLba7po04nq+6o7UCYtMPSwsjm7utx3HklaaZFG6m\nS+FzHf72MNY4OuvDJ5XsUsx0IlzSKUk3Jd2W1NmrPyTdlfRTccfTcuvB3qVImgJ+BV5jUNl8HXgr\nIn62BsJ/Uwwfd85420ULPwHcjog7EfEAuACc7iCOTuhC+AHg3tD2UvFdFwS7zHjbNl0MBNrurlpX\nqdLLEbFcvGDnqqRfivv/I6OLFr4EHBraPggsdxBHJzPediH8OnBU0hFJ08AZBu9fsdLVjLf2LiUi\n1iXNAleAKWA+Im6446DtGW8rkleaZvJK00wKN5PCzaRwMyncTAo3k8LNpHAz/wI3tcUJSFM3KQAA\nAABJRU5ErkJggg==\n",
  330.       "text/plain": [
  331.        "<matplotlib.figure.Figure at 0x110aff898>"
  332.       ]
  333.      },
  334.      "metadata": {},
  335.      "output_type": "display_data"
  336.     },
  337.     {
  338.      "data": {
  339.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFwAAACPCAYAAAB3RbzZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAABUxJREFUeJztnc9rHWUUhp/XSDbiwlpbYltshW7E\nRaGhG0HqQgluiru6KijUTf8Adwpu3InbKMGV7a5YRKylG7dtwR+pGFtLpTGlNbhxV1OPizuRmzSZ\njDNz35ncnCcMc+dy78zhycc3Z+Z+Zz5FBImPx7oOYKeRws2kcDMp3EwKN5PCzaRwMyncTAo383iT\nL0uaAT4GJoBPI+LDLT4/tpe1EaGqH6y1MJD8K/A8MAl8D7ywxXdiXJeq3pp0KceAmxFxKyIeAOeA\nEw32tyNoInwfcGdoe7F4bw2STku6Kulqg2ONDU368I36rEf66IiYBWZhvPvwqjRp4YvAgaHt/cBS\ns3DGnybCrwCHJR2SNAmcBC60E9b4UrtLiYg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rUEr5ablLwBjn3Q2W2vFso6SxwHNgtaRF4Dzgu6QiDLuU28E7F4y0DvxWvdxfb\nXdNGHM9V/aC1AmLNgaWrI5u7rcdx5JWmmRRupkvhsx0eexhrHJ314TuV7FLMdCJc0oykBUk3JXX2\n6A9JtyX9WNzxtNx6sHcpkiaAX4BXGVQ2XwHejIifrIHw3xTD084Zb7to4ceAmxFxKyIeAOeAEx3E\n0QldCN8H3BnaXize64Jgixlv26aLgUAb3VXrKlV6KSKWJO0BLkn6ubj/PzK6aOGLwIGh7f3AUgdx\ndDLjbRfCrwCHJR2SNAmcZPD8FStdzXhr71IiYkXSGeAiMAHMRcR1dxy0PeNtRfJK00xeaZpJ4WZS\nuJkUbiaFm0nhZlK4mRRu5l/4Qs5/53bMdgAAAABJRU5ErkJggg==\n",
  340.       "text/plain": [
  341.        "<matplotlib.figure.Figure at 0x10cecdef0>"
  342.       ]
  343.      },
  344.      "metadata": {},
  345.      "output_type": "display_data"
  346.     },
  347.     {
  348.      "name": "stdout",
  349.      "output_type": "stream",
  350.      "text": [
  351.       "Test:\n"
  352.      ]
  353.     },
  354.     {
  355.      "data": {
  356.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFwAAACPCAYAAAB3RbzZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAABQtJREFUeJztnc9rHGUYxz9fI7mIB2tpiG2xFXIR\nDz2UXgSpByV4Kd7qqaBQL/0DvCl48SZeowRPtrdiEbGWXrymgj9SMTaWSmNCQ/DiraY+HnYqm5ps\nxpnZ78zuPp8wzM4yO/vwycs7z7w7z7yKCBIfj7UdwKSRws2kcDMp3EwKN5PCzaRwMyncTAo383id\nD0uaBz4CpoBPIuKDffYf28vaiFDZHSst9CT/CjwHTAPfA8/v85kY16WstzpdyilgNSJ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4scZyxrYAY6t2zEXEvIh5ExN/A\nx+TcD6WpJPxhuUnB6+TcD6XZd7RQ0kXgNHBQ0hrwLnBa0gl6Xcod4O2S37cF/Fa8Plhst00TcTxb\ndkdrBcSOL5ZudGHuNncceaVpJoWbaVP4Qovf3Y81jtb68EkluxQzrQiXNC9pRdKqpNYe/SHpjqQf\nixFPy9CDvUuRNAX8ArxCr7J5CXgjIn6yBsK/UwyfdM5420YLPwWsRsTtiLgPXALOtBBHK7Qh/DBw\nt297rXivDYJ9ZrxtmjZuBNptVK2tVOnFiFgvHrBzTdLPxfj/0Gijha8BR/u2jwDrLcTRyoy3bQhf\nAuYkHZc0DZyl9/wVK23NeGvvUiJiW9IF4CowBSxGxE13HLQ0421eaZrJK00zKdxMCjeTws2kcDMp\n3EwKN5PCzfwDR/2cFiJTgMQAAAAASUVORK5CYII=\n",
  357.       "text/plain": [
  358.        "<matplotlib.figure.Figure at 0x110de26d8>"
  359.       ]
  360.      },
  361.      "metadata": {},
  362.      "output_type": "display_data"
  363.     },
  364.     {
  365.      "data": {
  366.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFwAAACPCAYAAAB3RbzZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAABMJJREFUeJztnb2PFVUYh5+fa2iMhUggCEQo6CxI\nJDQmBgsMsSF2UJFogg1/gJ0mNnbGFg2xEjoiMUYkNLYLiR9A5CMEw7oEQmzsEHwt7mB2cT8md2Z/\ns9z7e5LJzLk798ybZ2fPnDM77xxVFcHHc0MHMG1EuJkINxPhZiLcTISbiXAzEW4mws083+XLkg4C\nnwMzwJdV9ekq+y87rH29SyAmLq3ws6pSmzo07tBe0gxwHTgAzAGzwJGqurrCd5Y92LNwg2Elo22F\nd2lS9gE3q+pWVT0ETgOHOtQ3F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sDZ8WkmTYmYQ4ZIOSrom6aakwV79Iem2pF+bO56WWw/2JkXSDHAdOMAo\ns3kWOFJVV62B8N8Uw3udM94OcYbvA25W1a2qegicBg4NEMcgDCF8G3BnQXmu+WwIilVmvO2bIV6F\nutRdtaG6Sm9U1Xzzgp3zkn5r7v+vGUOc4XPAjgXl7cD8AHEMMuPtEMJngd2SdknaABxm9P4VK0PN\neGtvUqrqkaTjwDlgBjhZVVfccTDQjLcZaZrJSNNMhJuJcDMRbibCzUS4mQg3E+Fm/gV0i++Q6by/\n7wAAAABJRU5ErkJggg==\n",
  367.       "text/plain": [
  368.        "<matplotlib.figure.Figure at 0x110e69240>"
  369.       ]
  370.      },
  371.      "metadata": {},
  372.      "output_type": "display_data"
  373.     },
  374.     {
  375.      "data": {
  376.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFwAAACPCAYAAAB3RbzZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAABQtJREFUeJztnc9rHGUYxz9fI72IB2tpiG2xFXIR\nDz2UXgSpB6V4Kd7qqaBQL/kDvCl48SZeowRPtrdiEbGWXrw2gj9SMTaWSGNCQ/HiraY+HnYim5ps\nxpnZ78zuPp8wzM4yO/vwycs7z7w7z7yKCBIfj7UdwKSRws2kcDMp3EwKN5PCzaRwMyncTAo383id\nD0s6C3wETAGfRMQH++w/tpe1EaGyO1Za6En+FXgOOAB8Dzy/z2diXJey3up0KaeBlYi4ExEPgMvA\nuRrHmwjqCD8C3O3bXive24Gki5IWJS3W+K6xoU4fvluf9Z8+OiLmgXkY7z68LHVa+BpwrG/7KLBe\nL5zxp47wm8CspBOSDgDngavNhDW+VO5SImJL0hxwjV7GshARtypHMqizKZdwjQRy/uIzsA8fceFl\n8/C80jSTws2kcDMp3EwKN1NrtLBRB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\nYsTTMvRg71IkTQG/AK/Qq2y+CbwRET9ZA+HfKYZPOWe8baOFnwZWIuJORDwALgPnWoijFdoQfgS4\n27e9VrzXBsE+M942TRs3Au02qtZWqvRiRKwXD9i5LunnYvx/aLTRwteAY33bR4H1FuJoZcbbNoTf\nBGYlnZB0ADhP7/krVtqa8dbepUTElqQ54BowBSxExC13HLQ0421eaZrJK00zKdxMCjeTws2kcDMp\n3EwKN5PCzfwDPf+cFkGXsiYAAAAASUVORK5CYII=\n",
  377.       "text/plain": [
  378.        "<matplotlib.figure.Figure at 0x110ee1b70>"
  379.       ]
  380.      },
  381.      "metadata": {},
  382.      "output_type": "display_data"
  383.     }
  384.    ],
  385.    "source": [
  386.     "print('Train:')\n",
  387.     "for i in range(3):\n",
  388.     "    # randomly compose symbols out of of strokes\n",
  389.     "    rand = np.random.randint(alphabet_size_train,size=2)\n",
  390.     "    strokes = [alphabet_train[rand[i]] for i in range(2)]\n",
  391.     "    img = compose_two_grid(subgrid_size, strokes )\n",
  392.     "    plt.figure(figsize=(2,2))\n",
  393.     "    plt.imshow(img)\n",
  394.     "    plt.show()\n",
  395.     "\n",
  396.     "print('Test:')\n",
  397.     "for i in range(3):\n",
  398.     "    # randomly compose images out of an alphabet\n",
  399.     "    rand = np.random.randint(alphabet_size_test,size=2)\n",
  400.     "    strokes = [alphabet_test[rand[i]] for i in range(2)]\n",
  401.     "    img = compose_two_grid(subgrid_size, strokes )\n",
  402.     "    plt.figure(figsize=(2,2))\n",
  403.     "    plt.imshow(img)\n",
  404.     "    plt.show()"
  405.    ]
  406.   },
  407.   {
  408.    "cell_type": "markdown",
  409.    "metadata": {},
  410.    "source": [
  411.     "# Generate dataset"
  412.    ]
  413.   },
  414.   {
  415.    "cell_type": "code",
  416.    "execution_count": 71,
  417.    "metadata": {
  418.     "collapsed": true
  419.    },
  420.    "outputs": [],
  421.    "source": [
  422.     "def generate_data_from_alphabet(alphabet):\n",
  423.     "    # create train images\n",
  424.     "    images = list()\n",
  425.     "    for i_a in alphabet:\n",
  426.     "        for j_a in alphabet:\n",
  427.     "            strokes = [i_a, j_a]\n",
  428.     "            img = compose_two_grid(subgrid_size, strokes )\n",
  429.     "            images.append(img)\n",
  430.     "    return images\n",
  431.     "#     plt.imshow(img)\n",
  432.     "#     plt.show()"
  433.    ]
  434.   },
  435.   {
  436.    "cell_type": "code",
  437.    "execution_count": 72,
  438.    "metadata": {
  439.     "collapsed": true
  440.    },
  441.    "outputs": [],
  442.    "source": [
  443.     "def generate_data(alphabet_size_train=64, \n",
  444.     "                  alphabet_size_test=16, \n",
  445.     "                  subgrid_size=(8,8), \n",
  446.     "                  colors=4, \n",
  447.     "                  num_strokes=6, \n",
  448.     "                  min_train=2, \n",
  449.     "                  max_train=6, \n",
  450.     "                  min_test=1, \n",
  451.     "                  max_test=1):\n",
  452.     "    \n",
  453.     "    # generate sets of symbols for train\n",
  454.     "    alphabet_train = create_strokes(alphabet_size=alphabet_size_train, num_strokes=num_strokes, colors=colors, mini=min_train, maxi=max_train)\n",
  455.     "    print('created train alphabet')\n",
  456.     "    # generate a different set of symbols for the test\n",
  457.     "    alphabet_test = create_strokes(alphabet_size=alphabet_size_test, num_strokes=num_strokes, ref=alphabet_train, colors=colors, mini=min_test, maxi=max_test)\n",
  458.     "    print('created test alphabet')\n",
  459.     "    train = generate_data_from_alphabet(alphabet_train)\n",
  460.     "    print('generated train images')\n",
  461.     "    test = generate_data_from_alphabet(alphabet_test)\n",
  462.     "    print('generated test images')\n",
  463.     "    return train, test, alphabet_train, alphabet_test"
  464.    ]
  465.   },
  466.   {
  467.    "cell_type": "code",
  468.    "execution_count": 73,
  469.    "metadata": {},
  470.    "outputs": [
  471.     {
  472.      "name": "stdout",
  473.      "output_type": "stream",
  474.      "text": [
  475.       "created train alphabet\n",
  476.       "created test alphabet\n",
  477.       "generated train images\n",
  478.       "generated test images\n"
  479.      ]
  480.     }
  481.    ],
  482.    "source": [
  483.     "train_images, test_images, alphabet_train, alphabet_test = generate_data()"
  484.    ]
  485.   },
  486.   {
  487.    "cell_type": "code",
  488.    "execution_count": 74,
  489.    "metadata": {},
  490.    "outputs": [
  491.     {
  492.      "name": "stdout",
  493.      "output_type": "stream",
  494.      "text": [
  495.       "num train examples 4096\n",
  496.       "num test examples 256\n"
  497.      ]
  498.     }
  499.    ],
  500.    "source": [
  501.     "print('num train examples', len(train_images))\n",
  502.     "print('num test examples', len(test_images))"
  503.    ]
  504.   },
  505.   {
  506.    "cell_type": "code",
  507.    "execution_count": 75,
  508.    "metadata": {},
  509.    "outputs": [],
  510.    "source": [
  511.     "# save \n",
  512.     "pickle.dump(train_images, open('dataset/train.p','wb'))\n",
  513.     "pickle.dump(test_images, open('dataset/test.p','wb'))\n",
  514.     "pickle.dump(alphabet_train, open('dataset/alphabet_train.p','wb'))\n",
  515.     "pickle.dump(alphabet_test, open('dataset/alphabet_test.p','wb'))"
  516.    ]
  517.   },
  518.   {
  519.    "cell_type": "code",
  520.    "execution_count": null,
  521.    "metadata": {
  522.     "collapsed": true
  523.    },
  524.    "outputs": [],
  525.    "source": []
  526.   }
  527.  ],
  528.  "metadata": {
  529.   "kernelspec": {
  530.    "display_name": "Python 3",
  531.    "language": "python",
  532.    "name": "python3"
  533.   },
  534.   "language_info": {
  535.    "codemirror_mode": {
  536.     "name": "ipython",
  537.     "version": 3
  538.    },
  539.    "file_extension": ".py",
  540.    "mimetype": "text/x-python",
  541.    "name": "python",
  542.    "nbconvert_exporter": "python",
  543.    "pygments_lexer": "ipython3",
  544.    "version": "3.6.1"
  545.   }
  546.  },
  547.  "nbformat": 4,
  548.  "nbformat_minor": 2
  549. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top