harryhan618 / SCNN_Pytorch

Pytorch implementation of "Spatial As Deep: Spatial CNN for Traffic Scene Understanding"
MIT License
250 stars 68 forks source link

Run demo_test.py on GPU #28

Closed maym86 closed 4 years ago

maym86 commented 4 years ago

Hello,

I am running the demo_test.py script successfully but it seems to be using the cpu.

I tried a few things including setting the map_location to cuda:

save_dict = torch.load(weight_path, map_location='cuda')

And setting the model to cuda() in model.py. But neither of these seem to make any difference.

Any ideas?

maym86 commented 4 years ago

Figured it out

add torch.set_default_tensor_type('torch.cuda.FloatTensor') to the top of demo_test.py

and add .cuda() to this line in demo_test.py def main() around line 60

x = transform_to_net({'img': img})['img'].cuda()
vabrishami commented 3 years ago

Hi @maym86. Can you please help me with running the demo on GPU? I did change what you suggested in your second comment, however, still, some errors are there. Should I also consider the proposed changes in your first comment? Thanks!

maym86 commented 3 years ago

Try it. I can't remember tbh. Been a few years since I did this. Sorry.

harryhan618 commented 3 years ago

@vabrishami Maybe you can change map_location='cuda' to map_location='cpu'.

vabrishami commented 3 years ago

Thanks @harryhan618 and @maym86. I made the following changes to make it work:

1- After net.eval() line, add a new line with net.cuda() 2- Change x = transform_to_net({'img': img})['img'].cpu() to x = transform_to_net({'img': img})['img'].cuda()

That's it. With these changes, I could run it on GPU.