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: a view of a leaf Variable that requires grad is being used in an in-place operation. #23

Open
liuhuaijjin opened this issue Nov 16, 2020 · 3 comments

Comments

@liuhuaijjin
Copy link

Traceback (most recent call last):
File "/home/hqu/yolov5/models/yolo.py", line 274, in
model = Model(opt.cfg).to(device)
File "/home/hqu/yolov5/models/yolo.py", line 95, in init
self._initialize_biases() # only run once
File "/home/hqu/yolov5/models/yolo.py", line 150, in _initialize_biases
b[:,4] = b[:,4]+math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
博主,我在train过程中报这个错误,不知道怎么解决了,我的环境是RTX3090+CUDA11+pytorch1.8。跑ultralytics的yolo.py也报这个错误。

@DataXujing
Copy link
Owner

Pytorch版本太高导致的吧,可以试着降低Pytorch版本

@liuhuaijjin
Copy link
Author

liuhuaijjin commented Nov 17, 2020 via email

@HorizonLiang
Copy link

改成这样就好了:
with torch.no_grad():
b[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum()) # cls

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

3 participants