summaryrefslogtreecommitdiff
path: root/cli/app
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-01-10 14:41:24 +0100
committerJules Laplace <julescarbon@gmail.com>2020-01-10 14:41:24 +0100
commit4ad173ed0f8cc623549d2ccbc21114ac28237c4b (patch)
treeee69edaf08c7f0bef8bc1e88fcc0e0d79d4cdd87 /cli/app
parentc9f1c4dc4820d854cd550c0c36a9468508c9aff2 (diff)
graph magic
Diffstat (limited to 'cli/app')
-rw-r--r--cli/app/search/live.py8
-rw-r--r--cli/app/utils/cortex_utils.py18
2 files changed, 14 insertions, 12 deletions
diff --git a/cli/app/search/live.py b/cli/app/search/live.py
index b52ec03..63799a1 100644
--- a/cli/app/search/live.py
+++ b/cli/app/search/live.py
@@ -220,6 +220,7 @@ class Interpolator:
gen_layer_name = 'module_apply_' + gen_signature + '/' + params.inv_layer
encoding_latent = tf.get_default_graph().get_tensor_by_name(gen_layer_name)
+ print(encoding_latent.get_shape())
encoding_shape = [1,] + encoding_latent.get_shape().as_list()[1:]
print(encoding_shape)
encoding_shape_placeholder = tf.constant(np.zeros(encoding_shape, dtype=np.float32))
@@ -272,20 +273,21 @@ class Interpolator:
def set_encoding(self, opt):
next_id = opt['id']
data = load_pickle(os.path.join(app_cfg.DIR_VECTORS, "file_{}.pkl".format(next_id)))
+ encoding = np.expand_dims(data['encoding'], axis=0)
encoding_stored = self.lerp_params['encoding_stored']
encoding_mix = self.lerp_params['encoding_mix']
# if we're showing an encoding already, lerp to the next one
if encoding_mix.n.value > 0:
- encoding_stored.switch(target_value=data['encoding'])
+ encoding_stored.switch(target_value=encoding)
# otherwise (we're showing the latent)...
else:
# jump to the stored encoding, then switch
if encoding_stored.n.value < 0.5:
encoding_stored.n.value = 0
- encoding_stored.a.assign(data['encoding'])
+ encoding_stored.a.assign(encoding)
else:
encoding_stored.n.value = 1
- encoding_stored.b.assign(data['encoding'])
+ encoding_stored.b.assign(encoding)
encoding_mix.switch()
def on_step(self, i, dt, sess):
diff --git a/cli/app/utils/cortex_utils.py b/cli/app/utils/cortex_utils.py
index 8f00dfa..bf49f96 100644
--- a/cli/app/utils/cortex_utils.py
+++ b/cli/app/utils/cortex_utils.py
@@ -68,27 +68,27 @@ def fetch_file(url, fn, **kwargs):
f.write(chunk)
return size
-def upload_fp_to_cortex(opt_folder_id, fp):
+def upload_fp_to_cortex(opt_folder_id, fp, generated='true', module='biggan', activity='invert', datatype='image'):
"""Upload an open file/BytesIO object"""
files = {
'file': fp
}
data = {
'folder_id': opt_folder_id,
- 'generated': 'true',
- 'module': 'biggan',
- 'activity': 'invert',
- 'datatype': 'image',
+ 'generated': generated,
+ 'module': module,
+ 'activity': activity,
+ 'datatype': datatype,
}
url = os.path.join(api_url('folder'), str(opt_folder_id), 'upload/')
r = requests.post(url, files=files, data=data)
return None if r.status_code != 200 else r.json()
-def upload_bytes_to_cortex(opt_folder_id, fn, fp, mimetype):
+def upload_bytes_to_cortex(opt_folder_id, fn, fp, mimetype, **kwargs):
"""Upload a BytesIO object"""
- return upload_fp_to_cortex(opt_folder_id, (fn, fp.getvalue(), mimetype,))
+ return upload_fp_to_cortex(opt_folder_id, (fn, fp.getvalue(), mimetype,), **kwargs)
-def upload_file_to_cortex(opt_folder_id, fn):
+def upload_file_to_cortex(opt_folder_id, fn, **kwargs):
"""Upload a file from disk"""
with open(fn, 'rb') as fp:
- return upload_fp_to_cortex(opt_folder_id, fp)
+ return upload_fp_to_cortex(opt_folder_id, fp, **kwargs)