Lesson 8 Discussion

I’m getting an error generating the random image: ValueError: Floating point image RGB values must be in the 0…1 range.

If I change the range from -2.5, 2.5 to 0, 100 it works well, but not sure if I’ll get the same result as the original.

How long is it taking to run the first solve_image function? Here with a 1080ti it’s taking 5 mins.

It’s even better, as explained in Lesson 9, as I’m sure you’ve figured out by now :slight_smile:

1 Like

When you say

the first solve_image function

do you mean the 10 iterations? I have a 1080 Ti as well and it takes about 20 seconds tops. When you run

watch -n 1 nvidia-smi

what % GPU Util. are you seeing while running those 10 iterations? It should get above 90%.

As regards the random image, I couldn’t for the life of me figure out why it was -2.5 to 2.5, so I changed my function to the following:

rand_img = lambda shape: np.random.uniform(0, 255, shape)
x = rand_img(img_shape)

Don’t know if this helps at all, but let me know if you’re still running into issues

Thanks @corbin! It wasn’t using my gpu, I had to reinstall Tensorflow and not it’s taking about 8 seconds, way better.

The only thing that I’ve noticed is that the quality generated seems worst than with CPU.

Check out some images:

  • Content Extraction from block5_conv1, 10 iterations:
    res_at_iteration_9
  • Style extraction from Starry Night. 10 iterations:
    res_at_iteration_9
  • Result with 10 iterations:
    res_at_iteration_9

Any idea?

That looks very odd. Are you running the notebook exactly as provided? What version of keras are you using?

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.

Is my understanding correct?

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?

1 Like

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)))