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

一个代码中的小问题 #2

Open
lyq998 opened this issue Nov 6, 2020 · 3 comments
Open

一个代码中的小问题 #2

lyq998 opened this issue Nov 6, 2020 · 3 comments

Comments

@lyq998
Copy link

lyq998 commented Nov 6, 2020

最近用了一下DBN在CUDA上面跑代码,发现一个运行的小问题
dbn.py 里 52行
s = (torch.rand(p.size())< p).float().to(self.dvc)
会报错
Traceback (most recent call last):
File "mnist_cls.py", line 55, in
model.run(e=3, pre_e=3)
File "../core/epoch.py", line 98, in run
self.pre_batch_training(pre_e, b)
File "../core/pre_module.py", line 60, in pre_batch_training
module.batch_training(i)
File "../model/dbn.py", line 99, in batch_training
v0,h0,vk,hk = self.forward(data)
File "../model/dbn.py", line 65, in forward
ph0, h0 = self.transfrom(v0,'v2h')
File "../model/dbn.py", line 52, in transfrom
s = (torch.rand(p.size())< p).float().to(self.dvc)
RuntimeError: expected device cpu but got device cuda:0

修改为s = (torch.rand(p.size())< p.cpu()).float().to(self.dvc),正常运行

@zhuofupan
Copy link
Owner

谢谢您的指出,是有点问题,大意了。torch.rand(p.size()) 应该生成之后是在 cpu 上。

@liupeng996
Copy link

请问如果用DBN做回归该怎么在您的代码上改啊

1 similar comment
@i-am-jsk
Copy link

i-am-jsk commented Jul 8, 2022

请问如果用DBN做回归该怎么在您的代码上改啊

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

4 participants