{"id":285285,"date":"2017-04-20T15:15:05","date_gmt":"2017-04-20T11:15:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=285285"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=285285","title":{"rendered":"\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f: Keras"},"content":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u044b \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043f\u0440\u043e <a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/323272\/\">Theano<\/a> \u0438 <a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/324898\/\">Tensorflow<\/a> (\u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e \u0447\u0442\u043e \u0435\u0449\u0435), \u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e Keras.<br \/>  \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e Keras \u0432\u044b\u0440\u043e\u0441 \u043a\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043d\u0430\u0434 Theano. \u041e\u0442\u0441\u044e\u0434\u0430 \u0438 \u0435\u0433\u043e \u0433\u0440\u0435\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u043c\u044f \u2014 \u03ba\u03ad\u03c1\u03b1\u03c2, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 &quot;\u0440\u043e\u0433&quot; \u043f\u043e-\u0433\u0440\u0435\u0447\u0435\u0441\u043a\u0438, \u0447\u0442\u043e, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u044b\u043b\u043a\u043e\u0439 \u043a \u041e\u0434\u0438\u0441\u0441\u0435\u0435 \u0413\u043e\u043c\u0435\u0440\u0430. \u0425\u043e\u0442\u044f, \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440 \u0443\u0442\u0435\u043a\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u043e\u0434\u044b, \u0438 Keras \u0441\u0442\u0430\u043b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c Tensorflow, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438 \u0432\u043e\u0432\u0441\u0435 \u0441\u0442\u0430\u043b \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u044c\u044e. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u043d\u0430\u0448 \u0440\u0430\u0441\u0441\u043a\u0430\u0437 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0443\u0434\u044c\u0431\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u0430 \u0435\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/68f\/fc1\/d69\/68ffc1d69c10d1ede103288c779c8f4e.jpg\" alt=\"image\" \/><\/div>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041d\u0430\u0447\u0430\u0442\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0442 \u043f\u0435\u0447\u043a\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0441 \u043e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<ul>\n<li>[\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430]<\/li>\n<li>[\u0411\u044d\u043a\u0435\u043d\u0434\u044b]<\/li>\n<li>[\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440]<br \/> \n<ul>\n<li>[\u0414\u0430\u043d\u043d\u044b\u0435]<\/li>\n<li>[\u041c\u043e\u0434\u0435\u043b\u044c]<br \/> \n<ul>\n<li>[Sequential API]<\/li>\n<li>[Functional API]<\/li>\n<\/ul>\n<\/li>\n<li>[\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a \u0440\u0430\u0431\u043e\u0442\u0435]<\/li>\n<li>[Custom loss]<\/li>\n<li>[\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435]<\/li>\n<li>[Callbacks]<br \/> \n<ul>\n<li>[Tensorboard]<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>[\u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0433\u0440\u0430\u0444\u044b]<\/li>\n<li>[\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435]<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"ustanovka\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/h2>\n<p>  <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Keras \u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430, \u0442.\u043a. \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u043c \u043f\u0430\u043a\u0435\u0442\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">pip install keras<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0435\u0433\u043e \u0440\u0430\u0437\u0431\u043e\u0440\u0443, \u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e \u0431\u044d\u043a\u0435\u043d\u0434\u044b.<br \/>  <strong>\u0412\u041d\u0418\u041c\u0410\u041d\u0418\u0415:<\/strong> \u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Keras, \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0438\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u2014 Theano \u0438\u043b\u0438 Tensorflow.<\/p>\n<p>  <\/p>\n<h2 id=\"bekendy\">\u0411\u044d\u043a\u0435\u043d\u0434\u044b<\/h2>\n<p>  <\/p>\n<p>\u0411\u044d\u043a\u0435\u043d\u0434\u044b \u2014 \u044d\u0442\u043e \u0442\u043e, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e Keras \u0441\u0442\u0430\u043b \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d (\u043f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u043e\u0447\u0438\u0445 \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043d\u0438\u0436\u0435). Keras \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u044d\u043a\u0435\u043d\u0434\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u0430\u043c\u0438 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u0431\u044d\u043a\u0435\u043d\u0434\u0430. \u041d\u0430\u0447\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430, \u043a\u0430\u043a \u043c\u044b \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438, \u0441 Theano, \u043d\u043e \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f Tensorflow. \u0421\u0435\u0439\u0447\u0430\u0441 Keras \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u043d\u0438\u043c, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Theano, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 keras.json, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0436\u0438\u0442 \u043f\u043e \u043f\u0443\u0442\u0438 <code>$HOME\/.keras\/keras.json<\/code> (\u0438\u043b\u0438 <code>%USERPROFILE%\\.keras\\keras.json<\/code> \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0430 Windows). \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0435 <code>backend<\/code>:<br \/> \n<pre><code>{ &quot;image_data_format&quot;: &quot;channels_last&quot;, &quot;epsilon&quot;: 1e-07, &quot;floatx&quot;: &quot;float32&quot;, &quot;backend&quot;: &quot;theano&quot; }<\/code><\/pre>\n<\/li>\n<li>\u0412\u0442\u043e\u0440\u043e\u0439 \u043f\u0443\u0442\u044c \u2014 \u044d\u0442\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>KERAS_BACKEND<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a:<br \/> \n<pre><code class=\"bash\">KERAS_BACKEND=theano python -c &quot;from keras import backend&quot; Using Theano backend.<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u0435\u0434\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u043e\u0432 \u0434\u043b\u044f CNTK \u043e\u0442 Microsoft, \u0442\u0430\u043a \u0447\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0431\u044d\u043a\u0435\u043d\u0434. \u0421\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u044d\u0442\u0438\u043c \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/github.com\/Microsoft\/CNTK\/issues\/797\">\u0437\u0434\u0435\u0441\u044c<\/a>. <\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 <a href=\"https:\/\/github.com\/dmlc\/mxnet\/issues\/4173\">MXNet Keras backend<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0432\u0441\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 MXNet, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0415\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 <a href=\"https:\/\/github.com\/transcranial\/keras-js\">Keras.js<\/a>, \u0434\u0430\u044e\u0449\u0438\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0430\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 Keras \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430\u0445, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c GPU.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u0431\u044d\u043a\u0435\u043d\u0434\u044b Keras \u0448\u0438\u0440\u044f\u0442\u0441\u044f \u0438 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0437\u0430\u0445\u0432\u0430\u0442\u044f\u0442 \u043c\u0438\u0440! (\u041d\u043e \u044d\u0442\u043e \u043d\u0435\u0442\u043e\u0447\u043d\u043e.)<\/p>\n<p>  <\/p>\n<h2 id=\"prakticheskiy-primer\">\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u044b\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043c\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0431\u044b\u043b\u043e \u0443\u0434\u0435\u043b\u0435\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445. \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0437\u044f\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 [\u043d\u0435 \u043e\u0447\u0435\u043d\u044c] \u0433\u043b\u0443\u0431\u043e\u043a\u0443\u044e \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c.<\/p>\n<p>  <\/p>\n<h3 id=\"dannye\">\u0414\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/740\/39f\/eda\/74039feda6fca05afd8419cd1c8d6071.png\" \/><\/div>\n<p>  <\/p>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0434\u0430\u043d\u043d\u044b\u0445. Keras \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432, \u043d\u043e \u043e\u043d\u0438 \u0443\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0432 \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u043e\u0440\u043c\u0443 \u0438 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u044e \u043c\u043e\u0449\u044c Keras. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u044b\u0440\u043e\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 20 newsgroups \u2014 20 \u0442\u044b\u0441\u044f\u0447 \u043d\u043e\u0432\u043e\u0441\u0442\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u0437 \u0433\u0440\u0443\u043f\u043f Usenet (\u044d\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0431\u043c\u0435\u043d\u0430 \u043f\u043e\u0447\u0442\u043e\u0439 \u0440\u043e\u0434\u043e\u043c \u0438\u0437 1990-\u0445, \u0440\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f FIDO, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0447\u0443\u0442\u044c \u043b\u0443\u0447\u0448\u0435 \u0437\u043d\u0430\u043a\u043e\u043c \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e) \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u0440\u043e\u0432\u043d\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u043e 20 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u043c. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u0441\u0435\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e \u044d\u0442\u0438\u043c \u043d\u043e\u0432\u043e\u0441\u0442\u043d\u044b\u043c \u0433\u0440\u0443\u043f\u043f\u0430\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from sklearn.datasets import fetch_20newsgroups newsgroups_train = fetch_20newsgroups(subset='train') newsgroups_test = fetch_20newsgroups(subset='test')<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438: <\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">newsgroups_train[&#39;data&#39;][0]<\/b><\/p>\n<div class=\"spoiler_text\">\n<p>From: lerxst@wam.umd.edu (where&#8217;s my thing)<br \/>  Subject: WHAT car is this!?<br \/>  Nntp-Posting-Host: rac3.wam.umd.edu<br \/>  Organization: University of Maryland, College Park<br \/>  Lines: 15<\/p>\n<p>  <\/p>\n<p>I was wondering if anyone out there could enlighten me on this car I saw<br \/>  the other day. It was a 2-door sports car, looked to be from the late 60s\/<br \/>  early 70s. It was called a Bricklin. The doors were really small. In addition,<br \/>  the front bumper was separate from the rest of the body. This is<br \/>  all I know. If anyone can tellme a model name, engine specs, years<br \/>  of production, where this car is made, history, or whatever info you<br \/>  have on this funky looking car, please e-mail.<\/p>\n<p>  <\/p>\n<p>Thanks,<\/p>\n<p>  <\/p>\n<ul>\n<li>IL<br \/>   \u2014 brought to you by your neighborhood Lerxst &#8212;-<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p>  <\/p>\n<h3 id=\"preprocessing\">\u041f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433<\/h3>\n<p>  <\/p>\n<p>Keras \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432, \u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0438\u0445 \u043d\u0430 \u0442\u043e\u043a\u0435\u043d\u044b \u0438 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0432 \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">tokenizer = Tokenizer(num_words=max_words) tokenizer.fit_on_texts(newsgroups_train[&quot;data&quot;])  # \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440 \u0437\u043d\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0440\u043f\u0443\u0441\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432  x_train = tokenizer.texts_to_matrix(newsgroups_train[&quot;data&quot;], mode='binary') x_test = tokenizer.texts_to_matrix(newsgroups_test[&quot;data&quot;], mode='binary')<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432: <\/p>\n<p>  <\/p>\n<pre><code>x_train shape: (11314, 1000) x_test shape: (7532, 1000)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0435, \u0430 \u0432\u0442\u043e\u0440\u043e\u0435 \u2014 \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f (\u043e\u0434\u043d\u0430 \u0442\u044b\u0441\u044f\u0447\u0430 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435).<br \/>  \u0415\u0449\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043a \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u043e\u043c\u0443 \u0432\u0438\u0434\u0443 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 one-hot \u0432\u0435\u043a\u0442\u043e\u0440, \u0442.\u0435. \u0432\u0435\u043a\u0442\u043e\u0440, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u043d\u0443\u043b\u0435\u0439 \u0438 \u043e\u0434\u043d\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">y_train = keras.utils.to_categorical(newsgroups_train[&quot;target&quot;], num_classes) y_test = keras.utils.to_categorical(newsgroups_test[&quot;target&quot;], num_classes)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0430\u043a\u0436\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code>y_train shape: (11314, 20) y_test shape: (7532, 20)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u044d\u0442\u0438\u0445 \u043c\u0430\u0442\u0440\u0438\u0446 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 \u2014 \u0447\u0438\u0441\u043b\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445), \u0430 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u2014 \u043d\u0435\u0442. \u041f\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u0441\u0442\u043e\u0438\u0442 \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (20, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430).<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u0441\u0435\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0441\u0442\u0438!<\/p>\n<p>  <\/p>\n<h3 id=\"model\">\u041c\u043e\u0434\u0435\u043b\u044c<\/h3>\n<p>  <\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0432 Keras \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0432\u0443\u043c\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<h4 id=\"sequential-api\">Sequential API<\/h4>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u2014 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">model = Sequential() model.add(Dense(512, input_shape=(max_words,))) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(num_classes)) model.add(Activation('softmax'))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">model = Sequential([           Dense(512, input_shape=(max_words,)),           Activation('relu'),           Dropout(0.5),           Dense(num_classes),           Activation('softmax')         ])<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"functional-api\">Functional API<\/h4>\n<p>  <\/p>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0437\u0430\u0434 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 API \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u2014 \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">a = Input(shape=(max_words,)) b = Dense(512)(a) b = Activation('relu')(b) b = Dropout(0.5)(b) b = Dense(num_classes)(b) b = Activation('softmax')(b) model = Model(inputs=a, outputs=b)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043d\u0435\u0442, \u0432\u044b\u0431\u0438\u0440\u0430\u0439\u0442\u0435, \u043a\u0430\u043a\u043e\u0439 \u0432\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e \u0434\u0443\u0448\u0435.<br \/>  \u041a\u043b\u0430\u0441\u0441 <code>Model<\/code> (\u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 \u043d\u0435\u0433\u043e <code>Sequential<\/code>) \u0438\u043c\u0435\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0441\u043b\u043e\u0438 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u2014 <code>model.layers<\/code>, \u0432\u0445\u043e\u0434\u044b \u2014 <code>model.inputs<\/code>, \u0438 \u0432\u044b\u0445\u043e\u0434\u044b \u2014 <code>model.outputs<\/code>.<br \/>  \u0422\u0430\u043a\u0436\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u2014 <code>model.to_yaml<\/code>.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438.<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>backend: tensorflow class_name: Model config:   input_layers:   - [input_4, 0, 0]   layers:   - class_name: InputLayer     config:       batch_input_shape: !!python\/tuple [null, 1000]       dtype: float32       name: input_4       sparse: false     inbound_nodes: []     name: input_4   - class_name: Dense     config:       activation: linear       activity_regularizer: null       bias_constraint: null       bias_initializer:         class_name: Zeros         config: {}       bias_regularizer: null       kernel_constraint: null       kernel_initializer:         class_name: VarianceScaling         config: {distribution: uniform, mode: fan_avg, scale: 1.0, seed: null}       kernel_regularizer: null       name: dense_10       trainable: true       units: 512       use_bias: true     inbound_nodes:     - - - input_4         - 0         - 0         - {}     name: dense_10   - class_name: Activation     config: {activation: relu, name: activation_9, trainable: true}     inbound_nodes:     - - - dense_10         - 0         - 0         - {}     name: activation_9   - class_name: Dropout     config: {name: dropout_5, rate: 0.5, trainable: true}     inbound_nodes:     - - - activation_9         - 0         - 0         - {}     name: dropout_5   - class_name: Dense     config:       activation: linear       activity_regularizer: null       bias_constraint: null       bias_initializer:         class_name: Zeros         config: {}       bias_regularizer: null       kernel_constraint: null       kernel_initializer:         class_name: VarianceScaling         config: {distribution: uniform, mode: fan_avg, scale: 1.0, seed: null}       kernel_regularizer: null       name: dense_11       trainable: true       units: !!python\/object\/apply:numpy.core.multiarray.scalar       - !!python\/object\/apply:numpy.dtype         args: [i8, 0, 1]         state: !!python\/tuple [3, &lt;, null, null, null, -1, -1, 0]       - !!binary |         FAAAAAAAAAA=       use_bias: true     inbound_nodes:     - - - dropout_5         - 0         - 0         - {}     name: dense_11   - class_name: Activation     config: {activation: softmax, name: activation_10, trainable: true}     inbound_nodes:     - - - dense_11         - 0         - 0         - {}     name: activation_10   name: model_1   output_layers:   - [activation_10, 0, 0] keras_version: 2.0.2<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e-\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c \u0432\u0438\u0434\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from keras.models import model_from_yaml  yaml_string = model.to_yaml() model = model_from_yaml(yaml_string)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u0430\u044f \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u0432\u0438\u0434\u0435 (\u043a\u0441\u0442\u0430\u0442\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0436\u0435 \u0438 \u0432 JSON) \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0435\u0441\u043e\u0432. \u0414\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432\u0435\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>save_weights<\/code> \u0438 <code>load_weights<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>  <\/p>\n<h3 id=\"vizualizaciya-modeli\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438<\/h3>\n<p>  <\/p>\n<p>\u041d\u0435\u043b\u044c\u0437\u044f \u043e\u0431\u043e\u0439\u0442\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. Keras \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from keras.utils import plot_model plot_model(model, to_file='model.png', show_shapes=True)<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u043f\u043e\u0434 \u0438\u043c\u0435\u043d\u0435\u043c <code>model.png<\/code> \u0432\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443:<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/f93\/a8d\/d5f\/f93a8dd5f0d64105ab2335595136d176.png\" \/><\/div>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432\u0445\u043e\u0434\u043e\u0432 \u0438 \u0432\u044b\u0445\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0441\u043b\u043e\u0435\u0432. <code>None<\/code>, \u0438\u0434\u0443\u0449\u0438\u0439 \u043f\u0435\u0440\u0432\u044b\u043c \u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0442\u0447\u0430. \u0422.\u043a. \u0441\u0442\u043e\u0438\u0442 <code>None<\/code>, \u0442\u043e \u0431\u0430\u0442\u0447 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0435\u0435 \u0432 <code>jupyter<\/code>-\u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435, \u0432\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from IPython.display import SVG from keras.utils.vis_utils import model_to_dot  SVG(model_to_dot(model, show_shapes=True).create(prog='dot', format='svg'))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u0435\u043d \u043f\u0430\u043a\u0435\u0442 <a href=\"http:\/\/www.graphviz.org\/\">graphviz<\/a>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0439 \u043f\u0430\u043a\u0435\u0442 <code>pydot<\/code>. \u0415\u0441\u0442\u044c \u0442\u043e\u043d\u043a\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u043a\u0435\u0442 <code>pydot<\/code> \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043d\u0435 \u043f\u043e\u0439\u0434\u0435\u0442, \u043d\u0443\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e <code>pydot-ng<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">pip install pydot-ng<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0430\u043a\u0435\u0442 <code>graphviz<\/code> \u0432 Ubuntu \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u0442\u0430\u043a (\u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0430\u0445 Linux \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e):<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">apt install graphviz<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430 MacOS (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 HomeBrew):<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">brew install graphviz<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0430 Windows \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"http:\/\/www.graphviz.org\/Download_windows.php\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<h3 id=\"podgotovka-modeli-k-rabote\">\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a \u0440\u0430\u0431\u043e\u0442\u0435<\/h3>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0435\u0435 \u043a \u0440\u0430\u0431\u043e\u0442\u0435: <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">model.compile(loss='categorical_crossentropy',               optimizer='adam',               metrics=['accuracy'])<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>compile<\/code>? <code>loss<\/code> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u0430\u044f \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044f, \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0435 \u043c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0438 \u043d\u0430\u0448\u0438 \u043c\u0435\u0442\u043a\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0442\u0440\u0438\u0446; <code>optimizer<\/code> \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440, \u0437\u0434\u0435\u0441\u044c \u043c\u043e\u0433 \u0431\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a, \u043d\u043e Adam \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043b\u0443\u0447\u0448\u0443\u044e \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435; <code>metrics<\/code> \u2014 \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u044d\u0442\u043e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c (accuracy), \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u043e\u043b\u044f \u0432\u0435\u0440\u043d\u043e \u0443\u0433\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<h3 id=\"custom-loss\">Custom loss<\/h3>\n<p>  <\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e Keras \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435. \u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>loss<\/code>, \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e: \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445<br \/>  \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u0432\u044b\u0434\u0430\u044e\u0449\u0443\u044e \u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e \u043d\u0430 \u0432\u044b\u0445\u043e\u0434. \u0414\u043b\u044f \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u043f\u0435\u0440\u0435\u043a\u0440\u0435\u0441\u0442\u043d\u043e\u0439 \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438. \u0427\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u0447\u0435\u043c-\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u043b\u0430\u0441\u044c, \u0432\u0432\u0435\u0434\u0435\u043c \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 clipping \u2014 \u043e\u0431\u0440\u0435\u0437\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u0432\u0435\u0440\u0445\u0443 \u0438 \u0441\u043d\u0438\u0437\u0443. \u0414\u0430, \u0435\u0449\u0435 \u0432\u0430\u0436\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>loss<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0435\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 Keras.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from keras import backend as K  epsilon = 1.0e-9 def custom_objective(y_true, y_pred):     '''Yet another cross-entropy'''     y_pred = K.clip(y_pred, epsilon, 1.0 - epsilon)     y_pred \/= K.sum(y_pred, axis=-1, keepdims=True)     cce = categorical_crossentropy(y_pred, y_true)     return cce<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c <code>y_true<\/code> \u0438 <code>y_pred<\/code> \u2014 \u0442\u0435\u043d\u0437\u043e\u0440\u044b \u0438\u0437 Tensorflow, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Tensorflow.<br \/>  \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>loss<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>compile<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0442\u0443\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c (\u0432 \u043f\u0438\u0442\u043e\u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u0442\u043e\u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f):<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">model.compile(loss=custom_objective,               optimizer='adam',               metrics=['accuracy'])<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"obuchenie-i-testirovanie\">\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">history = model.fit(x_train, y_train,                     batch_size=batch_size,                     epochs=epochs,                     verbose=1,                     validation_split=0.1)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>fit<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043c\u0435\u0442\u043a\u0430\u043c\u0438 \u2014 <code>x_train<\/code> \u0438 <code>y_train<\/code>, \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0431\u0430\u0442\u0447\u0430 <code>batch_size<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043f\u043e\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0437\u0430 \u0440\u0430\u0437, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u044d\u043f\u043e\u0445 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f <code>epochs<\/code> (\u043e\u0434\u043d\u0430 \u044d\u043f\u043e\u0445\u0430 \u2014 \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0435\u043c, \u043a\u0430\u043a\u0443\u044e \u0434\u043e\u043b\u044e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043e\u0442\u0434\u0430\u0442\u044c \u043f\u043e\u0434 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u2014 <code>validation_split<\/code>.<br \/>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 <code>history<\/code> \u2014 \u044d\u0442\u043e \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u041c\u0435\u0442\u043e\u0434 <code>evaluate<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043c\u0435\u0442\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u043d\u0435\u0435. \u041c\u0435\u0442\u0440\u0438\u043a\u0430 \u0431\u044b\u043b\u0430 \u0437\u0430\u0434\u0430\u043d\u0430 \u0435\u0449\u0435 \u043f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u043a \u0440\u0430\u0431\u043e\u0442\u0435, \u0442\u0430\u043a \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e. (\u041d\u043e \u043c\u044b \u0443\u043a\u0430\u0436\u0435\u043c \u0435\u0449\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430).<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">score = model.evaluate(x_test, y_test, batch_size=batch_size)<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"callbacks\">Callbacks<\/h3>\n<p>  <\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0432 \u043e \u0442\u0430\u043a\u043e\u0439 \u0432\u0430\u0436\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 Keras, \u043a\u0430\u043a \u043a\u043e\u043b\u0431\u0435\u043a\u0438. \u0427\u0435\u0440\u0435\u0437 \u043d\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u0442\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u0442\u0435 \u0441\u0435\u0442\u044c \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0440\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043b\u0430 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c\u0441\u044f. \u041f\u043e-\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f &quot;early stopping&quot; (&quot;\u0440\u0430\u043d\u043d\u044f\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430&quot;). \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u0430\u0448\u0435\u0439 \u0441\u0435\u0442\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from keras.callbacks import EarlyStopping   early_stopping=EarlyStopping(monitor='value_loss')    history = model.fit(x_train, y_train,                     batch_size=batch_size,                     epochs=epochs,                     verbose=1,                     validation_split=0.1,                     callbacks=[early_stopping])<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0438\u0442\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 early stopping \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435?<\/p>\n<p>  <\/p>\n<h4 id=\"tensorboard\">Tensorboard<\/h4>\n<p>  <\/p>\n<p>\u0415\u0449\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u043b\u0431\u0435\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0434\u043b\u044f Tensorboard (\u043e \u043d\u0435\u043c \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440 \u0431\u044b\u043b \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e Tensorflow, \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u043b\u043e\u0433\u043e\u0432 Tensorflow).<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from keras.callbacks import TensorBoard   tensorboard=TensorBoard(log_dir='.\/logs', write_graph=True)  history = model.fit(x_train, y_train,                     batch_size=batch_size,                     epochs=epochs,                     verbose=1,                     validation_split=0.1,                     callbacks=[tensorboard])<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f (\u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435!), \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <code>Tensorboard<\/code>, \u0443\u043a\u0430\u0437\u0430\u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441 \u043b\u043e\u0433\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">tensorboard --logdir=\/path\/to\/logs<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u043c\u0435\u043d\u044f\u043b\u0441\u044f <code>loss<\/code> \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d17\/209\/d25\/d17209d255384483ae77a4a78f9cf062.png\" alt=\"image\"\/><br \/>  (\u041a\u0441\u0442\u0430\u0442\u0438, \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0441\u0435\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f.)<\/p>\n<p>  <\/p>\n<h2 id=\"prodvinutye-grafy\">\u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0433\u0440\u0430\u0444\u044b<\/h2>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u0423 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0434\u043e\u0432 \u0438 \u0432\u044b\u0445\u043e\u0434\u043e\u0432, \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438. \u0414\u043b\u044f \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0433\u0440\u0430\u0444\u043e\u0432 (\u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0434\u043b\u044f <code>transfer learning<\/code>) \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a \u043d\u043e\u0432\u044b\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043a\u0443\u0441\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438. <\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u044f \u043e\u0431\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u2014 <code>Functional API<\/code> \u0438 <code>Sequential API<\/code>, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u043d\u0435\u0435.<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 Siamese Network. \u0421\u0445\u043e\u0436\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439, \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439 \u043b\u0438\u0446 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440, \u0447\u0442\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u043b\u0438\u0446 \u0431\u0443\u0434\u0443\u0442 \u0431\u043b\u0438\u0437\u043a\u043e \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a FindFace.<\/p>\n<p>  <\/p>\n<p>\u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"http:\/\/datasciencelatam.com\/wp-content\/uploads\/2017\/02\/siamese2.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>G<\/code> \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0434\u043b\u044f \u043f\u0430\u0440\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a. \u0415\u0441\u043b\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0442\u0430\u043a\u0430\u044f \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0430, \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 <code>G(x)<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043b\u0438\u0431\u043e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043b\u0438\u0431\u043e \u043a\u0430\u043a \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. <\/p>\n<p>  <\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043a\u043e\u0434\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0432 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0438.<\/p>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430 Keras \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0443\u044e \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440.<\/p>\n<p>  <\/p>\n<pre><code>def create_base_network(input_dim):     seq = Sequential()     seq.add(Dense(128, input_shape=(input_dim,), activation='relu'))     seq.add(Dropout(0.1))     seq.add(Dense(128, activation='relu'))     seq.add(Dropout(0.1))     seq.add(Dense(128, activation='relu'))     return seq<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>Sequential API<\/code>, \u043e\u0434\u043d\u0430\u043a\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u0432\u044b\u0437\u0432\u0430\u0432 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>Functional API<\/code> \u043a\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c:<\/p>\n<p>  <\/p>\n<pre><code>base_network = create_base_network(input_dim)  input_a = Input(shape=(input_dim,)) input_b = Input(shape=(input_dim,))  processed_a = base_network(input_a) processed_b = base_network(input_b)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <code>processed_a<\/code> \u0438 <code>processed_b<\/code> \u043b\u0435\u0436\u0430\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u0443\u0442\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0435\u0442\u0438, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u043d\u0435\u0435, \u043a \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c.<br \/>  \u041d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 Keras \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043e\u0431\u0435\u0440\u0442\u043a\u0430 <code>Lambda<\/code>, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u043b\u044e\u0431\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u043a \u0441\u043b\u043e\u0439 (<code>Layer<\/code>). \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0430\u0442\u0447\u0430\u0445, \u0442\u0430\u043a \u0447\u0442\u043e \u0443 \u0432\u0441\u0435\u0445 \u0442\u0435\u043d\u0437\u043e\u0440\u043e\u0432 \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0430\u044f \u0437\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430. <\/p>\n<p>  <\/p>\n<pre><code>from keras import backend as K  def euclidean_distance(vects):     x, y = vects     return K.sqrt(K.sum(K.square(x - y), axis=1, keepdims=True))  distance = Lambda(euclidean_distance)([processed_a, processed_b])<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044b \u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u043e\u0434\u043d\u0443 \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<p>  <\/p>\n<pre><code>model = Model([input_a, input_b], distance)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>base_network<\/code> \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438. \u041a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c? \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043b\u043e\u0438 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<p>  <\/p>\n<pre><code>&gt;&gt;&gt; model.layers [&lt;keras.engine.topology.InputLayer object at 0x7f238fdacb38&gt;, &lt;keras.engine.topology.InputLayer object at 0x7f238fdc34a8&gt;, &lt;keras.models.Sequential object at 0x7f239127c3c8&gt;, &lt;keras.layers.core.Lambda object at 0x7f238fddc4a8&gt;]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0438\u0434\u0438\u043c \u0442\u0440\u0435\u0442\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0442\u0438\u043f\u0430 <code>models.Sequential<\/code>. \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0430\u044f \u0432\u0445\u043e\u0434\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440. \u0427\u0442\u043e\u0431\u044b \u0435\u0435 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c (\u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c, \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0433\u0440\u0430\u0444) \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0435\u0435 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u043b\u043e\u0435\u0432:<\/p>\n<p>  <\/p>\n<pre><code>&gt;&gt;&gt; embedding_model = model.layers[2] &gt;&gt;&gt; embedding_model.layers [&lt;keras.layers.core.Dense object at 0x7f23c4e557f0&gt;, &lt;keras.layers.core.Dropout object at 0x7f238fe97908&gt;, &lt;keras.layers.core.Dense object at 0x7f238fe44898&gt;, &lt;keras.layers.core.Dropout object at 0x7f238fe449e8&gt;, &lt;keras.layers.core.Dense object at 0x7f238fe01f60&gt;]<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0443\u0436\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 MNIST \u0441\u0438\u0430\u043c\u0441\u043a\u043e\u0439 \u0441\u0435\u0442\u0438 \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 <code>base_model<\/code>, \u0440\u0430\u0432\u043d\u043e\u0439 \u0434\u0432\u0443\u043c, \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 <code>28x28<\/code> \u043a \u043f\u043b\u043e\u0441\u043a\u0438\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c.<\/p>\n<p>  <\/p>\n<pre><code>(x_train, y_train), (x_test, y_test) = mnist.load_data() x_test = x_test.reshape(10000, 784)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u043d\u0435\u0435 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<p>  <\/p>\n<pre><code>embeddings = embedding_model.predict(x_test)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 <code>embeddings<\/code> \u043b\u0435\u0436\u0430\u0442 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438:<br \/>  <img decoding=\"async\" src=\"http:\/\/i.imgur.com\/rdKz9lN.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0438\u0430\u043c\u0441\u043a\u043e\u0439 \u0441\u0435\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c <a href=\"https:\/\/github.com\/fchollet\/keras\/blob\/master\/examples\/mnist_siamese_graph.py\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435, \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 Keras! \u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0438 \u0432\u0430\u0441, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435. <\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b Keras. \u041a \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u043f\u043b\u044e\u0441\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u0432\u0442\u043e\u0440\u044b \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/325096\/\">\u043f\u0440\u043e \u0441\u043f\u0443\u0442\u043d\u0438\u043a\u0438<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0438\u043c\u0435\u043d\u043d\u043e Keras. \u0412 \u0446\u0435\u043b\u043e\u043c \u044d\u0442\u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u0441\u0435 \u0431\u043e\u043b\u0435\u0435 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c:<br \/>  <img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*8a2Nz2SnCgT9UFl7rSaywg.png\" alt=\"image\"\/><br \/>  Keras \u0437\u0430 \u0433\u043e\u0434 \u0434\u043e\u0433\u043d\u0430\u043b Torch, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 5 \u043b\u0435\u0442, \u0441\u0443\u0434\u044f \u043f\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u044f\u043c \u0432 \u043d\u0430\u0443\u0447\u043d\u044b\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445. \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0441\u0432\u043e\u0435\u0439 \u0446\u0435\u043b\u0438 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u0424\u0440\u0430\u043d\u0441\u0443\u0430 \u0428\u043e\u043b\u043b\u0435 (Fran\u00e7ois Chollet, \u0430\u0432\u0442\u043e\u0440 Keras) \u0434\u043e\u0431\u0438\u043b\u0441\u044f. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u0442\u0438\u0432\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u043d\u0435\u0437\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0439: \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f Google \u043f\u0440\u0438\u0433\u043b\u0430\u0441\u0438\u043b\u0430 \u0435\u0433\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u044d\u0442\u0438\u043c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435, \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0435\u0439 Tensorflow. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Tensorflow 1.2 Keras \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 TF (tf.keras).<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u0434\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430\u0445. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0438\u0434\u0435\u044f Keras \u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430: Keras 2.0 \u043f\u043e\u043b\u043e\u043c\u0430\u043b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043b\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u0435\u0445\u0430\u043b\u0438, \u0432 \u043e\u0431\u0449\u0435\u043c, \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u0438\u0439 python. \u041e\u0442\u043b\u0438\u0447\u0438\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 Keras \u0431\u044b\u043b\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f. \u0422\u0430\u043a\u0436\u0435 \u043a\u043e\u0434 Keras \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 Tensorflow \u043f\u043e\u043a\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u043d\u0430 Theano (\u0445\u043e\u0442\u044f \u0434\u043b\u044f \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, <a href=\"https:\/\/arxiv.org\/abs\/1511.06435\">\u0441\u0440\u0430\u0432\u043d\u0438\u043c\u044b<\/a>).<\/p>\n<p>  <\/p>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u0442\u044c Keras \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0432\u0435\u0449\u0438, \u0432\u0440\u043e\u0434\u0435 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0438\u043b\u0438 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e GPU, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 (\u0430 \u043f\u043e\u0434\u0447\u0430\u0441 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0438\u0436\u0435\u043b\u0435\u0436\u0430\u0449\u0438\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u0435\u0441\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0430 <a href=\"https:\/\/gist.github.com\/madrugado\/63c068b52a135c6fdbbb6fe17acbc0c8\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0422\u0430\u043a\u0436\u0435 \u043e\u0447\u0435\u043d\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c \u0432\u0430\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e Keras: <a href=\"http:\/\/keras.io\">keras.io<\/a>, \u0430 \u0442\u0430\u043a \u0436\u0435 <a href=\"https:\/\/github.com\/fchollet\/keras\/tree\/master\/examples\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/a>, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0432 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0441 <a href=\"https:\/\/habrahabr.ru\/users\/wordbearer\/\" class=\"user_link\">Wordbearer<\/a>.<\/p>\n<p> \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:\/\/habrahabr.ru\/post\/325432\/\"> https:\/\/habrahabr.ru\/post\/325432\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u044b \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043f\u0440\u043e <a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/323272\/\">Theano<\/a> \u0438 <a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/324898\/\">Tensorflow<\/a> (\u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e \u0447\u0442\u043e \u0435\u0449\u0435), \u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e Keras.<br \/>  \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e Keras \u0432\u044b\u0440\u043e\u0441 \u043a\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043d\u0430\u0434 Theano. \u041e\u0442\u0441\u044e\u0434\u0430 \u0438 \u0435\u0433\u043e \u0433\u0440\u0435\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u043c\u044f \u2014 \u03ba\u03ad\u03c1\u03b1\u03c2, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 &quot;\u0440\u043e\u0433&quot; \u043f\u043e-\u0433\u0440\u0435\u0447\u0435\u0441\u043a\u0438, \u0447\u0442\u043e, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0441\u044b\u043b\u043a\u043e\u0439 \u043a \u041e\u0434\u0438\u0441\u0441\u0435\u0435 \u0413\u043e\u043c\u0435\u0440\u0430. \u0425\u043e\u0442\u044f, \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440 \u0443\u0442\u0435\u043a\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u043e\u0434\u044b, \u0438 Keras \u0441\u0442\u0430\u043b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c Tensorflow, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438 \u0432\u043e\u0432\u0441\u0435 \u0441\u0442\u0430\u043b \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u044c\u044e. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u043d\u0430\u0448 \u0440\u0430\u0441\u0441\u043a\u0430\u0437 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0443\u0434\u044c\u0431\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u0430 \u0435\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/68f\/fc1\/d69\/68ffc1d69c10d1ede103288c779c8f4e.jpg\" alt=\"image\" \/><\/div>\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-285285","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285285","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=285285"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285285\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}