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)))
Returns | |
---|---|
counts
|
The histogram, as counts per bin. |
boundaries
|
A Tensor used to build the histogram representing boundaries.
|