qkeras.b2t
Implements total/partial Binary to Thermometer decoder.
Functions
|
Converts binary to one-hot (with scales). |
- qkeras.b2t.BinaryToThermometer(x, classes, value_range, with_residue=False, merge_with_channels=False, use_two_hot_encoding=False)[source]
Converts binary to one-hot (with scales).
Given input matrix x with values (for example) 0, 1, 2, 3, 4, 5, 6, 7, create a number of classes as follows:
classes=2, value_range=8, with_residue=0
A true one-hot representation, and the remaining bits are truncated, using one bit representation.
0 - [1,0] 1 - [1,0] 2 - [1,0] 3 - [1,0] 4 - [0,1] 5 - [0,1] 6 - [0,1] 7 - [0,1]
classes=2, value_range=8, with_residue=1
In this case, the residue is added to the one-hot class, and the class will use 2 bits (for the remainder) + 1 bit (for the one hot)
0 - [1,0] 1 - [1.25,0] 2 - [1.5,0] 3 - [1.75,0] 4 - [0,1] 5 - [0,1.25] 6 - [0,1.5] 7 - [0,1.75]
- Parameters:
x – the input vector we want to convert. typically its dimension will be (B,H,W,C) for an image, or (B,T,C) or (B,C) for for a 1D signal, where B=batch, H=height, W=width, C=channels or features, T=time for time series.
classes – the number of classes to (or log2(classes) bits) to use of the values.
value_range – max(x) - min(x) over all possible x values (e.g. for 8 bits, we would use 256 here).
with_residue – if true, we split the value range into two sets and add the decimal fraction of the set to the one-hot representation for partial thermometer representation.
merge_with_channels – if True, we will not create a separate dimension for the resulting matrix, but we will merge this dimension with the last dimension.
use_two_hot_encoding – if true, we will distribute the weight between the current value and the next one to make sure the numbers will always be < 1.
- Returns:
Converted x with classes with the last shape being C*classes.