< >
Home » TX2入门教程软件篇 » TX2入门教程软件篇-安装PyTorch(jetpack3.0)

TX2入门教程软件篇-安装PyTorch(jetpack3.0)

TX2入门教程软件篇-安装PyTorch(jetpack3.0)

说明:

  • 介绍如果在TX2安装深度学习框架pyTorch

步骤:

  • 新建安装脚本:
mkdir -p ~/dl/pytorch
cd ~/dl/pytorch
sudo vim pytorch_jetson_install.sh
  • 内容如下:
#!/bin/bash
#
# pyTorch install script for NVIDIA Jetson TX1/TX2,
# from a fresh flashing of JetPack 2.3.1 / JetPack 3.0
#
# note:  pyTorch documentation calls for use of Anaconda,
#        however Anaconda isn't available for aarch64.
#        Instead, we install directly from source using setup.py

sudo apt-get install python-pip

# upgrade pip
pip install -U pip
pip --version
# pip 9.0.1 from /home/ubuntu/.local/lib/python2.7/site-packages (python 2.7)

# clone pyTorch repo
git clone -b v0.1.9 http://github.com/pytorch/pytorch
cd pytorch

# install prereqs
sudo pip install -U setuptools
sudo pip install -r requirements.txt

# Develop Mode:
python setup.py build_deps
sudo python setup.py develop

# Install Mode:  (substitute for Develop Mode commands)
#sudo python setup.py install

# Verify CUDA (from python interactive terminal)
# import torch
# print(torch.cuda.is_available())
# a = torch.cuda.FloatTensor(2)
# print(a)
# b = torch.randn(2).cuda()
# print(b)
# c = a + b
# print(c)

测试:

  • 新建文件
vim test.py
  • 内容如下:
import torch
print(torch.cuda.is_available())
a = torch.cuda.FloatTensor(2)
print(a)
b = torch.randn(2).cuda()
print(b)
c = a + b
print(c)
  • 执行结果:
python  test.py
  • 输出:
True


 0
 0
[torch.cuda.FloatTensor of size 2 (GPU 0)]


 0.6851
-0.3392
[torch.cuda.FloatTensor of size 2 (GPU 0)]


 0.6851
-0.3392
[torch.cuda.FloatTensor of size 2 (GPU 0)]

参考:

  • https://gist.github.com/dusty-nv/ef2b372301c00c0a9d3203e42fd83426

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: tx2入门教程软件篇