summaryrefslogtreecommitdiff
path: root/cli/app
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-01-08 14:00:32 +0100
committerJules Laplace <julescarbon@gmail.com>2020-01-08 14:00:32 +0100
commit4d236ffc49f377d54d6a8a93e864c52f925c6ee9 (patch)
tree6d336a32c23c5b4da2af1ffb6c2dc2f0d51b832f /cli/app
parentca032925551726fbca9e3fffa76aa766fdc37499 (diff)
clip latents differently
Diffstat (limited to 'cli/app')
-rw-r--r--cli/app/search/search_class.py8
-rw-r--r--cli/app/search/search_dense.py9
2 files changed, 10 insertions, 7 deletions
diff --git a/cli/app/search/search_class.py b/cli/app/search/search_class.py
index f7b2136..105fc9f 100644
--- a/cli/app/search/search_class.py
+++ b/cli/app/search/search_class.py
@@ -96,6 +96,8 @@ def find_nearest_vector(sess, generator, opt_fp_in, opt_dims, out_images, out_la
'truncation': input_trunc,
})
+ target = tf.compat.v1.placeholder(tf.float32, shape=(batch_size, img_size, img_size, num_channels))
+
## clip the Z encoding
opt_clip = 1.0
@@ -104,10 +106,10 @@ def find_nearest_vector(sess, generator, opt_fp_in, opt_dims, out_images, out_la
tf.random.uniform([batch_size, z_dim], minval=-opt_clip, maxval=opt_clip), input_z)
clip_latent = tf.assign(input_z, clipped_encoding)
- target = tf.compat.v1.placeholder(tf.float32, shape=(batch_size, img_size, img_size, num_channels))
-
## normalize the Y encoding
- normalized_labels = tf.nn.l2_normalize(input_y)
+ # normalized_labels = tf.nn.l2_normalize(input_y)
+ # tf.reduce_mean(tf.abs(encoding - gen_encoding))
+ normalized_labels = input_y / tf.reduce_sum(input_y)
clip_labels = tf.assign(input_y, normalized_labels)
## if computing Feature loss, use these encoders
diff --git a/cli/app/search/search_dense.py b/cli/app/search/search_dense.py
index ac4dc59..46183c7 100644
--- a/cli/app/search/search_dense.py
+++ b/cli/app/search/search_dense.py
@@ -124,6 +124,8 @@ def find_dense_embedding_for_images(params):
else:
gen_img = generator(latent, signature=gen_signature)
+ gen_img_orig = gen_img
+
# Convert generated image to channels_first.
gen_img = tf.transpose(gen_img, [0, 3, 1, 2])
@@ -393,7 +395,7 @@ def find_dense_embedding_for_images(params):
])
# Main optimization loop.
- print("Total iterations: {}".format(params.inv_it))
+ print("Beginning dense iteration...")
for _ in range(params.inv_it):
_inv_loss, _mse_loss, _feat_loss,\
@@ -435,15 +437,14 @@ def find_dense_embedding_for_images(params):
out_labels[out_pos:out_pos+BATCH_SIZE] = label_batch
out_err[out_pos:out_pos+BATCH_SIZE] = rec_err_batch
- gen_images = sess.run(gen_img)
+ gen_images = sess.run(gen_img_orig)
images = vs.data2img(gen_images)
# write encoding, latent to pkl file
for i in range(BATCH_SIZE):
out_i = out_pos + i
sample_fn, ext = os.path.splitext(sample_fns[out_i])
- image = Image.fromarray(images[i])
- image = vs.grid_transform(image)
+ image = Image.fromarray(image)
fp = BytesIO()
image.save(fp, format='png')
data = upload_bytes_to_cortex(params.folder_id, sample_fn + "-inverse.png", fp, "image/png")