tensorflow/models · error · ValueError

Invalid encoding type.

Error message

Invalid encoding type.

What it means

Error "Invalid encoding type." thrown in tensorflow/models.

Source

Thrown at official/projects/unified_detector/data_conversion/utils.py:34

from typing import Any, Dict, List, Tuple, Union


import cv2
import numpy as np
import tensorflow as tf, tf_keras


def encode_image(
    image_tensor: np.ndarray,
    encoding_type: str = 'png') -> Union[np.ndarray, tf.Tensor]:
  """Encode image tensor into byte string."""
  if encoding_type == 'jpg':
    image_encoded = tf.image.encode_jpeg(tf.constant(image_tensor))
  elif encoding_type == 'png':
    image_encoded = tf.image.encode_png(tf.constant(image_tensor))
  else:
    raise ValueError('Invalid encoding type.')
  if tf.executing_eagerly():
    image_encoded = image_encoded.numpy()
  else:
    image_encoded = image_encoded.eval()
  return image_encoded


def int64_feature(value: Union[int, List[int]]) -> tf.train.Feature:
  if not isinstance(value, list):
    value = [value]
  return tf.train.Feature(int64_list=tf.train.Int64List(value=value))


def float_feature(value: Union[float, List[float]]) -> tf.train.Feature:
  if not isinstance(value, list):
    value = [value]
  return tf.train.Feature(float_list=tf.train.FloatList(value=value))

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/unified_detector/data_conversion/utils.py:34 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/2376bcc4e4ab2ee0. Report an issue: GitHub.