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

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

telloの画像でtiny yolo and v3 を試してみる

f:id:robonchu:20181009211731p:plain

やりたいこと

安い割に性能がなかなか良い中国製 Toy Drone "tello"のカメラを使って、yoloをまわす。

今回はpytorchでやってみる。

Shanghai Maker Carnivalのための準備 !

pytorchのインストール

python2.7のCPUバージョン

  1. pip install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl

  2. pip install torchvision

pipのエラーが出たら以下で対処。いつのまにこんなことに。。。

python2.7 GPUバージョン(CUDA 8.x)

  1. pip install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl

  2. pip install torchvision

CUDA8.0 and cuDNN6 のインストール

Telloをpythonで操作するための設定

ffmpegのインストール

  1. git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg

  2. ./configure --disable-static --enable-shared --disable-x86asm

  3. make -j 4

  4. sudo make install

PyAvのインストール

  1. sudo pip install av==0.5.2

  2. パスの設定

    1. export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/usr/local/lib:$LD_LIBRARY_PATH

Tellopy

以下に従ってイントール

  1. pip install tellopy

画像の取得や処理は以下のスクリプトを実行

  1. WIFIでtelloとPCをつなぐ

  2. cd TelloPy/tellopy/examples/

  3. python video_effect.py

処理を早くしたいときは以下の対策

こうするとtelloの画像が取得できる

yolo v2 and 3 by Pytorch

上記を参考に実行。

  1. yolo v2 by web cam

    1. python demo.py cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights
  2. yolo v3 by image

    1. python detect.py cfg/yolov3.cfg yolov3.weights data/dog.jpg

pytorchのバージョンの問題でエラーが発生。以下で対処。

The actual solution is changing 

conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w])); start = start + num_w

to

conv_model.weight.data.copy_(torch.reshape(torch.from_numpy(buf[start:start+num_w]),(conv_model.weight.shape[0],conv_model.weight.shape[1], conv_model.weight.shape[2],conv_model.weight.shape[3]))); start=start + num_w

tello画像を使ってyoloを回す

GitHub - marvis/pytorch-yolo2: Convert https://pjreddie.com/darknet/yolo/ into pytorch のdemo.pyの入力にGitHub - hanyazou/TelloPy: DJI Tello drone controller python packageのvideo_effect.pyで取得した画像を入れる。

f:id:robonchu:20181009215019j:plain

f:id:robonchu:20181009215151p:plain

所感

明後日から初めての中国。。。

Let's Enjoy !!!

参考