diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-01-08 10:46:01 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-01-08 10:46:01 +0100 |
| commit | 41575d512f2c4a79c8909da02f7953bdaef674d1 (patch) | |
| tree | 8245ab828823349dd22efae40aa99dac7b5393ab /cli/app/search/search_dense.py | |
| parent | 4d05266f3c1f62646a5948f532528f591c6dc2ee (diff) | |
up
Diffstat (limited to 'cli/app/search/search_dense.py')
| -rw-r--r-- | cli/app/search/search_dense.py | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/cli/app/search/search_dense.py b/cli/app/search/search_dense.py index 27be015..7c0c728 100644 --- a/cli/app/search/search_dense.py +++ b/cli/app/search/search_dense.py @@ -284,42 +284,6 @@ def find_dense_embedding_for_images(params): feat_loss = tf.constant(0.0) img_feat_err = tf.constant(0.0) - # -------------------------- - # Regularization losses. - # -------------------------- - # Loss on the norm of the encoding. - if params.norm_loss: - dim = 20 - chi2_dist = tfp.distributions.Chi2(dim) - mode = dim - 2 - mode_log_prob = chi2_dist.log_prob(mode) - norm_loss = 0.0 - for i in range(int(Z_DIM / dim)): - squared_l2 = tf.reduce_sum(tf.square(latent[:,i*dim:(i+1)*dim]), axis=1) - over_mode = tf.nn.relu(squared_l2 - mode) - norm_loss -= tf.reduce_mean(chi2_dist.log_prob(mode + over_mode)) - norm_loss += mode_log_prob - else: - norm_loss = tf.constant(0.0) - - # Loss on the likelihood of the encoding. - if params.likeli_loss: - norm_dist = tfp.distributions.Normal(0.0, 1.0) - likeli_loss = - tf.reduce_mean(norm_dist.log_prob(latent)) - mode_log_prob = norm_dist.log_prob(0.0) - likeli_loss += mode_log_prob - else: - likeli_loss = tf.constant(0.0) - - # Regularization loss. - reg_loss = norm_loss + likeli_loss - - # Loss on the l1 distance between gen_encoding and inverted encoding. - if params.dist_loss: - dist_loss = tf.reduce_mean(tf.abs(encoding - gen_encoding)) - else: - dist_loss = tf.constant(0.0) - # Per image reconstruction error. img_rec_err = params.lambda_mse * img_mse_err\ + params.lambda_feat * img_feat_err @@ -328,8 +292,7 @@ def find_dense_embedding_for_images(params): rec_loss = params.lambda_mse * mse_loss + params.lambda_feat * feat_loss # Total inversion loss. - inv_loss = rec_loss + params.lambda_reg * reg_loss\ - + params.lambda_dist * dist_loss + inv_loss = rec_loss # -------------------------- # Optimizer. @@ -480,6 +443,7 @@ def find_dense_embedding_for_images(params): 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) fp = BytesIO() image.save(fp, format='png') data = upload_bytes_to_cortex(params.folder_id, sample_fn + "-inverse.png", fp, "image/png") |
