title: How can I convert NHWC to NCHW in python for deepstream
body: <p>I have a TensorFlow Keras model which is stored in .pb format and from .pb format I am converting the model to .onnx format using the tf2onnx model</p>
  <pre><code>!python -m tf2onnx.convert --saved-model model.pb --output model.onnx 
  </code></pre>
  <p>now after converting I see that my input layer is in NHWC format and I need to convert the same to NCHW, to achieve that I am using</p>
  <pre><code>!python -m tf2onnx.convert --saved-model model.pb --output model_3.onnx --inputs-as-nchw input0:0
  </code></pre>
  <p>which is still giving me the same output as NHWC
  I have to consume the above model in NVIDIA Deepstream which only accepts NCHW format.</p>
  <p>I found this link which talks about the transpose of the input layer, but unfortunately, that is also not working.
  <a href="https://stackoverflow.com/questions/37689423/convert-between-nhwc-and-nchw-in-tensorflow">Convert between NHWC and NCHW in TensorFlow</a></p>
  <pre><code>#import tensorflow as tf
  images_nhwc = tf.compat.v1.placeholder(tf.float32, [1, 200, 300, 3])  
  # input batch
  out = tf.transpose(images_nhwc, [0, 3, 1, 2])
  #print(out.get_shape())
  model.build(out.get_shape())
  </code></pre>
  <p><a href="https://i.stack.imgur.com/uK7j8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uK7j8.png" alt="enter image description here" /></a>
  It would be really helpful if some experts can share their thoughts on how to convert NHWC to NCHW</p>