コード例 #1
0
ファイル: gen_image_ops.py プロジェクト: whqkdhfh13/sswp
def image_projective_transform(images, transforms, interpolation, name=None):
  r"""Applies the given transform to each of the images.

  Input `image` is a `Tensor` in NHWC format (where the axes are image in batch,
  rows, columns, and channels. Input `transforms` is a num_images x 8 or 1 x 8
  matrix, where each row corresponds to a 3 x 3 projective transformation matrix,
  with the last entry assumed to be 1. If there is one row, the same
  transformation will be applied to all images.

  If one row of `transforms` is `[a0, a1, a2, b0, b1, b2, c0, c1]`, then it maps
  the *output* point `(x, y)` to a transformed *input* point
  `(x', y') = ((a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k)`, where
  `k = c0 x + c1 y + 1`. If the transformed point lays outside of the input
  image, the output pixel is set to 0.

  Args:
    images: A `Tensor`. Must be one of the following types: `uint8`, `int32`, `int64`, `half`, `float32`, `float64`.
      4D `Tensor`, input image(s) in NHWC format.
    transforms: A `Tensor` of type `float32`.
      2D `Tensor`, projective transform(s) to apply to the image(s).
    interpolation: A `string`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `images`.
    4D `Tensor`, image(s) in NHWC format, generated by applying
    the `transforms` to the `images`. Satisfies the description above.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    interpolation = _execute.make_str(interpolation, "interpolation")
    _, _, _op = _op_def_lib._apply_op_helper(
        "ImageProjectiveTransform", images=images, transforms=transforms,
        interpolation=interpolation, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("dtype", _op.get_attr("dtype"), "interpolation",
              _op.get_attr("interpolation"))
    _execute.record_gradient(
      "ImageProjectiveTransform", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "ImageProjectiveTransform", name, _ctx._post_execution_callbacks,
        images, transforms, "interpolation", interpolation)
      return _result
    except _core._FallbackException:
      return image_projective_transform_eager_fallback(
          images, transforms, interpolation=interpolation, name=name,
          ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #2
0
ファイル: gen_dataset_ops.py プロジェクト: whqkdhfh13/sswp
def ignite_dataset(cache_name, host, port, local, part, page_size, schema, permutation, name=None):
  r"""IgniteDataset that allows to get data from Apache Ignite.

  Apache Ignite is a memory-centric distributed database, caching, and processing
  platform for transactional, analytical, and streaming workloads, delivering
  in-memory speeds at petabyte scale. This contrib package contains an
  integration between Apache Ignite and TensorFlow. The integration is based on
  tf.data from TensorFlow side and Binary Client Protocol from Apache Ignite side.
  It allows to use Apache Ignite as a datasource for neural network training,
  inference and all other computations supported by TensorFlow. Ignite Dataset
  is based on Apache Ignite Binary Client Protocol.

  Args:
    cache_name: A `Tensor` of type `string`. Ignite Cache Name.
    host: A `Tensor` of type `string`. Ignite Thin Client Host.
    port: A `Tensor` of type `int32`. Ignite Thin Client Port.
    local: A `Tensor` of type `bool`.
      Local flag that defines that data should be fetched from local host only.
    part: A `Tensor` of type `int32`. Partition data should be fetched from.
    page_size: A `Tensor` of type `int32`. Page size for Ignite Thin Client.
    schema: A `Tensor` of type `int32`.
      Internal structure that defines schema of cache objects.
    permutation: A `Tensor` of type `int32`.
      Internal structure that defines permutation of cache objects.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `variant`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "IgniteDataset", cache_name=cache_name, host=host, port=port,
        local=local, part=part, page_size=page_size, schema=schema,
        permutation=permutation, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "IgniteDataset", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "IgniteDataset", name, _ctx._post_execution_callbacks, cache_name,
        host, port, local, part, page_size, schema, permutation)
      return _result
    except _core._FallbackException:
      return ignite_dataset_eager_fallback(
          cache_name, host, port, local, part, page_size, schema, permutation,
          name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #3
0
ファイル: execute.py プロジェクト: keveman/tensorflow
def execute(op_name, num_outputs, inputs, attrs=None, name=None):
  """Execute a TensorFlow operation.

  Args:
    op_name: Name of the TensorFlow operation (see REGISTER_OP in C++ code) to
      execute.
    num_outputs: The number of outputs of the operation to fetch.
                 (Explicitly provided instead of being inferred for performance
                 reasons).
    inputs: A list of inputs to the operation. Each entry should be a Tensor, or
      a value which can be passed to the Tensor constructor to create one.
    attrs: A tuple with alternating string attr names and attr values for this
      operation.
    name: Customized name for the operation.

  Returns:
    None if there are no outputs, a single Tensor object if there is one output
    and a list of Tensor objects if there are multiple outputs.

  Raises:
    An exception on error.
  """
  ctx = context.get_default_context()
  # TODO(apassos) move this to convert_to_tensor
  inputs = [ag_core.getval(x) for x in inputs]
  # pylint: disable=protected-access
  input_handles = [c._handle for c in inputs]
  device_name = ctx.device_name
  try:
    outh = pywrap_tensorflow.TFE_Py_Execute(ctx._handle, device_name,
                                            str(op_name), input_handles, attrs,
                                            num_outputs)
    # pylint: enable=protected-access
  except core._NotOkStatusException as e:  # pylint: disable=protected-access
    if name is not None:
      message = e.message + " name: " + name
    else:
      message = e.message
    raise core._status_to_exception(e.code, message)  # pylint: disable=protected-access
  # pylint: enable=protected-access

  tensors = [tensor._tensor_from_handle(x) for x in outh]  # pylint: disable=protected-access
  # TODO(alive, cais): Use the execution callback mechanism.
  if core.active_trace() is not None:
    trace_name = name if name else op_name
    for t in tensors:
      # pylint: disable=protected-access
      core.active_trace().record_tensor(trace_name,
                                        ops.tensor_id(t),
                                        t._device_name(),
                                        t.shape.num_elements())
      # pylint: enable=protected-access

  # TODO(cais): Optimize this, perhaps by replacing this execute function with
  # a different one when there are execution callback(s).
  for callback in ctx.post_execution_callbacks:
    callback(op_name, name, attrs, inputs, tensors)

  return tensors
コード例 #4
0
ファイル: xla_ops.py プロジェクト: whqkdhfh13/sswp
def xla_launch(constants, args, resources, Tresults, function, name=None):
  r"""XLA Launch Op. For use by the XLA JIT only.

  Args:
    constants: A list of `Tensor` objects.
    args: A list of `Tensor` objects.
    resources: A list of `Tensor` objects with type `resource`.
    Tresults: A list of `tf.DTypes`.
    function: A function decorated with @Defun.
    name: A name for the operation (optional).

  Returns:
    A list of `Tensor` objects of type `Tresults`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    if not isinstance(resources, (list, tuple)):
      raise TypeError(
          "Expected list for 'resources' argument to "
          "'xla_launch' Op, not %r." % resources)
    _attr_Nresources = len(resources)
    if not isinstance(Tresults, (list, tuple)):
      raise TypeError(
          "Expected list for 'Tresults' argument to "
          "'xla_launch' Op, not %r." % Tresults)
    Tresults = [_execute.make_type(_t, "Tresults") for _t in Tresults]
    _, _, _op = _op_def_lib._apply_op_helper(
        "XlaLaunch", constants=constants, args=args, resources=resources,
        Tresults=Tresults, function=function, name=name)
    _result = _op.outputs[:]
    if not _result:
      return _op
    _inputs_flat = _op.inputs
    _attrs = ("Tconstants", _op.get_attr("Tconstants"), "Targs",
              _op.get_attr("Targs"), "Nresources", _op.get_attr("Nresources"),
              "Tresults", _op.get_attr("Tresults"), "function",
              _op.get_attr("function"))
    _execute.record_gradient(
      "XlaLaunch", _inputs_flat, _attrs, _result, name)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name, "XlaLaunch",
        name, _ctx._post_execution_callbacks, constants, args, resources,
        "Tresults", Tresults, "function", function)
      return _result
    except _core._FallbackException:
      return xla_launch_eager_fallback(
          constants, args, resources, Tresults=Tresults, function=function,
          name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #5
0
ファイル: gen_clustering_ops.py プロジェクト: whqkdhfh13/sswp
def kmeans_plus_plus_initialization(points, num_to_sample, seed, num_retries_per_sample, name=None):
  r"""Selects num_to_sample rows of input using the KMeans++ criterion.

  Rows of points are assumed to be input points. One row is selected at random.
  Subsequent rows are sampled with probability proportional to the squared L2
  distance from the nearest row selected thus far till num_to_sample rows have
  been sampled.

  Args:
    points: A `Tensor` of type `float32`.
      Matrix of shape (n, d). Rows are assumed to be input points.
    num_to_sample: A `Tensor` of type `int64`.
      Scalar. The number of rows to sample. This value must not be
      larger than n.
    seed: A `Tensor` of type `int64`.
      Scalar. Seed for initializing the random number generator.
    num_retries_per_sample: A `Tensor` of type `int64`.
      Scalar. For each row that is sampled, this parameter
      specifies the number of additional points to draw from the current
      distribution before selecting the best. If a negative value is specified, a
      heuristic is used to sample O(log(num_to_sample)) additional points.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `float32`.
    Matrix of shape (num_to_sample, d). The sampled rows.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "KmeansPlusPlusInitialization", points=points,
        num_to_sample=num_to_sample, seed=seed,
        num_retries_per_sample=num_retries_per_sample, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "KmeansPlusPlusInitialization", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "KmeansPlusPlusInitialization", name, _ctx._post_execution_callbacks,
        points, num_to_sample, seed, num_retries_per_sample)
      return _result
    except _core._FallbackException:
      return kmeans_plus_plus_initialization_eager_fallback(
          points, num_to_sample, seed, num_retries_per_sample, name=name,
          ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #6
0
ファイル: gen_coder_ops.py プロジェクト: whqkdhfh13/sswp
def range_decode(encoded, shape, cdf, precision, name=None):
  r"""Decodes a range-coded `code` into an int32 tensor of shape `shape`.

  This is the reverse op of RangeEncode. The shape of the tensor that was encoded
  should be known by the caller.

  Implementation notes:

  - If wrong input was given (e.g., corrupt `encoded` string, or `cdf` or
  `precision` do not match encoder), the decode is unsuccessful. Because of
  potential performance issues, the decoder does not return error status.

  Args:
    encoded: A `Tensor` of type `string`.
      A scalar string tensor from RangeEncode.
    shape: A `Tensor` of type `int32`.
      An int32 1-D tensor representing the shape of the data encoded by
      RangeEncode.
    cdf: A `Tensor` of type `int32`.
    precision: An `int` that is `>= 1`.
      The number of bits for probability quantization. Must be <= 16, and
      must match the precision used by RangeEncode that produced `encoded`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int16`. An int16 tensor with shape equal to `shape`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    precision = _execute.make_int(precision, "precision")
    _, _, _op = _op_def_lib._apply_op_helper(
        "RangeDecode", encoded=encoded, shape=shape, cdf=cdf,
        precision=precision, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("precision", _op.get_attr("precision"))
    _execute.record_gradient(
      "RangeDecode", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name, "RangeDecode",
        name, _ctx._post_execution_callbacks, encoded, shape, cdf,
        "precision", precision)
      return _result
    except _core._FallbackException:
      return range_decode_eager_fallback(
          encoded, shape, cdf, precision=precision, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #7
0
ファイル: gen_clustering_ops.py プロジェクト: whqkdhfh13/sswp
def nearest_neighbors(points, centers, k, name=None):
  r"""Selects the k nearest centers for each point.

  Rows of points are assumed to be input points. Rows of centers are assumed to be
  the list of candidate centers. For each point, the k centers that have least L2
  distance to it are computed.

  Args:
    points: A `Tensor` of type `float32`.
      Matrix of shape (n, d). Rows are assumed to be input points.
    centers: A `Tensor` of type `float32`.
      Matrix of shape (m, d). Rows are assumed to be centers.
    k: A `Tensor` of type `int64`.
      Scalar. Number of nearest centers to return for each point. If k is larger
      than m, then only m centers are returned.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (nearest_center_indices, nearest_center_distances).

    nearest_center_indices: A `Tensor` of type `int64`. Matrix of shape (n, min(m, k)). Each row contains the
      indices of the centers closest to the corresponding point, ordered by
      increasing distance.
    nearest_center_distances: A `Tensor` of type `float32`. Matrix of shape (n, min(m, k)). Each row contains the
      squared L2 distance to the corresponding center in nearest_center_indices.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "NearestNeighbors", points=points, centers=centers, k=k, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "NearestNeighbors", _inputs_flat, _attrs, _result, name)
    _result = _NearestNeighborsOutput._make(_result)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "NearestNeighbors", name, _ctx._post_execution_callbacks, points,
        centers, k)
      _result = _NearestNeighborsOutput._make(_result)
      return _result
    except _core._FallbackException:
      return nearest_neighbors_eager_fallback(
          points, centers, k, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #8
0
def _create_tensor(value, device=None, dtype=None):
  ctx = context.context()
  if device is None:
    device = ctx.device_name
  if dtype is not None:
    dtype = dtype.as_datatype_enum
  try:
    return ops.EagerTensor(
        value, context=ctx._handle, device=device, dtype=dtype)
  except core._NotOkStatusException as e:  # pylint: disable=protected-access
    raise core._status_to_exception(e.code, e.message)
コード例 #9
0
ファイル: gen_image_ops.py プロジェクト: whqkdhfh13/sswp
def image_connected_components(image, name=None):
  r"""Find the connected components of image(s).

  For each image (along the 0th axis), all connected components of adjacent pixels
  with the same non-zero value are detected and given unique ids.

  The returned `components` tensor has 0s for the zero pixels of `images`, and
  arbitrary nonzero ids for the connected components of nonzero values. Ids are
  unique across all of the images, and are in row-major order by the first pixel
  in the component.

  Uses union-find with union by rank but not path compression, giving a runtime of
  `O(n log n)`. See:
      https://en.wikipedia.org/wiki/Disjoint-set_data_structure#Time_Complexity

  Args:
    image: A `Tensor`. Must be one of the following types: `int64`, `int32`, `uint16`, `int16`, `uint8`, `int8`, `half`, `float32`, `float64`, `bool`, `string`.
      Image(s) with shape (N, H, W).
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int64`.
    Component ids for each pixel in "image". Same shape as "image". Zero
    pixels all have an output of 0, and all components of adjacent pixels with
    the same value are given consecutive ids, starting from 1.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "ImageConnectedComponents", image=image, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("dtype", _op.get_attr("dtype"))
    _execute.record_gradient(
      "ImageConnectedComponents", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "ImageConnectedComponents", name, _ctx._post_execution_callbacks,
        image)
      return _result
    except _core._FallbackException:
      return image_connected_components_eager_fallback(
          image, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #10
0
ファイル: gen_model_ops.py プロジェクト: whqkdhfh13/sswp
def tree_ensemble_used_handlers(tree_ensemble_handle, stamp_token, num_all_handlers, name=None):
  r"""Returns the mask of used handlers along with the number of non-zero elements in

  this mask. Used in feature selection.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
      Handle to the tree ensemble.
    stamp_token: A `Tensor` of type `int64`.
      Token to use as the new value of the resource stamp.
    num_all_handlers: An `int` that is `>= 0`.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (num_used_handlers, used_handlers_mask).

    num_used_handlers: A `Tensor` of type `int64`. number of feature column handlers used in the model.
    used_handlers_mask: A `Tensor` of type `bool`. A boolean vector of showing which handlers are used in the
      model.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    num_all_handlers = _execute.make_int(num_all_handlers, "num_all_handlers")
    _, _, _op = _op_def_lib._apply_op_helper(
        "TreeEnsembleUsedHandlers", tree_ensemble_handle=tree_ensemble_handle,
        stamp_token=stamp_token, num_all_handlers=num_all_handlers, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("num_all_handlers", _op.get_attr("num_all_handlers"))
    _execute.record_gradient(
      "TreeEnsembleUsedHandlers", _inputs_flat, _attrs, _result, name)
    _result = _TreeEnsembleUsedHandlersOutput._make(_result)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "TreeEnsembleUsedHandlers", name, _ctx._post_execution_callbacks,
        tree_ensemble_handle, stamp_token, "num_all_handlers",
        num_all_handlers)
      _result = _TreeEnsembleUsedHandlersOutput._make(_result)
      return _result
    except _core._FallbackException:
      return tree_ensemble_used_handlers_eager_fallback(
          tree_ensemble_handle, stamp_token,
          num_all_handlers=num_all_handlers, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #11
0
ファイル: gen_coder_ops.py プロジェクト: whqkdhfh13/sswp
def pmf_to_quantized_cdf(pmf, precision, name=None):
  r"""Converts PMF to quantized CDF. This op uses floating-point operations

  internally. Therefore the quantized output may not be consistent across multiple
  platforms. For entropy encoders and decoders to have the same quantized CDF on
  different platforms, the quantized CDF should be produced once and saved, then
  the saved quantized CDF should be used everywhere.

  After quantization, if PMF does not sum to 2^precision, then some values of PMF
  are increased or decreased to adjust the sum to equal to 2^precision.

  Note that the input PMF is pre-quantization. The input PMF is not normalized
  by this op prior to quantization. Therefore the user is responsible for
  normalizing PMF if necessary.

  Args:
    pmf: A `Tensor` of type `float32`.
    precision: An `int` that is `>= 1`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int32`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    precision = _execute.make_int(precision, "precision")
    _, _, _op = _op_def_lib._apply_op_helper(
        "PmfToQuantizedCdf", pmf=pmf, precision=precision, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("precision", _op.get_attr("precision"))
    _execute.record_gradient(
      "PmfToQuantizedCdf", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "PmfToQuantizedCdf", name, _ctx._post_execution_callbacks, pmf,
        "precision", precision)
      return _result
    except _core._FallbackException:
      return pmf_to_quantized_cdf_eager_fallback(
          pmf, precision=precision, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #12
0
ファイル: gen_training_ops.py プロジェクト: whqkdhfh13/sswp
def tree_ensemble_stats(tree_ensemble_handle, stamp_token, name=None):
  r"""Retrieves stats related to the tree ensemble.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
      Handle to the ensemble variable.
    stamp_token: A `Tensor` of type `int64`.
      Stamp token for validating operation consistency.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (num_trees, num_layers, active_tree, active_layer, attempted_trees, attempted_layers).

    num_trees: A `Tensor` of type `int64`. Scalar indicating the number of finalized trees in the ensemble.
    num_layers: A `Tensor` of type `int64`. Scalar indicating the number of layers in the ensemble.
    active_tree: A `Tensor` of type `int64`. Scalar indicating the active tree being trained.
    active_layer: A `Tensor` of type `int64`. Scalar indicating the active layer being trained.
    attempted_trees: A `Tensor` of type `int64`.
    attempted_layers: A `Tensor` of type `int64`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "TreeEnsembleStats", tree_ensemble_handle=tree_ensemble_handle,
        stamp_token=stamp_token, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "TreeEnsembleStats", _inputs_flat, _attrs, _result, name)
    _result = _TreeEnsembleStatsOutput._make(_result)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "TreeEnsembleStats", name, _ctx._post_execution_callbacks,
        tree_ensemble_handle, stamp_token)
      _result = _TreeEnsembleStatsOutput._make(_result)
      return _result
    except _core._FallbackException:
      return tree_ensemble_stats_eager_fallback(
          tree_ensemble_handle, stamp_token, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #13
0
ファイル: gen_model_ops.py プロジェクト: whqkdhfh13/sswp
def decision_tree_ensemble_resource_handle_op(container="", shared_name="", name=None):
  r"""TODO: add doc.

  Args:
    container: An optional `string`. Defaults to `""`.
    shared_name: An optional `string`. Defaults to `""`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `resource`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    if container is None:
      container = ""
    container = _execute.make_str(container, "container")
    if shared_name is None:
      shared_name = ""
    shared_name = _execute.make_str(shared_name, "shared_name")
    _, _, _op = _op_def_lib._apply_op_helper(
        "DecisionTreeEnsembleResourceHandleOp", container=container,
        shared_name=shared_name, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("container", _op.get_attr("container"), "shared_name",
              _op.get_attr("shared_name"))
    _execute.record_gradient(
      "DecisionTreeEnsembleResourceHandleOp", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "DecisionTreeEnsembleResourceHandleOp", name,
        _ctx._post_execution_callbacks, "container", container, "shared_name",
        shared_name)
      return _result
    except _core._FallbackException:
      return decision_tree_ensemble_resource_handle_op_eager_fallback(
          container=container, shared_name=shared_name, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #14
0
ファイル: gen_clustering_ops.py プロジェクト: whqkdhfh13/sswp
def kmc2_chain_initialization(distances, seed, name=None):
  r"""Returns the index of a data point that should be added to the seed set.

  Entries in distances are assumed to be squared distances of candidate points to
  the already sampled centers in the seed set. The op constructs one Markov chain
  of the k-MC^2 algorithm and returns the index of one candidate point to be added
  as an additional cluster center.

  Args:
    distances: A `Tensor` of type `float32`.
      Vector with squared distances to the closest previously sampled
      cluster center for each candidate point.
    seed: A `Tensor` of type `int64`.
      Scalar. Seed for initializing the random number generator.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int64`. Scalar with the index of the sampled point.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "KMC2ChainInitialization", distances=distances, seed=seed, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "KMC2ChainInitialization", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "KMC2ChainInitialization", name, _ctx._post_execution_callbacks,
        distances, seed)
      return _result
    except _core._FallbackException:
      return kmc2_chain_initialization_eager_fallback(
          distances, seed, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #15
0
ファイル: gen_variable_ops.py プロジェクト: whqkdhfh13/sswp
def zero_var_initializer(var, dtype, shape, name=None):
  r"""Initialize 'var' with all zeros. This op requires that the resource var is not

  initialized. The var will first be allocated memory, then be filled with all
  zeros. This op is intended to save memory during initialization,
  if you use this op, you should not run initializer of the var.

  Args:
    var: A `Tensor` of type `resource`. Should be a ResourceVariable.
    dtype: A `tf.DType`.
    shape: A `tf.TensorShape` or list of `ints`.
    name: A name for the operation (optional).

  Returns:
    Same as "var".
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    dtype = _execute.make_type(dtype, "dtype")
    shape = _execute.make_shape(shape, "shape")
    _, _, _op = _op_def_lib._apply_op_helper(
        "ZeroVarInitializer", var=var, dtype=dtype, shape=shape, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("dtype", _op.get_attr("dtype"), "shape", _op.get_attr("shape"))
    _execute.record_gradient(
      "ZeroVarInitializer", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "ZeroVarInitializer", name, _ctx._post_execution_callbacks, var,
        "dtype", dtype, "shape", shape)
      return _result
    except _core._FallbackException:
      return zero_var_initializer_eager_fallback(
          var, dtype=dtype, shape=shape, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #16
0
ファイル: execute.py プロジェクト: JonathanRaiman/tensorflow
def quick_execute(op_name, num_outputs, inputs, attrs, ctx, name=None):
  """Execute a TensorFlow operation.

  Args:
    op_name: Name of the TensorFlow operation (see REGISTER_OP in C++ code) to
      execute.
    num_outputs: The number of outputs of the operation to fetch.
                 (Explicitly provided instead of being inferred for performance
                 reasons).
    inputs: A list of inputs to the operation. Each entry should be a Tensor, or
      a value which can be passed to the Tensor constructor to create one.
    attrs: A tuple with alternating string attr names and attr values for this
      operation.
    ctx: The value of context.context().
    name: Customized name for the operation.

  Returns:
    List of output Tensor objects. The list is empty if there are no outputs

  Raises:
    An exception on error.
  """
  device_name = ctx.device_name
  # pylint: disable=protected-access
  try:
    tensors = pywrap_tensorflow.TFE_Py_Execute(ctx._handle, device_name,
                                               op_name, inputs, attrs,
                                               num_outputs)
  except core._NotOkStatusException as e:
    if name is not None:
      message = e.message + " name: " + name
    else:
      message = e.message
    six.raise_from(core._status_to_exception(e.code, message), None)
  except TypeError as e:
    if any(ops._is_keras_symbolic_tensor(x) for x in inputs):
      if any(isinstance(x, ops.EagerTensor) for x in inputs):
        raise TypeError("You are attempting to mix computation of symbolic "
                        "Tensors (computation rooted at tf.keras.Input()) "
                        "and concrete values. This is not supported. "
                        "If you need this support, file an issue on the "
                        "TensorFlow GitHub repository.")
      raise core._SymbolicException
    raise e
  # pylint: enable=protected-access
  return tensors
コード例 #17
0
ファイル: gen_model_ops.py プロジェクト: whqkdhfh13/sswp
def tree_ensemble_deserialize(tree_ensemble_handle, stamp_token, tree_ensemble_config, name=None):
  r"""Deserializes a serialized tree ensemble config and replaces current tree

  ensemble.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
      Handle to the tree ensemble.
    stamp_token: A `Tensor` of type `int64`.
      Token to use as the new value of the resource stamp.
    tree_ensemble_config: A `Tensor` of type `string`.
      Serialized proto of the ensemble.
    name: A name for the operation (optional).

  Returns:
    The created Operation.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "TreeEnsembleDeserialize", tree_ensemble_handle=tree_ensemble_handle,
        stamp_token=stamp_token, tree_ensemble_config=tree_ensemble_config,
        name=name)
    return _op
    _result = None
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "TreeEnsembleDeserialize", name, _ctx._post_execution_callbacks,
        tree_ensemble_handle, stamp_token, tree_ensemble_config)
      return _result
    except _core._FallbackException:
      return tree_ensemble_deserialize_eager_fallback(
          tree_ensemble_handle, stamp_token, tree_ensemble_config, name=name,
          ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #18
0
ファイル: gen_model_ops.py プロジェクト: whqkdhfh13/sswp
def tree_ensemble_serialize(tree_ensemble_handle, name=None):
  r"""Serializes the tree ensemble to a proto.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
      Handle to the tree ensemble.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (stamp_token, tree_ensemble_config).

    stamp_token: A `Tensor` of type `int64`. Stamp token of the tree ensemble resource.
    tree_ensemble_config: A `Tensor` of type `string`. Serialized proto of the ensemble.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "TreeEnsembleSerialize", tree_ensemble_handle=tree_ensemble_handle,
        name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "TreeEnsembleSerialize", _inputs_flat, _attrs, _result, name)
    _result = _TreeEnsembleSerializeOutput._make(_result)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "TreeEnsembleSerialize", name, _ctx._post_execution_callbacks,
        tree_ensemble_handle)
      _result = _TreeEnsembleSerializeOutput._make(_result)
      return _result
    except _core._FallbackException:
      return tree_ensemble_serialize_eager_fallback(
          tree_ensemble_handle, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #19
0
ファイル: benchmarks_test.py プロジェクト: becster/tensorflow
def c_tfe_py_fastpath_execute(a,
                              b,
                              transpose_a=False,
                              transpose_b=False,
                              name=None):
  ctx = context.context()
  assert ctx.executing_eagerly(
  ), "The prototype doesn't contain C code for graph construction"
  try:
    return pywrap_tensorflow.TFE_Py_FastPathExecute(
        ctx._handle, ctx.device_name, "MatMul", name,
        ctx._post_execution_callbacks, a, b, "transpose_a", transpose_a,
        "transpose_b", transpose_b)
  except core._NotOkStatusException as e:
    if name is not None:
      message = e.message + " name: " + name
    else:
      message = e.message
    six.raise_from(core._status_to_exception(e.code, message), None)
コード例 #20
0
ファイル: gen_model_ops.py プロジェクト: whqkdhfh13/sswp
def tree_ensemble_is_initialized_op(tree_ensemble_handle, name=None):
  r"""Checks whether a tree ensemble has been initialized.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `bool`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "TreeEnsembleIsInitializedOp",
        tree_ensemble_handle=tree_ensemble_handle, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "TreeEnsembleIsInitializedOp", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "TreeEnsembleIsInitializedOp", name, _ctx._post_execution_callbacks,
        tree_ensemble_handle)
      return _result
    except _core._FallbackException:
      return tree_ensemble_is_initialized_op_eager_fallback(
          tree_ensemble_handle, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #21
0
ファイル: xla_ops.py プロジェクト: whqkdhfh13/sswp
def xla_cluster_output(input, name=None):
  r"""Operator that connects the output of an XLA computation to other consumer graph nodes.

  Args:
    input: A `Tensor`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `input`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "XlaClusterOutput", input=input, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"))
    _execute.record_gradient(
      "XlaClusterOutput", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "XlaClusterOutput", name, _ctx._post_execution_callbacks, input)
      return _result
    except _core._FallbackException:
      return xla_cluster_output_eager_fallback(
          input, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #22
0
ファイル: execute.py プロジェクト: AbhinavJain13/tensorflow
def quick_execute(op_name, num_outputs, inputs, attrs, ctx, name=None):
  """Execute a TensorFlow operation.

  Args:
    op_name: Name of the TensorFlow operation (see REGISTER_OP in C++ code) to
      execute.
    num_outputs: The number of outputs of the operation to fetch.
                 (Explicitly provided instead of being inferred for performance
                 reasons).
    inputs: A list of inputs to the operation. Each entry should be a Tensor, or
      a value which can be passed to the Tensor constructor to create one.
    attrs: A tuple with alternating string attr names and attr values for this
      operation.
    ctx: The value of context.context().
    name: Customized name for the operation.

  Returns:
    List of output Tensor objects. The list is empty if there are no outputs

  Raises:
    An exception on error.
  """
  device_name = ctx.device_name
  # pylint: disable=protected-access
  try:
    tensors = pywrap_tensorflow.TFE_Py_Execute(ctx._handle, device_name,
                                               op_name, inputs, attrs,
                                               num_outputs)
  except core._NotOkStatusException as e:
    if name is not None:
      message = e.message + " name: " + name
    else:
      message = e.message
    six.raise_from(core._status_to_exception(e.code, message), None)
  # pylint: enable=protected-access
  return tensors
コード例 #23
0
def nccl_all_reduce(input, reduction, num_devices, shared_name, name=None):
    r"""Outputs a tensor containing the reduction across all input tensors passed to ops

  within the same `shared_name.

  The graph should be constructed so if one op runs with shared_name value `c`,
  then `num_devices` ops will run with shared_name value `c`.  Failure to do so
  will cause the graph execution to fail to complete.

  Args:
    input: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`, `int32`, `int64`.
      the input to the reduction
    reduction: A `string` from: `"min", "max", "prod", "sum"`.
      the reduction operation to perform.
    num_devices: An `int`.
      The number of devices participating in this reduction.
    shared_name: A `string`.
      Identifier that shared between ops of the same reduction.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `input`.
    the value of the reduction across all `num_devices` devices.
  """
    _ctx = _context._context
    if _ctx is None or not _ctx._eager_context.is_eager:
        reduction = _execute.make_str(reduction, "reduction")
        num_devices = _execute.make_int(num_devices, "num_devices")
        shared_name = _execute.make_str(shared_name, "shared_name")
        _, _, _op = _op_def_lib._apply_op_helper("NcclAllReduce",
                                                 input=input,
                                                 reduction=reduction,
                                                 num_devices=num_devices,
                                                 shared_name=shared_name,
                                                 name=name)
        _result = _op.outputs[:]
        _inputs_flat = _op.inputs
        _attrs = ("reduction", _op.get_attr("reduction"),
                  "T", _op.get_attr("T"), "num_devices",
                  _op.get_attr("num_devices"), "shared_name",
                  _op.get_attr("shared_name"))
        _execute.record_gradient("NcclAllReduce", _inputs_flat, _attrs,
                                 _result, name)
        _result, = _result
        return _result

    else:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._eager_context.device_name,
                "NcclAllReduce", name, _ctx._post_execution_callbacks, input,
                "reduction", reduction, "num_devices", num_devices,
                "shared_name", shared_name)
            return _result
        except _core._FallbackException:
            return nccl_all_reduce_eager_fallback(input,
                                                  reduction=reduction,
                                                  num_devices=num_devices,
                                                  shared_name=shared_name,
                                                  name=name,
                                                  ctx=_ctx)
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #24
0
def collective_bcast_recv(T,
                          group_size,
                          group_key,
                          instance_key,
                          shape,
                          name=None):
    r"""Receives a tensor value broadcast from another device.

  Args:
    T: A `tf.DType` from: `tf.float32, tf.half, tf.float64, tf.int32, tf.int64`.
    group_size: An `int`.
    group_key: An `int`.
    instance_key: An `int`.
    shape: A `tf.TensorShape` or list of `ints`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `T`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "CollectiveBcastRecv", name, _ctx._post_execution_callbacks,
                "T", T, "group_size", group_size, "group_key", group_key,
                "instance_key", instance_key, "shape", shape)
            return _result
        except _core._FallbackException:
            try:
                return collective_bcast_recv_eager_fallback(
                    T=T,
                    group_size=group_size,
                    group_key=group_key,
                    instance_key=instance_key,
                    shape=shape,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    T = _execute.make_type(T, "T")
    group_size = _execute.make_int(group_size, "group_size")
    group_key = _execute.make_int(group_key, "group_key")
    instance_key = _execute.make_int(instance_key, "instance_key")
    shape = _execute.make_shape(shape, "shape")
    _, _, _op = _op_def_lib._apply_op_helper("CollectiveBcastRecv",
                                             T=T,
                                             group_size=group_size,
                                             group_key=group_key,
                                             instance_key=instance_key,
                                             shape=shape,
                                             name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"), "group_size", _op.get_attr("group_size"),
              "group_key", _op.get_attr("group_key"), "instance_key",
              _op.get_attr("instance_key"), "shape", _op.get_attr("shape"))
    _execute.record_gradient("CollectiveBcastRecv", _inputs_flat, _attrs,
                             _result, name)
    _result, = _result
    return _result
コード例 #25
0
def adjust_hsv_in_yiq(images, delta_h, scale_s, scale_v, name=None):
  r"""Adjust the YIQ hue of one or more images.

  `images` is a tensor of at least 3 dimensions.  The last dimension is
  interpreted as channels, and must be three.

  We used linear transformation described in:
   beesbuzz.biz/code/hsv_color_transforms.php
  The input image is considered in the RGB colorspace. Conceptually, the RGB
  colors are first mapped into YIQ space, rotated around the Y channel by
  delta_h in radians, multiplying the chrominance channels (I, Q)  by scale_s,
  multiplying all channels (Y, I, Q)  by scale_v, and then remapped back to RGB
  colorspace. Each operation described above is a linear transformation.

  Args:
    images: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int16`, `int32`, `int64`, `half`, `float32`, `float64`.
      Images to adjust.  At least 3-D.
    delta_h: A `Tensor` of type `float32`.
      A float scale that represents the hue rotation amount, in radians.
      Although delta_h can be any float value.
    scale_s: A `Tensor` of type `float32`.
      A float scale that represents the factor to multiply the saturation by.
      scale_s needs to be non-negative.
    scale_v: A `Tensor` of type `float32`.
      A float scale that represents the factor to multiply the value by.
      scale_v needs to be non-negative.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `images`.
    The hsv-adjusted image or images. No clipping will be done in this op.
    The client can clip them using additional ops in their graph.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "AdjustHsvInYiq", images=images, delta_h=delta_h, scale_s=scale_s,
        scale_v=scale_v, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"))
    _execute.record_gradient(
      "AdjustHsvInYiq", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "AdjustHsvInYiq", name, _ctx._post_execution_callbacks, images,
        delta_h, scale_s, scale_v)
      return _result
    except _core._FallbackException:
      return adjust_hsv_in_yiq_eager_fallback(
          images, delta_h, scale_s, scale_v, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #26
0
def batch_function(in_tensors, captured_tensors, f, num_batch_threads, max_batch_size, batch_timeout_micros, Tout, max_enqueued_batches=10, allowed_batch_sizes=[], container="", shared_name="", batching_queue="", name=None):
  r"""Batches all the inputs tensors to the computation done by the function.

  So, for example, in the following code

    ```python

    # This input will be captured.
    y = tf.placeholder_with_default(1.0, shape=[])

    @tf.Defun(tf.float32)
    def computation(a):
      return tf.matmul(a, a) + y

    b = gen_batch_ops.batch_function(
            f=computation
            in_tensors=[a],
            captured_tensors=computation.captured_inputs,
            Tout=[o.type for o in computation.definition.signature.output_arg],
            num_batch_threads=1,
            max_batch_size=10,
            batch_timeout_micros=100000,  # 100ms
            allowed_batch_sizes=[3, 10],
            batching_queue="")

  If more than one session.run call is simultaneously trying to compute `b`
  the values of `a` will be gathered, non-deterministically concatenated
  along the first axis, and only one thread will run the computation.

  Assumes that all arguments of the function are Tensors which will be batched
  along their first dimension.

  Arguments that are captured, are not batched. The session.run call which does
  the concatenation, will use the values of the captured tensors available to it.
  Therefore, typical uses of captured tensors should involve values which remain
  unchanged across session.run calls. Inference is a good example of this.

  SparseTensor is not supported. The return value of the decorated function
  must be a Tensor or a list/tuple of Tensors.

  Args:
    in_tensors: A list of `Tensor` objects. The tensors to be batched.
    captured_tensors: A list of `Tensor` objects.
      The tensors which are captured in the function, and don't need
      to be batched.
    f: A function decorated with @Defun.
    num_batch_threads: An `int`.
      Number of scheduling threads for processing batches of work.
      Determines the number of batches processed in parallel.
    max_batch_size: An `int`. Batch sizes will never be bigger than this.
    batch_timeout_micros: An `int`.
      Maximum number of microseconds to wait before outputting
      an incomplete batch.
    Tout: A list of `tf.DTypes` that has length `>= 1`.
      the types of the output tensors.
    max_enqueued_batches: An optional `int`. Defaults to `10`.
      Maximum number of batches enqueued. Default: 10.
    allowed_batch_sizes: An optional list of `ints`. Defaults to `[]`.
      Optional list of allowed batch sizes. If left empty, does
      nothing. Otherwise, supplies a list of batch sizes, causing the op to pad
      batches up to one of those sizes. The entries must increase monotonically, and
      the final entry must equal max_batch_size.
    container: An optional `string`. Defaults to `""`.
      Controls the scope of sharing of this batch.
    shared_name: An optional `string`. Defaults to `""`.
      Concurrently running instances of batch in the same device with the
      same container and shared_name will batch their elements together. If left
      empty, the op name will be used as the shared name.
    batching_queue: An optional `string`. Defaults to `""`.
    name: A name for the operation (optional).

  Returns:
    A list of `Tensor` objects of type `Tout`.
  """
  _ctx = _context._context
  if _ctx is not None and _ctx._eager_context.is_eager:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "BatchFunction", name, _ctx._post_execution_callbacks, in_tensors,
        captured_tensors, "f", f, "num_batch_threads", num_batch_threads,
        "max_batch_size", max_batch_size, "batch_timeout_micros",
        batch_timeout_micros, "max_enqueued_batches", max_enqueued_batches,
        "allowed_batch_sizes", allowed_batch_sizes, "container", container,
        "shared_name", shared_name, "batching_queue", batching_queue, "Tout",
        Tout)
      return _result
    except _core._FallbackException:
      try:
        return batch_function_eager_fallback(
            in_tensors, captured_tensors, f=f,
            num_batch_threads=num_batch_threads,
            max_batch_size=max_batch_size,
            batch_timeout_micros=batch_timeout_micros,
            max_enqueued_batches=max_enqueued_batches,
            allowed_batch_sizes=allowed_batch_sizes, container=container,
            shared_name=shared_name, batching_queue=batching_queue, Tout=Tout,
            name=name, ctx=_ctx)
      except _core._SymbolicException:
        pass  # Add nodes to the TensorFlow graph.
      except (TypeError, ValueError):
        result = _dispatch.dispatch(
              batch_function, in_tensors=in_tensors,
                              captured_tensors=captured_tensors, f=f,
                              num_batch_threads=num_batch_threads,
                              max_batch_size=max_batch_size,
                              batch_timeout_micros=batch_timeout_micros,
                              Tout=Tout,
                              max_enqueued_batches=max_enqueued_batches,
                              allowed_batch_sizes=allowed_batch_sizes,
                              container=container, shared_name=shared_name,
                              batching_queue=batching_queue, name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
          return result
        raise
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
  # Add nodes to the TensorFlow graph.
  num_batch_threads = _execute.make_int(num_batch_threads, "num_batch_threads")
  max_batch_size = _execute.make_int(max_batch_size, "max_batch_size")
  batch_timeout_micros = _execute.make_int(batch_timeout_micros, "batch_timeout_micros")
  if not isinstance(Tout, (list, tuple)):
    raise TypeError(
        "Expected list for 'Tout' argument to "
        "'batch_function' Op, not %r." % Tout)
  Tout = [_execute.make_type(_t, "Tout") for _t in Tout]
  if max_enqueued_batches is None:
    max_enqueued_batches = 10
  max_enqueued_batches = _execute.make_int(max_enqueued_batches, "max_enqueued_batches")
  if allowed_batch_sizes is None:
    allowed_batch_sizes = []
  if not isinstance(allowed_batch_sizes, (list, tuple)):
    raise TypeError(
        "Expected list for 'allowed_batch_sizes' argument to "
        "'batch_function' Op, not %r." % allowed_batch_sizes)
  allowed_batch_sizes = [_execute.make_int(_i, "allowed_batch_sizes") for _i in allowed_batch_sizes]
  if container is None:
    container = ""
  container = _execute.make_str(container, "container")
  if shared_name is None:
    shared_name = ""
  shared_name = _execute.make_str(shared_name, "shared_name")
  if batching_queue is None:
    batching_queue = ""
  batching_queue = _execute.make_str(batching_queue, "batching_queue")
  try:
    _, _, _op = _op_def_lib._apply_op_helper(
        "BatchFunction", in_tensors=in_tensors,
                         captured_tensors=captured_tensors, f=f,
                         num_batch_threads=num_batch_threads,
                         max_batch_size=max_batch_size,
                         batch_timeout_micros=batch_timeout_micros, Tout=Tout,
                         max_enqueued_batches=max_enqueued_batches,
                         allowed_batch_sizes=allowed_batch_sizes,
                         container=container, shared_name=shared_name,
                         batching_queue=batching_queue, name=name)
  except (TypeError, ValueError):
    result = _dispatch.dispatch(
          batch_function, in_tensors=in_tensors,
                          captured_tensors=captured_tensors, f=f,
                          num_batch_threads=num_batch_threads,
                          max_batch_size=max_batch_size,
                          batch_timeout_micros=batch_timeout_micros,
                          Tout=Tout,
                          max_enqueued_batches=max_enqueued_batches,
                          allowed_batch_sizes=allowed_batch_sizes,
                          container=container, shared_name=shared_name,
                          batching_queue=batching_queue, name=name)
    if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
      return result
    raise
  _result = _op.outputs[:]
  _inputs_flat = _op.inputs
  _attrs = ("f", _op.get_attr("f"), "num_batch_threads",
            _op.get_attr("num_batch_threads"), "max_batch_size",
            _op.get_attr("max_batch_size"), "batch_timeout_micros",
            _op.get_attr("batch_timeout_micros"), "max_enqueued_batches",
            _op.get_attr("max_enqueued_batches"), "allowed_batch_sizes",
            _op.get_attr("allowed_batch_sizes"), "container",
            _op.get_attr("container"), "shared_name",
            _op.get_attr("shared_name"), "batching_queue",
            _op.get_attr("batching_queue"), "Tin", _op.get_attr("Tin"),
            "Tcaptured", _op.get_attr("Tcaptured"), "Tout",
            _op.get_attr("Tout"))
  _execute.record_gradient(
      "BatchFunction", _inputs_flat, _attrs, _result, name)
  return _result
コード例 #27
0
def collective_reduce(input,
                      group_size,
                      group_key,
                      instance_key,
                      merge_op,
                      final_op,
                      subdiv_offsets,
                      wait_for=[],
                      name=None):
    r"""Mutually reduces multiple tensors of identical type and shape.

  Args:
    input: A `Tensor`. Must be one of the following types: `float32`, `half`, `float64`, `int32`, `int64`.
    group_size: An `int`.
    group_key: An `int`.
    instance_key: An `int`.
    merge_op: A `string` from: `"Min", "Max", "Mul", "Add"`.
    final_op: A `string` from: `"Id", "Div"`.
    subdiv_offsets: A list of `ints`.
    wait_for: An optional list of `ints`. Defaults to `[]`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `input`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "CollectiveReduce", name, _ctx._post_execution_callbacks,
                input, "group_size", group_size, "group_key", group_key,
                "instance_key", instance_key, "merge_op", merge_op, "final_op",
                final_op, "subdiv_offsets", subdiv_offsets, "wait_for",
                wait_for)
            return _result
        except _core._FallbackException:
            try:
                return collective_reduce_eager_fallback(
                    input,
                    group_size=group_size,
                    group_key=group_key,
                    instance_key=instance_key,
                    merge_op=merge_op,
                    final_op=final_op,
                    subdiv_offsets=subdiv_offsets,
                    wait_for=wait_for,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    group_size = _execute.make_int(group_size, "group_size")
    group_key = _execute.make_int(group_key, "group_key")
    instance_key = _execute.make_int(instance_key, "instance_key")
    merge_op = _execute.make_str(merge_op, "merge_op")
    final_op = _execute.make_str(final_op, "final_op")
    if not isinstance(subdiv_offsets, (list, tuple)):
        raise TypeError("Expected list for 'subdiv_offsets' argument to "
                        "'collective_reduce' Op, not %r." % subdiv_offsets)
    subdiv_offsets = [
        _execute.make_int(_i, "subdiv_offsets") for _i in subdiv_offsets
    ]
    if wait_for is None:
        wait_for = []
    if not isinstance(wait_for, (list, tuple)):
        raise TypeError("Expected list for 'wait_for' argument to "
                        "'collective_reduce' Op, not %r." % wait_for)
    wait_for = [_execute.make_int(_i, "wait_for") for _i in wait_for]
    _, _, _op = _op_def_lib._apply_op_helper("CollectiveReduce",
                                             input=input,
                                             group_size=group_size,
                                             group_key=group_key,
                                             instance_key=instance_key,
                                             merge_op=merge_op,
                                             final_op=final_op,
                                             subdiv_offsets=subdiv_offsets,
                                             wait_for=wait_for,
                                             name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"), "group_size", _op.get_attr("group_size"),
              "group_key", _op.get_attr("group_key"), "instance_key",
              _op.get_attr("instance_key"),
              "merge_op", _op.get_attr("merge_op"), "final_op",
              _op.get_attr("final_op"), "subdiv_offsets",
              _op.get_attr("subdiv_offsets"), "wait_for",
              _op.get_attr("wait_for"))
    _execute.record_gradient("CollectiveReduce", _inputs_flat, _attrs, _result,
                             name)
    _result, = _result
    return _result
コード例 #28
0
ファイル: gen_image_ops.py プロジェクト: whqkdhfh13/sswp
def bipartite_match(distance_mat, num_valid_rows, top_k=-1, name=None):
  r"""Find bipartite matching based on a given distance matrix.

  A greedy bi-partite matching algorithm is used to obtain the matching with the
  (greedy) minimum distance.

  Args:
    distance_mat: A `Tensor` of type `float32`.
      A 2-D float tensor of shape `[num_rows, num_columns]`. It is a
      pair-wise distance matrix between the entities represented by each row and
      each column. It is an asymmetric matrix. The smaller the distance is, the more
      similar the pairs are. The bipartite matching is to minimize the distances.
    num_valid_rows: A `Tensor` of type `float32`.
      A scalar or a 1-D tensor with one element describing the
      number of valid rows of distance_mat to consider for the bipartite matching.
      If set to be negative, then all rows from `distance_mat` are used.
    top_k: An optional `int`. Defaults to `-1`.
      A scalar that specifies the number of top-k matches to retrieve.
      If set to be negative, then is set according to the maximum number of
      matches from `distance_mat`.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (row_to_col_match_indices, col_to_row_match_indices).

    row_to_col_match_indices: A `Tensor` of type `int32`. A vector of length num_rows, which is the number of
      rows of the input `distance_matrix`.
      If `row_to_col_match_indices[i]` is not -1, row i is matched to column
      `row_to_col_match_indices[i]`.
    col_to_row_match_indices: A `Tensor` of type `int32`. A vector of length num_columns, which is the number
      of columns of the input distance matrix.
      If `col_to_row_match_indices[j]` is not -1, column j is matched to row
      `col_to_row_match_indices[j]`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    if top_k is None:
      top_k = -1
    top_k = _execute.make_int(top_k, "top_k")
    _, _, _op = _op_def_lib._apply_op_helper(
        "BipartiteMatch", distance_mat=distance_mat,
        num_valid_rows=num_valid_rows, top_k=top_k, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("top_k", _op.get_attr("top_k"))
    _execute.record_gradient(
      "BipartiteMatch", _inputs_flat, _attrs, _result, name)
    _result = _BipartiteMatchOutput._make(_result)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "BipartiteMatch", name, _ctx._post_execution_callbacks, distance_mat,
        num_valid_rows, "top_k", top_k)
      _result = _BipartiteMatchOutput._make(_result)
      return _result
    except _core._FallbackException:
      return bipartite_match_eager_fallback(
          distance_mat, num_valid_rows, top_k=top_k, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #29
0
def stateless_multinomial(logits,
                          num_samples,
                          seed,
                          output_dtype=_dtypes.int64,
                          name=None):
    r"""Draws samples from a multinomial distribution.

  Args:
    logits: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `int64`, `bfloat16`, `uint16`, `half`, `uint32`, `uint64`.
      2-D Tensor with shape `[batch_size, num_classes]`.  Each slice `[i, :]`

      represents the unnormalized log probabilities for all classes.
    num_samples: A `Tensor` of type `int32`.
      0-D.  Number of independent samples to draw for each row slice.
    seed: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      2 seeds (shape [2]).
    output_dtype: An optional `tf.DType` from: `tf.int32, tf.int64`. Defaults to `tf.int64`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `output_dtype`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "StatelessMultinomial", name, _ctx._post_execution_callbacks,
                logits, num_samples, seed, "output_dtype", output_dtype)
            return _result
        except _core._FallbackException:
            try:
                return stateless_multinomial_eager_fallback(
                    logits,
                    num_samples,
                    seed,
                    output_dtype=output_dtype,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    if output_dtype is None:
        output_dtype = _dtypes.int64
    output_dtype = _execute.make_type(output_dtype, "output_dtype")
    _, _, _op = _op_def_lib._apply_op_helper("StatelessMultinomial",
                                             logits=logits,
                                             num_samples=num_samples,
                                             seed=seed,
                                             output_dtype=output_dtype,
                                             name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"), "Tseed", _op.get_attr("Tseed"),
              "output_dtype", _op.get_attr("output_dtype"))
    _execute.record_gradient("StatelessMultinomial", _inputs_flat, _attrs,
                             _result, name)
    _result, = _result
    return _result
コード例 #30
0
ファイル: gen_trt_ops.py プロジェクト: nimeshgit/temp
def trt_engine_op(in_tensor,
                  serialized_segment,
                  OutT,
                  workspace_size_bytes,
                  precision_mode,
                  segment_func="",
                  max_cached_engines_count=1,
                  calibration_data="",
                  use_calibration=True,
                  segment_funcdef_name="",
                  cached_engine_batches=[],
                  fixed_input_size=True,
                  input_shapes=[],
                  output_shapes=[],
                  static_engine=True,
                  name=None):
    r"""TODO: add doc.

  Args:
    in_tensor: A list of `Tensor` objects with types from: `int8`, `half`, `float32`, `int32`.
    serialized_segment: A `string`.
    OutT: A list of `tf.DTypes` from: `tf.int8, tf.half, tf.float32, tf.int32` that has length `>= 1`.
    workspace_size_bytes: An `int`.
    precision_mode: A `string` from: `"FP32", "FP16", "INT8"`.
    segment_func: An optional function decorated with @Defun. Defaults to `""`.
    max_cached_engines_count: An optional `int`. Defaults to `1`.
    calibration_data: An optional `string`. Defaults to `""`.
    use_calibration: An optional `bool`. Defaults to `True`.
    segment_funcdef_name: An optional `string`. Defaults to `""`.
    cached_engine_batches: An optional list of `ints`. Defaults to `[]`.
    fixed_input_size: An optional `bool`. Defaults to `True`.
    input_shapes: An optional list of shapes (each a `tf.TensorShape` or list of `ints`). Defaults to `[]`.
    output_shapes: An optional list of shapes (each a `tf.TensorShape` or list of `ints`). Defaults to `[]`.
    static_engine: An optional `bool`. Defaults to `True`.
    name: A name for the operation (optional).

  Returns:
    A list of `Tensor` objects of type `OutT`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "TRTEngineOp", name, _ctx.post_execution_callbacks, in_tensor,
                "serialized_segment", serialized_segment, "segment_func",
                segment_func, "OutT", OutT, "max_cached_engines_count",
                max_cached_engines_count, "workspace_size_bytes",
                workspace_size_bytes, "precision_mode", precision_mode,
                "calibration_data", calibration_data, "use_calibration",
                use_calibration, "segment_funcdef_name", segment_funcdef_name,
                "cached_engine_batches", cached_engine_batches,
                "fixed_input_size", fixed_input_size, "input_shapes",
                input_shapes, "output_shapes", output_shapes, "static_engine",
                static_engine)
            return _result
        except _core._FallbackException:
            try:
                return trt_engine_op_eager_fallback(
                    in_tensor,
                    serialized_segment=serialized_segment,
                    segment_func=segment_func,
                    OutT=OutT,
                    max_cached_engines_count=max_cached_engines_count,
                    workspace_size_bytes=workspace_size_bytes,
                    precision_mode=precision_mode,
                    calibration_data=calibration_data,
                    use_calibration=use_calibration,
                    segment_funcdef_name=segment_funcdef_name,
                    cached_engine_batches=cached_engine_batches,
                    fixed_input_size=fixed_input_size,
                    input_shapes=input_shapes,
                    output_shapes=output_shapes,
                    static_engine=static_engine,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
            except (TypeError, ValueError):
                result = _dispatch.dispatch(
                    trt_engine_op,
                    in_tensor=in_tensor,
                    serialized_segment=serialized_segment,
                    OutT=OutT,
                    workspace_size_bytes=workspace_size_bytes,
                    precision_mode=precision_mode,
                    segment_func=segment_func,
                    max_cached_engines_count=max_cached_engines_count,
                    calibration_data=calibration_data,
                    use_calibration=use_calibration,
                    segment_funcdef_name=segment_funcdef_name,
                    cached_engine_batches=cached_engine_batches,
                    fixed_input_size=fixed_input_size,
                    input_shapes=input_shapes,
                    output_shapes=output_shapes,
                    static_engine=static_engine,
                    name=name)
                if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                    return result
                raise
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    serialized_segment = _execute.make_str(serialized_segment,
                                           "serialized_segment")
    if not isinstance(OutT, (list, tuple)):
        raise TypeError("Expected list for 'OutT' argument to "
                        "'trt_engine_op' Op, not %r." % OutT)
    OutT = [_execute.make_type(_t, "OutT") for _t in OutT]
    workspace_size_bytes = _execute.make_int(workspace_size_bytes,
                                             "workspace_size_bytes")
    precision_mode = _execute.make_str(precision_mode, "precision_mode")
    if segment_func is None:
        segment_func = ""
    if max_cached_engines_count is None:
        max_cached_engines_count = 1
    max_cached_engines_count = _execute.make_int(max_cached_engines_count,
                                                 "max_cached_engines_count")
    if calibration_data is None:
        calibration_data = ""
    calibration_data = _execute.make_str(calibration_data, "calibration_data")
    if use_calibration is None:
        use_calibration = True
    use_calibration = _execute.make_bool(use_calibration, "use_calibration")
    if segment_funcdef_name is None:
        segment_funcdef_name = ""
    segment_funcdef_name = _execute.make_str(segment_funcdef_name,
                                             "segment_funcdef_name")
    if cached_engine_batches is None:
        cached_engine_batches = []
    if not isinstance(cached_engine_batches, (list, tuple)):
        raise TypeError(
            "Expected list for 'cached_engine_batches' argument to "
            "'trt_engine_op' Op, not %r." % cached_engine_batches)
    cached_engine_batches = [
        _execute.make_int(_i, "cached_engine_batches")
        for _i in cached_engine_batches
    ]
    if fixed_input_size is None:
        fixed_input_size = True
    fixed_input_size = _execute.make_bool(fixed_input_size, "fixed_input_size")
    if input_shapes is None:
        input_shapes = []
    if not isinstance(input_shapes, (list, tuple)):
        raise TypeError("Expected list for 'input_shapes' argument to "
                        "'trt_engine_op' Op, not %r." % input_shapes)
    input_shapes = [
        _execute.make_shape(_s, "input_shapes") for _s in input_shapes
    ]
    if output_shapes is None:
        output_shapes = []
    if not isinstance(output_shapes, (list, tuple)):
        raise TypeError("Expected list for 'output_shapes' argument to "
                        "'trt_engine_op' Op, not %r." % output_shapes)
    output_shapes = [
        _execute.make_shape(_s, "output_shapes") for _s in output_shapes
    ]
    if static_engine is None:
        static_engine = True
    static_engine = _execute.make_bool(static_engine, "static_engine")
    try:
        _, _, _op = _op_def_lib._apply_op_helper(
            "TRTEngineOp",
            in_tensor=in_tensor,
            serialized_segment=serialized_segment,
            OutT=OutT,
            workspace_size_bytes=workspace_size_bytes,
            precision_mode=precision_mode,
            segment_func=segment_func,
            max_cached_engines_count=max_cached_engines_count,
            calibration_data=calibration_data,
            use_calibration=use_calibration,
            segment_funcdef_name=segment_funcdef_name,
            cached_engine_batches=cached_engine_batches,
            fixed_input_size=fixed_input_size,
            input_shapes=input_shapes,
            output_shapes=output_shapes,
            static_engine=static_engine,
            name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(
            trt_engine_op,
            in_tensor=in_tensor,
            serialized_segment=serialized_segment,
            OutT=OutT,
            workspace_size_bytes=workspace_size_bytes,
            precision_mode=precision_mode,
            segment_func=segment_func,
            max_cached_engines_count=max_cached_engines_count,
            calibration_data=calibration_data,
            use_calibration=use_calibration,
            segment_funcdef_name=segment_funcdef_name,
            cached_engine_batches=cached_engine_batches,
            fixed_input_size=fixed_input_size,
            input_shapes=input_shapes,
            output_shapes=output_shapes,
            static_engine=static_engine,
            name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("serialized_segment",
              _op.get_attr("serialized_segment"), "segment_func",
              _op.get_attr("segment_func"), "InT", _op.get_attr("InT"), "OutT",
              _op.get_attr("OutT"), "max_cached_engines_count",
              _op.get_attr("max_cached_engines_count"), "workspace_size_bytes",
              _op.get_attr("workspace_size_bytes"), "precision_mode",
              _op.get_attr("precision_mode"), "calibration_data",
              _op.get_attr("calibration_data"), "use_calibration",
              _op.get_attr("use_calibration"), "segment_funcdef_name",
              _op.get_attr("segment_funcdef_name"), "cached_engine_batches",
              _op.get_attr("cached_engine_batches"), "fixed_input_size",
              _op.get_attr("fixed_input_size"), "input_shapes",
              _op.get_attr("input_shapes"), "output_shapes",
              _op.get_attr("output_shapes"), "static_engine",
              _op.get_attr("static_engine"))
    _execute.record_gradient("TRTEngineOp", _inputs_flat, _attrs, _result,
                             name)
    return _result
コード例 #31
0
def grow_tree_ensemble(tree_ensemble_handle,
                       stamp_token,
                       next_stamp_token,
                       learning_rate,
                       dropout_seed,
                       partition_ids,
                       gains,
                       splits,
                       learner_config,
                       center_bias,
                       name=None):
    r"""Grows the tree ensemble by either adding a layer to the last tree being grown

  or by starting a new tree.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
      Handle to the ensemble variable.
    stamp_token: A `Tensor` of type `int64`.
      Stamp token for validating operation consistency.
    next_stamp_token: A `Tensor` of type `int64`.
      Stamp token to be used for the next iteration.
    learning_rate: A `Tensor` of type `float32`. Scalar learning rate.
    dropout_seed: A `Tensor` of type `int64`.
    partition_ids: A list of `Tensor` objects with type `int32`.
      List of Rank 1 Tensors containing partition Id per candidate.
    gains: A list with the same length as `partition_ids` of `Tensor` objects with type `float32`.
      List of Rank 1 Tensors containing gains per candidate.
    splits: A list with the same length as `partition_ids` of `Tensor` objects with type `string`.
      List of Rank 1 Tensors containing serialized SplitInfo protos per candidate.
    learner_config: A `string`.
      Config for the learner of type LearnerConfig proto.
    center_bias: A `bool`.
    name: A name for the operation (optional).

  Returns:
    The created Operation.
  """
    _ctx = _context.context()
    if not _ctx.executing_eagerly():
        if not isinstance(partition_ids, (list, tuple)):
            raise TypeError("Expected list for 'partition_ids' argument to "
                            "'grow_tree_ensemble' Op, not %r." % partition_ids)
        _attr_num_handlers = len(partition_ids)
        if not isinstance(gains, (list, tuple)):
            raise TypeError("Expected list for 'gains' argument to "
                            "'grow_tree_ensemble' Op, not %r." % gains)
        if len(gains) != _attr_num_handlers:
            raise ValueError(
                "List argument 'gains' to 'grow_tree_ensemble' Op with length %d "
                "must match length %d of argument 'partition_ids'." %
                (len(gains), _attr_num_handlers))
        if not isinstance(splits, (list, tuple)):
            raise TypeError("Expected list for 'splits' argument to "
                            "'grow_tree_ensemble' Op, not %r." % splits)
        if len(splits) != _attr_num_handlers:
            raise ValueError(
                "List argument 'splits' to 'grow_tree_ensemble' Op with length %d "
                "must match length %d of argument 'partition_ids'." %
                (len(splits), _attr_num_handlers))
        learner_config = _execute.make_str(learner_config, "learner_config")
        center_bias = _execute.make_bool(center_bias, "center_bias")
        _, _, _op = _op_def_lib._apply_op_helper(
            "GrowTreeEnsemble",
            tree_ensemble_handle=tree_ensemble_handle,
            stamp_token=stamp_token,
            next_stamp_token=next_stamp_token,
            learning_rate=learning_rate,
            dropout_seed=dropout_seed,
            partition_ids=partition_ids,
            gains=gains,
            splits=splits,
            learner_config=learner_config,
            center_bias=center_bias,
            name=name)
        return _op
        _result = None
        return _result

    else:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._handle, _ctx.device_name, "GrowTreeEnsemble", name,
                _ctx._post_execution_callbacks, tree_ensemble_handle,
                stamp_token, next_stamp_token, learning_rate, dropout_seed,
                partition_ids, gains, splits, "learner_config", learner_config,
                "center_bias", center_bias)
            return _result
        except _core._FallbackException:
            return grow_tree_ensemble_eager_fallback(
                tree_ensemble_handle,
                stamp_token,
                next_stamp_token,
                learning_rate,
                dropout_seed,
                partition_ids,
                gains,
                splits,
                learner_config=learner_config,
                center_bias=center_bias,
                name=name)
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #32
0
ファイル: gen_dataset_ops.py プロジェクト: aMp37/SimpleHTR
def ignite_dataset(cache_name,
                   host,
                   port,
                   local,
                   part,
                   page_size,
                   schema,
                   permutation,
                   name=None):
    r"""IgniteDataset that allows to get data from Apache Ignite.

  Apache Ignite is a memory-centric distributed database, caching, and processing
  platform for transactional, analytical, and streaming workloads, delivering
  in-memory speeds at petabyte scale. This contrib package contains an
  integration between Apache Ignite and TensorFlow. The integration is based on
  tf.data from TensorFlow side and Binary Client Protocol from Apache Ignite side.
  It allows to use Apache Ignite as a datasource for neural network training,
  inference and all other computations supported by TensorFlow. Ignite Dataset
  is based on Apache Ignite Binary Client Protocol.

  Args:
    cache_name: A `Tensor` of type `string`. Ignite Cache Name.
    host: A `Tensor` of type `string`. Ignite Thin Client Host.
    port: A `Tensor` of type `int32`. Ignite Thin Client Port.
    local: A `Tensor` of type `bool`.
      Local flag that defines that data should be fetched from local host only.
    part: A `Tensor` of type `int32`. Partition data should be fetched from.
    page_size: A `Tensor` of type `int32`. Page size for Ignite Thin Client.
    schema: A `Tensor` of type `int32`.
      Internal structure that defines schema of cache objects.
    permutation: A `Tensor` of type `int32`.
      Internal structure that defines permutation of cache objects.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `variant`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "IgniteDataset", name, _ctx.post_execution_callbacks,
                cache_name, host, port, local, part, page_size, schema,
                permutation)
            return _result
        except _core._FallbackException:
            try:
                return ignite_dataset_eager_fallback(cache_name,
                                                     host,
                                                     port,
                                                     local,
                                                     part,
                                                     page_size,
                                                     schema,
                                                     permutation,
                                                     name=name,
                                                     ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
            except (TypeError, ValueError):
                result = _dispatch.dispatch(ignite_dataset,
                                            cache_name=cache_name,
                                            host=host,
                                            port=port,
                                            local=local,
                                            part=part,
                                            page_size=page_size,
                                            schema=schema,
                                            permutation=permutation,
                                            name=name)
                if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                    return result
                raise
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    try:
        _, _, _op = _op_def_lib._apply_op_helper("IgniteDataset",
                                                 cache_name=cache_name,
                                                 host=host,
                                                 port=port,
                                                 local=local,
                                                 part=part,
                                                 page_size=page_size,
                                                 schema=schema,
                                                 permutation=permutation,
                                                 name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(ignite_dataset,
                                    cache_name=cache_name,
                                    host=host,
                                    port=port,
                                    local=local,
                                    part=part,
                                    page_size=page_size,
                                    schema=schema,
                                    permutation=permutation,
                                    name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient("IgniteDataset", _inputs_flat, _attrs, _result,
                             name)
    _result, = _result
    return _result
コード例 #33
0
ファイル: gen_trt_ops.py プロジェクト: nimeshgit/temp
def serialize_trt_resource(resource_name,
                           filename,
                           delete_resource=False,
                           name=None):
    r"""TODO: add doc.

  Args:
    resource_name: A `Tensor` of type `string`.
    filename: A `Tensor` of type `string`.
    delete_resource: An optional `bool`. Defaults to `False`.
    name: A name for the operation (optional).

  Returns:
    The created Operation.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "SerializeTRTResource", name, _ctx.post_execution_callbacks,
                resource_name, filename, "delete_resource", delete_resource)
            return _result
        except _core._FallbackException:
            try:
                return serialize_trt_resource_eager_fallback(
                    resource_name,
                    filename,
                    delete_resource=delete_resource,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
            except (TypeError, ValueError):
                result = _dispatch.dispatch(serialize_trt_resource,
                                            resource_name=resource_name,
                                            filename=filename,
                                            delete_resource=delete_resource,
                                            name=name)
                if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                    return result
                raise
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    if delete_resource is None:
        delete_resource = False
    delete_resource = _execute.make_bool(delete_resource, "delete_resource")
    try:
        _, _, _op = _op_def_lib._apply_op_helper(
            "SerializeTRTResource",
            resource_name=resource_name,
            filename=filename,
            delete_resource=delete_resource,
            name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(serialize_trt_resource,
                                    resource_name=resource_name,
                                    filename=filename,
                                    delete_resource=delete_resource,
                                    name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    return _op
    _result = None
    return _result
コード例 #34
0
def adjust_hsv_in_yiq(images, delta_h, scale_s, scale_v, name=None):
    r"""Adjust the YIQ hue of one or more images.

  `images` is a tensor of at least 3 dimensions.  The last dimension is
  interpreted as channels, and must be three.

  We used linear transformation described in:
   beesbuzz.biz/code/hsv_color_transforms.php
  The input image is considered in the RGB colorspace. Conceptually, the RGB
  colors are first mapped into YIQ space, rotated around the Y channel by
  delta_h in radians, multiplying the chrominance channels (I, Q)  by scale_s,
  multiplying all channels (Y, I, Q)  by scale_v, and then remapped back to RGB
  colorspace. Each operation described above is a linear transformation.

  Args:
    images: A `Tensor`. Must be one of the following types: `uint8`, `int8`, `int16`, `int32`, `int64`, `half`, `float32`, `float64`.
      Images to adjust.  At least 3-D.
    delta_h: A `Tensor` of type `float32`.
      A float scale that represents the hue rotation amount, in radians.
      Although delta_h can be any float value.
    scale_s: A `Tensor` of type `float32`.
      A float scale that represents the factor to multiply the saturation by.
      scale_s needs to be non-negative.
    scale_v: A `Tensor` of type `float32`.
      A float scale that represents the factor to multiply the value by.
      scale_v needs to be non-negative.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `images`.
    The hsv-adjusted image or images. No clipping will be done in this op.
    The client can clip them using additional ops in their graph.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "AdjustHsvInYiq", name, _ctx.post_execution_callbacks, images,
                delta_h, scale_s, scale_v)
            return _result
        except _core._FallbackException:
            try:
                return adjust_hsv_in_yiq_eager_fallback(images,
                                                        delta_h,
                                                        scale_s,
                                                        scale_v,
                                                        name=name,
                                                        ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
            except (TypeError, ValueError):
                result = _dispatch.dispatch(adjust_hsv_in_yiq,
                                            images=images,
                                            delta_h=delta_h,
                                            scale_s=scale_s,
                                            scale_v=scale_v,
                                            name=name)
                if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                    return result
                raise
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    try:
        _, _, _op = _op_def_lib._apply_op_helper("AdjustHsvInYiq",
                                                 images=images,
                                                 delta_h=delta_h,
                                                 scale_s=scale_s,
                                                 scale_v=scale_v,
                                                 name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(adjust_hsv_in_yiq,
                                    images=images,
                                    delta_h=delta_h,
                                    scale_s=scale_s,
                                    scale_v=scale_v,
                                    name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op._get_attr_type("T"))
    _execute.record_gradient("AdjustHsvInYiq", _inputs_flat, _attrs, _result,
                             name)
    _result, = _result
    return _result
コード例 #35
0
def encode_proto(sizes,
                 values,
                 field_names,
                 message_type,
                 descriptor_source="local://",
                 name=None):
    r"""TODO: add doc.

  Args:
    sizes: A `Tensor` of type `int32`.
    values: A list of `Tensor` objects.
    field_names: A list of `strings`.
    message_type: A `string`.
    descriptor_source: An optional `string`. Defaults to `"local://"`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `string`.
  """
    _ctx = _context._context
    if _ctx is None or not _ctx._eager_context.is_eager:
        if not isinstance(field_names, (list, tuple)):
            raise TypeError("Expected list for 'field_names' argument to "
                            "'encode_proto' Op, not %r." % field_names)
        field_names = [
            _execute.make_str(_s, "field_names") for _s in field_names
        ]
        message_type = _execute.make_str(message_type, "message_type")
        if descriptor_source is None:
            descriptor_source = "local://"
        descriptor_source = _execute.make_str(descriptor_source,
                                              "descriptor_source")
        _, _, _op = _op_def_lib._apply_op_helper(
            "EncodeProto",
            sizes=sizes,
            values=values,
            field_names=field_names,
            message_type=message_type,
            descriptor_source=descriptor_source,
            name=name)
        _result = _op.outputs[:]
        _inputs_flat = _op.inputs
        _attrs = ("field_names", _op.get_attr("field_names"), "message_type",
                  _op.get_attr("message_type"), "descriptor_source",
                  _op.get_attr("descriptor_source"), "Tinput_types",
                  _op.get_attr("Tinput_types"))
        _execute.record_gradient("EncodeProto", _inputs_flat, _attrs, _result,
                                 name)
        _result, = _result
        return _result

    else:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._eager_context.device_name,
                "EncodeProto", name, _ctx._post_execution_callbacks, sizes,
                values, "field_names", field_names, "message_type",
                message_type, "descriptor_source", descriptor_source)
            return _result
        except _core._FallbackException:
            return encode_proto_eager_fallback(
                sizes,
                values,
                field_names=field_names,
                message_type=message_type,
                descriptor_source=descriptor_source,
                name=name,
                ctx=_ctx)
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #36
0
def xla_launch(constants, args, resources, Tresults, function, name=None):
    r"""XLA Launch Op. For use by the XLA JIT only.

  Args:
    constants: A list of `Tensor` objects.
    args: A list of `Tensor` objects.
    resources: A list of `Tensor` objects with type `resource`.
    Tresults: A list of `tf.DTypes`.
    function: A function decorated with @Defun.
    name: A name for the operation (optional).

  Returns:
    A list of `Tensor` objects of type `Tresults`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "XlaLaunch", name, _ctx.post_execution_callbacks, constants,
                args, resources, "Tresults", Tresults, "function", function)
            return _result
        except _core._FallbackException:
            try:
                return xla_launch_eager_fallback(constants,
                                                 args,
                                                 resources,
                                                 Tresults=Tresults,
                                                 function=function,
                                                 name=name,
                                                 ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
            except (TypeError, ValueError):
                result = _dispatch.dispatch(xla_launch,
                                            constants=constants,
                                            args=args,
                                            resources=resources,
                                            Tresults=Tresults,
                                            function=function,
                                            name=name)
                if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                    return result
                raise
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    if not isinstance(resources, (list, tuple)):
        raise TypeError("Expected list for 'resources' argument to "
                        "'xla_launch' Op, not %r." % resources)
    _attr_Nresources = len(resources)
    if not isinstance(Tresults, (list, tuple)):
        raise TypeError("Expected list for 'Tresults' argument to "
                        "'xla_launch' Op, not %r." % Tresults)
    Tresults = [_execute.make_type(_t, "Tresults") for _t in Tresults]
    try:
        _, _, _op = _op_def_lib._apply_op_helper("XlaLaunch",
                                                 constants=constants,
                                                 args=args,
                                                 resources=resources,
                                                 Tresults=Tresults,
                                                 function=function,
                                                 name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(xla_launch,
                                    constants=constants,
                                    args=args,
                                    resources=resources,
                                    Tresults=Tresults,
                                    function=function,
                                    name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _op.outputs[:]
    if not _result:
        return _op
    _inputs_flat = _op.inputs
    _attrs = ("Tconstants", _op.get_attr("Tconstants"), "Targs",
              _op.get_attr("Targs"), "Nresources", _op.get_attr("Nresources"),
              "Tresults", _op.get_attr("Tresults"), "function",
              _op.get_attr("function"))
    _execute.record_gradient("XlaLaunch", _inputs_flat, _attrs, _result, name)
    return _result
コード例 #37
0
def mfcc(spectrogram, sample_rate, upper_frequency_limit=4000, lower_frequency_limit=20, filterbank_channel_count=40, dct_coefficient_count=13, name=None):
  r"""Transforms a spectrogram into a form that's useful for speech recognition.

  Mel Frequency Cepstral Coefficients are a way of representing audio data that's
  been effective as an input feature for machine learning. They are created by
  taking the spectrum of a spectrogram (a 'cepstrum'), and discarding some of the
  higher frequencies that are less significant to the human ear. They have a long
  history in the speech recognition world, and https://en.wikipedia.org/wiki/Mel-frequency_cepstrum
  is a good resource to learn more.

  Args:
    spectrogram: A `Tensor` of type `float32`.
      Typically produced by the Spectrogram op, with magnitude_squared
      set to true.
    sample_rate: A `Tensor` of type `int32`.
      How many samples per second the source audio used.
    upper_frequency_limit: An optional `float`. Defaults to `4000`.
      The highest frequency to use when calculating the
      ceptstrum.
    lower_frequency_limit: An optional `float`. Defaults to `20`.
      The lowest frequency to use when calculating the
      ceptstrum.
    filterbank_channel_count: An optional `int`. Defaults to `40`.
      Resolution of the Mel bank used internally.
    dct_coefficient_count: An optional `int`. Defaults to `13`.
      How many output channels to produce per time slice.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `float32`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    if upper_frequency_limit is None:
      upper_frequency_limit = 4000
    upper_frequency_limit = _execute.make_float(upper_frequency_limit, "upper_frequency_limit")
    if lower_frequency_limit is None:
      lower_frequency_limit = 20
    lower_frequency_limit = _execute.make_float(lower_frequency_limit, "lower_frequency_limit")
    if filterbank_channel_count is None:
      filterbank_channel_count = 40
    filterbank_channel_count = _execute.make_int(filterbank_channel_count, "filterbank_channel_count")
    if dct_coefficient_count is None:
      dct_coefficient_count = 13
    dct_coefficient_count = _execute.make_int(dct_coefficient_count, "dct_coefficient_count")
    _, _, _op = _op_def_lib._apply_op_helper(
        "Mfcc", spectrogram=spectrogram, sample_rate=sample_rate,
        upper_frequency_limit=upper_frequency_limit,
        lower_frequency_limit=lower_frequency_limit,
        filterbank_channel_count=filterbank_channel_count,
        dct_coefficient_count=dct_coefficient_count, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("upper_frequency_limit", _op.get_attr("upper_frequency_limit"),
              "lower_frequency_limit", _op.get_attr("lower_frequency_limit"),
              "filterbank_channel_count",
              _op.get_attr("filterbank_channel_count"),
              "dct_coefficient_count", _op.get_attr("dct_coefficient_count"))
    _execute.record_gradient(
      "Mfcc", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name, "Mfcc", name,
        _ctx._post_execution_callbacks, spectrogram, sample_rate,
        "upper_frequency_limit", upper_frequency_limit,
        "lower_frequency_limit", lower_frequency_limit,
        "filterbank_channel_count", filterbank_channel_count,
        "dct_coefficient_count", dct_coefficient_count)
      return _result
    except _core._FallbackException:
      return mfcc_eager_fallback(
          spectrogram, sample_rate,
          upper_frequency_limit=upper_frequency_limit,
          lower_frequency_limit=lower_frequency_limit,
          filterbank_channel_count=filterbank_channel_count,
          dct_coefficient_count=dct_coefficient_count, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #38
0
ファイル: gen_set_ops.py プロジェクト: elammend/yogaBackend
def dense_to_sparse_set_operation(set1,
                                  set2_indices,
                                  set2_values,
                                  set2_shape,
                                  set_operation,
                                  validate_indices=True,
                                  name=None):
    r"""Applies set operation along last dimension of `Tensor` and `SparseTensor`.

  See SetOperationOp::SetOperationFromContext for values of `set_operation`.

  Input `set2` is a `SparseTensor` represented by `set2_indices`, `set2_values`,
  and `set2_shape`. For `set2` ranked `n`, 1st `n-1` dimensions must be the same
  as `set1`. Dimension `n` contains values in a set, duplicates are allowed but
  ignored.

  If `validate_indices` is `True`, this op validates the order and range of `set2`
  indices.

  Output `result` is a `SparseTensor` represented by `result_indices`,
  `result_values`, and `result_shape`. For `set1` and `set2` ranked `n`, this
  has rank `n` and the same 1st `n-1` dimensions as `set1` and `set2`. The `nth`
  dimension contains the result of `set_operation` applied to the corresponding
  `[0...n-1]` dimension of `set`.

  Args:
    set1: A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `string`.
      `Tensor` with rank `n`. 1st `n-1` dimensions must be the same as `set2`.
      Dimension `n` contains values in a set, duplicates are allowed but ignored.
    set2_indices: A `Tensor` of type `int64`.
      2D `Tensor`, indices of a `SparseTensor`. Must be in row-major
      order.
    set2_values: A `Tensor`. Must have the same type as `set1`.
      1D `Tensor`, values of a `SparseTensor`. Must be in row-major
      order.
    set2_shape: A `Tensor` of type `int64`.
      1D `Tensor`, shape of a `SparseTensor`. `set2_shape[0...n-1]` must
      be the same as the 1st `n-1` dimensions of `set1`, `result_shape[n]` is the
      max set size across `n-1` dimensions.
    set_operation: A `string`.
    validate_indices: An optional `bool`. Defaults to `True`.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (result_indices, result_values, result_shape).

    result_indices: A `Tensor` of type `int64`.
    result_values: A `Tensor`. Has the same type as `set1`.
    result_shape: A `Tensor` of type `int64`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "DenseToSparseSetOperation", name,
                _ctx._post_execution_callbacks, set1, set2_indices,
                set2_values, set2_shape, "set_operation", set_operation,
                "validate_indices", validate_indices)
            _result = _DenseToSparseSetOperationOutput._make(_result)
            return _result
        except _core._FallbackException:
            try:
                return dense_to_sparse_set_operation_eager_fallback(
                    set1,
                    set2_indices,
                    set2_values,
                    set2_shape,
                    set_operation=set_operation,
                    validate_indices=validate_indices,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    set_operation = _execute.make_str(set_operation, "set_operation")
    if validate_indices is None:
        validate_indices = True
    validate_indices = _execute.make_bool(validate_indices, "validate_indices")
    _, _, _op = _op_def_lib._apply_op_helper("DenseToSparseSetOperation",
                                             set1=set1,
                                             set2_indices=set2_indices,
                                             set2_values=set2_values,
                                             set2_shape=set2_shape,
                                             set_operation=set_operation,
                                             validate_indices=validate_indices,
                                             name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("set_operation", _op.get_attr("set_operation"),
              "validate_indices", _op.get_attr("validate_indices"), "T",
              _op.get_attr("T"))
    _execute.record_gradient("DenseToSparseSetOperation", _inputs_flat, _attrs,
                             _result, name)
    _result = _DenseToSparseSetOperationOutput._make(_result)
    return _result
コード例 #39
0
def rpc(address,
        method,
        request,
        protocol="",
        fail_fast=True,
        timeout_in_ms=0,
        name=None):
    r"""TODO: add doc.

  Args:
    address: A `Tensor` of type `string`.
    method: A `Tensor` of type `string`.
    request: A `Tensor` of type `string`.
    protocol: An optional `string`. Defaults to `""`.
    fail_fast: An optional `bool`. Defaults to `True`.
    timeout_in_ms: An optional `int`. Defaults to `0`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `string`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "Rpc", name, _ctx._post_execution_callbacks, address, method,
                request, "protocol", protocol, "fail_fast", fail_fast,
                "timeout_in_ms", timeout_in_ms)
            return _result
        except _core._FallbackException:
            try:
                return rpc_eager_fallback(address,
                                          method,
                                          request,
                                          protocol=protocol,
                                          fail_fast=fail_fast,
                                          timeout_in_ms=timeout_in_ms,
                                          name=name,
                                          ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
            except (TypeError, ValueError):
                result = _dispatch.dispatch(rpc,
                                            address=address,
                                            method=method,
                                            request=request,
                                            protocol=protocol,
                                            fail_fast=fail_fast,
                                            timeout_in_ms=timeout_in_ms,
                                            name=name)
                if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                    return result
                raise
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    if protocol is None:
        protocol = ""
    protocol = _execute.make_str(protocol, "protocol")
    if fail_fast is None:
        fail_fast = True
    fail_fast = _execute.make_bool(fail_fast, "fail_fast")
    if timeout_in_ms is None:
        timeout_in_ms = 0
    timeout_in_ms = _execute.make_int(timeout_in_ms, "timeout_in_ms")
    try:
        _, _, _op = _op_def_lib._apply_op_helper("Rpc",
                                                 address=address,
                                                 method=method,
                                                 request=request,
                                                 protocol=protocol,
                                                 fail_fast=fail_fast,
                                                 timeout_in_ms=timeout_in_ms,
                                                 name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(rpc,
                                    address=address,
                                    method=method,
                                    request=request,
                                    protocol=protocol,
                                    fail_fast=fail_fast,
                                    timeout_in_ms=timeout_in_ms,
                                    name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("protocol", _op.get_attr("protocol"), "fail_fast",
              _op.get_attr("fail_fast"), "timeout_in_ms",
              _op.get_attr("timeout_in_ms"))
    _execute.record_gradient("Rpc", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result
コード例 #40
0
ファイル: gen_resampler_ops.py プロジェクト: aMp37/SimpleHTR
def resampler_grad(data, warp, grad_output, name=None):
  r"""Resampler Grad op.

  Args:
    data: A `Tensor`. Must be one of the following types: `half`, `bfloat16`, `float32`, `float64`.
    warp: A `Tensor`. Must have the same type as `data`.
    grad_output: A `Tensor`. Must have the same type as `data`.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (grad_data, grad_warp).

    grad_data: A `Tensor`. Has the same type as `data`.
    grad_warp: A `Tensor`. Has the same type as `data`.
  """
  _ctx = _context._context or _context.context()
  if _ctx is not None and _ctx._thread_local_data.is_eager:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._thread_local_data.device_name,
        "ResamplerGrad", name, _ctx.post_execution_callbacks, data, warp,
        grad_output)
      _result = _ResamplerGradOutput._make(_result)
      return _result
    except _core._FallbackException:
      try:
        return resampler_grad_eager_fallback(
            data, warp, grad_output, name=name, ctx=_ctx)
      except _core._SymbolicException:
        pass  # Add nodes to the TensorFlow graph.
      except (TypeError, ValueError):
        result = _dispatch.dispatch(
              resampler_grad, data=data, warp=warp, grad_output=grad_output,
                              name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
          return result
        raise
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
  # Add nodes to the TensorFlow graph.
  try:
    _, _, _op = _op_def_lib._apply_op_helper(
        "ResamplerGrad", data=data, warp=warp, grad_output=grad_output,
                         name=name)
  except (TypeError, ValueError):
    result = _dispatch.dispatch(
          resampler_grad, data=data, warp=warp, grad_output=grad_output,
                          name=name)
    if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
      return result
    raise
  _result = _op.outputs[:]
  _inputs_flat = _op.inputs
  _attrs = ("T", _op._get_attr_type("T"))
  _execute.record_gradient(
      "ResamplerGrad", _inputs_flat, _attrs, _result, name)
  _result = _ResamplerGradOutput._make(_result)
  return _result
コード例 #41
0
def batch(in_tensors, num_batch_threads, max_batch_size, batch_timeout_micros, grad_timeout_micros, max_enqueued_batches=10, allowed_batch_sizes=[], container="", shared_name="", batching_queue="", name=None):
  r"""Batches all input tensors nondeterministically.

  When many instances of this Op are being run concurrently with the same
  container/shared_name in the same device, some will output zero-shaped Tensors
  and others will output Tensors of size up to max_batch_size.

  All Tensors in in_tensors are batched together (so, for example, labels and
  features should be batched with a single instance of this operation.

  Each invocation of batch emits an `id` scalar which will be used to identify
  this particular invocation when doing unbatch or its gradient.

  Each op which emits a non-empty batch will also emit a non-empty batch_index
  Tensor, which, is a [K, 3] matrix where each row contains the invocation's id,
  start, and length of elements of each set of Tensors present in batched_tensors.

  Batched tensors are concatenated along the first dimension, and all tensors in
  in_tensors must have the first dimension of the same size.

  in_tensors: The tensors to be batched.
  num_batch_threads: Number of scheduling threads for processing batches of work.
   Determines the number of batches processed in parallel.
  max_batch_size: Batch sizes will never be bigger than this.
  batch_timeout_micros: Maximum number of microseconds to wait before outputting
   an incomplete batch.
  allowed_batch_sizes: Optional list of allowed batch sizes. If left empty, does
   nothing. Otherwise, supplies a list of batch sizes, causing the op to pad
   batches up to one of those sizes. The entries must increase monotonically, and
   the final entry must equal max_batch_size.
  grad_timeout_micros: The timeout to use for the gradient. See Unbatch.
  batched_tensors: Either empty tensors or a batch of concatenated Tensors.
  batch_index: If out_tensors is non-empty, has information to invert it.
  container: Controls the scope of sharing of this batch.
  id: always contains a scalar with a unique ID for this invocation of Batch.
  shared_name: Concurrently running instances of batch in the same device with the
   same container and shared_name will batch their elements together. If left
   empty, the op name will be used as the shared name.
  T: the types of tensors to be batched.

  Args:
    in_tensors: A list of `Tensor` objects.
    num_batch_threads: An `int`.
    max_batch_size: An `int`.
    batch_timeout_micros: An `int`.
    grad_timeout_micros: An `int`.
    max_enqueued_batches: An optional `int`. Defaults to `10`.
    allowed_batch_sizes: An optional list of `ints`. Defaults to `[]`.
    container: An optional `string`. Defaults to `""`.
    shared_name: An optional `string`. Defaults to `""`.
    batching_queue: An optional `string`. Defaults to `""`.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (batched_tensors, batch_index, id).

    batched_tensors: A list of `Tensor` objects. Has the same type as `in_tensors`.
    batch_index: A `Tensor` of type `int64`.
    id: A `Tensor` of type `int64`.
  """
  _ctx = _context._context
  if _ctx is not None and _ctx._eager_context.is_eager:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name, "Batch", name,
        _ctx._post_execution_callbacks, in_tensors, "num_batch_threads",
        num_batch_threads, "max_batch_size", max_batch_size,
        "max_enqueued_batches", max_enqueued_batches, "batch_timeout_micros",
        batch_timeout_micros, "allowed_batch_sizes", allowed_batch_sizes,
        "grad_timeout_micros", grad_timeout_micros, "container", container,
        "shared_name", shared_name, "batching_queue", batching_queue)
      _result = _BatchOutput._make(_result)
      return _result
    except _core._FallbackException:
      try:
        return batch_eager_fallback(
            in_tensors, num_batch_threads=num_batch_threads,
            max_batch_size=max_batch_size,
            max_enqueued_batches=max_enqueued_batches,
            batch_timeout_micros=batch_timeout_micros,
            allowed_batch_sizes=allowed_batch_sizes,
            grad_timeout_micros=grad_timeout_micros, container=container,
            shared_name=shared_name, batching_queue=batching_queue, name=name,
            ctx=_ctx)
      except _core._SymbolicException:
        pass  # Add nodes to the TensorFlow graph.
      except (TypeError, ValueError):
        result = _dispatch.dispatch(
              batch, in_tensors=in_tensors,
                     num_batch_threads=num_batch_threads,
                     max_batch_size=max_batch_size,
                     batch_timeout_micros=batch_timeout_micros,
                     grad_timeout_micros=grad_timeout_micros,
                     max_enqueued_batches=max_enqueued_batches,
                     allowed_batch_sizes=allowed_batch_sizes,
                     container=container, shared_name=shared_name,
                     batching_queue=batching_queue, name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
          return result
        raise
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
  # Add nodes to the TensorFlow graph.
  num_batch_threads = _execute.make_int(num_batch_threads, "num_batch_threads")
  max_batch_size = _execute.make_int(max_batch_size, "max_batch_size")
  batch_timeout_micros = _execute.make_int(batch_timeout_micros, "batch_timeout_micros")
  grad_timeout_micros = _execute.make_int(grad_timeout_micros, "grad_timeout_micros")
  if max_enqueued_batches is None:
    max_enqueued_batches = 10
  max_enqueued_batches = _execute.make_int(max_enqueued_batches, "max_enqueued_batches")
  if allowed_batch_sizes is None:
    allowed_batch_sizes = []
  if not isinstance(allowed_batch_sizes, (list, tuple)):
    raise TypeError(
        "Expected list for 'allowed_batch_sizes' argument to "
        "'batch' Op, not %r." % allowed_batch_sizes)
  allowed_batch_sizes = [_execute.make_int(_i, "allowed_batch_sizes") for _i in allowed_batch_sizes]
  if container is None:
    container = ""
  container = _execute.make_str(container, "container")
  if shared_name is None:
    shared_name = ""
  shared_name = _execute.make_str(shared_name, "shared_name")
  if batching_queue is None:
    batching_queue = ""
  batching_queue = _execute.make_str(batching_queue, "batching_queue")
  try:
    _, _, _op = _op_def_lib._apply_op_helper(
        "Batch", in_tensors=in_tensors, num_batch_threads=num_batch_threads,
                 max_batch_size=max_batch_size,
                 batch_timeout_micros=batch_timeout_micros,
                 grad_timeout_micros=grad_timeout_micros,
                 max_enqueued_batches=max_enqueued_batches,
                 allowed_batch_sizes=allowed_batch_sizes, container=container,
                 shared_name=shared_name, batching_queue=batching_queue,
                 name=name)
  except (TypeError, ValueError):
    result = _dispatch.dispatch(
          batch, in_tensors=in_tensors, num_batch_threads=num_batch_threads,
                 max_batch_size=max_batch_size,
                 batch_timeout_micros=batch_timeout_micros,
                 grad_timeout_micros=grad_timeout_micros,
                 max_enqueued_batches=max_enqueued_batches,
                 allowed_batch_sizes=allowed_batch_sizes, container=container,
                 shared_name=shared_name, batching_queue=batching_queue,
                 name=name)
    if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
      return result
    raise
  _result = _op.outputs[:]
  _inputs_flat = _op.inputs
  _attrs = ("num_batch_threads", _op.get_attr("num_batch_threads"),
            "max_batch_size", _op.get_attr("max_batch_size"),
            "max_enqueued_batches", _op.get_attr("max_enqueued_batches"),
            "batch_timeout_micros", _op.get_attr("batch_timeout_micros"),
            "allowed_batch_sizes", _op.get_attr("allowed_batch_sizes"),
            "grad_timeout_micros", _op.get_attr("grad_timeout_micros"),
            "container", _op.get_attr("container"), "shared_name",
            _op.get_attr("shared_name"), "batching_queue",
            _op.get_attr("batching_queue"), "T", _op.get_attr("T"))
  _execute.record_gradient(
      "Batch", _inputs_flat, _attrs, _result, name)
  _result = [_result[:len(in_tensors)]] + _result[len(in_tensors):]
  _result = _BatchOutput._make(_result)
  return _result
コード例 #42
0
def unbatch_grad(original_input, batch_index, grad, id, container="", shared_name="", name=None):
  r"""Gradient of Unbatch.

  Acts like Batch but using the given batch_index index of batching things as they
  become available. This ensures that the gradients are propagated back in the
  same session which did the forward pass.

  original_input: The input to the Unbatch operation this is the gradient of.
  batch_index: The batch_index given to the Unbatch operation this is the gradient
  of.
  grad: The downstream gradient.
  id: The id scalar emitted by Batch.
  batched_grad: The return value, either an empty tensor or the batched gradient.
  container: Container to control resource sharing.
  shared_name: Instances of UnbatchGrad with the same container and shared_name
   are assumed to possibly belong to the same batch. If left empty, the op name
   will be used as the shared name.

  Args:
    original_input: A `Tensor`.
    batch_index: A `Tensor` of type `int64`.
    grad: A `Tensor`. Must have the same type as `original_input`.
    id: A `Tensor` of type `int64`.
    container: An optional `string`. Defaults to `""`.
    shared_name: An optional `string`. Defaults to `""`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `original_input`.
  """
  _ctx = _context._context
  if _ctx is not None and _ctx._eager_context.is_eager:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name, "UnbatchGrad",
        name, _ctx._post_execution_callbacks, original_input, batch_index,
        grad, id, "container", container, "shared_name", shared_name)
      return _result
    except _core._FallbackException:
      try:
        return unbatch_grad_eager_fallback(
            original_input, batch_index, grad, id, container=container,
            shared_name=shared_name, name=name, ctx=_ctx)
      except _core._SymbolicException:
        pass  # Add nodes to the TensorFlow graph.
      except (TypeError, ValueError):
        result = _dispatch.dispatch(
              unbatch_grad, original_input=original_input,
                            batch_index=batch_index, grad=grad, id=id,
                            container=container, shared_name=shared_name,
                            name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
          return result
        raise
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
  # Add nodes to the TensorFlow graph.
  if container is None:
    container = ""
  container = _execute.make_str(container, "container")
  if shared_name is None:
    shared_name = ""
  shared_name = _execute.make_str(shared_name, "shared_name")
  try:
    _, _, _op = _op_def_lib._apply_op_helper(
        "UnbatchGrad", original_input=original_input, batch_index=batch_index,
                       grad=grad, id=id, container=container,
                       shared_name=shared_name, name=name)
  except (TypeError, ValueError):
    result = _dispatch.dispatch(
          unbatch_grad, original_input=original_input,
                        batch_index=batch_index, grad=grad, id=id,
                        container=container, shared_name=shared_name,
                        name=name)
    if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
      return result
    raise
  _result = _op.outputs[:]
  _inputs_flat = _op.inputs
  _attrs = ("container", _op.get_attr("container"), "shared_name",
            _op.get_attr("shared_name"), "T", _op.get_attr("T"))
  _execute.record_gradient(
      "UnbatchGrad", _inputs_flat, _attrs, _result, name)
  _result, = _result
  return _result
コード例 #43
0
def reduce_slice_sum(data, indices, axis, name=None):
    r"""Dynamically sum over the first dimension of a tensor according to start and end

  indices specified at 'index'.

  For example:

  ```prettyprint
  # if 'data' is [[   1,   2,   3]
                  [  40,  50,  60]
                  [ 700, 800, 900]
                  [1000,2000,3000]],

  and 'indices' is [[0,1]
                    [1,1]
                    [0,2]],

  the output will be [[ 1, 2, 3]
                      [ 0, 0, 0]
                      [41,52,63]].
  ```

  The data must be at least rank 1. The indices must be of shape (?,2) where the
  first column is start indices and the second column is end indices. The end indices
  are not included in the reduce operation, which means, if you want to do a reduce
  over indices 0,1,2, then you should have start index 0 and end index 3. If end
  index is smaller than or equal to start, the result will be zero. If end index is
  out of bounds, then the reduce operation will automatically stop at the bound, so
  feel free to put a large number as your end of your index if you want to do the
  reduction until the bound.

  Args:
    data: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `complex64`, `int64`, `qint8`, `quint8`, `qint32`, `bfloat16`, `uint16`, `complex128`, `half`, `uint32`, `uint64`.
      The source of data where the computation will be taken from.
    indices: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      start, end indices that controls which part to be included.
    axis: A `Tensor` of type `int64`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `data`. the computed sum values.
  """
    _ctx = _context._context
    if _ctx is not None and _ctx._eager_context.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._eager_context.device_name,
                "ReduceSliceSum", name, _ctx._post_execution_callbacks, data,
                indices, axis)
            return _result
        except _core._FallbackException:
            try:
                return reduce_slice_sum_eager_fallback(data,
                                                       indices,
                                                       axis,
                                                       name=name,
                                                       ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
            except (TypeError, ValueError):
                result = _dispatch.dispatch(reduce_slice_sum,
                                            data=data,
                                            indices=indices,
                                            axis=axis,
                                            name=name)
                if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                    return result
                raise
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    try:
        _, _, _op = _op_def_lib._apply_op_helper("ReduceSliceSum",
                                                 data=data,
                                                 indices=indices,
                                                 axis=axis,
                                                 name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(reduce_slice_sum,
                                    data=data,
                                    indices=indices,
                                    axis=axis,
                                    name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"), "Tindices", _op.get_attr("Tindices"))
    _execute.record_gradient("ReduceSliceSum", _inputs_flat, _attrs, _result,
                             name)
    _result, = _result
    return _result
コード例 #44
0
def audio_spectrogram(input, window_size, stride, magnitude_squared=False, name=None):
  r"""Produces a visualization of audio data over time.

  Spectrograms are a standard way of representing audio information as a series of
  slices of frequency information, one slice for each window of time. By joining
  these together into a sequence, they form a distinctive fingerprint of the sound
  over time.

  This op expects to receive audio data as an input, stored as floats in the range
  -1 to 1, together with a window width in samples, and a stride specifying how
  far to move the window between slices. From this it generates a three
  dimensional output. The lowest dimension has an amplitude value for each
  frequency during that time slice. The next dimension is time, with successive
  frequency slices. The final dimension is for the channels in the input, so a
  stereo audio input would have two here for example.

  This means the layout when converted and saved as an image is rotated 90 degrees
  clockwise from a typical spectrogram. Time is descending down the Y axis, and
  the frequency decreases from left to right.

  Each value in the result represents the square root of the sum of the real and
  imaginary parts of an FFT on the current window of samples. In this way, the
  lowest dimension represents the power of each frequency in the current window,
  and adjacent windows are concatenated in the next dimension.

  To get a more intuitive and visual look at what this operation does, you can run
  tensorflow/examples/wav_to_spectrogram to read in an audio file and save out the
  resulting spectrogram as a PNG image.

  Args:
    input: A `Tensor` of type `float32`. Float representation of audio data.
    window_size: An `int`.
      How wide the input window is in samples. For the highest efficiency
      this should be a power of two, but other values are accepted.
    stride: An `int`.
      How widely apart the center of adjacent sample windows should be.
    magnitude_squared: An optional `bool`. Defaults to `False`.
      Whether to return the squared magnitude or just the
      magnitude. Using squared magnitude can avoid extra calculations.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `float32`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    window_size = _execute.make_int(window_size, "window_size")
    stride = _execute.make_int(stride, "stride")
    if magnitude_squared is None:
      magnitude_squared = False
    magnitude_squared = _execute.make_bool(magnitude_squared, "magnitude_squared")
    _, _, _op = _op_def_lib._apply_op_helper(
        "AudioSpectrogram", input=input, window_size=window_size,
        stride=stride, magnitude_squared=magnitude_squared, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("window_size", _op.get_attr("window_size"), "stride",
              _op.get_attr("stride"), "magnitude_squared",
              _op.get_attr("magnitude_squared"))
    _execute.record_gradient(
      "AudioSpectrogram", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "AudioSpectrogram", name, _ctx._post_execution_callbacks, input,
        "window_size", window_size, "stride", stride, "magnitude_squared",
        magnitude_squared)
      return _result
    except _core._FallbackException:
      return audio_spectrogram_eager_fallback(
          input, window_size=window_size, stride=stride,
          magnitude_squared=magnitude_squared, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #45
0
def periodic_resample(values, shape, name=None):
  r"""Periodically resample elements of a tensor to conform to `shape`.

  This function implements a slightly more generic version of the subpixel
  convolutions found in this [paper](https://arxiv.org/abs/1609.05158).

  The formula for computing the elements in the `output` tensor is as follows:

    `T` = `values` tensor of rank `R`

    `S` = desired `shape` of output tensor (vector of length `R`)

    `P` = `output` tensor of rank `R`

    \\((T_1,\\ldots,T_R)\\) = shape(`T`)

    \\([S_1,\\ldots,S_q,\\ldots,S_R]\\) = elements of vector `S`

    A single element in `S` is left unspecified (denoted \\(S_q=-1\\)).

    Let \\(f_i\\) denote the (possibly non-integer) factor that relates the original
    dimension to the desired dimensions, \\(S_i=f_i T_i\\), for \\(i\\neq q\\) where
    \\(f_i>0\\).

    Define the following:

    \\(g_i=\\lceil f_i\\rceil\\)

    \\(t=\\prod_i T_i\\)

    \\(s=\\prod_{i\\neq q} S_i\\)

    \\(S_q\\) can then be defined by \\(S_q=\\lfloor t/s\\rfloor\\).
    The elements of the resulting tensor are defined as

    \\(P_{s_1,\\ldots,s_R}=T_{h_1,\\ldots,h_q,\\ldots,h_R}\\).

    The \\(h_i\\) (\\(i\\neq q\\)) are defined by \\(h_i=\\lfloor s_i/g_i\\rfloor\\).

    \\(h_q=S_q\\sum_{j\\neq q}^{q-1}G_j \\mathrm{mod}(s_j,g_j) + s_q\\), where
    \\(G_j=\\prod_{i}^{j-1}g_i\\) (\\(G_0=1\\)).

  One drawback of this method is that whenever the output dimensions are slightly
  less than integer multiples of the input dimensions, many of the tensor elements
  are repeated in an inefficient way. This is resolved by specifying that all
  desired dimensions are integer multiples of the input tensor.

  For example:

  ```prettyprint
  `input` is [[ 0  1  2  3]
              [ 4  5  6  7]
              [ 8  9 10 11]]

  tf.periodic_resample(input, [6, None]) ==> [[ 0  1]
                                              [ 2  3]
                                              [ 4  5]
                                              [ 6  7]
                                              [ 8  9]
                                              [10 11]]
  ```

  Args:
    values: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `complex64`, `int64`, `qint8`, `quint8`, `qint32`, `bfloat16`, `uint16`, `complex128`, `half`, `uint32`, `uint64`.
      The tensor of rank `R` to periodic_resample
    shape: A `tf.TensorShape` or list of `ints`.
      A 1-D tensor representing the desired shape of the output tensor.
      Exactly one element of this tensor must have the value `None` which represents
      that this dimension of `values` can be adjusted downward in order to
      accommodate increases in other dimensions. The specified sizes of the
      non-adjustable dimensions must by at least as large as in the `values` tensor.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `values`.
    Periodically resampled tensor that has dimensions specified as in
    `shape` except that the dimension specified as `None` will be minimally
    decreased as necessary.
  """
  _ctx = _context._context
  if _ctx is not None and _ctx._eager_context.is_eager:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "PeriodicResample", name, _ctx._post_execution_callbacks, values,
        "shape", shape)
      return _result
    except _core._FallbackException:
      try:
        return periodic_resample_eager_fallback(
            values, shape=shape, name=name, ctx=_ctx)
      except _core._SymbolicException:
        pass  # Add nodes to the TensorFlow graph.
      except (TypeError, ValueError):
        result = _dispatch.dispatch(
              periodic_resample, values=values, shape=shape, name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
          return result
        raise
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
  # Add nodes to the TensorFlow graph.
  shape = _execute.make_shape(shape, "shape")
  try:
    _, _, _op = _op_def_lib._apply_op_helper(
        "PeriodicResample", values=values, shape=shape, name=name)
  except (TypeError, ValueError):
    result = _dispatch.dispatch(
          periodic_resample, values=values, shape=shape, name=name)
    if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
      return result
    raise
  _result = _op.outputs[:]
  _inputs_flat = _op.inputs
  _attrs = ("T", _op.get_attr("T"), "shape", _op.get_attr("shape"))
  _execute.record_gradient(
      "PeriodicResample", _inputs_flat, _attrs, _result, name)
  _result, = _result
  return _result
コード例 #46
0
def stateless_truncated_normal(shape, seed, dtype=_dtypes.float32, name=None):
    r"""Outputs deterministic pseudorandom values from a truncated normal distribution.

  The generated values follow a normal distribution with mean 0 and standard

  deviation 1, except that values whose magnitude is more than 2 standard

  deviations from the mean are dropped and re-picked.

  

  The outputs are a deterministic function of `shape` and `seed`.

  Args:
    shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      The shape of the output tensor.
    seed: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      2 seeds (shape [2]).
    dtype: An optional `tf.DType` from: `tf.half, tf.bfloat16, tf.float32, tf.float64`. Defaults to `tf.float32`.
      The type of the output.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `dtype`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "StatelessTruncatedNormal", name,
                _ctx._post_execution_callbacks, shape, seed, "dtype", dtype)
            return _result
        except _core._FallbackException:
            try:
                return stateless_truncated_normal_eager_fallback(shape,
                                                                 seed,
                                                                 dtype=dtype,
                                                                 name=name,
                                                                 ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    if dtype is None:
        dtype = _dtypes.float32
    dtype = _execute.make_type(dtype, "dtype")
    _, _, _op = _op_def_lib._apply_op_helper("StatelessTruncatedNormal",
                                             shape=shape,
                                             seed=seed,
                                             dtype=dtype,
                                             name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("dtype", _op.get_attr("dtype"), "T", _op.get_attr("T"), "Tseed",
              _op.get_attr("Tseed"))
    _execute.record_gradient("StatelessTruncatedNormal", _inputs_flat, _attrs,
                             _result, name)
    _result, = _result
    return _result
コード例 #47
0
ファイル: gen_training_ops.py プロジェクト: whqkdhfh13/sswp
def grow_tree_ensemble(tree_ensemble_handle, stamp_token, next_stamp_token, learning_rate, dropout_seed, max_tree_depth, weak_learner_type, partition_ids, gains, splits, learner_config, center_bias, name=None):
  r"""Grows the tree ensemble by either adding a layer to the last tree being grown

  or by starting a new tree.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
      Handle to the ensemble variable.
    stamp_token: A `Tensor` of type `int64`.
      Stamp token for validating operation consistency.
    next_stamp_token: A `Tensor` of type `int64`.
      Stamp token to be used for the next iteration.
    learning_rate: A `Tensor` of type `float32`. Scalar learning rate.
    dropout_seed: A `Tensor` of type `int64`.
    max_tree_depth: A `Tensor` of type `int32`.
    weak_learner_type: A `Tensor` of type `int32`.
      The type of weak learner to use.
    partition_ids: A list of `Tensor` objects with type `int32`.
      List of Rank 1 Tensors containing partition Id per candidate.
    gains: A list with the same length as `partition_ids` of `Tensor` objects with type `float32`.
      List of Rank 1 Tensors containing gains per candidate.
    splits: A list with the same length as `partition_ids` of `Tensor` objects with type `string`.
      List of Rank 1 Tensors containing serialized SplitInfo protos per candidate.
    learner_config: A `string`.
      Config for the learner of type LearnerConfig proto.
    center_bias: A `bool`.
    name: A name for the operation (optional).

  Returns:
    The created Operation.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    if not isinstance(partition_ids, (list, tuple)):
      raise TypeError(
          "Expected list for 'partition_ids' argument to "
          "'grow_tree_ensemble' Op, not %r." % partition_ids)
    _attr_num_handlers = len(partition_ids)
    if not isinstance(gains, (list, tuple)):
      raise TypeError(
          "Expected list for 'gains' argument to "
          "'grow_tree_ensemble' Op, not %r." % gains)
    if len(gains) != _attr_num_handlers:
      raise ValueError(
          "List argument 'gains' to 'grow_tree_ensemble' Op with length %d "
          "must match length %d of argument 'partition_ids'." %
          (len(gains), _attr_num_handlers))
    if not isinstance(splits, (list, tuple)):
      raise TypeError(
          "Expected list for 'splits' argument to "
          "'grow_tree_ensemble' Op, not %r." % splits)
    if len(splits) != _attr_num_handlers:
      raise ValueError(
          "List argument 'splits' to 'grow_tree_ensemble' Op with length %d "
          "must match length %d of argument 'partition_ids'." %
          (len(splits), _attr_num_handlers))
    learner_config = _execute.make_str(learner_config, "learner_config")
    center_bias = _execute.make_bool(center_bias, "center_bias")
    _, _, _op = _op_def_lib._apply_op_helper(
        "GrowTreeEnsemble", tree_ensemble_handle=tree_ensemble_handle,
        stamp_token=stamp_token, next_stamp_token=next_stamp_token,
        learning_rate=learning_rate, dropout_seed=dropout_seed,
        max_tree_depth=max_tree_depth, weak_learner_type=weak_learner_type,
        partition_ids=partition_ids, gains=gains, splits=splits,
        learner_config=learner_config, center_bias=center_bias, name=name)
    return _op
    _result = None
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "GrowTreeEnsemble", name, _ctx._post_execution_callbacks,
        tree_ensemble_handle, stamp_token, next_stamp_token, learning_rate,
        dropout_seed, max_tree_depth, weak_learner_type, partition_ids, gains,
        splits, "learner_config", learner_config, "center_bias", center_bias)
      return _result
    except _core._FallbackException:
      return grow_tree_ensemble_eager_fallback(
          tree_ensemble_handle, stamp_token, next_stamp_token, learning_rate,
          dropout_seed, max_tree_depth, weak_learner_type, partition_ids,
          gains, splits, learner_config=learner_config,
          center_bias=center_bias, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #48
0
def single_image_random_dot_stereograms(depth_values, hidden_surface_removal=True, convergence_dots_size=8, dots_per_inch=72, eye_separation=2.5, mu=0.3333, normalize=True, normalize_max=-100, normalize_min=100, border_level=0, number_colors=256, output_image_shape=[1024, 768, 1], output_data_window=[1022, 757], name=None):
  r"""Outputs a single image random dot stereogram for export via encode_PNG/JPG OP.

  Given the 2-D tensor 'depth_values' with encoded Z values, this operation will
  encode 3-D data into a 2-D image.  The output of this Op is suitable for the
  encode_PNG/JPG ops.  Be careful with image compression as this may corrupt the
  encode 3-D data within the image.

  This Op is based upon:
  'http://www.learningace.com/doc/4331582/b6ab058d1e206d68ab60e4e1ead2fe6e/sirds-paper'

  Example use which outputs a SIRDS image as picture_out.png:
  ```python
  img=[[1,2,3,3,2,1],
       [1,2,3,4,5,2],
       [1,2,3,4,5,3],
       [1,2,3,4,5,4],
       [6,5,4,4,5,5]]

  session = tf.InteractiveSession()

  sirds = single_image_random_dot_stereograms(img,convergence_dots_size=8,number_colors=256,normalize=True)

  out = sirds.eval()

  png = tf.image.encode_png(out).eval()

  with open('picture_out.png', 'wb') as f:
      f.write(png)
  ```

  Args:
    depth_values: A `Tensor`. Must be one of the following types: `float64`, `float32`, `int64`, `int32`.
      Z values of data to encode into 'output_data_window' window,
      lower values are further away {0.0 floor(far), 1.0 ceiling(near) after normalization}, must be 2-D tensor
    hidden_surface_removal: An optional `bool`. Defaults to `True`.
      Activate hidden surface removal
    convergence_dots_size: An optional `int`. Defaults to `8`.
      Black dot size in pixels to help view converge image, drawn on bottom of image
    dots_per_inch: An optional `int`. Defaults to `72`.
      Output device in dots/inch
    eye_separation: An optional `float`. Defaults to `2.5`.
      Separation between eyes in inches
    mu: An optional `float`. Defaults to `0.3333`.
      Depth of field, Fraction of viewing distance (eg. 1/3 = .3333)
    normalize: An optional `bool`. Defaults to `True`.
      Normalize input data to [0.0, 1.0]
    normalize_max: An optional `float`. Defaults to `-100`.
      Fix MAX value for Normalization - if < MIN, autoscale
    normalize_min: An optional `float`. Defaults to `100`.
      Fix MIN value for Normalization - if > MAX, autoscale
    border_level: An optional `float`. Defaults to `0`.
      Value of border depth 0.0 {far} to 1.0 {near}
    number_colors: An optional `int`. Defaults to `256`.
      2 (Black & White),256 (grayscale), and Numbers > 256 (Full Color) are all that are supported currently
    output_image_shape: An optional `tf.TensorShape` or list of `ints`. Defaults to `[1024, 768, 1]`.
      Output size of returned image in X,Y, Channels 1-grayscale, 3 color (1024, 768, 1),
      channels will be updated to 3 if 'number_colors' > 256
    output_data_window: An optional `tf.TensorShape` or list of `ints`. Defaults to `[1022, 757]`.
      Size of "DATA" window, must be equal to or smaller than 'output_image_shape', will be centered
      and use 'convergence_dots_size' for best fit to avoid overlap if possible
    name: A name for the operation (optional).

  Returns:
    A tensor of size 'output_image_shape' with the encoded 'depth_values'
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    if hidden_surface_removal is None:
      hidden_surface_removal = True
    hidden_surface_removal = _execute.make_bool(hidden_surface_removal, "hidden_surface_removal")
    if convergence_dots_size is None:
      convergence_dots_size = 8
    convergence_dots_size = _execute.make_int(convergence_dots_size, "convergence_dots_size")
    if dots_per_inch is None:
      dots_per_inch = 72
    dots_per_inch = _execute.make_int(dots_per_inch, "dots_per_inch")
    if eye_separation is None:
      eye_separation = 2.5
    eye_separation = _execute.make_float(eye_separation, "eye_separation")
    if mu is None:
      mu = 0.3333
    mu = _execute.make_float(mu, "mu")
    if normalize is None:
      normalize = True
    normalize = _execute.make_bool(normalize, "normalize")
    if normalize_max is None:
      normalize_max = -100
    normalize_max = _execute.make_float(normalize_max, "normalize_max")
    if normalize_min is None:
      normalize_min = 100
    normalize_min = _execute.make_float(normalize_min, "normalize_min")
    if border_level is None:
      border_level = 0
    border_level = _execute.make_float(border_level, "border_level")
    if number_colors is None:
      number_colors = 256
    number_colors = _execute.make_int(number_colors, "number_colors")
    if output_image_shape is None:
      output_image_shape = [1024, 768, 1]
    output_image_shape = _execute.make_shape(output_image_shape, "output_image_shape")
    if output_data_window is None:
      output_data_window = [1022, 757]
    output_data_window = _execute.make_shape(output_data_window, "output_data_window")
    _, _, _op = _op_def_lib._apply_op_helper(
        "SingleImageRandomDotStereograms", depth_values=depth_values,
        hidden_surface_removal=hidden_surface_removal,
        convergence_dots_size=convergence_dots_size,
        dots_per_inch=dots_per_inch, eye_separation=eye_separation, mu=mu,
        normalize=normalize, normalize_max=normalize_max,
        normalize_min=normalize_min, border_level=border_level,
        number_colors=number_colors, output_image_shape=output_image_shape,
        output_data_window=output_data_window, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"), "hidden_surface_removal",
              _op.get_attr("hidden_surface_removal"), "convergence_dots_size",
              _op.get_attr("convergence_dots_size"), "dots_per_inch",
              _op.get_attr("dots_per_inch"), "eye_separation",
              _op.get_attr("eye_separation"), "mu", _op.get_attr("mu"),
              "normalize", _op.get_attr("normalize"), "normalize_max",
              _op.get_attr("normalize_max"), "normalize_min",
              _op.get_attr("normalize_min"), "border_level",
              _op.get_attr("border_level"), "number_colors",
              _op.get_attr("number_colors"), "output_image_shape",
              _op.get_attr("output_image_shape"), "output_data_window",
              _op.get_attr("output_data_window"))
    _execute.record_gradient(
      "SingleImageRandomDotStereograms", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "SingleImageRandomDotStereograms", name,
        _ctx._post_execution_callbacks, depth_values,
        "hidden_surface_removal", hidden_surface_removal,
        "convergence_dots_size", convergence_dots_size, "dots_per_inch",
        dots_per_inch, "eye_separation", eye_separation, "mu", mu,
        "normalize", normalize, "normalize_max", normalize_max,
        "normalize_min", normalize_min, "border_level", border_level,
        "number_colors", number_colors, "output_image_shape",
        output_image_shape, "output_data_window", output_data_window)
      return _result
    except _core._FallbackException:
      return single_image_random_dot_stereograms_eager_fallback(
          depth_values, hidden_surface_removal=hidden_surface_removal,
          convergence_dots_size=convergence_dots_size,
          dots_per_inch=dots_per_inch, eye_separation=eye_separation, mu=mu,
          normalize=normalize, normalize_max=normalize_max,
          normalize_min=normalize_min, border_level=border_level,
          number_colors=number_colors, output_image_shape=output_image_shape,
          output_data_window=output_data_window, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #49
0
ファイル: gen_training_ops.py プロジェクト: whqkdhfh13/sswp
def center_tree_ensemble_bias(tree_ensemble_handle, stamp_token, next_stamp_token, delta_updates, learner_config, centering_epsilon=0.01, name=None):
  r"""Centers the tree ensemble bias before adding trees based on feature splits.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
      Handle to the ensemble variable.
    stamp_token: A `Tensor` of type `int64`.
      Stamp token for validating operation consistency.
    next_stamp_token: A `Tensor` of type `int64`.
      Stamp token to be used for the next iteration.
    delta_updates: A `Tensor` of type `float32`.
      Rank 1 Tensor containing delta updates per bias dimension.
    learner_config: A `string`.
      Config for the learner of type LearnerConfig proto.
    centering_epsilon: An optional `float`. Defaults to `0.01`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `bool`.
    Scalar indicating whether more centering is needed.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    learner_config = _execute.make_str(learner_config, "learner_config")
    if centering_epsilon is None:
      centering_epsilon = 0.01
    centering_epsilon = _execute.make_float(centering_epsilon, "centering_epsilon")
    _, _, _op = _op_def_lib._apply_op_helper(
        "CenterTreeEnsembleBias", tree_ensemble_handle=tree_ensemble_handle,
        stamp_token=stamp_token, next_stamp_token=next_stamp_token,
        delta_updates=delta_updates, learner_config=learner_config,
        centering_epsilon=centering_epsilon, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("learner_config", _op.get_attr("learner_config"),
              "centering_epsilon", _op.get_attr("centering_epsilon"))
    _execute.record_gradient(
      "CenterTreeEnsembleBias", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "CenterTreeEnsembleBias", name, _ctx._post_execution_callbacks,
        tree_ensemble_handle, stamp_token, next_stamp_token, delta_updates,
        "learner_config", learner_config, "centering_epsilon",
        centering_epsilon)
      return _result
    except _core._FallbackException:
      return center_tree_ensemble_bias_eager_fallback(
          tree_ensemble_handle, stamp_token, next_stamp_token, delta_updates,
          learner_config=learner_config, centering_epsilon=centering_epsilon,
          name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #50
0
def sparse_feature_cross(indices, values, shapes, dense, hashed_output, num_buckets, out_type, internal_type, name=None):
  r"""Generates sparse cross form a list of sparse tensors.

  The op takes two lists, one of 2D `SparseTensor` and one of 2D `Tensor`, each
  representing features of one feature column. It outputs a 2D `SparseTensor` with
  the batchwise crosses of these features.

  For example, if the inputs are

      inputs[0]: SparseTensor with shape = [2, 2]
      [0, 0]: "a"
      [1, 0]: "b"
      [1, 1]: "c"

      inputs[1]: SparseTensor with shape = [2, 1]
      [0, 0]: "d"
      [1, 0]: "e"

      inputs[2]: Tensor [["f"], ["g"]]

  then the output will be

      shape = [2, 2]
      [0, 0]: "a_X_d_X_f"
      [1, 0]: "b_X_e_X_g"
      [1, 1]: "c_X_e_X_g"

  if hashed_output=true then the output will be

      shape = [2, 2]
      [0, 0]: HashCombine(
                  Fingerprint64("f"), HashCombine(
                      Fingerprint64("d"), Fingerprint64("a")))
      [1, 0]: HashCombine(
                  Fingerprint64("g"), HashCombine(
                      Fingerprint64("e"), Fingerprint64("b")))
      [1, 1]: HashCombine(
                  Fingerprint64("g"), HashCombine(
                      Fingerprint64("e"), Fingerprint64("c")))

  Args:
    indices: A list of `Tensor` objects with type `int64`.
      2-D.  Indices of each input `SparseTensor`.
    values: A list of `Tensor` objects with types from: `int64`, `string`.
      1-D.   values of each `SparseTensor`.
    shapes: A list with the same length as `indices` of `Tensor` objects with type `int64`.
      1-D.   Shapes of each `SparseTensor`.
    dense: A list of `Tensor` objects with types from: `int64`, `string`.
      2-D.    Columns represented by dense `Tensor`.
    hashed_output: A `bool`.
    num_buckets: An `int` that is `>= 0`.
    out_type: A `tf.DType` from: `tf.int64, tf.string`.
    internal_type: A `tf.DType` from: `tf.int64, tf.string`.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (output_indices, output_values, output_shape).

    output_indices: A `Tensor` of type `int64`. 2-D.  Indices of the concatenated `SparseTensor`.
    output_values: A `Tensor` of type `out_type`. 1-D.  Non-empty values of the concatenated or hashed
      `SparseTensor`.
    output_shape: A `Tensor` of type `int64`. 1-D.  Shape of the concatenated `SparseTensor`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    if not isinstance(indices, (list, tuple)):
      raise TypeError(
          "Expected list for 'indices' argument to "
          "'sparse_feature_cross' Op, not %r." % indices)
    _attr_N = len(indices)
    if not isinstance(shapes, (list, tuple)):
      raise TypeError(
          "Expected list for 'shapes' argument to "
          "'sparse_feature_cross' Op, not %r." % shapes)
    if len(shapes) != _attr_N:
      raise ValueError(
          "List argument 'shapes' to 'sparse_feature_cross' Op with length %d "
          "must match length %d of argument 'indices'." %
          (len(shapes), _attr_N))
    hashed_output = _execute.make_bool(hashed_output, "hashed_output")
    num_buckets = _execute.make_int(num_buckets, "num_buckets")
    out_type = _execute.make_type(out_type, "out_type")
    internal_type = _execute.make_type(internal_type, "internal_type")
    _, _, _op = _op_def_lib._apply_op_helper(
        "SparseFeatureCross", indices=indices, values=values, shapes=shapes,
        dense=dense, hashed_output=hashed_output, num_buckets=num_buckets,
        out_type=out_type, internal_type=internal_type, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("N", _op.get_attr("N"), "hashed_output",
              _op.get_attr("hashed_output"), "num_buckets",
              _op.get_attr("num_buckets"), "sparse_types",
              _op.get_attr("sparse_types"), "dense_types",
              _op.get_attr("dense_types"), "out_type",
              _op.get_attr("out_type"), "internal_type",
              _op.get_attr("internal_type"))
    _execute.record_gradient(
      "SparseFeatureCross", _inputs_flat, _attrs, _result, name)
    _result = _SparseFeatureCrossOutput._make(_result)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "SparseFeatureCross", name, _ctx._post_execution_callbacks, indices,
        values, shapes, dense, "hashed_output", hashed_output, "num_buckets",
        num_buckets, "out_type", out_type, "internal_type", internal_type)
      _result = _SparseFeatureCrossOutput._make(_result)
      return _result
    except _core._FallbackException:
      return sparse_feature_cross_eager_fallback(
          indices, values, shapes, dense, hashed_output=hashed_output,
          num_buckets=num_buckets, out_type=out_type,
          internal_type=internal_type, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #51
0
def collective_gather(input,
                      group_size,
                      group_key,
                      instance_key,
                      shape,
                      name=None):
    r"""Mutually accumulates multiple tensors of identical type and shape.

  Args:
    input: A `Tensor`. Must be one of the following types: `float32`, `half`, `float64`, `int32`, `int64`.
    group_size: An `int`.
    group_key: An `int`.
    instance_key: An `int`.
    shape: A `tf.TensorShape` or list of `ints`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `input`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "CollectiveGather", name, _ctx._post_execution_callbacks,
                input, "group_size", group_size, "group_key", group_key,
                "instance_key", instance_key, "shape", shape)
            return _result
        except _core._FallbackException:
            try:
                return collective_gather_eager_fallback(
                    input,
                    group_size=group_size,
                    group_key=group_key,
                    instance_key=instance_key,
                    shape=shape,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    group_size = _execute.make_int(group_size, "group_size")
    group_key = _execute.make_int(group_key, "group_key")
    instance_key = _execute.make_int(instance_key, "instance_key")
    shape = _execute.make_shape(shape, "shape")
    _, _, _op = _op_def_lib._apply_op_helper("CollectiveGather",
                                             input=input,
                                             group_size=group_size,
                                             group_key=group_key,
                                             instance_key=instance_key,
                                             shape=shape,
                                             name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"), "group_size", _op.get_attr("group_size"),
              "group_key", _op.get_attr("group_key"), "instance_key",
              _op.get_attr("instance_key"), "shape", _op.get_attr("shape"))
    _execute.record_gradient("CollectiveGather", _inputs_flat, _attrs, _result,
                             name)
    _result, = _result
    return _result
コード例 #52
0
def unbatch(batched_tensor, batch_index, id, timeout_micros, container="", shared_name="", name=None):
  r"""Reverses the operation of Batch for a single output Tensor.

  An instance of Unbatch either receives an empty batched_tensor, in which case it
  asynchronously waits until the values become available from a concurrently
  running instance of Unbatch with the same container and shared_name, or receives
  a non-empty batched_tensor in which case it finalizes all other concurrently
  running instances and outputs its own element from the batch.

  batched_tensor: The possibly transformed output of Batch. The size of the first
   dimension should remain unchanged by the transformations for the operation to
   work.
  batch_index: The matching batch_index obtained from Batch.
  id: The id scalar emitted by Batch.
  unbatched_tensor: The Tensor corresponding to this execution.
  timeout_micros: Maximum amount of time (in microseconds) to wait to receive the
   batched input tensor associated with a given invocation of the op.
  container: Container to control resource sharing.
  shared_name: Instances of Unbatch with the same container and shared_name are
   assumed to possibly belong to the same batch. If left empty, the op name will
   be used as the shared name.

  Args:
    batched_tensor: A `Tensor`.
    batch_index: A `Tensor` of type `int64`.
    id: A `Tensor` of type `int64`.
    timeout_micros: An `int`.
    container: An optional `string`. Defaults to `""`.
    shared_name: An optional `string`. Defaults to `""`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `batched_tensor`.
  """
  _ctx = _context._context
  if _ctx is not None and _ctx._eager_context.is_eager:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name, "Unbatch",
        name, _ctx._post_execution_callbacks, batched_tensor, batch_index, id,
        "timeout_micros", timeout_micros, "container", container,
        "shared_name", shared_name)
      return _result
    except _core._FallbackException:
      try:
        return unbatch_eager_fallback(
            batched_tensor, batch_index, id, timeout_micros=timeout_micros,
            container=container, shared_name=shared_name, name=name, ctx=_ctx)
      except _core._SymbolicException:
        pass  # Add nodes to the TensorFlow graph.
      except (TypeError, ValueError):
        result = _dispatch.dispatch(
              unbatch, batched_tensor=batched_tensor, batch_index=batch_index,
                       id=id, timeout_micros=timeout_micros,
                       container=container, shared_name=shared_name,
                       name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
          return result
        raise
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
  # Add nodes to the TensorFlow graph.
  timeout_micros = _execute.make_int(timeout_micros, "timeout_micros")
  if container is None:
    container = ""
  container = _execute.make_str(container, "container")
  if shared_name is None:
    shared_name = ""
  shared_name = _execute.make_str(shared_name, "shared_name")
  try:
    _, _, _op = _op_def_lib._apply_op_helper(
        "Unbatch", batched_tensor=batched_tensor, batch_index=batch_index,
                   id=id, timeout_micros=timeout_micros, container=container,
                   shared_name=shared_name, name=name)
  except (TypeError, ValueError):
    result = _dispatch.dispatch(
          unbatch, batched_tensor=batched_tensor, batch_index=batch_index,
                   id=id, timeout_micros=timeout_micros, container=container,
                   shared_name=shared_name, name=name)
    if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
      return result
    raise
  _result = _op.outputs[:]
  _inputs_flat = _op.inputs
  _attrs = ("timeout_micros", _op.get_attr("timeout_micros"), "container",
            _op.get_attr("container"), "shared_name",
            _op.get_attr("shared_name"), "T", _op.get_attr("T"))
  _execute.record_gradient(
      "Unbatch", _inputs_flat, _attrs, _result, name)
  _result, = _result
  return _result
コード例 #53
0
def gcs_configure_credentials(json, name=None):
    r"""Configures the credentials used by the GCS client of the local TF runtime.

  The json input can be of the format:

  1. Refresh Token:
  {
    "client_id": "<redacted>",
    "client_secret": "<redacted>",
    "refresh_token: "<redacted>",
    "type": "authorized_user",
  }

  2. Service Account:
  {
    "type": "service_account",
    "project_id": "<redacted>",
    "private_key_id": "<redacted>",
    "private_key": "------BEGIN PRIVATE KEY-----\n<REDACTED>\n-----END PRIVATE KEY------\n",
    "client_email": "<REDACTED>@<REDACTED>.iam.gserviceaccount.com",
    "client_id": "<REDACTED>",
    # Some additional fields elided
  }

  Note the credentials established through this method are shared across all
  sessions run on this runtime.

  Note be sure to feed the inputs to this op to ensure the credentials are not
  stored in a constant op within the graph that might accidentally be checkpointed
  or in other ways be persisted or exfiltrated.

  Args:
    json: A `Tensor` of type `string`.
    name: A name for the operation (optional).

  Returns:
    The created Operation.
  """
    _ctx = _context._context
    if _ctx is None or not _ctx._eager_context.is_eager:
        _, _, _op = _op_def_lib._apply_op_helper("GcsConfigureCredentials",
                                                 json=json,
                                                 name=name)
        return _op
        _result = None
        return _result

    else:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._eager_context.device_name,
                "GcsConfigureCredentials", name,
                _ctx._post_execution_callbacks, json)
            return _result
        except _core._FallbackException:
            return gcs_configure_credentials_eager_fallback(json,
                                                            name=name,
                                                            ctx=_ctx)
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #54
0
def stateless_random_uniform_int(shape, seed, minval, maxval, name=None):
    r"""Outputs deterministic pseudorandom random integers from a uniform distribution.

  The generated values follow a uniform distribution in the range `[minval, maxval)`.

  

  The outputs are a deterministic function of `shape`, `seed`, `minval`, and `maxval`.

  Args:
    shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      The shape of the output tensor.
    seed: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      2 seeds (shape [2]).
    minval: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      Minimum value (inclusive, scalar).
    maxval: A `Tensor`. Must have the same type as `minval`.
      Maximum value (exclusive, scalar).
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `minval`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "StatelessRandomUniformInt", name,
                _ctx._post_execution_callbacks, shape, seed, minval, maxval)
            return _result
        except _core._FallbackException:
            try:
                return stateless_random_uniform_int_eager_fallback(shape,
                                                                   seed,
                                                                   minval,
                                                                   maxval,
                                                                   name=name,
                                                                   ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    _, _, _op = _op_def_lib._apply_op_helper("StatelessRandomUniformInt",
                                             shape=shape,
                                             seed=seed,
                                             minval=minval,
                                             maxval=maxval,
                                             name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("dtype", _op.get_attr("dtype"), "T", _op.get_attr("T"), "Tseed",
              _op.get_attr("Tseed"))
    _execute.record_gradient("StatelessRandomUniformInt", _inputs_flat, _attrs,
                             _result, name)
    _result, = _result
    return _result
コード例 #55
0
ファイル: gen_set_ops.py プロジェクト: elammend/yogaBackend
def set_size(set_indices,
             set_values,
             set_shape,
             validate_indices=True,
             name=None):
    r"""Number of unique elements along last dimension of input `set`.

  Input `set` is a `SparseTensor` represented by `set_indices`, `set_values`,
  and `set_shape`. The last dimension contains values in a set, duplicates are
  allowed but ignored.

  If `validate_indices` is `True`, this op validates the order and range of `set`
  indices.

  Args:
    set_indices: A `Tensor` of type `int64`.
      2D `Tensor`, indices of a `SparseTensor`.
    set_values: A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `string`.
      1D `Tensor`, values of a `SparseTensor`.
    set_shape: A `Tensor` of type `int64`.
      1D `Tensor`, shape of a `SparseTensor`.
    validate_indices: An optional `bool`. Defaults to `True`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int32`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "SetSize", name, _ctx._post_execution_callbacks, set_indices,
                set_values, set_shape, "validate_indices", validate_indices)
            return _result
        except _core._FallbackException:
            try:
                return set_size_eager_fallback(
                    set_indices,
                    set_values,
                    set_shape,
                    validate_indices=validate_indices,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    if validate_indices is None:
        validate_indices = True
    validate_indices = _execute.make_bool(validate_indices, "validate_indices")
    _, _, _op = _op_def_lib._apply_op_helper("SetSize",
                                             set_indices=set_indices,
                                             set_values=set_values,
                                             set_shape=set_shape,
                                             validate_indices=validate_indices,
                                             name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("validate_indices", _op.get_attr("validate_indices"), "T",
              _op.get_attr("T"))
    _execute.record_gradient("SetSize", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result
コード例 #56
0
def center_tree_ensemble_bias(tree_ensemble_handle,
                              stamp_token,
                              next_stamp_token,
                              delta_updates,
                              learner_config,
                              centering_epsilon=0.01,
                              name=None):
    r"""Centers the tree ensemble bias before adding trees based on feature splits.

  Args:
    tree_ensemble_handle: A `Tensor` of type `resource`.
      Handle to the ensemble variable.
    stamp_token: A `Tensor` of type `int64`.
      Stamp token for validating operation consistency.
    next_stamp_token: A `Tensor` of type `int64`.
      Stamp token to be used for the next iteration.
    delta_updates: A `Tensor` of type `float32`.
      Rank 1 Tensor containing delta updates per bias dimension.
    learner_config: A `string`.
      Config for the learner of type LearnerConfig proto.
    centering_epsilon: An optional `float`. Defaults to `0.01`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `bool`.
    Scalar indicating whether more centering is needed.
  """
    _ctx = _context.context()
    if not _ctx.executing_eagerly():
        learner_config = _execute.make_str(learner_config, "learner_config")
        if centering_epsilon is None:
            centering_epsilon = 0.01
        centering_epsilon = _execute.make_float(centering_epsilon,
                                                "centering_epsilon")
        _, _, _op = _op_def_lib._apply_op_helper(
            "CenterTreeEnsembleBias",
            tree_ensemble_handle=tree_ensemble_handle,
            stamp_token=stamp_token,
            next_stamp_token=next_stamp_token,
            delta_updates=delta_updates,
            learner_config=learner_config,
            centering_epsilon=centering_epsilon,
            name=name)
        _result = _op.outputs[:]
        _inputs_flat = _op.inputs
        _attrs = ("learner_config", _op.get_attr("learner_config"),
                  "centering_epsilon", _op.get_attr("centering_epsilon"))
        _execute.record_gradient("CenterTreeEnsembleBias", _inputs_flat,
                                 _attrs, _result, name)
        _result, = _result
        return _result

    else:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._handle, _ctx.device_name, "CenterTreeEnsembleBias", name,
                _ctx._post_execution_callbacks, tree_ensemble_handle,
                stamp_token, next_stamp_token, delta_updates, "learner_config",
                learner_config, "centering_epsilon", centering_epsilon)
            return _result
        except _core._FallbackException:
            return center_tree_ensemble_bias_eager_fallback(
                tree_ensemble_handle,
                stamp_token,
                next_stamp_token,
                delta_updates,
                learner_config=learner_config,
                centering_epsilon=centering_epsilon,
                name=name)
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #57
0
def masked_matmul(a, b, mask_indices, transpose_a, transpose_b, name=None):
  r"""Computes the product a * b, but only for indices (i, j) in mask_indices. The

  result is stored in prod_values, a rank 1 tensor, such that for all i,
  prod_values[i] = (a * b)[mask_indices[i, 0], mask_indices[i, 1]].
  Note that the shapes of the input matrices a, b should be compatible (after
  transposing as specified by the arguments transpose_a and transpose_b).

  Input arguments:

  Args:
    a: A `Tensor` of type `float32`. A rank 2 tensor of shape [m, n].
    b: A `Tensor` of type `float32`.
      A rank 2 tensor of shape [s, t]. The inner dimensions of a and b should match
      after transposition.
    mask_indices: A `Tensor` of type `int64`.
      A rank 2 tensor, of shape [nnz, 2] where nnz is the number of
      non-zero elements in the output. The indices are not assumed to be in
      lexicographic, or any particular order.
      For all i, mask_indices[i, :] should represent a valid index of the product
      matrix (a * b) (after transposition). That is:
      mask_indices[i, 0] should be in [0, m) if !transpose_a, and in [0, n)
        otherwise.
      mask_indices[i, 1] should be in [0, t) if !transpose_b, and in [0, s)
        otherwise.
    transpose_a: A `Tensor` of type `bool`.
      A boolean, specifies whether to transpose the matrix a.
    transpose_b: A `Tensor` of type `bool`.
      A boolean, specifies whether to transpose the matrix b.

      Output arguments:
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `float32`.
    A rank 1 tensor of shape [nnz], representing the values of the
    non-zero elements in the product, such that for all i,
    prod_values[i] = (a * b)[mask_indices[i, 0], mask_indices[i, 1]].
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "MaskedMatmul", a=a, b=b, mask_indices=mask_indices,
        transpose_a=transpose_a, transpose_b=transpose_b, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "MaskedMatmul", _inputs_flat, _attrs, _result, name)
    _result, = _result
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name, "MaskedMatmul",
        name, _ctx._post_execution_callbacks, a, b, mask_indices, transpose_a,
        transpose_b)
      return _result
    except _core._FallbackException:
      return masked_matmul_eager_fallback(
          a, b, mask_indices, transpose_a, transpose_b, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #58
0
def build_categorical_equality_splits(num_minibatches, partition_ids, feature_ids, gradients, hessians, class_id, feature_column_group_id, bias_feature_id, l1_regularization, l2_regularization, tree_complexity_regularization, min_node_weight, multiclass_strategy, weak_learner_type, name=None):
  r"""Find the split that has the best gain for the accumulated stats.

  Args:
    num_minibatches: A `Tensor` of type `int64`.
      A scalar, the number of times per example gradients & hessians
      were accumulated. The stats are divided by this to get per example stats.
    partition_ids: A `Tensor` of type `int32`.
      A rank 1 tensor of partition IDs.
    feature_ids: A `Tensor` of type `int64`.
      A rank 2 tensor of feature IDs and dimensions.
    gradients: A `Tensor` of type `float32`. A rank 1 tensor of gradients.
    hessians: A `Tensor` of type `float32`. A rank 1 tensor of hessians.
    class_id: A `Tensor` of type `int32`.
      A scalar, the class id for which we're building the splits.
    feature_column_group_id: A `Tensor` of type `int32`.
      A scalar, the index of the feature we are spiltting on.
    bias_feature_id: A `Tensor` of type `int64`.
    l1_regularization: A `Tensor` of type `float32`.
      A scalar, which specifies the l1 regularization term.
    l2_regularization: A `Tensor` of type `float32`.
      A scalar, which specifies the l2 regularization term.
    tree_complexity_regularization: A `Tensor` of type `float32`.
      A scalar, which specifies the tree complexity
      regularization term.
    min_node_weight: A `Tensor` of type `float32`.
      A scalar, minimum sum of example hessian needed in a child.
      If a split results in a leaf node with a smaller value, the split will not
      be considered.
    multiclass_strategy: A `Tensor` of type `int32`.
      A scalar, specifying the multiclass handling strategy.
      See LearnerConfig.MultiClassStrategy for valid values.
    weak_learner_type: A `Tensor` of type `int32`.
      A scalar, specifying the weak learner type to use.
      See LearnerConfig.WeakLearnerType for valid values.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (output_partition_ids, gains, split_infos).

    output_partition_ids: A `Tensor` of type `int32`. A rank 1 tensor, the partition IDs that we created splits
      for.
    gains: A `Tensor` of type `float32`. A rank 1 tensor, for the computed gain for the created splits.
    split_infos: A `Tensor` of type `string`. A rank 1 tensor of serialized protos which contains the
      `SplitInfo`s.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    _, _, _op = _op_def_lib._apply_op_helper(
        "BuildCategoricalEqualitySplits", num_minibatches=num_minibatches,
        partition_ids=partition_ids, feature_ids=feature_ids,
        gradients=gradients, hessians=hessians, class_id=class_id,
        feature_column_group_id=feature_column_group_id,
        bias_feature_id=bias_feature_id, l1_regularization=l1_regularization,
        l2_regularization=l2_regularization,
        tree_complexity_regularization=tree_complexity_regularization,
        min_node_weight=min_node_weight,
        multiclass_strategy=multiclass_strategy,
        weak_learner_type=weak_learner_type, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = None
    _execute.record_gradient(
      "BuildCategoricalEqualitySplits", _inputs_flat, _attrs, _result, name)
    _result = _BuildCategoricalEqualitySplitsOutput._make(_result)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name,
        "BuildCategoricalEqualitySplits", name,
        _ctx._post_execution_callbacks, num_minibatches, partition_ids,
        feature_ids, gradients, hessians, class_id, feature_column_group_id,
        bias_feature_id, l1_regularization, l2_regularization,
        tree_complexity_regularization, min_node_weight, multiclass_strategy,
        weak_learner_type)
      _result = _BuildCategoricalEqualitySplitsOutput._make(_result)
      return _result
    except _core._FallbackException:
      return build_categorical_equality_splits_eager_fallback(
          num_minibatches, partition_ids, feature_ids, gradients, hessians,
          class_id, feature_column_group_id, bias_feature_id,
          l1_regularization, l2_regularization,
          tree_complexity_regularization, min_node_weight,
          multiclass_strategy, weak_learner_type, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)
コード例 #59
0
def sequence_file_dataset(filenames, output_types, name=None):
    r"""TODO: add doc.

  Args:
    filenames: A `Tensor` of type `string`.
    output_types: A list of `tf.DTypes` that has length `>= 1`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `variant`.
  """
    _ctx = _context._context or _context.context()
    if _ctx is not None and _ctx._thread_local_data.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, _ctx._thread_local_data.device_name,
                "SequenceFileDataset", name, _ctx._post_execution_callbacks,
                filenames, "output_types", output_types)
            return _result
        except _core._FallbackException:
            try:
                return sequence_file_dataset_eager_fallback(
                    filenames, output_types=output_types, name=name, ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
            except (TypeError, ValueError):
                result = _dispatch.dispatch(sequence_file_dataset,
                                            filenames=filenames,
                                            output_types=output_types,
                                            name=name)
                if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                    return result
                raise
        except _core._NotOkStatusException as e:
            if name is not None:
                message = e.message + " name: " + name
            else:
                message = e.message
            _six.raise_from(_core._status_to_exception(e.code, message), None)
    # Add nodes to the TensorFlow graph.
    if not isinstance(output_types, (list, tuple)):
        raise TypeError("Expected list for 'output_types' argument to "
                        "'sequence_file_dataset' Op, not %r." % output_types)
    output_types = [
        _execute.make_type(_t, "output_types") for _t in output_types
    ]
    try:
        _, _, _op = _op_def_lib._apply_op_helper("SequenceFileDataset",
                                                 filenames=filenames,
                                                 output_types=output_types,
                                                 name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(sequence_file_dataset,
                                    filenames=filenames,
                                    output_types=output_types,
                                    name=name)
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("output_types", _op.get_attr("output_types"))
    _execute.record_gradient("SequenceFileDataset", _inputs_flat, _attrs,
                             _result, name)
    _result, = _result
    return _result
コード例 #60
0
def decode_wav(contents, desired_channels=-1, desired_samples=-1, name=None):
  r"""Decode a 16-bit PCM WAV file to a float tensor.

  The -32768 to 32767 signed 16-bit values will be scaled to -1.0 to 1.0 in float.

  When desired_channels is set, if the input contains fewer channels than this
  then the last channel will be duplicated to give the requested number, else if
  the input has more channels than requested then the additional channels will be
  ignored.

  If desired_samples is set, then the audio will be cropped or padded with zeroes
  to the requested length.

  The first output contains a Tensor with the content of the audio samples. The
  lowest dimension will be the number of channels, and the second will be the
  number of samples. For example, a ten-sample-long stereo WAV file should give an
  output shape of [10, 2].

  Args:
    contents: A `Tensor` of type `string`.
      The WAV-encoded audio, usually from a file.
    desired_channels: An optional `int`. Defaults to `-1`.
      Number of sample channels wanted.
    desired_samples: An optional `int`. Defaults to `-1`.
      Length of audio requested.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (audio, sample_rate).

    audio: A `Tensor` of type `float32`.
    sample_rate: A `Tensor` of type `int32`.
  """
  _ctx = _context._context
  if _ctx is None or not _ctx._eager_context.is_eager:
    if desired_channels is None:
      desired_channels = -1
    desired_channels = _execute.make_int(desired_channels, "desired_channels")
    if desired_samples is None:
      desired_samples = -1
    desired_samples = _execute.make_int(desired_samples, "desired_samples")
    _, _, _op = _op_def_lib._apply_op_helper(
        "DecodeWav", contents=contents, desired_channels=desired_channels,
        desired_samples=desired_samples, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("desired_channels", _op.get_attr("desired_channels"),
              "desired_samples", _op.get_attr("desired_samples"))
    _execute.record_gradient(
      "DecodeWav", _inputs_flat, _attrs, _result, name)
    _result = _DecodeWavOutput._make(_result)
    return _result

  else:
    try:
      _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
        _ctx._context_handle, _ctx._eager_context.device_name, "DecodeWav",
        name, _ctx._post_execution_callbacks, contents, "desired_channels",
        desired_channels, "desired_samples", desired_samples)
      _result = _DecodeWavOutput._make(_result)
      return _result
    except _core._FallbackException:
      return decode_wav_eager_fallback(
          contents, desired_channels=desired_channels,
          desired_samples=desired_samples, name=name, ctx=_ctx)
    except _core._NotOkStatusException as e:
      if name is not None:
        message = e.message + " name: " + name
      else:
        message = e.message
      _six.raise_from(_core._status_to_exception(e.code, message), None)