summaryrefslogtreecommitdiff
path: root/cli/app/search
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-02-14 16:38:46 +0100
committerJules Laplace <julescarbon@gmail.com>2020-02-14 16:38:46 +0100
commit887feafc4a9bb8fb818bfed208fdafb1cd21b5fc (patch)
treef4a6e2cebc6541b51ae9cde38c81b479ec091660 /cli/app/search
parentdfaac1a79fdc2219e2ec597d3781a81992716e24 (diff)
vgg feature loss
Diffstat (limited to 'cli/app/search')
-rw-r--r--cli/app/search/search_dense.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/cli/app/search/search_dense.py b/cli/app/search/search_dense.py
index f453a44..267d7ff 100644
--- a/cli/app/search/search_dense.py
+++ b/cli/app/search/search_dense.py
@@ -210,10 +210,10 @@ def find_dense_embedding_for_images(params, opt_tag="inverse_" + timestamp(), op
feature_extractor = slim.nets.vgg.vgg_16
# conv1_1, conv1_2, conv3_2, conv4_2
opt_feature_layers = [
- 'vgg_16/conv1/conv1_1',
- 'vgg_16/conv1/conv1_2',
- 'vgg_16/conv3/conv3_2',
- 'vgg_16/conv4/conv4_2',
+ 'conv1/conv1_1',
+ 'conv1/conv1_2',
+ 'conv3/conv3_2',
+ 'conv4/conv4_2',
]
feature_loss = feature_loss_vgg
height = 224
@@ -581,11 +581,10 @@ def feature_loss_vgg(feature_extractor, opt_feature_layers, BATCH_SIZE, img_a, i
img_b = tf.image.resize_images(img_b, [resize_height, resize_width])
global scope_index
- scope_index += 1
- gen_fc, gen_feat_ex = nets.vgg.vgg_16(img_a, scope='vgg_16_{}'.format(scope_index))
-
- scope_index += 1
- target_fc, target_feat_ex = nets.vgg.vgg_16(img_b, scope='vgg_16_{}'.format(scope_index))
+ scope_a = 'vgg_16_{}_a'.format(scope_index)
+ scope_b = 'vgg_16_{}_b'.format(scope_index)
+ gen_fc, gen_feat_ex = nets.vgg.vgg_16(img_a, scope=scope_a)
+ target_fc, target_feat_ex = nets.vgg.vgg_16(img_b, scope=scope_b)
# gen_feat_ex = feature_extractor(dict(images=img_a), as_dict=True, signature='image_feature_vector')
# target_feat_ex = feature_extractor(dict(images=img_b), as_dict=True, signature='image_feature_vector')
@@ -593,8 +592,8 @@ def feature_loss_vgg(feature_extractor, opt_feature_layers, BATCH_SIZE, img_a, i
img_feat_err = tf.constant(0.0)
for layer_name in opt_feature_layers:
- gen_feat = gen_feat_ex[layer_name]
- target_feat = target_feat_ex[layer_name]
+ gen_feat = gen_feat_ex[scope_a + '/' + layer_name]
+ target_feat = target_feat_ex[scope_b + '/' + layer_name]
feat_square_diff = tf.reshape(tf.square(gen_feat - target_feat), [BATCH_SIZE, -1])
feat_loss += tf.reduce_mean(feat_square_diff)
img_feat_err += tf.reduce_mean(feat_square_diff, axis=1)