C 语言 tensorflow 隐蔽通道,Tensorflow 3通道彩色输入顺序

我正在使用张量流来处理彩色图像和卷积神经网络。代码片段如下。Tensorflow 3通道彩色输入顺序

我的代码运行,所以我认为我得到了正确的渠道数量。我的问题是,我如何正确订购rgb数据?它的形式是rgbrgbrgb还是rrrgggbbb?目前我正在使用后者。谢谢。任何帮助,将不胜感激。

c_output = 2

c_input = 784 * 3

def weight_variable(shape):

initial = tf.truncated_normal(shape, stddev=0.1)

return tf.Variable(initial)

def bias_variable(shape):

initial = tf.constant(0.1, shape=shape)

return tf.Variable(initial)

def conv2d(x, W):

return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')

def max_pool_2x2(x):

return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],

strides=[1, 2, 2, 1], padding='SAME')

self.c_x = tf.placeholder(tf.float32, shape=[None, c_input])

self.c_y_ = tf.placeholder(tf.float32, shape=[None, c_output])

self.W_conv1 = weight_variable([5, 5, 3, 32])

self.b_conv1 = bias_variable([32])

self.x_image = tf.reshape(self.c_x, [-1, 28, 28 , 3])

self.h_conv1 = tf.nn.relu(conv2d(self.x_image, self.W_conv1) + self.b_conv1)

self.h_pool1 = max_pool_2x2(self.h_conv1)

self.W_conv2 = weight_variable([5, 5, 32, 64])

self.b_conv2 = bias_variable([64])

self.h_conv2 = tf.nn.relu(conv2d(self.h_pool1, self.W_conv2) + self.b_conv2)

self.h_pool2 = max_pool_2x2(self.h_conv2)

self.W_fc1 = weight_variable([7 * 7 * 64, 1024])

self.b_fc1 = bias_variable([1024])

self.h_pool2_flat = tf.reshape(self.h_pool2, [-1, 7 * 7 * 64 ])

self.h_fc1 = tf.nn.relu(tf.matmul(self.h_pool2_flat, self.W_fc1) + self.b_fc1)

self.keep_prob = tf.placeholder(tf.float32)

self.h_fc1_drop = tf.nn.dropout(self.h_fc1, self.keep_prob)

self.W_fc2 = weight_variable([1024, c_output])

self.b_fc2 = bias_variable([c_output])

self.y_conv = tf.matmul(self.h_fc1_drop, self.W_fc2) + self.b_fc2

self.c_cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(self.y_conv, self.c_y_))

self.c_train_step = tf.train.AdamOptimizer(1e-4).minimize(self.c_cross_entropy)

self.c_correct_prediction = tf.equal(tf.argmax(self.y_conv, 1), tf.argmax(self.c_y_, 1))

self.c_accuracy = tf.reduce_mean(tf.cast(self.c_correct_prediction, tf.float32))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值