简体   繁体   English

“ Encoder / conv6 / Conv2D”的2减去3导致的负尺寸大小

[英]Negative dimension size caused by subtracting 3 from 2 for 'Encoder/conv6/Conv2D'

I am trying to implement an AutoEncoder in Tensorflow. 我正在尝试在Tensorflow中实现自动编码器。 I am a beginner in Python as well as StackOverflow. 我是Python和StackOverflow的初学者。 These two are my encoder and decoder.My train_data.shape is (42000,28,28,1) (mnist dataset). 这两个是我的编码器和解码器,我的train_data.shape是(42000,28,28,1)(mnist数据集)。

def Network(Input):
with tf.name_scope("Encoder"):
    #encoder starts here
    conv1 = tf.layers.conv2d(Input, filters = 64, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv1')
    conv2 = tf.layers.conv2d(conv1, filters = 64, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv2')
    pool1 = tf.layers.max_pooling2d(conv2, pool_size = 2, strides = 2, name = 'pool1')

    conv3 = tf.layers.conv2d(pool1, filters = 128, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv3')
    conv4 = tf.layers.conv2d(conv3, filters = 128, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv4')
    pool2 = tf.layers.max_pooling2d(conv4, pool_size = 2, strides = 2, name = 'pool2')


    conv5 = tf.layers.conv2d(pool2, filters = 256, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv5')
    conv6 = tf.layers.conv2d(conv5, filters = 256, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv6')
    conv7 = tf.layers.conv2d(conv6, filters = 256, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv7')
    pool3 = tf.layers.max_pooling2d(conv7, pool_size = 2, strides = 2, name = 'pool3')

    conv8 = tf.layers.conv2d(pool3, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv8')
    conv9 = tf.layers.conv2d(conv8, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv9')
    conv10 = tf.layers.conv2d(conv9, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv10')
    pool4 = tf.layers.max_pooling2d(conv10, pool_size = 2, strides = 2, name = 'pool4')

    conv11 = tf.layers.conv2d(pool4, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv11')
    conv12 = tf.layers.conv2d(conv11, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv12')
    conv13 = tf.layers.conv2d(conv12, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'conv13')

    pool5 = tf.layers.max_pooling2d(conv13, pool_size = 2, strides = 2, name = 'pool5')

return pool5

.. ..

def Decoder(pool5):
with tf.name_scope("Decoder"):

    deconv1=tf.layers.conv2d_transpose(pool5, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv1')
    deconv2=tf.layers.conv2d_transpose(deconv1, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv2')
    deconv3=tf.layers.conv2d_transpose(deconv2, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv3')

    pool6=tf.layers.max_pooling2d(deconv3, pool_size = 2, strides = 2, name = 'pool6')
    deconv4 = tf.layers.conv2d_transpose(pool6, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv4')
    deconv5 = tf.layers.conv2d_transpose(deconv4, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv5')
    deconv6 = tf.layers.conv2d_transpose(deconv5, filters = 512, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv6')

    pool7 = tf.layers.max_pooling2d(deconv6, pool_size = 2, strides = 2, name = 'pool7')
    deconv7 = tf.layers.conv2d_transpose(pool7, filters = 256, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv7')
    deconv8 = tf.layers.conv2d_transpose(deconv7, filters = 256, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv8')
    deconv9 = tf.layers.conv2d_transpose(deconv8, filters = 256, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv9')

    pool8 = tf.layers.max_pooling2d(deconv9, pool_size = 2, strides = 2, name = 'pool8')
    deconv10 = tf.layers.conv2d_transpose(pool8, filters = 128, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv10')
    deconv11 = tf.layers.conv2d_transpose(deconv10, filters = 128, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv11')

    pool9= tf.layers.max_pooling2d(deconv11, pool_size = 2, strides = 2, name = 'pool9')
    deconv12 = tf.layers.conv2d_transpose(pool9, filters = 64, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv12')
    deconv13 = tf.layers.conv2d_transpose(deconv12, filters = 64, kernel_size = 3, strides = 1, activation = tf.nn.relu, name = 'deconv13')


    flat = tf.contrib.layers.flatten(deconv13)
    fc1 = tf.layers.dense(flat, units = 1024, activation = tf.nn.relu, name = 'fc1')
    fc2 = tf.layers.dense(fc1, units = 10, activation = None, name = 'fc2')

return fc2

I run into this error: 我遇到这个错误:

 ----------------------------------------------------------------------
 ValueError                                Traceback (most recent call    last)


ValueError: Negative dimension size caused by subtracting 3 from 2 for 'Encoder/conv6/Conv2D' (op: 'Conv2D') with input shapes: [?,2,2,256],                   [3,3,256,256].

I feel there is some error in my Input.Please suggest how to visualise the shape of tensor after each conv2d operation. 我感觉输入中有一些错误,请提出每次conv2d操作后如何可视化张量的形状。

Input = tf.placeholder(dtype = tf.float32, shape = [None, 28, 28, 1])

To visualize the shape of the tensor t you use t.get_shape() . 要可视化张量t的形状,请使用t.get_shape() The error explicitly says that you're trying to use a too big kernel on a too small input. 该错误明确表明您正在尝试在太小的输入上使用太大的内核。 From Stanford's CS231n class notes you can get the equation to compute the exact shapes of your data given certain kernel size, stride and padding 斯坦福大学的CS231n类笔记中,您可以得到方程式,以在给定特定内核大小,步幅和填充的情况下计算数据的确切形状 在此处输入图片说明 You should either decrease the kernel size, increase the stride, or get bigger input to be able to perform that many convolutions. 您应该减小内核大小,增加步幅或获得更大的输入以执行许多卷积。 Keep in mind that your max_pooling will also shrink the input as many times as large is your pool size in that layer, so if it's 2 then your data will shrink 2 times 请记住, max_pooling还将收缩输入,其大小是该层中池大小的多少倍,因此,如果为2,则数据将收缩2倍。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'Conv2D' 从 1 中减去 3 导致的负尺寸大小 - Negative dimension size caused by subtracting 3 from 1 for 'Conv2D' InvalidArgumentError: 1减3导致的负维度大小'{{node conv2d_28/Conv2D}} - InvalidArgumentError: Negative dimension size caused by subtracting 3 from 1 '{{node conv2d_28/Conv2D}} '{{node conv2d_3/Conv2D} 从 1 中减去 3 导致的负维度大小 - Negative dimension size caused by subtracting 3 from 1 for '{{node conv2d_3/Conv2D} ValueError:'{{node conv2d_3/Conv2D}} 从 1 中减去 2 导致的负维度大小 - ValueError: Negative dimension size caused by subtracting 2 from 1 for '{{node conv2d_3/Conv2D}} 多个Conv1D图层:由于'conv1d_2 / convolution / Conv2D从1中减去8而导致的负尺寸大小 - Multiple Conv1D Layers: Negative dimension size caused by subtracting 8 from 1 for 'conv1d_2/convolution/Conv2D CNN Keras:ValueError:负数尺寸是由'conv2d的2减去3引起的 - CNN Keras: ValueError: Negative dimension size caused by subtracting 3 from 2 for 'conv2d 'conv2d_2/convolution' 从 1 中减去 3 导致的负维度大小 - Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution' ValueError:由 1 为 'conv3d_3/convolution' 减去 22 引起的负尺寸大小(操作:'Conv3D') - ValueError: Negative dimension size caused by subtracting 22 from 1 for 'conv3d_3/convolution' (op: 'Conv3D') Keras-输入尺寸为[?,4,80,64],[5,5,64,64]的'conv2d_5 / convolution'(op:'Conv2D')的4中减去5引起的负尺寸大小 - Keras - Negative dimension size caused by subtracting 5 from 4 for 'conv2d_5/convolution' (op: 'Conv2D') with input shapes: [?,4,80,64], [5,5,64,64] 输入形状为 [?,1,10000,80], [3,3,80,16] 的 'conv2d_1/convolution'(操作:'Conv2D')从 1 中减去 3 导致的负尺寸大小 - Negative dimension size caused by subtracting 3 from 1 for 'conv2d_1/convolution' (op: 'Conv2D') with input shapes: [?,1,10000,80], [3,3,80,16]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM