Home | History | Annotate | Download | only in ops
      1 # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #     http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 # ==============================================================================
     15 """Resampling dataset transformations."""
     16 from __future__ import absolute_import
     17 from __future__ import division
     18 from __future__ import print_function
     19 
     20 from tensorflow.python.data.experimental.ops import resampling
     21 from tensorflow.python.util import deprecation
     22 
     23 
     24 @deprecation.deprecated(None,
     25                         "Use `tf.data.experimental.rejection_resample(...)`.")
     26 def rejection_resample(class_func, target_dist, initial_dist=None, seed=None):
     27   """A transformation that resamples a dataset to achieve a target distribution.
     28 
     29   **NOTE** Resampling is performed via rejection sampling; some fraction
     30   of the input values will be dropped.
     31 
     32   Args:
     33     class_func: A function mapping an element of the input dataset to a scalar
     34       `tf.int32` tensor. Values should be in `[0, num_classes)`.
     35     target_dist: A floating point type tensor, shaped `[num_classes]`.
     36     initial_dist: (Optional.)  A floating point type tensor, shaped
     37       `[num_classes]`.  If not provided, the true class distribution is
     38       estimated live in a streaming fashion.
     39     seed: (Optional.) Python integer seed for the resampler.
     40 
     41   Returns:
     42     A `Dataset` transformation function, which can be passed to
     43     `tf.data.Dataset.apply`.
     44   """
     45   return resampling.rejection_resample(class_func, target_dist, initial_dist,
     46                                        seed)
     47