{"id":296214,"date":"2019-12-22T21:00:10","date_gmt":"2019-12-22T21:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=296214"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=296214","title":{"rendered":"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u0435\u0440\u0442\u043e\u0447\u043d\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u0438\u0433\u0440\u044b \u0432 \u00ab\u0416\u0438\u0437\u043d\u044c\u00bb (\u043d\u0430 Keras)"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/481544\/\">\n<p><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/3564\/1*bqNylp7FcqIBWg0DrcimUw.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0426\u0435\u043b\u044c \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0438\u0433\u0440\u0430\u0442\u044c \u0432 \u0438\u0433\u0440\u0443 &quot;\u0416\u0438\u0437\u043d\u044c&quot;, \u043d\u0435 \u043e\u0431\u0443\u0447\u0430\u044f \u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0438\u0433\u0440\u044b.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/kylewbanks.com\/blog\/conways-game-of-life-convolutional-neural-network-keras\">&quot;Using a Convolutional Neural Network to Play Conway&#8217;s Game of Life with Keras&quot;<\/a> \u0430\u0432\u0442\u043e\u0440\u0430 kylewbanks.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0438\u0433\u0440\u043e\u0439 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0416\u0438\u0437\u043d\u044c (<em>\u044d\u0442\u043e \u043a\u043b\u0435\u0442\u043e\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043d\u044b\u0439 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u043c \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u043e\u043c \u0414\u0436\u043e\u043d\u043e\u043c \u041a\u043e\u043d\u0432\u0435\u0435\u043c \u0432 1970 \u0433\u043e\u0434\u0443<\/em>), \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0442\u0430\u043a\u043e\u0432\u044b.<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u0438\u0433\u0440\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e, \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u0443\u044e \u0441\u0435\u0442\u043a\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 \u044f\u0447\u0435\u0435\u043a, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0434\u0432\u0443\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439: \u0436\u0438\u0432\u0430\u044f \u0438\u043b\u0438 \u043c\u0435\u0440\u0442\u0432\u0430\u044f (\u0438\u043b\u0438 \u043d\u0430\u0441\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u0438 \u043d\u0435\u0437\u0430\u0441\u0435\u043b\u0435\u043d\u043d\u0430\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e). \u041a\u0430\u0436\u0434\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0432\u043e\u0441\u0435\u043c\u044c\u044e \u0441\u043e\u0441\u0435\u0434\u044f\u043c\u0438 \u043f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438, \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0438 \u0438\u043b\u0438 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041b\u044e\u0431\u0430\u044f \u0436\u0438\u0432\u0430\u044f \u043a\u043b\u0435\u0442\u043a\u0430 \u0441 \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u0434\u0432\u0443\u043c\u044f \u0436\u0438\u0432\u044b\u043c\u0438 \u0441\u043e\u0441\u0435\u0434\u044f\u043c\u0438 \u0443\u043c\u0438\u0440\u0430\u0435\u0442.<\/li>\n<li>\u041b\u044e\u0431\u0430\u044f \u0436\u0438\u0432\u0430\u044f \u043a\u043b\u0435\u0442\u043a\u0430 \u0441 \u0434\u0432\u0443\u043c\u044f \u0438\u043b\u0438 \u0442\u0440\u0435\u043c\u044f \u0436\u0438\u0432\u044b\u043c\u0438 \u0441\u043e\u0441\u0435\u0434\u044f\u043c\u0438 \u0434\u043e\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f.<\/li>\n<li>\u041b\u044e\u0431\u0430\u044f \u0436\u0438\u0432\u0430\u044f \u043a\u043b\u0435\u0442\u043a\u0430 \u0441 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0442\u0440\u0435\u043c\u044f \u0436\u0438\u0432\u044b\u043c\u0438 \u0441\u043e\u0441\u0435\u0434\u044f\u043c\u0438 \u0443\u043c\u0438\u0440\u0430\u0435\u0442.<\/li>\n<li>\u041b\u044e\u0431\u0430\u044f \u043c\u0435\u0440\u0442\u0432\u0430\u044f \u043a\u043b\u0435\u0442\u043a\u0430 \u0441 \u0440\u043e\u0432\u043d\u043e \u0442\u0440\u0435\u043c\u044f \u0436\u0438\u0432\u044b\u043c\u0438 \u0441\u043e\u0441\u0435\u0434\u044f\u043c\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0436\u0438\u0432\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u043e\u0439.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438, \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0438 \u0441\u043c\u0435\u0440\u0442\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0447\u0438\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e. \u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%98%D0%B3%D1%80%D0%B0_%C2%AB%D0%96%D0%B8%D0%B7%D0%BD%D1%8C%C2%BB\">\u0441\u043c. \u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u044e<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c? \u0413\u043b\u0430\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f, \u0438 \u0447\u0442\u043e\u0431\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u0441\u0432\u0435\u0440\u0442\u043e\u0447\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a&#8230;<\/p>\n<p>  <\/p>\n<h1 id=\"igrovaya-logika\">\u0418\u0433\u0440\u043e\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430<\/h1>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u0433\u0440\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a: <a href=\"https:\/\/jakevdp.github.io\/blog\/2013\/08\/07\/conways-game-of-life\/\">https:\/\/jakevdp.github.io\/blog\/2013\/08\/07\/conways-game-of-life\/<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u043e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0433\u0434\u0435 0 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0440\u0442\u0432\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443, \u0430 1 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0436\u0438\u0432\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0442\u043e\u0433\u043e \u0436\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0433\u0440\u044b.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import numpy as np  def life_step(X):     live_neighbors = sum(np.roll(np.roll(X, i, 0), j, 1)                      for i in (-1, 0, 1) for j in (-1, 0, 1)                      if (i != 0 or j != 0))     return (live_neighbors == 3) | (X &amp; (live_neighbors == 2)).astype(int)<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"generaciya-igrovogo-polya\">\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f<\/h1>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044f \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0435, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u044f \u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0445 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>generate_frames<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 <code>num_frames<\/code> \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u043e\u0439 \u0438 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 &quot;\u0436\u0438\u0432\u043e\u0439&quot;, \u0430 <code>render_frames<\/code> \u0440\u0438\u0441\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0434\u0432\u0443\u0445 \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0440\u044f\u0434\u043e\u043c \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f (\u0436\u0438\u0432\u044b\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u0431\u0435\u043b\u044b\u0435, \u0430 \u043c\u0435\u0440\u0442\u0432\u044b\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u0447\u0435\u0440\u043d\u044b\u0435):<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import matplotlib.pyplot as plt  def generate_frames(num_frames, board_shape=(100,100), prob_alive=0.15):     return np.array([         np.random.choice([False, True], size=board_shape, p=[1-prob_alive, prob_alive])         for _ in range(num_frames)     ]).astype(int)  def render_frames(frame1, frame2):     plt.subplot(1, 2, 1)     plt.imshow(frame1.flatten().reshape(board_shape), cmap='gray')      plt.subplot(1, 2, 2)     plt.imshow(frame2.flatten().reshape(board_shape), cmap='gray')<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u044d\u0442\u0438 \u043f\u043e\u043b\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">board_shape = (20, 20) board_size = board_shape[0] * board_shape[1] probability_alive = 0.15  frames = generate_frames(10, board_shape=board_shape, prob_alive=probability_alive) print(frames.shape) # (num_frames, board_w, board_h)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(10, 20, 20)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">print(frames[0])<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[[0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1],  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0],  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0],  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],  [0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1],  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1],  [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],  [0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],  [1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],  [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0],  [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],  [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],  [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],  [0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],  [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0]])<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.<br \/>  \u0421\u043f\u0440\u0430\u0432\u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>life_step<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">ender_frames(frames[1], life_step(frames[1]))<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kylewbanks.com\/images\/post\/cnn_cgol_sample_frames.png\"\/><\/p>\n<p>  <\/p>\n<h1 id=\"postroenie-obuschayuschego-i-testovogo-naborov\">\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043e\u0431\u0443\u0449\u0430\u044e\u0449\u0435\u0433\u043e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u043e\u0432<\/h1>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445 <code>y_train<\/code>\/<code>y_val<\/code>\/<code>y_test<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043f\u043e\u043b\u0435 \u0438\u0433\u0440\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430 \u043f\u043e\u043b\u044f \u0432 <code>X_train<\/code>\/<code>X_val<\/code>\/<code>X_test<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def reshape_input(X):     return X.reshape(X.shape[0], X.shape[1], X.shape[2], 1)  def generate_dataset(num_frames, board_shape, prob_alive):     X = generate_frames(num_frames, board_shape=board_shape, prob_alive=prob_alive)     X = reshape_input(X)     y = np.array([         life_step(frame)          for frame in X     ])     return X, y  train_size = 70000 val_size   = 10000 test_size  = 20000<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">print(&quot;Training Set:&quot;) X_train, y_train = generate_dataset(train_size, board_shape, probability_alive) print(X_train.shape) print(y_train.shape)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Training Set: (70000, 20, 20, 1) (70000, 20, 20, 1)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">print(&quot;Validation Set:&quot;) X_val, y_val = generate_dataset(val_size, board_shape, probability_alive) print(X_val.shape) print(y_val.shape)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Validation Set: (10000, 20, 20, 1) (10000, 20, 20, 1)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\">print(&quot;Test Set:&quot;) X_test, y_test = generate_dataset(test_size, board_shape, probability_alive) print(X_test.shape) print(y_test.shape)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Test Set: (20000, 20, 20, 1) (20000, 20, 20, 1)<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"postroenie-svertochnoy-neyronnoy-seti\">\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0440\u0442\u043e\u0447\u043d\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/h1>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u0441\u0432\u0435\u0440\u0442\u043e\u0447\u043d\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Keras. \u041a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440 \u044f\u0434\u0440\u0430 (3, 3) \u0438 \u0448\u0430\u0433 1. \u041e\u043d\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 CNN \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 3&#215;3 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u0445 \u044f\u0447\u0435\u0435\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438 \u043f\u043e\u043b\u044f, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043d\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0438\u0436\u0435\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0431\u044b\u043b\u043e \u0438\u0433\u0440\u043e\u0432\u044b\u043c \u043f\u043e\u043b\u0435\u043c, \u0430 \u043c\u044b \u0431\u044b\u043b\u0438 \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u044f\u0447\u0435\u0439\u043a\u0435 <code>x<\/code>, \u043e\u043d\u0430 \u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0430 \u043d\u0430 \u0432\u0441\u0435 \u044f\u0447\u0435\u0439\u043a\u0438, \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0432\u043e\u0441\u043a\u043b\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u043a\u043e\u043c <code>!<\/code> \u0438 \u044f\u0447\u0435\u0439\u043a\u0443 <code>\u0445<\/code>. \u0417\u0430\u0442\u0435\u043c \u0441\u0435\u0442\u044c \u0434\u0432\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0432\u0434\u043e\u043b\u044c \u044f\u0447\u0435\u0439\u043a\u0438 \u0432\u043f\u0440\u0430\u0432\u043e \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044f \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443 \u0438 \u0435\u0435 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043f\u043e\u043b\u044e.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">0 0 0 0 0 0! ! ! 0 0! x ! 0 0! ! ! 0 0 0 0 0 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from keras.models import Sequential from keras.layers import Dense, Dropout, Activation, Conv2D, MaxPool2D  # CNN Properties filters = 50 kernel_size = (3, 3) # look at all 8 neighboring cells, plus itself strides = 1 hidden_dims = 100  model = Sequential() model.add(Conv2D(     filters,      kernel_size,     padding='same',     activation='relu',     strides=strides,     input_shape=(board_shape[0], board_shape[1], 1) )) model.add(Dense(hidden_dims)) model.add(Dense(1)) model.add(Activation('sigmoid'))  model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0432\u044b\u0432\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>summary<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">model.summary()<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">_________________________________________________________________ Layer (type)                 Output Shape              Param #    ================================================================= conv2d_9 (Conv2D)            (None, 20, 20, 50)        500        _________________________________________________________________ dense_17 (Dense)             (None, 20, 20, 100)       5100       _________________________________________________________________ dense_18 (Dense)             (None, 20, 20, 1)         101        _________________________________________________________________ activation_9 (Activation)    (None, 20, 20, 1)         0          ================================================================= Total params: 5,701 Trainable params: 5,701 Non-trainable params: 0 _________________________________________________________________<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"obuchenie-i-sohranenie-modeli\">\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/h1>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0432 CNN, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u0443\u0447\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0435\u0435 \u043d\u0430 \u0434\u0438\u0441\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def train(model, X_train, y_train, X_val, y_val, batch_size=50, epochs=2, filename_suffix=''):     model.fit(         X_train, y_train,          batch_size=batch_size,          epochs=epochs,         validation_data=(X_val, y_val)     )      with open('cgol_cnn{}.json'.format(filename_suffix), 'w') as file:         file.write(model.to_json())     model.save_weights('cgol_cnn{}.h5'.format(filename_suffix))  train(model, X_train, y_train, X_val, y_val, filename_suffix='_basic')<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Train on 70000 samples, validate on 10000 samples Epoch 1\/2 70000\/70000 [==============================] - 27s 388us\/step      - loss: 0.1324 - acc: 0.9651 - val_loss: 0.0833 - val_acc: 0.9815 Epoch 2\/2 70000\/70000 [==============================] - 27s 383us\/step      - loss: 0.0819 - acc: 0.9817 - val_loss: 0.0823 - val_acc: 0.9816<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 98% \u043a\u0430\u043a \u0434\u043b\u044f \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u0447\u043d\u044b\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0433\u0434\u0435 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>  <\/p>\n<h1 id=\"probuem\">\u041f\u0440\u043e\u0431\u0443\u0435\u043c<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0438 \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043e\u0434\u043d\u043e \u0438\u0433\u0440\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">X, y = generate_dataset(1, board_shape=board_shape, prob_alive=probability_alive)  render_frames(X[0].flatten().reshape(board_shape), y)<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kylewbanks.com\/images\/post\/cnn_cgol_sample_frames_2.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044f\u0447\u0435\u0435\u043a \u0431\u044b\u043b\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">pred = model.predict_classes(X) print(np.count_nonzero(pred.flatten() - y.flatten()), &quot;incorrect cells.&quot;)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">4 incorrect cells.<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u0441 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">render_frames(y, pred.flatten().reshape(board_shape))<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kylewbanks.com\/images\/post\/cnn_cgol_bad_prediction.png\"\/><\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043d\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e, \u043d\u043e \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u0433\u0434\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c? \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0441\u0435\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043b\u0435\u0442\u043a\u0438 \u043f\u043e \u043a\u0440\u0430\u044f\u043c \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0443\u0434\u0430, \u0433\u0434\u0435 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">print(pred.flatten().reshape(board_shape) - y.flatten().reshape(board_shape))<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[[ 0  0  0  0  0  0  0 -1  0  0  0  0  0  0  0  0  0 -1 -1  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]  [ 0  0  0  0  0  0 -1  0  0  0  0  0  0  0  0  0  0  0  0  0]]<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432\u0441\u0435 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043f\u043e \u043a\u0440\u0430\u044f\u043c \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u043e.<\/p>\n<p>  <\/p>\n<h1 id=\"prosmotr-oshibok-ispolzuya-testovyy-nabor\">\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u043e\u0448\u0438\u0431\u043e\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440<\/h1>\n<p>  <\/p>\n<p>\u041c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0442\u0435\u043f\u043b\u043e\u0432\u0443\u044e \u043a\u0430\u0440\u0442\u0443, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e, \u0433\u0434\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0435\u043b\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0435\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0435\u0441\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def view_prediction_errors(model, X, y):     y_pred = model.predict_classes(X)     sum_y_pred = np.sum(y_pred, axis=0).flatten().reshape(board_shape)     sum_y = np.sum(y, axis=0).flatten().reshape(board_shape)      plt.imshow(sum_y_pred - sum_y, cmap='hot', interpolation='nearest')     plt.show()  view_prediction_errors(model, X_test, y_test)<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kylewbanks.com\/images\/post\/cnn_cgol_bad_prediction_heatmap.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u043a\u0440\u0430\u044f\u0445 \u0438 \u0432 \u0443\u0433\u043b\u0430\u0445. \u0427\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a CNN \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u043c, \u043d\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u0438\u0433\u0440\u044b \u0432 <code>life_step<\/code> \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435. \u0413\u043b\u044f\u0434\u044f \u043d\u0430 \u043a\u0440\u0430\u0435\u0432\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443 <code>x<\/code> \u043d\u0438\u0436\u0435, CNN \u0432\u0438\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <code>x<\/code> \u0438 <code>!<\/code> \u043a\u043b\u0435\u0442\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">0 0 0 0 0 ! ! 0 0 0  x ! 0 0 0 ! ! 0 0 0  0 0 0 0 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0445\u043e\u0442\u0438\u043c, \u0438 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <code>life_step<\/code>, \u0442\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0438 \u0441 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">0 0 0 0 0 ! ! 0 0 !  x ! 0 0 ! ! ! 0 0 !  0 0 0 0 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0445\u043e\u0436\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0432 \u0443\u0433\u043b\u0430\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">x ! 0 0 ! ! ! 0 0 !  0 0 0 0 0 0 0 0 0 0 ! 0 0 0 !<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, <code>Conv2D<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u0430\u043a-\u0442\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b, \u043a\u0430\u0436\u0434\u0430\u044f \u0432\u0445\u043e\u0434\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u0440\u0430\u0435\u0432 \u0441 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0438 \u0442\u043e\u0433\u0434\u0430 Conv2D \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0438 \u0441\u0442\u0440\u043e\u043a\u0443. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432\u043e \u0432\u043b\u0430\u0441\u0442\u0438 Keras \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u0449\u0435\u043c, \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h1 id=\"ispravlenie-kraevyh-defektov-s-pomoschyu-zapolneniya\">\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0440\u0430\u0435\u0432\u044b\u0445 \u0434\u0435\u0444\u0435\u043a\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0433\u0440\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e, \u043a\u0430\u043a <code>life_step<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u043a\u0440\u0430\u0435\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>np.pad<\/code> \u0441 <code>mode = \u2019wrap\u2019<\/code> \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043d\u0438\u0436\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">x = np.array([     [1, 2, 3],     [4, 5, 6],     [7, 8, 9] ])  print(np.pad(x, (1, 1), mode='wrap'))<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">[[9, 7, 8, 9, 7],  [3, 1, 2, 3, 1],  [6, 4, 5, 6, 4],  [9, 7, 8, 9, 7],  [3, 1, 2, 3, 1]]<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446\/\u0441\u0442\u0440\u043e\u043a\u0430 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446\/\u0441\u0442\u0440\u043e\u043a\u0430 \u043e\u0442\u0437\u0435\u0440\u043a\u0430\u043b\u0438\u0432\u0430\u044e\u0442 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u0430 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 3&#215;3 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>x<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044f\u0447\u0435\u0439\u043a\u0430 [1] [1] \u0431\u044b\u043b\u0430 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0432 \u044f\u0447\u0435\u0439\u043a\u0435 [4] [1], \u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e [0] [1] \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 [3] [1]. \u0412\u043e \u0432\u0441\u0435\u0445 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445 \u0438 \u0434\u0430\u0436\u0435 \u0432 \u0443\u0433\u043b\u0430\u0445 \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u044b\u043b \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 CNN \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0440\u0430\u0439\u043d\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043c\u0430\u0442\u0440\u0438\u0446:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def pad_input(X):     return reshape_input(np.array([         np.pad(x.reshape(board_shape), (1,1), mode='wrap')         for x in X     ]))  X_train_padded = pad_input(X_train) X_val_padded = pad_input(X_val) X_test_padded = pad_input(X_test)  print(X_train_padded.shape) print(X_val_padded.shape) print(X_test_padded.shape)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(70000, 22, 22, 1) (10000, 22, 22, 1) (20000, 22, 22, 1)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438\/\u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 CNN \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <code>life_step<\/code>. \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 22&#215;22 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0445 20&#215;20.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0442\u0435\u043c, CNN \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u043e\u0435\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>padding = 'valid'<\/code> (\u0447\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 Conv2D \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0440\u0430\u044f, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e), \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e <code>input_shape<\/code>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u044f \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 22&#215;22, \u043c\u044b \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 20&#215;20 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446\/\u0441\u0442\u0440\u043e\u043a\u0443. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">model_padded = Sequential() model_padded.add(Conv2D(     filters,      kernel_size,     padding='valid',     activation='relu',     strides=strides,     input_shape=(board_shape[0] + 2, board_shape[1] + 2, 1) )) model_padded.add(Dense(hidden_dims)) model_padded.add(Dense(1)) model_padded.add(Activation('sigmoid'))  model_padded.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) model_padded.summary()<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">_________________________________________________________________ Layer (type)                 Output Shape              Param #    ================================================================= conv2d_10 (Conv2D)           (None, 20, 20, 50)        500        _________________________________________________________________ dense_19 (Dense)             (None, 20, 20, 100)       5100       _________________________________________________________________ dense_20 (Dense)             (None, 20, 20, 1)         101        _________________________________________________________________ activation_10 (Activation)   (None, 20, 20, 1)         0          ================================================================= Total params: 5,701 Trainable params: 5,701 Non-trainable params: 0 _________________________________________________________________<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0443\u0447\u0438\u0442\u044c\u0441\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u044b\u0440\u043e\u0432\u043d\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">train(     model_padded,      X_train_padded, y_train, X_val_padded, y_val,      filename_suffix='_padded' )<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Train on 70000 samples, validate on 10000 samples Epoch 1\/2 70000\/70000 [==============================] - 27s 389us\/step - loss: 0.0604 - acc: 0.9807 - val_loss: 4.5475e-04 - val_acc: 1.0000 Epoch 2\/2 70000\/70000 [==============================] - 27s 382us\/step - loss: 1.7058e-04 - acc: 1.0000 - val_loss: 5.9932e-05 - val_acc: 1.0000<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442 98% \u0434\u043e 100%, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0434\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">view_prediction_errors(model_padded, X_test_padded, y_test)<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kylewbanks.com\/images\/post\/cnn_cgol_good_prediction_heatmap.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u0427\u0435\u0440\u043d\u0430\u044f \u0442\u0435\u043f\u043b\u043e\u0432\u0430\u044f \u043a\u0430\u0440\u0442\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445, \u0438 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043b\u0438 \u043a\u0430\u0436\u0434\u0443\u044e \u044f\u0447\u0435\u0439\u043a\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0433\u0440\u044b.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u0431\u0430\u0432\u043d\u043e\u0435 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 \u0441\u0432\u0435\u0440\u0442\u043e\u0447\u043d\u044b\u043c\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0441\u0435\u0442\u044f\u043c\u0438, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. <a href=\"https:\/\/github.com\/KyleBanks\/conways-gol-cnn\">\u041d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 GitHub<\/a>.<\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/481544\/\"> https:\/\/habr.com\/ru\/post\/481544\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/481544\/\">\n<p><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/3564\/1*bqNylp7FcqIBWg0DrcimUw.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0426\u0435\u043b\u044c \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u0438\u0433\u0440\u0430\u0442\u044c \u0432 \u0438\u0433\u0440\u0443 &quot;\u0416\u0438\u0437\u043d\u044c&quot;, \u043d\u0435 \u043e\u0431\u0443\u0447\u0430\u044f \u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0438\u0433\u0440\u044b.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/kylewbanks.com\/blog\/conways-game-of-life-convolutional-neural-network-keras\">&quot;Using a Convolutional Neural Network to Play Conway&#8217;s Game of Life with Keras&quot;<\/a> \u0430\u0432\u0442\u043e\u0440\u0430 kylewbanks.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-296214","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/296214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=296214"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/296214\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=296214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=296214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=296214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}