{"record":{"id":"2376bcc4e4ab2ee0","repo":"tensorflow/models","slug":"invalid-encoding-type","errorCode":null,"errorMessage":"Invalid encoding type.","messagePattern":"Invalid encoding type\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/unified_detector/data_conversion/utils.py","lineNumber":34,"sourceCode":"\nfrom typing import Any, Dict, List, Tuple, Union\n\n\nimport cv2\nimport numpy as np\nimport tensorflow as tf, tf_keras\n\n\ndef encode_image(\n    image_tensor: np.ndarray,\n    encoding_type: str = 'png') -> Union[np.ndarray, tf.Tensor]:\n  \"\"\"Encode image tensor into byte string.\"\"\"\n  if encoding_type == 'jpg':\n    image_encoded = tf.image.encode_jpeg(tf.constant(image_tensor))\n  elif encoding_type == 'png':\n    image_encoded = tf.image.encode_png(tf.constant(image_tensor))\n  else:\n    raise ValueError('Invalid encoding type.')\n  if tf.executing_eagerly():\n    image_encoded = image_encoded.numpy()\n  else:\n    image_encoded = image_encoded.eval()\n  return image_encoded\n\n\ndef int64_feature(value: Union[int, List[int]]) -> tf.train.Feature:\n  if not isinstance(value, list):\n    value = [value]\n  return tf.train.Feature(int64_list=tf.train.Int64List(value=value))\n\n\ndef float_feature(value: Union[float, List[float]]) -> tf.train.Feature:\n  if not isinstance(value, list):\n    value = [value]\n  return tf.train.Feature(float_list=tf.train.FloatList(value=value))\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/unified_detector/data_conversion/utils.py#L16-L52","documentation":"Error \"Invalid encoding type.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/unified_detector/data_conversion/utils.py:34 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"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"}