gpt4 book ai didi

python - 如何将 tf.layers 变量放入 tf.name_scope/tf.variable_scope 中?

转载 作者:行者123 更新时间:2023-12-01 09:10:07 25 4
gpt4 key购买 nike

我在使用 Tensorflow 时遇到问题:

以下代码为卷积 block 生成正确的图:

def conv_layer(self, inputs, filter_size = 3, num_filters = 256, name = None):
scope_name = name
if name == None:
scope_name = "conv_layer"

with tf.name_scope(scope_name):
conv = tf.contrib.layers.conv2d(inputs, num_filters, filter_size, activation_fn = None)
batch_norm = tf.contrib.layers.batch_norm(conv)
act = tf.nn.leaky_relu(batch_norm)

return act

问题在于 tf.layers API 生成了一些丑陋的变量,这些变量实际上并不保留在 name_scope 内。这是 Tensorboard View ,您可以明白我的意思。

Tensorboard

是否有办法让这些变量进入作用域?当涉及到图形可视化时,这是一个大问题,因为我计划将这个网络变得更大。 (如右图所示,这已经是一个大问题了,每次启动 Tensorboard 时我都必须手动从主图中删除它们。)

最佳答案

您可以尝试使用tf.variable_scope代替。 tf.name_scope 会被通过 tf.get_variable() 创建的变量忽略,该变量通常由 tf.layers 函数使用。这与通过 tf.Variable 创建的变量形成对比。

参见this question有关差异的解释(尽管有些过时)。

关于python - 如何将 tf.layers 变量放入 tf.name_scope/tf.variable_scope 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51732039/

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