The shape of tensorflow four-dimensional tensor and the notes of the function tf.argmax( )

Regarding the organization of multidimensional arrays (mainly four-dimensional) in tensorflow, I have not understood it before. I have encountered related problems recently, and I have figured out some things, especially written down, so as not to forget it again.

The three-dimensional form can easily make up the three-dimensional shape, so I won't repeat it.

I have been entangled with how the data is filled in four-dimensional time. Especially when encountering deep learning, the input is [batch, height, width, channel], when this four-dimensional tensor is, what is the shape of the data.

Look at the code first:

prediction2 = tf.constant([1,2,3,4,5,6,7,8,9,13,14,14,15,1,6,34,23,7],shape=[2,1,3,3])

Generate a tensor with a shape of [2, 1, 3, 3]. When it is generated, it is filled according to one dimension and one dimension. The most "inner" dimension is filled first, which refers to dimension 3, and then it is filled out in turn. So you can think of [1,1,3,3] as this shape:

And [2,1,3,3] is a combination of two such cubes. When generating such a tensor, fill in [0][0][0][0], [0][0][0][1], [0][0][0][2]... ...

It is easy to understand when you find the maximum coordinate of this tensor in the corresponding dimension in turn, such as this code:

result = tf.argmax(prediction2,3)

will return the coordinate of the maximum value on the Z axis, so the first column of the cube is [0][0][0][0], [0][0][0][1], [0][0][ 0][2], the order is 1, 2, 3, the maximum is 2, and the return dimension is 2; the same can be deduced, the function return value is:

[[2,2,2],

 [1,0,0]]

The actual running result is also the same:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324997496&siteId=291194637