Help with C1_W3_Assignment UNQC_C4

Hi, I am stuck with this exercice. I am getting the above error. Thank you for the help!
(My ID lab is: rbmfamcawijv)


InvalidArgumentError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
1606 try:
→ 1607 c_op = c_api.TF_FinishOperation(op_desc)
1608 except errors.InvalidArgumentError as e:

InvalidArgumentError: Invalid reduction dimension 3 for input with 3 dimensions. for ‘Sum_18’ (op: ‘Sum’) with input shapes: [2,2,1], [3] and with computed input tensors: input[1] = <1 2 3>.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
in ()
6 ### do not edit anything below
7 sess = K.get_session()
----> 8 dice_coefficient_test(dice_coefficient, epsilon, sess)

~/work/W3A1/public_tests.py in dice_coefficient_test(target, epsilon, sess)
193 print(label_1[0, :, :, 0])
194
→ 195 dc_1= target(pred_1, label_1, epsilon=epsilon)
196 print("\nDice coefficient: ", dc_1.eval(session=sess), “\n\n----------------------\n”)
197

in dice_coefficient(y_true, y_pred, axis, epsilon)
27 y_pred_class = y_pred[class_idx]
28
—> 29 dice_numerator = 2 * tf.keras.backend.sum(y_true_class * y_pred_class, axis=axis) + epsilon
30 dice_denominator = tf.keras.backend.sum(y_true_class, axis=axis) + tf.keras.backend.sum(y_pred_class, axis=axis) + epsilon
31 dice_coefficient_class = dice_numerator / dice_denominator

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py in sum(x, axis, keepdims)
1895 A tensor with sum of x.
1896 “”"
→ 1897 return math_ops.reduce_sum(x, axis, keepdims)
1898
1899

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/util/dispatch.py in wrapper(*args, **kwargs)
178 “”“Call target, and fall back on dispatchers if there is a TypeError.”“”
179 try:
→ 180 return target(*args, **kwargs)
181 except (TypeError, ValueError):
182 # Note: convert_to_eager_tensor currently raises a ValueError, not a

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/ops/math_ops.py in reduce_sum(input_tensor, axis, keepdims, name)
1562 gen_math_ops._sum(
1563 input_tensor, _ReductionDims(input_tensor, axis), keepdims,
→ 1564 name=name))
1565
1566

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/ops/gen_math_ops.py in _sum(input, axis, keep_dims, name)
11164 _, _, _op = _op_def_lib._apply_op_helper(
11165 “Sum”, input=input, reduction_indices=axis, keep_dims=keep_dims,

11166 name=name)
11167 _result = _op.outputs[:]
11168 _inputs_flat = _op.inputs

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
792 op = g.create_op(op_type_name, inputs, dtypes=None, name=scope,
793 input_types=input_types, attrs=attr_protos,
→ 794 op_def=op_def)
795
796 # Conditionally invoke tfdbg v2’s op callback(s).

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/util/deprecation.py in new_func(*args, **kwargs)
505 ‘in a future version’ if date is None else ('after s' date),
506 instructions)
→ 507 return func(*args, **kwargs)
508
509 doc = _add_deprecated_arg_notice_to_docstring(

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in create_op(failed resolving arguments)
3355 raise TypeError("Input #%d is not a tensor: s" (idx, a))
3356 return self._create_op_internal(op_type, inputs, dtypes, input_types, name,
→ 3357 attrs, op_def, compute_device)
3358
3359 def _create_op_internal(

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in _create_op_internal(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_device)
3424 input_types=input_types,
3425 original_op=self._default_original_op,
→ 3426 op_def=op_def)
3427 self._create_op_helper(ret, compute_device=compute_device)
3428 return ret

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in init(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def)
1768 op_def, inputs, node_def.attr)
1769 self._c_op = _create_c_op(self._graph, node_def, grouped_inputs,
→ 1770 control_input_ops)
1771 # pylint: enable=protected-access
1772

/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
1608 except errors.InvalidArgumentError as e:
1609 # Convert to ValueError for backwards compatibility.
→ 1610 raise ValueError(str(e))
1611
1612 return c_op

ValueError: Invalid reduction dimension 3 for input with 3 dimensions. for ‘Sum_18’ (op: ‘Sum’) with input shapes: [2,2,1], [3] and with computed input tensors: input[1] = <1 2 3>.

Hi @Tamara_Iungman,

You have tried implementing the function in a complicated way. Please look at the equation provided above the exercise and try again.

Best,
Mubsi

Hello,

You have multiple issues with your assignment. Some of the functions codes you recalled with incorrect code.

Has your grader cell for C1, C2 and C3 passed.

UNQC1 errors
TypeError("Input #%d is not a tensor: s(idx, a))
You have got type error for inputs.
make sure you have imported all the libraries correctly.
Run all the cells one by one.

Convert to ValueError for backwards compatibility.

→ 1610 raise ValueError(str(e))
error in this code
bgrd_ratio =

You have modified grader cell beyond these markers ###START CODE HERE —###END CODE###

Check you dice_numerator code for UNQC4 grader cell

Regards
DP