Permalink
Browse files

add parameters for the number of patch matching steps to perform

  • Loading branch information...
1 parent 169b924 commit 8215be10de41135cee698335ddf68bdbef4cafcd @awentzonline committed Mar 15, 2016
Showing with 17 additions and 9 deletions.
  1. +6 −0 image_analogy/argparser.py
  2. +4 −5 image_analogy/models/nnf.py
  3. +7 −4 scripts/make_image_analogy.py
@@ -44,6 +44,12 @@ def parse_args():
default=5, help='Number of iterations per scale')
parser.add_argument('--model', dest='match_model', type=str,
default='patchmatch', help='Matching algorithm (patchmatch or brute)')
+ parser.add_argument('--mrf-nnf-steps', dest='mrf_nnf_steps', type=int,
+ default=3, help='Number of patchmatch updates per iteration for local coherence loss.')
+ parser.add_argument('--no-zoom-mrf-nnf', dest='reset_mnf_steps', action='store_true',
+ help='Randomize the local coherence similarity matrix at the start of an iteration instead of scaling up the last one.')
+ parser.add_argument('--analogy-nnf-steps', dest='analogy_nnf_steps', type=int,
+ default=10, help='Number of patchmatch updates for the analogy loss.')
# loss
parser.add_argument('--mrf-w', dest='mrf_weight', type=float,
default=1.0, help='Weight for MRF loss between A\' and B\'')
@@ -11,9 +11,6 @@
class NNFModel(BaseModel):
'''Faster model for image analogies.'''
- num_mrf_nnf_steps = 10
- num_analogy_nnf_steps = 30
-
def build(self, a_image, ap_image, b_image, output_shape):
self.output_shape = output_shape
loss = self.build_loss(a_image, ap_image, b_image)
@@ -33,10 +30,12 @@ def eval_loss_and_grads(self, x):
x = x.reshape(self.output_shape)
f_inputs = [x]
# update the patch indexes
+ # start_t = time.time()
for nnf in self.feature_nnfs:
- nnf.update(x, num_steps=self.num_mrf_nnf_steps)
+ nnf.update(x, num_steps=self.args.mrf_nnf_steps)
new_target = nnf.matcher.get_reconstruction()
f_inputs.append(new_target)
+ # print('PatchMatch update in {:.2f} seconds'.format(time.time() - start_t))
# run it through
outs = self.f_outputs(f_inputs)
loss_value = outs[0]
@@ -64,7 +63,7 @@ def build_loss(self, a_image, ap_image, b_image):
combination_features = layer_features[0, :, :, :]
al = nnf_analogy_loss(
a_features, ap_image_features, b_features, combination_features,
- num_steps=self.num_analogy_nnf_steps, patch_size=self.args.patch_size,
+ num_steps=self.args.analogy_nnf_steps, patch_size=self.args.patch_size,
patch_stride=self.args.patch_stride, jump_size=1.0)
loss += (self.args.analogy_weight / len(self.args.analogy_layers)) * al
@@ -1,13 +1,14 @@
#!/usr/bin/env python
'''Neural Image Analogies with Keras
-Before running this script, download the weights for the VGG16 model at:
-https://drive.google.com/file/d/0Bz7KyqmuGsilT0J5dmRCM0ROVHc/view?usp=sharing
+Before running this script, download the weights for the convolutional layers of
+the VGG16 model at:
+https://github.com/awentzonline/image-analogies/releases/download/v0.0.5/vgg16_weights.h5
(source: https://gist.github.com/baraldilorenzo/07d7802847aaad0a35d3)
and make sure the parameter `vgg_weights` matches the location of the file.
-
-It is preferrable to run this script on GPU, for speed.
'''
+import time
+
import image_analogy.argparser
import image_analogy.main
@@ -21,7 +22,9 @@
else:
print('Using brute-force model')
from image_analogy.models.analogy import AnalogyModel as model_class
+ start_time = time.time()
try:
image_analogy.main.main(args, model_class)
except KeyboardInterrupt:
print('Shutting down...')
+ print('Done after {:.2f} seconds'.format(time.time() - start_time))

0 comments on commit 8215be1

Please sign in to comment.