code: def _feature_from_feature_spec(spec, name, domains):
      """Returns a representation of a Feature from a feature spec."""
      if isinstance(spec, tf.io.FixedLenFeature):
          if spec.default_value is not None:
              raise ValueError(
                  'feature "{}" had default_value {}, but FixedLenFeature must have '
                  "default_value=None".format(name, spec.default_value)
              )
          dims = [
              schema_pb2.FixedShape.Dim(size=size)
              for size in spec.shape
          ]
          feature = schema_pb2.Feature(
              name=name,
              presence=schema_pb2.FeaturePresence(min_fraction=1.0),
              shape=schema_pb2.FixedShape(dim=dims),
          )
      elif isinstance(spec, tf.io.VarLenFeature):
          feature = schema_pb2.Feature(name=name)
      else:
          raise TypeError(
              'Spec for feature "{}" was {} of type {}, expected a '
              "FixedLenFeature, VarLenFeature or SparseFeature".format(
                  name, spec, type(spec)
              )
          )
  
      _set_type(name, feature, spec.dtype)
      _set_domain(name, feature, domains.get(name))
      return feature
  
imports: import dataclasses
  import typing
  from typing import Dict, List, Mapping, Optional, Tuple, Union
  import tensorflow
  from tensorflow_transform import common_types
  from tensorflow_transform.tf_metadata import schema_utils_legacy
  from tfx_bsl.tfxio import tensor_representation_util
  from tensorflow_metadata.proto.v0 import path_pb2
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 4 for calling a global function with example usage: _feature_from_feature_spec(spec, name, domains) and returns: feature