Pytorch tutorials for Neural Style transfert

Overview
Comments
  • Doesn't seem to work?

    Doesn't seem to work?

    With the code cloned to local machine, removed .cuda() and .cpu(), this error is encountered with Python3.6 + Pytorch 0.1:

    Traceback (most recent call last):
      File "Neural_Style.py", line 205, in <module>
        style_score += sl.backward()
      File "Neural_Style.py", line 105, in backward
        self.loss.backward(retain_variables=retain_variables)
      File "/usr/local/lib/python3.6/site-packages/torch/autograd/variable.py", line 146, in backward
        self._execution_engine.run_backward((self,), (gradient,), retain_variables)
      File "/usr/local/lib/python3.6/site-packages/torch/nn/_functions/conv.py", line 48, in backward
        if self.needs_input_grad[0] else None)
      File "/usr/local/lib/python3.6/site-packages/torch/nn/_functions/conv.py", line 119, in _grad_input
        return self._thnn('grad_input', input, weight, grad_output)
      File "/usr/local/lib/python3.6/site-packages/torch/nn/_functions/conv.py", line 161, in _thnn
        return impl[fn_name](self, self._bufs[0], input, weight, *args)
      File "/usr/local/lib/python3.6/site-packages/torch/nn/_functions/conv.py", line 251, in call_grad_input
        grad_input, weight, *args)
    RuntimeError: Need gradOutput of dimension 4 and gradOutput.size[1] == 64 but got gradOutput to be of shape: [64 x 2401] at /Users/soumith/code/pytorch-builder/wheel/pytorch-src/torch/lib/THNN/generic/SpatialConvolutionMM.c:50
    
    opened by ecolss 4
  • error trying https://github.com/alexis-jacq/Pytorch-Tutorials/blob/master/Neural_Style.ipynb  on PyTorch-0.4

    error trying https://github.com/alexis-jacq/Pytorch-Tutorials/blob/master/Neural_Style.ipynb on PyTorch-0.4

    code:

    run = [0]
    while run[0] <= 300:
        
        def closure():
            optimizer.zero_grad()
            model.forward(input)
            style_score = 0
            content_score = 0
    
            for sl in style_losses:
                style_score += sl.backward()
            for cl in content_losses:
                content_score += cl.backward()
    
            run[0]+=1
            if run[0] % 10 == 0:
                print("run " + str(run) + ":")
                print(style_score.data[0])
                print(content_score.data[0])
    
            return content_score+style_score
    
        optimizer.step(closure)
    
    plt.subplot(224)
    imshow(input.data)
    plt.show()
    

    error:

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-22-0659e65a7a4a> in <module>()
         21         return content_score+style_score
         22 
    ---> 23     optimizer.step(closure)
         24 
         25 plt.subplot(224)
    
    C:\WinP\bd36\buQt5\winp64-3.6.x.1\python-3.6.5.amd64\lib\site-packages\torch\optim\lbfgs.py in step(self, closure)
        101 
        102         # evaluate initial f(x) and df/dx
    --> 103         orig_loss = closure()
        104         loss = float(orig_loss)
        105         current_evals = 1
    
    <ipython-input-22-0659e65a7a4a> in closure()
          9 
         10         for sl in style_losses:
    ---> 11             style_score += sl.backward()
         12         for cl in content_losses:
         13             content_score += cl.backward()
    
    <ipython-input-15-ed2dfef0a270> in backward(self, retain_variables)
         15 
         16     def backward(self, retain_variables=True):
    ---> 17         self.loss.backward(retain_variables=retain_variables)
         18         return self.loss
    
    TypeError: backward() got an unexpected keyword argument 'retain_variables'
    ````
    opened by stonebig 3
  • Errors when using tansforms.Normalize() instead of define a normalisation module

    Errors when using tansforms.Normalize() instead of define a normalisation module

    Hello, cool work! I tried to use the transforms.Normalize() method instead of designing a Normalization class as you did ,but the loss seems not converging, is it unachievable to usetransforms.Normalize() method in your code?

    load_transform = transforms.Compose([
        transforms.Resize(
            image_size),  # notice the resized img width is image_size
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])
    ])
    
    
    def img_loader(image_name):
        img = Image.open(image_name)
        img = load_transform(img).unsqueeze(0)  
        return img.to(device, torch.float)
    
    
    style_img = img_loader("./datasets/images/picasso.jpg")  # 650*650
    content_img = img_loader("./datasets/images/dancing.jpg")  # 444*444
    assert style_img.size() == content_img.size(
    ), "The content-image and the style-image is not compatiable in shape"
    
    
    # Define the function to show the tensor(Caution: we need to change the tensor format to PIL format)
    def img_show(tensor, title=None):
        img = tensor.cpu().clone()  # we clone the tensor to not do changes on it
        img = img.squeeze(0)  # CHW format
        img = img.detach().numpy().transpose((1, 2, 0))  # HWC format
        img = img * np.array([0.229, 0.224, 0.225]) + \
              np.array([0.485, 0.456, 0.406])
        img = img.clip(0, 1)
        plt.imshow(img)
        #  function plt.imshow() performs on RGB data of float [0-1] or int [0-255]
        if title != None:
            plt.title(title)
        plt.pause(0.5)
    
    
    plt.ion()
    plt.figure()
    img_show(style_img, title="Style Image")
    plt.figure()
    img_show(content_img, title="Content Image")
    
    opened by Lelouch-Ice 0
  • Why no normalization ?

    Why no normalization ?

    Hi, In order to use vgg19, the following normalizing step has to be used: (Values of the input image being between 0 and 1) normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) cf : https://github.com/pytorch/vision#models Why arn't you using here, not needed ? Thx :)

    opened by tcosmo 0
  • The result image is nothing like the expected

    The result image is nothing like the expected "style-transfer" image

    Hello,

    I have run the code in your Jupyter notebook but the result image after training does not look like the "style-transfer" image that you'd expect. Did I do anything wrong or is there any way to make the image better? Here is the screenshot:

    neural-jupyter
    opened by salman1993 0
Owner
Alexis David Jacq
Alexis David Jacq
Fast Neural Style for Image Style Transform by Pytorch

FastNeuralStyle by Pytorch Fast Neural Style for Image Style Transform by Pytorch This is famous Fast Neural Style of Paper Perceptual Losses for Real

Bengxy 81 Sep 3, 2022
The Incredible PyTorch: a curated list of tutorials, papers, projects, communities and more relating to PyTorch.

This is a curated list of tutorials, projects, libraries, videos, papers, books and anything related to the incredible PyTorch. Feel free to make a pu

Ritchie Ng 9.2k Jan 2, 2023
Only a Matter of Style: Age Transformation Using a Style-Based Regression Model

Only a Matter of Style: Age Transformation Using a Style-Based Regression Model The task of age transformation illustrates the change of an individual

null 444 Dec 30, 2022
Simple tutorials on Pytorch DDP training

pytorch-distributed-training Distribute Dataparallel (DDP) Training on Pytorch Features Easy to study DDP training You can directly copy this code for

Ren Tianhe 188 Jan 6, 2023
Pytorch Geometric Tutorials

Pytorch Geometric Tutorials

Antonio Longa 648 Jan 8, 2023
PyTorch implementation of neural style transfer algorithm

neural-style-pt This is a PyTorch implementation of the paper A Neural Algorithm of Artistic Style by Leon A. Gatys, Alexander S. Ecker, and Matthias

null 770 Jan 2, 2023
Neural style transfer in PyTorch.

style-transfer-pytorch An implementation of neural style transfer (A Neural Algorithm of Artistic Style) in PyTorch, supporting CPUs and Nvidia GPUs.

Katherine Crowson 395 Jan 6, 2023
Official PyTorch implementation of "ArtFlow: Unbiased Image Style Transfer via Reversible Neural Flows"

ArtFlow Official PyTorch implementation of the paper: ArtFlow: Unbiased Image Style Transfer via Reversible Neural Flows Jie An*, Siyu Huang*, Yibing

null 123 Dec 27, 2022
Neural style transfer as a class in PyTorch

pt-styletransfer Neural style transfer as a class in PyTorch Based on: https://github.com/alexis-jacq/Pytorch-Tutorials Adds: StyleTransferNet as a cl

Tyler Kvochick 31 Jun 27, 2022
PyTorch implementation of neural style randomization for data augmentation

README Augment training images for deep neural networks by randomizing their visual style, as described in our paper: https://arxiv.org/abs/1809.05375

null 84 Nov 23, 2022
PyTorch implementation of paper: AdaAttN: Revisit Attention Mechanism in Arbitrary Neural Style Transfer, ICCV 2021.

AdaAttN: Revisit Attention Mechanism in Arbitrary Neural Style Transfer [Paper] [PyTorch Implementation] [Paddle Implementation] Overview This reposit

null 148 Dec 30, 2022
pytorch implementation of fast-neural-style

fast-neural-style ?? ?? NOTICE: This codebase is no longer maintained, please use the codebase from pytorch examples repository available at pytorch/e

Abhishek Kadian 405 Dec 15, 2022
Implementation of Neural Style Transfer in Pytorch

PytorchNeuralStyleTransfer Code to run Neural Style Transfer from our paper Image Style Transfer Using Convolutional Neural Networks. Also includes co

Leon Gatys 396 Dec 1, 2022
This repository contains notebook implementations of the following Neural Process variants: Conditional Neural Processes (CNPs), Neural Processes (NPs), Attentive Neural Processes (ANPs).

The Neural Process Family This repository contains notebook implementations of the following Neural Process variants: Conditional Neural Processes (CN

DeepMind 892 Dec 28, 2022
Repository of Jupyter notebook tutorials for teaching the Deep Learning Course at the University of Amsterdam (MSc AI), Fall 2020

Repository of Jupyter notebook tutorials for teaching the Deep Learning Course at the University of Amsterdam (MSc AI), Fall 2020

Phillip Lippe 1.1k Jan 7, 2023
Useful materials and tutorials for 110-1 NTU DBME5028 (Application of Deep Learning in Medical Imaging)

Useful materials and tutorials for 110-1 NTU DBME5028 (Application of Deep Learning in Medical Imaging)

null 7 Jun 22, 2022
Towards Ultra-Resolution Neural Style Transfer via Thumbnail Instance Normalization

Towards Ultra-Resolution Neural Style Transfer via Thumbnail Instance Normalization Official PyTorch implementation for our URST (Ultra-Resolution Sty

czczup 148 Dec 27, 2022
STYLER: Style Factor Modeling with Rapidity and Robustness via Speech Decomposition for Expressive and Controllable Neural Text to Speech

STYLER: Style Factor Modeling with Rapidity and Robustness via Speech Decomposition for Expressive and Controllable Neural Text to Speech Keon Lee, Ky

Keon Lee 114 Dec 12, 2022
An implementation of the paper "A Neural Algorithm of Artistic Style"

A Neural Algorithm of Artistic Style implementation - Neural Style Transfer This is an implementation of the research paper "A Neural Algorithm of Art

Srijarko Roy 27 Sep 20, 2022