{"id":744,"date":"2018-10-19T02:31:17","date_gmt":"2018-10-18T17:31:17","guid":{"rendered":"http:\/\/www.ecobioinfo.com\/?p=744"},"modified":"2022-06-05T22:52:51","modified_gmt":"2022-06-05T13:52:51","slug":"%e6%b7%b1%e5%b1%a4%e5%ad%a6%e7%bf%92%e3%80%80ubuntu-18-04-%e3%81%ab-tensorflow-gpu-%e3%82%92%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab","status":"publish","type":"post","link":"http:\/\/www.ecobioinfo.com\/?p=744","title":{"rendered":"\u6df1\u5c64\u5b66\u7fd2\u3000Ubuntu 18.04 \u306b Tensorflow GPU \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb"},"content":{"rendered":"<p>\uff08\u300c<a href=\"https:\/\/www.ecobioinfo.com\/?p=733\">\u6df1\u5c64\u5b66\u7fd2\u3000Ubuntu 18.04 \u306b Tensorflow \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a>\u300d\u306e\u7d9a\u304d\uff09<\/p>\n<p>Ubuntu 18.04 \u7528\u306e CUDA + cuDNN + Tensorflow GPU \u306f\u3001\u73fe\u6642\u70b9\uff082018\/10\/18\uff09\u3067\u307e\u3060\u516c\u5f0f\u306b\u306f\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u3089\u3057\u3044\u306e\u3067\u3001\u3068\u308a\u3042\u3048\u305a Ubuntu 17 \u7528\u306e CUDA 9 + cuDNN 7 \u3067 Tensorflow GPU 1.8 \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>(1) PC \u306e Secure boot \u306e\u7121\u52b9\u5316<\/p>\n<p>Secure boot \u6a5f\u80fd\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306e\u90aa\u9b54\u306b\u306a\u3063\u3066\u3044\u308b\u3089\u3057\u3044\u306e\u3067\u3001<br \/>\n\u8d77\u52d5\u6642\u306b Delete \u30ad\u30fc\u3092\u9023\u6253\u3057\u3066 Bios \u753b\u9762\u3092\u8d77\u52d5\u3001Security \u306e\u30bf\u30d6\u3067 Secure boot \u6a5f\u80fd\u3092 Disable \u306b\u8a2d\u5b9a\u3002<\/p>\n<p>(2) \u30c9\u30e9\u30a4\u30d0\u306e\u518d\u8a2d\u5b9a<\/p>\n<p>\u30c9\u30e9\u30a4\u30d0\u3092\u66f4\u65b0\u3057\u307e\u3059\u3002<\/p>\n<p>~$ sudo add-apt-repository ppa:graphics-drivers\/ppa<br \/>\n~$ sudo apt update<br \/>\n~$ sudo apt install nvidia-390 nvidia-390-dev<\/p>\n<p>\u518d\u8d77\u52d5<\/p>\n<p>\u5143\u306e\u30c9\u30e9\u30a4\u30d0(nouveau)\u304c\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3002<\/p>\n<p>~$ lsmod | grep -i nouveau<br \/>\n~$<\/p>\n<p>NVIDIA\u30c9\u30e9\u30a4\u30d0\u3092\u78ba\u8a8d<br \/>\n~$ nvidia-smi<br \/>\nFri Oct 19 01:08:22 2018<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| NVIDIA-SMI 390.87 Driver Version: 390.87 |<br \/>\n|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |<br \/>\n| Fan Temp Perf Pwr:Usage\/Cap| Memory-Usage | GPU-Util Compute M. |<br \/>\n|===============================+======================+======================|<br \/>\n| 0 GeForce GTX 960 Off | 00000000:01:00.0 On | N\/A |<br \/>\n| 20% 37C P5 19W \/ 160W | 179MiB \/ 4035MiB | 0% Default |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| Processes: GPU Memory |<br \/>\n| GPU PID Type Process name Usage |<br \/>\n|=============================================================================|<br \/>\n| 0 1238 G \/usr\/lib\/xorg\/Xorg 12MiB |<br \/>\n| 0 1280 G \/usr\/bin\/gnome-shell 48MiB |<br \/>\n| 0 1534 G \/usr\/lib\/xorg\/Xorg 53MiB |<br \/>\n| 0 1672 G \/usr\/bin\/gnome-shell 61MiB |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/p>\n<p>(3) CUDA \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<p>https:\/\/developer.nvidia.com\/cuda-toolkit-archive<br \/>\nUbuntu 17.04 \u306e CUDA 9.0 \u3092\u9078\u629e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<br \/>\nLinux -&gt; x86_64 -&gt; Ubuntu -&gt; 17.04 -&gt; deb (local) -&gt; Base Installer<\/p>\n<p>~$ sudo dpkg -i cuda-repo-ubuntu1704-9-0-local_9.0.176-1_amd64.deb<br \/>\n~$ sudo apt-key add \/var\/cuda-repo-9-0-local\/7fa2af80.pub<br \/>\n~$ sudo apt-get update<br \/>\n~$ sudo apt-get install cuda-9-0<\/p>\n<p>(4) cuDNN \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<p>https:\/\/developer.nvidia.com\/rdp\/cudnn-download<br \/>\nCUDA 9.0 \u7528\u306e cuDNN 7.1.3 \u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3002<\/p>\n<p>~$ sudo dpkg -i libcudnn7_7.1.3.16-1+cuda9.0_amd64.deb<br \/>\n~$ sudo dpkg -i libcudnn7-dev_7.1.3.16-1+cuda9.0_amd64.deb<br \/>\n~$ sudo dpkg -i libcudnn7-doc_7.1.3.16-1+cuda9.0_amd64.deb<\/p>\n<p>\u30d1\u30b9\u8a2d\u5b9a<br \/>\n~$ vi .bashrc<br \/>\n\u30fb\u30fb\u30fb<br \/>\nexport PATH=\u201d\/usr\/local\/cuda-9.0\/bin:$PATH\u201d<br \/>\nexport LD_LIBRARY_PATH=\u201d\/usr\/local\/cuda\/lib64:$LD_LIBRARY_PATH\u201d<\/p>\n<p>~$ source .bashrc<\/p>\n<p>libcupti \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<br \/>\n~$ sudo apt-get install libcupti-dev<\/p>\n<p>(5) Tensorflow GPU \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<p>\u4ee5\u524d\u306etensorflow\u3092\u6d88\u3059\u3002<br \/>\n~$ pip3 uninstall tensorflow<\/p>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<br \/>\n~$ pip3 install &#8211;upgrade tensorflow-gpu==1.8.0<br \/>\n~$ pip3 install &#8211;upgrade tflearn<br \/>\n~$ pip3 install &#8211;upgrade keras<\/p>\n<p>(\u518d\u8d77\u52d5)<\/p>\n<p>\u78ba\u8a8d<br \/>\n~$ python<br \/>\n&gt;&gt;&gt; import tensorflow<br \/>\n&gt;&gt;&gt; import tflearn<br \/>\n&gt;&gt;&gt; import keras<br \/>\nUsing TensorFlow backend.<br \/>\n&gt;&gt;&gt;<\/p>\n<p>GPU\u306e\u78ba\u8a8d<\/p>\n<p>&gt;&gt;&gt; from tensorflow.python.client import device_lib<br \/>\n&gt;&gt;&gt; device_lib.list_local_devices()<\/p>\n<p>incarnation: 8298168254807972213<br \/>\n, name: &#8220;\/device:GPU:0&#8221;<br \/>\ndevice_type: &#8220;GPU&#8221;<br \/>\nmemory_limit: 3606380544<br \/>\nlocality {<br \/>\nbus_id: 1<br \/>\nlinks {<br \/>\n}<br \/>\n}<br \/>\nincarnation: 2748502406460115902<br \/>\nphysical_device_desc: &#8220;device: 0, name: GeForce GTX 960, pci bus id: 0000:01:00.0, compute capability: 5.2&#8221;<\/p>\n<p>(6) \u52d5\u4f5c\u78ba\u8a8d<\/p>\n<p><a href=\"https:\/\/www.ecobioinfo.com\/?p=464\">\u300c\u6df1\u5c64\u5b66\u7fd2 TensorFlow \u3092 MNIST \u3067\u8a66\u3059<\/a>\u300d \u306e\u30bd\u30fc\u30b9\u3067\u30c6\u30b9\u30c8\u3002<\/p>\n<p>| SGD | epoch: 020 | loss: 0.51773 &#8211; acc: 0.9417 | val_loss: 0.07854 &#8211; val_acc: 0.9780 &#8212; iter: 49500\/49500<br \/>\n&#8212;<br \/>\nlearning start:2018-10-19 01:27:50.571832<br \/>\nlearning end:\u20192018-10-19 01:29:11.786083<br \/>\npredict start:2018-10-19 01:29:11.786196<br \/>\npredict end:2018-10-19 01:29:11.849480<br \/>\n[7 2 1 &#8230; 4 5 6]<br \/>\n[7 2 1 &#8230; 4 5 6]<br \/>\n0.9793<\/p>\n<p>\u30a8\u30e9\u30fc\u306a\u3057\u3002<\/p>\n<p><a href=\"http:\/\/www.ecobioinfo.com\/?p=582\">\u300c\u6df1\u5c64\u5b66\u7fd2\u3000Keras\uff08TensorFlow\u7528\uff09\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a>\u300d \u306e\u30bd\u30fc\u30b9\u3067\u30c6\u30b9\u30c8\u3002<\/p>\n<p>Epoch 20\/20<br \/>\n54000\/54000 [==============================] &#8211; 1s 19us\/step &#8211; loss: 0.2495 &#8211; acc: 0.9289 &#8211; val_loss: 0.1574 &#8211; val_acc: 0.9600<br \/>\n[7 2 1 &#8230; 4 5 6]<br \/>\n[7 2 1 &#8230; 4 5 6]<br \/>\n0.949<\/p>\n<p>\u30a8\u30e9\u30fc\u306a\u3057\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a<\/p>\n<p>\u3010\u53c2\u8003\u6587\u732e\u3011\u3053\u306e\u30d6\u30ed\u30b0\u306e\u53c2\u8003\u66f8\u7c4d\u306f\u3053\u3061\u3089\u306b\u307e\u3068\u3081\u3066\u3042\u308a\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/www.ecobioinfo.com\/?page_id=838\">http:\/\/www.ecobioinfo.com\/?page_id=838<\/a><\/p>\n<p>\uff082018\/10\/19 S.Onda\uff09<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"\uff08\u300c\u6df1\u5c64\u5b66\u7fd2\u3000Ubuntu 18.04 \u306b Tensorflow \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u300d\u306e\u7d9a\u304d\uff09 Ubuntu 18.04 \u7528\u306e CUDA + cuDNN + Tensorflow GPU \u306f\u3001\u73fe\u6642\u70b9\uff082018\/10\/18\uff09\u3067 &#8230;","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-744","post","type-post","status-publish","format-standard","hentry","category-ai_ecobio"],"_links":{"self":[{"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=\/wp\/v2\/posts\/744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=744"}],"version-history":[{"count":11,"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=\/wp\/v2\/posts\/744\/revisions"}],"predecessor-version":[{"id":1494,"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=\/wp\/v2\/posts\/744\/revisions\/1494"}],"wp:attachment":[{"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=744"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ecobioinfo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}