tensorflow tensor Flatten 张量扁平化,多通道转单通道数据

slim.flatten(inputs,outputs_collections=None,scope=None)

(注:import tensorflow.contrib.slim as slim) 
将输入扁平化但保留batch_size,假设第一维是batch。 
Args: 
inputs: a tensor of size [batch_size, …]. 
outputs_collections: collection to add the outputs. 
scope: Optional scope for name_scope. 
如:

test=([[[1,2,3],[4,5,6],[7,8,9]],[[10,11,12],[13,14,15],[16,17,27]],[[18,19,20],[21,22,23],[24,25,26]]])    #shape is (3,3,3)
test=slim.fatten(test)
test.eval()
array([[ 1,  2,  3, ...,  7,  8,  9],
       [10, 11, 12, ..., 16, 17, 27],
       [18, 19, 20, ..., 24, 25, 26]], dtype=int32)
test.get_shape()
TensorShape([Dimension(3), Dimension(9)])  #(3,9)

猜你喜欢

转载自www.cnblogs.com/xiaoniu-666/p/10412635.html