C4W4, 'Art Generation <...>' error in compute_layer_style_cost

Hi guys,

Been trying to fix this for several hours now, but all of my attempts have been unsuccessful so far. Could anybody point me to the right direction?

ERROR:

InvalidArgumentError Traceback (most recent call last)
in
2 a_S = tf.random.normal([1, 4, 4, 3], mean=1, stddev=4)
3 a_G = tf.random.normal([1, 4, 4, 3], mean=1, stddev=4)
----> 4 J_style_layer_GG = compute_layer_style_cost(a_G, a_G)
5 J_style_layer_SG = compute_layer_style_cost(a_S, a_G)
6

in compute_layer_style_cost(a_S, a_G)
25
26 # Computing the loss (β‰ˆ1 line)
β€”> 27 J_style_layer = (1/(4*tf.square(n_C)tf.square(n_Hn_W))) * tf.reduce_sum(tf.square(tf.subtract(GS,GG)))
28
29 ### END CODE HERE

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_ops.py in binary_op_wrapper(x, y)
1123 with ops.name_scope(None, op_name, [x, y]) as name:
1124 try:
β†’ 1125 return func(x, y, name=name)
1126 except (TypeError, ValueError) as e:
1127 # Even if dispatching the op failed, the RHS may be a tensor aware

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_ops.py in _mul_dispatch(x, y, name)
1455 return sparse_tensor.SparseTensor(y.indices, new_vals, y.dense_shape)
1456 else:
β†’ 1457 return multiply(x, y, name=name)
1458
1459

/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 β€œβ€β€œCall target, and fall back on dispatchers if there is a TypeError.”""
200 try:
β†’ 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_ops.py in multiply(x, y, name)
507 β€œβ€"
508
β†’ 509 return gen_math_ops.mul(x, y, name)
510
511

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_math_ops.py in mul(x, y, name)
6164 return _result
6165 except _core._NotOkStatusException as e:
β†’ 6166 _ops.raise_from_not_ok_status(e, name)
6167 except _core._FallbackException:
6168 pass

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
6841 message = e.message + (" name: " + name if name is not None else β€œβ€)
6842 # pylint: disable=protected-access
β†’ 6843 six.raise_from(core._status_to_exception(e.code, message), None)
6844 # pylint: enable=protected-access
6845

/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: cannot compute Mul as input #1(zero-based) was expected to be a double tensor but is a float tensor [Op:Mul]

This issue has been solved by using **2 instead of tf.square() when defining J_style_layer.

This has been proposed by Anomy (please find his entry here: Course 4, week 4 Neural Style Transfer: train_step "Unexpected cost for epoch 0"). Thanks Anomy!

2 Likes