Reconstructing input image from layers of a CNN2019 Community Moderator ElectionHow to adapt the softmax layer for multiple labels?How to improve the neural art algorithm?Accuracy drops if more layers trainable - weirdUsing deconvolution in practiceHow to input & pre-process images for a Deep Convolutional Neural Network?What does “Model recursive loss convergence” mean?Image features (produced by VGG19) do not properly train an ANN in KerasSubsequent convolution layersKeras Attention Guided CNN problemRemedies to CNN-LSTM overfitting on relatively small image dataset

Is the Joker left-handed?

Should I tell management that I intend to leave due to bad software development practices?

How could indestructible materials be used in power generation?

Is it canonical bit space?

Latex document compiles but tikzpicture is not showing up

What is going on with Captain Marvel's blood colour?

How do I gain back my faith in my PhD degree?

Python: return float 1.0 as int 1 but float 1.5 as float 1.5

Is it inappropriate for a student to attend their mentor's dissertation defense?

Why are electrically insulating heatsinks so rare? Is it just cost?

Why does ы have a soft sign in it?

Why doesn't using multiple commands with a || or && conditional work?

How do I find out when a node was added to an availability group?

How can I tell some body that I want to be his or her friend?

What exploit are these user agents trying to use?

Expand and Contract

Forgetting the musical notes while performing in concert

Facing a paradox: Ehrenfest theorem in one dimension

Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?

Why is the ratio of two extensive quantities always intensive?

How to say in German "enjoying home comforts"

What method can I use to design a dungeon difficult enough that the PCs can't make it through without killing them?

Fully-Firstable Anagram Sets

Why is Collection not simply treated as Collection<?>



Reconstructing input image from layers of a CNN



2019 Community Moderator ElectionHow to adapt the softmax layer for multiple labels?How to improve the neural art algorithm?Accuracy drops if more layers trainable - weirdUsing deconvolution in practiceHow to input & pre-process images for a Deep Convolutional Neural Network?What does “Model recursive loss convergence” mean?Image features (produced by VGG19) do not properly train an ANN in KerasSubsequent convolution layersKeras Attention Guided CNN problemRemedies to CNN-LSTM overfitting on relatively small image dataset










1












$begingroup$


I've been trying to implement neural style transfer as described in this paper here According to the paper,




we can visualise the information at different processing stages in the
CNN by reconstructing the input image from only knowing the network’s
responses in a particular layer.




My question is, how exactly does one go about reconstructing image from a single layer?
I'm implementing this in pytorch. I've the output from layer conv4_2 stored in a tensor of shape [1,512,50,50] but how do I visualize this?



Here's a part of my code, if that helps.



vgg = models.vgg19(pretrained=True).features

for param in vgg.parameters():
param.requires_grad_(False)

device = torch.device("cpu")

vgg.to(device)

content_img = Image.open("image3.jpg").convert('RGB')
style_img = Image.open("image5.jpg").convert('RGB')
content_img = transformation(content_img).to(device)
style_img = transformation(style_img).to(device)

def get_features(image, model):

layers = '0': 'conv1_1', '5': 'conv2_1', '10': 'conv3_1',
'19': 'conv4_1', '21': 'conv4_2', '28': 'conv5_1'
x = image
features =

for name, layer in model._modules.items():
x = layer(x)

if name in layers:
features[layers[name]] = x

return features

content_img_features = get_features(content_img, vgg)
style_img_features = get_features(style_img, vgg)

target_content = content_img_features['conv4_2']


How do I reconstruct the image from the output of conv4_2?










share|improve this question









$endgroup$
















    1












    $begingroup$


    I've been trying to implement neural style transfer as described in this paper here According to the paper,




    we can visualise the information at different processing stages in the
    CNN by reconstructing the input image from only knowing the network’s
    responses in a particular layer.




    My question is, how exactly does one go about reconstructing image from a single layer?
    I'm implementing this in pytorch. I've the output from layer conv4_2 stored in a tensor of shape [1,512,50,50] but how do I visualize this?



    Here's a part of my code, if that helps.



    vgg = models.vgg19(pretrained=True).features

    for param in vgg.parameters():
    param.requires_grad_(False)

    device = torch.device("cpu")

    vgg.to(device)

    content_img = Image.open("image3.jpg").convert('RGB')
    style_img = Image.open("image5.jpg").convert('RGB')
    content_img = transformation(content_img).to(device)
    style_img = transformation(style_img).to(device)

    def get_features(image, model):

    layers = '0': 'conv1_1', '5': 'conv2_1', '10': 'conv3_1',
    '19': 'conv4_1', '21': 'conv4_2', '28': 'conv5_1'
    x = image
    features =

    for name, layer in model._modules.items():
    x = layer(x)

    if name in layers:
    features[layers[name]] = x

    return features

    content_img_features = get_features(content_img, vgg)
    style_img_features = get_features(style_img, vgg)

    target_content = content_img_features['conv4_2']


    How do I reconstruct the image from the output of conv4_2?










    share|improve this question









    $endgroup$














      1












      1








      1





      $begingroup$


      I've been trying to implement neural style transfer as described in this paper here According to the paper,




      we can visualise the information at different processing stages in the
      CNN by reconstructing the input image from only knowing the network’s
      responses in a particular layer.




      My question is, how exactly does one go about reconstructing image from a single layer?
      I'm implementing this in pytorch. I've the output from layer conv4_2 stored in a tensor of shape [1,512,50,50] but how do I visualize this?



      Here's a part of my code, if that helps.



      vgg = models.vgg19(pretrained=True).features

      for param in vgg.parameters():
      param.requires_grad_(False)

      device = torch.device("cpu")

      vgg.to(device)

      content_img = Image.open("image3.jpg").convert('RGB')
      style_img = Image.open("image5.jpg").convert('RGB')
      content_img = transformation(content_img).to(device)
      style_img = transformation(style_img).to(device)

      def get_features(image, model):

      layers = '0': 'conv1_1', '5': 'conv2_1', '10': 'conv3_1',
      '19': 'conv4_1', '21': 'conv4_2', '28': 'conv5_1'
      x = image
      features =

      for name, layer in model._modules.items():
      x = layer(x)

      if name in layers:
      features[layers[name]] = x

      return features

      content_img_features = get_features(content_img, vgg)
      style_img_features = get_features(style_img, vgg)

      target_content = content_img_features['conv4_2']


      How do I reconstruct the image from the output of conv4_2?










      share|improve this question









      $endgroup$




      I've been trying to implement neural style transfer as described in this paper here According to the paper,




      we can visualise the information at different processing stages in the
      CNN by reconstructing the input image from only knowing the network’s
      responses in a particular layer.




      My question is, how exactly does one go about reconstructing image from a single layer?
      I'm implementing this in pytorch. I've the output from layer conv4_2 stored in a tensor of shape [1,512,50,50] but how do I visualize this?



      Here's a part of my code, if that helps.



      vgg = models.vgg19(pretrained=True).features

      for param in vgg.parameters():
      param.requires_grad_(False)

      device = torch.device("cpu")

      vgg.to(device)

      content_img = Image.open("image3.jpg").convert('RGB')
      style_img = Image.open("image5.jpg").convert('RGB')
      content_img = transformation(content_img).to(device)
      style_img = transformation(style_img).to(device)

      def get_features(image, model):

      layers = '0': 'conv1_1', '5': 'conv2_1', '10': 'conv3_1',
      '19': 'conv4_1', '21': 'conv4_2', '28': 'conv5_1'
      x = image
      features =

      for name, layer in model._modules.items():
      x = layer(x)

      if name in layers:
      features[layers[name]] = x

      return features

      content_img_features = get_features(content_img, vgg)
      style_img_features = get_features(style_img, vgg)

      target_content = content_img_features['conv4_2']


      How do I reconstruct the image from the output of conv4_2?







      neural-network cnn convolution pytorch neural-style-transfer






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 5:11









      Judy T RajJudy T Raj

      1211




      1211




















          0






          active

          oldest

          votes












          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47992%2freconstructing-input-image-from-layers-of-a-cnn%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47992%2freconstructing-input-image-from-layers-of-a-cnn%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

          Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High