One thing you can try is to clone my implementation of Jeremy’s code and see if it works better, then we can use that to figure out what’s wrong. (Mine is modified for Keras 2.0.6, however)
Just skip down to the section titled “Bringing it all together”
Hi,
I am trying to get my head around the definition of solve_image function
def solve_image(eval_obj, niter, x):
for i in range(niter):
x, min_val, info = fmin_l_bfgs_b(eval_obj.loss, x.flatten(),
fprime=eval_obj.grads, maxfun=20)
x = np.clip(x, -127,127)
print('Current loss value:', min_val)
imsave('results\\res_at_iteration_' +str(i) +'.png', deproc(x.copy(), shp)[0])
return x
The thing which is not clear to me is why there is a for loop. BFGS is deterministic optimizer and therefore I would expect it to find the optimal solution.
My only explanation is that using the param maxfun=20 we limit the number of iterations done by the optimizer in each loop. It allows us to save the intermediate state of the image image and stop the optimization sooner than it finds the optimum.
Jeremy, just a setup question, where I can find the pictures you used in the class, the three files I downloaded doesn’t contain pictures like the bird?
Just change the loss function to K.mean of the mse like in the example below - def style_loss(x, targ): return K.mean(metrics.mse(gram_matrix(x), gram_matrix(targ)))