ONE - On-device Neural Engine
Loading...
Searching...
No Matches
fmelib.ComputeParam Namespace Reference

Functions

Tuple[List[float], List[float]] _channelwiseMinMax (Tensors tensors, int channel)
 
np.ndarray getActivationMax (np.ndarray tensor)
 

Variables

 Tensors = List[np.ndarray]
 

Function Documentation

◆ _channelwiseMinMax()

Tuple[List[float], List[float]] fmelib.ComputeParam._channelwiseMinMax ( Tensors  tensors,
int  channel 
)
protected
Compute channel-wise min and max for the tensor.
:param tensors: a list of numpy array (each is a tensor)
:param channel: number of channels
:return: lists of min and max for each channel

Definition at line 25 of file ComputeParam.py.

25def _channelwiseMinMax(tensors: Tensors, channel: int) -> Tuple[List[float], List[float]]:
26 """
27 Compute channel-wise min and max for the tensor.
28 :param tensors: a list of numpy array (each is a tensor)
29 :param channel: number of channels
30 :return: lists of min and max for each channel
31 """
32 channel_wise_min = []
33 channel_wise_max = []
34 for c in range(channel):
35 min_act = min(tensors, key=lambda activation: np.min(activation[:, :, :, c]))
36 max_act = max(tensors, key=lambda activation: np.max(activation[:, :, :, c]))
37 channel_wise_min.append(float(np.min(min_act[:, :, :, c])))
38 channel_wise_max.append(float(np.max(max_act[:, :, :, c])))
39 return channel_wise_min, channel_wise_max
40
41

◆ getActivationMax()

np.ndarray fmelib.ComputeParam.getActivationMax ( np.ndarray  tensor)
Get max values of activation.
:param tensors: a list of numpy array (each is a tensor)
:return: 1D array of max absolute values for each channel

Definition at line 42 of file ComputeParam.py.

42def getActivationMax(tensor: np.ndarray) -> np.ndarray:
43 """
44 Get max values of activation.
45 :param tensors: a list of numpy array (each is a tensor)
46 :return: 1D array of max absolute values for each channel
47 """
48 # max along with last dimension
49 return np.abs(tensor.reshape(-1, tensor.shape[-1])).max(axis=0)

Variable Documentation

◆ Tensors

fmelib.ComputeParam.Tensors = List[np.ndarray]

Definition at line 22 of file ComputeParam.py.