DATA
转载自https://blog.csdn.net/qq_39622065/article/details/81228915
NHWC
[batch, in_height, in_width, in_channels]
NCHW
[batch, in_channels, in_height, in_width]
转换
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) 1 2123456789101112
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)12345678910
这是一个无可奈何的问题,在如何表示一组彩色图片的问题上,Theano和TensorFlow发生了分歧, ‘日’模式,也即Theano模式会把100张RGB三通道的16×32(高为16宽为32)彩色图表示为下面这种形式(100,3,16,32),Caffe采取的也是这种方式。第0个维度是样本维,代表样本的数目,第1个维度是通道维,代表颜色通道数。后面两个就是高和宽了。这种theano风格的数据组织方法,称为“channels_first”,即通道维靠前。
而TensorFlow,的表达形式是(100,16,32,3),即把通道维放在了最后,这种数据组织方式称为“channels_last”。
tensorflow的格式如下:
[batch,in_height,in_with,in_channels]批量批次1000高度图片的长宽宽通道通道数
channels RGB则为3黑白为1
Keras默认的数据组织形式在〜/ .keras / keras.json中规定,查看柯林斯该文件的image_data_format一项查看,也可在代码中通过K.image_data_format()函数返回,请在网络的训练和测试中保持维度顺序一致。
唉,真是蛋疼,你们商量好不行吗?
keras中添加卷积层时,可以指定deat_format格式:
model.add(Convolution2D( batch_input_shape=(None, 1, 28, 28), #多少数据 通道数 宽 高 filters=32, #滤波器数量 kernel_size=5, #滤波器大小5x5 strides=1, #步长1 padding='same', # Padding method data_format='channels_first', ))123456789
1、代码中的DATA_FORMAT = ‘channels_first’,即通道维靠前。
[batch,in_channels,in_height,in_with]既批次:批次大小渠道:通道数高度:图片的长宽度:宽
2、当然也可以和tensorflow中的数据格式一样指定 channels_last = ‘channels_last’,keras默认为channels_last。
通用模板:
from keras import backend as K w = 100 #图片宽度 h = 100 #图片高度 c = 3 #图片通道数 if K.image_dim_ordering() == 'th': X_train = X_train.reshape(-1, c, w, h) X_test = X_test.reshape(-1, c, w, h) input_shape = (1, w, h) else: X_train = X_train.reshape(-1, w, h, c) X_test = X_test.reshape(-1, w, h, c) input_shape = (w, h, c) X_train = X_train.reshape(-1, w, h, c) X_test = X_test.reshape(-1, w, h, c) input_shape = (w, h, c)
123456789101112131415161718例
model.add(Convolution2D( batch_input_shape=(None,w,h,c), #多少数据 通道数 宽 高 filters=32, #滤波器数量 kernel_size=5, #滤波器大小 strides=1, #步长 padding='same' # Padding method ))12345678
网址:DATA https://www.yuejiaxmz.com/news/view/65667
相关内容
MySql错误:mysqld: Can't create directory '/usr/local/mysql/data/淮安一男孩将10厘米针灸针塞进体内, 忍了近1年!取出已生锈!
中医13种按摩手法,一学就会
10道纯素烘焙,不是一般的美味。
@各位“厨神”,在家做饭到底该怎么做你知道吗?
减肥三步走:饮食+运动+习惯,就怕你瘦得快!
计控“心”声
基于python代码,家庭财务管理系统(可以存盘和读盘)
“一看就懂、一学就会、一练就有效”的居家健身十八招,来啦!
学生营养餐,分享8道做法,营养均衡又健康,好吃下饭