View source on GitHub
|
Computes a histogram over x, given the bin boundaries or bin count.
tft.histogram(
x: common_types.TensorType,
boundaries: Optional[Union[tf.Tensor, int]] = None,
categorical: Optional[bool] = False,
name: Optional[str] = None
) -> Tuple[tf.Tensor, tf.Tensor]
Ex (1): counts, boundaries = histogram([0, 1, 0, 1, 0, 3, 0, 1], range(5)) counts: [4, 3, 0, 1, 0] boundaries: [0, 1, 2, 3, 4]
Ex (2): Can be used to compute class weights. counts, classes = histogram([0, 1, 0, 1, 0, 3, 0, 1], categorical=True) probabilities = counts / tf.reduce_sum(counts) class_weights = dict(map(lambda (a, b): (a.numpy(), 1.0 / b.numpy()), zip(classes, probabilities)))
Args |
|---|
x: A Tensor, SparseTensor, or RaggedTensor.
boundaries: (Optional) A Tensor or int used to build the histogram;
ignored if categorical is True. If possible, provide boundaries as
multiple sorted values. Default to 10 intervals over the 0-1 range, or
find the min/max if an int is provided (not recommended because
multi-phase analysis is inefficient).
categorical: (Optional) A bool that treats x as discrete values if true.
name: (Optional) A name for this operation.
Returns |
|---|
counts: The histogram, as counts per bin.
boundaries: A Tensor used to build the histogram representing boundaries.
View source on GitHub