{"id":229,"date":"2016-03-21T10:59:35","date_gmt":"2016-03-21T10:59:35","guid":{"rendered":"http:\/\/liipetti.net\/erratic\/?p=229"},"modified":"2018-05-06T09:41:38","modified_gmt":"2018-05-06T09:41:38","slug":"using-nin-imagenet-conv-in-neural-style","status":"publish","type":"post","link":"http:\/\/liipetti.net\/erratic\/2016\/03\/21\/using-nin-imagenet-conv-in-neural-style\/","title":{"rendered":"Using nin-imagenet-conv in neural-style"},"content":{"rendered":"<p>Many people appear to have problems getting neural-style to run, and this is often related to the fact that they try to use it with limited memory such as 2GB. My own tests indicate that neural-style, when used with the default VGG19 network, requires at least 3 GB memory. Lowering image_size does not help, as there is a memory peak during initialization which appears to be unrelated to the image_size. My tests have been conducted using CPU, so results may vary when using a GPU, but in practice it still seems getting neural-style with VGG19 to run with only 2GB memory does not work.<\/p>\n<p>There is an alternative to VGG19, nin-imagenet-conv, which runs quite comfortably even under 2GB of memory. You can download the files from<a href=\"https:\/\/drive.google.com\/folderview?id=0B0IedYUunOQINEFtUi1QNWVhVVU&amp;usp=drive_web\" target=\"_blank\"> https:\/\/drive.google.com\/folderview?id=0B0IedYUunOQINEFtUi1QNWVhVVU&amp;usp=drive_web<\/a> . Download nin_imagenet_conv.caffemodel and train_val.prototxt into your models\/ folder.<\/p>\n<p>You can then run neural-style as follows (adjust the -gpu parameter if you want to run using GPU):<\/p>\n<pre>th neural_style.lua -gpu -1 -print_iter 1 -save_iter 50 -num_iterations 2000 -image_size 512\u00a0 -output_image nintest.png -model_file models\/nin_imagenet_conv.caffemodel -proto_file models\/train_val.prototxt -content_layers relu7 -style_layers relu1,relu3,relu5,relu7,relu9<\/pre>\n<p>On my CPU, this will only use around 0.8GB reserved memory and produces the following image in 1000 iterations.<\/p>\n<p><a href=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316b_1000.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-238\" src=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316b_1000-300x225.png\" alt=\"nintest210316b_1000\" width=\"300\" height=\"225\" srcset=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316b_1000-300x225.png 300w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316b_1000-200x150.png 200w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316b_1000-150x113.png 150w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316b_1000.png 512w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Increasing image_size to 960 still runs in under 3GB and produces the following picture in 1000 iterations.<\/p>\n<p><a href=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316a_1000.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-230\" src=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316a_1000-300x225.png\" alt=\"nintest210316a_1000\" width=\"300\" height=\"225\" srcset=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316a_1000-300x225.png 300w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316a_1000-200x150.png 200w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316a_1000-150x113.png 150w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316a_1000.png 960w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The content and style weights can be changed as usual. Likewise one can experiment with the layers: relu1,relu2,relu3,relu5 (no relu4),relu6,relu7,relu8,relu9,relu10,relu11,relu12. Running the first try again, image_size=512 but content layer relu3, we get in 1200 iterations while using only slightly more than 0.8GB memory.<\/p>\n<p><a href=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316c3-b_1200.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-244\" src=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316c3-b_1200-300x225.png\" alt=\"nintest210316c3-b_1200\" width=\"300\" height=\"225\" srcset=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316c3-b_1200-300x225.png 300w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316c3-b_1200-200x150.png 200w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316c3-b_1200-150x113.png 150w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/nintest210316c3-b_1200.png 512w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Many different results are possible by tweaking the parameters. The results will not be identical to those achieved with VGG19 but they should still be interesting and useful.<\/p>\n<p><a href=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c10_s4800_1000.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-235\" src=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c10_s4800_1000-300x225.png\" alt=\"out_nin800c7s1279_c10_s4800_1000\" width=\"300\" height=\"225\" srcset=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c10_s4800_1000-300x225.png 300w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c10_s4800_1000-200x150.png 200w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c10_s4800_1000-150x113.png 150w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c10_s4800_1000.png 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s4800_550.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-237\" src=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s4800_550-300x225.png\" alt=\"out_nin800c7s1279_c50_s4800_550\" width=\"300\" height=\"225\" srcset=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s4800_550-300x225.png 300w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s4800_550-200x150.png 200w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s4800_550-150x113.png 150w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s4800_550.png 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s900_1000.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-236\" src=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s900_1000-300x225.png\" alt=\"out_nin800c7s1279_c50_s900_1000\" width=\"300\" height=\"225\" srcset=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s900_1000-300x225.png 300w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s900_1000-200x150.png 200w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s900_1000-150x113.png 150w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin800c7s1279_c50_s900_1000.png 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin512c7s1279_c50_s300_1000.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-233\" src=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin512c7s1279_c50_s300_1000-300x225.png\" alt=\"out_nin512c7s1279_c50_s300_1000\" width=\"300\" height=\"225\" srcset=\"http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin512c7s1279_c50_s300_1000-300x225.png 300w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin512c7s1279_c50_s300_1000-200x150.png 200w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin512c7s1279_c50_s300_1000-150x113.png 150w, http:\/\/liipetti.net\/erratic\/wp-content\/uploads\/2016\/03\/out_nin512c7s1279_c50_s300_1000.png 512w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>For more examples using nin-imagenet-conv, see my earlier post <a href=\"http:\/\/liipetti.net\/erratic\/2016\/02\/14\/switching-to-a-smaller-net\/\" target=\"_blank\">Switching to a smaller net<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many people appear to have problems getting neural-style to run, and this is often related to the fact that they try to use it with limited memory such as 2GB. My own tests indicate that neural-style, when used with the default VGG19 network, requires at least 3 GB memory. Lowering \u2026<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"http:\/\/liipetti.net\/erratic\/2016\/03\/21\/using-nin-imagenet-conv-in-neural-style\/\">Continue reading<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-neural-networks"],"_links":{"self":[{"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":7,"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":301,"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/posts\/229\/revisions\/301"}],"wp:attachment":[{"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/liipetti.net\/erratic\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}