diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-01-09 13:16:51 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-01-09 13:16:51 +0100 |
| commit | 21bb879e00eea74a5df9e703749b8cfa20ec1732 (patch) | |
| tree | 46728510c70b97a7325d1b95daeb0146e357f730 /cli/app | |
| parent | dcf472bbd3d26072b03924b2b0d1592e964d6392 (diff) | |
video
Diffstat (limited to 'cli/app')
| -rw-r--r-- | cli/app/search/live.py | 3 | ||||
| -rw-r--r-- | cli/app/search/params.py | 3 | ||||
| -rw-r--r-- | cli/app/search/search_class.py | 17 | ||||
| -rw-r--r-- | cli/app/search/video.py | 39 | ||||
| -rw-r--r-- | cli/app/settings/app_cfg.py | 7 | ||||
| -rw-r--r-- | cli/app/utils/cortex_utils.py | 2 |
6 files changed, 55 insertions, 16 deletions
diff --git a/cli/app/search/live.py b/cli/app/search/live.py index 0b97f15..33e00b3 100644 --- a/cli/app/search/live.py +++ b/cli/app/search/live.py @@ -21,6 +21,7 @@ from app.settings import app_cfg tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../../live-cortex/rpc/')) from rpc import CortexRPC +from app.search.params import timestamp FPS = 25 @@ -332,6 +333,7 @@ class Listener: print("Building interpolator...") interpolator.build() self.rpc_client.send_status('processing', True) + tag = "biggan_" + timestamp() dt = 1 / FPS for i in range(99999): if i == 0: @@ -348,6 +350,7 @@ class Listener: 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: img_to_send = out_img.resize((256, 256), Image.BICUBIC) meta = { diff --git a/cli/app/search/params.py b/cli/app/search/params.py index 8972436..2fe2722 100644 --- a/cli/app/search/params.py +++ b/cli/app/search/params.py @@ -54,3 +54,6 @@ class ParamsDict(): def update(self, *args, **kwargs): return self.__dict__.update(*args, **kwargs) + +def timestamp(): + return time.strftime("%Y-%m-%d_%H%M") diff --git a/cli/app/search/search_class.py b/cli/app/search/search_class.py index 875bc75..0afa762 100644 --- a/cli/app/search/search_class.py +++ b/cli/app/search/search_class.py @@ -23,6 +23,7 @@ from app.search.image import image_to_uint8, imconvert_uint8, imconvert_float32, imread, imwrite, imgrid, resize_and_crop_image from app.search.vector import truncated_z_sample, truncated_z_single, \ create_labels, create_labels_uniform +from app.search.video import export_video feature_layer_names = { '1a': "InceptionV3/Conv2d_1a_3x3", @@ -192,7 +193,7 @@ def find_nearest_vector(sess, generator, opt_fp_in, opt_dims, out_images, out_la if i > 0: if opt_stochastic_clipping and (i % opt_clip_interval) == 0 and i < opt_steps * 0.45: sess.run(clip_latent, { clipped_alpha: (i / opt_steps) ** 2 }) - if opt_label_clipping and (i % opt_clip_interval) == 0: + if opt_label_clipping and (i % opt_clip_interval) == 0 and i < opt_steps * 0.75: sess.run(clip_labels, { normalized_alpha: (i / opt_steps) ** 2 }) if opt_video and opt_snapshot_interval != 0 and (i % opt_snapshot_interval) == 0: phi_guess = sess.run(output) @@ -211,20 +212,6 @@ def find_nearest_vector(sess, generator, opt_fp_in, opt_dims, out_images, out_la out_latent[index] = z_guess return fp_frames -def export_video(fp_frames): - print("Exporting video...") - cmd = [ - '/home/lens/bin/ffmpeg', - '-y', # '-v', 'quiet', - '-r', '30', - '-i', join(app_cfg.DIR_OUTPUTS, fp_frames, 'frame_%04d.png'), - '-pix_fmt', 'yuv420p', - join(app_cfg.DIR_OUTPUTS, fp_frames + '.mp4') - ] - # print(' '.join(cmd)) - call(cmd) - shutil.rmtree(join(app_cfg.DIR_OUTPUTS, fp_frames)) - def load_target_image(opt_fp_in): print("Loading {}".format(opt_fp_in)) fn = os.path.basename(opt_fp_in) diff --git a/cli/app/search/video.py b/cli/app/search/video.py new file mode 100644 index 0000000..4f10d49 --- /dev/null +++ b/cli/app/search/video.py @@ -0,0 +1,39 @@ +import shutil +import os + +from app.settings import app_cfg + +def export_video(fp_frames, fps=30): + print("Exporting video...") + cmd = [ + '/home/lens/bin/ffmpeg', + '-hide_banner', + '-y', # '-v', 'quiet', + '-r', fps, + '-i', join(app_cfg.DIR_OUTPUTS, fp_frames, 'frame_%04d.png'), + '-pix_fmt', 'yuv420p', + join(app_cfg.DIR_OUTPUTS, fp_frames + '.mp4') + ] + # print(' '.join(cmd)) + call(cmd) + shutil.rmtree(join(app_cfg.DIR_OUTPUTS, fp_frames)) + +def export_video_final(fp_frames): + print("Exporting video...") + cmd = [ + '/home/lens/bin/ffmpeg', + '-hide_banner', + '-y', # '-v', 'quiet', + '-r', fps, + '-i', join(app_cfg.DIR_OUTPUTS, fp_frames, 'frame_%05d.png'), + '-c:v', 'libx264', + '-preset', 'slow', + '-crf', '19', + '-vf', 'fps=25', + '-pix_fmt', 'yuv420p', + '-s', '512x512', + join(app_cfg.DIR_RENDERS, fp_frames + '.mp4') + ] + # print(' '.join(cmd)) + call(cmd) + shutil.rmtree(join(app_cfg.DIR_OUTPUTS, fp_frames)) diff --git a/cli/app/settings/app_cfg.py b/cli/app/settings/app_cfg.py index 6ddd445..57f51d6 100644 --- a/cli/app/settings/app_cfg.py +++ b/cli/app/settings/app_cfg.py @@ -34,8 +34,15 @@ 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_RENDERS = join(DIR_APP, 'data_store/renders') FP_MODELZOO = join(DIR_APP, 'modelzoo/modelzoo.yaml') +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_RENDERS, exist_ok=True) + # ----------------------------------------------------------------------------- # Model config # ----------------------------------------------------------------------------- diff --git a/cli/app/utils/cortex_utils.py b/cli/app/utils/cortex_utils.py index 947c7e1..8f00dfa 100644 --- a/cli/app/utils/cortex_utils.py +++ b/cli/app/utils/cortex_utils.py @@ -82,7 +82,7 @@ def upload_fp_to_cortex(opt_folder_id, fp): } url = os.path.join(api_url('folder'), str(opt_folder_id), 'upload/') r = requests.post(url, files=files, data=data) - return None if resp.status_code != 200 else resp.json() + return None if r.status_code != 200 else r.json() def upload_bytes_to_cortex(opt_folder_id, fn, fp, mimetype): """Upload a BytesIO object""" |
