{"id":246652,"date":"2022-07-17T08:00:32","date_gmt":"2022-07-17T00:00:32","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=246652"},"modified":"2022-07-04T13:01:18","modified_gmt":"2022-07-04T05:01:18","slug":"python-tensorflow-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-tensorflow-linux.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdpython\u6df1\u5ea6\u5b66\u4e60tensorflow\u5b9e\u4f8b\u6570\u636e\u4e0b\u8f7d\u4e0e\u8bfb\u53d6"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e86python\u6df1\u5ea6\u5b66\u4e60tensorflow\u5b9e\u4f8b\u6570\u636e\u4e0b\u8f7d\u4e0e\u8bfb\u53d6\u793a\u4f8b\u8be6\u89e3\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u501f\u9274\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u591f\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u5927\u5bb6\u591a\u591a\u8fdb\u6b65\uff0c\u65e9\u65e5\u5347\u804c\u52a0\u85aa<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u4e00\u3001mnist\u6570\u636e<\/strong><\/div>\n

\u6df1\u5ea6\u5b66\u4e60\u7684\u5165\u95e8\u5b9e\u4f8b\uff0c\u4e00\u822c\u5c31\u662fmnist\u624b\u5199\u6570\u5b57\u5206\u7c7b\u8bc6\u522b\uff0c\u56e0\u6b64\u6211\u4eec\u5e94\u8be5\u5148\u4e0b\u8f7d\u8fd9\u4e2a\u6570\u636e\u96c6\u3002<\/p>\n

tensorflow\u63d0\u4f9b\u4e00\u4e2ainput_data.py\u6587\u4ef6\uff0c\u4e13\u95e8\u7528\u4e8e\u4e0b\u8f7dmnist\u6570\u636e\uff0c\u6211\u4eec\u76f4\u63a5\u8c03\u7528\u5c31\u53ef\u4ee5\u4e86\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

import tensorflow.examples.tutorials.mnist.input_data\r\nmnist = input_data.read_data_sets(\"MNIST_data\/\", one_hot=True)<\/pre>\n

\u6267\u884c\u5b8c\u6210\u540e\uff0c\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939MNIST_data, \u4e0b\u8f7d\u7684\u6570\u636e\u5c06\u653e\u5165\u8fd9\u4e2a\u6587\u4ef6\u5939\u5185\u3002\u4e0b\u8f7d\u7684\u56db\u4e2a\u6587\u4ef6\u4e3a\uff1a<\/p>\n

\"\"<\/p>\n

input_data\u6587\u4ef6\u4f1a\u8c03\u7528\u4e00\u4e2amaybe_download\u51fd\u6570\uff0c\u786e\u4fdd\u6570\u636e\u4e0b\u8f7d\u6210\u529f\u3002\u8fd9\u4e2a\u51fd\u6570\u8fd8\u4f1a\u5224\u65ad\u6570\u636e\u662f\u5426\u5df2\u7ecf\u4e0b\u8f7d\uff0c\u5982\u679c\u5df2\u7ecf\u4e0b\u8f7d\u597d\u4e86\uff0c\u5c31\u4e0d\u518d\u91cd\u590d\u4e0b\u8f7d\u3002<\/p>\n

\u4e0b\u8f7d\u4e0b\u6765\u7684\u6570\u636e\u96c6\u88ab\u5206\u4e09\u4e2a\u5b50\u96c6\uff1a5.5W\u884c\u7684\u8bad\u7ec3\u6570\u636e\u96c6\uff08mnist.train\uff09\uff0c5\u5343\u884c\u7684\u9a8c\u8bc1\u6570\u636e\u96c6\uff08mnist.validation)\u548c1W\u884c\u7684\u6d4b\u8bd5\u6570\u636e\u96c6\uff08mnist.test\uff09\u3002\u56e0\u4e3a\u6bcf\u5f20\u56fe\u7247\u4e3a28x28\u7684\u9ed1\u767d\u56fe\u7247\uff0c\u6240\u4ee5\u6bcf\u884c\u4e3a784\u7ef4\u7684\u5411\u91cf\u3002<\/p>\n

\u6bcf\u4e2a\u5b50\u96c6\u90fd\u7531\u4e24\u90e8\u5206\u7ec4\u6210\uff1a\u56fe\u7247\u90e8\u5206\uff08images)\u548c\u6807\u7b7e\u90e8\u5206(labels), \u6211\u4eec\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u6765\u67e5\u770b \uff1a<\/p>\n

print mnist.train.images.shape\r\nprint mnist.train.labels.shape\r\nprint mnist.validation.images.shape\r\nprint mnist.validation.labels.shape\r\nprint mnist.test.images.shape\r\nprint mnist.test.labels.shape<\/pre>\n

\u5982\u679c\u60f3\u5728spyder\u7f16\u8f91\u5668\u4e2d\u67e5\u770b\u5177\u4f53\u6570\u503c\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u6570\u636e\u63d0\u53d6\u4e3a\u53d8\u91cf\u6765\u67e5\u770b\uff0c\u5982\uff1a<\/p>\n

val_data=mnist.validation.images\r\nval_label=mnist.validation.labels<\/pre>\n
\u4e8c\u3001CSV\u6570\u636e <\/strong><\/div>\n

\u9664\u4e86mnist\u624b\u5199\u5b57\u4f53\u56fe\u7247\u6570\u636e\uff0ctf\u8fd8\u63d0\u4f9b\u4e86\u51e0\u4e2acsv\u7684\u6570\u636e\u4f9b\u5927\u5bb6\u7ec3\u4e60\uff0c\u5b58\u653e\u8def\u5f84\u4e3a\uff1a<\/p>\n

\/home\/xxx\/anaconda3\/lib\/python3.5\/site-packages\/tensorflow\/contrib\/learn\/python\/learn\/datasets\/data\/text_train.csv<\/pre>\n

\u5982\u679c\u8981\u5c06\u8fd9\u4e9b\u6570\u636e\u8bfb\u51fa\u6765\uff0c\u53ef\u7528\u4ee3\u7801\uff1a<\/p>\n

import tensorflow.contrib.learn.python.learn.datasets.base as base\r\niris_data,iris_label=base.load_iris()\r\nhouse_data,house_label=base.load_boston()<\/pre>\n

\u524d\u8005\u4e3airis\u9e22\u5c3e\u82b1\u5349\u6570\u636e\u96c6,\u540e\u8005\u4e3a\u6ce2\u58eb\u987f\u623f\u4ef7\u6570\u636e\u3002<\/p>\n

\u4e09\u3001cifar10\u6570\u636e<\/strong><\/div>\n

tf\u63d0\u4f9b\u4e86cifar10\u6570\u636e\u7684\u4e0b\u8f7d\u548c\u8bfb\u53d6\u7684\u51fd\u6570\uff0c\u6211\u4eec\u76f4\u63a5\u8c03\u7528\u5c31\u53ef\u4ee5\u4e86\u3002\u6267\u884c\u4e0b\u5217\u4ee3\u7801\uff1a<\/p>\n

import tensorflow.models.image.cifar10.cifar10 as cifar10\r\ncifar10.maybe_download_and_extract()\r\nimages, labels = cifar10.distorted_inputs()\r\nprint images\r\nprint labels<\/pre>\n

\u5c31\u53ef\u4ee5\u5c06cifar10\u4e0b\u8f7d\u5e76\u8bfb\u53d6\u51fa\u6765\u3002<\/p>\n

\u4ee5\u4e0a\u5c31\u662fpython\u6df1\u5ea6\u5b66\u4e60tensorflow\u5b9e\u4f8b\u6570\u636e\u4e0b\u8f7d\u4e0e\u8bfb\u53d6\u7684\u8be6\u7ec6\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u6df1\u5ea6\u5b66\u4e60\u7684\u5165\u95e8\u5b9e\u4f8b\uff0c\u4e00\u822c\u5c31\u662fmnist\u624b\u5199\u6570\u5b57\u5206\u7c7b\u8bc6\u522b\uff0c\u56e0\u6b64\u6211\u4eec\u5e94\u8be5\u5148\u4e0b\u8f7d\u8fd9\u4e2a\u6570\u636e\u96c6\u3002 tensorflow\u63d0 […]<\/p>\n","protected":false},"author":1479,"featured_media":231815,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-246652","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/246652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=246652"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/246652\/revisions"}],"predecessor-version":[{"id":246656,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/246652\/revisions\/246656"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/231815"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=246652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=246652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=246652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}