Spyder应用技巧

  ————解决PyTorch的相关问题

   

        PyTorch是一个开源的Python机器学习库,基于Torch,用于自然语言处理等应用程序。2017年1月,由Facebook人工智能研究院(FAIR)基于Torch推出了PyTorch。它是一个基于Python的可续计算包,提供两个高级功能:1、具有强大的GPU加速的张量计算(如NumPy)2、包含自动求导系统的深度神经网络
          我个人觉得开发python语言,用Spyder还是蛮好用,它是python的发明人开发的。在用的当中,有几个问题,
    1)加入参数如图:
    Run=>Run configuration per file,勾选 Command line options(注意参数前有--)
     

2)如果PyTorch是CPU方式,可以改_ _init.py_ _:

def set_device(device: _device_t) -> None:
r"""Sets the current device.

Usage of this function is discouraged in favor of :any:`device`. In most
cases it's better to use ``CUDA_VISIBLE_DEVICES`` environmental variable.

Args:
device (torch.device or int): selected device. This function is a no-op
if this argument is negative.
"""
device = _get_device_index(device)
if device >= 0:
#torch._C._cuda_setDevice(device)
torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

 最后通过搜索“Win10+Anaconda安装CPU版本Pytorch与GPU版Pytorch”,找到相关的测试程序。

,Best Wish 不负年华
原文地址:https://www.cnblogs.com/shiningleo007/p/14962583.html