为“ maxpool1 / MaxPool”(2)减去3导致的负尺寸大小(操作:“ MaxPool”)

时间:2018-12-08 00:16:32

标签: python tensorflow deep-learning

我已经在tensorflow中实现了用于图像分类的squeezenet模型,如下所示:

    net = conv2d(images, 96, [7, 7], stride=2, scope='conv1')
    net = max_pool2d(net, [3, 3], stride=2, scope='maxpool1')
    net = fire_module(net, 16, 64, scope='fire2')
    net = fire_module(net, 16, 64, scope='fire3')
    net = fire_module(net, 32, 128, scope='fire4')
    net = max_pool2d(net, [3, 3], stride=2, scope='maxpool4')
    net = fire_module(net, 32, 128, scope='fire5')
    net = fire_module(net, 48, 192, scope='fire6')
    net = fire_module(net, 48, 192, scope='fire7')
    net = fire_module(net, 64, 256, scope='fire8')
    net = max_pool2d(net, [3, 3], stride=2, scope='maxpool8')
    net = fire_module(net, 64, 256, scope='fire9')
    net = conv2d(net, num_classes, [1, 1], stride=1, scope='conv10')
    net = avg_pool2d(net, [13, 13], stride=1, scope='avgpool10')
    logits = tf.squeeze(net, [2], name='logits')
    return logits

运行培训时,出现以下错误:

ValueError: Negative dimension size caused by subtracting 3 from 2 for 'maxpool1/MaxPool' (op: 'MaxPool') with input shapes: [?,96,122,2].

我尝试过改变步幅和填充率,就像其他帖子所建议的那样,但没有任何效果。我可能在这里缺少一些简单的东西。

1 个答案:

答案 0 :(得分:2)

我怀疑conv2d正在使用padding='VALID'(无填充),也许您需要'SAME''same'。由于代码中未提供值,因此我只在张量流中定义的conv2dmax_pool中列出可能的填充混淆。这些conv2d版本中的padding的默认值如下: