{"record":{"id":"2731ed1ba45ae7da","repo":"tensorflow/models","slug":"labels-must-be-1-dimensional-got-a-tensor-of-shap","errorCode":null,"errorMessage":"labels must be 1 dimensional, got a tensor of shape %s","messagePattern":"labels must be 1 dimensional, got a tensor of shape (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/ops/sampling_ops.py","lineNumber":343,"sourceCode":"      batch_size: desired batch size. If None, keeps all positive samples and\n        randomly selects negative samples so that the positive sample fraction\n        matches self._positive_fraction. It cannot be None is is_static is True.\n      labels: boolean tensor of shape [N] denoting positive(=True) and negative\n          (=False) examples.\n      scope: name scope.\n\n    Returns:\n      sampled_idx_indicator: boolean tensor of shape [N], True for entries which\n        are sampled.\n\n    Raises:\n      ValueError: if labels and indicator are not 1D boolean tensors.\n    \"\"\"\n    if len(indicator.get_shape().as_list()) != 1:\n      raise ValueError('indicator must be 1 dimensional, got a tensor of '\n                       'shape %s' % indicator.get_shape())\n    if len(labels.get_shape().as_list()) != 1:\n      raise ValueError('labels must be 1 dimensional, got a tensor of '\n                       'shape %s' % labels.get_shape())\n    if labels.dtype != tf.bool:\n      raise ValueError('labels should be of type bool. Received: %s' %\n                       labels.dtype)\n    if indicator.dtype != tf.bool:\n      raise ValueError('indicator should be of type bool. Received: %s' %\n                       indicator.dtype)\n    scope = scope or 'BalancedPositiveNegativeSampler'\n    with tf.name_scope(scope):\n      if self._is_static:\n        return self._static_subsample(indicator, batch_size, labels)\n\n      else:\n        # Only sample from indicated samples\n        negative_idx = tf.logical_not(labels)\n        positive_idx = tf.logical_and(labels, indicator)\n        negative_idx = tf.logical_and(negative_idx, indicator)\n","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/ops/sampling_ops.py#L325-L361","documentation":"Error \"labels must be 1 dimensional, got a tensor of shape %s\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/ops/sampling_ops.py:343 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a 1-D labels tensor (shape [num_boxes]).","Flatten or reshape the labels tensor to rank 1."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}