Join the SIG TFX-Addons community and help make TFX even better!


Computes a histogram over x, given the bin boundaries or bin count.

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)))

x A Tensor or SparseTensor.
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.

counts The histogram, as counts per bin.
boundaries A Tensor used to build the histogram representing boundaries.