question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SourceChangeWarning

See original GitHub issue

Problem: C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torchvision.models.resnet.Bottleneck’ has changed. yo u can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to r evert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.batchnorm.BatchNorm2d’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torchvision.models.resnet.Bottleneck’ has changed. yo u can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to r evert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘models.DecoderWithAttention’ has changed. you can ret rieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘models.Attention’ has changed. you can retrieve the o riginal source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.linear.Linear’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.sparse.Embedding’ has changed. you c an retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to reve rt the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.rnn.LSTMCell’ has changed. you can r etrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert t he changes. warnings.warn(msg, SourceChangeWarning) Traceback (most recent call last): File “caption.py”, line 222, in <module> seq, alphas = caption_image_beam_search(encoder, decoder, args.img, word_map, args.beam_size) File “caption.py”, line 45, in caption_image_beam_search image = transform(img) # (3, 256, 256) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py”, line 60, in call img = t(img) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py”, line 163, in call return F.normalize(tensor, self.mean, self.std, self.inplace) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\functional.py”, line 208, in normalize tensor.sub_(mean[:, None, None]).div_(std[:, None, None]) RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #4 ‘other’

(empty) E:\Program Files\a-PyTorch-Tutorial-to-Image-Captioning> (empty) E:\Program Files\a-PyTorch-Tutorial-to-Image-Captioning>python caption.py --img=e:/paper.jpg --model=fake/BEST_checkpoint_coco_5_cap_per_img_5_min_ word_freq.pth.tar --word_map=fake/WORDMAP_coco_5_cap_per_img_5_min_word_freq.json --beam_size=5 C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘models.Encoder’ has changed. you can retrieve the ori ginal source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.conv.Conv2d’ has changed. you can re trieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert th e changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.batchnorm.BatchNorm2d’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torchvision.models.resnet.Bottleneck’ has changed. yo u can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to r evert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘models.DecoderWithAttention’ has changed. you can ret rieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘models.Attention’ has changed. you can retrieve the o riginal source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.linear.Linear’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.sparse.Embedding’ has changed. you c an retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to reve rt the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.rnn.LSTMCell’ has changed. you can r etrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert t he changes. warnings.warn(msg, SourceChangeWarning) Traceback (most recent call last): File “caption.py”, line 222, in <module> seq,alphas = caption_image_beam_search(encoder, decoder, args.img, word_map, args.beam_size) File “caption.py”, line 45, in caption_image_beam_search image = transform(img) # (3, 256, 256) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py”, line 60, in call img = t(img) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py”, line 163, in call return F.normalize(tensor, self.mean, self.std, self.inplace) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\functional.py”, line 208, in normalize tensor.sub_(mean[:, None, None]).div_(std[:, None, None]) RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #4 ‘other’

(empty) E:\Program Files\a-PyTorch-Tutorial-to-Image-Captioning>python caption.py --img=e:/paper.jpg --model=fake/BEST_checkpoint_coco_5_cap_per_img_5_min_ word_freq.pth.tar --word_map=fake/WORDMAP_coco_5_cap_per_img_5_min_word_freq.json --beam_size=5 C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘models.Encoder’ has changed. you can retrieve the ori ginal source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.conv.Conv2d’ has changed. you can re trieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert th e changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.batchnorm.BatchNorm2d’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torchvision.models.resnet.Bottleneck’ has changed. yo u can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to r evert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘models.DecoderWithAttention’ has changed. you can ret rieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘models.Attention’ has changed. you can retrieve the o riginal source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.linear.Linear’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.sparse.Embedding’ has changed. you c an retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to reve rt the changes. warnings.warn(msg, SourceChangeWarning) C:\Anaconda3\lib\site-packages\torch\serialization.py:425: SourceChangeWarning: source code of class ‘torch.nn.modules.rnn.LSTMCell’ has changed. you can r etrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert t he changes. warnings.warn(msg, SourceChangeWarning) Traceback (most recent call last): File “caption.py”, line 222, in <module> seq,alphas = caption_image_beam_search(encoder, decoder, args.img, word_map, args.beam_size) File “caption.py”, line 45, in caption_image_beam_search image = transform(img) # (3, 256, 256) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py”, line 60, in call img = t(img) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py”, line 163, in call return F.normalize(tensor, self.mean, self.std, self.inplace) File “C:\Anaconda3\lib\site-packages\torchvision\transforms\functional.py”, line 208, in normalize tensor.sub_(mean[:, None, None]).div_(std[:, None, None]) RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #4 ‘other’

Pytorch and python are installed according to the version you provide. Why does this happen? Thank you for your answer.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
purveshpatel511commented, Apr 28, 2020

Source-code Change Warning.

i get error after running caption.py file:::

/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'models.Encoder' has changed. Saved a reverse patch to Encoder.patch. Run `patch -p0 < Encoder.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. Saved a reverse patch to Sequential.patch. Run `patch -p0 < Sequential.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. Saved a reverse patch to Conv2d.patch. Run `patch -p0 < Conv2d.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed. Saved a reverse patch to BatchNorm2d.patch. Run `patch -p0 < BatchNorm2d.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.activation.ReLU' has changed. Saved a reverse patch to ReLU.patch. Run `patch -p0 < ReLU.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.MaxPool2d' has changed. Saved a reverse patch to MaxPool2d.patch. Run `patch -p0 < MaxPool2d.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torchvision.models.resnet.Bottleneck' has changed. Saved a reverse patch to Bottleneck.patch. Run `patch -p0 < Bottleneck.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.AdaptiveAvgPool2d' has changed. Saved a reverse patch to AdaptiveAvgPool2d.patch. Run `patch -p0 < AdaptiveAvgPool2d.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'models.DecoderWithAttention' has changed. Saved a reverse patch to DecoderWithAttention.patch. Run `patch -p0 < DecoderWithAttention.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'models.Attention' has changed. Saved a reverse patch to Attention.patch. Run `patch -p0 < Attention.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.linear.Linear' has changed. Saved a reverse patch to Linear.patch. Run `patch -p0 < Linear.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.activation.Softmax' has changed. Saved a reverse patch to Softmax.patch. Run `patch -p0 < Softmax.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.sparse.Embedding' has changed. Saved a reverse patch to Embedding.patch. Run `patch -p0 < Embedding.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.dropout.Dropout' has changed. Saved a reverse patch to Dropout.patch. Run `patch -p0 < Dropout.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.rnn.LSTMCell' has changed. Saved a reverse patch to LSTMCell.patch. Run `patch -p0 < LSTMCell.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.activation.Sigmoid' has changed. Saved a reverse patch to Sigmoid.patch. Run `patch -p0 < Sigmoid.patch` to revert your changes.
  warnings.warn(msg, SourceChangeWarning)

here i set torch.nn.Module.dump_patches=True as per first error but both the time i am getting same output for every image.

output is :: <start> a close up of a black and white background <end>

can you help me through this error and please you specifi the version of pytorch, torch, torchvision that is compitable with current source code. i think upgraded version of this package is remove or deprecated some functions.

2reactions
sgrvinodcommented, Mar 16, 2019

@672401341 Hi, were you able to fix this?

It looks like the image (which is being normalized) is on the GPU, whereas the mean and standard deviation tensors are on the CPU. We’re supplying the mean and standard deviations as lists, so they’re converted to tensors by PyTorch internally. It’s weird – I don’t get the error when I try it on my computer.

You could try putting the image on the GPU after the normalization:

    img = torch.FloatTensor(img)
    normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225])
    transform = transforms.Compose([normalize])
    image = transform(img).to(device)  # (3, 256, 256)

Let me know if this fixes it.

(You can ignore the other warnings, they’re only because some layer definitions were changed after the model was trained.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to suppress " SourceChangeWarning"? - PyTorch Forums
I am using pytorch to deploy models in a way where processes communicate over stdout/stderr pipes. I therefore want to suppress all messages ......
Read more >
SourceChangeWarning - fastai - fast.ai Course Forums
When I export, and use the pkl file in another computer, I got this: /opt/conda/lib/python3.6/site-packages/torch/serialization.py:454: ...
Read more >
Python API: torch.serialization.SourceChangeWarning Class ...
SourceChangeWarning Class Reference. Inheritance diagram for torch.serialization.SourceChangeWarning: Detailed Description. Definition at line 33 of file ...
Read more >
stderr - CodaLab Worksheets
... the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) ... SourceChangeWarning: source code of class 'torch.nn.modules.sparse.
Read more >
yolo5_final_basemodel - Kaggle
Time # Log Message 6.2s 2 warnings.warn(msg, SourceChangeWarning) 6.2s 4 warnings.warn(msg, SourceChangeWarning) 6.2s 6 warnings.warn(msg, SourceChangeWarning)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found