summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-01-11 00:23:46 +0100
committerJules Laplace <julescarbon@gmail.com>2020-01-11 00:23:46 +0100
commit179f98c949dbeeb383d152e46610dd6789616231 (patch)
treee48ce022dfd09b06520a46bcf50a46a64ed68c6d /cli
parentb280b3b837b205e9283c0444bdb28bc2aa4e48ad (diff)
upload video script
Diffstat (limited to 'cli')
-rw-r--r--cli/app/commands/cortex/upload_video.py33
-rw-r--r--cli/app/search/live.py6
-rw-r--r--cli/app/search/search_dense.py16
-rw-r--r--cli/app/search/video.py6
-rw-r--r--cli/app/settings/app_cfg.py2
5 files changed, 49 insertions, 14 deletions
diff --git a/cli/app/commands/cortex/upload_video.py b/cli/app/commands/cortex/upload_video.py
new file mode 100644
index 0000000..138bdf5
--- /dev/null
+++ b/cli/app/commands/cortex/upload_video.py
@@ -0,0 +1,33 @@
+import click
+import json
+
+from app.search.video import export_video_final
+from app.utils.cortex_utils import upload_file_to_cortex
+
+@click.command('')
+@click.option('-i', '--input', 'opt_fp_in',
+ help='Path to input image')
+@click.option('-f', '--folder_id', 'opt_folder_id', required=True,
+ help='ID of folder on Cortex')
+@click.pass_context
+def cli(ctx, opt_fp_in, opt_folder_id):
+ """
+ Test uploading a file to Cortex
+ """
+ # export_video_final
+ if opt_fp_in is None:
+ results_dir = os.path.join(app_cfg.RESULTS_DIR)
+ for fn in sorted(os.listdir(app_cfg.RESULTS_DIR), reverse=True):
+ fp_frames = os.path.join(app_cfg.RESULTS_DIR, fn)
+ if os.path.isdir(f):
+ break
+ fp_out = os.path.join(app_cfg.DIR_RENDERS, fn + '.mp4')
+ export_video_final(fp_frames, fp_out)
+ else:
+ fp_out = opt_fp_in
+ if not os.path.exists(fp_out):
+ print("No video found")
+ return
+ print("Uploading {}".format(fp_out))
+ data = upload_file_to_cortex(opt_folder_id, fp_out, datatype='video', activity='live')
+ print(json.dumps(data, indent=2))
diff --git a/cli/app/search/live.py b/cli/app/search/live.py
index b09575d..4c66873 100644
--- a/cli/app/search/live.py
+++ b/cli/app/search/live.py
@@ -374,6 +374,8 @@ class Listener:
interpolator.build()
self.rpc_client.send_status('processing', True)
tag = "biggan_" + timestamp()
+ path_out = os.path.join(app_cfg.RESULTS_DIR, tag)
+ os.makedirs(path_out, exist_ok=True)
dt = 1 / FPS
for i in range(99999):
if i == 0:
@@ -386,12 +388,10 @@ class Listener:
print("Exiting...")
break
if (i % 100) == 0 or i == 1:
- # print(gen_images.shape)
print("Step {}. Generation time: {:.2f}s".format(i, time.time() - gen_time))
out_img = vs.data2pil(gen_images[0])
if out_img is not None:
- # save image
- #if out_img.resize_before_sending:
+ out_img.save(os.path.join(path_out, "image_{:5d}.png".format(i)), format='png')
img_to_send = out_img.resize((256, 256), Image.BICUBIC)
meta = {
'i': i,
diff --git a/cli/app/search/search_dense.py b/cli/app/search/search_dense.py
index 3719de6..ac67d07 100644
--- a/cli/app/search/search_dense.py
+++ b/cli/app/search/search_dense.py
@@ -240,18 +240,18 @@ def find_dense_embedding_for_images(params):
feat_loss += tf.reduce_mean(feat_square_diff) * 0.25
img_feat_err += tf.reduce_mean(feat_square_diff, axis=1) * 0.25
- # gen_feat = gen_feat_ex["InceptionV3/Conv2d_3b_1x1"]
- # target_feat = target_feat_ex["InceptionV3/Conv2d_3b_1x1"]
- # feat_square_diff = tf.reshape(tf.square(gen_feat - target_feat), [BATCH_SIZE, -1])
- # feat_loss += tf.reduce_mean(feat_square_diff) * 0.25
- # img_feat_err += tf.reduce_mean(feat_square_diff, axis=1) * 0.25
-
- gen_feat = gen_feat_ex["InceptionV3/Mixed_6a"]
- target_feat = target_feat_ex["InceptionV3/Mixed_6a"]
+ gen_feat = gen_feat_ex["InceptionV3/Conv2d_3b_1x1"]
+ target_feat = target_feat_ex["InceptionV3/Conv2d_3b_1x1"]
feat_square_diff = tf.reshape(tf.square(gen_feat - target_feat), [BATCH_SIZE, -1])
feat_loss += tf.reduce_mean(feat_square_diff) * 0.25
img_feat_err += tf.reduce_mean(feat_square_diff, axis=1) * 0.25
+ # gen_feat = gen_feat_ex["InceptionV3/Mixed_6a"]
+ # target_feat = target_feat_ex["InceptionV3/Mixed_6a"]
+ # feat_square_diff = tf.reshape(tf.square(gen_feat - target_feat), [BATCH_SIZE, -1])
+ # feat_loss += tf.reduce_mean(feat_square_diff) * 0.25
+ # img_feat_err += tf.reduce_mean(feat_square_diff, axis=1) * 0.25
+
gen_feat = gen_feat_ex["InceptionV3/Mixed_7a"]
target_feat = target_feat_ex["InceptionV3/Mixed_7a"]
feat_square_diff = tf.reshape(tf.square(gen_feat - target_feat), [BATCH_SIZE, -1])
diff --git a/cli/app/search/video.py b/cli/app/search/video.py
index d8e3f3f..14d84b4 100644
--- a/cli/app/search/video.py
+++ b/cli/app/search/video.py
@@ -19,7 +19,7 @@ def export_video(fp_frames, fps=30):
call(cmd)
shutil.rmtree(os.path.join(app_cfg.DIR_OUTPUTS, fp_frames))
-def export_video_final(fp_frames, fps=25):
+def export_video_final(fp_frames, fp_out, fps=25):
print("Exporting video...")
cmd = [
'/home/lens/bin/ffmpeg',
@@ -33,8 +33,8 @@ def export_video_final(fp_frames, fps=25):
'-vf', 'fps=25',
'-pix_fmt', 'yuv420p',
'-s', '512x512',
- os.path.join(app_cfg.DIR_RENDERS, fp_frames + '.mp4')
+ fp_out
]
# print(' '.join(cmd))
call(cmd)
- # shutil.rmtree(os.path.join(app_cfg.DIR_OUTPUTS, fp_frames))
+ return fp_out
diff --git a/cli/app/settings/app_cfg.py b/cli/app/settings/app_cfg.py
index 57f51d6..149d1cf 100644
--- a/cli/app/settings/app_cfg.py
+++ b/cli/app/settings/app_cfg.py
@@ -34,6 +34,7 @@ DIR_INVERSES = join(DIR_APP, 'data_store/inverses')
DIR_VECTORS = join(DIR_APP, 'data_store/vectors')
DIR_INPUTS = join(DIR_APP, 'data_store/inputs')
DIR_OUTPUTS = join(DIR_APP, 'data_store/outputs')
+DIR_RESULTS = join(DIR_APP, 'data_store/results')
DIR_RENDERS = join(DIR_APP, 'data_store/renders')
FP_MODELZOO = join(DIR_APP, 'modelzoo/modelzoo.yaml')
@@ -41,6 +42,7 @@ os.makedirs(DIR_INVERSES, exist_ok=True)
os.makedirs(DIR_VECTORS, exist_ok=True)
os.makedirs(DIR_INPUTS, exist_ok=True)
os.makedirs(DIR_OUTPUTS, exist_ok=True)
+os.makedirs(DIR_RESULTS, exist_ok=True)
os.makedirs(DIR_RENDERS, exist_ok=True)
# -----------------------------------------------------------------------------