{"id":1173799,"date":"2025-01-15T17:08:12","date_gmt":"2025-01-15T09:08:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1173799.html"},"modified":"2025-01-15T17:08:17","modified_gmt":"2025-01-15T09:08:17","slug":"python-%e5%a6%82%e4%bd%95%e5%af%bc%e5%85%a5mnist%e6%95%b0%e6%8d%ae%e9%9b%86","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1173799.html","title":{"rendered":"python \u5982\u4f55\u5bfc\u5165mnist\u6570\u636e\u96c6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26075510\/2a6adf3d-aa9a-483b-9014-1055ee426e9b.webp\" alt=\"python \u5982\u4f55\u5bfc\u5165mnist\u6570\u636e\u96c6\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>tensorflow<\/code>\u5e93\u5bfc\u5165MNIST\u6570\u636e\u96c6\u3001\u4f7f\u7528<code>keras<\/code>\u5e93\u5bfc\u5165MNIST\u6570\u636e\u96c6\u3001\u4f7f\u7528<code>scikit-learn<\/code>\u5e93\u5bfc\u5165MNIST\u6570\u636e\u96c6\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528<code>tensorflow<\/code>\u5e93\u5bfc\u5165MNIST\u6570\u636e\u96c6\u662f\u6700\u5e38\u7528\u7684\u4e00\u79cd\u65b9\u6cd5\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528<code>tensorflow<\/code>\u5e93\u5bfc\u5165MNIST\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u5bfc\u5165MNIST\u6570\u636e\u96c6\uff0c\u4f60\u9700\u8981\u5148\u5b89\u88c5TensorFlow\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install tensorflow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5bfc\u5165MNIST\u6570\u636e\u96c6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<h2><strong>\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/strong><\/h2>\n<p>mnist = tf.keras.datasets.mnist<\/p>\n<h2><strong>\u5c06\u6570\u636e\u96c6\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\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<h2><strong>\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\uff0c\u5c06\u50cf\u7d20\u503c\u4ece0-255\u538b\u7f29\u52300-1\u4e4b\u95f4<\/strong><\/h2>\n<p>x_train, x_test = x_train \/ 255.0, x_test \/ 255.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u6210\u529f\u5bfc\u5165\u4e86MNIST\u6570\u636e\u96c6\u5e76\u5c06\u5176\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\uff0c\u540c\u65f6\u5bf9\u6570\u636e\u8fdb\u884c\u4e86\u6807\u51c6\u5316\u5904\u7406\uff0c\u4f7f\u5f97\u50cf\u7d20\u503c\u57280\u52301\u4e4b\u95f4\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528<code>tensorflow<\/code>\u5e93\u5bfc\u5165MNIST\u6570\u636e\u96c6\u4ee5\u53ca\u5176\u4ed6\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528TensorFlow\u5bfc\u5165MNIST\u6570\u636e\u96c6<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528TensorFlow\u5bfc\u5165MNIST\u6570\u636e\u96c6\u4e4b\u524d\uff0c\u9700\u8981\u5148\u4e86\u89e3MNIST\u6570\u636e\u96c6\u7684\u57fa\u672c\u60c5\u51b5\u3002MNIST\u6570\u636e\u96c6\u753170000\u5f20\u624b\u5199\u6570\u5b57\u7684\u7070\u5ea6\u56fe\u50cf\u7ec4\u6210\uff0c\u5176\u4e2d60000\u5f20\u7528\u4e8e\u8bad\u7ec3\uff0c10000\u5f20\u7528\u4e8e\u6d4b\u8bd5\u3002\u6bcf\u5f20\u56fe\u50cf\u7684\u5927\u5c0f\u4e3a28&#215;28\u50cf\u7d20\uff0c\u50cf\u7d20\u503c\u8303\u56f4\u4e3a0\u5230255\uff0c\u6807\u7b7e\u4e3a0\u52309\u7684\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5bfc\u5165\u6570\u636e\u96c6<\/h4>\n<\/p>\n<p><p>\u5982\u524d\u6240\u8ff0\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5bfc\u5165MNIST\u6570\u636e\u96c6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<h2><strong>\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/strong><\/h2>\n<p>mnist = tf.keras.datasets.mnist<\/p>\n<h2><strong>\u5c06\u6570\u636e\u96c6\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/strong><\/h2>\n<p>(x_train, y_train), (x_test, y_test) = mnist.load_data()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6570\u636e\u9884\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u6a21\u578b\u7684\u8bad\u7ec3\u6548\u679c\uff0c\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\u3002\u5e38\u89c1\u7684\u9884\u5904\u7406\u65b9\u6cd5\u5305\u62ec\u6807\u51c6\u5316\u3001\u6570\u636e\u589e\u5f3a\u7b49\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u50cf\u7d20\u503c\u4ece0-255\u538b\u7f29\u52300-1\u4e4b\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406<\/p>\n<p>x_train, x_test = x_train \/ 255.0, x_test \/ 255.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u6784\u5efa\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u5728\u5bfc\u5165\u5e76\u9884\u5904\u7406MNIST\u6570\u636e\u96c6\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528TensorFlow\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Keras\u6784\u5efa\u7684\u7b80\u5355\u6a21\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">model = tf.keras.models.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.Dropout(0.2),<\/p>\n<p>    tf.keras.layers.Dense(10, activation=&#39;softmax&#39;)<\/p>\n<p>])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u7f16\u8bd1\u548c\u8bad\u7ec3\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u7f16\u8bd1\u6a21\u578b\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u635f\u5931\u51fd\u6570\u3001\u4f18\u5316\u5668\u548c\u8bc4\u4f30\u6307\u6807\u3002\u4ee5\u4e0b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u7f16\u8bd1\u548c\u8bad\u7ec3\u6a21\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">model.compile(optimizer=&#39;adam&#39;,<\/p>\n<p>              loss=&#39;sparse_categorical_crossentropy&#39;,<\/p>\n<p>              metrics=[&#39;accuracy&#39;])<\/p>\n<p>model.fit(x_train, y_train, epochs=5)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5\u3001\u8bc4\u4f30\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u5728\u8bad\u7ec3\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6d4b\u8bd5\u96c6\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">model.evaluate(x_test, y_test)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Keras\u5bfc\u5165MNIST\u6570\u636e\u96c6<\/h3>\n<\/p>\n<p><p>Keras\u662f\u4e00\u4e2a\u9ad8\u5c42\u6b21\u7684\u795e\u7ecf\u7f51\u7edcAPI\uff0c\u80fd\u591f\u8fd0\u884c\u5728TensorFlow\u3001Theano\u548cCNTK\u4e4b\u4e0a\u3002Keras\u4e5f\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u63a5\u53e3\u6765\u5bfc\u5165MNIST\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5bfc\u5165\u6570\u636e\u96c6<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5bfc\u5165MNIST\u6570\u636e\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_train, y_train), (x_test, y_test) = mnist.load_data()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6570\u636e\u9884\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u4e0eTensorFlow\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x_train, x_test = x_train \/ 255.0, x_test \/ 255.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u6784\u5efa\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Keras\u6784\u5efa\u6a21\u578b\u7684\u4ee3\u7801\u4e0eTensorFlow\u7684\u4ee3\u7801\u975e\u5e38\u76f8\u4f3c\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, Dropout<\/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>    Dropout(0.2),<\/p>\n<p>    Dense(10, activation=&#39;softmax&#39;)<\/p>\n<p>])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u7f16\u8bd1\u548c\u8bad\u7ec3\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u7f16\u8bd1\u548c\u8bad\u7ec3\u6a21\u578b\u65f6\uff0c\u4e5f\u9700\u8981\u6307\u5b9a\u635f\u5931\u51fd\u6570\u3001\u4f18\u5316\u5668\u548c\u8bc4\u4f30\u6307\u6807\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">model.compile(optimizer=&#39;adam&#39;,<\/p>\n<p>              loss=&#39;sparse_categorical_crossentropy&#39;,<\/p>\n<p>              metrics=[&#39;accuracy&#39;])<\/p>\n<p>model.fit(x_train, y_train, epochs=5)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5\u3001\u8bc4\u4f30\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u8bc4\u4f30\u6a21\u578b\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">model.evaluate(x_test, y_test)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Scikit-learn\u5bfc\u5165MNIST\u6570\u636e\u96c6<\/h3>\n<\/p>\n<p><p>Scikit-learn\u662f\u4e00\u4e2a\u6d41\u884c\u7684<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u5de5\u5177\u6765\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\u3001\u6a21\u578b\u6784\u5efa\u548c\u8bc4\u4f30\u3002Scikit-learn\u4e5f\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u63a5\u53e3\u6765\u5bfc\u5165MNIST\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5bfc\u5165\u6570\u636e\u96c6<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5bfc\u5165MNIST\u6570\u636e\u96c6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.datasets import fetch_openml<\/p>\n<h2><strong>\u52a0\u8f7dMNIST\u6570\u636e\u96c6<\/strong><\/h2>\n<p>mnist = fetch_openml(&#39;mnist_784&#39;, version=1)<\/p>\n<p>x, y = mnist[&quot;data&quot;], mnist[&quot;target&quot;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6570\u636e\u9884\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u4e0eTensorFlow\u548cKeras\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = x \/ 255.0<\/p>\n<p>y = y.astype(int)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5212\u5206\u6570\u636e\u96c6<\/h4>\n<\/p>\n<p><p>\u5c06\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.model_selection import train_test_split<\/p>\n<p>x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u6784\u5efa\u6a21\u578b<\/h4>\n<\/p>\n<p><p>Scikit-learn\u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u7684\u6a21\u578b\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4f7f\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u968f\u673a\u68ee\u6797\u5206\u7c7b\u5668\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.ensemble import RandomForestClassifier<\/p>\n<p>model = RandomForestClassifier(n_estimators=100, random_state=42)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5\u3001\u8bad\u7ec3\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u8bad\u7ec3\u96c6\u8bad\u7ec3\u6a21\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">model.fit(x_train, y_train)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>6\u3001\u8bc4\u4f30\u6a21\u578b<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u6d4b\u8bd5\u96c6\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.metrics import accuracy_score<\/p>\n<p>y_pred = model.predict(x_test)<\/p>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>print(f&quot;Accuracy: {accuracy:.4f}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u4e09\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u6765\u5bfc\u5165MNIST\u6570\u636e\u96c6\uff1a\u4f7f\u7528TensorFlow\u3001Keras\u548cScikit-learn\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u4e2a\u4eba\u504f\u597d\u3002\u603b\u7684\u6765\u8bf4\uff0c<strong>TensorFlow\u548cKeras\u63d0\u4f9b\u4e86\u66f4\u9ad8\u5c42\u6b21\u7684API\uff0c\u66f4\u9002\u5408\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u7684\u6784\u5efa\u548c\u8bad\u7ec3\uff0c\u800cScikit-learn\u5219\u63d0\u4f9b\u4e86\u66f4\u591a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u7684\u5b9e\u73b0\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5bfc\u5165\u548c\u5904\u7406MNIST\u6570\u636e\u96c6\uff1a\u5bfc\u5165\u6570\u636e\u96c6\u3001\u6570\u636e\u9884\u5904\u7406\u3001\u5212\u5206\u6570\u636e\u96c6\u3001\u6784\u5efa\u6a21\u578b\u3001\u8bad\u7ec3\u6a21\u578b\u548c\u8bc4\u4f30\u6a21\u578b\u3002\u8fd9\u4e9b\u6b65\u9aa4\u662f\u673a\u5668\u5b66\u4e60\u548c\u6df1\u5ea6\u5b66\u4e60\u9879\u76ee\u7684\u57fa\u672c\u6d41\u7a0b\uff0c\u638c\u63e1\u8fd9\u4e9b\u6b65\u9aa4\u5bf9\u4e8e\u5f00\u5c55\u5404\u79cd\u673a\u5668\u5b66\u4e60\u9879\u76ee\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u60a8\u80fd\u591f\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728Python\u4e2d\u5bfc\u5165\u548c\u5904\u7406MNIST\u6570\u636e\u96c6\uff0c\u5e76\u5e94\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u6784\u5efa\u548c\u8bc4\u4f30\u81ea\u5df1\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u83b7\u53d6MNIST\u6570\u636e\u96c6\uff1f<\/strong><br \/>MNIST\u6570\u636e\u96c6\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u5e93\u8f7b\u677e\u83b7\u53d6\u3002\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u662f\u4f7f\u7528TensorFlow\u6216Keras\u5e93\u3002\u53ea\u9700\u7b80\u5355\u7684\u51e0\u884c\u4ee3\u7801\u5373\u53ef\u4e0b\u8f7d\u548c\u52a0\u8f7d\u6570\u636e\u96c6\u3002\u4f8b\u5982\uff0c\u5728Keras\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>keras.datasets.mnist.load_data()<\/code>\u6765\u83b7\u53d6\u8bad\u7ec3\u548c\u6d4b\u8bd5\u6570\u636e\u3002\u786e\u4fdd\u5728\u8fd0\u884c\u4ee3\u7801\u4e4b\u524d\u5df2\u7ecf\u5b89\u88c5\u4e86\u76f8\u5173\u5e93\u3002<\/p>\n<p><strong>MNIST\u6570\u636e\u96c6\u7684\u683c\u5f0f\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>MNIST\u6570\u636e\u96c6\u5305\u542b\u624b\u5199\u6570\u5b57\u7684\u56fe\u50cf\uff0c\u6bcf\u4e2a\u56fe\u50cf\u7684\u5927\u5c0f\u4e3a28&#215;28\u50cf\u7d20\uff0c\u4e14\u4ee5\u7070\u5ea6\u5f62\u5f0f\u5b58\u50a8\u3002\u6570\u636e\u96c6\u5206\u4e3a60000\u4e2a\u8bad\u7ec3\u6837\u672c\u548c10000\u4e2a\u6d4b\u8bd5\u6837\u672c\u3002\u6bcf\u4e2a\u6837\u672c\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684\u6807\u7b7e\uff0c\u4ece0\u52309\u8868\u793a\u6570\u5b57\u3002\u901a\u5e38\u5728\u4f7f\u7528\u65f6\uff0c\u56fe\u50cf\u6570\u636e\u4f1a\u88ab\u5f52\u4e00\u5316\uff0c\u4ee5\u4fbf\u63d0\u9ad8\u6a21\u578b\u8bad\u7ec3\u7684\u6548\u7387\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u53ef\u89c6\u5316MNIST\u6570\u636e\u96c6\u7684\u6837\u672c\uff1f<\/strong><br \/>\u53ef\u89c6\u5316MNIST\u6570\u636e\u96c6\u7684\u6837\u672c\u53ef\u4ee5\u5e2e\u52a9\u7406\u89e3\u6570\u636e\u5206\u5e03\u548c\u7279\u5f81\u3002\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u663e\u793a\u6837\u672c\u56fe\u50cf\u3002\u901a\u8fc7<code>plt.imshow()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u56fe\u50cf\u4ee528&#215;28\u7684\u5f62\u5f0f\u5c55\u793a\u51fa\u6765\uff0c\u914d\u5408<code>plt.show()<\/code>\u53ef\u4ee5\u8ba9\u56fe\u50cf\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u3002\u901a\u8fc7\u7b80\u5355\u7684\u5faa\u73af\uff0c\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u591a\u4e2a\u6837\u672c\uff0c\u4ee5\u4fbf\u5bf9\u6570\u636e\u6709\u66f4\u76f4\u89c2\u7684\u8ba4\u8bc6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7tensorflow\u5e93\u5bfc\u5165MNIST\u6570\u636e\u96c6\u3001\u4f7f\u7528keras\u5e93\u5bfc\u5165MNIST\u6570\u636e\u96c6\u3001\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1173808,"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\/1173799"}],"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=1173799"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1173799\/revisions"}],"predecessor-version":[{"id":1173812,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1173799\/revisions\/1173812"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1173808"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1173799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1173799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1173799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}