6
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 5 years have passed since last update.

PythonAdvent Calendar 2016

Day 3

deep3d に挑戦して敗れた話

Last updated at Posted at 2016-12-02
1 / 19

はじめに

本記事は、Python Advent Calendar 2016の 3 日目の記事です。
敗れた話なので、最後はエラーで終わります。


deep3dとは

DeepLearning を使って、画像を 3D 用に変換するライブラリです。

teaser.png


これが

demo.jpg


こうなるんじゃ!

demo.gif


夢が広がりますね (人´∀`)


ここからは簡単な手順の解説


GPU が使えるマシンを準備

  • AWS の g2.2xlarge、もしくは g2.8xlarge の EC2 インスタンスを作る
    • 事前に使用制限解除の申請をする必要あり
    • 結構ストレージを使うので、無料枠は 30GB 全部使う
  • もちろん AWS 以外でも全然おk

ライブラリをインストール

  • CUDA(GPU の統合開発環境)
  • cuDNN(GPU で neural network を動かすためのライブラリ)
    • NVIDIA に developer 登録する必要あり
  • MXNet(DeepLearning のライブラリ)

参考


python の準備


画像を準備する

demo2.png


サンプルと同じように実行

  • これ参考にするのが良いかと
  • 画像は事前に差し替える
  • git clone してきた deep3d ディレクトリで実行しないと、deep3d-symbol.json の読み込みエラーが発生する
    • 実行したいディレクトリにコピーしてもおk
  • 今回、jupyter は使わなかった

サンプルと同じように実行

import mxnet as mx
import numpy as np
import os
import urllib
import cv2
from PIL import Image
from images2gif import writeGif
import logging
logging.basicConfig(level=logging.DEBUG)

サンプルと同じように実行

if not os.path.exists('deep3d-0050.params'):
    urllib.urlretrieve('http://homes.cs.washington.edu/~jxie/download/deep3d-0050.params', 'deep3d-0050.params')
model = mx.model.FeedForward.load('deep3d', 50, mx.gpu(0))
shape = (384, 160)
img = cv2.imread('demo.jpg')
raw_shape = (img.shape[1], img.shape[0])
img = cv2.resize(img, shape)
X = img.astype(np.float32).transpose((2,0,1))
X = X.reshape((1,)+X.shape)
test_iter = mx.io.NDArrayIter({'left': X, 'left0':X})
Y = model.predict(test_iter)

FATAL ERROR!!!!

>>> test_iter = mx.io.NDArrayIter({'left': X, 'left0':X})
>>> Y = model.predict(test_iter)
[16:21:56] src/operator/./reshape-inl.h:311: Using target_shape will be deprecated.
[16:21:57] src/operator/./reshape-inl.h:311: Using target_shape will be deprecated.
[16:21:57] src/operator/./reshape-inl.h:311: Using target_shape will be deprecated.
[16:21:57] /home/ubuntu/mxnet/dmlc-core/include/dmlc/logging.h:235: [16:21:57] src/operator/./cudnn_softmax_activation-inl.h:44: Check failed: (in_data[softmax_activation::kData].ndim()) == (2) Input need to have 2 dimensions when mode=instance.
[16:21:57] /home/ubuntu/mxnet/dmlc-core/include/dmlc/logging.h:235: [16:21:57] src/engine/./threaded_engine.h:306: [16:21:57] src/operator/./cudnn_softmax_activation-inl.h:44: Check failed: (in_data[softmax_activation::kData].ndim()) == (2) Input need to have 2 dimensions when mode=instance.
An fatal error occurred in asynchronous engine operation. If you do not know what caused this error, you can try set environment variable MXNET_ENGINE_TYPE to NaiveEngine and run with debugger (i.e. gdb). This will force all operations to be synchronous and backtrace will give you the series of calls that lead to this error. Remember to set MXNET_ENGINE_TYPE back to empty after debugging.
terminate called after throwing an instance of 'dmlc::Error'
  what():  [16:21:57] src/engine/./threaded_engine.h:306: [16:21:57] src/operator/./cudnn_softmax_activation-inl.h:44: Check failed: (in_data[softmax_activation::kData].ndim()) == (2) Input need to have 2 dimensions when mode=instance.
An fatal error occurred in asynchronous engine operation. If you do not know what caused this error, you can try set environment variable MXNET_ENGINE_TYPE to NaiveEngine and run with debugger (i.e. gdb). This will force all operations to be synchronous and backtrace will give you the series of calls that lead to this error. Remember to set MXNET_ENGINE_TYPE back to empty after debugging.
Aborted (core dumped)

why?

  • Input need to have 2 dimensions when mode=instance.
    • 渡してるやん?
    • test_iter = mx.io.NDArrayIter({'left': X, 'left0':X})
  • c++ のソースコード読んだけど、解決に至らず・・

(´・ω・`)


おわりに

  • deep3d は動画にも使えるらしいので、もうちょっと頑張りたい
    • そのうち DeepLearning のロジックとかも理解したい
  • AWS がマジ便利
  • python がホント便利
    • 今回は特に anaconda が神がかってた
6
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
6
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?