tensorflow/models · error · ValueError

Invalid tensor type: should be tf.float32

Error message

Invalid tensor type: should be tf.float32

What it means

Dtype guard in BoxList.__init__: downstream box ops (IoU, clipping, coding) assume float32 corner coordinates for exact arithmetic and dtype stability; a `boxes` tensor of any other dtype is rejected before it can poison later ops.

Solutions

  1. Cast the box tensor to tf.float32 before creating the BoxList.
  2. Use tf.cast(boxes, tf.float32) on integer or float64 inputs.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at official/vision/utils/object_detection/box_list.py:55 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24). Data as JSON: /api/errors/3c1b09d05eb03b68. Report an issue: GitHub.

Appendix: source

Thrown at official/vision/utils/object_detection/box_list.py:55


class BoxList(object):
  """Box collection."""

  def __init__(self, boxes):
    """Constructs box collection.

    Args:
      boxes: a tensor of shape [N, 4] representing box corners

    Raises:
      ValueError: if invalid dimensions for bbox data or if bbox data is not in
          float32 format.
    """
    if len(boxes.get_shape()) != 2 or boxes.get_shape()[-1] != 4:
      raise ValueError('Invalid dimensions for box data.')
    if boxes.dtype != tf.float32:
      raise ValueError('Invalid tensor type: should be tf.float32')
    self.data = {'boxes': boxes}

  def num_boxes(self):
    """Returns number of boxes held in collection.

    Returns:
      a tensor representing the number of boxes held in the collection.
    """
    return tf.shape(input=self.data['boxes'])[0]

  def num_boxes_static(self):
    """Returns number of boxes held in collection.

    This number is inferred at graph construction time rather than run-time.

    Returns:
      Number of boxes held in collection (integer) or None if this is not
        inferrable at graph construction time.

View on GitHub (pinned to e006f5f0d5)