[PYTHON] The story of trying deep3d and losing

Introduction

This article is the third day article of Python Advent Calendar 2016. It's a defeated story, so the end ends with an error.


What is deep3d

A library that uses DeepLearning to convert images for 3D.

teaser.png


This is

demo.jpg


It will be like this!

demo.gif


Your dreams will spread (people'∀`)


Explanation of simple procedure from here


Prepare a machine that can use GPU

--Create an AWS g2.2xlarge or g2.8xlarge EC2 instance --It is necessary to apply for cancellation of usage restrictions in advance ――Since it uses a lot of storage, the free tier uses all 30GB ――Of course, it's not at all other than AWS.


Install library

--CUDA (GPU integrated development environment) --cuDNN (library for running neural network on GPU) --Requires developer registration with NVIDIA --MXNet (DeepLearning library)


reference


python preparation

--Install pyenv -Building Python 3.x environment with Pyenv (CentOS, Ubuntu) --Install anaconda and openCV -The easiest way to use OpenCV with python --Include images2gif - PinguCarsti / packages / images2gif


Prepare the image

demo2.png


Run like sample

――Is it good to refer to this? - deep3d.ipynb --Replace the image in advance --If you do not execute it in the deep3d directory that you have git cloned, you will get a read error of deep3d-symbol.json. --You can copy it to the directory you want to execute. --I didn't use jupyter this time


Run like sample

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)

Run like sample

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?


(´ ・ ω ・ `)


in conclusion

――It seems that deep3d can also be used for videos, so I want to do my best ――I want to understand the logic of Deep Learning. --AWS is really convenient --python is really convenient ――This time, especially anaconda was godly

Recommended Posts

The story of trying deep3d and losing
The story of Python and the story of NaN
The story of trying to reconnect the client
The story of sys.path.append ()
The story of trying Sourcetrail × macOS × VS Code
The story of building Zabbix 4.4
The story of Python without increment and decrement operators.
[Apache] The story of prefork
A story of trying out pyenv, virtualenv and virtualenvwrapper
Story of trying competitive programming 2
The story of trying to contribute to COVID-19 analysis with AWS free tier and failing
The story of participating in AtCoder
The story of the "hole" in the file
Story of trying competitive programming Part 1
The story of remounting the application server
The story of writing a program
The story of running python and displaying the results without closing vim
This and that of the inclusion notation.
The story of an error in PyOCR
The story of verifying the open data of COVID-19
The story of adding MeCab to ubuntu 16.04
The story of making Python an exe
Review the concept and terminology of regression
The story of manipulating python global variables
The story of deciphering Keras' LSTM model.predict
The story of blackjack A processing (python)
The story of pep8 changing to pycodestyle
I tried to extract and illustrate the stage of the story using COTOHA
The story of making a sound camera with Touch Designer and ReSpeaker
The story of trying to push SSH_AUTH_SOCK obsolete on screen with LD_PRELOAD
The story of doing deep learning with TPU
The story of low learning costs for Python
About the behavior of copy, deepcopy and numpy.copy
The story of creating (probably) the smallest skill that implements personalization and in-skill billing
Summary of the differences between PHP and Python
Full understanding of the concepts of Bellman-Ford and Dijkstra
The answer of "1/2" is different between python2 and 3
The story of making a box that interconnects Pepper's AL Memory and MQTT
Organize the meaning of methods, classes and objects
The story of making the Mel Icon Generator version2
Change the color of Fabric errors and warnings
Compare the speed of Python append and map
Image processing? The story of starting Python for
The story of making a lie news generator
The story of finding the optimal n in N fist
Story of trying to use tensorboard with pytorch
The story of misreading the swap line of the top command
The story of reading HSPICE data in Python
The story of viewing media files in Django
General description of the CPUFreq core and CPUFreq notifiers
Organize the super-basic usage of Autotools and pkg-config
The story of making a mel icon generator
I read and implemented the Variants of UKR
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
[Small story] Download the image of Ghibli immediately
The story of moving from Pipenv to Poetry
The nice and regrettable parts of Cloud Datalab
A story of a high school graduate technician trying to predict the survival of the Titanic
The story of porting code from C to Go and getting hooked (and to the language spec)
A story about trying to introduce Linter in the middle of a Python (Flask) project