{"id":938162,"date":"2024-12-26T20:06:19","date_gmt":"2024-12-26T12:06:19","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/938162.html"},"modified":"2024-12-26T20:06:21","modified_gmt":"2024-12-26T12:06:21","slug":"python%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8mnist","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/938162.html","title":{"rendered":"python\u5982\u4f55\u4f7f\u7528mnist"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073729\/2c95a69c-490d-4022-bcb2-288f46e70010.webp\" alt=\"python\u5982\u4f55\u4f7f\u7528mnist\" \/><\/p>\n<p><p> <strong>Python\u4f7f\u7528MNIST\u6570\u636e\u96c6\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Keras\u5e93\u52a0\u8f7dMNIST\u6570\u636e\u96c6\u3001\u901a\u8fc7TensorFlow\u52a0\u8f7dMNIST\u6570\u636e\u96c6\u3001\u4ece\u7f51\u4e0a\u624b\u52a8\u4e0b\u8f7d\u5e76\u52a0\u8f7dMNIST\u6570\u636e\u96c6\u3002<\/strong> \u5176\u4e2d\uff0c<strong>\u4f7f\u7528Keras\u5e93\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/strong>\u662f\u6700\u7b80\u5355\u548c\u76f4\u63a5\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3aKeras\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684MNIST\u6570\u636e\u96c6\u52a0\u8f7d\u529f\u80fd\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5bfc\u5165\u548c\u4f7f\u7528\u3002Keras\u5c06\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\uff0c\u5e76\u5c06\u5176\u683c\u5f0f\u5316\u4e3a\u9002\u5408<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u6a21\u578b\u8f93\u5165\u7684\u5f62\u5f0f\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528Python\u52a0\u8f7d\u548c\u64cd\u4f5cMNIST\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001Keras\u5e93\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/h3>\n<\/p>\n<p><p>Keras\u662f\u4e00\u4e2a\u9ad8\u5c42\u795e\u7ecf\u7f51\u7edcAPI\uff0c\u8fd0\u884c\u5728TensorFlow\u4e4b\u4e0a\u3002\u5b83\u4f7f\u5f97\u52a0\u8f7d\u548c\u4f7f\u7528MNIST\u6570\u636e\u96c6\u53d8\u5f97\u975e\u5e38\u7b80\u5355\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Keras\u52a0\u8f7dMNIST\u6570\u636e\u96c6\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165\u5e93\u548c\u52a0\u8f7d\u6570\u636e\u96c6<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u5bfc\u5165Keras\u5e93\u4e2d\u7684<code>datasets<\/code>\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>mnist.load_data()<\/code>\u51fd\u6570\u52a0\u8f7d\u6570\u636e\u96c6\u3002\u52a0\u8f7d\u540e\uff0c\u6570\u636e\u96c6\u88ab\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from keras.datasets import mnist<\/p>\n<h2><strong>\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/strong><\/h2>\n<p>(x_tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n, y_train), (x_test, y_test) = mnist.load_data()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u9884\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p>\u52a0\u8f7d\u7684\u6570\u636e\u9700\u8981\u8fdb\u884c\u9884\u5904\u7406\uff0c\u5305\u62ec\u5f52\u4e00\u5316\u548c\u5f62\u72b6\u8c03\u6574\u3002MNIST\u6570\u636e\u96c6\u4e2d\u6bcf\u4e2a\u56fe\u50cf\u662f28&#215;28\u7684\u7070\u5ea6\u56fe\uff0c\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\uff0c\u5e76\u5c06\u50cf\u7d20\u503c\u7f29\u653e\u52300\u52301\u4e4b\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x_train = x_train.astype(&#39;float32&#39;) \/ 255<\/p>\n<p>x_test = x_test.astype(&#39;float32&#39;) \/ 255<\/p>\n<h2><strong>\u5c06\u6807\u7b7e\u8f6c\u6362\u4e3aone-hot\u7f16\u7801<\/strong><\/h2>\n<p>from keras.utils import to_categorical<\/p>\n<p>y_train = to_categorical(y_train, 10)<\/p>\n<p>y_test = to_categorical(y_test, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6784\u5efa\u548c\u8bad\u7ec3\u6a21\u578b<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Keras\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u7b80\u5355\u7684\u5168\u8fde\u63a5\u7f51\u7edc\uff08Dense layers\uff09\u6765\u8bad\u7ec3\u6a21\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from keras.models import Sequential<\/p>\n<p>from keras.layers import Dense, Flatten<\/p>\n<p>model = Sequential([<\/p>\n<p>    Flatten(input_shape=(28, 28)),<\/p>\n<p>    Dense(128, activation=&#39;relu&#39;),<\/p>\n<p>    Dense(10, activation=&#39;softmax&#39;)<\/p>\n<p>])<\/p>\n<h2><strong>\u7f16\u8bd1\u6a21\u578b<\/strong><\/h2>\n<p>model.compile(optimizer=&#39;adam&#39;,<\/p>\n<p>              loss=&#39;categorical_crossentropy&#39;,<\/p>\n<p>              metrics=[&#39;accuracy&#39;])<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bc4\u4f30\u6a21\u578b\u6027\u80fd<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u6d4b\u8bd5\u96c6\u4e0a\u8bc4\u4f30\u6a21\u578b\u6027\u80fd\uff0c\u67e5\u770b\u51c6\u786e\u7387\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">test_loss, test_accuracy = model.evaluate(x_test, y_test)<\/p>\n<p>print(&#39;Test accuracy:&#39;, test_accuracy)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u901a\u8fc7TensorFlow\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/h3>\n<\/p>\n<p><p>TensorFlow\u4e5f\u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff0c\u76f4\u63a5\u652f\u6301MNIST\u6570\u636e\u96c6\u7684\u52a0\u8f7d\u3002\u4ee5\u4e0b\u662f\u901a\u8fc7TensorFlow\u52a0\u8f7dMNIST\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165TensorFlow\u548c\u52a0\u8f7d\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p>TensorFlow\u63d0\u4f9b\u4e86<code>tensorflow.keras.datasets<\/code>\u6a21\u5757\uff0c\u53ef\u4ee5\u76f4\u63a5\u52a0\u8f7dMNIST\u6570\u636e\u96c6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<h2><strong>\u4f7f\u7528TensorFlow\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/strong><\/h2>\n<p>(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u6b65\u9aa4\u4e0eKeras\u52a0\u8f7d\u65b9\u5f0f\u7c7b\u4f3c\uff0c\u56e0\u4e3aTensorFlow\u4e2d\u7684Keras\u6a21\u5757\u4e0e\u72ec\u7acb\u7684Keras\u5e93\u975e\u5e38\u76f8\u4f3c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u9884\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p>\u540c\u6837\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u5f52\u4e00\u5316\u548c\u6807\u7b7e\u7684one-hot\u7f16\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x_train = x_train.astype(&#39;float32&#39;) \/ 255<\/p>\n<p>x_test = x_test.astype(&#39;float32&#39;) \/ 255<\/p>\n<p>y_train = tf.keras.utils.to_categorical(y_train, 10)<\/p>\n<p>y_test = tf.keras.utils.to_categorical(y_test, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6784\u5efa\u548c\u8bad\u7ec3TensorFlow\u6a21\u578b<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528TensorFlow\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">model = tf.keras.Sequential([<\/p>\n<p>    tf.keras.layers.Flatten(input_shape=(28, 28)),<\/p>\n<p>    tf.keras.layers.Dense(128, activation=&#39;relu&#39;),<\/p>\n<p>    tf.keras.layers.Dense(10, activation=&#39;softmax&#39;)<\/p>\n<p>])<\/p>\n<p>model.compile(optimizer=&#39;adam&#39;,<\/p>\n<p>              loss=&#39;categorical_crossentropy&#39;,<\/p>\n<p>              metrics=[&#39;accuracy&#39;])<\/p>\n<p>model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bc4\u4f30\u6a21\u578b<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u6d4b\u8bd5\u6570\u636e\u96c6\u8fdb\u884c\u8bc4\u4f30\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">test_loss, test_accuracy = model.evaluate(x_test, y_test)<\/p>\n<p>print(&#39;Test accuracy:&#39;, test_accuracy)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u624b\u52a8\u4e0b\u8f7d\u5e76\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4e0d\u60f3\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u52a0\u8f7d\u6570\u636e\u96c6\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u624b\u52a8\u4e0b\u8f7d\u548c\u52a0\u8f7dMNIST\u6570\u636e\u96c6\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u5bf9\u6570\u636e\u8fdb\u884c\u81ea\u5b9a\u4e49\u9884\u5904\u7406\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u6570\u636e\u96c6<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4ece<a href=\"http:\/\/yann.lecun.com\/exdb\/mnist\/\">MNIST\u6570\u636e\u5e93\u5b98\u7f51<\/a>\u4e0b\u8f7d\u56db\u4e2a\u6587\u4ef6\uff1a\u8bad\u7ec3\u56fe\u50cf\u3001\u8bad\u7ec3\u6807\u7b7e\u3001\u6d4b\u8bd5\u56fe\u50cf\u3001\u6d4b\u8bd5\u6807\u7b7e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bfb\u53d6\u548c\u89e3\u6790\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Python\u8bfb\u53d6\u4e8c\u8fdb\u5236\u6587\u4ef6\u5e76\u89e3\u6790\u4e3aNumPy\u6570\u7ec4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def load_mnist_images(filename):<\/p>\n<p>    with open(filename, &#39;rb&#39;) as f:<\/p>\n<p>        f.read(16)  # \u8df3\u8fc7\u5934\u90e8\u4fe1\u606f<\/p>\n<p>        data = np.frombuffer(f.read(), dtype=np.uint8)<\/p>\n<p>        return data.reshape(-1, 28, 28)<\/p>\n<p>def load_mnist_labels(filename):<\/p>\n<p>    with open(filename, &#39;rb&#39;) as f:<\/p>\n<p>        f.read(8)  # \u8df3\u8fc7\u5934\u90e8\u4fe1\u606f<\/p>\n<p>        labels = np.frombuffer(f.read(), dtype=np.uint8)<\/p>\n<p>        return labels<\/p>\n<p>x_train = load_mnist_images(&#39;train-images-idx3-ubyte&#39;)<\/p>\n<p>y_train = load_mnist_labels(&#39;train-labels-idx1-ubyte&#39;)<\/p>\n<p>x_test = load_mnist_images(&#39;t10k-images-idx3-ubyte&#39;)<\/p>\n<p>y_test = load_mnist_labels(&#39;t10k-labels-idx1-ubyte&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u9884\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p>\u5bf9\u624b\u52a8\u52a0\u8f7d\u7684\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x_train = x_train.astype(&#39;float32&#39;) \/ 255<\/p>\n<p>x_test = x_test.astype(&#39;float32&#39;) \/ 255<\/p>\n<p>from tensorflow.keras.utils import to_categorical<\/p>\n<p>y_train = to_categorical(y_train, 10)<\/p>\n<p>y_test = to_categorical(y_test, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6784\u5efa\u548c\u8bad\u7ec3\u6a21\u578b<\/strong><\/p>\n<\/p>\n<p><p>\u4e0e\u524d\u8ff0Keras\u548cTensorFlow\u65b9\u6cd5\u76f8\u540c\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u4efb\u610f\u6846\u67b6\u6765\u6784\u5efa\u548c\u8bad\u7ec3\u6a21\u578b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001MNIST\u6570\u636e\u96c6\u5e94\u7528\u4e0e\u6269\u5c55<\/h3>\n<\/p>\n<p><p>MNIST\u6570\u636e\u96c6\u662f\u4e00\u4e2a\u5165\u95e8\u7ea7\u7684\u6570\u636e\u96c6\uff0c\u867d\u7136\u7b80\u5355\uff0c\u4f46\u5b83\u5728\u673a\u5668\u5b66\u4e60\u548c\u6df1\u5ea6\u5b66\u4e60\u7814\u7a76\u4e2d\u5177\u6709\u6781\u5927\u7684\u5f71\u54cd\u529b\u3002\u9664\u4e86\u57fa\u672c\u7684\u5206\u7c7b\u95ee\u9898\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528MNIST\u8fdb\u884c\u5176\u4ed6\u6269\u5c55\u7814\u7a76\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u56fe\u50cf\u751f\u6210<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u751f\u6210\u5bf9\u6297\u7f51\u7edc\uff08GANs\uff09\u6765\u751f\u6210\u65b0\u7684\u624b\u5199\u6570\u5b57\u56fe\u50cf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u56fe\u50cf\u964d\u566a<\/strong><\/p>\n<\/p>\n<p><p>\u8bad\u7ec3\u53bb\u566a\u81ea\u7f16\u7801\u5668\u6765\u53bb\u9664\u624b\u5199\u6570\u5b57\u56fe\u50cf\u4e2d\u7684\u566a\u58f0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fc1\u79fb\u5b66\u4e60<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u9884\u8bad\u7ec3\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u8fdb\u884c\u8fc1\u79fb\u5b66\u4e60\uff0c\u4ee5\u63d0\u9ad8\u5206\u7c7b\u6027\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e0d\u540c\u6a21\u578b\u7684\u6bd4\u8f83<\/strong><\/p>\n<\/p>\n<p><p>\u6d4b\u8bd5\u4e0d\u540c\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\uff08\u5982SVM\u3001\u968f\u673a\u68ee\u6797\uff09\u5728MNIST\u6570\u636e\u96c6\u4e0a\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5728Python\u4e2d\u6210\u529f\u52a0\u8f7d\u548c\u4f7f\u7528MNIST\u6570\u636e\u96c6\uff0c\u5e76\u8fdb\u884c\u5404\u79cd\u673a\u5668\u5b66\u4e60\u548c\u6df1\u5ea6\u5b66\u4e60\u5b9e\u9a8c\u3002\u65e0\u8bba\u662f\u521d\u5b66\u8005\u8fd8\u662f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u7814\u7a76\u4eba\u5458\uff0cMNIST\u90fd\u662f\u4e00\u4e2a\u7406\u60f3\u7684\u5b9e\u9a8c\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u52a0\u8f7dMNIST\u6570\u636e\u96c6\uff1f<\/strong><br \/>\u5728Python\u4e2d\u52a0\u8f7dMNIST\u6570\u636e\u96c6\u901a\u5e38\u4f7f\u7528<code>keras<\/code>\u5e93\u6216<code>tensorflow<\/code>\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u8f7b\u677e\u52a0\u8f7d\u6570\u636e\u96c6\uff1a  <\/p>\n<pre><code class=\"language-python\">from keras.datasets import mnist\n(X_train, y_train), (X_test, y_test) = mnist.load_data()\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5f97\u5230\u8bad\u7ec3\u548c\u6d4b\u8bd5\u6570\u636e\uff0c<code>X_train<\/code>\u548c<code>X_test<\/code>\u5305\u542b\u56fe\u50cf\u6570\u636e\uff0c\u800c<code>y_train<\/code>\u548c<code>y_test<\/code>\u5219\u5305\u542b\u5bf9\u5e94\u7684\u6807\u7b7e\u3002<\/p>\n<p><strong>\u4f7f\u7528MNIST\u6570\u636e\u96c6\u8fdb\u884c\u6a21\u578b\u8bad\u7ec3\u7684\u6700\u4f73\u5b9e\u8df5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728\u4f7f\u7528MNIST\u6570\u636e\u96c6\u8fdb\u884c\u6a21\u578b\u8bad\u7ec3\u65f6\uff0c\u5efa\u8bae\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\uff0c\u5305\u62ec\u5f52\u4e00\u5316\u56fe\u50cf\u6570\u636e\u52300\u52301\u4e4b\u95f4\uff0c\u4ee5\u53ca\u5c06\u6807\u7b7e\u8fdb\u884c\u72ec\u70ed\u7f16\u7801\u3002\u6b64\u5916\uff0c\u91c7\u7528\u9002\u5f53\u7684\u6a21\u578b\u67b6\u6784\uff0c\u5982\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\uff0c\u80fd\u591f\u663e\u8457\u63d0\u9ad8\u5206\u7c7b\u51c6\u786e\u7387\u3002\u540c\u65f6\uff0c\u4f7f\u7528\u4ea4\u53c9\u9a8c\u8bc1\u53ef\u4ee5\u5e2e\u52a9\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n<p><strong>\u5982\u4f55\u8bc4\u4f30\u4f7f\u7528MNIST\u6570\u636e\u96c6\u8bad\u7ec3\u7684\u6a21\u578b\u7684\u6548\u679c\uff1f<\/strong><br \/>\u8bc4\u4f30\u6a21\u578b\u6548\u679c\u7684\u5e38\u7528\u65b9\u6cd5\u662f\u8ba1\u7b97\u5206\u7c7b\u51c6\u786e\u7387\u3002\u53ef\u4ee5\u4f7f\u7528<code>sklearn<\/code>\u5e93\u4e2d\u7684<code>accuracy_score<\/code>\u51fd\u6570\u6765\u8bc4\u4f30\u3002\u9664\u4e86\u51c6\u786e\u7387\uff0c\u6df7\u6dc6\u77e9\u9635\u3001\u7cbe\u786e\u7387\u3001\u53ec\u56de\u7387\u7b49\u6307\u6807\u4e5f\u662f\u975e\u5e38\u6709\u7528\u7684\u8bc4\u4f30\u6807\u51c6\u3002\u901a\u8fc7\u53ef\u89c6\u5316\u6df7\u6dc6\u77e9\u9635\uff0c\u53ef\u4ee5\u66f4\u76f4\u89c2\u5730\u4e86\u89e3\u6a21\u578b\u5728\u5404\u7c7b\u4e0a\u7684\u8868\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4f7f\u7528MNIST\u6570\u636e\u96c6\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Keras\u5e93\u52a0\u8f7dMNIST\u6570\u636e\u96c6\u3001\u901a\u8fc7TensorFlow\u52a0\u8f7d [&hellip;]","protected":false},"author":3,"featured_media":938166,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/938162"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=938162"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/938162\/revisions"}],"predecessor-version":[{"id":938167,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/938162\/revisions\/938167"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/938166"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=938162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=938162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=938162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}