gpt4 book ai didi

python - arg_scope 实际上是做什么的?

转载 作者:IT老高 更新时间:2023-10-28 21:18:49 24 4
gpt4 key购买 nike

我是神经网络和 TensorFlow 的初学者,我正在尝试了解 arg_scope 的作用.

在我看来,这是一种将“你想做的事情”字典放在具有特定变量的特定层的方法。如果我错了,请纠正我。您如何准确地向初学者解释它的用途?

最佳答案

在定义卷积层时,您可能总是使用相同的填充类型和相同的初始化器,甚至可能使用相同的卷积大小。对于你的池,也许你也总是使用相同的 2x2 池大小。以此类推。

arg_scope 是一种避免向相同层类型反复提供相同参数的方法。

source documentation 中的示例:

Example of how to use tf.contrib.framework.arg_scope:

from third_party.tensorflow.contrib.layers.python import layers
arg_scope = tf.contrib.framework.arg_scope
with arg_scope([layers.conv2d], padding='SAME',
initializer=layers.variance_scaling_initializer(),
regularizer=layers.l2_regularizer(0.05)):
net = layers.conv2d(inputs, 64, [11, 11], 4, padding='VALID', scope='conv1')
net = layers.conv2d(net, 256, [5, 5], scope='conv2')

The first call to conv2d will behave as follows:

   layers.conv2d(inputs, 64, [11, 11], 4, padding='VALID',
initializer=layers.variance_scaling_initializer(),
regularizer=layers.l2_regularizer(0.05), scope='conv1')

The second call to conv2d will also use the arg_scope's default for padding:

  layers.conv2d(inputs, 256, [5, 5], padding='SAME',
initializer=layers.variance_scaling_initializer(),
regularizer=layers.l2_regularizer(0.05), scope='conv2')

Example of how to reuse an arg_scope:

with arg_scope([layers.conv2d], padding='SAME',
initializer=layers.variance_scaling_initializer(),
regularizer=layers.l2_regularizer(0.05)) as sc:
net = layers.conv2d(net, 256, [5, 5], scope='conv1')
....
with arg_scope(sc):
net = layers.conv2d(net, 256, [5, 5], scope='conv2')

关于python - arg_scope 实际上是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45226950/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com