示例#1
0
def fertile_stats_variable(params, stats_config, name, container=None):
    r"""Creates a stats object and returns a handle to it.

  Args:
    params: A TensorForestParams object.
    stats_config: A `Tensor` of type `string`. Serialized proto of the stats.
    name: A name for the variable.
    container: An optional `string`. Defaults to `""`.

  Returns:
    A `Tensor` of type mutable `string`. The handle to the stats.
  """
    with ops.name_scope(name, "FertileStatsVariable") as name:
        resource_handle = gen_stats_ops.fertile_stats_resource_handle_op(
            container, shared_name=name, name=name)

        create_op = gen_stats_ops.create_fertile_stats_variable(
            resource_handle,
            stats_config,
            params=params.serialized_params_proto)
        is_initialized_op = gen_stats_ops.fertile_stats_is_initialized_op(
            resource_handle)
        # Adds the variable to the savable list.
        saveable = FertileStatsVariableSavable(params, resource_handle,
                                               create_op, resource_handle.name)
        ops.add_to_collection(ops.GraphKeys.SAVEABLE_OBJECTS, saveable)
        resources.register_resource(resource_handle, create_op,
                                    is_initialized_op)
        return resource_handle
示例#2
0
def fertile_stats_variable(params, stats_config, name,
                           container=None):
  r"""Creates a stats object and returns a handle to it.

  Args:
    params: A TensorForestParams object.
    stats_config: A `Tensor` of type `string`. Serialized proto of the stats.
    name: A name for the variable.
    container: An optional `string`. Defaults to `""`.

  Returns:
    A `Tensor` of type mutable `string`. The handle to the stats.
  """
  with ops.name_scope(name, "FertileStatsVariable") as name:
    resource_handle = gen_stats_ops.fertile_stats_resource_handle_op(
        container, shared_name=name, name=name)

    create_op = gen_stats_ops.create_fertile_stats_variable(
        resource_handle, stats_config,
        params=params.serialized_params_proto)
    is_initialized_op = gen_stats_ops.fertile_stats_is_initialized_op(
        resource_handle)
    # Adds the variable to the savable list.
    saveable = FertileStatsVariableSavable(params, resource_handle, create_op,
                                           resource_handle.name)
    ops.add_to_collection(ops.GraphKeys.SAVEABLE_OBJECTS, saveable)
    resources.register_resource(resource_handle, create_op, is_initialized_op)
    return resource_handle
示例#3
0
 def create_resource(self):
   if context.executing_eagerly():
     # TODO(allenl): This will leak memory due to kernel caching by the
     # shared_name attribute value (but is better than the alternative of
     # sharing everything by default when executing eagerly; hopefully creating
     # tables in a loop is uncommon).
     shared_name = "fertile_stats_variable_%d" % (ops.uid(),)
   else:
     shared_name = self._name
   return gen_stats_ops.fertile_stats_resource_handle_op(
       self._container, shared_name=shared_name, name=self._name)