{"id":1253,"date":"2025-04-26T05:53:58","date_gmt":"2025-04-25T20:53:58","guid":{"rendered":"https:\/\/www.dogrow.net\/nnet\/?p=1253"},"modified":"2025-05-22T04:13:47","modified_gmt":"2025-05-21T19:13:47","slug":"blog39-%e5%85%b1%e7%94%a8%e3%82%b5%e3%83%bc%e3%83%90%e3%81%a7pytorach%ef%bc%88%e9%a0%86%e4%bc%9d%e6%92%ad%e3%81%a0%e3%81%91%ef%bc%89%e5%ae%9f%e8%a1%8c%e3%81%97%e3%81%9f%e3%81%84%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/nnet\/blog39-%e5%85%b1%e7%94%a8%e3%82%b5%e3%83%bc%e3%83%90%e3%81%a7pytorach%ef%bc%88%e9%a0%86%e4%bc%9d%e6%92%ad%e3%81%a0%e3%81%91%ef%bc%89%e5%ae%9f%e8%a1%8c%e3%81%97%e3%81%9f%e3%81%84%e3%80%82\/","title":{"rendered":"(39) \u5171\u7528\u30b5\u30fc\u30d0\u3067PyTorach\uff08\u9806\u4f1d\u64ad\u3060\u3051\uff09\u3092\u5b9f\u884c\u3057\u305f\u3044\u3002"},"content":{"rendered":"<h1 class=\"my_h\">\u30101\u3011\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4f8b\u3048\u3070\u3001MNIST\u81ea\u52d5\u8a8d\u8b58\u3067\u3053\u3093\u306a\u3053\u3068\u3092\u3084\u308a\u305f\u3044\u3002<br \/>\n\u30fb\u81ea\u5b85\u30b5\u30fc\u30d0\u30fc\u4e0a\u3067\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057\u3001\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u3055\u308c\u305f\u5b66\u7fd2\u6e08\u307f\u30d1\u30e9\u30e1\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f5c\u308b\u3002<br \/>\n\u30fb\u3053\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u3001\u5171\u7528\u30b5\u30fc\u30d0\u4e0a\u3067 <span class=\"my_fc_deeppinkBBig\">\u6570\u5b57\u306e\u81ea\u52d5\u8a8d\u8b58 Web\u30b5\u30fc\u30d3\u30b9<\/span> \u3092\u516c\u958b\u3057\u305f\u3044\u3002<\/p>\n<p>\u3042\u304f\u307e\u3067\u3082\u4f8b\u3060\u3002<br \/>\n\u3053\u3093\u306a\u3082\u306e\u306b\u9700\u8981\u304c\u3042\u308b\u306f\u305a\u306f\u306a\u3044\u3002<\/p>\n<p>\u3053\u306e\u305f\u3081\u306b\u5fc5\u8981\u306a\u3053\u3068\u306f\u3001\u4ee5\u4e0b\u306e\u901a\u308a\u3002<br \/>\n<span class=\"my_fc_deeppinkBBig\">\u30fb\u30db\u30fc\u30e0\u30da\u30fc\u30b8\u304c\u8a2d\u7f6e\u53ef\u80fd\uff06\u5b89\u4fa1\u306a\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\uff08\uff1d\u5171\u7528\u30b5\u30fc\u30d0\uff09\u4e0a\u306b PyTorch\u5b9f\u884c\u74b0\u5883\u3092\u8a2d\u7f6e\u3057\u305f\u3044\u3002<\/span><\/p>\n<p>\u554f\u984c\u70b9\u306f\uff1f<br \/>\n<span class=\"my_fc_red\">\u30fb\u5171\u7528\u30b5\u30fc\u30d0\u306f root\u6a29\u9650\u304c\u4e0e\u3048\u3089\u308c\u3066\u3044\u306a\u3044\u3002<br \/>\n\u30fb\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308bPython\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u53e4\u3044\u3002<br \/>\n\u30fb\u91cd\u305f\u3044\u51e6\u7406\u3092\u7e70\u308a\u8fd4\u3059\u3068\u3001\u30da\u30ca\u30eb\u30c6\u30a3\u304c\u4e0e\u3048\u3089\u308c\u305f\u308a\u3001\u6700\u60aa\u306e\u5834\u5408\u306f\u30a2\u30ab\u30a6\u30f3\u30c8\u3092BAN\u3055\u308c\u3066\u3057\u307e\u3046\u3002<\/span><\/p>\n<p>\u3053\u308c\u3092\u4ee5\u4e0b\u306e\u65b9\u6cd5\u3067\u56de\u907f\u3057\u305f\u3044\u3002<br \/>\n<span class=\"my_fc_blue\">\u30fb\u975eroot\u3067\u3082\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u53ef\u80fd\u306a Anaconda\u3092\u4f7f\u3044\u3001\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u306e Python\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<br \/>\n\u30fb\u7d76\u5bfe\u306b\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u52d5\u304b\u3055\u306a\u3044\uff01<br \/>\n\u30fbGPU\u3092\u4f7f\u308f\u305a\u3001CPU\u306e\u307f\u3067\u5b9f\u884c\u3059\u308b\u3002<br \/>\n\u3000\u5b66\u7fd2\u306f\u81ea\u5b85\u30b5\u30fc\u30d0\u3067\u5b9f\u884c\u3057\u3001\u5171\u7528\u30b5\u30fc\u30d0\u4e0a\u3067\u306f\u51e6\u7406\u8ca0\u8377\u306e\u8efd\u3044\u9806\u4f1d\u64ad\u3060\u3051\u3092\u52d5\u304b\u3059\u3002<\/span><\/p>\n<h1 class=\"my_h\">\u30102\u3011\u3084\u3063\u3066\u307f\u308b<\/h1>\n<h2 class=\"my_h\">Step 1\/6: Anaconda\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/h2>\n<p>\u3053\u3061\u3089\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002<br \/>\n<span class=\"my_fc_crimson\">\u203b\u30e1\u30fc\u30eb\u767b\u9332\u3059\u308b\u3068\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30ea\u30f3\u30af\u304c\u9001\u3089\u308c\u3066\u304f\u308b\u3002<\/span><br \/>\n<a href=\"https:\/\/www.anaconda.com\/download\/\" target=\"_blank\">https:\/\/www.anaconda.com\/download\/<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/i001-2.jpg\" alt=\"\" class=\"my_add_bs1\" \/><\/a><\/p>\n<p>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30ea\u30f3\u30af\u304c\u9001\u3089\u308c\u3066\u304d\u305f\u3089\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u3044\u30de\u30b7\u30f3\u4e0a\uff08\uff1d\u5171\u7528\u30b5\u30fc\u30d0\u4e0a\uff09\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">wget https:\/\/repo.anaconda.com\/archive\/Anaconda3-2024.10-1-Linux-x86_64.sh<\/span>\r\n<\/pre>\n<p>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306b\u5b9f\u884c\u5c5e\u6027\u3092\u4ed8\u4e0e\u3057\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u3092\u8d77\u52d5\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">chmod +x Anaconda3-2024.10-1-Linux-x86_64.sh<\/span>\r\n$ <span class=\"my_fc_yellow\">.\/Anaconda3-2024.10-1-Linux-x86_64.sh<\/span>\r\n<\/pre>\n<p>\u5bfe\u8a71\u5f0f\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u304c\u958b\u59cb\u3055\u308c\u308b\u306e\u3067\u3001\u306e\u6307\u793a\u306b\u5f93\u3063\u3066\u5165\u529b\u3059\u308b\u3002<\/p>\n<p>\u3053\u306e\u3068\u304d\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u307e\u307e\u3060\u3068 <span class=\"my_fc_blue\">\/home\/{user}\/anaconda3<\/span> \u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u308b\u3002<br \/>\n\u3082\u3057\u3001\u4efb\u610f\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b anaconda\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u3044\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u500b\u6240\u3067\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u30d5\u30eb\u30d1\u30b9\u6307\u5b9a\u3059\u308b\u3002<br \/>\n\u4e0b\u8a18\u306e\u5834\u5408\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5148\u3092 <span class=\"my_fc_blue\">\/opt\/anaconda<\/span> \u306b\u6307\u5b9a\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\nAnaconda3 will now be installed into this location:\r\n\/home\/hoge\/anaconda3\r\n\r\n  - Press ENTER to confirm the location\r\n  - Press CTRL-C to abort the installation\r\n  - Or specify a different location below\r\n\r\n[\/home\/ana\/anaconda3] &gt;&gt;&gt; \/opt\/anaconda\r\n<\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5b8c\u4e86\u3057\u305f\u3089 conda init \u3092\u5b9f\u884c\u3059\u308b\u3002<br \/>\nconda\u306e\u30d1\u30b9\u304c\u901a\u3063\u3066\u3044\u306a\u3044\u306e\u3067\u3001conda\u304c\u5b58\u5728\u3059\u308b\u5834\u6240\u307e\u3067\u79fb\u52d5\u3057\u3066\u3057\u307e\u3046\u306e\u304c\u697d\u3060\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">cd ~\/anaconda3\/bin<\/span>\r\n$ <span class=\"my_fc_yellow\">conda init<\/span>\r\n<\/pre>\n<p>conda init\u3067 .bashrc \u304c\u66f4\u65b0\u3055\u308c\u308b\u306e\u3067\u3001\u4eca\u306e shell\u3067\u3053\u308c\u3092\u6709\u52b9\u5316\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">source .bashrc<\/span>\r\n<\/pre>\n<h2 class=\"my_h\">Step 2\/6: Anaconda\u3067 Python\u4eee\u60f3\u74b0\u5883\u3092\u4f5c\u308b\u3002<\/h2>\n<p>Anaconda\u4e0a\u3067 PyTorch\u4eee\u60f3\u74b0\u5883\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\n\u4eca\u56de\u306f Python3.12\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">conda create -n pytorch-env python=3.12<\/span>\r\n<\/pre>\n<h2 class=\"my_h\">Step 3\/6: Anaconda\u3067\u4f5c\u3063\u305f Python\u4eee\u60f3\u74b0\u5883\u306b PyTorch\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/h2>\n<p>Anaconda\u4e0a\u3067\u4f5c\u3063\u305f\u4eee\u60f3\u74b0\u5883\u3092\u958b\u59cb\u3059\u308b\u3002<br \/>\n\u2192 \u30d7\u30ed\u30f3\u30d7\u30c8\u306b (\u4eee\u60f3\u74b0\u5883\u540d) \u304c\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">conda activate pytorch-env<\/span>\r\n(pytorch-env) $\r\n<\/pre>\n<p>Anaconda\u3067\u4f5c\u3063\u305f Python\u4eee\u60f3\u74b0\u5883\u306b PyTorch\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<br \/>\n<span class=\"my_fc_crimson\">\u203b\u3053\u306e\u3068\u304d\u3001GPU\u7121\u3057\u306e cpuonly \u3092\u6307\u5b9a\u3059\u308b\u3002<\/span><\/p>\n<pre class=\"my_pre_bgBlack\">\r\n(pytorch-env) $ <span class=\"my_fc_yellow\">conda install pytorch torchvision torchaudio cpuonly -c pytorch<\/span>\r\n<\/pre>\n<p>PyTorch\u3092\u52d5\u304b\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n(pytorch-env) $ <span class=\"my_fc_yellow\">python<\/span>\r\n<\/pre>\n<pre class=\"my_pre_python\">\n&gt;&gt;&gt; import torch\n&gt;&gt;&gt; device = torch.device(&#8220;cuda&#8221; if torch.cuda.is_available() else &#8220;cpu&#8221;)\n&gt;&gt;&gt; device\ndevice(type=&#8217;cpu&#8217;)\n&gt;&gt;&gt;\n&gt;&gt;&gt; a = torch.rand(10000, 10000, device=device)\n&gt;&gt;&gt; b = torch.rand(10000, 10000, device=device)\n&gt;&gt;&gt; a+b\ntensor([[1.2592, 1.5727, 1.2522,  ..., 0.8918, 1.3854, 0.4311],\n        [1.0928, 1.7651, 1.0456,  ..., 0.1744, 0.3453, 1.5659],\n        [1.0411, 1.6282, 1.3648,  ..., 1.4476, 1.6432, 1.7056],\n        ...,\n        [0.8896, 0.6764, 1.8263,  ..., 1.0261, 0.2022, 0.5871],\n        [1.0192, 0.8412, 1.0861,  ..., 0.9996, 1.0850, 1.3208],\n        [1.2890, 0.8559, 1.4905,  ..., 0.5868, 0.9619, 1.1812]])\n<\/pre>\n<p>\u30a8\u30e9\u30fc\u304c\u51fa\u305a\u306b\u52d5\u3044\u305f\uff01<br \/>\nOK\u3060\uff01<\/p>\n<h2 class=\"my_h\">Step 4\/6: PyTorch\u3092\u4f7f\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3002<\/h2>\n<p>\u904e\u53bb\u8a18\u4e8b <a href=\"https:\/\/www.dogrow.net\/nnet\/blog36%e3%80%90pytorch%e3%81%a7mnist-7%e3%80%91%e8%87%aa%e7%ad%86%e7%94%bb%e5%83%8fpng%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e8%87%aa%e5%8b%95%e8%aa%8d%e8%ad%98%e3%81%95%e3%81%9b%e3%82%8b\/\" target=\"_blank\">(36)\u3010PyTorch\u3067MNIST #7\u3011\u81ea\u7b46\u753b\u50cfPNG\u30d5\u30a1\u30a4\u30eb\u3092\u81ea\u52d5\u8a8d\u8b58\u3055\u305b\u308b\u3002<\/a> \u3067\u4f7f\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u52d5\u4f5c\u3055\u305b\u3066\u307f\u308b\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u4e00\u5f0f\u3068\u5b66\u7fd2\u6e08\u307f\u30d1\u30e9\u30e1\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u3092\u3001\u5171\u7528\u30b5\u30fc\u30d0\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u3002FileZilla\u3092\u4f7f\u3046\u3068\u4fbf\u5229\u3060\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">ll<\/span>\r\ntotal 1636\r\n-rw-rw-r-- 1 hoge hoge 1639253 Apr 26 05:16 AAA.pth\r\ndrwxrwxr-x 2 hoge hoge     148 Apr 26 05:16 Img\r\n-rw-rw-r-- 1 hoge hoge    1538 Apr 26 05:16 control_test_one_img.py\r\n-rw-rw-r-- 1 hoge hoge    1110 Apr 26 05:16 dataset_MNIST.py\r\n-rw-rw-r-- 1 hoge hoge    1409 Apr 26 05:16 net_model_CNN_01.py\r\n-rw-rw-r-- 1 hoge hoge    2725 Apr 26 05:21 trainer.py\r\n<\/pre>\n<p>Anaconda\u4e0a\u3067\u4f5c\u3063\u305f\u4eee\u60f3\u74b0\u5883\u3092\u958b\u59cb\u3059\u308b\u3002<br \/>\n\u2192 \u30d7\u30ed\u30f3\u30d7\u30c8\u306b (\u4eee\u60f3\u74b0\u5883\u540d) \u304c\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">conda activate pytorch-env<\/span>\r\n(pytorch-env) $\r\n<\/pre>\n<p>\u4e0a\u8a18\u306e\u904e\u53bb\u8a18\u4e8b\u3067\u4f5c\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/t_001_2.png\" alt=\"\" class=\"my_add_bs1 my_mgT_1rem\" style=\"width:4rem\"\/><\/p>\n<pre class=\"my_pre_bgBlack\">\r\n(pytorch-env) $ <span class=\"my_fc_yellow\">python control_test_one_img.py -p AAA.pth -i .\/Img\/t_001_2.png<\/span>\r\nModel loaded from AAA.pth\r\n\u4e88\u6e2c\u3055\u308c\u305f\u6570\u5b57\u306f: 2\r\n\u5404\u30af\u30e9\u30b9\u306e\u78ba\u7387: ['0.0', '0.0', '1.0', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0']\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/t_006_6.png\" alt=\"\" class=\"my_add_bs1 my_mgT_1rem\" style=\"width:4rem\"\/><\/p>\n<pre class=\"my_pre_bgBlack\">\r\n(pytorch-env) $ <span class=\"my_fc_yellow\">python control_test_one_img.py -p AAA.pth -i .\/Img\/t_006_6.png<\/span>\r\nModel loaded from AAA.pth\r\n\u4e88\u6e2c\u3055\u308c\u305f\u6570\u5b57\u306f: 6\r\n\u5404\u30af\u30e9\u30b9\u306e\u78ba\u7387: ['0.0', '0.0', '0.0', '0.0', '0.0', '0.0', '0.8', '0.0', '0.2', '0.0']\r\n<\/pre>\n<p>\u81ea\u5b85\u30b5\u30fc\u30d0\u3067\u306e\u5b9f\u884c\u6642\u3068\u307e\u3063\u305f\u304f\u540c\u3058\u7d50\u679c\u306b\u306a\u3063\u305f\u3002<br \/>\nOK\u3060\uff01<\/p>\n<h2 class=\"my_h\">Step 5\/6: Web\u7d4c\u7531\u3067 PyTorch\u3092\u5b9f\u884c\u3059\u308b\u3002<\/h2>\n<p>CGI\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"brush: python; title: testcgi.cgi; notranslate\" title=\"testcgi.cgi\">\r\n#!\/home\/hoge\/anaconda3\/envs\/pytorch-env\/bin\/python3.12\r\n# -*- coding: utf-8 -*-\r\n\r\nimport cgi\r\nimport torch\r\n\r\nprint(&quot;Content-Type: text\/html\\n&quot;)\r\n\r\nprint(f&quot;&quot;&quot;\r\n&lt;html&gt;\r\n  &lt;body&gt;\r\n    &lt;h1&gt;Hello from PyTorch!&lt;\/h1&gt;\r\n    &lt;p&gt;PyTorch Version: {torch.__version__}&lt;\/p&gt;\r\n    &lt;p&gt;Random Tensor: {torch.rand(2,3)}&lt;\/p&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n&quot;&quot;&quot;)\r\n<\/pre>\n<p>\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5171\u7528\u30b5\u30fc\u30d0\u306e Web\u30da\u30fc\u30b8\u516c\u958b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u3002<br \/>\nWeb\u30b5\u30fc\u30d0\u7d4c\u7531\u3067\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u5b9f\u884c\u5c5e\u6027\u3092\u4ed8\u4e0e\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_bgBlack\">\r\n$ <span class=\"my_fc_yellow\">chmod +x testcgi.cgi<\/span>\r\n<\/pre>\n<p>\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u7d4c\u7531\u3067\u3001Web\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u308b\u3002<br \/>\n<a href=\"https:\/\/www.dogrow.net\/nnet\/sample\/00039\/webtest.cgi\" target=\"_blank\">https:\/\/www.dogrow.net\/nnet\/sample\/00039\/webtest.cgi<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/Screenshot-from-2025-04-26-06-31-08.png\" alt=\"\" \/><\/a><br \/>\nOK\u3060\uff01<\/p>\n<h2 class=\"my_h\">Step 6\/6: Web\u7d4c\u7531\u3067\u9806\u4f1d\u64ad\u3092\u5b9f\u884c\u3059\u308b\u3002<\/h2>\n<p>\u3053\u3053\u307e\u3067\u306e\u6bb5\u968e\u3067\u3001Web\u30d6\u30e9\u30a6\u30b6\u7d4c\u7531\u3067\u5171\u6709\u30b5\u30fc\u30d0\u4e0a\u306e PyTorch\u3092\u5b9f\u884c\u3059\u308b\u74b0\u5883\u304c\u51fa\u6765\u305f\u3002<br \/>\n\u3044\u3088\u3044\u3088\u5927\u672c\u547d\u3001\u4e0a\u8a18 Step 4\/6 \u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092 Web\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u8d77\u52d5\u3057\u305f\u3044\u3002<\/p>\n<p>Web\u30b5\u30fc\u30d0\u7d4c\u7531\u3067\u8d77\u52d5\u3057\u305f cgi\u306e\u4e2d\u3067\u3001\u65e2\u5b58\u306e control_test_one_img.py \u306e\u4e2d\u306e\u95a2\u6570\u3092\u4f7f\u3063\u3066\u81ea\u52d5\u8a8d\u8b58\u3092\u5b9f\u73fe\u3059\u308b\u3002<br \/>\n\u53c2\u8003\uff1a <a href=\"https:\/\/www.dogrow.net\/nnet\/blog36%e3%80%90pytorch%e3%81%a7mnist-7%e3%80%91%e8%87%aa%e7%ad%86%e7%94%bb%e5%83%8fpng%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e8%87%aa%e5%8b%95%e8%aa%8d%e8%ad%98%e3%81%95%e3%81%9b%e3%82%8b\/\" target=\"_blank\">(36)\u3010PyTorch\u3067MNIST #7\u3011\u81ea\u7b46\u753b\u50cfPNG\u30d5\u30a1\u30a4\u30eb\u3092\u81ea\u52d5\u8a8d\u8b58\u3055\u305b\u308b\u3002<\/a><\/p>\n<pre class=\"brush: python; title: test1img.cgi; notranslate\" title=\"test1img.cgi\">\r\n#!\/home\/hoge\/anaconda3\/envs\/pytorch-env\/bin\/python3.12\r\n# -*- coding: utf-8 -*-\r\n\r\nprint(&quot;Content-Type: text\/html; charset=utf-8\\n&quot;)\r\n\r\npath_MNIST = &#039;\/home\/hoge\/MNIST&#039;\r\n\r\nimport sys\r\nsys.path.append(path_MNIST)\r\n\r\nimport control_test_one_img\r\nimg_path   = path_MNIST + &#039;\/Img\/t_003_8.png&#039;\r\nmodel_path = path_MNIST + &#039;\/AAA.pth&#039;\r\ncontrol_test_one_img.predict_image(img_path, model_path)\r\n<\/pre>\n<p>\u3053\u306e\u753b\u50cf\u3092\u81ea\u52d5\u8a8d\u8b58\u3055\u305b\u3066\u307f\u308b\u3068\u30fb\u30fb\u30fb<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/t_003_8.png\" alt=\"\" class=\"my_add_bs1 my_mgT_1rem\" style=\"width:4rem\"\/><br \/>\nOK\u3060\uff01 \u9806\u4f1d\u64ad\u304c\u6b63\u3057\u304f\u52d5\u3044\u305f\u3002<br \/>\n<a href=\"https:\/\/www.dogrow.net\/nnet\/sample\/00039\/test1img.cgi\" target=\"_blank\">https:\/\/www.dogrow.net\/nnet\/sample\/00039\/test1img.cgi<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/04\/Screenshot-from-2025-04-26-07-01-15.png\" alt=\"\" \/><\/a><\/p>\n<h1 class=\"my_h\">\u30104\u3011\u6240\u611f<\/h1>\n<p>\u30fbWeb\u30da\u30fc\u30b8\u7d4c\u7531\u3067\u3001\u5171\u7528\u30b5\u30fc\u30d0\u4e0a\u306e PyTorch\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3067\u304d\u305f\u3002<br \/>\n\u30fb\u6c17\u306b\u306a\u308b\u306e\u306f\u3001\u5c11\u3005\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u9045\u3044\u3053\u3068\u30fb\u30fb\u30fb<br \/>\n\u3000\u2192 <span class=\"my_fc_red\">\u9ad8\u8ca0\u8377\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a2d\u7f6e\u3092\u7406\u7531\u306b\u3001\u5171\u7528\u30b5\u30fc\u30d0\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u304c BAN\u3055\u308c\u306a\u3044\u304b\u5fc3\u914d\u3060\u3002<\/span><br \/>\n\u3000\u3000 \u7ba1\u7406\u753b\u9762\u3067\u8a3a\u65ad\u7d50\u679c\uff08CPU\u8ca0\u8377\uff09\u3092\u6ce8\u8996\u3057\u3066\u304a\u3053\u3046\u3002<\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>\u30101\u3011\u3084\u308a\u305f\u3044\u3053\u3068 \u4f8b\u3048\u3070\u3001MNIST\u81ea\u52d5\u8a8d\u8b58\u3067\u3053\u3093\u306a\u3053\u3068\u3092\u3084\u308a\u305f\u3044\u3002 \u30fb\u81ea\u5b85\u30b5\u30fc\u30d0\u30fc\u4e0a\u3067\u5b66\u7fd2\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057\u3001\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u3055\u308c\u305f\u5b66\u7fd2\u6e08\u307f\u30d1\u30e9\u30e1\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f5c\u308b\u3002 \u30fb\u3053\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u3001\u5171\u7528\u30b5\u30fc\u30d0\u4e0a\u3067 \u6570\u5b57\u306e\u81ea\u52d5\u8a8d\u8b58 \u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/nnet\/blog39-%e5%85%b1%e7%94%a8%e3%82%b5%e3%83%bc%e3%83%90%e3%81%a7pytorach%ef%bc%88%e9%a0%86%e4%bc%9d%e6%92%ad%e3%81%a0%e3%81%91%ef%bc%89%e5%ae%9f%e8%a1%8c%e3%81%97%e3%81%9f%e3%81%84%e3%80%82\/\">\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":[19,18,16],"tags":[],"class_list":["post-1253","post","type-post","status-publish","format-standard","hentry","category-cgi","category-mnist","category-pytorch"],"views":1020,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/1253","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=1253"}],"version-history":[{"count":47,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/1253\/revisions"}],"predecessor-version":[{"id":1664,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/1253\/revisions\/1664"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/media?parent=1253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/categories?post=1253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/tags?post=1253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}