コンテンツへスキップ

NVIDIA Jetson Nano 初期設定 その1

NVIDIA Jetson Nano初期設定①

SDカードなどを用いて、最初のOSイメージを作成し、Jetson Nanoを起動させます。
参考記事:Jetson Nano DeveloperをUSB 接続HDD/SSDルート構成

導入パッケージのアップデート

sudo apt update
sudo apt upgrade -y

SWAP領域作成

SWAP領域は、ディスクアクセスが多いので、USB接続のHDD上にSWAP領域を作成しました。
/dev/sda1 swap swapをSWAPとしました。
また、各種ユーザー領域として、/dev/sda2のパーティションを作成し、両方のパーティションがブート時に自動マウントされるように、/etc/fstabに登録します。また、デバイス名(/dev/sda, /dev/sdbなど)はブート時に変わる場合もあるので、UUIDを用いて、fstabaへの設定をおすすめします。

UUID=75f4a210-081e-4572-8f0a-bffb1f3d84c3 swap   swap     defaults                    0  0

UUIDは、デバイスの以下のコマンドで確認出来ます。

root@jetson:~# ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx 1 root root 10 10月 1 17:41 408b9b27-133c-475d-8b8e-151ebe91e6e9 -> ../../sda2
lrwxrwxrwx 1 root root 10 10月 1 17:41 75f4a210-081e-4572-8f0a-bffb1f3d84c3 -> ../../sda1

各種パッケージ導入

TensorFlow導入

NVIDIAの開発者コミュニティに記載されている内容で、インストールを行います。

https://docs.nvidia.com/deeplearning/frameworks/install-tf-jetson-platform/index.html#install

    1. 前提ソフトをaptコマンドを用いてインストールします。
      $ sudo apt install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev
      
    2. pip3のアップデートを行います。
      $ sudo apt install python3-pip
      $ sudo pip3 install -U pip
    3. NVIDIAの開発サイトからtensorflow-gpuをインストールします。
      $ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu

インストールコマンド実行により、以下のパッケージがインストールされました。

Successfully installed absl-py-0.8.0 astor-0.8.0 gast-0.2.2 google-pasta-0.1.7 grpcio-1.24.0 h5py-2.10.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.1.1 numpy-1.17.2 protobuf-3.10.0rc1 setuptools-41.2.0 tensorboard-1.14.0 tensorflow-estimator-1.14.0 tensorflow-gpu-1.14.0+nv19.9 termcolor-1.1.0 werkzeug-0.16.0 wrapt-1.11.2

keras導入

インストール自体は 「pip3 install keras」 なのですが、依存関係のあるscipyのインストールに失敗します。scipyインストールに必要なライブラリーを事前にインストールしておきます。
以下インストール失敗時の画面コピーです。
  Downloading https://files.pythonhosted.org/packages/ee/5b/5afcd1c46f97b3c2ac3489dbc95d6ca28eacf8e3634e51f495da68d97f0f/scipy-1.3.1.tar.gz (23.6MB)
     |████████████████████████████████| 23.6MB 20.9MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 /usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp4e1y85sd
         cwd: /tmp/pip-install-_nnfhs_r/scipy
    Complete output (139 lines):
    lapack_opt_info:
    lapack_mkl_info:
    customize UnixCCompiler
      libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
      NOT AVAILABLE
    
    openblas_lapack_info:
    customize UnixCCompiler
    customize UnixCCompiler
      libraries openblas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
      NOT AVAILABLE
    
    openblas_clapack_info:
    customize UnixCCompiler
    customize UnixCCompiler
      libraries openblas,lapack not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
      NOT AVAILABLE
    
    flame_info:
    customize UnixCCompiler
      libraries flame not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
      NOT AVAILABLE
    
    atlas_3_10_threads_info:
    Setting PTATLAS=ATLAS
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/local/lib
    customize UnixCCompiler
      libraries tatlas,tatlas not found in /usr/local/lib
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/lib
    customize UnixCCompiler
      libraries tatlas,tatlas not found in /usr/lib
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/lib/aarch64-linux-gnu
    customize UnixCCompiler
      libraries tatlas,tatlas not found in /usr/lib/aarch64-linux-gnu
    <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
      NOT AVAILABLE
    
    atlas_3_10_info:
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/local/lib
    customize UnixCCompiler
      libraries satlas,satlas not found in /usr/local/lib
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/lib
    customize UnixCCompiler
      libraries satlas,satlas not found in /usr/lib
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/lib/aarch64-linux-gnu
    customize UnixCCompiler
      libraries satlas,satlas not found in /usr/lib/aarch64-linux-gnu
    <class 'numpy.distutils.system_info.atlas_3_10_info'>
      NOT AVAILABLE
    
    atlas_threads_info:
    Setting PTATLAS=ATLAS
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/local/lib
    customize UnixCCompiler
      libraries ptf77blas,ptcblas,atlas not found in /usr/local/lib
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/lib
    customize UnixCCompiler
      libraries ptf77blas,ptcblas,atlas not found in /usr/lib
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/lib/aarch64-linux-gnu
    customize UnixCCompiler
      libraries ptf77blas,ptcblas,atlas not found in /usr/lib/aarch64-linux-gnu
    <class 'numpy.distutils.system_info.atlas_threads_info'>
      NOT AVAILABLE
    
    atlas_info:
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/local/lib
    customize UnixCCompiler
      libraries f77blas,cblas,atlas not found in /usr/local/lib
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/lib
    customize UnixCCompiler
      libraries f77blas,cblas,atlas not found in /usr/lib
    customize UnixCCompiler
      libraries lapack_atlas not found in /usr/lib/aarch64-linux-gnu
    customize UnixCCompiler
      libraries f77blas,cblas,atlas not found in /usr/lib/aarch64-linux-gnu
    <class 'numpy.distutils.system_info.atlas_info'>
      NOT AVAILABLE
    
    accelerate_info:
      NOT AVAILABLE
    
    lapack_info:
    customize UnixCCompiler
      libraries lapack not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
      NOT AVAILABLE
    
    lapack_src_info:
      NOT AVAILABLE
    
      NOT AVAILABLE
    
    setup.py:388: UserWarning: Unrecognized setuptools command ('dist_info --egg-base /tmp/pip-install-_nnfhs_r/scipy/pip-wheel-metadata'), proceeding with generating Cython sources and expanding templates
      ' '.join(sys.argv[1:])))
    Running from scipy source directory.
    /usr/local/lib/python3.6/dist-packages/numpy/distutils/system_info.py:1712: UserWarning:
        Lapack (http://www.netlib.org/lapack/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [lapack]) or by setting
        the LAPACK environment variable.
      if getattr(self, '_calc_info_{}'.format(lapack))():
    /usr/local/lib/python3.6/dist-packages/numpy/distutils/system_info.py:1712: UserWarning:
        Lapack (http://www.netlib.org/lapack/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [lapack_src]) or by setting
        the LAPACK_SRC environment variable.
      if getattr(self, '_calc_info_{}'.format(lapack))():
    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py", line 207, in <module>
        main()
      File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py", line 197, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py", line 69, in prepare_metadata_for_build_wheel
        return hook(metadata_directory, config_settings)
      File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 156, in prepare_metadata_for_build_wheel
        self.run_setup()
      File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 237, in run_setup
        self).run_setup(setup_script=setup_script)
      File "/usr/local/lib/python3.6/dist-packages/setuptools/build_meta.py", line 142, in run_setup
        exec(compile(code, __file__, 'exec'), locals())
      File "setup.py", line 505, in <module>
        setup_package()
      File "setup.py", line 501, in setup_package
        setup(**metadata)
      File "/usr/local/lib/python3.6/dist-packages/numpy/distutils/core.py", line 137, in setup
        config = configuration()
      File "setup.py", line 403, in configuration
        raise NotFoundError(msg)
    numpy.distutils.system_info.NotFoundError: No lapack/blas resources found.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp4e1y85sd Check the logs for full command output.

依存ライブラリのインストール

# apt install libatlas-base-dev gfortran

次に、cythonをインストールします。

root@jetson:~# pip3 install -U cython
Collecting cython
Installing collected packages: cython
Successfully installed cython-0.29.13
pip3 install Keras

Kerasインストール後に以下のメッセージが表示されます。

Installing collected packages: scipy, Keras
Successfully installed Keras-2.3.0 scipy-1.3.1

OpenCV導入

NVIDIAのJetson Nanoでは、Open CVインストール向けに各種スクリプトが公開されています。基本的に、公開されているスクリプトを用いれば、簡単にOpenCVを導入することが出来ます。

NVIDIAのCuda対応のOpenCVが、各種バージョン簡単に導入できるのは、非常に助かります。
バージョン3系と4系を複数導入してみましたが、特に問題は起きませんでした。

#!/bin/bash
#
# Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.
#

if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <Install Folder>"
    exit
fi
folder="$1"
user="nvidia"
passwd="nvidia"

echo "** Remove OpenCV3.3 first"
sudo sudo apt-get purge *libopencv*

echo "** Install requirement"
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python2.7-dev python3.6-dev python-dev python-numpy python3-numpy
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl
sudo apt-get update

echo "** Download opencv-4.0.0"
cd $folder
curl -L https://github.com/opencv/opencv/archive/4.0.0.zip -o opencv-4.0.0.zip
curl -L https://github.com/opencv/opencv_contrib/archive/4.0.0.zip -o opencv_contrib-4.0.0.zip
unzip opencv-4.0.0.zip 
unzip opencv_contrib-4.0.0.zip 
cd opencv-4.0.0/

echo "** Building..."
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="5.3" -D CUDA_ARCH_PTX="" -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.0/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j3
sudo make install

echo "** Install opencv-4.0.0 successfully"
echo "** Bye :)"
mkdir opencv
sh install_opencv4.0.0_Nano.sh opencv
(コンパイル/インストールが始まります)

python3-opencv (3.2.0+dfsg-4ubuntu0.1) を設定しています ...
python-opencv (3.2.0+dfsg-4ubuntu0.1) を設定しています ...
libc-bin (2.27-3ubuntu1) のトリガを処理しています ...
** Install opencv-4.1.0 successfully
** Bye 🙂

インストール後の確認

root@jetson:/home/miki# python3
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.1.0'

created by Rinker
NVIDIA
¥19,000 (2021/08/19 16:46:56時点 Amazon調べ-詳細)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA