Jetson Nano 2GB + Tensorflow1.15 + ROS
1. Jetson Nano 2GB 本文使用2GB版本的Jetson Nano 来配置深度学习环境,同时安装ROS系统,为后面开发做铺垫。 2. jetpack 4.6 下载与安装 (建议用梯子,不然很慢) 镜像下载: Jetson Nano 2GB Developer Kit SD Card Image 也可在这个网址下载:https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-2gb-devkit#write 存储卡格式化软件:https://www.sdcard.org/downloads/formatter/ 镜像烧录软件: https://www.balena.io/etcher/
** Jetpack4.6本质还是Ubuntu18.04,具体设置不在赘述!**
Jetpack4.6 自带OpenCv4.1.1 不用我们安装,查看版本代码如下:
pkg-config --modversion opencv4
3. Tensorflow1.15 安装,因项目需要,安装的Tensorflow<2 3.1 安装好Jetpack4.6 之后,我们来安装tensorflow1.15,根据官网提示,JetPack4.6对标Tensorflow1.5,大家安装时一定要看准版本,不然很难安装成功! 3.2安装TensorFlow需要的系统包
sudo apt-get update
sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
3.3 安装和升级 pip3
sudo apt-get install python3-pip
sudo pip3 install -U pip testresources setuptools==49.6.0
3.4 安装 Python 包依赖项
sudo pip3 install -U numpy==1.19.4 future==0.18.2 mock==3.0.5 h5py==2.10.0 keras_preprocessing==1.1.1 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11
*注意,Warning不用刻意去解决,只需关注ERROR就行!*
3.5 使用pip3安装与 JetPack 4.6 兼容的最新版本的TensorFlow
sudo pip3 install --pre --extra-index-url https:
3.6 安装 TensorFlow 1.x 包 注意引号! 该命令会安装最新的1.X版本
sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v46 'tensorflow<2'
3.7 安装指定版本,需要查看官网的表确定版本
sudo pip3 install --extra-index-url https:
**
安装成功界面
** 4. 深度学习实现图像识别 4.1 下载Jetson Nano 官方案例库 注意第8条指令,无法执行,因为有墙,这条指令可以跳过 首先进入:https://github.com/dusty-nv/jetson-inference/releases 下载需要的深度学习模型,之后利用XFTP软件传输至Jetson Nano 的jetson-inference/data/newworks目录下 完成以上操作,再从第九条指令开始执行!
$ sudo apt-get update
$ sudo apt-get install git cmake libpython3-dev python3-numpy
$ git clone --recursive https:
$ cd jetson-inference
$ mkdir build
$ cd build
$ cmake ../
$ make -j$(nproc)
$ sudo make install
$ sudo ldconfig
4.2 解压命令
cd <jetson-inference>/data/networks/
tar -zxvf <model-archive-name>.tar.gz
4.3 更新
$ sudo apt-get update
$ sudo apt-get install git cmake
4.4 编译项目
$ cd jetson-inference/build
$ make
$ sudo make install
$ sudo ldconfig
4.5 ImageNet程序和运行步骤
jetson.inference.imageNet = class imageNet(tensorNet)
| Image Recognition DNN - classifies an image
|
| __init__(...)
| Loads an image recognition model.
|
| Parameters:
| network (string) -- name of a built-in network to use
| values can be: 'alexnet', 'googlenet', 'googlenet-12', 'resnet-18`, ect.
| the default is 'googlenet'
|
| argv (strings) -- command line arguments passed to imageNet,
| for loading a custom model or custom settings
|
| Classify(...)
| Classify an RGBA image and return the object's class and confidence.
|
| Parameters:
| image (capsule) -- CUDA memory capsule
| width (int) -- width of the image (in pixels)
| height (int) -- height of the image (in pixels)
|
| Returns:
| (int, float) -- tuple containing the object's class index and confidence
|
| GetClassDesc(...)
| Return the class description for the given object class.
|
| Parameters:
| (int) -- index of the class, between [0, GetNumClasses()]
|
| Returns:
| (string) -- the text description of the object class
|
| GetNumClasses(...)
| Return the number of object classes that this network model is able to classify.
|
| Parameters: (none)
|
| Returns:
| (int) -- number of object classes that the model supports
----------------------------------------------------------------------
4.5.1
$ cd jetson-inference/build/aarch64/bin
4.5.2 使用的是googleNet
# C++
$ ./imagenet images/orange_0.jpg images/test/output_0.jpg # (default network is googlenet)
# Python
$ ./imagenet.py images/orange_0.jpg images/test/output_0.jpg # (default network is googlenet)
注意,第一次运行程序,可能会出现内存不足的问题,因为执行了TensorRT优化网络,在以后的执行中不会出现!
结果图如下:
- 安装ROS
5.1
# install ROS Melodic
$ sudo apt-add-repository universe
$ sudo apt-add-repository multiverse
$ sudo apt-add-repository restricted
5.2
# add ROS repository to apt sources
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
$ sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
5.3不建议安装full的,在嵌入式设备上可能会爆内存!
# install ROS Base
$ sudo apt-get update
$ sudo apt-get install ros-melodic-ros-desktop
5.4 初始化
sudo rosdep init
注意,可能会出现命令不存在的问题,需要自行安装 如下:
sudo apt-get install python-rosdep
5.5 安装完成,设置环境变量
# add ROS paths to environment
sudo sh -c 'echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc'
5.6 启动
roscore
5.7 运行实例
5.7.1 安装ros turtlesim
sudo apt install ros-melodic-turtlesim
5.7.2 打开三个终端,分别输入
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
为什么要三个终端? 一个终端就相当于一个正在运行的程序,因为启动ros,需要一个终端,启动机器人,又是一个终端,然后启动键盘控制节点是第三个终端,这三个终端是一直运行的,你才能够通过键盘控制机器人运动,如果你关闭了其中一个终端,就会报错!
至此,完成了Jetson Nano 2GB 系统安装、Tensorflow1.15安装与深度学习模型运行、ROS系统安装与实例运行!
|