{"id":1876,"date":"2018-04-28T14:03:51","date_gmt":"2018-04-28T22:03:51","guid":{"rendered":"http:\/\/antoine.wojdyla.fr\/blog\/?p=1876"},"modified":"2018-05-14T21:51:59","modified_gmt":"2018-05-15T05:51:59","slug":"art-and-science-ix-neural-networks","status":"publish","type":"post","link":"http:\/\/antoine.wojdyla.fr\/blog\/2018\/04\/28\/art-and-science-ix-neural-networks\/","title":{"rendered":"Art and science (IX) &#8211; Neural networks"},"content":{"rendered":"<p><em>This is a continuation of a <a href=\"http:\/\/antoine.wojdyla.fr\/blog\/2011\/05\/20\/lart-et-la-science-introduction\/\">series of blog posts<\/a>, written mostly in French, about <a href=\"http:\/\/antoine.wojdyla.fr\/blog\/category\/science\/art-science\/\">arts and science<\/a><\/em><\/p>In the past few years, we&#8217;ve seen the emergence of Deep Neural Networks (DNN), and the latest developments are <a href=\"https:\/\/en.wikipedia.org\/wiki\/Generative_adversarial_network\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/en.wikipedia.org\/wiki\/Generative_adversarial_network', 'Generative Adverserial Networks']);\" >Generative Adverserial Networks<\/a> (GAN), where the goal is to pit two neural networks against each other so that they find the best way to generate an object from a label or a <a href=\"https:\/\/quickdraw.withgoogle.com\/#\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/quickdraw.withgoogle.com\/#', 'simple drawing']);\" >simple drawing<\/a>, or mimick the style of an artist.<\/p>The first ripple in the vast ocean of possibility was <a href=\"https:\/\/github.com\/google\/deepdream\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/github.com\/google\/deepdream', 'Deep Dream']);\" >Deep Dream<\/a>, though it wasn&#8217;t technically a GAN:<\/p>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/DgPaCWJL7XI\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>Now, things have evolved even more, and you can not only generate trippy videos, but also use neural network to emulate the style of an artist and generate from scratch content that is indeed appealing!<\/p><!--more--><\/p>For instance, there is the <a href=\"http:\/\/magenta.tensorflow.org\/\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/magenta.tensorflow.org\/', 'Magenta Project']);\" >Magenta Project<\/a> at Google where the goal is to use DNN to augment recorded music, and improve the look and feel of computer-generated music (try out <a href=\"https:\/\/deeplearnjs.org\/demos\/performance_rnn\/index.html\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/deeplearnjs.org\/demos\/performance_rnn\/index.html', 'Perfomance RNN']);\" >Perfomance RNN<\/a>!) or create and blend melodies that do sound interesting (musicVAE):<\/p>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/G5JT16flZwM\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>Recently, GAN used on video have attracted lots of attention beacause of <a href=\"https:\/\/www.nytimes.com\/2018\/03\/04\/technology\/fake-videos-deepfakes.html\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/www.nytimes.com\/2018\/03\/04\/technology\/fake-videos-deepfakes.html', 'DeepFake']);\" >DeepFake<\/a>, where the the face of celebrities where merged with bodies of actor on pornographic footage (it seems that nowadays the abuse of good ideas goes at light speed; that&#8217;s the drawback of open source.)<\/p>Quite interesting are the GAN such as <a href=\"https:\/\/github.com\/junyanz\/CycleGAN\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/github.com\/junyanz\/CycleGAN', 'CycleGAN']);\" >CycleGAN<\/a> that apply &#8212; and\/or remove! &#8212; the style from an artist, or even allows make a horse look like a zebra in a video.<\/p>\n<div id=\"attachment_1877\" style=\"width: 711px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/antoine.wojdyla.fr\/blog\/wp-content\/uploads\/cyclegan_tests.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1877\" class=\" wp-image-1877\" src=\"http:\/\/antoine.wojdyla.fr\/blog\/wp-content\/uploads\/cyclegan_tests-1024x179.jpg\" alt=\"\" width=\"701\" height=\"122\" srcset=\"http:\/\/antoine.wojdyla.fr\/blog\/wp-content\/uploads\/cyclegan_tests-1024x179.jpg 1024w, http:\/\/antoine.wojdyla.fr\/blog\/wp-content\/uploads\/cyclegan_tests-300x52.jpg 300w, http:\/\/antoine.wojdyla.fr\/blog\/wp-content\/uploads\/cyclegan_tests-768x134.jpg 768w, http:\/\/antoine.wojdyla.fr\/blog\/wp-content\/uploads\/cyclegan_tests.jpg 1510w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><\/a><\/p>\n<p id=\"caption-attachment-1877\" class=\"wp-caption-text\">My attempts at using CycleGAN on some views from Berkeley hills, with ukiyo-e styling, Monet styling, Cezanne styling and Van Gogh styling (with a dash of shame)<\/p>\n<\/div><p>(you can try on your own using the instructions listed further in the post)<\/p>The latest thing is to not only recreate the style, but also <strong>the technique<\/strong> of an artist, but teaching a robot to make brush strokes, such as in the <a href=\"https:\/\/deepmind.com\/blog\/learning-to-generate-images\/\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/deepmind.com\/blog\/learning-to-generate-images\/', 'DeepMind SPIRAL']);\" >DeepMind SPIRAL<\/a> work.<\/p>I was really excited to learn that there will be many events in the Bay Area on Arts and Science, as part of the <a href=\"http:\/\/aftertomorrow2018.com\/\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/aftertomorrow2018.com\/', 'After tomorrow']);\" >After tomorrow<\/a> project &#8212; I hope to see many interesting things there:)<\/p>\n<p style=\"text-align: center;\">* \u00a0\u00a0 *<br \/>\n*<\/p>\n<h3>Installing Torch with CUDA and cuDNN on a MacBook Pro<\/h3><p>Here are some tricks to install <strong>CUDA 9.1<\/strong> and <strong>CuDNN 7.05<\/strong> to run the graphics card acceleration for <strong>Torch 7<\/strong> on a MacBook Pro (Early 2014, version 11,3) with a <strong>nvidia GeForce GT 750M <\/strong>graphics card and <strong>Mac OS X 10.13.3 High Sierra<\/strong> (to tell which version you have, you need to go to \uf8ff\/Apple menu on the top left of your screen, then enter the &#8220;About this Mac menu&#8221; and click on system report.) Since this is a fairly old version, I assume that this might be of help to many people with more recent computers, the idea is to show how to jump through all the hoops to use it on High Sierra.<\/p>First, you need to <strong>update your drivers<\/strong> to at least <strong>nVidia GeForce 387.10.10.25.161<\/strong> (you can go to System Preferences\/NVIDIA Driver Manager pane and check for updates, or you can try to get them <a href=\"http:\/\/www.nvidia.com\/download\/driverResults.aspx\/131833\/en-us\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.nvidia.com\/download\/driverResults.aspx\/131833\/en-us', 'here']);\" >here<\/a>)<\/p>Then you need to <a href=\"https:\/\/developer.nvidia.com\/cuda-downloads?target_os=MacOSX&target_arch=x86_64&target_version=1013\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/developer.nvidia.com\/cuda-downloads?target_os=MacOSX&amp;target_arch=x86_64&amp;target_version=1013', 'download']);\" >download<\/a> and install <strong>CUDA 9.1 for MacOS X 10.3 64bits<\/strong>.<\/p>Next, you will need to <a href=\"https:\/\/developer.nvidia.com\/rdp\/cudnn-download\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/developer.nvidia.com\/rdp\/cudnn-download', 'download']);\" >download<\/a> <strong>CuDNN 7.0.5 for CUDA 9.1 on MacOS X<\/strong>. To do so, you will probably have to\u00a0register to NVIDIA developer website. It&#8217;s important that you make sure you get the proper version; the one that supports CUDA 9.1; also not the Linux version, and not the latest which right now doesn&#8217;t support MacOS X; here&#8217;s a direct link to the download if you&#8217;re already logged in: <a href=\"https:\/\/developer.nvidia.com\/compute\/machine-learning\/cudnn\/secure\/v7.0.5\/prod\/9.1_20171129\/cudnn-9.1-osx-x64-v7-ga\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/developer.nvidia.com\/compute\/machine-learning\/cudnn\/secure\/v7.0.5\/prod\/9.1_20171129\/cudnn-9.1-osx-x64-v7-ga', 'CuDNN 7.0.5 for CUDA 9.1 on MacOS X 64bits']);\" >CuDNN 7.0.5 for CUDA 9.1 on MacOS X 64bits<\/a>)<\/p>Then, you can follow the <a href=\"http:\/\/docs.nvidia.com\/deeplearning\/sdk\/cudnn-install\/index.html\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/docs.nvidia.com\/deeplearning\/sdk\/cudnn-install\/index.html', 'instruction listed here']);\" >instruction listed here<\/a>, or try something along this line in the terminal, to bring the download files to a place where they belong, and adding a new PATH to your environment:<\/p>\n<blockquote><p><code>tar -zxf cudnn-9.1-osx-x64-v7-ga.tgz<br \/>\nsudo cp cuda\/include\/cudnn.h \/usr\/local\/cuda\/include<br \/>\nsudo cp cuda\/lib64\/libcudnn* \/usr\/local\/cuda\/lib<br \/>\nsudo chmod a+r \/usr\/local\/cuda\/include\/cudnn.h \/usr\/local\/cuda\/lib\/libcudnn*<br \/>\nexport CUDNN_PATH=\/usr\/local\/cuda\/lib\/libcudnn.7.dylib<\/code><\/p><\/blockquote><p>Then installation you should be able to <a href=\"https:\/\/github.com\/torch\/distro\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/github.com\/torch\/distro', 'install Torch']);\" >install Torch<\/a> (there&#8217;s a <a href=\"http:\/\/torch.ch\/docs\/getting-started.html#\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/torch.ch\/docs\/getting-started.html#', 'guide here']);\" >guide here<\/a> to help you.)<\/p><em>Make sure you have the latest XCode Command Line tools (type <code>xcode-select --install<\/code>in the terminal) , and <a href=\"https:\/\/brew.sh\/\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/brew.sh\/', 'brew']);\" >brew<\/a> (type <code id=\"selectable\">\/usr\/bin\/ruby -e \"$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/master\/install)\"<\/code>).<\/em><\/p>Basically now what you need to do type this in your terminal (assuming you have git)<\/p>\n<blockquote><p><code>git clone https:\/\/github.com\/torch\/distro.git ~\/torch --recursive<\/code><\/p><\/blockquote><p><span style=\"text-decoration: underline;\">BEFORE YOUR START THE INSTALL<\/span>, you will need to modify THCTensorRandom.cuh because it has a small tweak thing prevents it from compiling. You will need to search the file on your computer (mine is located at \/Users\/awojdyla\/torch\/extra\/cutorch\/lib\/THC\/THCTensorRandom.cuh), and remove the <code>__align__<\/code> string at two locations, otherwise your compilator will scream.<\/p>There&#8217;s also a fix that you might need to apply to make the compilation work:<\/p><code>git clone https:\/\/github.com\/soumith\/cudnn.torch.git -b R7 && cd cudnn.torch && luarocks make cudnn-scm-1.rockspec<\/code><\/p>Then you can run the following lines and go get a cup of tea with your friends<\/p>\n<blockquote><p><code>cd ~\/torch; bash install-deps;<br \/>\n.\/clean<br \/>\nexport TORCH_NVCC_FLAGS=\"-D__CUDA_NO_HALF_OPERATORS__\"<br \/>\n.\/install.sh<\/code><\/p><\/blockquote><p>finally type<br \/>\n<code>.\/Users\/ [you user name] \/torch\/install\/bin\/torch-activate<\/code><\/p>and you should be able to run Torch (type <code>th<\/code> in your terminal to see if this works.)<\/p>Now you&#8217;re ready to use Torch anf cool stuff such as <a href=\"https:\/\/github.com\/junyanz\/CycleGAN\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/github.com\/junyanz\/CycleGAN', 'CycleGAN']);\" >CycleGAN<\/a><\/p>(it seems there is another helper available <a href=\"https:\/\/gist.github.com\/geekcui\/d0800d62e377e0103b1cc2b889ed1128\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'https:\/\/gist.github.com\/geekcui\/d0800d62e377e0103b1cc2b889ed1128', 'here']);\" >here<\/a>)<\/p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a continuation of a series of blog posts, written mostly in French, about arts and scienceIn the past few years, we&#8217;ve seen the emergence of Deep Neural Networks (DNN), and the latest developments are Generative Adverserial Networks (GAN), where the goal is to pit two neural networks against each other so that they [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,11,14,16],"tags":[],"class_list":["post-1876","post","type-post","status-publish","format-standard","hentry","category-art-science","category-english","category-projects","category-resources"],"_links":{"self":[{"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/posts\/1876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/comments?post=1876"}],"version-history":[{"count":3,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/posts\/1876\/revisions"}],"predecessor-version":[{"id":1880,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/posts\/1876\/revisions\/1880"}],"wp:attachment":[{"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/media?parent=1876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/categories?post=1876"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/tags?post=1876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}