(Ubuntu/Window) pytorch verification (whether pytorch is installed successfully)

Verify that pytorch is available (CPU/GPU)

The following is the verification code for whether pytorch is installed successfully. If you see that there is no error and the normal output, then you have to congratulate you on the first step of Xiaobai!
Share it: After confirming your own graphics card driver, you can actually install the two versions of pytorch (GPU/CPU) directly through the command on the Pytorch official website. The installation failure is basically a network problem!
pip install -i "Douban Source" ---->>>> (can be done in this general way u)

Test on GPU

import torch   # 能否调用pytorch库

print(torch.cuda.current_device())   # 输出当前设备(我只有一个GPU为0)
print(torch.cuda.device(0))   # <torch.cuda.device object at 0x7fdfb60aa588>
print(torch.cuda.device_count())  # 输出含有的GPU数目
print(torch.cuda.get_device_name(0))  # 输出GPU名称 --比如1080Ti
x = torch.rand(5, 3)
print(x)  # 输出一个5 x 3 的tenor(张量)

Test on CPU

import torch
x = torch.rand(5,3)
print(x)

Guess you like

Origin blog.csdn.net/Leomn_J/article/details/111758600