AI

ubuntu18.04でstruct2depthを使ってみた

struct2depthとは、Google Brainが開発した、単眼カメラから深度とエゴモーション(カメラ自身の動き)を推定する手法です。

仮想環境(VirtualBox)を使ってまっさらの環境から動くところまでです。

環境
OS: Ubuntu18.04LTS
Python 2.7.17
Tensorflow 1.12.0
Opencv 4.4.0-pre

まず以下の順番で必要なライブラリをインストールしていきます。

sudo apt install python-pip
pip install --upgrade pip
pip install absl-py
pip install numpy
pip install tensorflow==1.12.0
pip install matplotlib

つぎにgithubからstruct2depthをcloneします。
tensorflow/models: Models and examples built with TensorFlow

git clone https://github.com/tensorflow/models.git

struct2depthはresearch/struct2depthにあります。
そのディレクトリに、inputとoutputというディレクトリを作る。

SnapCrab_No-0000

学習済みのモデルをダウンロードする。

KITTIで学習したモデル
struct2depth_model_kitti.tar.gz – Google ドライブ
Cityscapesで学習したモデル
struct2depth_model_cityscapes.tar.gz – Google ドライブ

これらのモデルはmodelディレクトリに格納します。
SnapCrab_No-0001

inputディレクトリにgoogleストリートビューで拾ってきた適当な画像を格納します。

SnapCrab_No-0002

なお、対応拡張子はpngです。
inputの中には階層分けされたデータセットを入れても、正常に処理されます。

ここまでできたら推論の開始、struct2depthのルートに戻って以下のコマンドを実行します。
この場合KITTIのモデルを使用しています。
python inference.py --logtostderr --file_extension png --depth --egomotion true --input_dir input --output_dir output --model_ckpt model/model-199160

ここで、自分の環境では実行時に下記のエラーが発生しました。
locale.Error: unsupported locale setting
です。

これを解決するための情報はこちらにありました。

fixed script relative link by bigsnarfdude · Pull Request #58 · tensorflow/models

Changing line 236 in util.py
locale.setlocale(locale.LC_ALL, ‘en_US’) to locale.setlocale(locale.LC_ALL, ‘en_US.UTF-8’)
solves the problem for me.

書かれている通り、struct2depth/util.pyのlocale.setlocale(locale.LC_ALL, ‘en_US’)を変更しましょう。



locale.setlocale(locale.LC_ALL, 'en_US')

locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

気を取り直してもう一度推論の開始。
python inference.py --logtostderr --file_extension png --depth --egomotion true --input_dir input --output_dir output --model_ckpt model/model-199160

無事、解析が終わりました。
1

2

結構距離の推測ができている感じです。

主に下記URLの情報を参考にさせていただきました。
非常に助かりました。ありがとうございます。
struct2depth(距離推定)を動かしてみた – ハードウェア技術者のスキルアップ日誌

SSD_KERAS(AI)を使って物体認識をしてみた。前のページ

iPhoneでMacにAirdropで写真を送るとデフォルトでHEICだったから次のページ

最近の記事

Twitter

PAGE TOP