【问题标题】:How to run python script on gpu如何在gpu上运行python脚本
【发布时间】:2020-04-09 09:08:07
【问题描述】:

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

【问题讨论】:

  • 请将代码作为文本包含在问题中,而不是作为图像链接。
  • 对我来说,您所指的 python 似乎没有正确链接到 cuda,所以您需要修复它。
  • 你可能想检查你的系统默认是哪个python。尝试!python --version 从命令行检查您使用的版本。
  • 要知道您从 Jupiter 运行哪个版本,请尝试 import sys 然后 sys.version
  • @Marc “正确链接”是什么意思?我将如何链接它?

标签: python jupyter-notebook


【解决方案1】:

我使用了以下内容:

%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”。

【讨论】:

    猜你喜欢
    • 2016-09-03
    • 1970-01-01
    • 2021-07-22
    • 2019-10-06
    • 2020-04-19
    • 2014-01-03
    • 1970-01-01
    • 2020-01-10
    • 2022-08-06
    相关资源
    最近更新 更多