# Assertion \`t \>= 0 && t \< n\_classes\` failed error

**URL:** <https://discuss.pytorch.org/t/assertion-t-0-t-n-classes-failed-error/133794>\
**Category:** vision\
**Created:** [October 9, 2021, 7:46am UTC](https://discuss.pytorch.org/t/assertion-t-0-t-n-classes-failed-error/133794 "2021-10-09T07:46:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [October 9, 2021, 9:59am UTC](https://discuss.pytorch.org/t/assertion-t-0-t-n-classes-failed-error/133794/2 "2021-10-09T09:59:56Z")

</div>

The target tensor for `nn.CrossEntropyLoss` is expected to contain class indices in the range `[0, nb_classes-1]`, which seems to fail in your script.  
Check its values via `print(target.min(), target.max())` and make sure they are valid.

---

_[View the full topic](https://discuss.pytorch.org/t/assertion-t-0-t-n-classes-failed-error/133794)._
