regarding the tensor shape is (?,?,?,1)
<p>During debuging the Tensorflow code, I would like to output the shape of a tensor, say, <code>print("mask's shape is: ",mask.get_shape())</code>  However, the corresponding output is <code>mask's shape is (?,?,?,1)</code>  How to explain this kind of output, is there anyway to know the exactly value of the first three dimensions of this tensor?</p>

<p>This output means that TensorFlow's shape inference has only been able to infer a <em>partial shape</em> for the <code>mask</code> tensor. It has been able to infer (i) that <code>mask</code> is a 4-D tensor, and (ii) its last dimension is 1; but it does not know statically the shape of the first three dimensions.</p>

<p>If you want to get the actual shape of the tensor, the main approaches are:</p>

<ol>
<li>Compute <code>mask_val = sess.run(mask)</code> and print <code>mask_val.shape</code>.</li>
<li>Create a symbolic <code>mask_shape = tf.shape(mask)</code> tensor, compute <code>mask_shape_val = sess.run(mask_shape)</code> and print `mask_shape.</li>
</ol>

<p>Shapes usually have unknown components if the shape depends on the data, or if the tensor is itself a function of some tensor(s) with a partially known shape. If you believe that the shape of the mask <strong>should be</strong> static, you can trace the source of the uncertainty by (recursively) looking at the inputs of the operation(s) that compute <code>mask</code> and finding out where the shape becomes partially known.</p>

python tensorflow