TF之data_format:data_format中的NHWC&NCHW简介、转换的详细攻略

简介: TF之data_format:data_format中的NHWC&NCHW简介、转换的详细攻略

NHWC&NCHW简介


NHWC & NCHW是两种参数呈现的表达方式。在如何表示一组彩色图片的问题上,不同的DL框架有不同的表达。

image.png

NHWC&NCHW转换

1、NHWC →  NCHW


import tensorflow as tf

x = tf.reshape(tf.range(24), [1, 3, 4, 2])

out = tf.transpose(x, [0, 3, 1, 2])

print(x.shape)

print(out.shape)

(1, 3, 4, 2)

(1, 2, 3, 4)


2、NCHW → NHWC


import tensorflow as tf

x = tf.reshape(tf.range(24), [1, 2, 3, 4])

out = tf.transpose(x, [0, 2, 3, 1])

print(x.shape)

print(out.shape)

(1, 2, 3, 4)

(1, 3, 4, 2)





相关文章
|
9月前
Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.
Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.
159 0
|
存储 Python
​Data Science | 福利列表 | Numpy基础(三)
​Data Science | 福利列表 | Numpy基础(三)
R语言-创建空数据框(Empty Data Frame )用于追加数据
本文分享了如何在R语言通过创建空数据框来实现追加数据的简单实现方法,以供参考
804 0
|
机器学习/深度学习 Python
python中print参数sep和end 输出中的奥秘!
python中print参数sep和end 输出中的奥秘!
155 0
|
机器学习/深度学习 搜索推荐 TensorFlow
tf_record_writer.py代码解释
这段代码是用来将电影评分数据集转换为 TensorFlow 训练所需的二进制 TFRecord 格式的。这里采用的是 MovieLens 数据集,其中包含了 1 百万个电影评分记录,用于推荐系统任务的训练和测试。 该代码主要分为几个部分:
115 0
|
SQL
format函数
format函数
158 0
Google Earth Engine(GEE)——export影像导出错误Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid
Google Earth Engine(GEE)——export影像导出错误Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid
715 0
Google Earth Engine(GEE)——export影像导出错误Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid
|
JSON 数据格式 Python
python编程:json indent can't multiply sequence by non-int of type 'str'
python编程:json indent can't multiply sequence by non-int of type 'str'
194 0
【转载】format的用法。
以前没太注意这个用法,到网上找一个,copy过来,方便以后的查看。   "I see stuff like {0,-8:G2} passed in as a format string. What exactly does that do?" -- Very Confused String Fo...
919 0