{"id":83979,"date":"2024-03-29T11:20:27","date_gmt":"2024-03-29T03:20:27","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=83979"},"modified":"2024-03-29T11:20:27","modified_gmt":"2024-03-29T03:20:27","slug":"linux%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85%e5%92%8c%e4%bd%bf%e7%94%a8tensorflow","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/83979.html","title":{"rendered":"Linux\u4e2d\u5982\u4f55\u5b89\u88c5\u548c\u4f7f\u7528TensorFlow"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/03\/uploading_images2024-03-19_17-10-11_5903.png?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"Linux\u4e2d\u5982\u4f55\u5b89\u88c5\u548c\u4f7f\u7528TensorFlow\" \/><\/p>\n<p><strong>\u5728Linux\u4e2d\u5b89\u88c5\u548c\u4f7f\u7528TensorFlow<\/strong>\u7684\u8fc7\u7a0b\u76f8\u5bf9\u76f4\u89c2\uff0c\u4f46\u5fc5\u987b\u4f9d\u6b21\u5b8c\u6210\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a\u9996\u5148\u662f<strong>\u5b89\u88c5Python\u73af\u5883<\/strong>\uff0c\u63a5\u4e0b\u6765\u662f\u901a\u8fc7<strong>pip\u5b89\u88c5TensorFlow<\/strong>\u5305\uff0c\u7136\u540e<strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong>\u662f\u5426\u6210\u529f\uff0c\u6700\u540e<strong>\u8fd0\u7528TensorFlow\u8fdb\u884c\u5f00\u53d1<\/strong>\u3002\u7279\u522b\u662f\uff0c<strong>Python\u73af\u5883\u7684\u914d\u7f6e<\/strong>\u5bf9\u4e8eTensorFlow\u7684\u4f7f\u7528\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3aTensorFlow\u662f\u7528Python\u7f16\u5199\u7684\uff0c\u5e76\u4e14\u901a\u8fc7Python API\u8fdb\u884c\u4ea4\u4e92\u64cd\u4f5c\u3002\u6b63\u786e\u8bbe\u7f6ePython\u73af\u5883\u786e\u4fdd\u4e86TensorFlow\u53ef\u4ee5\u987a\u7545\u5b89\u88c5\u548c\u8fd0\u884c\u3002<\/p>\n<p>\u5728\u8fdb\u884c\u8be6\u7ec6\u7684\u5b89\u88c5\u6307\u5bfc\u524d\uff0c\u9700\u8981\u4fdd\u8bc1Linux\u7cfb\u7edf\u4e2d\u5b89\u88c5\u6709Python 3.5\u6216\u66f4\u9ad8\u7248\u672c\u3002\u56e0TensorFlow\u4f9d\u8d56\u4e8e\u7279\u5b9a\u7684Python\u7248\u672c\uff0c\u9009\u62e9\u5408\u9002\u7684\u7248\u672c\u662f\u6210\u529f\u5b89\u88c5\u7684\u524d\u63d0\u3002<\/p>\n<h2><strong>\u4e00\u3001\u5b89\u88c5PYTHON\u73af\u5883<\/strong><\/h2>\n<p>\u4f7f\u7528TensorFlow\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5728Linux\u73af\u5883\u4e0b\u5b89\u88c5Python\u3002\u63a8\u8350\u4f7f\u7528<strong>Python 3.5\u53ca\u4ee5\u4e0a\u7248\u672c<\/strong>\uff0c\u56e0\u4e3aTensorFlow\u4e0d\u652f\u6301\u65e7\u7248\u672cPython\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u5b89\u88c5Python\uff1a<\/p>\n<p>\u9996\u5148\uff0c\u6253\u5f00Linux\u7ec8\u7aef\u3002\u53ef\u4ee5\u901a\u8fc7\u5feb\u6377\u952e`Ctrl + Alt + T`\u6765\u5feb\u901f\u6253\u5f00\u7ec8\u7aef\u754c\u9762\u3002<\/p>\n<p>\u5176\u6b21\uff0c\u66f4\u65b0\u5305\u7ba1\u7406\u5668\u3002\u5728Ubuntu\u6216Debian\u7cfb\u7edf\u4e2d\uff0c\u547d\u4ee4\u4e3a`sudo apt-get update`\uff1b\u5bf9\u4e8eRedHat\u6216CentOS\uff0c\u547d\u4ee4\u4e3a`sudo yum update`\u3002\u8fd9\u4e00\u6b65\u4fdd\u8bc1\u4f60\u5b89\u88c5\u7684Python\u662f\u6700\u65b0\u7248\u672c\u3002<\/p>\n<p>\u63a5\u7740\uff0c\u5b89\u88c5Python\u53ca\u5176\u76f8\u5173\u5f00\u53d1\u5de5\u5177\u3002\u5728Debian\u7cfb\u7cfb\u7edf\u4e2d\u4f7f\u7528`sudo apt-get install python3-dev python3-pip`\uff1b\u800c\u5728RedHat\u7cfb\u4e2d\u5219\u4f7f\u7528`sudo yum install python3-devel python3-pip`\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u4e3a\u4e86\u9694\u79bb\u4e0d\u540c\u7684Python\u73af\u5883\uff0c\u5efa\u8bae\u4f7f\u7528`virtualenv`\u6216`conda`\u521b\u5efa\u72ec\u7acb\u7684\u73af\u5883\u3002<\/p>\n<h2><strong>\u4e8c\u3001\u901a\u8fc7PIP\u5b89\u88c5TENSORFLOW<\/strong><\/h2>\n<p>\u5728\u5df2\u7ecf\u5b89\u88c5\u597dPython\u73af\u5883\u540e\uff0c\u4e0b\u4e00\u6b65\u662f\u4f7f\u7528pip\u8fdb\u884cTensorFlow\u7684\u5b89\u88c5\u3002pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002\u4e3a\u4e86\u786e\u4fddTensorFlow\u5b89\u88c5\u987a\u5229\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p>\u9996\u5148\uff0c\u66f4\u65b0pip\u5230\u6700\u65b0\u7248\u672c\uff0c\u4f7f\u7528\u547d\u4ee4`pip3 install &#8211;upgrade pip`\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6839\u636e\u9700\u6c42\u9009\u62e9\u5b89\u88c5<strong>TensorFlow CPU\u7248\u672c<\/strong>\u6216<strong>TensorFlow GPU\u7248\u672c<\/strong>\u3002\u5bf9\u4e8e\u5927\u591a\u6570\u7528\u6237\u800c\u8a00\uff0cCPU\u7248\u672c\u8db3\u591f\u7528\u4e86\u3002\u5b89\u88c5CPU\u7248\u672c\u4f7f\u7528\u547d\u4ee4`pip3 install tensorflow`\u3002\u5982\u679c\u9700\u8981\u5b89\u88c5\u652f\u6301GPU\u7684\u7248\u672c\uff0c\u5219\u4f7f\u7528\u547d\u4ee4`pip3 install tensorflow-gpu`\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5b89\u88c5GPU\u7248\u672c\u524d\u9700\u8981\u5148\u5904\u7406\u597dGPU\u7684\u9a71\u52a8\u4ee5\u53caCUDA\u76f8\u5173\u7684\u5b89\u88c5\u548c\u914d\u7f6e\uff0c\u8fd9\u8981\u6c42\u7528\u6237\u5177\u6709\u4e00\u5b9a\u7684Linux\u7cfb\u7edf\u77e5\u8bc6\u57fa\u7840\u3002<\/p>\n<h2><strong>\u4e09\u3001\u9a8c\u8bc1TENSORFLOW\u5b89\u88c5<\/strong><\/h2>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u9700\u8981\u9a8c\u8bc1TensorFlow\u662f\u5426\u6b63\u786e\u5b89\u88c5\u5e76\u53ef\u7528\u3002\u53ef\u4ee5\u7528\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u9a8c\u8bc1\uff1a<\/p>\n<p>\u6253\u5f00Python\u89e3\u91ca\u5668\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165`python3`\uff0c\u8fdb\u5165Python\u73af\u5883\u3002<\/p>\n<p>\u5bfc\u5165TensorFlow\u5e93\uff0c\u5e76\u67e5\u770b\u7248\u672c\u3002\u901a\u8fc7\u547d\u4ee4`import tensorflow as tf`\u5bfc\u5165TensorFlow\u5e93\uff0c\u7136\u540e\u4f7f\u7528`print(tf.__version__)`\u6765\u6253\u5370\u7248\u672c\u4fe1\u606f\u3002<\/p>\n<p>\u8fdb\u884c\u529f\u80fd\u6027\u6d4b\u8bd5\u3002\u53ef\u4ee5\u901a\u8fc7\u6267\u884c\u4e00\u4e9b\u57fa\u7840\u7684TensorFlow\u64cd\u4f5c\uff0c\u6bd4\u5982\u521b\u5efa\u5e76\u8fd0\u884c\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u56fe\uff0c\u6765\u6d4b\u8bd5TensorFlow\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<h2><strong>\u56db\u3001\u8fd0\u7528TENSORFLOW\u8fdb\u884c\u5f00\u53d1<\/strong><\/h2>\n<p>\u4e00\u65e6TensorFlow\u5b89\u88c5\u597d\u4e86\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u4f7f\u7528TensorFlow\u8fdb\u884c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u6216\u6df1\u5ea6\u5b66\u4e60\u7684\u5f00\u53d1\u5de5\u4f5c\u4e86\u3002TensorFlow\u5b98\u7f51\u4e0a\u6709\u5927\u91cf\u7684\u6559\u7a0b\u548c\u6587\u6863\uff0c\u65b0\u624b\u53ef\u4ee5\u4ece\u8fd9\u4e9b\u6750\u6599\u5165\u624b\u5b66\u4e60\u3002\u4e3a\u4e86\u66f4\u597d\u5730\u5b66\u4e60\u548c\u4f7f\u7528TensorFlow\uff0c\u53ef\u4ee5\u5173\u6ce8\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<p>\u7406\u89e3TensorFlow\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u6bd4\u5982\u8ba1\u7b97\u56fe\uff08Graph\uff09\u3001\u4f1a\u8bdd\uff08Session\uff09\u3001\u5f20\u91cf\uff08Tensor\uff09\u548c\u53d8\u91cf\uff08Variable\uff09\u3002<\/p>\n<p>\u901a\u8fc7\u7f16\u5199\u4e00\u4e9b\u7b80\u5355\u7684\u7a0b\u5e8f\u6765\u638c\u63e1TensorFlow\u7684\u57fa\u672c\u7528\u6cd5\u3002\u6bd4\u5982\u5b9e\u73b0\u4e00\u4e2a\u7ebf\u6027\u56de\u5f52\u6a21\u578b\u6216\u8005\u5206\u7c7b\u6a21\u578b\uff0c\u719f\u6089TensorFlow\u4e2d\u7684\u6570\u636e\u5904\u7406\u3001\u6a21\u578b\u6784\u5efa\u3001\u8bad\u7ec3\u548c\u8bc4\u4f30\u8fc7\u7a0b\u3002<\/p>\n<p>\u63a2\u7d22TensorFlow\u7684\u9ad8\u7ea7\u529f\u80fd\uff0c\u6bd4\u5982\u4f7f\u7528TensorBoard\u8fdb\u884c\u6a21\u578b\u8bad\u7ec3\u7684\u53ef\u89c6\u5316\uff0c\u4ee5\u53ca\u5229\u7528tf.data\u8fdb\u884c\u9ad8\u6548\u7684\u6570\u636e\u8f93\u5165\u7ba1\u7ebf\u6784\u5efa\u3002<\/p>\n<p>\u4e0d\u65ad\u53c2\u4e0e\u5b9e\u8df5\u3002TensorFlow\u7684\u6700\u4f73\u5b66\u4e60\u65b9\u6cd5\u5c31\u662f\u4e0d\u65ad\u5b9e\u6218\uff0c\u5c1d\u8bd5\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\uff0c\u4e0d\u65ad\u8c03\u6574\u548c\u4f18\u5316\u6a21\u578b\u3002\u53c2\u52a0\u5728\u7ebf\u7ade\u8d5b\u6216\u8005\u5728GitHub\u4e0a\u5bfb\u627e\u5f00\u6e90\u9879\u76ee\u4e5f\u662f\u63d0\u9ad8\u6280\u80fd\u7684\u6709\u6548\u9014\u5f84\u3002<\/p>\n<p>\u901a\u8fc7\u4e0d\u65ad\u5730\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u53ef\u4ee5\u9010\u6e10\u719f\u6089TensorFlow\u7684\u5185\u5728\u673a\u5236\uff0c\u5e76\u80fd\u591f\u5e94\u7528TensorFlow\u89e3\u51b3\u5b9e\u9645\u7684\u673a\u5668\u5b66\u4e60\u95ee\u9898\u3002\u4e0d\u7ba1\u662f\u7528\u4e8e\u7814\u7a76\u8fd8\u662f\u5546\u4e1a\u9879\u76ee\uff0cTensorFlow\u90fd\u80fd\u591f\u63d0\u4f9b\u5f3a\u5927\u4e14\u7075\u6d3b\u7684\u5e73\u53f0\u4ee5\u652f\u6301\u590d\u6742\u6a21\u578b\u7684\u5efa\u6784\u548c\u90e8\u7f72\u3002<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e0a\u5b89\u88c5TensorFlow\uff1f<\/strong><\/p>\n<p>\u8981\u5728Linux\u7cfb\u7edf\u4e0a\u5b89\u88c5TensorFlow\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86\u5408\u9002\u7684Python\u7248\u672c\uff08\u4e00\u822c\u63a8\u8350Python 3\uff09\u3002\u7136\u540e\u53ef\u4ee5\u901a\u8fc7pip\u5de5\u5177\u6765\u5b89\u88c5TensorFlow\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a&#8220;`pip install tensorflow&#8220;`\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u9700\u8981\u7279\u5b9a\u7248\u672c\u7684TensorFlow\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u540e\u52a0\u4e0a\u7248\u672c\u53f7\uff0c\u6bd4\u5982&#8220;`pip install tensorflow==2.0&#8220;`\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u4e2d\u5bfc\u5165TensorFlow\u5e93\u5f00\u59cb\u4f7f\u7528\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e2d\u4f7f\u7528TensorFlow\u8fdb\u884c\u6df1\u5ea6\u5b66\u4e60\uff1f<\/strong><\/p>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\u4f7f\u7528TensorFlow\u8fdb\u884c\u6df1\u5ea6\u5b66\u4e60\u65f6\uff0c\u9996\u5148\u8981\u719f\u6089TensorFlow\u7684API\u548c\u6587\u6863\u4ee5\u4e86\u89e3\u5982\u4f55\u6784\u5efa\u548c\u8bad\u7ec3\u6a21\u578b\u3002\u53ef\u4ee5\u4f7f\u7528TensorFlow\u63d0\u4f9b\u7684Keras\u63a5\u53e3\u6765\u5feb\u901f\u642d\u5efa\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528TensorFlow\u7684\u4f4e\u7ea7API\u6765\u8fdb\u884c\u7075\u6d3b\u7684\u6a21\u578b\u5b9a\u4e49\u548c\u8bad\u7ec3\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u53ef\u4ee5\u7ed3\u5408\u5176\u4ed6\u5e38\u7528\u7684Python\u5e93\u5982NumPy\u3001Matplotlib\u7b49\u6765\u5904\u7406\u6570\u636e\u548c\u53ef\u89c6\u5316\u7ed3\u679c\uff0c\u4ece\u800c\u8fdb\u884c\u6df1\u5ea6\u5b66\u4e60\u4efb\u52a1\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e2d\u66f4\u65b0TensorFlow\uff1f<\/strong><\/p>\n<p>\u8981\u5728Linux\u7cfb\u7edf\u4e2d\u66f4\u65b0TensorFlow\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u6765\u5347\u7ea7\uff0c\u5177\u4f53\u6b65\u9aa4\u4e3a\uff1a&#8220;`pip install &#8211;upgrade tensorflow&#8220;`\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u81ea\u52a8\u5347\u7ea7\u5230\u6700\u65b0\u7248\u672c\u7684TensorFlow\u3002\u5982\u679c\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u540e\u9762\u52a0\u4e0a\u7248\u672c\u53f7\u3002\u53e6\u5916\uff0c\u5efa\u8bae\u5b9a\u671f\u68c0\u67e5TensorFlow\u5b98\u65b9\u7f51\u7ad9\uff0c\u4ee5\u4e86\u89e3\u6700\u65b0\u7248\u672c\u548c\u66f4\u65b0\u5185\u5bb9\uff0c\u53ca\u65f6\u66f4\u65b0\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Linux\u4e2d\u5b89\u88c5\u548c\u4f7f\u7528TensorFlow\u7684\u8fc7\u7a0b\u76f8\u5bf9\u76f4\u89c2\uff0c\u4f46\u5fc5\u987b\u4f9d\u6b21\u5b8c\u6210\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a\u9996\u5148\u662f\u5b89\u88c5Python [&hellip;]","protected":false},"author":1,"featured_media":83980,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[384],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/83979"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=83979"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/83979\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/83980"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=83979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=83979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=83979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}