{"id":290951,"date":"2018-10-17T20:15:02","date_gmt":"2018-10-17T16:15:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=290951"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=290951","title":{"rendered":"\u041d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c TensorFlow: \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\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:\/\/www.tensorflow.org\/tutorials\/keras\/basic_classification\">\u00abTrain your first neural network: basic classification\u00bb<\/a>.<\/p>\n<p>  \u042d\u0442\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043e\u0434\u0435\u0436\u0434\u044b, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043a\u0440\u043e\u0441\u0441\u043e\u0432\u043a\u0438 \u0438 \u0440\u0443\u0431\u0430\u0448\u043a\u0438. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c python \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 TensorFlow.<br \/>  <a name=\"habracut\"><\/a>   <\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 TensorFlow<\/h3>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<ol>\n<li> numpy (\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0438\u0448\u0435\u043c: pip install numpy)<\/li>\n<li> matplotlib (\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0438\u0448\u0435\u043c: pip install matplotlib)<\/li>\n<li> keras (\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0438\u0448\u0435\u043c: pip install keras) <\/li>\n<li> jupyter (\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0438\u0448\u0435\u043c: pip install jupyter) <\/li>\n<\/ol>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pip: \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0438\u0448\u0435\u043c pip install tensorflow<br \/>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/www.lfd.uci.edu\/~gohlke\/pythonlibs\/#tensorflow\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c .whl \u0444\u0430\u0439\u043b<\/a> \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pip: pip install \u043f\u0443\u0442\u044c_\u043a_\u0444\u0430\u0439\u043b\u0443\\\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435_\u0444\u0430\u0439\u043b\u0430.whl<\/p>\n<p>  <a href=\"https:\/\/www.tensorflow.org\/install\/\">\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 TensorFlow (\u043d\u0430 \u0430\u043d\u0433\u043b.)<\/a><br \/>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Jupyter. \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0438\u0448\u0435\u043c jupyter notebook.<\/p>\n<h3>\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u044b<\/h3>\n<p>  <\/p>\n<pre><code class=\"python\">#\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 import tensorflow as tf from tensorflow import keras import numpy as np import matplotlib.pyplot as plt <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 Fashion MNIST, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 70 000 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 \u043e\u0442\u0442\u0435\u043d\u043a\u0430\u0445 \u0441\u0435\u0440\u043e\u0433\u043e \u0432 10 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u0445. \u041d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u044b \u043e\u0434\u0435\u0436\u0434\u044b \u0441 \u043d\u0438\u0437\u043a\u0438\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c (28 \u043d\u0430 28 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439):<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/xl\/ei\/sx\/xleisxiszvqmubgj2f2zxzogej0.png\"\/><\/p>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c 60 000 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u0442\u0438 \u0438 10 000 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u043e\u0446\u0435\u043d\u0438\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0447\u043d\u043e \u0441\u0435\u0442\u044c \u043d\u0430\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a Fashion MNIST \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 TensorFlow, \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0432 \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"python\">fashion_mnist = keras.datasets.fashion_mnist (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() <\/code><\/pre>\n<p>  \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 NumPy:<\/p>\n<ol>\n<li> \u041c\u0430\u0441\u0441\u0438\u0432\u044b train_images \u0438 train_labels \u2014 \u044d\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f <\/li>\n<li> \u041c\u0430\u0441\u0441\u0438\u0432\u044b test_images \u0438 test_labels \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 <\/li>\n<\/ol>\n<p>  \u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 NumPy \u043c\u0430\u0441\u0441\u0438\u0432\u044b 28&#215;28, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 255. \u041c\u0435\u0442\u043a\u0438 (labels) \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 0 \u0434\u043e 9. \u041e\u043d\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043a\u043b\u0430\u0441\u0441\u0443 \u043e\u0434\u0435\u0436\u0434\u044b:<\/p>\n<table>\n<tr>\n<td>\u041c\u0435\u0442\u043a\u0430<\/td>\n<td>\u041a\u043b\u0430\u0441\u0441<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>T-shirt (\u0424\u0443\u0442\u0431\u043e\u043b\u043a\u0430)<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>Trouser (\u0411\u0440\u044e\u043a\u0438)<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td> Pullover (\u0421\u0432\u0438\u0442\u0435\u0440)<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Dress (\u041f\u043b\u0430\u0442\u044c\u0435)<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td> Coat (\u041f\u0430\u043b\u044c\u0442\u043e)<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>Sandal (\u0421\u0430\u043d\u0434\u0430\u043b\u0438)<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>&nbsp;Shirt (\u0420\u0443\u0431\u0430\u0448\u043a\u0430)<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>Sneaker (\u041a\u0440\u043e\u0441\u0441\u043e\u0432\u043a\u0438)<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>Bag (\u0421\u0443\u043c\u043a\u0430)<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>Ankle boot (\u0411\u043e\u0442\u0438\u043b\u044c\u043e\u043d\u044b)<\/td>\n<\/tr>\n<\/table>\n<p>  \u0418\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">class_names = ['T-shirt\/top', 'Trouser', 'Pullover', 'Dress', 'Coat',                 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] <\/code><\/pre>\n<p>  <\/p>\n<h3> \u0418\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <\/h3>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u043e\u0440\u043c\u0430\u0442 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0434 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438. <\/p>\n<pre><code class=\"python\">train_images.shape #\u0412 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f 60 000 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043a\u0430\u043a 28 x 28 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439  test_images.shape #\u0412 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f 10 000 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043a\u0430\u043a 28 x 28 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439  len(train_labels) #\u0412 \u0443\u0447\u0435\u0431\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 60 000 \u043c\u0435\u0442\u043e\u043a  len(test_labels) #\u0412 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 10 000 \u043c\u0435\u0442\u043e\u043a  train_labels #\u041a\u0430\u0436\u0434\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043e\u0442 0 \u0434\u043e 9 (\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u0435 3 \u043c\u0435\u0442\u043a\u0438 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 3 \u043c\u0435\u0442\u043a\u0438) <\/code><\/pre>\n<p>  <\/p>\n<h3> \u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <\/h3>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \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\u044b. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 255:<\/p>\n<pre><code class=\"python\">plt.figure() plt.imshow(train_images[0]) plt.colorbar() plt.grid(False) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/7f\/8l\/lb\/7f8llbgtwwhervtpbgiqq77x5j4.png\"\/><br \/>  \u041c\u044b \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u043e\u0442 0 \u0434\u043e 1:  <\/p>\n<pre><code class=\"python\">train_images = train_images \/ 255.0 test_images = test_images \/ 255.0 <\/code><\/pre>\n<p>  \u041e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0435 25 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438\u0437 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0438 \u043f\u043e\u043a\u0430\u0436\u0435\u043c \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c. \u0423\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435.<\/p>\n<pre><code class=\"python\">plt.figure(figsize=(10,10)) for i in range(25):     plt.subplot(5,5,i+1)     plt.xticks([])     plt.yticks([])     plt.grid(False)     plt.imshow(train_images[i], cmap=plt.cm.binary)     plt.xlabel(class_names[train_labels[i]]) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pw\/wl\/n6\/pwwln6kfnvjidpgyix61kcoudpc.png\"\/><\/p>\n<h3> \u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 <\/h3>\n<p>  \u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u043b\u043e\u0435\u0432 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0431\u043b\u043e\u043a\u043e\u043c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0439. \u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u043e\u0435\u0432. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0435\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a tf.keras.layers.Dense, \u0438\u043c\u0435\u044e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">model = keras.Sequential([     keras.layers.Flatten(input_shape=(28, 28)),     keras.layers.Dense(128, activation=tf.nn.relu),     keras.layers.Dense(10, activation=tf.nn.softmax) ]) <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043b\u043e\u0439 \u0432 \u0441\u0435\u0442\u0438 tf.keras.layers.Flatten \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0444\u043e\u0440\u043c\u0430\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438\u0437 2d-\u043c\u0430\u0441\u0441\u0438\u0432\u0430 (28 \u043d\u0430 28 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439) \u0432 1d-\u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 28 * 28 = 784 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439. \u0423 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u043d\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f, \u043e\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435. <\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0432\u0430 \u0441\u043b\u043e\u044f \u044d\u0442\u043e tf.keras.layers.Dense. \u042d\u0442\u043e \u043f\u043b\u043e\u0442\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0438\u043b\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u043b\u043e\u0438. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043b\u043e\u0439 Dense \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 128 \u0443\u0437\u043b\u043e\u0432 (\u0438\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432). \u0412\u0442\u043e\u0440\u043e\u0439 (\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439) \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u2014 \u044d\u0442\u043e \u0441\u043b\u043e\u0439 \u0441 10 \u0443\u0437\u043b\u0430\u043c\u0438 tf.nn.softmax, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 \u0434\u0435\u0441\u044f\u0442\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u044b\u0445 \u043e\u0446\u0435\u043d\u043e\u043a, \u0441\u0443\u043c\u043c\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0432\u043d\u0430 1. \u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0446\u0435\u043d\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 10 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<h3>\u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/h3>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u0430 \u043a \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e, \u0435\u0439 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a. \u041e\u043d\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u044d\u0442\u0430\u043f\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438:<\/p>\n<ul>\n<li> Loss function (\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u0438) \u2014 \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0447\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/li>\n<li> Optimizer (\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440) \u2014 \u044d\u0442\u043e \u0442\u043e, \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0430 \u0432\u0438\u0434\u0438\u0442, \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u0438<\/li>\n<li> Metrics (\u043c\u0435\u0442\u0440\u0438\u043a\u0438) \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0437\u0430 \u044d\u0442\u0430\u043f\u0430\u043c\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"python\">model.compile(optimizer=tf.train.AdamOptimizer(),                loss='sparse_categorical_crossentropy',               metrics=['accuracy']) <\/code><\/pre>\n<p>  <\/p>\n<h3>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/h3>\n<p>  \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0448\u0430\u0433\u043e\u0432:<\/p>\n<ol>\n<li> \u041f\u043e\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 (\u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2014 \u043c\u0430\u0441\u0441\u0438\u0432\u044b train_images \u0438 train_labels) <\/li>\n<li> \u041c\u043e\u0434\u0435\u043b\u044c \u0443\u0447\u0438\u0442\u0441\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u043c\u0435\u0442\u043a\u0438 <\/li>\n<li> \u041c\u044b \u043f\u0440\u043e\u0441\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 (\u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 test_images). \u041c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u043a \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043c\u0435\u0442\u043e\u043a (\u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 test_labels) <\/li>\n<\/ol>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435, \u0432\u044b\u0437\u043e\u0432\u0438\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 model.fit:<\/p>\n<pre><code class=\"python\">model.fit(train_images, train_labels, epochs=5) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/wi\/ys\/qj\/wiysqjlya8tocuimzlpebxwgjuu.png\"\/><\/p>\n<p>  \u041f\u0440\u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043f\u043e\u0442\u0435\u0440\u044c (loss) \u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 (acc). \u042d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u043a\u043e\u043b\u043e 0,88 (\u0438\u043b\u0438 88%) \u043f\u043e \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<h3> \u041e\u0446\u0435\u043d\u043a\u0430 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438<\/h3>\n<p>  \u0421\u0440\u0430\u0432\u043d\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">test_loss, test_acc = model.evaluate(test_images, test_labels) print('Test accuracy:', test_acc) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/zl\/6n\/b1\/zl6nb1vueyzp26zsqavpipuoir4.png\"\/><\/p>\n<p>  \u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0432 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435. \u042d\u0442\u043e\u0442 \u0440\u0430\u0437\u0440\u044b\u0432 \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0445\u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0447\u0435\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<h3> \u041f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <\/h3>\n<p>   \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"python\">predictions = model.predict(test_images) <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043b\u0430 \u043c\u0435\u0442\u043a\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">predictions[0] <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/6f\/i3\/wp\/6fi3wpwdebetyalfzzwjkoequum.png\"\/><\/p>\n<p>  \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 10 \u0447\u0438\u0441\u0435\u043b. \u041e\u043d\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u00ab\u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u00bb \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437 10 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043e\u0432 \u043e\u0434\u0435\u0436\u0434\u044b. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0434\u043e\u0432\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">np.argmax(predictions[0]) #9 <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u2014 Ankle boot (\u0411\u043e\u0442\u0438\u043b\u044c\u043e\u043d\u044b), \u0438\u043b\u0438 class_names [9]. \u0418 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u043c\u0435\u0442\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"python\">test_labels[0]  #9 <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439<\/p>\n<pre><code class=\"python\">def plot_image(i, predictions_array, true_label, img):   predictions_array, true_label, img = predictions_array[i], true_label[i], img[i]   plt.grid(False)   plt.xticks([])   plt.yticks([])      plt.imshow(img, cmap=plt.cm.binary)    predicted_label = np.argmax(predictions_array)   if predicted_label == true_label:     color = 'blue'   else:     color = 'red'      plt.xlabel(&quot;{} {:2.0f}% ({})&quot;.format(class_names[predicted_label],                                 100*np.max(predictions_array),                                 class_names[true_label]),                                 color=color)  def plot_value_array(i, predictions_array, true_label):   predictions_array, true_label = predictions_array[i], true_label[i]   plt.grid(False)   plt.xticks([])   plt.yticks([])   thisplot = plt.bar(range(10), predictions_array, color=&quot;#777777&quot;)   plt.ylim([0, 1])    predicted_label = np.argmax(predictions_array)     thisplot[predicted_label].set_color('red')   thisplot[true_label].set_color('blue') <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 0-\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439.<\/p>\n<pre><code class=\"python\">i = 0 plt.figure(figsize=(6,3)) plt.subplot(1,2,1) plot_image(i, predictions, test_labels, test_images) plt.subplot(1,2,2) plot_value_array(i, predictions,  test_labels) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/4u\/ti\/om\/4utiomn2fn76nidyyrbppgeuwx0.png\"\/><\/p>\n<p>  \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u0438\u0445 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430\u043c\u0438. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430 \u2014 \u0441\u0438\u043d\u0438\u0435, \u0430 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430 \u2014 \u043a\u0440\u0430\u0441\u043d\u044b\u0435. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0434\u0430\u0436\u0435 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043e\u0447\u0435\u043d\u044c \u0443\u0432\u0435\u0440\u0435\u043d.<\/p>\n<pre><code class=\"python\">num_rows = 5 num_cols = 3 num_images = num_rows*num_cols plt.figure(figsize=(2*2*num_cols, 2*num_rows)) for i in range(num_images):   plt.subplot(num_rows, 2*num_cols, 2*i+1)   plot_image(i, predictions, test_labels, test_images)   plt.subplot(num_rows, 2*num_cols, 2*i+2)   plot_value_array(i, predictions, test_labels) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ot\/9n\/zs\/ot9nzsbnvbnkibec8blv5xvcg0g.png\"\/><\/p>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043e\u0431 \u043e\u0434\u043d\u043e\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"python\"># \u0412\u043e\u0437\u044c\u043c\u0451\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 img = test_images[0] <\/code><\/pre>\n<p>  \u041c\u043e\u0434\u0435\u043b\u0438 tf.keras \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u044b \u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u044b (batch) \u0438\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 (collection). \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0445\u043e\u0442\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0434\u043d\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<pre><code class=\"python\">#\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043a\u0435\u0442, \u0433\u0434\u0435 \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0447\u043b\u0435\u043d\u043e\u043c img = (np.expand_dims (img, 0)) <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0433\u043d\u043e\u0437 \u0434\u043b\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">predictions_single = model.predict(img) print(predictions_single) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/wb\/ld\/we\/wbldwexgmyhxevj9oeinj7tjq9i.png\"\/><\/p>\n<pre><code class=\"python\">plot_value_array(0, predictions_single, test_labels) _ = plt.xticks(range(10), class_names, rotation=45) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/zt\/ts\/kt\/zttsktrkmknnvpcpnfq9x8hbrym.png\"\/><\/p>\n<pre><code class=\"python\">np.argmax(predictions_single[0]) <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043a\u0443 9.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0438\u043b\u0438 \u0432 \u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p><\/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\/post\/426797\/\"> https:\/\/habr.com\/post\/426797\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\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:\/\/www.tensorflow.org\/tutorials\/keras\/basic_classification\">\u00abTrain your first neural network: basic classification\u00bb<\/a>.<\/p>\n<p>  \u042d\u0442\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043e\u0434\u0435\u0436\u0434\u044b, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043a\u0440\u043e\u0441\u0441\u043e\u0432\u043a\u0438 \u0438 \u0440\u0443\u0431\u0430\u0448\u043a\u0438. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c python \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 TensorFlow.  <\/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-290951","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290951","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=290951"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290951\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=290951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=290951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=290951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}