summaryrefslogtreecommitdiff
path: root/cli/app/search/live.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-01-17 01:31:51 +0100
committerJules Laplace <julescarbon@gmail.com>2020-01-17 01:31:51 +0100
commit895938a610b629df666b7f1a68f2e80407278550 (patch)
treed5af7e485fd1d99d4ed5946146c8fd4399031609 /cli/app/search/live.py
parent4a6259c21629bcfa31a0f756ddc31ee511f154c7 (diff)
sine encoding
Diffstat (limited to 'cli/app/search/live.py')
-rw-r--r--cli/app/search/live.py89
1 files changed, 50 insertions, 39 deletions
diff --git a/cli/app/search/live.py b/cli/app/search/live.py
index 8d9a5ef..e626e25 100644
--- a/cli/app/search/live.py
+++ b/cli/app/search/live.py
@@ -88,12 +88,16 @@ def normal_z_sample(shape=(BATCH_SIZE, Z_DIM,)):
# --------------------------
class SinParam:
- def __init__(self, name, shape, datatype="noise"):
- noise = LerpParam(name + '_noise', shape=shape, datatype=datatype)
+ def __init__(self, name, shape, datatype="noise", lerp=True):
orbit_radius = InterpolatorParam(name=name + '_radius', value=0.25)
orbit_speed = InterpolatorParam(name=name + '_speed', value=FPS)
orbit_time = InterpolatorParam(name=name + '_time', value=0.0)
- output = tf.math.sin(orbit_time.variable + noise.output) * orbit_radius.variable
+ if lerp:
+ noise = LerpParam(name + '_noise', shape=shape, datatype=datatype)
+ output = tf.math.sin(orbit_time.variable + noise.output) * orbit_radius.variable
+ else:
+ noise = InterpolatorParam(name + '_noise_a', shape=shape, datatype=datatype)
+ output = tf.math.sin(orbit_time.variable + noise.variable) * orbit_radius.variable
interpolator.sin_params[name] = self
self.name = name
self.orbit_speed = orbit_speed
@@ -219,15 +223,16 @@ class Interpolator:
disentangled = z_mix.output + zoom + shiftx + shifty + luminance
# Latent - stored vector
- latent_stored = LerpParam(name='latent_stored', shape=[BATCH_SIZE, Z_DIM], datatype="noise")
- latent_stored_mix = LerpParam('latent_stored_mix', a_in=disentangled, b_in=latent_stored.output, shape=[BATCH_SIZE, Z_DIM], datatype="input")
+ # latent_stored = LerpParam(name='latent_stored', shape=[BATCH_SIZE, Z_DIM], datatype="noise")
+ latent_stored = InterpolatorParam(name='latent_stored', shape=[BATCH_SIZE, Z_DIM], datatype="noise")
+ latent_stored_mix = LerpParam('latent_stored_mix', a_in=disentangled, b_in=latent_stored.variable, shape=[BATCH_SIZE, Z_DIM], datatype="input")
# Label
lerp_label = LerpParam('label', shape=[BATCH_SIZE, N_CLASS], datatype="label")
# Latent - stored vector
- label_stored = LerpParam(name='label_stored', shape=[BATCH_SIZE, N_CLASS], datatype="label")
- label_stored_mix = LerpParam('label_stored_mix', a_in=lerp_label.output, b_in=label_stored.output, shape=[BATCH_SIZE, Z_DIM], datatype="input")
+ label_stored = InterpolatorParam(name='label_stored', shape=[BATCH_SIZE, N_CLASS], datatype="label")
+ label_stored_mix = LerpParam('label_stored_mix', a_in=lerp_label.output, b_in=label_stored.variable, shape=[BATCH_SIZE, Z_DIM], datatype="input")
# Generator
gen_in = {}
@@ -243,20 +248,22 @@ class Interpolator:
encoding_shape = encoding_latent.get_shape().as_list()
encoding_shape_np = tuple([1,] + encoding_shape[1:])
- encoding_shape_placeholder = tf.constant(np.zeros(encoding_shape_np, dtype=np.float32))
- encoding_stored = LerpParam('encoding_stored', shape=encoding_shape_np, datatype="encoding")
- encoding_stored_mix = LerpParam('encoding_stored_mix', a_in=encoding_shape_placeholder, b_in=encoding_stored.output, shape=encoding_shape_np, datatype="encoding")
+ encoding_latent_placeholder = tf.constant(np.zeros(encoding_shape_np, dtype=np.float32))
+ encoding_stored = InterpolatorParam('encoding_stored', shape=encoding_shape_np, datatype="noise")
+ encoding_stored_sin = SinParam('encoding_orbit', shape=encoding_shape_np, datatype="noise")
+ encoding_stored_sum = encoding_stored.variable + encoding_stored_sin.output
+ encoding_stored_mix = LerpParam('encoding_stored_mix', a_in=encoding_latent_placeholder, b_in=encoding_stored_sum, shape=encoding_shape_np, datatype="encoding")
# Use the placeholder to redirect parts of the graph.
# - computed encoding goes into the encoding_mix
# - encoding mix output goes into the main biggan graph
# We do it this way so the encoding_latent won't be going into two places at once.
- tf.contrib.graph_editor.swap_ts(encoding_shape_placeholder, encoding_latent)
- tf.contrib.graph_editor.swap_ts(encoding_stored_mix.output, encoding_shape_placeholder)
+ tf.contrib.graph_editor.swap_ts(encoding_latent_placeholder, encoding_latent)
+ tf.contrib.graph_editor.swap_ts(encoding_stored_mix.output, encoding_latent_placeholder)
# Make all the stored lerps use the same interpolation amount.
- tf.contrib.graph_editor.reroute_ts(encoding_stored.n.variable, latent_stored.n.variable)
- tf.contrib.graph_editor.reroute_ts(encoding_stored.n.variable, label_stored.n.variable)
+ # tf.contrib.graph_editor.reroute_ts(encoding_stored.n.variable, latent_stored.n.variable)
+ # tf.contrib.graph_editor.reroute_ts(encoding_stored.n.variable, label_stored.n.variable)
tf.contrib.graph_editor.reroute_ts(encoding_stored_mix.n.variable, latent_stored_mix.n.variable)
tf.contrib.graph_editor.reroute_ts(encoding_stored_mix.n.variable, label_stored_mix.n.variable)
@@ -316,34 +323,38 @@ class Interpolator:
next_id = opt['id']
data = load_pickle(os.path.join(app_cfg.DIR_VECTORS, "file_{}.pkl".format(next_id)))
- new_encoding = np.expand_dims(data['encoding'], axis=0)
- new_label = np.expand_dims(data['label'], axis=0)
new_latent = np.expand_dims(data['latent'], axis=0)
+ new_label = np.expand_dims(data['label'], axis=0)
+ new_encoding = np.expand_dims(data['encoding'], axis=0)
- latent_stored = self.lerp_params['latent_stored']
- label_stored = self.lerp_params['label_stored']
- encoding_stored = self.lerp_params['encoding_stored']
- encoding_stored_mix = self.lerp_params['encoding_stored_mix']
+ self.opts['latent_stored'].assign(new_latent)
+ self.opts['label_stored'].assign(new_label)
+ self.opts['encoding_stored'].assign(new_encoding)
+ encoding_stored_mix.switch()
+ # latent_stored = self.lerp_params['latent_stored']
+ # label_stored = self.lerp_params['label_stored']
+ # encoding_stored = self.lerp_params['encoding_stored']
+ # encoding_stored_mix = self.lerp_params['encoding_stored_mix']
- # if we're showing an encoding already, lerp to the next one
- if encoding_stored_mix.n.value > 0:
- encoding_stored.switch(target_value=new_encoding)
- label_stored.switch(target_value=new_label)
- latent_stored.switch(target_value=new_latent)
- # otherwise (we're showing the latent)...
- else:
- # jump to the stored encoding, then switch
- if encoding_stored.n.value < 0.5:
- encoding_stored.n.assign(0)
- encoding_stored.a.assign(new_encoding)
- latent_stored.a.assign(new_latent)
- label_stored.a.assign(new_label)
- else:
- encoding_stored.n.assign(1)
- encoding_stored.b.assign(new_encoding)
- latent_stored.b.assign(new_latent)
- label_stored.b.assign(new_label)
- encoding_stored_mix.switch()
+ # # if we're showing an encoding already, lerp to the next one
+ # if encoding_stored_mix.n.value > 0:
+ # encoding_stored.switch(target_value=new_encoding)
+ # label_stored.switch(target_value=new_label)
+ # latent_stored.switch(target_value=new_latent)
+ # # otherwise (we're showing the latent)...
+ # else:
+ # # jump to the stored encoding, then switch
+ # if encoding_stored.n.value < 0.5:
+ # encoding_stored.n.assign(0)
+ # encoding_stored.a.assign(new_encoding)
+ # latent_stored.a.assign(new_latent)
+ # label_stored.a.assign(new_label)
+ # else:
+ # encoding_stored.n.assign(1)
+ # encoding_stored.b.assign(new_encoding)
+ # latent_stored.b.assign(new_latent)
+ # label_stored.b.assign(new_label)
+ # encoding_stored_mix.switch()
def on_step(self, i, sess):
for param in self.sin_params.values():