class_docstr: Representative dataset saver in TFRecord format.
  
  Saves representative datasets for quantization calibration in TFRecord format.
  The samples are serialized as `RepresentativeDataSample`.
  
  The `save` method return a signature key to `RepresentativeDatasetFile` map,
  which can be used for QuantizationOptions.
  
  Example usage:
  
  ```python
  # Creating the representative dataset.
  representative_dataset = [{"input": tf.random.uniform(shape=(3, 3))}
                        for _ in range(256)]
  
  # Saving to a TFRecord file.
  dataset_file_map = (
    tf.quantization.experimental.TfRecordRepresentativeDatasetSaver(
          path_map={'serving_default': '/tmp/representative_dataset_path'}
      ).save({'serving_default': representative_dataset})
  )
  
  # Using in QuantizationOptions.
  quantization_options = tf.quantization.experimental.QuantizationOptions(
      signature_keys=['serving_default'],
      representative_datasets=dataset_file_map,
  )
  tf.quantization.experimental.quantize_saved_model(
      '/tmp/input_model',
      '/tmp/output_model',
      quantization_options=quantization_options,
  )
  ```
class_docstr_tok: ["Representative","dataset","saver","in","TFRecord","format",".","Saves","representative","datasets","for","quantization","calibration","in","TFRecord","format",".","The","samples","are","serialized","as","`","RepresentativeDataSample","`",".","The","`","save","`","method","return","a","signature","key","to","`","RepresentativeDatasetFile","`","map",",","which","can","be","used","for","QuantizationOptions",".","Example","usage",":","``","`","python","#","Creating","the","representative","dataset",".","representative_dataset","=","[","{","``","input","''",":","tf.random.uniform","(","shape=","(","3",",","3",")",")","}","for","_","in","range","(","256",")","]","#","Saving","to","a","TFRecord","file",".","dataset_file_map","=","(","tf.quantization.experimental.TfRecordRepresentativeDatasetSaver","(","path_map=","{","'serving_default","'",":","'\/tmp\/representative_dataset_path","'","}",")",".save","(","{","'serving_default","'",":","representative_dataset","}",")",")","#","Using","in","QuantizationOptions",".","quantization_options","=","tf.quantization.experimental.QuantizationOptions","(","signature_keys=","[","'serving_default","'","]",",","representative_datasets=dataset_file_map",",",")","tf.quantization.experimental.quantize_saved_model","(","'\/tmp\/input_model","'",",","'\/tmp\/output_model","'",",","quantization_options=quantization_options",",",")","``","`"]
docstr: Saves `repr_ds` to a TFRecord file.
  
  Each sample in `repr_ds` is serialized as `RepresentativeDataSample`.
  
  Args:
    repr_ds: `RepresentativeDataset` to save.
    signature_def_key: The signature def key associated with `repr_ds`.
  
  Returns:
    a RepresentativeDatasetFile instance contains the path to the saved file.
docstr_tok: ["Saves","`","repr_ds","`","to","a","TFRecord","file",".","Each","sample","in","`","repr_ds","`","is","serialized","as","`","RepresentativeDataSample","`",".","Args",":","repr_ds",":","`","RepresentativeDataset","`","to","save",".","signature_def_key",":","The","signature","def","key","associated","with","`","repr_ds","`",".","Returns",":","a","RepresentativeDatasetFile","instance","contains","the","path","to","the","saved","file","."]
code: def _save_tf_record_dataset(
      self,
      repr_ds: RepresentativeDataset,
      signature_def_key: str,
  ) -> _RepresentativeDatasetFile:
      """Saves `repr_ds` to a TFRecord file.
  
      Each sample in `repr_ds` is serialized as `RepresentativeDataSample`.
  
      Args:
        repr_ds: `RepresentativeDataset` to save.
        signature_def_key: The signature def key associated with `repr_ds`.
  
      Returns:
        a RepresentativeDatasetFile instance contains the path to the saved file.
      """
      tfrecord_file_path = self.path_map[signature_def_key]
      with python_io.TFRecordWriter(tfrecord_file_path) as writer:
          for repr_sample in repr_ds:
              sample = _RepresentativeDataSample()
              for input_name, input_value in repr_sample.items():
                  sample.tensor_proto_inputs[input_name].CopyFrom(
                      tensor_util.make_tensor_proto(input_value)
                  )
  
              writer.write(sample.SerializeToString())
  
      logging.info(
          "Saved representative dataset for signature def: %s to: %s",
          signature_def_key,
          tfrecord_file_path,
      )
      return _RepresentativeDatasetFile(
          tfrecord_file_path=str(tfrecord_file_path)
      )
  
imports: import collections.abc
  import os
  from typing import Iterable, Mapping, Optional, Union
  import numpy
  from tensorflow.compiler.mlir.quantization.tensorflow import quantization_options_pb2
  from tensorflow.core.protobuf import meta_graph_pb2
  from tensorflow.python.client import session
  from tensorflow.python.data.ops import readers
  from tensorflow.python.eager import context
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.lib.io import python_io
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.types import core
  from tensorflow.python.util import tf_export
label_desc: Use image node_id 2 for calling the TfRecordRepresentativeDatasetSaver obj's underlying member method code with example usage: obj._save_tf_record_dataset(repr_ds, signature_def_key) and returns: _RepresentativeDatasetFile