Jetson TX2使用说明

博客原文地址: https://www.mikoychinese.top/post/20180209-jetson-tx2-wiki/

  Nvidia Jetson stands for a series of computation processor boards from Nvidia. The Jetson TK1, TX1 and TX2 models are all are carrying a Tegra processor from Nvidia. Nvidia claims that it is an AI supercomputer on a module, powered by NVIDIA Pascal architecture. Best of all, it packs this performance into a small, power-efficient form factor that’s ideal for intelligent edge devices like robots, drones, smart cameras, and portable medical devices. It supports all the features of the Jetson TX1 module while enabling bigger, more complex deep neural networks. If you want to know more useful information about Jetson TX2, you can scan Nvidia Jetson.

jetsonTX2配置.png

JetsonTX2外观.jpg

Introduction:

  Because Jeston TX2 is so different from the other PC installed Ubuntu16.04, I reconized that it needs to write an article to guide other people who are the hardware and software developers and wanna learn it more to install and configure Jeston TX2. Finally, I am enormously grateful for the help from JetsonHacks, it provides so many useful tutorials and sources which is built in JetsonHacks Github.

Install JetPack(Ubuntu):

  When we get the Jetson TX2, it already installed an origin system(Ubuntu), but it has little usefulness. If we do use actraly to develop it for Deep Learning or other way to play what you want, you need to install the official system JetPack(This article is based on JetPack 3.1 which introduces L4T 28.1).

Release Highlight For JetPack 3.1 on Jetson TX2:

  • New L4T Production Release 28.1
  • TensorRT 2.1
  • cuDNN v6.0
  • Multimedia API v28.1
    • New functionality
      • TNRv2 (Temporal Noise Reduction)
        • High quality spatio-temporal noise reduction using GPU. Recommended for applications where low light video quality is important and GPU requirement is acceptable. Typical GPU utilization is <8.5% for 1080p30fps operation on Jetson TX1.
      • Piecewise linear WDR Support
        • ISP now supports cameras with “built-in WDR” that combine multiple exposures on-sensor and transmit the result with a piecewise linear encoding. Functionality verified using Sony IMX-185 (and reference driver is included). This feature does not include support for other WDR technologies such as DOL or spatial interleaving.
    • New samples
      • How to share CUDA buffer with v412 camera and then process color conversion (YUYV to RGB) with CUDA algorithm.
      • How to render video stream (YUV) or UI (RGB) with Tegra DRM (Direct Rendering Manager), i.e. rendering support for non-X11 and lightweight display system. Tegra DRM is implemented in user-space and is compatible with standard DRM 2.0.

Note:

When you start to install JetPack, you need to prepare something necessary.

  1. An desktop or laptop computer with an Intel or AMD x86 processor.
  2. A Micro USB and An Ethernet cable which will connect your PC and Jetson TX2.
  3. LAN(Local Area Network).

Installing Step:

  1. <font color=red>First Step:</font> Download JetPack
  2. <font color=red>Second Step:</font> Run JetPack on your PC
    • Cd your file's path.
      cd ~/Downloads
    • Set the file executable permission.
      chmod +x ./JetPack-L4T-3.1-linux-x64.run
    • Run it.
      ./JetPack-L4T-3.1-linux-x64.run
  3. <font color=red>Third Step:</font> Installing Interface
    • Read and watch it conscientiously. If it is no choice for you, you can click next no worry about it.
    • Full install or make your choice. As for me, I choosed no action OpenCV because this version is called OpenCV4Tegra and some libraries require different modules and such that require upstream OpenCV versions.


      installface.png
    • Accept all licenses.
    • Select the network layout(I recommend you select the first way.).
      002.png
    • Then you will select the network interface and it will show that all the network card in your PC. You can run the ifconfig command on your PC terminal, and choose the device which has IP net or is in your LAN. Such like this:
      Network Device
    • So you need to choose the wlp4s0 device.(The picture is catch by Internet, not my PC show. You should make choice depending on your PC.)


      003.png
    • Clicking the next, and you will obtain the interface from terminal where show you how to put your Jetson TX2 to force USB Recovery Mode and if you are ready, press the Enter key.
      1. Power off your device, the best way you do is that shutdown your Jetson TX2 and remove the power adapter for 3 seconds.
      2. Connect Your PC up to TX2 with Micro-USB.
      3. Power on your device, and immediately press and hold the RECOVERY button(REC on your board), meanwhile press the RESET(RES on your board) button and release it. If you see the TX2 board flash it's light for a while, that means that you are successful in Recovery Mode.
        004.png
      4. Also you can run lsusb in your PC terminal to show whether you are successful.(You can also skip this step.)
        005.png
    • Installing Process will spend some time, then the Jetson TX2 will power on and your PC will connect it by SSH(automatic).
      006.png
    • Finish in installing and you can remove all packages about JetPack.

2.Install Tensorflow:

  TensorFlow is one of the major deep learning systems. Created at Google, it is an open-source software library for machine intelligence. The Jetson TX2 ships with TensorRT. TensorRT is what is called an “Inference Engine“, the idea being that large machine learning systems can train models which are then transferred over and “run” on the Jetson.

  There are two ways to install Tensorflow in Jetson TX2, this article just show you install by wheel file. Because when I build the tensorflow by myself, I got a error: locale en_US, the issue address: https://github.com/bazelbuild/bazel/issues/4483.

Build Information and Tensorflow Version:

  • L4T 28.1 (JetPack 3.1)
  • CUDA 8.0
  • cuDNN 6.0
  • Tensorflow Version 1.3.0
  • Built with CUDA support

Install Preparation:

  1. Download the wheel file from https://github.com/jetsonhacks/installTensorFlowJetsonTX.git.
  2. Install the matching pip for your Python installation and install tensorflow_wheel_file in your download path.

    If you are Chinese, you can choose update your apt-sources like the 3 step next.
    • Python 2.7
      sudo apt-get install -y python-pip python-dev
      pip install <tensorflow_wheel_file>
      
    • Python 3.5
      sudo apt-get install -y python3-pip python3-dev
      pip3 install <tensorflow_wheel_file>
      
  3. Update apt-sources:(For Chinese)
    • 使用 HTTPS 可以有效避免国内运营商的缓存劫持,但需要事先安装 apt-transport-https
    • CD your apt-sources path.
      cd /etc/apt
      
    • Edit the sources file.
      1. sudo gedit ./sources.list
      2. Replace all the text by this:
      # 默认注释了源码仓库,如有需要可自行取消注释
      deb https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main restricted universe multiverse
      # deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main main restricted universe multiverse
      deb https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse
      # deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse
      deb https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse
      # deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse
      deb https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse
      # deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse
      
      # 预发布软件源,不建议启用
      # deb https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main restricted universe multiverse
      # deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main restricted universe multiverse
      
    • Update apt-sources.
      sudo apt-get update
      

3.Build OpenCV:

Background:

  JetPack can install a CPU and GPU accelerated version of the OpenCV libraries, called OpenCV4Tegra, on the Jetson. OpenCV4Tegra is version 2.4.13 as of this writing. This is great for many applications, especially when you are writing your own apps. However, some libraries require different modules and such that require upstream OpenCV versions.

Installation:

  • Download the sources and build OpenCV:
    git clone https://github.com/jetsonhacks/buildOpenCVTX2.git
    cd buildOpenCVTX2
    ./buildOpenCV.sh
    
    Note: If you need the OpenCV which is also working in python3, you should open the buildOpenCV.sh file and change it like this:
    Change the BUILD_opencv_python3=OFF to ON
    Also you can make the building in python2 OFF
    
  • CD your download path and make bulid:
    cd ~/opencv/build
    sudo make install
    
  • Check your library vaild:
    import cv2
    cv2.__version__
    

Note:

1.Use GStreamer and OpenCV Capture the Image of Camera

  • As I think, there are so many people who have theirselves tasks or goals, so I copy other developer's code to show how to use the camera in Jetson TX2. What you need is up to you.
# --------------------------------------------------------
# Camera sample code for Tegra X2/X1
#
# This program could capture and display video from
# IP CAM, USB webcam, or the Tegra onboard camera.
# Refer to the following blog post for how to set up
# and run the code:
#   https://jkjung-avt.github.io/tx2-camera-with-python/
#
# Written by JK Jung <jkjung13@gmail.com>
# --------------------------------------------------------

import sys
import argparse
import cv2
import numpy as np

windowName = "CameraDemo"

def parse_args():
    """
    Parse input arguments
    """
    parser = argparse.ArgumentParser(description=
                                     "Capture and display live camera video on Jetson TX2/TX1")
    parser.add_argument("--rtsp", dest="use_rtsp",
                        help="use IP CAM (remember to also set --uri)",
                        action="store_true")
    parser.add_argument("--uri", dest="rtsp_uri",
                        help="RTSP URI string, e.g. rtsp://192.168.1.64:554",
                        default=None, type=str)
    parser.add_argument("--latency", dest="rtsp_latency",
                        help="latency in ms for RTSP [200]",
                        default=200, type=int)
    parser.add_argument("--usb", dest="use_usb",
                        help="use USB webcam (remember to also set --vid)",
                        action="store_true")
    parser.add_argument("--vid", dest="video_dev",
                        help="video device # of USB webcam (/dev/video?) [1]",
                        default=1, type=int)
    parser.add_argument("--width", dest="image_width",
                        help="image width [1920]",
                        default=1920, type=int)
    parser.add_argument("--height", dest="image_height",
                        help="image width [1080]",
                        default=1080, type=int)
    args = parser.parse_args()
    return args

def open_cam_rtsp(uri, width, height, latency):
    gst_str = ("rtspsrc location={} latency={} ! rtph264depay ! h264parse ! omxh264dec ! "
               "nvvidconv ! video/x-raw, width=(int){}, height=(int){}, format=(string)BGRx ! "
               "videoconvert ! appsink").format(uri, latency, width, height)
    return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

def open_cam_usb(dev, width, height):
    # We want to set width and height here, otherwise we could just do:
    #     return cv2.VideoCapture(dev)
    gst_str = ("v4l2src device=/dev/video{} ! "
               "video/x-raw, width=(int){}, height=(int){}, format=(string)RGB ! "
               "videoconvert ! appsink").format(dev, width, height)
    return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

def open_cam_onboard(width, height):
    # On versions of L4T previous to L4T 28.1, flip-method=2
    # Use Jetson onboard camera
    gst_str = ("nvcamerasrc ! "
               "video/x-raw(memory:NVMM), width=(int)2592, height=(int)1458, format=(string)I420, framerate=(fraction)30/1 ! "
               "nvvidconv ! video/x-raw, width=(int){}, height=(int){}, format=(string)BGRx ! "
               "videoconvert ! appsink").format(width, height)
    return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

def open_window(windowName, width, height):
    cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
    cv2.resizeWindow(windowName, width, height)
    cv2.moveWindow(windowName, 0, 0)
    cv2.setWindowTitle(windowName, "Camera Demo for Jetson TX2/TX1")

def read_cam(windowName, cap):
    showHelp = True
    showFullScreen = False
    helpText = "'Esc' to Quit, 'H' to Toggle Help, 'F' to Toggle Fullscreen"
    font = cv2.FONT_HERSHEY_PLAIN
    while True:
        if cv2.getWindowProperty(windowName, 0) < 0: # Check to see if the user closed the window
            # This will fail if the user closed the window; Nasties get printed to the console
            break;
        ret_val, displayBuf = cap.read();
        if showHelp == True:
            cv2.putText(displayBuf, helpText, (11,20), font, 1.0, (32,32,32), 4, cv2.LINE_AA)
            cv2.putText(displayBuf, helpText, (10,20), font, 1.0, (240,240,240), 1, cv2.LINE_AA)
        cv2.imshow(windowName, displayBuf)
        key = cv2.waitKey(10)
        if key == 27: # ESC key: quit program
            break
        elif key == ord('H') or key == ord('h'): # toggle help message
            showHelp = not showHelp
        elif key == ord('F') or key == ord('f'): # toggle fullscreen
            showFullScreen = not showFullScreen
            if showFullScreen == True: 
                cv2.setWindowProperty(windowName, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
            else:
                cv2.setWindowProperty(windowName, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_NORMAL) 

if __name__ == "__main__":
    args = parse_args()
    print("Called with args:")
    print(args)
    print("OpenCV version: {}".format(cv2.__version__))

    if args.use_rtsp:
        cap = open_cam_rtsp(args.rtsp_uri, args.image_width, args.image_height, args.rtsp_latency)
    elif args.use_usb:
        cap = open_cam_usb(args.video_dev, args.image_width, args.image_height)
    else: # by default, use the Jetson onboard camera
        cap = open_cam_onboard(args.image_width, args.image_height)

    if not cap.isOpened():
        sys.exit("Failed to open camera!")

    open_window(windowName, args.image_width, args.image_height)
    read_cam(windowName, cap)
    
    cap.release()
    cv2.destroyAllWindows()

2. Opening the Max performance of TX2

  • Jetson TX2 consists of a CPU and a GPU cluster. Dual - core CPU clusters composed of 2 processors and quad - core ARM Cortex-A57 in Denver, connected by a high-performance interconnect architectures.
  • Next I will list all modes of Jetson TX2 and the detail about it.
mode of TX2
  • Check the mode Version:
    sudo nvpmodel -q –verbose
    
  • Open the Max Power:
    sudo nvpmodel -m 0
    
  • Show the Information of GPU:
    sudo tegrastats
    #If you see some cpus not opening, you can run like this:
    sudo su
    echo 1 > /sys/devices/system/cpu/cpu1/online
    
    #执行~/jetson_clocks.sh可以开启最大频率
    ~/jetson_clocks.sh
    

3. About Host PC Failed to Fetch(sudo apt-get update failed)

sudo apt-get remove .*:arm64
sudo dpkg --remove-architecture arm64
#Then you can update your apt.
sudo apt-get update
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,332评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,508评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,812评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,607评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,728评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,919评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,071评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,802评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,256评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,576评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,712评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,389评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,032评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,798评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,026评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,473评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,606评论 2 350

推荐阅读更多精彩内容