0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

単眼深度推定モデルMonoDepth2をMacbookで動かしてみた

Last updated at Posted at 2021-08-06

単眼カメラで撮影された画像ファイルから、距離情報を推定する深層学習モデルの一つに、__Monodepth2モデル__があります。

Qiitaの記事を含めて、このモデルを解説した日本語記事があります。

今回、Macbookに、__Monodepth2モデルgit clone__sして、学習済みモデルに1枚の画像ファイルを渡して、挙動を確認してみました。

( 実行環境 )

  • OS: macOS Catalina
  • Python ver.: Python 3.9.6

git cloneで資源取得

まずは、__git clone__です。

Terminal
electron@diynoMacBook-Pro Desktop % git clone https://github.com/nianticlabs/monodepth2.git

ディレクトリの中身を確認。

Terminal
electron@diynoMacBook-Pro Desktop % cd monodepth2 
electron@diynoMacBook-Pro monodepth2 % ls
LICENSE				evaluate_depth.py		layers.py			train.py
README.md			evaluate_pose.py		networks			trainer.py
assets				experiments			options.py			utils.py
datasets			export_gt_depth.py		splits
depth_prediction_example.ipynb	kitti_utils.py			test_simple.py
electron@diynoMacBook-Pro monodepth2 % 
Terminal
electron@diynoMacBook-Pro monodepth2 % pip3 install tensorboardX==1.4 

GitHubのチュートリアルのサンプルコードを動かす(成功)

####Prediction for a single image
You can predict scaled disparity for a single image with:

python test_simple.py --image_path assets/test_image.jpg --model_name mono+stereo_640x192

引数でtest_sinple.py__に渡す画像ファイルは、これ

test_image.jpg

test_image.jpg

選択するモデル

コマンドライン引数で、次の__9種類の学習済みモデル__を選ぶことができます。

test_simple.py
    parser.add_argument('--model_name', type=str,
                        help='name of a pretrained model to use',
                        choices=[
                            "mono_640x192",
                            "stereo_640x192",
                            "mono+stereo_640x192",
                            "mono_no_pt_640x192",
                            "stereo_no_pt_640x192",
                            "mono+stereo_no_pt_640x192",
                            "mono_1024x320",
                            "stereo_1024x320",
                            "mono+stereo_1024x320"])

今回は、__mono+stereo_640x192__というモデルを選択します。

Terminal
electron@diynoMacBook-Pro monodepth2 % python3 test_simple.py --image_path assets/test_image.jpg --model_name mono+stereo_640x192
-> Downloading pretrained model to models/mono+stereo_640x192.zip
   Unzipping model...
   Model unzipped to models/mono+stereo_640x192
-> Loading model from  models/mono+stereo_640x192
   Loading pretrained encoder
   Loading pretrained decoder
-> Predicting on 1 test images
   Processed 1 of 1 images - saved predictions to:
   - assets/test_image_disp.jpeg
   - assets/test_image_disp.npy
-> Done!
electron@diynoMacBook-Pro monodepth2 % 

出力ファイルを確認

  • __test_image_disp.jpeg__がある。
Terminal
electron@diynoMacBook-Pro monodepth2 % ls assets/
copyright_notice.txt	teaser.gif		test_image.jpg		test_image_disp.jpeg	test_image_disp.npy
electron@diynoMacBook-Pro monodepth2 % 
  • openコマンドでファイルを開く
Terminal
electron@diynoMacBook-Pro monodepth2 % open assets/test_image_disp.jpeg

test_image_disp.jpeg

他の画像ファイルで試してみる

次のウェブサイトから、エベレスト山の全景を収めた画像ファイルを拝借。

( 画像ファイルのURLを取得 )

スクリーンショット 2021-08-06 18.49.28.png

wgetコマンドでget

Terminal
electron@diynoMacBook-Pro monodepth2 % cd assets
electron@diynoMacBook-Pro assets % wget https://tabizine.jp/wp-content/uploads/2017/10/156619-01.jpg
--2021-08-06 18:47:42--  https://tabizine.jp/wp-content/uploads/2017/10/156619-01.jpg
tabizine.jp (tabizine.jp) をDNSに問いあわせています... 163.43.243.84
tabizine.jp (tabizine.jp)|163.43.243.84|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 217988 (213K) [image/jpeg]
`156619-01.jpg' に保存中

156619-01.jpg                         100%[======================================================================>] 212.88K  --.-KB/s 時間 0.1s     

2021-08-06 18:47:42 (1.57 MB/s) - `156619-01.jpg' へ保存完了 [217988/217988]

electron@diynoMacBook-Pro assets % ls
156619-01.jpg		copyright_notice.txt	teaser.gif		test_image.jpg		test_image_disp.jpeg	test_image_disp.npy
electron@diynoMacBook-Pro assets % 
  • ファイル名を変更

mountain.jpg

mountain.jpg

Terminal
electron@diynoMacBook-Pro assets % mv 156619-01.jpg mountain.jpg
electron@diynoMacBook-Pro assets % ls
copyright_notice.txt	mountain.jpg		teaser.gif		test_image.jpg		test_image_disp.jpeg	test_image_disp.npy
electron@diynoMacBook-Pro assets %

__test_simple.py__を走らせる:rocket:

Terminal
electron@diynoMacBook-Pro assets % cd ..
electron@diynoMacBook-Pro monodepth2 % python3 test_simple.py --image_path assets/mountain.jpg --model_name mono+stereo_640x192
-> Loading model from  models/mono+stereo_640x192
   Loading pretrained encoder
   Loading pretrained decoder
-> Predicting on 1 test images
   Processed 1 of 1 images - saved predictions to:
   - assets/mountain_disp.jpeg
   - assets/mountain_disp.npy
-> Done!
electron@diynoMacBook-Pro monodepth2 % 

__mountain_disp.jpeg__が吐き出されている。

mountain_disp.jpeg

Terminal
electron@diynoMacBook-Pro monodepth2 % open assets/mountain_disp.jpeg                                                          
electron@diynoMacBook-Pro monodepth2 % 

もう1つ別の画像を・・・

スクリーンショット 2021-08-06 19.23.27.png

Terminal
electron@diynoMacBook-Pro assets % wget https://contents.trafficnews.jp/post_image/000/013/650/large_171221_runway_01.jpg
--2021-08-06 19:25:34--  https://contents.trafficnews.jp/post_image/000/013/650/large_171221_runway_01.jpg
contents.trafficnews.jp (contents.trafficnews.jp) をDNSに問いあわせています... 13.225.159.59, 13.225.159.51, 13.225.159.81, ...
contents.trafficnews.jp (contents.trafficnews.jp)|13.225.159.59|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 70262 (69K) [image/jpeg]
`large_171221_runway_01.jpg' に保存中

large_171221_runway_01.jpg            100%[======================================================================>]  68.62K  --.-KB/s 時間 0.007s   

2021-08-06 19:25:34 (8.99 MB/s) - `large_171221_runway_01.jpg' へ保存完了 [70262/70262]

electron@diynoMacBook-Pro assets %
electron@diynoMacBook-Pro assets % ls large_171221_runway_01.jpg 
large_171221_runway_01.jpg
electron@diynoMacBook-Pro assets % 
electron@diynoMacBook-Pro assets % mv large_171221_runway_01.jpg takeoff.jpg
electron@diynoMacBook-Pro assets % ls takeoff.jpg 
takeoff.jpg
electron@diynoMacBook-Pro assets % 

推論実行

Terminal
electron@diynoMacBook-Pro assets % python3 test_simple.py --image_path assets/takeoff.jpg --model_name mono+stereo_640x192
/usr/local/bin/python3: can't open file '/Users/electron/Desktop/monodepth2/assets/test_simple.py': [Errno 2] No such file or directory
electron@diynoMacBook-Pro assets % 
electron@diynoMacBook-Pro assets % cd ..                                                                                  
electron@diynoMacBook-Pro monodepth2 % python3 test_simple.py --image_path assets/takeoff.jpg --model_name mono+stereo_640x192
-> Loading model from  models/mono+stereo_640x192
   Loading pretrained encoder
   Loading pretrained decoder
-> Predicting on 1 test images
   Processed 1 of 1 images - saved predictions to:
   - assets/takeoff_disp.jpeg
   - assets/takeoff_disp.npy
-> Done!
electron@diynoMacBook-Pro monodepth2 %

結果を確認

Terminal
electron@diynoMacBook-Pro monodepth2 % open assets/takeoff_disp.jpeg
electron@diynoMacBook-Pro monodepth2 % 

__うーむ・・・:astonished:

スクリーンショット 2021-08-06 19.28.02.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?