Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Output 0 of UnbindBackward is a view and is being modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one. #28

Open
scutfrank opened this issue Oct 9, 2022 · 4 comments

Comments

@scutfrank
Copy link

Traceback (most recent call last):
File "D:/1.Study/PycharmProjects/Score-CAM-master/test.py", line 50, in
basic_visualize(input_.cpu(), scorecam_map.type(torch.FloatTensor).cpu(), save_path='resnet.png')
File "D:\1.Study\PycharmProjects\Score-CAM-master\utils_init_.py", line 299, in basic_visualize
input_ = format_for_plotting(denormalize(input_))
File "D:\1.Study\PycharmProjects\Score-CAM-master\utils_init_.py", line 173, in denormalize
channel.mul_(std).add_(mean)

@scucmpunk
Copy link

me too

@haofanwang
Copy link
Owner

Could you try it on Colab? I think this is caused by the update in torch.

@hayleeXinyi
Copy link

hayleeXinyi commented Dec 29, 2022

change to this
count = 0 for channel, mean, std in zip(denormalized[0], means, stds): denormalized[0][count] = denormalized[0][count].mul(std) denormalized[0][count] = denormalized[0][count].add(mean) count+=1
the key is change channel.mul_(std).add_(mean) to denormalized[0][count] = denormalized[0][count].mul(std) and denormalized[0][count] = denormalized[0][count].add(mean). Because these are in place. 这里的乘法和加法都是就地操作的,这里不适用,所以要拆开来。按照发的这个代码换一下就可以了。

@zhengyuan-xie
Copy link

change to this count = 0 for channel, mean, std in zip(denormalized[0], means, stds): denormalized[0][count] = denormalized[0][count].mul(std) denormalized[0][count] = denormalized[0][count].add(mean) count+=1 the key is change channel.mul_(std).add_(mean) to denormalized[0][count] = denormalized[0][count].mul(std) and denormalized[0][count] = denormalized[0][count].add(mean). Because these are in place. 这里的乘法和加法都是就地操作的,这里不适用,所以要拆开来。按照发的这个代码换一下就可以了。

This solution is useful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants