Train_test_step_fns Filename: train_test_step_fns 8/10Score: 8 of 10 Grader output Failed train_result_shape_check. Expected: (), but got: (5,)

Hello,

I’m getting an error during grading

Filename: train_test_step_fns
8/10Score: 8 of 10
Grader output
Failed train_result_shape_check.
Expected:
(),
but got:
(5,).

Here’s my function and I don’t understand the error

Hi,

As far as i saw the code seems fine, you should check the input (images and labels) shapes. The erros says the output of the train_step is not right.

Are you referring to this piece of code?

# Take a look at a single batch from the train_dist_dataset

x = iter(train_dist_dataset).get_next()

    

print(f"x is a tuple that contains {len(x)} values ")

print(f"x[0] contains the features, and has shape {x[0].shape}")

print(f"  so it has {x[0].shape[0]} examples in the batch, each is an image that is {x[0].shape[1:]}")

print(f"x[1] contains the labels, and has shape {x[1].shape}")

WARNING:tensorflow:From /opt/conda/lib/python3.7/site-packages/tensorflow/python/data/ops/multi_device_iterator_ops.py:601: get_next_as_optional (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Iterator.get_next_as_optional()` instead.

WARNING:tensorflow:From /opt/conda/lib/python3.7/site-packages/tensorflow/python/data/ops/multi_device_iterator_ops.py:601: get_next_as_optional (from tensorflow.python.data.ops.iterator_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Iterator.get_next_as_optional()` instead.

x is a tuple that contains 2 values 
x[0] contains the features, and has shape (64, 224, 224, 3)
  so it has 64 examples in the batch, each is an image that is (224, 224, 3)
x[1] contains the labels, and has shape (64,)

I am saying you have to trace back why the train_result is not of the required shape and obviously its probable that this should be coming form the inputs to the function or even maybe the model or
even the loss function if not implemented as supposed to, but you have to check them out, trace back the error. I would start with the images, labels = inputs, check their shape, are they right, then check the rest.