{"id":995,"date":"2025-04-23T20:28:30","date_gmt":"2025-04-23T11:28:30","guid":{"rendered":"https:\/\/www.dogrow.net\/nnet\/?p=995"},"modified":"2025-06-11T22:47:31","modified_gmt":"2025-06-11T13:47:31","slug":"blog37-cifar-10%e7%94%bb%e5%83%8f%e3%82%bb%e3%83%83%e3%83%88%e3%82%92%e8%a6%8b%e3%81%a6%e3%81%bf%e3%82%8b%ef%bc%88python%e7%89%88%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/nnet\/blog37-cifar-10%e7%94%bb%e5%83%8f%e3%82%bb%e3%83%83%e3%83%88%e3%82%92%e8%a6%8b%e3%81%a6%e3%81%bf%e3%82%8b%ef%bc%88python%e7%89%88%ef%bc%89\/","title":{"rendered":"(37) CIFAR-10\u306e\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u898b\u3066\u307f\u308b\uff08Python\u7248\uff09"},"content":{"rendered":"<h2 class=\"my_h\">1) CIFAR-10\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5165\u624b\u3059\u308b\u3002<\/h2>\n<p>\u753b\u50cf\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5143\u306f\u3053\u3061\u3089\uff08\u2193\uff09 Python\u7528\u306b pickle\u3067\u4f5c\u6210\u3055\u308c\u305f\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002<br \/>\n<a href=\"https:\/\/www.cs.utoronto.ca\/~kriz\/cifar.html\" target=\"_blank\">https:\/\/www.cs.utoronto.ca\/~kriz\/cifar.html<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/i001-1.jpg\" alt=\"\" class=\"my_add_bs1\" \/><\/a><\/p>\n<p>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u89e3\u51cd\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class='my_fc_yellow'>tar -xzvf cifar-10-python.tar.gz<\/span>\r\n<\/pre>\n<p>\u753b\u50cf\u8868\u793a\u7528\u306b Python\u4eee\u60f3\u74b0\u5883\u306b Matplotlib\u3092\u5165\u308c\u3066\u304a\u304f\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class='my_fc_yellow'>sudo apt install python3-matplotlib<\/span>\r\n<\/pre>\n<p>\u4ee5\u4e0b\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30c7\u30fc\u30bf\u3092\u89e3\u51cd\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u4f5c\u696d\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class='my_fc_yellow'>ls -l<\/span>\r\ntotal 181884\r\ndrwxr-xr-x 2 hoge hoge     4096 Jun  5  2009 .\/\r\ndrwxrwxr-x 3 hoge hoge     4096 Apr 23 04:31 ..\/\r\n-rw-r--r-- 1 hoge hoge      158 Mar 31  2009 batches.meta\r\n-rw-r--r-- 1 hoge hoge 31035704 Mar 31  2009 data_batch_1\r\n-rw-r--r-- 1 hoge hoge 31035320 Mar 31  2009 data_batch_2\r\n-rw-r--r-- 1 hoge hoge 31035999 Mar 31  2009 data_batch_3\r\n-rw-r--r-- 1 hoge hoge 31035696 Mar 31  2009 data_batch_4\r\n-rw-r--r-- 1 hoge hoge 31035623 Mar 31  2009 data_batch_5\r\n-rw-r--r-- 1 hoge hoge       88 Jun  5  2009 readme.html\r\n-rw-r--r-- 1 hoge hoge 31035526 Mar 31  2009 test_batch\r\n<\/pre>\n<h2 class=\"my_h\">2) \u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306e\u69cb\u9020\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/h2>\n<h3 class=\"my_h\">(1) batches.meta<\/h3>\n<p>\u307e\u305a\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u30ed\u30fc\u30c9\u3059\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; import pickle\n&gt;&gt;&gt; with open(&#8216;batches.meta&#8217;, &#8216;rb&#8217;) as f:\n...     meta = pickle.load(f, encoding=&#8217;bytes&#8217;)\n<\/pre><\/p>\n<p>\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u3092\u78ba\u8a8d\u3057\u3066\u307f\u308b\u3068 dictionary\u578b\u306a\u306e\u3067\u3001key\u306e\u5024\u3092\u8868\u793a\u3059\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; type(meta)\n&lt;class 'dict'>\n&gt;&gt;&gt;\n&gt;&gt;&gt; meta.keys()\ndict_keys([b&#8217;num_cases_per_batch&#8217;, b&#8217;label_names&#8217;, b&#8217;num_vis&#8217;])\n<\/pre><br \/>\n\u4ee5\u4e0b\u306e\u4e09\u7a2e\u985e\u306e\u30c7\u30fc\u30bf\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3002<br \/>\nmeta[ b&#8217;num_cases_per_batch&#8217; ]<br \/>\nmeta[ b&#8217;label_names&#8217; ]<br \/>\nmeta[ b&#8217;num_vis&#8217; ]<\/p>\n<p>\u305d\u308c\u305e\u308c\u306e\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u3068\u4e2d\u8eab\u3092\u898b\u3066\u307f\u308b\u3002<\/p>\n<p>num_cases_per_batch \u306b\u306f\u3001\u4e00\u3064\u306e\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u753b\u50cf\u306e\u500b\u6570\u304c\u5165\u3063\u3066\u3044\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; type(meta[b&#8217;num_cases_per_batch&#8217;])\n&lt;class 'int'&gt;\n&gt;&gt;&gt; meta[b&#8217;num_cases_per_batch&#8217;]\n10000\n<\/pre><\/p>\n<p>label_names \u306b\u306f\u3001\u753b\u50cf\u306e\u30e9\u30d9\u30eb\u540d\uff08airplane, automobile, bird, deer, etc.\uff09\u304c\u5165\u3063\u3066\u3044\u308b\u3002<br \/>\nb&#8217;airplane&#8217; \u3068\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u3001Unicode\u3067\u306f\u306a\u304f 1\u30d0\u30a4\u30c8\u306e\u30a2\u30b9\u30ad\u30fc\u30b3\u30fc\u30c9\u3067\u5165\u3063\u3066\u3044\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; type(meta[b&#8217;label_names&#8217;])\n&lt;class 'list'&gt;\n&gt;&gt;&gt; len(meta[b&#8217;label_names&#8217;])\n10\n&gt;&gt;&gt;\n&gt;&gt;&gt; type(meta[b&#8217;label_names&#8217;][0])\n&lt;class 'bytes'&gt;\n&gt;&gt;&gt;\n&gt;&gt;&gt; meta[b&#8217;label_names&#8217;]\n[b&#8217;airplane&#8217;, b&#8217;automobile&#8217;, b&#8217;bird&#8217;, b&#8217;cat&#8217;, b&#8217;deer&#8217;, b&#8217;dog&#8217;, b&#8217;frog&#8217;, b&#8217;horse&#8217;, b&#8217;ship&#8217;, b&#8217;truck&#8217;]\n<\/pre><\/p>\n<p>num_vis\u306b\u306f\u3001\u4e00\u3064\u306e\u753b\u50cf\u30c7\u30fc\u30bf\u306e\u30d0\u30a4\u30c8\u30b5\u30a4\u30ba\u304c\u5165\u3063\u3066\u3044\u308b\u3002<br \/>\n(\u7e26, \u6a2a, \u30c1\u30e3\u30cd\u30eb) = (32, 32, 3) = 3072\u30d0\u30a4\u30c8\u306e\u753b\u50cf\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; type(meta[b&#8217;num_vis&#8217;])\n&lt;class 'int'&gt;\n&gt;&gt;&gt; meta[b&#8217;num_vis&#8217;]\n3072\n<\/pre><\/p>\n<h3 class=\"my_h\">(2) data_batch_n, test_batch<\/h3>\n<p>\u307e\u305a\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u30ed\u30fc\u30c9\u3059\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; with open(&#8216;data_batch_1&#8217;, &#8216;rb&#8217;) as f:\n...     batch = pickle.load(f, encoding=&#8217;bytes&#8217;)\n<\/pre><\/p>\n<p>\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u3092\u78ba\u8a8d\u3057\u3066\u307f\u308b\u3068 dictionary\u578b\u306a\u306e\u3067\u3001key\u306e\u5024\u3092\u8868\u793a\u3059\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; type(batch)\n&lt;class 'dict'&gt;\n&gt;&gt;&gt;\n&gt;&gt;&gt; batch.keys()\ndict_keys([b&#8217;batch_label&#8217;, b&#8217;labels&#8217;, b&#8217;data&#8217;, b&#8217;filenames&#8217;])\n<\/pre><br \/>\n\u4ee5\u4e0b\u306e\u4e09\u7a2e\u985e\u306e\u30c7\u30fc\u30bf\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3002<br \/>\nbatch[ b&#8217;batch_label&#8217; ]<br \/>\nbatch[ b&#8217;labels&#8217; ]<br \/>\nbatch[ b&#8217;filenames&#8217; ]<\/p>\n<p>\u305d\u308c\u305e\u308c\u306e\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7\u3068\u4e2d\u8eab\u3092\u898b\u3066\u307f\u308b\u3002<\/p>\n<p>batch_label \u306b\u306f\u3001\u4eca\u56de\u958b\u3044\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u8aac\u660e\u304c\u66f8\u304b\u308c\u3066\u3044\u308b\u3002<br \/>\ndata_batch_1 \u301c data_batch_5 \u306e\u4e2d\u306e\u4e00\u756a\u76ee\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u305f\u306e\u3067\u3001training batch 1 of 5 \u3068\u66f8\u304b\u308c\u3066\u3044\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; type(batch[b&#8217;batch_label&#8217;])\n&lt;class 'bytes'&gt;\n&gt;&gt;&gt; batch[b&#8217;batch_label&#8217;]\nb&#8217;training batch 1 of 5&#8242;\n<\/pre><\/p>\n<p>labels \u306b\u306f\u3001\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u5404\u753b\u50cf\u306e\u30e9\u30d9\u30eb\u756a\u53f7\uff080:airplane, 1:automobile, 2:bird, etc.\uff09\u304c\u5165\u3063\u3066\u3044\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; type(batch[b&#8217;labels&#8217;])\n&lt;class 'list'&gt;\n&gt;&gt;&gt; len(batch[b&#8217;labels&#8217;])\n10000\n&gt;&gt;&gt; batch[b&#8217;labels&#8217;][0]\n6\n&gt;&gt;&gt; batch[b&#8217;labels&#8217;][1]\n9\n<\/pre><\/p>\n<p>data \u306b\u306f\u3001\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u5404\u753b\u50cf\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u308b\u3002<br \/>\n\u5404\u753b\u50cf\u30c7\u30fc\u30bf\u306f\u3001\u8981\u7d20\u6570 3072\u500b\u306e\u914d\u5217\u30c7\u30fc\u30bf\u3068\u3057\u3066\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u3002 \u4e0a\u8a18\u306e num_vis \u306b\u66f8\u304b\u308c\u3066\u3044\u305f\u901a\u308a\u3060\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; type(batch[b&#8217;data&#8217;])\n&lt;class 'numpy.ndarray'&gt;\n&gt;&gt;&gt; len(batch[b&#8217;data&#8217;])\n10000\n&gt;&gt;&gt; batch[b&#8217;data&#8217;][0].shape\n(3072,)\n&gt;&gt;&gt; batch[b&#8217;data&#8217;][1].shape\n(3072,)\n<\/pre><\/p>\n<h2 class=\"my_h\">3) \u5b66\u7fd2\u7528\u753b\u50cf\u3092\u8868\u793a\u3057\u3066\u307f\u308b\u3002<\/h2>\n<h3 class=\"my_h\">(1) \u6307\u5b9aindex\u306e\u753b\u50cf 1\u679a\u3092\u8868\u793a\u3059\u308b\u3002<\/h3>\n<p>\u3053\u306e\u30d6\u30ed\u30b0\u57f7\u7b46\u4f5c\u696d\u306f Ubuntu24.04 Desktop \u4e0a\u3067\u884c\u3063\u3066\u3044\u308b\u3002<br \/>\n\u753b\u9762\u4e0a\u306b\u753b\u50cf\u3092\u8868\u793a\u3057\u305f\u3044\u306e\u3067\u3001\u4f7f\u7528\u4e2d\u306e Python\u4eee\u60f3\u74b0\u5883\u306b\u3082 matplotlib\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class='my_fc_yellow'>pip install matplotlib<\/span>\r\n<\/pre>\n<p>Python shell\u3092\u8d77\u52d5\u3057\u3001\u4ee5\u4e0b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3002<br \/>\n\u3053\u306e\u5f8c\u3001show_image( index ) \u3092\u5b9f\u884c\u3059\u308c\u3070\u3001\u4efb\u610f\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u753b\u50cf\u3092\u8868\u793a\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport pickle\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\n# CIFAR-10 \u30c7\u30fc\u30bf\u306e\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\r\nfile_path = &quot;.\/cifar-10-batches-py\/data_batch_1&quot;\r\n\r\n# Python 3 \u7528\u306b\u30a8\u30f3\u30b3\u30fc\u30c9\u6307\u5b9a\u3057\u3066\u8aad\u307f\u8fbc\u307f\r\nwith open(&#039;data_batch_1&#039;, &#039;rb&#039;) as f:\r\n    batch = pickle.load(f, encoding=&#039;bytes&#039;)\r\n\r\n# \u30c7\u30fc\u30bf\u3068\u30e9\u30d9\u30eb\u3092\u53d6\u308a\u51fa\u3059\uff08\u30ad\u30fc\u306f\u30d0\u30a4\u30c8\u6587\u5b57\u5217\uff09\r\nimages = batch&#x5B;b&#039;data&#039;]         # shape: (10000, 3072)\r\nlabels = batch&#x5B;b&#039;labels&#039;]       # shape: (10000,)\r\n\r\ndef show_image(index):\r\n    # \u753b\u50cf\u30c7\u30fc\u30bf&#x5B;3072]\u3092 &#x5B;32]&#x5B;32]&#x5B;3] \u306b\u4e26\u3073\u66ff\u3048\u308b\r\n    img = images&#x5B;index].reshape(3, 32, 32)   # &#x5B;3074] \u2192 &#x5B;C:3]&#x5B;V:32]&#x5B;H:32]\r\n    img = np.transpose(img, (1, 2, 0))       #        \u2192 &#x5B;V:32]&#x5B;H:32]&#x5B;C:3]\r\n    # \u753b\u50cf\u3092\u8868\u793a\r\n    plt.imshow(img)\r\n    plt.title(f&quot;Label: {labels&#x5B;index]}&quot;)\r\n    plt.show()\r\n<\/pre>\n<p>\u307e\u305a\u306f\u3001\u5148\u982d\u753b\u50cf\uff08index=0\uff09\u3092\u8868\u793a\u3059\u308b\u3002<br \/>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; show_image(0)\n<\/pre><br \/>\n<a href=\"https:\/\/www.dogrow.net\/nnet\/blog8\/\" target=\"_blank\">\u524d\u56de<\/a>\u3068\u540c\u3058\u3001frog \u304c\u8868\u793a\u3055\u308c\u305f\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/Screenshot-from-2025-04-23-06-09-43.png\" alt=\"\"  \/><\/p>\n<h3 class=\"my_h\">(2) \u8907\u6570\u679a\u306e\u753b\u50cf\u3092\u307e\u3068\u3081\u3066\u30bf\u30a4\u30eb\u8868\u793a\u3059\u308b\u3002<\/h3>\n<p>\u3082\u3063\u3068\u8868\u793a\u3057\u3066\u307f\u308b\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/Screenshot-from-2025-04-23-06-20-30.png\" alt=\"\" \/><\/p>\n<p>\u6700\u5f8c\u306e36\u753b\u50cf\u306e\u30bf\u30a4\u30eb\u8868\u793a\u306f\u3001\u4ee5\u4e0b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u5b9f\u884c\u3057\u305f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport pickle\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\n# CIFAR-10 \u30d0\u30c3\u30c1\u8aad\u307f\u8fbc\u307f\r\nwith open(&#039;data_batch_1&#039;, &#039;rb&#039;) as f:\r\n    batch = pickle.load(f, encoding=&#039;bytes&#039;)\r\n\r\nimages = batch&#x5B;b&#039;data&#039;]\r\nlabels = batch&#x5B;b&#039;labels&#039;]\r\n\r\n# \u753b\u50cf\u30c7\u30fc\u30bf&#x5B;3072]\u3092 &#x5B;32]&#x5B;32]&#x5B;3] \u306b\u4e26\u3073\u66ff\u3048\u308b\u95a2\u6570\r\ndef convert_image(raw):\r\n    img = raw.reshape(3, 32, 32)          # &#x5B;3074] \u2192 &#x5B;C:3]&#x5B;V:32]&#x5B;H:32]\r\n    img = np.transpose(img, (1, 2, 0))    #        \u2192 &#x5B;V:32]&#x5B;H:32]&#x5B;C:3]\r\n    return img\r\n\r\n# 6x6\u500b\u306e\u753b\u50cf\u30d7\u30ed\u30c3\u30c8\u30a8\u30ea\u30a2\u3092\u4f5c\u308b\u3002\r\nfig, axes = plt.subplots(6, 6, figsize=(8, 8))\r\n\r\n# \u6700\u521d\u306e36\u679a\u306e\u753b\u50cf\u3092\u30eb\u30fc\u30d7\u3057\u3066\u63cf\u753b\u3059\u308b\u3002\r\nfor i in range(36):\r\n    row = i \/\/ 6                    # \u884c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\uff080\u301c5\uff09\r\n    col = i %  6                    # \u5217\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\uff080\u301c5\uff09\r\n    ax = axes&#x5B;row, col]             # \u8a72\u5f53\u306esubplot\u3092\u53d6\u5f97\r\n    img = convert_image(images&#x5B;i])  # \u753b\u50cf\u3092\u6574\u5f62\r\n    ax.imshow(img)                  # \u8868\u793a\r\n    ax.set_title(f&quot;Label: {labels&#x5B;i]}&quot;, fontsize=8)  # \u30bf\u30a4\u30c8\u30eb\u306b\u30e9\u30d9\u30eb\u8868\u793a\r\n    ax.axis(&#039;off&#039;)                  # \u67a0\u7dda\u30fb\u8ef8\u76ee\u76db\u308a\u3092\u975e\u8868\u793a\r\n\r\nplt.tight_layout()                  # \u30bf\u30a4\u30eb\u9593\u306e\u9593\u9694\u3092\u81ea\u52d5\u8abf\u6574\r\nplt.show()\r\n<\/pre>\n<h3 class=\"my_h\">(3) \u8907\u6570\u679a\u306e\u753b\u50cf\u3092\u307e\u3068\u3081\u3066\u30bf\u30a4\u30eb\u8868\u793a\u3059\u308b\u3002\u6539\u826f\u7248<\/h3>\n<p>\u30e9\u30d9\u30eb\u756a\u53f7\u3088\u308a\u3082\u30e9\u30d9\u30eb\u540d\u3067\u8868\u793a\u3057\u305f\u307b\u3046\u304c\u89aa\u5207\u304b\u306a\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/Screenshot-from-2025-04-23-10-41-26.png\" alt=\"\"  \/><\/p>\n<p>batches.meta\u3092\u8aad\u307f\u8fbc\u307f\u3001\u30e9\u30d9\u30eb\u540d\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u6539\u5584\u3057\u305f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport pickle\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\n# CIFAR-10 \u30e1\u30bf\u8aad\u307f\u8fbc\u307f\r\nwith open(&#039;.\/cifar-10-batches-py\/batches.meta&#039;, &#039;rb&#039;) as f:\r\n    meta = pickle.load(f, encoding=&#039;bytes&#039;)\r\nlabel_names = &#x5B;b.decode(&#039;utf-8&#039;) for b in meta&#x5B;b&#039;label_names&#039;]]\r\n\r\n# CIFAR-10 \u30d0\u30c3\u30c1\u8aad\u307f\u8fbc\u307f\r\nwith open(&#039;.\/cifar-10-batches-py\/data_batch_1&#039;, &#039;rb&#039;) as f:\r\n    batch = pickle.load(f, encoding=&#039;bytes&#039;)\r\n \r\nimages = batch&#x5B;b&#039;data&#039;]\r\nlabels = batch&#x5B;b&#039;labels&#039;]\r\n \r\n# \u753b\u50cf\u30c7\u30fc\u30bf&#x5B;3072]\u3092 &#x5B;32]&#x5B;32]&#x5B;3] \u306b\u4e26\u3073\u66ff\u3048\u308b\u95a2\u6570\r\ndef convert_image(raw):\r\n    img = raw.reshape(3, 32, 32)          # &#x5B;3074] \u2192 &#x5B;C:3]&#x5B;V:32]&#x5B;H:32]\r\n    img = np.transpose(img, (1, 2, 0))    #        \u2192 &#x5B;V:32]&#x5B;H:32]&#x5B;C:3]\r\n    return img\r\n \r\n# 6x6\u500b\u306e\u753b\u50cf\u30d7\u30ed\u30c3\u30c8\u30a8\u30ea\u30a2\u3092\u4f5c\u308b\u3002\r\nfig, axes = plt.subplots(6, 6, figsize=(8, 8))\r\n \r\n# \u6700\u521d\u306e36\u679a\u306e\u753b\u50cf\u3092\u30eb\u30fc\u30d7\u3057\u3066\u63cf\u753b\u3059\u308b\u3002\r\nfor i in range(36):\r\n    row = i \/\/ 6                    # \u884c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\uff080\u301c5\uff09\r\n    col = i %  6                    # \u5217\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\uff080\u301c5\uff09\r\n    ax = axes&#x5B;row, col]             # \u8a72\u5f53\u306esubplot\u3092\u53d6\u5f97\r\n    img = convert_image(images&#x5B;i])  # \u753b\u50cf\u3092\u6574\u5f62\r\n    ax.imshow(img)                  # \u8868\u793a\r\n    ax.set_title(f&quot;{label_names&#x5B;labels&#x5B;i]]}&quot;, fontsize=8)  # \u30bf\u30a4\u30c8\u30eb\u306b\u30e9\u30d9\u30eb\u8868\u793a\r\n    ax.axis(&#039;off&#039;)                  # \u67a0\u7dda\u30fb\u8ef8\u76ee\u76db\u308a\u3092\u975e\u8868\u793a\r\n \r\nplt.tight_layout()                  # \u30bf\u30a4\u30eb\u9593\u306e\u9593\u9694\u3092\u81ea\u52d5\u8abf\u6574\r\nplt.show()\r\n<\/pre>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>1) CIFAR-10\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5165\u624b\u3059\u308b\u3002 \u753b\u50cf\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5143\u306f\u3053\u3061\u3089\uff08\u2193\uff09 Python\u7528\u306b pickle\u3067\u4f5c\u6210\u3055\u308c\u305f\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002 https:\/\/www.cs.utoronto.ca\/~k\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/nnet\/blog37-cifar-10%e7%94%bb%e5%83%8f%e3%82%bb%e3%83%83%e3%83%88%e3%82%92%e8%a6%8b%e3%81%a6%e3%81%bf%e3%82%8b%ef%bc%88python%e7%89%88%ef%bc%89\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,2,4],"tags":[],"class_list":["post-995","post","type-post","status-publish","format-standard","hentry","category-cifar-10","category-2","category-4"],"views":1538,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/comments?post=995"}],"version-history":[{"count":57,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/995\/revisions"}],"predecessor-version":[{"id":2530,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/995\/revisions\/2530"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/media?parent=995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/categories?post=995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/tags?post=995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}