jul*_*jul 56 python tensorflow
使用tf.nn.*结束有什么好处tf.layers.*吗?
tf.nn.conv2d例如,doc中的大多数示例都使用,但不清楚为什么会这样做.
小智 39
正如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]
Run Code Online (Sandbox Code Playgroud)
对于tf.layers.conv2d:
filters: Integer, the dimensionality of the output space (i.e. the number of filters in the convolution).
Run Code Online (Sandbox Code Playgroud)
我会在加载预训练模型时使用tf.nn.conv2d(示例代码:https://github.com/ry/tensorflow-vgg16),并为从头开始训练的模型使用tf.layers.conv2d.
GBY*_*GBY 26
对于卷积,它们是相同的.更准确地说,tf.layers.conv2d(实际上_Conv)tf.nn.convolution用作后端.您可以关注以下的调用链:tf.layers.conv2d>Conv2D>Conv2D.apply()>_Conv>_Conv.apply()>_Layer.apply()>_Layer.\__call__()>_Conv.call()>nn.convolution()...
EXP*_*XP0 12
正如其他人所提到的,参数不同,特别是"过滤器".tf.nn.conv2d将张量作为过滤器,这意味着您可以在cifar10代码中指定权重衰减(或可能是其他属性),如下所示.(你是否想要/需要在转换层中减轻重量是另一个问题.)
kernel = _variable_with_weight_decay('weights',
shape=[5, 5, 3, 64],
stddev=5e-2,
wd=0.0)
conv = tf.nn.conv2d(images, kernel, [1, 1, 1, 1], padding='SAME')
Run Code Online (Sandbox Code Playgroud)
我不太确定如何在tf.layers.conv2d中设置权重衰减,因为它只使用整数作为过滤器.也许用kernel_constraint?
另一方面,如果您使用tf.nn.conv2d,tf.layers.conv2d会自动处理激活和偏差,而您必须为这些代码编写其他代码.
所有这些其他回复都说参数是如何不同的,但实际上,tf.nn 和 tf.layers conv2d 的主要区别在于,对于 tf.nn,您需要创建自己的过滤器张量并将其传入。这个过滤器需要有以下大小: [kernel_height, kernel_width, in_channels, num_filters]
本质上,tf.nn 的级别低于 tf.layers。不幸的是,这个答案不再适用是 tf.layers 已过时
| 归档时间: |
|
| 查看次数: |
29270 次 |
| 最近记录: |