tensorflow/models · error · ValueError

Invalid tensor type: should be tf.float32

Error message

Invalid tensor type: should be tf.float32

What it means

Error "Invalid tensor type: should be tf.float32" thrown in tensorflow/models.

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)

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.

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.