{"id":25818,"date":"2019-06-16T13:25:29","date_gmt":"2019-06-16T17:25:29","guid":{"rendered":"https:\/\/www.dannyadam.com\/blog\/?p=25818"},"modified":"2023-07-20T11:00:54","modified_gmt":"2023-07-20T15:00:54","slug":"pastiche","status":"publish","type":"post","link":"https:\/\/www.dannyadam.com\/blog\/2019\/06\/pastiche\/","title":{"rendered":"pastiche"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.dannyadam.com\/blog\/wp-content\/uploads\/2019\/06\/pastiche.jpg\"><img decoding=\"async\" src=\"https:\/\/www.dannyadam.com\/blog\/wp-content\/uploads\/2019\/06\/pastiche_thumbnail.jpg\" class=\"wp-image\" alt=\"\" width=\"400\"><\/a><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><em><strong>pastiche<\/strong> A literary, artistic, musical, or architectural work that imitates the style of previous work.<\/em><\/p><cite>\u2015Merriam-Webster dictionary<\/cite><\/blockquote>\n\n\n\n<p><strong>Update 1\/20\/2021<\/strong>: The command line usage snippets were updated in accordance with <code>v1.1.0<\/code>.<\/p>\n\n\n\n<p>I recently implemented <a href=\"https:\/\/github.com\/dstein64\/pastiche\">pastiche<\/a>, a PyTorch-based Python program for applying <em><a href=\"https:\/\/en.wikipedia.org\/wiki\/Neural_Style_Transfer\">neural style transfer<\/a><\/em> [<a href=\"\/\/www.dannyadam.com\/blog\/2019\/06\/pastiche\/#references\">1<\/a>]. Given a content image <strong>C<\/strong> and a style image <strong>S<\/strong>, <em>neural style transfer<\/em> (NST) synthesizes a new image <strong>I<\/strong> that retains the content from <strong>C<\/strong> and style from <strong>S<\/strong>. This is achieved by iteratively updating <strong>I<\/strong> so that relevant properties of its representation within the VGG neural network [<a href=\"\/\/www.dannyadam.com\/blog\/2019\/06\/pastiche\/#references\">3<\/a>] approach the corresponding properties for <strong>C<\/strong> and <strong>S<\/strong>.<\/p>\n\n\n\n<p>The library&nbsp;is <a href=\"https:\/\/pypi.python.org\/pypi\/pastiche\">available<\/a>&nbsp;on PyPI and can be installed with <em>pip<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ pip3 install pastiche<\/code><\/pre>\n\n\n\n<p>The example image above was synthesized by applying the style from Vincent van Gogh&#8217;s <em><a href=\"https:\/\/en.wikipedia.org\/wiki\/The_Starry_Night\">The Starry Night<\/a><\/em> to a <a href=\"https:\/\/photos.dannyadam.com\/Gallery\/i-2RX5VX5\">photo<\/a> I took in Boston in 2015.<\/p>\n\n\n<p><!--more--><\/p>\n\n\n<p>The command line usage is shown below. Use <code>--help<\/code> to access documentation for the additional options (e.g., <code>--device<\/code> for controlling whether to use a CPU or GPU).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ pastiche                    \\\n    --content CONTENT         \\\n    --styles STYLE &#91;STYLE ..] \\\n    --output OUTPUT<\/code><\/pre>\n\n\n\n<p><code>CONTENT<\/code> is the path to the content image, <code>STYLE<\/code> is a path to a style image, and <code>OUTPUT<\/code> is the path to save the synthesized pastiche PNG file.<\/p>\n\n\n\n<p>If the launcher script was not installed within a directory on your <code>PATH<\/code>, pastiche can be launched by passing its module name to Python.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ python3 -m pastiche         \\\n    --content CONTENT         \\\n    --styles STYLE &#91;STYLE ..] \\\n    --output OUTPUT<\/code><\/pre>\n\n\n\n<p>The source code is available on GitHub:<br><a href=\"https:\/\/github.com\/dstein64\/pastiche\">https:\/\/github.com\/dstein64\/pastiche<\/a><\/p>\n\n\n\n<p>The <a href=\"https:\/\/github.com\/dstein64\/pastiche\/blob\/master\/README.md\">README<\/a> includes an example showing how to generate a high-resolution image incrementally, with increasing resolution, using the coarse-to-fine approach described in [<a href=\"\/\/www.dannyadam.com\/blog\/2019\/06\/pastiche\/#references\">2<\/a>].<\/p>\n\n\n\n<p>The <code>--preserve-color<\/code> option can be used to retain colors from the content image.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.dannyadam.com\/blog\/wp-content\/uploads\/2019\/06\/pastiche_preserve_color.jpg\"><img decoding=\"async\" src=\"https:\/\/www.dannyadam.com\/blog\/wp-content\/uploads\/2019\/06\/pastiche_preserve_color_thumbnail.jpg\" class=\"wp-image\" width=\"400\"><\/a><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"references\"><strong><span style=\"text-decoration: underline;\">References<\/span><\/strong><\/h4>\n\n\n\n<p>[1] Gatys, Leon A., Alexander S. Ecker, and Matthias Bethge. \u201cA Neural Algorithm of Artistic Style.\u201d ArXiv:1508.06576 [Cs, q-Bio], August 26, 2015. <a href=\"http:\/\/arxiv.org\/abs\/1508.06576\">http:\/\/arxiv.org\/abs\/1508.06576<\/a>.<br><br>[2] Gatys, Leon A., Alexander S. Ecker, Matthias Bethge, Aaron Hertzmann, and Eli Shechtman. &#8220;Controlling Perceptual Factors in Neural Style Transfer.&#8221; ArXiv:1611.07865 [Cs], November 23, 2016. <a href=\"http:\/\/arxiv.org\/abs\/1611.07865\">http:\/\/arxiv.org\/abs\/1611.07865<\/a>.<br><br>[3] Simonyan, Karen, and Andrew Zisserman. \u201cVery Deep Convolutional Networks for Large-Scale Image Recognition.\u201d ArXiv:1409.1556 [Cs], September 4, 2014. <a href=\"http:\/\/arxiv.org\/abs\/1409.1556\">http:\/\/arxiv.org\/abs\/1409.1556<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>pastiche A literary, artistic, musical, or architectural work that imitates the style of previous work. \u2015Merriam-Webster dictionary Update 1\/20\/2021: The command line usage snippets were updated in accordance with v1.1.0. I recently implemented pastiche, a PyTorch-based Python program for applying neural style transfer [1]. Given a content image C and a style image S, neural [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[56,65,67,36,66],"class_list":["post-25818","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-neural-networks","tag-neural-style-transfer","tag-pastiche","tag-python","tag-pytorch"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/s1sCC6-pastiche","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/posts\/25818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/comments?post=25818"}],"version-history":[{"count":52,"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/posts\/25818\/revisions"}],"predecessor-version":[{"id":26937,"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/posts\/25818\/revisions\/26937"}],"wp:attachment":[{"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/media?parent=25818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/categories?post=25818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dannyadam.com\/blog\/wp-json\/wp\/v2\/tags?post=25818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}