From 6c84c73abc5006681408232930d2d06cae716e11 Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Wed, 6 Apr 2016 09:33:46 +0200 Subject: [PATCH 1/9] add main.py --- main.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..38ded19 --- /dev/null +++ b/main.py @@ -0,0 +1,44 @@ +import argparse +%matplotlib inline +import mxnet as mx +import numpy as np +import os +import urllib +import cv2 +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("-b", "--base-model", required=True, help="base model path") +ap.add_argument("-i", "--image", required=True, help="path to base image") +ap.add_argument("-o", "--output", required=True, help="output folder") +args = ap.parse_args() + +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)) + + output_file = args.output + "/"+ str(int(time.time())) + ".gif" + +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)) +writeGif(output_file, [left, right], duration=0.3) From 9232a28f381625692aa11bf76fefab2d5a968b47 Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Wed, 6 Apr 2016 09:33:58 +0200 Subject: [PATCH 2/9] add main.py --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index 38ded19..90988d6 100644 --- a/main.py +++ b/main.py @@ -42,3 +42,4 @@ right = Image.fromarray(cv2.cvtColor(right, cv2.COLOR_BGR2RGB)) left = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) writeGif(output_file, [left, right], duration=0.3) +print(output_file) From b9d4a584dab161dcda86d066677fb816c0240af6 Mon Sep 17 00:00:00 2001 From: jason toy Date: Wed, 6 Apr 2016 07:48:16 +0000 Subject: [PATCH 3/9] new models! --- main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 90988d6..6e8f403 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,4 @@ import argparse -%matplotlib inline import mxnet as mx import numpy as np import os @@ -14,24 +13,23 @@ ap = argparse.ArgumentParser() -ap.add_argument("-b", "--base-model", required=True, help="base model path") ap.add_argument("-i", "--image", required=True, help="path to base image") -ap.add_argument("-o", "--output", required=True, help="output folder") +ap.add_argument("-o", "--output_folder", default="./", help="output folder") args = ap.parse_args() 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)) - output_file = args.output + "/"+ str(int(time.time())) + ".gif" +model = mx.model.FeedForward.load('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() +#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) @@ -41,5 +39,6 @@ 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)) +output_file = args.output_folder + "/"+ str(int(time.time())) + ".gif" writeGif(output_file, [left, right], duration=0.3) print(output_file) From df74289b6c7bf133b621e1054a400807ec8eec93 Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Wed, 6 Apr 2016 11:43:02 +0200 Subject: [PATCH 4/9] update docs --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 1a74bf4..5604ffc 100644 --- a/README.md +++ b/README.md @@ -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. Then append EXTRA\_OPERATORS=path/to/deep3d/operators to path/to/mxnet/config.mk and recompile MXNet. From a698091d2e5bd69fa8b54aaccfc7f8e2e0e3bc71 Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Thu, 7 Apr 2016 08:46:49 +0200 Subject: [PATCH 5/9] update duration --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 6e8f403..ad787d3 100644 --- a/main.py +++ b/main.py @@ -40,5 +40,5 @@ right = Image.fromarray(cv2.cvtColor(right, cv2.COLOR_BGR2RGB)) left = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) output_file = args.output_folder + "/"+ str(int(time.time())) + ".gif" -writeGif(output_file, [left, right], duration=0.3) +writeGif(output_file, [left, right], duration=0.8) print(output_file) From 255ae250f1d6cb948ec4e76b4fd803df6e5a4cf0 Mon Sep 17 00:00:00 2001 From: jtoy Date: Thu, 7 Apr 2016 21:05:55 +0200 Subject: [PATCH 6/9] update duration --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index ad787d3..b375d03 100644 --- a/main.py +++ b/main.py @@ -40,5 +40,5 @@ right = Image.fromarray(cv2.cvtColor(right, cv2.COLOR_BGR2RGB)) left = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) output_file = args.output_folder + "/"+ str(int(time.time())) + ".gif" -writeGif(output_file, [left, right], duration=0.8) +writeGif(output_file, [left, right], duration=0.08) print(output_file) From 65b39d1e6880107ddc285e3d4906f4221748ec24 Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Tue, 3 May 2016 17:43:57 -0400 Subject: [PATCH 7/9] json args --- main.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b375d03..940d1c4 100644 --- a/main.py +++ b/main.py @@ -2,8 +2,10 @@ 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 @@ -14,6 +16,7 @@ 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() @@ -39,6 +42,21 @@ 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)) -output_file = args.output_folder + "/"+ str(int(time.time())) + ".gif" -writeGif(output_file, [left, right], duration=0.08) +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,re = subprocess.check_output(["curl", "--upload-file", right_path,("https://transfer.sh/"+right_name)]); + left_output,le = subprocess.check_output(["curl", "--upload-file", left_path,("https://transfer.sh/"+left_name)]); + data = {right:right_output,left:left_output} + put_file = args.output_folder + "/"+ str(int(time.time())) + ".json" + with open(put_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) From ad08efa7a4364d0ae3562ec704dbf79c12b5c53b Mon Sep 17 00:00:00 2001 From: jason toy Date: Tue, 3 May 2016 22:14:50 +0000 Subject: [PATCH 8/9] json support --- main.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 940d1c4..691f14a 100644 --- a/main.py +++ b/main.py @@ -19,12 +19,12 @@ 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' +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)) -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)) - -model = mx.model.FeedForward.load('deep3d', 50, mx.gpu(0)) +model = mx.model.FeedForward.load('/tmp/deep3d', 50, mx.gpu(0)) shape = (384, 160) img = cv2.imread(args.image) @@ -50,11 +50,12 @@ right.save(right_path,"JPEG") left.save(left_path,"JPEG") - right_output,re = subprocess.check_output(["curl", "--upload-file", right_path,("https://transfer.sh/"+right_name)]); - left_output,le = subprocess.check_output(["curl", "--upload-file", left_path,("https://transfer.sh/"+left_name)]); - data = {right:right_output,left:left_output} - put_file = args.output_folder + "/"+ str(int(time.time())) + ".json" - with open(put_file, 'w') as outfile: + 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" From 3b02d123b81521874c39be8851a52081b9b0a78a Mon Sep 17 00:00:00 2001 From: Jason Toy Date: Tue, 3 May 2016 22:58:04 -0400 Subject: [PATCH 9/9] copy --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index 691f14a..78c8e29 100644 --- a/main.py +++ b/main.py @@ -20,6 +20,7 @@ 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))