{"record":{"id":"3baa043c79d01b21","repo":"tensorflow/models","slug":"batch-size-cannot-be-more-than-1","errorCode":null,"errorMessage":"Batch size cannot be more than 1.","messagePattern":"Batch size cannot be more than 1\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/serving/semantic_segmentation.py","lineNumber":95,"sourceCode":"            dtype=tf.float32,\n        )\n        image_info_spec = tf.TensorSpec(shape=[4, 2], dtype=tf.float32)\n\n        images, image_info = tf.nest.map_structure(\n            tf.identity,\n            tf.map_fn(\n                self._build_inputs,\n                elems=images,\n                fn_output_signature=(images_spec, image_info_spec),\n                parallel_iterations=32))\n\n    outputs = self.inference_step(images)\n\n    # Optionally resize prediction to the input image size.\n    if self.params.task.export_config.rescale_output:\n      logits = outputs['logits']\n      if logits.shape[0] != 1:\n        raise ValueError('Batch size cannot be more than 1.')\n\n      image_shape = tf.cast(image_info[0, 0, :], tf.int32)  # pyrefly: ignore[unsupported-operation]\n      if self.params.task.train_data.preserve_aspect_ratio:\n        rescale_size = tf.cast(\n            tf.math.ceil(image_info[0, 1, :] / image_info[0, 2, :]), tf.int32)  # pyrefly: ignore[unsupported-operation]\n        offsets = tf.cast(image_info[0, 3, :], tf.int32)  # pyrefly: ignore[unsupported-operation]\n        logits = tf.image.resize(logits, rescale_size, method='bilinear')\n        outputs['logits'] = tf.image.crop_to_bounding_box(\n            logits, offsets[0], offsets[1], image_shape[0], image_shape[1])\n      else:\n        outputs['logits'] = tf.image.resize(\n            logits, [image_shape[0], image_shape[1]], method='bilinear')\n    else:\n      outputs['logits'] = tf.image.resize(\n          outputs['logits'], self._input_image_size, method='bilinear')\n\n    if image_info is not None:\n      outputs.update({'image_info': image_info})","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/serving/semantic_segmentation.py#L77-L113","documentation":"Error \"Batch size cannot be more than 1.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/serving/semantic_segmentation.py:95 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Export with batch size 1 for the semantic segmentation serving module.","Reshape the serving input signature to a single image per request."],"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"}