예제 #1
0
  def initialize(self, table):
    """Initializes the given `table` with `keys` and `values` tensors.

    Args:
      table: The table to initialize.

    Returns:
      The operation that initializes the table.

    Raises:
      TypeError: when the keys and values data types do not match the table
      key and value data types.
    """
    _check_table_dtypes(table, self._keys.dtype, self._values.dtype)
    with ops.name_scope(
        self._name, values=(table.resource_handle, self._keys,
                            self._values)) as scope:
      if context.executing_eagerly():
        # Ensure a unique name when eager execution is enabled to avoid spurious
        # sharing issues.
        scope += str(ops.uid())
      if fwd_compat.forward_compatible(2018, 9, 19):
        init_op = gen_lookup_ops.lookup_table_import_v2(
            table.resource_handle, self._keys, self._values, name=scope)
      else:
        # To maintain forward compatibiltiy, use the old implementation.
        init_op = gen_lookup_ops.initialize_table_v2(
            table.resource_handle, self._keys, self._values, name=scope)
    ops.add_to_collection(ops.GraphKeys.TABLE_INITIALIZERS, init_op)
    return init_op
 def restore(self, restored_tensors, restored_shapes):
     del restored_shapes  # unused
     # pylint: disable=protected-access
     with ops.colocate_with(self.op.resource_handle):
         return gen_lookup_ops.lookup_table_import_v2(
             self.op.resource_handle, restored_tensors[0],
             restored_tensors[1])
예제 #3
0
  def initialize(self, table):
    """Initializes the given `table` with `keys` and `values` tensors.

    Args:
      table: The table to initialize.

    Returns:
      The operation that initializes the table.

    Raises:
      TypeError: when the keys and values data types do not match the table
      key and value data types.
    """
    _check_table_dtypes(table, self._keys.dtype, self._values.dtype)
    with ops.name_scope(
        self._name, values=(table.resource_handle, self._keys,
                            self._values)) as scope:
      if context.executing_eagerly():
        # Ensure a unique name when eager execution is enabled to avoid spurious
        # sharing issues.
        scope += str(ops.uid())
      if fwd_compat.forward_compatible(2018, 9, 19):
        init_op = gen_lookup_ops.lookup_table_import_v2(
            table.resource_handle, self._keys, self._values, name=scope)
      else:
        # To maintain forward compatibiltiy, use the old implementation.
        init_op = gen_lookup_ops.initialize_table_v2(
            table.resource_handle, self._keys, self._values, name=scope)
    ops.add_to_collection(ops.GraphKeys.TABLE_INITIALIZERS, init_op)
    return init_op
예제 #4
0
 def restore(self, restore_tensors, shapes):
     return gen_lookup_ops.lookup_table_import_v2(
         self.op.table_ref, restore_tensors[0], restore_tensors[1])
예제 #5
0
 def restore(self, restore_tensors, shapes):
   return gen_lookup_ops.lookup_table_import_v2(
       self.op.table_ref, restore_tensors[0], restore_tensors[1])
예제 #6
0
 def restore(self, restored_tensors, restored_shapes):
   del restored_shapes  # unused
   # pylint: disable=protected-access
   with ops.colocate_with(self.op._table_ref):
     return gen_lookup_ops.lookup_table_import_v2(
         self.op._table_ref, restored_tensors[0], restored_tensors[1])
예제 #7
0
 def restore(self, restored_tensors, unused_restored_shapes):
   # pylint: disable=protected-access
   with ops.colocate_with(self.op._table_ref):
     return gen_lookup_ops.lookup_table_import_v2(
         self.op._table_ref, restored_tensors[0], restored_tensors[1])