在tensorflow slim模型中,alexnet_v2.py使用conv2d而不是完全连接的层

时间:2018-04-17 17:11:54

标签: python tensorflow

在实现中,它使用conv2d而不是fully_connected_layers。

pool5的张量形状为6 * 6 * 256。

内核大小为5 * 5后无填充,stride = 1,输出应为2 * 2 * 4096。

但是从完全连接的层实现中,神经元是4096.

有人可以解释一下吗?非常感谢你。

with slim.arg_scope([slim.conv2d, slim.fully_connected, slim.max_pool2d],
                    outputs_collections=[end_points_collection]):
  net = slim.conv2d(inputs, 64, [11, 11], 4, padding='VALID',
                    scope='conv1')
  net = slim.max_pool2d(net, [3, 3], 2, scope='pool1')
  net = slim.conv2d(net, 192, [5, 5], scope='conv2')
  net = slim.max_pool2d(net, [3, 3], 2, scope='pool2')
  net = slim.conv2d(net, 384, [3, 3], scope='conv3')
  net = slim.conv2d(net, 384, [3, 3], scope='conv4')
  net = slim.conv2d(net, 256, [3, 3], scope='conv5')
  net = slim.max_pool2d(net, [3, 3], 2, scope='pool5')
  # Use conv2d instead of fully_connected layers.
  with slim.arg_scope([slim.conv2d],
                      weights_initializer=trunc_normal(0.005),
                      biases_initializer=tf.constant_initializer(0.1)):
    net = slim.conv2d(net, 4096, [5, 5], padding='VALID',
                      scope='fc6')
    net = slim.dropout(net, dropout_keep_prob, is_training=is_training,
                       scope='dropout6')
    net = slim.conv2d(net, 4096, [1, 1], scope='fc7')
    # Convert end_points_collection into a end_point dict.
    end_points = slim.utils.convert_collection_to_dict(
        end_points_collection)
    if global_pool:
      net = tf.reduce_mean(net, [1, 2], keep_dims=True, name='global_pool')
      end_points['global_pool'] = net
    if num_classes:
      net = slim.dropout(net, dropout_keep_prob, is_training=is_training,
                         scope='dropout7')
      net = slim.conv2d(net, num_classes, [1, 1],
                        activation_fn=None,
                        normalizer_fn=None,
                        biases_initializer=tf.zeros_initializer(),
                        scope='fc8')
      if spatial_squeeze:
        net = tf.squeeze(net, [1, 2], name='fc8/squeezed')
      end_points[sc.name + '/fc8'] = net

0 个答案:

没有答案