summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-06-26 14:02:59 +0200
committerJules Laplace <julescarbon@gmail.com>2018-06-26 14:02:59 +0200
commit34ff74aae6117c2cc5cee89b3cfa0d93499dba42 (patch)
tree6ccd652ef7ed0b2ad44682b8ea1975cdd01e2bac
parent8701134065d8c06274ee2980b23320a15e3b22fb (diff)
endpoint
-rw-r--r--run.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/run.py b/run.py
index e99374d..80eaecc 100644
--- a/run.py
+++ b/run.py
@@ -27,6 +27,8 @@ arguments_aOffset = 0
arguments_bOffset = 0
arguments_mixVideos = False
arguments_averageVideos = False
+arguments_endpoint = None
+arguments_dataset = "dataset"
for strOption, strArgument in getopt.getopt(sys.argv[1:], '', [ strParameter[2:] + '=' for strParameter in sys.argv[1::2] ])[0]:
print("{}: {}".format(strOption, strArgument))
@@ -56,6 +58,10 @@ for strOption, strArgument in getopt.getopt(sys.argv[1:], '', [ strParameter[2:]
arguments_aOffset = int(strArgument)
elif strOption == '--b-offset':
arguments_bOffset = int(strArgument)
+ elif strOption == '--endpoint':
+ arguments_endpoint = strArgument
+ elif strOption == '--dataset':
+ arguments_dataset = strArgument
if not os.path.exists('./renders'):
os.mkdir('renders')
@@ -182,7 +188,7 @@ def dilate_frames(moduleNetwork, tensorOutput, frames, dilate):
new_frames += [nextFrame]
return new_frames
-def store_frames(frames, outputPath, inputFirst=None, inputSecond=None):
+def store_frames(frames, outputPath, inputFirst=None, inputSecond=None, endpoint=None):
print('writing {}'.format(outputPath))
print('frames: {}'.format(len(frames)))
writer = FFMPEG_VideoWriter(outputPath, (1024, 512), 25)
@@ -192,6 +198,20 @@ def store_frames(frames, outputPath, inputFirst=None, inputSecond=None):
writer.write_frame(tensor_to_image(frame))
if inputSecond is not None:
writer.write_frame(inputSecond)
+ writer.close()
+
+ if endpoint is not None:
+ os.system(["curl",
+ "-X", "POST",
+ "-F", "module=morph",
+ "-F", "activity=morph",
+ "-F", "generated=true",
+ "-F", "dataset=" + dataset,
+ "-F", "datatype=video",
+ "-F", "file=@" + outputPath,
+ endpoint
+ ]);
+
def tensor_to_image(np_val):
return (numpy.rollaxis(np_val, 0, 3)[:,:,::-1] * 255.0).astype(numpy.uint8)
@@ -225,7 +245,7 @@ elif arguments_mixVideos:
frames = process_two_videos(moduleNetwork, tensorOutput, arguments_strFirst, arguments_strSecond, arguments_aOffset, arguments_bOffset, arguments_steps, arguments_dilate)
frames = smooth_frames(moduleNetwork, tensorOutput, frames, arguments_smooth)
frames = dilate_frames(moduleNetwork, tensorOutput, frames, arguments_dilate)
- store_frames(frames, outputPath)
+ store_frames(frames, outputPath, endpoint=arguments_endpoint, dataset=arguments_dataset)
elif arguments_averageVideos:
print("average two videos...")
print("{} => {}".format(arguments_strFirst, arguments_strSecond))
@@ -233,7 +253,7 @@ elif arguments_averageVideos:
frames = average_two_videos(moduleNetwork, tensorOutput, arguments_strFirst, arguments_strSecond, arguments_aOffset, arguments_bOffset, arguments_steps, arguments_dilate)
frames = smooth_frames(moduleNetwork, tensorOutput, frames, arguments_smooth)
frames = dilate_frames(moduleNetwork, tensorOutput, frames, arguments_dilate)
- store_frames(frames, outputPath)
+ store_frames(frames, outputPath, endpoint=arguments_endpoint, dataset=arguments_dataset)
elif arguments_steps == 0:
# Process image
tensorInputFirst = load_image_tensor(arguments_strFirst)
@@ -250,4 +270,4 @@ else:
frames = smooth_frames(moduleNetwork, tensorOutput, frames, arguments_smooth)
print("dilate... {}".format(arguments_dilate))
frames = dilate_frames(moduleNetwork, tensorOutput, frames, arguments_dilate)
- store_frames(frames, outputPath, inputFirst, inputSecond)
+ store_frames(frames, outputPath, inputFirst, inputSecond, endpoint=arguments_endpoint, dataset=arguments_dataset)