CNN学习-CNN图像尺寸输入限制问题

通过CNN组成(卷积层和全连接层)进行分析。
(1)卷积层
  卷积层对于图像是没有尺寸限制要求的。输入图像是28*28,卷积仅于自身的卷积核大小,维度有关,输入向量大小对其无影响(如第一层卷积,输入图像的大小和维度)。

# 输入图像
x = tf.placeholder(tf.float32, [None, 784])
y_ = tf.placeholder(tf.float32, [None, 10])
x_image = tf.reshape(x, [-1, 28, 28, 1])
# 卷积层
W_conv1 = weight_variable([5, 5, 1, 32])
b_conv1 = bias_variable([32])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
...
...
# 池化层
h_pool2 = max_pool_2x2(h_conv2)

(2)全连接层
  全连接过程中,w_fc1的输入与卷积层后的输出有关系,即对code中池化结果h_pool2进行reshape,该处是输入上一层的大小7764。

# 全连接层
W_fc1 = weight_variable([7*7*64, 1024])
b_fc1 = bias_variable([1024])
h_pool2_flat = tf.reshape(h_pool2,[-1, 7*7*64])
# h_pool2_flat = tf.reshape(h_pool2,[batch_size, -1])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)

可以看出,全连接层的输入是固定大小的,如果输入向量的维数不固定,那么全连接的权值参数的量也是不固定的,就会造成网络的动态变化,无法实现参数训练目的。

原文链接:

https://blog.csdn.net/u010801994/article/details/81482885?utm_source=blogxgwz9

发布了84 篇原创文章 · 获赞 108 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_42013574/article/details/90107589
CNN