Hello, I encountered a problem at the “Calculate loss” step with the detection_model at

```
try:
losses_dict = detection_model.loss(prediction_dict, true_shape_tensor)
except RuntimeError as e:
print(e)
```

I get:

Groundtruth tensor boxes has not been provided

then after that at losses_dict:

```
# Calculate the loss after you've provided the ground truth
losses_dict = detection_model.loss(prediction_dict, true_shape_tensor) # Error at this line!
# View the loss dictionary
losses_dict = detection_model.loss(prediction_dict, true_shape_tensor)
print(f"loss dictionary keys: {losses_dict.keys()}")
print(f"localization loss {losses_dict['Loss/localization_loss']:.8f}")
print(f"classification loss {losses_dict['Loss/classification_loss']:.8f}")
```

I get this error:

```
ValueError Traceback (most recent call last)
<ipython-input-54-36f83e7403b4> in <cell line: 2>()
1 # Calculate the loss after you've provided the ground truth
----> 2 losses_dict = detection_model.loss(prediction_dict, true_shape_tensor)
3
4 # View the loss dictionary
5 losses_dict = detection_model.loss(prediction_dict, true_shape_tensor)
4 frames
/usr/local/lib/python3.10/dist-packages/object_detection/utils/shape_utils.py in assert_shape_equal(shape_a, shape_b)
319 all(isinstance(dim, int) for dim in shape_b)):
320 if shape_a != shape_b:
--> 321 raise ValueError('Unequal shapes {}, {}'.format(shape_a, shape_b))
322 else: return tf.no_op()
323 else:
ValueError: Unequal shapes [2], [91]
```

I think there is a shape problem with either prediction_dict, true_shape_tensor after previous steps. I am not sure what I did incorrectly. Thanks for your help!

Did you run the previous cell where you provide the the ground truth boxes, detection_model.provide_groundtruth()…

Hello @noedigsti,

Try to run the previous cell, if the problem is still there try to run the cell from the start. Also, you can check out the link given below to know about [provide_ground_truth] (https://github.com/tensorflow/models/blob/fd6b24c19c68af026bb0a9efc9f7b1719c231d3d/research/object_detection/core/model.py#L297)

Thank you guys for your help! Indeed, I figured out the problem was when I restarted the notebook a few times and forgot to label the ground truth boxes or modify “override=False” to True at the Prepare the data for training (Optional). All cells worked fine for me now. I learned a lot, thank you for this assignment!

2 Likes

I have this problem too, but this didn’t work for me

Hello @NY_ZDAROVA

Do check out the link I provided above. If it isn’t solved do ask and specify where you are facing the problem.

## The same problem in the same place

ValueError Traceback (most recent call last)

in <cell line: 5>()

3

4 # View the loss dictionary

----> 5 losses_dict = detection_model.loss(prediction_dict, true_shape_tensor)

6 print(f"loss dictionary keys: {losses_dict.keys()}“)

7 print(f"localization loss {losses_dict[‘Loss/localization_loss’]:.8f}”)

4 frames

/usr/local/lib/python3.10/dist-packages/object_detection/utils/shape_utils.py in assert_shape_equal(shape_a, shape_b)

319 all(isinstance(dim, int) for dim in shape_b)):

320 if shape_a != shape_b:

→ 321 raise ValueError(‘Unequal shapes {}, {}’.format(shape_a, shape_b))

322 else: return tf.no_op()

323 else:

ValueError: Unequal shapes [2], [91]

this link you provided about function provide_groundtruth doesn’t tell me anything useful