1

For this Humanpose Tensorflow network, network_cmu and base, it accepts only NHWC input format. If I construct the network in NCHW format, there is error as

Depth of input (32) is not a multiple of input depth of filter (3) for 'conv1_1/Conv2D' (op: 'Conv2D') with input shapes: [1,3,24,32], [3,3,3,64]. 

My code to construct the network is

import tensorflow as tf
import numpy as np
from network_cmu import CmuNetwork


def main():
    #print(tensor_util.MakeNdarray(n.attr['value'].tensor))
    placeholder_input = tf.placeholder(dtype=tf.float32, shape=(1, 3, 24, 32), name="image") 
    net = CmuNetwork({'image': placeholder_input}, trainable=False)
    # Add an op to initialize the variables.
    init_op = tf.global_variables_initializer()
    saver = tf.train.Saver()
    init_op = tf.global_variables_initializer()
    with tf.Session() as sess:
        sess.run(init_op)
        #for n in tf.get_default_graph().as_graph_def().node:
        #   print(n.name)
        save_path = saver.save(sess, "cmuThreeOutputs/model.ckpt") 

if __name__ == '__main__':
   main()

What should I change to have network in NCHW format?

Cœur
  • 37,241
  • 25
  • 195
  • 267
batuman
  • 7,066
  • 26
  • 107
  • 229
  • Does this answer your question? [Convert between NHWC and NCHW in TensorFlow](https://stackoverflow.com/questions/37689423/convert-between-nhwc-and-nchw-in-tensorflow) – craq Nov 17 '21 at 02:07

1 Answers1

1

You can make use of tf.transpose to shift your axis from NHWC to NCHW

input_ = tf.convert_to_tensor(np.random.rand(1, 3, 24, 32))
a1 = tf.transpose(input_, perm=[0, 2, 3, 1])
print(a1.shape)  # 1, 24, 32, 3

You may even make use of tf.reshape

a2 = tf.reshape(input_, (-1, input_.shape[2], input_.shape[3], input_.shape[1]))
print(a2.shape)  # 1, 24, 32, 3
Prasad
  • 5,946
  • 3
  • 30
  • 36