title: Keras/TensorFlow: What is the order of the weight tensor dimensions of a convolutional layer?
body: <p>In <code>channels_last</code> format, the shape of the data tensor is <code>(batch_size, height, width, channels)</code> and the shape of the weight tensor is apparently (see reference 2) <code>(rows, cols, input_depth, output_depth)</code>.</p>
  <p>In <code>channels_first</code> format, the shape of the data tensor is <code>(batch_size, channels, height, width)</code> and the shape of the weight tensor is what?</p>
  <p>I've looked high and low for the answer to that question. When I run my code and use <code>model.get_weights()</code> to get the weight and bias tensors, it appears that the format of the weight tensors is the same in <code>channels_first</code> as in <code>channels_last</code>. Yet, when I output the weight tensors to a file and read them back into my C/C++ code which is hand-crafted and doesn't use TensorFlow, it doesn't appear to be working. The results are numerically nonsensical. Maybe there is some other problem, but I would like to obtain a definitive answer to this question.</p>
  <p>BTW, the reason I'm switching between <code>channels_last</code> and <code>channels_first</code> is that I need to be able to develop my code on a CPU machine and then run large training sessions on a GPU machine.</p>
  <p>Any help is appreciated.</p>
  <p>References:</p>
  <p><a href="https://keras.io/api/layers/convolution_layers/convolution2d/" rel="nofollow noreferrer">Data tensor shape is explained here.</a></p>
  <p><a href="https://keras.io/api/layers/constraints/" rel="nofollow noreferrer">Weight tensor shape is partially explained here.</a></p>