class_docstr: A mixin for putting Python state in an object-based checkpoint.
  
  This is an abstract class which allows extensions to TensorFlow's object-based
  checkpointing (see `tf.train.Checkpoint`). For example a wrapper for NumPy
  arrays:
  
  ```python
  import io
  import numpy
  
  class NumpyWrapper(tf.train.experimental.PythonState):
  
    def __init__(self, array):
      self.array = array
  
    def serialize(self):
      string_file = io.BytesIO()
      try:
        numpy.save(string_file, self.array, allow_pickle=False)
        serialized = string_file.getvalue()
      finally:
        string_file.close()
      return serialized
  
    def deserialize(self, string_value):
      string_file = io.BytesIO(string_value)
      try:
        self.array = numpy.load(string_file, allow_pickle=False)
      finally:
        string_file.close()
  ```
  
  Instances of `NumpyWrapper` are checkpointable objects, and will be saved and
  restored from checkpoints along with TensorFlow state like variables.
  
  ```python
  root = tf.train.Checkpoint(numpy=NumpyWrapper(numpy.array([1.])))
  save_path = root.save(prefix)
  root.numpy.array *= 2.
  assert [2.] == root.numpy.array
  root.restore(save_path)
  assert [1.] == root.numpy.array
  ```
class_docstr_tok: ["A","mixin","for","putting","Python","state","in","an","object-based","checkpoint",".","This","is","an","abstract","class","which","allows","extensions","to","TensorFlow","'s","object-based","checkpointing","(","see","`","tf.train.Checkpoint","`",")",".","For","example","a","wrapper","for","NumPy","arrays",":","``","`","python","import","io","import","numpy","class","NumpyWrapper","(","tf.train.experimental.PythonState",")",":","def","__init__","(","self",",","array",")",":","self.array","=","array","def","serialize","(","self",")",":","string_file","=","io.BytesIO","(",")","try",":","numpy.save","(","string_file",",","self.array",",","allow_pickle=False",")","serialized","=","string_file.getvalue","(",")","finally",":","string_file.close","(",")","return","serialized","def","deserialize","(","self",",","string_value",")",":","string_file","=","io.BytesIO","(","string_value",")","try",":","self.array","=","numpy.load","(","string_file",",","allow_pickle=False",")","finally",":","string_file.close","(",")","``","`","Instances","of","`","NumpyWrapper","`","are","checkpointable","objects",",","and","will","be","saved","and","restored","from","checkpoints","along","with","TensorFlow","state","like","variables",".","``","`","python","root","=","tf.train.Checkpoint","(","numpy=NumpyWrapper","(","numpy.array","(","[","1",".","]",")",")",")","save_path","=","root.save","(","prefix",")","root.numpy.array","*","=","2.","assert","[","2",".","]","==","root.numpy.array","root.restore","(","save_path",")","assert","[","1",".","]","==","root.numpy.array","``","`"]
docstr: Implements Trackable._serialize_to_tensors.
docstr_tok: ["Implements","Trackable._serialize_to_tensors","."]
code: def _serialize_to_tensors(self):
      """Implements Trackable._serialize_to_tensors."""
      with ops.init_scope():
          value = constant_op.constant(
              self.serialize(), dtype=dtypes.string
          )
      return {PYTHON_STATE: value}
  
file_path: tensorflow-upstream/tensorflow/python/trackable/python_state.py
imports: import abc
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.trackable import base
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 3 for calling the PythonState obj's underlying member method code with example usage: obj._serialize_to_tensors() and returns: dict