空飛ぶロボットのつくりかた

ロボットをつくるために必要な技術をまとめます。ロボットの未来についても考えたりします。

virtualenvの使い方・仕組み

やりたいこと

pythonのいろんなライブラリを他の環境を汚さず試したい

使い方

インストールと起動

  1. pip install virtualenv

  2. virtualenv my_env

  3. source myenv/bin/activate

環境の保存

  1. pip freeze

無効化と削除

  1. deactivate

  2. rm -rf myenv/

ros x vertualenv

  1. pip install catkin_tools

  2. pip install empy

  3. pip install rospkg

How to install and launch Python node inside a virtualenv? - ROS Answers: Open Source Q&A Forum

python 3.x - After install ROS Kinetic, cannot import OpenCV - Stack Overflow

参考記事

virtualenv 基本的なコマンド使い方メモ - Qiita

Virtualenvの使い方 - Qiita

Pythonの仮想環境を構築できるvirtualenvを使ってみる - Qiita

virtualenvの使い方 - Qiita

Pythonの仮想環境構築(2017年版) pyenvとpyenv-virtualenvとvirtualenvとvirtualenvwrapperとpyvenvとvenv - Qiita

Python で仮想環境管理 venv の使い方 - Qiita

virtualenvを使っていろいろなライブラリを手軽にためそう | Developers.IO

virtualenvのインストール、使い方 - CHANyoshiのブログ

仕組み

ToDo

参考記事

pyenv, virtualenvの仕組み - Qiita

pyenvとvirtualenvについて勉強した時のメモ | kazsoga blog

【手順紹介】Pythonでvirtualenvをインストールしてみる - フラミナル

TX2を動かしてみる(JetPack3.1トライ)

やりたいこと

TX2でDeepLearningの何かしらのフレームワークとROSを動かす

結果

以下の記事を参考にtensorflowのインストールとOpenPoseの動作確認。

mobilenetのモデルでTX2でも8fpsくらいでる。

NVIDIA Jetson TX2でTensorFlowによる人体姿勢推定プログラムを動かせるようになるまで - Qiita

f:id:robonchu:20180107113020j:plain

以下を参考にROSのインストール。超簡単。

Install Robot Operating System (ROS) on NVIDIA Jetson TX2 - YouTube

Wiki

Jetson TX2 - eLinux.org

JetPack

Version 3.1を用いる

  • HPからダウンロード:

Jetson Download Center | NVIDIA Developer

手順

以下を参照

  1. NVIDIA JetPack Documentation

  2. JetPack 3.0 - NVIDIA Jetson TX2 - YouTube

  3. Force USB Recovery Modeの仕方はQuick Start Guide参照

参考:

Double Your Deep Learning Performance with JetPack 2.3 - YouTube

TX2のモード選択

用途に応じて消費電力と性能を選択するモードが用意されている

NVPModel - NVIDIA Jetson TX2 Development Kit - JetsonHacks

CSI camera

開発キットにはCSIカメラが取り付けられており、USBカメラに比べて処理がはやい

CSI Cameras on the TX2 (The Easy Way) - Peter Moran's Blog

https://devtalk.nvidia.com/default/topic/1005345/examples-on-how-to-use-the-jetson-carrier-board-camera-module-/

JetsonTX2 OnBoardCam · eiichiromomma/CVMLAB Wiki · GitHub

ROSでCSIカメラをlaunch

GitHub - peter-moran/jetson_csi_cam: A ROS package making it simple to use CSI cameras on the Nvidia Jetson TK1, TX1, or TX2 with ROS.

キャリアボード

価格

性能比較

f:id:robonchu:20180107151419p:plain

Deep Learning フレームワーク&OpenCV&ROSインストール

Caffe install

Caffe Deep Learning Framework - NVIDIA Jetson TX2 - YouTube

Tensorflow install

TensorFlow Install on NVIDIA Jetson TX2 - YouTube

JetsonTX2 Tensorflow · eiichiromomma/CVMLAB Wiki · GitHub

How to install TensorFlow on the NVIDIA Jetson TX2? · NVIDIA Jetson TX2 Recipes

GitHub - jetsonhacks/installTensorFlowTX2: Install TensorFlow on the NVIDIA Jetson TX2 Development Kit

Keras

Jetson TX2にKerasをインストールする - Qiita

Pytorch install

GitHub - andrewadare/jetson-tx2-pytorch: Installing PyTorch on the Nvidia Jetson TX1/TX2

Install procedure for pyTorch on NVIDIA Jetson TX1/TX2 · GitHub

OpenCV install

TensorFlow Install on NVIDIA Jetson TX2 - YouTube

ROS install

Install Robot Operating System (ROS) on NVIDIA Jetson TX2 - YouTube

OpenPoseインストール

OpenCV3を使うときはMakefieのOPENCV_VERSIONの設定を3にしてアンコメント

Tensorflow

NVIDIA Jetson TX2でTensorFlowによる人体姿勢推定プログラムを動かせるようになるまで - Qiita

GitHub - ildoonet/tf-pose-estimation: Openpose from CMU implemented using Tensorflow with Custom Architecture for fast inference.

Caffe

JetsonTX2 OpenPose · eiichiromomma/CVMLAB Wiki · GitHub

Issue

can't find hdf5.h when build caffe · Issue #156 · NVIDIA/DIGITS · GitHub

caffe fails with error undefined reference to `cv::imread(cv::String const&, int)' and undefined reference to `cv::imdecode(cv::_InputArray const&, int) · Issue #3700 · BVLC/caffe · GitHub

TX2用のinstall scriptsを使わない場合はMakefileを以下の用に書き換える必要がある↓

diff --git a/3rdparty/caffe/Makefile b/3rdparty/caffe/Makefile
index 8674f3a..46028f7 100644
--- a/3rdparty/caffe/Makefile
+++ b/3rdparty/caffe/Makefile
@@ -181,7 +181,7 @@ ifneq ($(CPU_ONLY), 1)
    LIBRARIES := cudart cublas curand
 endif
 
-LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
+LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
 
 # handle IO dependencies
 USE_LEVELDB ?= 1
diff --git a/3rdparty/caffe/Makefile.config.Ubuntu16_cuda8.example b/3rdparty/caffe/Makefile.config.Ubuntu16_cuda8.example
index fb92360..1f62114 100644
--- a/3rdparty/caffe/Makefile.config.Ubuntu16_cuda8.example
+++ b/3rdparty/caffe/Makefile.config.Ubuntu16_cuda8.example
@@ -100,7 +100,7 @@ PYTHON_LIB := /usr/lib /usr/local/lib
 
 # Whatever else you find you need goes here.
 INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
-LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
+LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu /usr/lib/aarch64-linux-gnu/hdf5/serial
 
 # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
 # INCLUDE_DIRS += $(shell brew --prefix)/include
diff --git a/Makefile b/Makefile
index 8e2109b..32a093e 100644
--- a/Makefile
+++ b/Makefile
@@ -146,7 +146,7 @@ ifneq ($(CPU_ONLY), 1)
 endif
 
 # LIBRARIES += glog gflags boost_system boost_filesystem m hdf5_hl hdf5 caffe
-LIBRARIES += glog gflags boost_system boost_filesystem m hdf5_hl hdf5
+LIBRARIES += glog gflags boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
 
 # handle IO dependencies
 USE_LEVELDB ?= 1
diff --git a/ubuntu/Makefile.config.Ubuntu16_cuda8.example b/ubuntu/Makefile.config.Ubuntu16_cuda8.example
index c2940dc..053da67 100644
--- a/ubuntu/Makefile.config.Ubuntu16_cuda8.example
+++ b/ubuntu/Makefile.config.Ubuntu16_cuda8.example
@@ -78,7 +78,7 @@ CAFFE_DIR := 3rdparty/caffe/distribute
 
 # Whatever else you find you need goes here.
 INCLUDE_DIRS := /usr/local/include /usr/include/hdf5/serial
-LIBRARY_DIRS := /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
+LIBRARY_DIRS := /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu /usr/lib/aarch64-linux-gnu/hdf5/serial
 
 # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
 # INCLUDE_DIRS += $(shell brew --prefix)/include

YOLOインストール

JetsonTX2 Yolo · eiichiromomma/CVMLAB Wiki · GitHub

CUDA8.0のインストール

https://devtalk.nvidia.com/default/topic/1001520/setting-up-cuda-manually-on-tx2/

参考

JetsonTX2 · eiichiromomma/CVMLAB Wiki · GitHub

https://devtalk.nvidia.com/default/topic/1027463/jetson-tx2/jetpack-3-2-installation-on-tx2-stops/

JetsonTX2初期セットアップ(Jetpack)からサンプルのコンパイルまでの手順 - Qiita

bash: cannot create temp file for here-document: No space left on device · GitHub

TX2を動かしてみる(JetPack3.2トライ)

やりたいこと

TX2でDeepLearningの何かしらのフレームワークとROSを動かす

結果

ToDo

Wiki

Jetson TX2 - eLinux.org

JetPack

最新のVersion 3.2を用いる

手順

以下を参照

  1. NVIDIA JetPack Documentation

  2. JetPack 3.0 - NVIDIA Jetson TX2 - YouTube

  3. Force USB Recovery Modeの仕方はQuick Start Guide参照

参考:

Double Your Deep Learning Performance with JetPack 2.3 - YouTube

Docker install

Home · open-horizon/cogwerx-jetson-tx2 Wiki · GitHub

cogwerx-jetson-tx2/tx2-post-setup at master · open-horizon/cogwerx-jetson-tx2 · GitHub

Deep Learning install

GitHub - open-horizon/cogwerx-jetson-tx2: Deep learning builds for NVIDIA Jetson TX2

Caffe install

Caffe Deep Learning Framework - NVIDIA Jetson TX2 - YouTube

Tensorflow install

TensorFlow Install on NVIDIA Jetson TX2 - YouTube

JetsonTX2 Tensorflow · eiichiromomma/CVMLAB Wiki · GitHub

How to install TensorFlow on the NVIDIA Jetson TX2? · NVIDIA Jetson TX2 Recipes

GitHub - jetsonhacks/installTensorFlowTX2: Install TensorFlow on the NVIDIA Jetson TX2 Development Kit

Keras

Jetson TX2にKerasをインストールする - Qiita

OpenCV install

TensorFlow Install on NVIDIA Jetson TX2 - YouTube

ROS install

Install Robot Operating System (ROS) on NVIDIA Jetson TX2 - YouTube

Pytorch install

GitHub - andrewadare/jetson-tx2-pytorch: Installing PyTorch on the Nvidia Jetson TX1/TX2

Install procedure for pyTorch on NVIDIA Jetson TX1/TX2 · GitHub

OpenPose

Tensorflow

NVIDIA Jetson TX2でTensorFlowによる人体姿勢推定プログラムを動かせるようになるまで - Qiita

GitHub - ildoonet/tf-pose-estimation: Openpose from CMU implemented using Tensorflow with Custom Architecture for fast inference.

Caffe

JetsonTX2 OpenPose · eiichiromomma/CVMLAB Wiki · GitHub

YOLO

JetsonTX2 Yolo · eiichiromomma/CVMLAB Wiki · GitHub

CSI camera

CSI Cameras on the TX2 (The Easy Way) - Peter Moran's Blog

https://devtalk.nvidia.com/default/topic/1005345/examples-on-how-to-use-the-jetson-carrier-board-camera-module-/

JetsonTX2 OnBoardCam · eiichiromomma/CVMLAB Wiki · GitHub

CUDA8.0のインストール

https://devtalk.nvidia.com/default/topic/1001520/setting-up-cuda-manually-on-tx2/

参考

JetsonTX2 · eiichiromomma/CVMLAB Wiki · GitHub

https://devtalk.nvidia.com/default/topic/1027463/jetson-tx2/jetpack-3-2-installation-on-tx2-stops/

JetsonTX2初期セットアップ(Jetpack)からサンプルのコンパイルまでの手順 - Qiita

ROS x Docker x ネットワーク のお勉強

 やりたいこと

dockerコンテナとホストPCでros messageの通信を行いたい

ROS

ROBOT PCでroscoreを起動

HOST PC

  1. export ROS_IP = (HOST PCのIP)

  2. export ROS_MASTER_URI=http://(ROBOTのIP):11311

    • 正確にはroscoreが立ち上がっているPCのIP

ROBOT PC

  1. export ROS_IP = (ROBOT PCのIP)

  2. exprot ROS_MASTER_URI=http://(ROBOTのIP):11311

確認方法

ROBOT_PC

  • $ rostopic pub -r 10 /topic_name std_msgs/String hello

HOST_PC

  • $ rostopic echo /topic_name

参考:

ja/ROS/Tutorials/MultipleMachines - ROS Wiki

ROS 使い方メモ -- ROS ネットワーキング

ログ表示

複数 PC に分散したノードの ROS を使った通信 - Daily Tech Blog

複数のPCで処理する方法 | ロボット理工学科 演習

ネットワーク設定 - PukiWiki

ROS 複数のPCを使ってノードを走らせる場合。: マイコン漬け

ROS x Docker

上記と基本的には同じ。

下記のように

docker inspect -f "{{.NetworkSettings.IPAddress}}" CONTAINER

でIPを調べてROS_IPにセットする。

docker-compose で立ち上げたコンテナの IP アドレスを調べる - Qiita

コンテナのIP固定の方法

docker固定IP - Qiita

Public accessible IP in container (like bridge network in VirtualBox) - DockerEngine - Docker Forums

参考:

Docker + ROS(kinetic)でチュートリアル - Qiita

dockerでROSを試したい - Qiita

Exposing ROS Containers to Host Machine - ROS Answers: Open Source Q&A Forum

Small ROS Network Example · GitHub

Challenges with running ROS on Kubernetes | Service Engineering (ICCLab & SPLab)

Docker v1.9のマルチホストネットワーク機能を使ったROS通信が可能か検証してみた - Qiita

Docker単体

参考:

Docker の基本学習 ~ コンテナ間のリンク - Qiita

マルチホストでのDocker Container間通信 第1回: Dockerネットワークの基礎 - UZABASE Tech Blog

Dockerのマルチホストネットワークで複数ホスト間を繋ぐ仮想ネットワークを作る(Dockerの最新機能を使ってみよう:第1回) | さくらのナレッジ

[社内向け]Docker勉強会(コンテナ同士の通信) - Qiita

4.5 Dockerネットワークについて

pytorch,keras,chainer x ROSのDockerfileを作ってみる

やりたいこと

ros x deep learningのいろいろなDockerfileを作ってどんな環境でもすぐに開発ができるようにする

以下

  • ubuntu16.04

  • GPU

  • ros-kinetic

をベースとしている

chainer

cupy==1.0.3 chainer==2.1.0

Dockerfile

FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04

RUN apt-get update -y && \
    apt-get install -y --no-install-recommends \
    python-dev \
    python-setuptools \
    python-pip && \
    rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

RUN pip install --upgrade pip
RUN pip install cupy==1.0.3 chainer==2.1.0
RUN pip install matplotlib

# install packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    dirmngr \
    gnupg2 \
    && rm -rf /var/lib/apt/lists/*

# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 421C365BD9FF1F717815A3895523BAEEB01FA116

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list

# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
    python-rosdep \
    python-rosinstall \
    python-vcstools \
    && rm -rf /var/lib/apt/lists/*

# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# bootstrap rosdep
RUN rosdep init \
    && rosdep update

# install ros packages
ENV ROS_DISTRO kinetic
RUN apt-get update && apt-get install -y \
    ros-kinetic-ros-core=1.3.1-0* \
    && rm -rf /var/lib/apt/lists/*

# install cv2
RUN apt-get update && apt-get install -y ros-kinetic-cv-bridge

# install editor and tools
RUN apt-get install -y emacs 
RUN apt-get install -y tmux
RUN apt-get install -y python-tk

# setup entrypoint
COPY ./ros_entrypoint.sh /

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]

docker images: https://hub.docker.com/r/einstein25/chainer-ros-gpu/

pytorch

gpuが使えているかは

print torch.cuda.is_available()

で確認

Dockerfile

FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04

RUN apt-get update -y && \
    apt-get install -y --no-install-recommends \
    python-dev \
    python-setuptools \
    python-pip && \
    rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

RUN pip install --upgrade pip
RUN pip install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp27-cp27mu-linux_x86_64.whl
RUN pip install torchvision 
RUN pip install matplotlib

# ros install
# install packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    dirmngr \
    gnupg2 \
    && rm -rf /var/lib/apt/lists/*

# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 421C365BD9FF1F717815A3895523BAEEB01FA116

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list

# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
    python-rosdep \
    python-rosinstall \
    python-vcstools \
    && rm -rf /var/lib/apt/lists/*

# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# bootstrap rosdep
RUN rosdep init \
    && rosdep update

# install ros packages
ENV ROS_DISTRO kinetic
RUN apt-get update && apt-get install -y \
    ros-kinetic-ros-core=1.3.1-0* \
    && rm -rf /var/lib/apt/lists/*

# install cv2
RUN apt-get update && apt-get install -y ros-kinetic-cv-bridge

# setup entrypoint
COPY ./ros_entrypoint.sh /

# install editor and tools
RUN apt-get install -y emacs
RUN apt-get install -y tmux
RUN apt-get install -y python-tk

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]

docker images: https://hub.docker.com/r/einstein25/pytorch-ros-gpu/

keras

Dockerfile

FROM nvidia/cuda:8.0-cudnn6-devel-ubuntu16.04

RUN apt-get update -y && \
    apt-get install -y --no-install-recommends \
    python-dev \
    python-setuptools \
    python-pip && \
    rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

RUN pip install --upgrade pip
RUN pip install matplotlib
RUN pip install tensorflow-gpu keras

# ros install
# install packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    dirmngr \
    gnupg2 \
    && rm -rf /var/lib/apt/lists/*

# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 421C365BD9FF1F717815A3895523BAEEB01FA116

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list

# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
    python-rosdep \
    python-rosinstall \
    python-vcstools \
    && rm -rf /var/lib/apt/lists/*

# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# bootstrap rosdep
RUN rosdep init \
    && rosdep update

# install ros packages
ENV ROS_DISTRO kinetic
RUN apt-get update && apt-get install -y \
    ros-kinetic-ros-core=1.3.1-0* \
    && rm -rf /var/lib/apt/lists/*

# install cv2
RUN apt-get update && apt-get install -y ros-kinetic-cv-bridge

# setup entrypoint
COPY ./ros_entrypoint.sh /

# install editor and tools
RUN apt-get install -y emacs
RUN apt-get install -y tmux
RUN apt-get install -y python-tk

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]

docker images: https://hub.docker.com/r/einstein25/keras-ros-gpu/

動作確認

(container)# apt install wget
(container)# wget https://raw.githubusercontent.com/fchollet/keras/master/examples/mnist_cnn.py
(container)# python mnist_cnn.py

Dockerhubを使ってみる

やりたいこと

dockerhubでimageを管理したい

dockerhubにpushする手順

  1. アカウントの登録: https://hub.docker.com/

  2. Create Repository

  3. imageのrepository nameをdockerhubのrepository nameと揃える

    • ex: $ docker tag [image ID] einstein25/chainer-ros-gpu:v1
  4. pushする

    • ex: $ docker push einstein25/chainer-ros-gpu:v1

That's all ! 簡単!!

ROS x Dockerのお勉強

やりたいこと

ROSをDockerで動かしたい。

参考資料

Docker + ROS(kinetic)でチュートリアル - Qiita

https://hub.docker.com/r/_/ros/

docker - ROS Wiki

dockerでROSを試したい - Qiita

ROS-Docker-tutorial.md · GitHub

docs/ros at master · docker-library/docs · GitHub

Mac版DockerでROSを動かしてみたメモ - Qiita

ロボット向けアプリケーションをDockerコンテナで動かす - Qiita

第8回ROS勉強会へ行ってきました - memoメモ

Ubuntu16.04上でDocerを使いROSを動かす: たこ104のブログ

ros.youtalk.jp — ROS 2 + Dockerによるフォールトトレランス実践 (1)

参考動画

ROS Docker Demo - YouTube

Dockerfile

FROM ros:kinetic
# install ros tutorials packages
RUN apt-get update && apt-get install -y
RUN apt-get install -y ros-kinetic-ros-tutorials \
    ros-kinetic-common-tutorials \
    && rm -rf /var/lib/apt/lists/

Build

  • docker build --tag ros:ros-tutorials .

Tutorial

master, talker, listenerの3つを動作させ,talkerが発するメッセージをlistenerが聞く

  1. networkの作成

    • docker network create rosnet
  2. masterの起動

    • docker run -it --net rosnet --name master ros:ros-tutorials roscore
  3. talkerの起動

    • docker run -it --net rosnet --name talker --env ROS_HOSTNAME=talker --env ROS_MASTER_URI=http://master:11311 ros:ros-tutorials rosrun roscpp_tutorials talker
  4. listenerの起動

    • docker run -it --net rosnet --name listener --env ROS_HOSTNAME=listener --env ROS_MASTER_URI=http://master:11311 ros:ros-tutorials rosrun roscpp_tutorials listener

Docker Compose

Now that you have an appreciation for bootstrapping a distributed ROS example manually, lets try and automate it using docker-compose.

rosでいうlaunchファイル的なもの

docker-compose.yml

version: '2'
services:
  master:
    build: .
    container_name: master
    command:
      - roscore

  talker:
    build: .
    container_name: talker
    environment:
      - "ROS_HOSTNAME=talker"
      - "ROS_MASTER_URI=http://master:11311"
    command: rosrun roscpp_tutorials talker

  listener:
    build: .
    container_name: listener
    environment:
      - "ROS_HOSTNAME=listener"
      - "ROS_MASTER_URI=http://master:11311"
    command: rosrun roscpp_tutorials listener

docker build -> runを実行

  • 起動方法
    • docker-compose up

Docker composeの参考

docker-composeを使うと複数コンテナの管理が便利に - Qiita

ROS x Docker x GUI

docker/Tutorials/GUI - ROS Wiki

xhostコマンドの使い方

手順

  1. xhost +

  2. 以下コマンドを実行

docker run -it \
    --env="DISPLAY" \
    --env="QT_X11_NO_MITSHM=1" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    osrf/ros:indigo-desktop-full \
    rqt
export containerId=$(docker ps -l -q)

ROS(kinetic) x Docker x GPU

docker/Tutorials/Hardware Acceleration - ROS Wiki

1: Dockerfileの準備

FROM osrf/ros:kinetic-desktop-full
# nvidia-docker hooks
LABEL com.nvidia.volumes.needed="nvidia_driver"
ENV PATH /usr/local/nvidia/bin:${PATH}
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH}

2: build

docker build --tag ros:nvidia .

3: run

nvidia-docker run -it \
    --env="DISPLAY" \
    --env="QT_X11_NO_MITSHM=1" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    ros:nvidia \
    bash -c "roscore & rosrun rviz rviz"

f:id:robonchu:20171217192721p:plain

うごけばおけぃ

Deep Learningフレームワークをいろいろ動かす

Dockerfile

以下を追記

RUN apt-get update
RUN apt-get install emacs
RUN apt-get install tmux
RUN apt-get install wget
RUN apt-get install -y python-pip
RUN pip install tensorflow-gpu keras
RUN pip install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp27-cp27mu-linux_x86_64.whl
RUN pip install torchvision

kerasを動かす

  1. docker cp cuda-8.0/ [コンテナID]:/usr/local/

  2. コンテナ内でPATHの設定

  3. wget https://raw.githubusercontent.com/fchollet/keras/master/examples/mnist_cnn.py

  4. python mnist_cnn.py

pytorchを動かす

  1. python pytorch_sample.py

線形回帰をといてみる

TODO

torch.nn — PyTorch master documentation

chainer

FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu16.04

RUN apt-get update -y && \
    apt-get install -y --no-install-recommends \
    python-dev \
    python-setuptools \
    python-pip && \
    rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

RUN pip install --upgrade pip
RUN pip install cupy==1.0.3 chainer==2.1.0

# install packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    dirmngr \
    gnupg2 \
    && rm -rf /var/lib/apt/lists/*

# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 421C365BD9FF1F717815A3895523BAEEB01FA116

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list

# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
    python-rosdep \
    python-rosinstall \
    python-vcstools \
    && rm -rf /var/lib/apt/lists/*

# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# bootstrap rosdep
RUN rosdep init \
    && rosdep update

# install ros packages
ENV ROS_DISTRO kinetic
RUN apt-get update && apt-get install -y \
    ros-kinetic-ros-core=1.3.1-0* \
    && rm -rf /var/lib/apt/lists/*

# install cv2
RUN apt-get update && apt-get install -y ros-kinetic-cv-bridge

# install editor and tools
RUN apt-get install emacs 
RUN apt-get install tmux 

# setup entrypoint
COPY ./ros_entrypoint.sh /

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]

TODO

  1. TX2 x ROS上でpytorchを動かす