{"id":5029,"date":"2021-01-31T21:08:09","date_gmt":"2021-01-31T13:08:09","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=5029"},"modified":"2021-01-31T21:08:09","modified_gmt":"2021-01-31T13:08:09","slug":"python-pickle%e6%a8%a1%e5%9d%97%e7%9a%84%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/5029","title":{"rendered":"python\u2014\u2014pickle\u6a21\u5757\u7684\u8be6\u89e3"},"content":{"rendered":"<div id=\"header\">\n<div id=\"blogTitle\"><\/div>\n<\/div>\n<div id=\"main\">\n<div id=\"mainContent\">\n<div class=\"forFlow\">\n<div id=\"post_detail\">\n<div id=\"topics\">\n<div class=\"post\">\n<p class=\"postTitle\"><a href=\"https:\/\/www.cnblogs.com\/baby-lily\/p\/10990026.html\">\u539f\u6587\u5730\u5740<\/a><\/p>\n<p>&nbsp;<\/p>\n<div class=\"postBody\">\n<div id=\"cnblogs_post_body\" class=\"blogpost-body\">\n<p>\u8be5<code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">pickle<\/span><\/code>\u6a21\u5757\u5b9e\u73b0\u4e86\u7528\u4e8e\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316Python\u5bf9\u8c61\u7ed3\u6784\u7684\u4e8c\u8fdb\u5236\u534f\u8bae\u3002\u00a0\u201cPickling\u201d\u662f\u5c06Python\u5bf9\u8c61\u5c42\u6b21\u7ed3\u6784\u8f6c\u6362\u4e3a\u5b57\u8282\u6d41\u7684\u8fc7\u7a0b\uff0c\u00a0\u201cunpickling\u201d\u662f\u53cd\u5411\u64cd\u4f5c\uff0c\u4ece\u800c\u5c06\u5b57\u8282\u6d41\uff08\u6765\u81ea<span class=\"xref std std-term\">\u4e8c\u8fdb\u5236\u6587\u4ef6<\/span>\u6216<span class=\"xref std std-term\">\u7c7b\u4f3c\u5b57\u8282\u7684\u5bf9\u8c61<\/span>\uff09\u8f6c\u6362\u56de\u5bf9\u8c61\u5c42\u6b21\u7ed3\u6784\u3002<code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">pickle<\/span><\/code>\u6a21\u5757\u5bf9\u4e8e\u9519\u8bef\u6216\u6076\u610f\u6784\u9020\u7684\u6570\u636e\u662f\u4e0d\u5b89\u5168\u7684\u3002<\/p>\n<p>pickle\u534f\u8bae\u548cJSON\uff08JavaScript Object Notation\uff09\u7684\u533a\u522b\u00a0\uff1a<\/p>\n<p>1. JSON\u662f\u4e00\u79cd\u6587\u672c\u5e8f\u5217\u5316\u683c\u5f0f\uff08\u5b83\u8f93\u51faunicode\u6587\u672c\uff0c\u867d\u7136\u5927\u90e8\u5206\u65f6\u95f4\u5b83\u88ab\u7f16\u7801<code class=\"docutils literal notranslate\"><span class=\"pre\">utf-8<\/span><\/code>\uff09\uff0c\u800cpickle\u662f\u4e8c\u8fdb\u5236\u5e8f\u5217\u5316\u683c\u5f0f;<\/p>\n<p>2. JSON\u662f\u4eba\u7c7b\u53ef\u8bfb\u7684\uff0c\u800cpickle\u5219\u4e0d\u662f;<\/p>\n<p>3. JSON\u662f\u53ef\u4e92\u64cd\u4f5c\u7684\uff0c\u5e76\u4e14\u5728Python\u751f\u6001\u7cfb\u7edf\u4e4b\u5916\u5e7f\u6cdb\u4f7f\u7528\uff0c\u800cpickle\u662f\u7279\u5b9a\u4e8ePython\u7684;<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cJSON\u53ea\u80fd\u8868\u793aPython\u5185\u7f6e\u7c7b\u578b\u7684\u5b50\u96c6\uff0c\u800c\u4e0d\u80fd\u8868\u793a\u81ea\u5b9a\u4e49\u7c7b;\u00a0pickle\u53ef\u4ee5\u8868\u793a\u6781\u5176\u5e9e\u5927\u7684Python\u7c7b\u578b\uff08\u5176\u4e2d\u8bb8\u591a\u662f\u81ea\u52a8\u7684\uff0c\u901a\u8fc7\u5de7\u5999\u5730\u4f7f\u7528Python\u7684\u5185\u7701\u5de5\u5177;\u590d\u6742\u7684\u6848\u4f8b\u53ef\u4ee5\u901a\u8fc7\u5b9e\u73b0\u7279\u5b9a\u7684\u5bf9\u8c61API\u6765\u89e3\u51b3\uff09\u3002<\/p>\n<p id=\"index-1\">pickle \u6570\u636e\u683c\u5f0f\u662f\u7279\u5b9a\u4e8ePython\u7684\u3002\u5b83\u7684\u4f18\u70b9\u662f\u6ca1\u6709\u5916\u90e8\u6807\u51c6\u5f3a\u52a0\u7684\u9650\u5236\uff0c\u4f8b\u5982JSON\u6216XDR\uff08\u4e0d\u80fd\u4ee3\u8868\u6307\u9488\u5171\u4eab\uff09;\u00a0\u4f46\u662f\u8fd9\u610f\u5473\u7740\u975ePython\u7a0b\u5e8f\u53ef\u80fd\u65e0\u6cd5\u91cd\u5efapickled Python\u5bf9\u8c61\u3002<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c<code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">pickle<\/span><\/code>\u6570\u636e\u683c\u5f0f\u4f7f\u7528\u76f8\u5bf9\u7d27\u51d1\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u3002\u5982\u679c\u60a8\u9700\u8981\u6700\u4f73\u5c3a\u5bf8\u7279\u5f81\uff0c\u5219\u53ef\u4ee5\u6709\u6548\u5730\u538b\u7f29\u6570\u636e\u3002<\/p>\n<p><strong>\u6a21\u5757\u63a5\u53e3<\/strong><\/p>\n<p>\u8981\u5e8f\u5217\u5316\u5bf9\u8c61\u5c42\u6b21\u7ed3\u6784\uff0c\u53ea\u9700\u8c03\u7528\u8be5<code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">dumps()<\/span><\/code>\u51fd\u6570\u5373\u53ef\u3002\u540c\u6837\uff0c\u8981\u5bf9\u6570\u636e\u6d41\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\uff0c\u8bf7\u8c03\u7528\u8be5<code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">loads()<\/span><\/code>\u51fd\u6570\u3002\u4f46\u662f\uff0c\u5982\u679c\u60a8\u60f3\u8981\u66f4\u591a\u5730\u63a7\u5236\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\uff0c\u5219\u53ef\u4ee5\u5206\u522b\u521b\u5efa\u4e00\u4e2a<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Pickler<\/span><\/code>\u6216\u4e00\u4e2a<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Unpickler<\/span><\/code>\u5bf9\u8c61\u3002<\/p>\n<p><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">pickle<\/span><\/code>\u6a21\u5757\u63d0\u4f9b\u4ee5\u4e0b\u5e38\u91cf\uff1a<\/p>\n<dl class=\"data\">\n<dt id=\"pickle.HIGHEST_PROTOCOL\"><code class=\"descclassname\">pickle.<\/code><code class=\"descname\">HIGHEST_PROTOCOL<\/code><\/dt>\n<dd>\u6574\u6570\uff0c\u00a0\u53ef\u7528\u7684\u6700\u9ad8\u534f\u8bae\u7248\u672c\u3002\u8fd9\u4e2a\u503c\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u88ab\u4f20\u9012\u534f\u8bae\u7684\u4ef7\u503c\u51fd\u6570\u00a0<code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">dump()<\/span><\/code>\u548c<code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">dumps()<\/span><\/code>\u4ee5\u53ca\u8be5<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Pickler<\/span><\/code>\u00a0\u6784\u9020\u51fd\u6570\u3002<\/dd>\n<\/dl>\n<dl class=\"data\">\n<dt id=\"pickle.DEFAULT_PROTOCOL\"><code class=\"descclassname\">pickle.<\/code><code class=\"descname\">DEFAULT_PROTOCOL<\/code><\/dt>\n<dd>\u6574\u6570\uff0c\u7528\u4e8e\u7f16\u7801\u7684\u9ed8\u8ba4\u534f\u8bae\u7248\u672c\u3002\u53ef\u80fd\u4e0d\u5230<code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">HIGHEST_PROTOCOL<\/span><\/code>\u3002\u76ee\u524d\uff0c\u9ed8\u8ba4\u534f\u8bae\u662f3\uff0c\u8fd9\u662f\u4e3aPython 3\u8bbe\u8ba1\u7684\u65b0\u534f\u8bae\u3002<\/dd>\n<\/dl>\n<p><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">pickle<\/span><\/code>\u6a21\u5757\u63d0\u4f9b\u4ee5\u4e0b\u529f\u80fd\uff0c\u4f7f\u9178\u6d17\u8fc7\u7a0b\u66f4\u52a0\u65b9\u4fbf\uff1a<\/p>\n<dl class=\"function\">\n<dt id=\"pickle.dump\"><code class=\"descclassname\">pickle.<\/code><code class=\"descname\">dump<\/code><span class=\"sig-paren\">\uff08obj\uff0cfile\uff0cprotocol = None\uff0c*\uff0cfix_imports = True\u00a0\uff09<\/span><\/dt>\n<dd>\u5c06obj\u5bf9\u8c61\u7684\u7f16\u7801pickle\u7f16\u7801\u8868\u793a\u5199\u5165\u5230\u6587\u4ef6\u5bf9\u8c61\u4e2d\uff0c\u76f8\u5f53\u4e8e<code class=\"docutils literal notranslate\"><span class=\"pre\">Pickler(file,protocol).dump(obj)<\/span><\/code><\/p>\n<p>\u53ef\u4f9b\u9009\u62e9\u7684\u534f\u8bae\u53c2\u6570\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u6307\u5b9apickler\u4f7f\u7528\u7684\u534f\u8bae\u7248\u672c\uff0c\u652f\u6301\u7684\u534f\u8bae\u662f0\u5230<code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">HIGHEST_PROTOCOL<\/span><\/code>\u3002\u5982\u679c\u672a\u6307\u5b9a\uff0c\u5219\u9ed8\u8ba4\u4e3a<code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">DEFAULT_PROTOCOL<\/span><\/code>\u3002\u5982\u679c\u6307\u5b9a\u4e3a\u8d1f\u6570\uff0c\u5219\u9009\u62e9<code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">HIGHEST_PROTOCOL<\/span><\/code>\u3002<\/p>\n<p>\u6587\u4ef6\u53c2\u6570\u5fc5\u987b\u5177\u6709\u63a5\u53d7\u5355\u4e2a\u5b57\u8282\u7684\u53c2\u6570\u5199\u65b9\u6cd5\u3002\u56e0\u6b64\uff0c\u5b83\u53ef\u4ee5\u662f\u4e3a\u4e8c\u8fdb\u5236\u5199\u5165\u6253\u5f00\u7684\u78c1\u76d8\u6587\u4ef6\uff0c\u00a0<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">io.BytesIO<\/span><\/code>\u5b9e\u4f8b\u6216\u6ee1\u8db3\u6b64\u63a5\u53e3\u7684\u4efb\u4f55\u5176\u4ed6\u81ea\u5b9a\u4e49\u5bf9\u8c61\u3002<\/p>\n<p>\u5982\u679cfix_imports\u4e3atrue\u4e14protocol\u5c0f\u4e8e3\uff0c\u5219pickle\u5c06\u5c1d\u8bd5\u5c06\u65b0\u7684Python 3\u540d\u79f0\u6620\u5c04\u5230Python 2\u4e2d\u4f7f\u7528\u7684\u65e7\u6a21\u5757\u540d\u79f0\uff0c\u4ee5\u4fbf\u4f7f\u7528Python 2\u53ef\u8bfb\u53d6pickle\u6570\u636e\u6d41\u3002<\/dd>\n<\/dl>\n<dl class=\"function\">\n<dt id=\"pickle.dumps\"><code class=\"descclassname\">pickle.<\/code><code class=\"descname\">dumps<\/code><span class=\"sig-paren\">\uff08obj\uff0cprotocol = None\uff0c*\uff0cfix_imports = True\u00a0\uff09<\/span><\/dt>\n<dd>\u5c06\u5bf9\u8c61\u7684pickled\u8868\u793a\u4f5c\u4e3a<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">bytes<\/span><\/code>\u5bf9\u8c61\u8fd4\u56de\uff0c\u800c\u4e0d\u662f\u5c06\u5176\u5199\u5165\u6587\u4ef6\u3002<\/p>\n<p>\u53c2\u6570protocol\u548cfix_imports\u5177\u6709\u4e0ein\u4e2d\u76f8\u540c\u7684\u542b\u4e49\u00a0<code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">dump()<\/span><\/code>\u3002<\/dd>\n<\/dl>\n<dl class=\"function\">\n<dt id=\"pickle.load\"><code class=\"descclassname\">pickle.<\/code><code class=\"descname\">load<\/code><span class=\"sig-paren\">\uff08file\uff0c*\uff0cfix_imports = True\uff0cencoding =\u201cASCII\u201d\uff0cerrors =\u201cstrict\u201d\u00a0\uff09<\/span><\/dt>\n<dd>\u4ece\u6253\u5f00\u7684\u6587\u4ef6\u5bf9\u8c61\u00a0\u6587\u4ef6\u4e2d\u8bfb\u53d6pickle\u5bf9\u8c61\u8868\u793a\uff0c\u5e76\u8fd4\u56de\u5176\u4e2d\u6307\u5b9a\u7684\u91cd\u6784\u5bf9\u8c61\u5c42\u6b21\u7ed3\u6784\u3002\u8fd9\u76f8\u5f53\u4e8e<code class=\"docutils literal notranslate\"><span class=\"pre\">Unpickler(file).load()<\/span><\/code>\u3002<\/p>\n<p>pickle\u7684\u534f\u8bae\u7248\u672c\u662f\u81ea\u52a8\u68c0\u6d4b\u7684\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u534f\u8bae\u53c2\u6570\u3002\u8d85\u8fc7pickle\u5bf9\u8c61\u7684\u8868\u793a\u7684\u5b57\u8282\u5c06\u88ab\u5ffd\u7565\u3002<\/p>\n<p>\u53c2\u6570\u6587\u4ef6\u5fc5\u987b\u6709\u4e24\u4e2a\u65b9\u6cd5\uff0c\u4e00\u4e2a\u91c7\u7528\u6574\u6570\u53c2\u6570\u7684read()\u65b9\u6cd5\u548c\u4e00\u4e2a\u4e0d\u9700\u8981\u53c2\u6570\u7684readline()\u65b9\u6cd5\u3002\u4e24\u79cd\u65b9\u6cd5\u90fd\u5e94\u8fd4\u56de\u5b57\u8282\u3002\u56e0\u6b64\uff0c\u6587\u4ef6\u53ef\u4ee5\u662f\u4e3a\u4e8c\u8fdb\u5236\u8bfb\u53d6\u800c\u6253\u5f00\u7684\u78c1\u76d8\u6587\u4ef6\uff0c<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">io.BytesIO<\/span><\/code>\u5bf9\u8c61\u6216\u6ee1\u8db3\u6b64\u63a5\u53e3\u7684\u4efb\u4f55\u5176\u4ed6\u81ea\u5b9a\u4e49\u5bf9\u8c61\u3002<\/p>\n<p>\u53ef\u9009\u7684\u5173\u952e\u5b57\u53c2\u6570\u662ffix_imports\uff0cencoding\u548cerrors\uff0c\u7528\u4e8e\u63a7\u5236Python 2\u751f\u6210\u7684pickle\u6d41\u7684\u517c\u5bb9\u6027\u652f\u6301\u3002\u5982\u679cfix_imports\u4e3atrue\uff0c\u5219pickle\u5c06\u5c1d\u8bd5\u5c06\u65e7\u7684Python 2\u540d\u79f0\u6620\u5c04\u5230Python 3\u4e2d\u4f7f\u7528\u7684\u65b0\u540d\u79f0\u3002\u7f16\u7801\u548c\u00a0\u9519\u8bef\u544a\u8bc9pickle\u5982\u4f55\u89e3\u7801Python 2\u7f16\u7801\u76848\u4f4d\u5b57\u7b26\u4e32\u5b9e\u4f8b;\u00a0\u8fd9\u4e9b\u9ed8\u8ba4\u5206\u522b\u4e3a&#8217;ASCII&#8217;\u548c&#8217;strict&#8217;\u3002\u8be5\u7f16\u7801\u53ef\u4ee5\u662f\u201c\u5b57\u8282\u201d\u4f5c\u4e3a\u5b57\u8282\u5bf9\u8c61\u8bfb\u53d6\u8fd9\u4e9b8\u4f4d\u4e32\u7684\u5b9e\u4f8b\u3002\u4f7f\u7528<code class=\"docutils literal notranslate\"><span class=\"pre\">encoding='latin1'<\/span><\/code>\u6240\u9700\u7684\u53d6\u50a8\u5b58NumPy\u7684\u9635\u5217\u548c\u5b9e\u4f8b<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">datetime<\/span><\/code>\uff0c<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">date<\/span><\/code>\u5e76\u4e14<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">time<\/span><\/code>\u88abPython 2\u89e3\u7801\u3002<\/dd>\n<\/dl>\n<dl class=\"function\">\n<dt id=\"pickle.loads\"><code class=\"descclassname\">pickle.<\/code><code class=\"descname\">loads<\/code><span class=\"sig-paren\">\uff08bytes_object\uff0c*\uff0cfix_imports = True\uff0cencoding =\u201cASCII\u201d\uff0cerrors =\u201cstrict\u201d\u00a0\uff09<\/span><\/dt>\n<dd>\u4ece<code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">bytes<\/span><\/code>\u5bf9\u8c61\u8bfb\u53d6pickle\u5bf9\u8c61\u5c42\u6b21\u7ed3\u6784\u5e76\u8fd4\u56de\u5176\u4e2d\u6307\u5b9a\u7684\u91cd\u6784\u5bf9\u8c61\u5c42\u6b21\u7ed3\u6784\u3002<\/p>\n<p>pickle\u7684\u534f\u8bae\u7248\u672c\u662f\u81ea\u52a8\u68c0\u6d4b\u7684\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u534f\u8bae\u53c2\u6570\u3002\u8d85\u8fc7pickle\u5bf9\u8c61\u7684\u8868\u793a\u7684\u5b57\u8282\u5c06\u88ab\u5ffd\u7565\u3002<\/dd>\n<\/dl>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>import numpy as np\r\nimport pickle\r\nimport io\r\n\r\nif __name__ == '__main__':\r\n    path = 'test'\r\n    f = open(path, 'wb')\r\n    data = {'a':123, 'b':'ads', 'c':[[1,2],[3,4]]}\r\n    pickle.dump(data, f)\r\n    f.close()\r\n\r\n    f1 = open(path, 'rb')\r\n    data1 = pickle.load(f1)\r\n    print(data1)<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/img2018.cnblogs.com\/blog\/1636554\/201906\/1636554-20190605214431479-1478128997.png\" alt=\"\" width=\"807\" height=\"88\" \/><\/p>\n<p>\u5bf9\u4e8epython\u683c\u5f0f\u7684\u6570\u636e\u96c6\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528pickle\u8fdb\u884c\u52a0\u8f7d\u4e86\uff0c\u4e0b\u9762\u4e0ecifar10\u6570\u636e\u96c6\u4e3a\u4f8b\uff0c\u8fdb\u884c\u8bfb\u53d6\u548c\u52a0\u8f7d\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>import numpy as np\r\nimport pickle\r\nimport random\r\nimport matplotlib.pyplot as plt\r\nfrom PIL import Image\r\n\r\npath1 = 'D:\\\\tmp\\cifar10_data\\cifar-10-batches-py\\data_batch_1'\r\npath2 = 'D:\\\\tmp\\cifar10_data\\cifar-10-batches-py\\data_batch_2'\r\npath3 = 'D:\\\\tmp\\cifar10_data\\cifar-10-batches-py\\data_batch_3'\r\npath4 = 'D:\\\\tmp\\cifar10_data\\cifar-10-batches-py\\data_batch_4'\r\npath5 = 'D:\\\\tmp\\cifar10_data\\cifar-10-batches-py\\data_batch_5'\r\n\r\npath6 = 'D:\\\\tmp\\cifar10_data\\cifar-10-batches-py\\\\test_batch'\r\n\r\nif __name__ == '__main__':\r\n    with open(path1, 'rb') as fo:\r\n        data = pickle.load(fo, encoding='bytes')\r\n\r\n        # print(data[b'batch_label'])\r\n        # print(data[b'labels'])\r\n        # print(data[b'data'])\r\n        # print(data[b'filenames'])\r\n\r\n        print(data[b'data'].shape)\r\n\r\n        images_batch = np.array(data[b'data'])\r\n        images = images_batch.reshape([-1, 3, 32, 32])\r\n        print(images.shape)\r\n        imgs = images[5, :, :, :].reshape([3, 32, 32])\r\n        img = np.stack((imgs[0, :, :], imgs[1, :, :], imgs[2, :, :]), 2)\r\n\r\n        print(img.shape)\r\n\r\n        plt.imshow(img)\r\n        plt.axis('off')\r\n        plt.show()<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img2018.cnblogs.com\/blog\/1636554\/201906\/1636554-20190608095130249-1829743208.png\" alt=\"\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/img2018.cnblogs.com\/blog\/1636554\/201906\/1636554-20190608095148798-1674177438.png\" alt=\"\" width=\"480\" height=\"440\" \/><\/p>\n<p>\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u8bfb\u53d6\u6570\u636e\u8fdb\u884c\u8bad\u7ec3\u4e86\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 &nbsp; \u8be5pickle\u6a21<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[119],"class_list":["post-5029","post","type-post","status-publish","format-standard","hentry","tag-03-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=5029"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5029\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=5029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=5029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=5029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}