{"id":8352,"date":"2017-01-13T09:00:44","date_gmt":"2017-01-13T14:00:44","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=8352"},"modified":"2018-09-14T06:50:47","modified_gmt":"2018-09-14T10:50:47","slug":"deep-learning-in-11-lines","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2017\/01\/13\/deep-learning-in-11-lines\/","title":{"rendered":"Deep Learning in 11 Lines"},"content":{"rendered":"<div class=\"content\">\n<p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871\">Jiro<\/a>&#8216;s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/60659-deep-learning-in-11-lines-of-matlab-code\">Deep Learning in 11 Lines of MATLAB Code<\/a> by the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/8743315\">MathWorks Deep Learning Toolbox Team<\/a>.<\/p>\n<p>This is for anyone who would like to dabble in deep learning with minimal effort. There&#8217;s also a <a href=\"https:\/\/www.mathworks.com\/videos\/deep-learning-in-11-lines-of-matlab-code-1481229977318.html\">short video<\/a> of this in action by one of our senior developers. Note that this sample code requires R2016b or newer, the <a href=\"https:\/\/www.mathworks.com\/products\/deep-learning.html\">Deep Learning Toolbox<\/a>, and the <a href=\"https:\/\/www.mathworks.com\/products\/image.html\">Image Processing Toolbox<\/a>. Deep Learning Toolbox is a must to use the trained network, but Image Processing Toolbox is used for image resizing in this example. In addition, you need to download\/install the freely available packages for connecting to a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45182-matlab-support-package-for-usb-webcams\">webcam<\/a> and a pre-trained convolutional neural network (CNN) called <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59133\">AlexNet<\/a>. Both of these can be easily obtained from the <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/matlab_env\/get-add-ons.html (link no longer works)\">Add-On Explorer<\/a>.<\/p>\n<p>With R2016b, you get some really nice features in the area of deep learning.<\/p>\n<div>\n<ol>\n<li>CNNs used to require a supported GPU, but now you can run a trained network to extract features, make predictions, and classify on a CPU. GPU is still recommended for a much better performance.<\/li>\n<li>Training a network is a lot of work and time-consuming. Now, you can download a pre-trained network, called AlexNet, to extract features or to adapt to your own problem set, which is referred to as transfer learning.<\/li>\n<\/ol>\n<\/div>\n<p>Just as this entry promises, I was able to do some deep learning on a live image coming in from my webcam, just in 11 lines of MATLAB code.<\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_deeplearning11\/potw_deeplearning_coffeemug.png\" alt=\"\"> <\/p>\n<p>Seems like I have a coffee mug! :)<\/p>\n<p><b>Comments<\/b><\/p>\n<p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=8352#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/60659-deep-learning-in-11-lines-of-matlab-code#comments\">comment<\/a> for the Deep Learning Team.<\/p>\n<p><script language=\"JavaScript\"> <!-- \n    function grabCode_2c12ea51bd784d7b9f76c1e6c58d8cd6() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='2c12ea51bd784d7b9f76c1e6c58d8cd6 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 2c12ea51bd784d7b9f76c1e6c58d8cd6';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        copyright = 'Copyright 2017 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\n\n\\n');\n\n        d.title = title + ' (MATLAB code)';\n        d.close();\n    }   \n     --> <\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><a href=\"javascript:grabCode_2c12ea51bd784d7b9f76c1e6c58d8cd6()\"><span style=\"font-size: x-small;        font-style: italic;\">Get<br \/>\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p class=\"footer\">\n      Published with MATLAB&reg; R2016b<\/p>\n<\/div>\n<p><!--\n2c12ea51bd784d7b9f76c1e6c58d8cd6 ##### SOURCE BEGIN #####\n%%\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871 Jiro>'s\n% pick this week is\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/60659-deep-learning-in-11-lines-of-matlab-code Deep Learning\n% in 11 Lines of MATLAB Code> by the\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/8743315\n% MathWorks Deep Learning Toolbox Team>.\n%\n% This is for anyone who would like to dabble in deep learning with minimal\n% effort. There's also a\n% <https:\/\/www.mathworks.com\/videos\/deep-learning-in-11-lines-of-matlab-code-1481229977318.html\n% short video> of this in action by one of our senior developers. Note that\n% this sample code requires R2016b or newer, the\n% <https:\/\/www.mathworks.com\/products\/deep-learning.html Deep Learning\n% Toolbox>, and the <https:\/\/www.mathworks.com\/products\/image.html Image\n% Processing Toolbox>. Deep Learning Toolbox is a must to use the trained\n% network, but Image Processing Toolbox is used for image resizing in this\n% example. In addition, you need to download\/install the freely available\n% packages for connecting to a\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/45182-matlab-support-package-for-usb-webcams webcam> and a\n% pre-trained convolutional neural network (CNN) called\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59133 AlexNet>.\n% Both of these can be easily obtained from the\n% <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/matlab_env\/get-add-ons.html\n% Add-On Explorer>.\n% \n% With R2016b, you get some really nice features in the area of deep\n% learning.\n%\n% # CNNs used to require a supported GPU, but now you can run a trained\n% network to extract features, make predictions, and classify on a CPU. GPU\n% is still recommended for a much better performance.\n% # Training a network is a lot of work and time-consuming. Now, you can\n% download a pre-trained network, called AlexNet, to extract features or to\n% adapt to your own problem set, which is referred to as transfer learning.\n%\n% Just as this entry promises, I was able to do some deep learning on a\n% live image coming in from my webcam, just in 11 lines of MATLAB code.\n%\n% <<potw_deeplearning_coffeemug.png>>\n%\n% Seems like I have a coffee mug! :)\n%\n% *Comments*\n%\n% Give it a try and let us know what you think\n% <https:\/\/blogs.mathworks.com\/pick\/?p=8352#respond here> or leave a\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/60659-deep-learning-in-11-lines-of-matlab-code#comments comment> for the NNet Team.\n\n##### SOURCE END ##### 2c12ea51bd784d7b9f76c1e6c58d8cd6\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_deeplearning11\/potw_deeplearning_coffeemug.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>\nJiro&#8216;s pick this week is Deep Learning in 11 Lines of MATLAB Code by the MathWorks Deep Learning Toolbox Team.<br \/>\nThis is for anyone who would like to dabble in deep learning with minimal effort&#8230;. <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2017\/01\/13\/deep-learning-in-11-lines\/\">read more >><\/a><\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/8352"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=8352"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/8352\/revisions"}],"predecessor-version":[{"id":10129,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/8352\/revisions\/10129"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=8352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=8352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=8352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}