如何在GPU

时间:2020-04-09 09:08:07

标签: python jupyter-notebook

enter image description here

在我的jupyter笔记本中,torch.cuda.is_available()返回True。但是,当我运行python脚本时,python脚本中的同一行代码将返回False。这向我表明,当我在笔记本中运行python脚本时,它默认不使用cuda。有解决方法吗?

1 个答案:

答案 0 :(得分:2)

我使用了以下内容:

%run -i test_background-matting_image.py -m real-hand-held -i sample_data/input/ -o sample_data/output/ -tb sample_data/background/0001.png

根据this%run -i在IPython的命名空间中运行文件,而不是在空白文件中运行该文件,即与我的jupyter笔记本“ python相同”。