class_docstr: `FeatureConnector` for integer class labels.
docstr: Constructs a ClassLabel FeatureConnector.
  
  There are 3 ways to define a ClassLabel, which correspond to the 3
  arguments:
  
   * `num_classes`: create 0 to (num_classes-1) labels
   * `names`: a list of label strings
   * `names_file`: a file containing the list of labels.
  
  Note: On python2, the strings are encoded as utf-8.
  
  Args:
    num_classes: `int`, number of classes. All labels must be < num_classes.
    names: `list<str>`, string names for the integer classes. The order in
      which the names are provided is kept.
    names_file: `str`, path to a file with names for the integer classes, one
      per line.
    doc: Documentation of this feature (e.g. description).
docstr_tok: ["Constructs","a","ClassLabel","FeatureConnector",".","There","are","3","ways","to","define","a","ClassLabel",",","which","correspond","to","the","3","arguments",":","*","`","num_classes","`",":","create","0","to","(","num_classes-1",")","labels","*","`","names","`",":","a","list","of","label","strings","*","`","names_file","`",":","a","file","containing","the","list","of","labels",".","Note",":","On","python2",",","the","strings","are","encoded","as","utf-8",".","Args",":","num_classes",":","`","int","`",",","number","of","classes",".","All","labels","must","be","<","num_classes",".","names",":","`","list","<","str",">","`",",","string","names","for","the","integer","classes",".","The","order","in","which","the","names","are","provided","is","kept",".","names_file",":","`","str","`",",","path","to","a","file","with","names","for","the","integer","classes",",","one","per","line",".","doc",":","Documentation","of","this","feature","(","e.g",".","description",")","."]
code: def __init__(
      self,
      *,
      num_classes: Optional[int] = None,
      names=None,
      names_file: epath.Path | None = None,
      doc: feature_lib.DocArg = None,
  ):
      """Constructs a ClassLabel FeatureConnector.
  
      There are 3 ways to define a ClassLabel, which correspond to the 3
      arguments:
  
       * `num_classes`: create 0 to (num_classes-1) labels
       * `names`: a list of label strings
       * `names_file`: a file containing the list of labels.
  
      Note: On python2, the strings are encoded as utf-8.
  
      Args:
        num_classes: `int`, number of classes. All labels must be < num_classes.
        names: `list<str>`, string names for the integer classes. The order in
          which the names are provided is kept.
        names_file: `str`, path to a file with names for the integer classes, one
          per line.
        doc: Documentation of this feature (e.g. description).
      """
      super(ClassLabel, self).__init__(
          shape=(), dtype=np.int64, doc=doc
      )
  
      self._num_classes: Optional[int] = None
      self._str2int: Optional[dict[str, int]] = None
      self._int2str: Optional[list[str]] = None
  
      # The label is explicitly set as undefined (no label defined)
      if all(a is None for a in (num_classes, names, names_file)):
          return
  
      if (
          sum(a is not None for a in (num_classes, names, names_file))
          != 1
      ):
          raise ValueError(
              "Only a single argument of ClassLabel() should be provided."
          )
  
      if num_classes is not None:
          self._num_classes = num_classes
      elif names is not None:
          self.names = names
      elif names_file is not None:
          self.names = _load_names_from_file(epath.Path(names_file))
  
imports: from typing import Optional, Union
  from etils import epath
  import numpy
  from tensorflow_datasets.core.features import feature
  from tensorflow_datasets.core.features import tensor_feature
  from tensorflow_datasets.core.proto import feature_pb2
  from tensorflow_datasets.core.utils import type_utils
label_desc: Use image node_id 1 to create a new ClassLabel object from inherited base classes: tensor_feature with example: obj = ClassLabel()