I have a model that needs to be optimized to CPU.
Currently the model takes a 1024 x 1024 bytes data.
images = img[y:y+1024,x:x+1024,:]
As per this document, they want to change the default tensorflow data format from NHCW
to NCHW
format.
How can I transform from NHWC
to NCHW
format?
https://software.intel.com/en-us/articles/tensorflow-optimizations-on-modern-intel-architecture
Actually, I've never seen any Tensorflow function that supports
NHCW
format. For example,tf.nn.conv2d
andtf.nn.conv2d_transpose
supportNHWC
(current default) andNCHW
format.tf.nn.max_pool
supportsNHWC
,NCHW
andNCHW_VECT_C
(the last one is the most performant tensor format for cudnn6's quantized convolution, similar toNCHW
).But this transformation is possible, e.g. via
tf.transpose
that works with high-dimensional tensors as well:You can also do this in numpy via
np.swapaxes(array, 1, 2)
.