{"id":217,"date":"2020-04-14T14:56:19","date_gmt":"2020-04-14T14:56:19","guid":{"rendered":"https:\/\/marcelhaas.com\/?p=217"},"modified":"2020-04-14T14:56:19","modified_gmt":"2020-04-14T14:56:19","slug":"using-a-graphics-card-for-neural-networks","status":"publish","type":"post","link":"https:\/\/marcelhaas.com\/index.php\/2020\/04\/14\/using-a-graphics-card-for-neural-networks\/","title":{"rendered":"Using a graphics card for neural networks"},"content":{"rendered":"\n<p>Just a short blurb of text today, because I ran into an issue that ever so slightly annoyed me last weekend. I had bought an old second-hand desktop machine lately, because I wanted to try out a couple of things that are not particularly useful on a laptop (having a server to log on to\/<a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Secure_Shell\" target=\"_blank\">ssh <\/a>into, host my own <a rel=\"noreferrer noopener\" href=\"https:\/\/jupyter.org\/hub\" target=\"_blank\">Jupyter Hub<\/a>, doing some I\/O-heavy things with images from the internet, etc.). One more thing I wanted to try was using <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/TensorFlow\" target=\"_blank\">TensorFlow<\/a> with a GPU in your machine. The idea was to check out whether this indeed is as simple as just installing tensorflow-gpu (note that in versions newer than 1.15 of tensorflow, there is no need to install CPU and GPU capabilities separately) and the software would figure out itself whether or not to use the GPU.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/1\/11\/TensorFlowLogo.svg\/1280px-TensorFlowLogo.svg.png\" alt=\"\" width=\"281\" height=\"234\"\/><figcaption>Then TensorFlow logo, taken from the Wikipedia site linked above.<\/figcaption><\/figure><\/div>\n\n\n\n<p>&#8220;TensorFlow is a <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Free_software\" target=\"_blank\">free<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Open-source_software\" target=\"_blank\">open-source<\/a> <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Library_(computing)\" target=\"_blank\">software library<\/a> for <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Dataflow_programming\" target=\"_blank\">dataflow<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Differentiable_programming\" target=\"_blank\">differentiable<\/a> programming across a range of tasks. It is a symbolic math library, and is also used for <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Machine_learning\" target=\"_blank\">machine learning<\/a> applications such as <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Neural_networks\" target=\"_blank\">neural networks<\/a>. It is used for both research and production at <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Google\" target=\"_blank\">Google<\/a>.\u200d&#8221; (source: <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/TensorFlow\" target=\"_blank\">Wikipedia<\/a>)<\/p>\n\n\n\n<p>I use it mostly with the lovely <a href=\"https:\/\/keras.io\/\">Keras<\/a> API, which allows easy set-up of neural networks in TensorFlow. I have used it, for example (disclaimer: old code&#8230;) in a <a rel=\"noreferrer noopener\" href=\"https:\/\/marcelhaas.com\/index.php\/2019\/02\/10\/beyond-the-recognition-of-handwritten-digits\/\" target=\"_blank\">blog post<\/a> titled &#8220;Beyond the recognition of handwritten digits&#8221;.<\/p>\n\n\n\n<p>It turned out that TensorFlow will indeed do this for you, but not with just <em>any<\/em> graphics card. I have an NVIDIA GeForce GT 620. This is quite an old model indeed, but it still has 96 CUDA cores and a gigabyte of memory. Sounded good to me. After loading tensorflow from a Python session you can have it detect the graphics card, so you know it can be used for the calculations: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"94\" src=\"https:\/\/marcelhaas.com\/wp-content\/uploads\/2020\/04\/tensorflow_gpu.png\" alt=\"\" class=\"wp-image-219\" srcset=\"https:\/\/marcelhaas.com\/wp-content\/uploads\/2020\/04\/tensorflow_gpu.png 748w, https:\/\/marcelhaas.com\/wp-content\/uploads\/2020\/04\/tensorflow_gpu-300x38.png 300w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><figcaption>This is a screenshot of a console in Jupyter Lab.<\/figcaption><\/figure>\n\n\n\n<p>As you can see, it did not detect a graphics card&#8230;. There is a hint in a terminal session that is behind my jupyter session though: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"961\" height=\"57\" src=\"https:\/\/marcelhaas.com\/wp-content\/uploads\/2020\/04\/tensorflow_terminalsession.png\" alt=\"\" class=\"wp-image-220\" srcset=\"https:\/\/marcelhaas.com\/wp-content\/uploads\/2020\/04\/tensorflow_terminalsession.png 961w, https:\/\/marcelhaas.com\/wp-content\/uploads\/2020\/04\/tensorflow_terminalsession-300x18.png 300w, https:\/\/marcelhaas.com\/wp-content\/uploads\/2020\/04\/tensorflow_terminalsession-768x46.png 768w\" sizes=\"auto, (max-width: 961px) 100vw, 961px\" \/><figcaption>Aplogies for the sub-optimal reading experience here&#8230;.<\/figcaption><\/figure>\n\n\n\n<p>Apparently, the <strong>cuda compute capability<\/strong> of my graphics card is lower than it should be. Only cards with cuda capability of 3.5 or higher will work (I know the terminal says 3.0, but the documentation says 3.5). On <a rel=\"noreferrer noopener\" href=\"https:\/\/developer.nvidia.com\/cuda-gpus\" target=\"_blank\">this NVIDIA page<\/a>, there is a list of their cards and the corresponding cuda capabilities. Pleas check that out before trying to run TensorFlow on it (and before getting frustrated). And when you consider buying a (second-hand?) graphics card to play with, definitely make sure you buy a useful one!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just a short blurb of text today, because I ran into an issue that ever so slightly annoyed me last weekend. I had bought an old second-hand desktop machine lately, because I wanted to try out a couple of things that are not particularly useful on a laptop (having a server to log on to\/ssh &hellip; <a href=\"https:\/\/marcelhaas.com\/index.php\/2020\/04\/14\/using-a-graphics-card-for-neural-networks\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using a graphics card for neural networks<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[44,39,41,45,42,40,38],"class_list":["post-217","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cuda-compute-capability","tag-gpu","tag-graphics-card","tag-hardware","tag-neural-network","tag-nvidia","tag-tensorflow"],"_links":{"self":[{"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":2,"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"predecessor-version":[{"id":221,"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/posts\/217\/revisions\/221"}],"wp:attachment":[{"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marcelhaas.com\/index.php\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}