Skip to content

CLI interface #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Deep3D: Automatic 2D-to-3D Video Conversion with CNNs

## Model to try out online
http://www.somatic.io/models/oEG0wMkR

## How To Run
To run this code. Please install MXNet following the official document.
Deep3D requires MXNet to be built with Cuda 7.0 and Cudnn 4 or above. Please open mxnet/config.mk and set USE_CUDA and USE_CUDNN to 1. Then, append EXTRA\_OPERATORS=path/to/deep3d/operators to path/to/mxnet/config.mk and recompile MXNet.
Expand Down
64 changes: 64 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import argparse
import mxnet as mx
import numpy as np
import os
import json
import urllib
import cv2
import subprocess
import matplotlib.pyplot as plt
from PIL import Image
from images2gif import writeGif
import logging
import time
logging.basicConfig(level=logging.DEBUG)


ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to base image")
ap.add_argument("-j", "--json",default=False, help="upload images")
ap.add_argument("-o", "--output_folder", default="./", help="output folder")
args = ap.parse_args()
param_path = '/tmp/deep3d-0050.params'
junk = subprocess.check_output(["cp", 'deep3d-symbol.json', '/tmp/'])
if not os.path.exists(param_path):
urllib.urlretrieve('http://homes.cs.washington.edu/~jxie/download/deep3d-0050.params', param_path)
model = mx.model.FeedForward.load('/tmp/deep3d', 50, mx.gpu(0))

model = mx.model.FeedForward.load('/tmp/deep3d', 50, mx.gpu(0))

shape = (384, 160)
img = cv2.imread(args.image)
raw_shape = (img.shape[1], img.shape[0])
img = cv2.resize(img, shape)
#plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
#plt.axis('off')
#plt.show()

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)

right = np.clip(Y.squeeze().transpose((1,2,0)), 0, 255).astype(np.uint8)
right = Image.fromarray(cv2.cvtColor(right, cv2.COLOR_BGR2RGB))
left = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
if args.json != False:
right_name = str(int(time.time())) + ".jpg"
right_path = args.output_folder + "/" + right_name
left_name = str(int(time.time())) + ".jpg"
left_path = args.output_folder + "/" + left_name
right.save(right_path,"JPEG")
left.save(left_path,"JPEG")

right_output = subprocess.check_output(["curl","-s", "--upload-file", right_path,("https://transfer.sh/"+right_name)]).strip()
left_output = subprocess.check_output(["curl", "-s","--upload-file", left_path,("https://transfer.sh/"+left_name)]).strip()
data = {'right':right_output,'left':left_output}
output_file = args.output_folder + "/"+ str(int(time.time())) + ".json"
print(data)
with open(output_file, 'w') as outfile:
json.dump(data, outfile)
else:
put_file = args.output_folder + "/"+ str(int(time.time())) + ".gif"
writeGif(output_file, [left, right], duration=0.08)
print(output_file)