Neural style error - cannot recreate style - optimizer issue?

I am running the neural_style notebook and am having issues replicating the results. I have the following configuration:
Windows 10
python 3.5.0
tensorflow 1.1.0
keras 2.0.6
scipy 0.19.1 (upgraded after reading the forums)
numpy 1.12.1
sklearn 1.18.1

computer: alienware w/ GTX 1070/8GB

First, I updated the Vgg_avg code to fix the incompatibility with keras 2. That seemed to work:

Layer (type) Output Shape Param #

input_5 (InputLayer) (None, None, None, 3) 0


block1_conv1 (Conv2D) (None, None, None, 64) 1792


block1_conv2 (Conv2D) (None, None, None, 64) 36928


block1_pool (AveragePooling2 (None, None, None, 64) 0


block2_conv1 (Conv2D) (None, None, None, 128) 73856


block2_conv2 (Conv2D) (None, None, None, 128) 147584


block2_pool (AveragePooling2 (None, None, None, 128) 0


block3_conv1 (Conv2D) (None, None, None, 256) 295168


block3_conv2 (Conv2D) (None, None, None, 256) 590080


block3_conv3 (Conv2D) (None, None, None, 256) 590080


block3_pool (AveragePooling2 (None, None, None, 256) 0


block4_conv1 (Conv2D) (None, None, None, 512) 1180160


block4_conv2 (Conv2D) (None, None, None, 512) 2359808


block4_conv3 (Conv2D) (None, None, None, 512) 2359808


block4_pool (AveragePooling2 (None, None, None, 512) 0


block5_conv1 (Conv2D) (None, None, None, 512) 2359808


block5_conv2 (Conv2D) (None, None, None, 512) 2359808


block5_conv3 (Conv2D) (None, None, None, 512) 2359808


block5_pool (AveragePooling2 (None, None, None, 512) 0

Total params: 14,714,688
Trainable params: 14,714,688
Non-trainable params: 0

However, when I run the scipy optimizer, I don’t get a loss, instead I’m getting a min_val of shape (1,18,30). Is this correct? The results look like the original noise image.

I then tried to use a van gogh (starry night) image. Resized it to same size as input (do I need to do this?) and ran the solve_image with the gramian matrix method for the loss function.

I get this error:

InvalidArgumentError Traceback (most recent call last)
c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
1038 try:
-> 1039 return fn(*args)
1040 except errors.OpError as e:

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
1020 feed_dict, fetch_list, target_list,
-> 1021 status, run_metadata)
1022

c:\users\susan\appdata\local\programs\python\python35\lib\contextlib.py in exit(self, type, value, traceback)
65 try:
—> 66 next(self.gen)
67 except StopIteration:

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status()
465 compat.as_text(pywrap_tensorflow.TF_Message(status)),
–> 466 pywrap_tensorflow.TF_GetCode(status))
467 finally:

InvalidArgumentError: Incompatible shapes: [64] vs. [128]
[[Node: add_7 = Add[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](add_6, Mean_11)]]
[[Node: add_7/_577 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name=“edge_423_add_7”, tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]]

During handling of the above exception, another exception occurred:

InvalidArgumentError Traceback (most recent call last)
in ()
----> 1 x = solve_image(evaluator, iterations, x)

in solve_image(eval_obj, niter, x)
2 for i in range(niter):
3 x, min_val, info = fmin_l_bfgs_b(eval_obj.loss, x.flatten(),
----> 4 fprime=eval_obj.grads, maxfun=20)
5 x = np.clip(x, -127,127)
6 # print(‘Current loss value:’, min_val)

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\scipy\optimize\lbfgsb.py in fmin_l_bfgs_b(func, x0, fprime, args, approx_grad, bounds, m, factr, pgtol, epsilon, iprint, maxfun, maxiter, disp, callback, maxls)
191
192 res = _minimize_lbfgsb(fun, x0, args=args, jac=jac, bounds=bounds,
–> 193 **opts)
194 d = {‘grad’: res[‘jac’],
195 ‘task’: res[‘message’],

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\scipy\optimize\lbfgsb.py in _minimize_lbfgsb(fun, x0, args, jac, bounds, disp, maxcor, ftol, gtol, eps, maxfun, maxiter, iprint, callback, maxls, **unknown_options)
326 # until the completion of the current minimization iteration.
327 # Overwrite f and g:
–> 328 f, g = func_and_grad(x)
329 elif task_str.startswith(b’NEW_X’):
330 # new iteration

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\scipy\optimize\lbfgsb.py in func_and_grad(x)
276 else:
277 def func_and_grad(x):
–> 278 f = fun(x, *args)
279 g = jac(x, *args)
280 return f, g

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\scipy\optimize\optimize.py in function_wrapper(*wrapper_args)
290 def function_wrapper(wrapper_args):
291 ncalls[0] += 1
–> 292 return function(
(wrapper_args + args))
293
294 return ncalls, function_wrapper

in loss(self, x)
3
4 def loss(self, x):
----> 5 loss_, self.grad_values = self.f([x.reshape(self.shp)])
6 return loss_.astype(np.float64)
7

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\keras\backend\tensorflow_backend.py in call(self, inputs)
2266 updated = session.run(self.outputs + [self.updates_op],
2267 feed_dict=feed_dict,
-> 2268 **self.session_kwargs)
2269 return updated[:len(self.outputs)]
2270

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
776 try:
777 result = self._run(None, fetches, feed_dict, options_ptr,
–> 778 run_metadata_ptr)
779 if run_metadata:
780 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
980 if final_fetches or final_targets:
981 results = self._do_run(handle, final_targets, final_fetches,
–> 982 feed_dict_string, options, run_metadata)
983 else:
984 results = []

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1030 if handle is None:
1031 return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1032 target_list, options, run_metadata)
1033 else:
1034 return self._do_call(_prun_fn, self._session, handle, feed_dict,

c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
1050 except KeyError:
1051 pass
-> 1052 raise type(e)(node_def, op, message)
1053
1054 def _extend_graph(self):

InvalidArgumentError: Incompatible shapes: [64] vs. [128]
[[Node: add_7 = Add[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](add_6, Mean_11)]]
[[Node: add_7/_577 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name=“edge_423_add_7”, tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]]

Caused by op ‘add_7’, defined at:
File “c:\users\susan\appdata\local\programs\python\python35\lib\runpy.py”, line 170, in _run_module_as_main
"main", mod_spec)
File “c:\users\susan\appdata\local\programs\python\python35\lib\runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\ipykernel_launcher.py”, line 16, in
app.launch_new_instance()
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\traitlets\config\application.py”, line 658, in launch_instance
app.start()
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\ipykernel\kernelapp.py”, line 477, in start
ioloop.IOLoop.instance().start()
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\zmq\eventloop\ioloop.py”, line 177, in start
super(ZMQIOLoop, self).start()
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tornado\ioloop.py”, line 888, in start
handler_func(fd_obj, events)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tornado\stack_context.py”, line 277, in null_wrapper
return fn(*args, **kwargs)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\zmq\eventloop\zmqstream.py”, line 440, in _handle_events
self._handle_recv()
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\zmq\eventloop\zmqstream.py”, line 472, in _handle_recv
self._run_callback(callback, msg)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\zmq\eventloop\zmqstream.py”, line 414, in _run_callback
callback(*args, **kwargs)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tornado\stack_context.py”, line 277, in null_wrapper
return fn(*args, **kwargs)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\ipykernel\kernelbase.py”, line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\ipykernel\kernelbase.py”, line 235, in dispatch_shell
handler(stream, idents, msg)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\ipykernel\kernelbase.py”, line 399, in execute_request
user_expressions, allow_stdin)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\ipykernel\ipkernel.py”, line 196, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\ipykernel\zmqshell.py”, line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\IPython\core\interactiveshell.py”, line 2683, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\IPython\core\interactiveshell.py”, line 2787, in run_ast_nodes
if self.run_code(code, result):
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\IPython\core\interactiveshell.py”, line 2847, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 1, in
loss = sum(style_loss(l1[0], l2[0]) for l1,l2 in zip(layers, targs))
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\ops\math_ops.py”, line 821, in binary_op_wrapper
return func(x, y, name=name)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\ops\gen_math_ops.py”, line 73, in add
result = _op_def_lib.apply_op(“Add”, x=x, y=y, name=name)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\framework\op_def_library.py”, line 768, in apply_op
op_def=op_def)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\framework\ops.py”, line 2336, in create_op
original_op=self._default_original_op, op_def=op_def)
File “c:\users\susan\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\framework\ops.py”, line 1228, in init
self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Incompatible shapes: [64] vs. [128]
[[Node: add_7 = Add[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](add_6, Mean_11)]]
[[Node: add_7/_577 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name=“edge_423_add_7”, tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]]


I’ve spent a few hours on this without success - would appreciate any suggestions. BTW, I’ve successfully run all of the notebooks from Lesson 1 without problems other than updating the code for python 3/ keras 2 and tensorflow, so I’m hoping that’s not the issue.
Thanks.

Just found this on the forums - changing the loss function. I tried it and it worked.