tf.nn.conv2d 与 tf.layers.conv2d

新手上路,请多包涵

使用 tf.nn.*tf.layers.* 有什么优势吗?

例如,文档中的大多数示例都使用 tf.nn.conv2d ,但不清楚为什么要这样做。

原文由 jul 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 398
2 个回答

对于卷积,它们是相同的。更准确地说, tf.layers.conv2d (实际上 _Conv )使用 tf.nn.convolution 作为后端。您可以遵循以下调用链: tf.layers.conv2d>Conv2D>Conv2D.apply()>_Conv>_Conv.apply()>_Layer.apply()>_Layer.__call__()>_Conv.call()>nn.convolution()...

原文由 GBY 发布,翻译遵循 CC BY-SA 3.0 许可协议

正如 GBY 提到的,它们使用相同的实现。

参数略有不同。

对于 tf.nn.conv2d:

 filter: A Tensor. Must have the same type as input. A 4-D tensor of shape [filter_height, filter_width, in_channels, out_channels]

对于 tf.layers.conv2d:

 filters: Integer, the dimensionality of the output space (i.e. the number of filters in the convolution).

我会在加载预训练模型时使用 tf.nn.conv2d(示例代码: https ://github.com/ry/tensorflow-vgg16),而 tf.layers.conv2d 用于从头开始训练的模型。

原文由 Mircea 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题