Giter Club home page Giter Club logo

pytorch-tutorials's Introduction

pytorch-tutorials's People

Contributors

alexis-jacq avatar mehdi-shiba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytorch-tutorials's Issues

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 :)

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'
````

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

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 use transforms.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")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.