实现SNPE softmax layer的4D tensor 第4轴的排序
SNPE的softmax只支持1D和2D的输入,如何实现4D数据的排序呢? 并且SNPE的排序的轴是固定的axis=-1,如何对4D数据的第3个轴排序呢?
def softmax(sft_data, axis=3):
dt_shape = data.get_shape().as_list()
dt_axis1 = tf.split(sft_data[0], num_or_size_splits=dt_shape[1], axis=0)
for i in range(0, dt_shape[1]):
tf.nn.softmax(dt_axis1[i][0], axis=-1)
return data
上面的函数是我实现的SNPE支持的4D数据第3轴的排序,至于第1,2轴的排序可以照着这个例子推出来。简单说就是用2D的轴为-1的softmax排序拼出来4D的第3轴数据。
I implement the function which can apply the softmax to the 4D data with the axis = 3, and it is easy to implement softmax with other axis=1 or 2 following my codes. The idea is that I use many softmax suppoted 2D data with axis=-1 to achieve the same result to the softmax which supports 4D data with axis=3.