- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
以下代码(复制/粘贴可运行)说明了如何使用 tf.layers.batch_normalization
。
import tensorflow as tf
bn = tf.layers.batch_normalization(tf.constant([0.0]))
print(tf.get_collection(tf.GraphKeys.UPDATE_OPS))
> [] # UPDATE_OPS collection is empty
使用 TF 1.5,文档(在下面引用)明确指出在这种情况下 UPDATE_OPS 不应为空 (https://www.tensorflow.org/api_docs/python/tf/layers/batch_normalization):
Note: when training, the moving_mean and moving_variance need to be updated. By default the update ops are placed in
tf.GraphKeys.UPDATE_OPS
, so they need to be added as a dependency to the train_op. For example:
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(update_ops):
train_op = optimizer.minimize(loss)
最佳答案
只需将代码更改为训练模式(通过将 training
标志设置为 True
),如 quote 中所述:
Note: when training, the moving_mean and moving_variance need to be updated. By default the update ops are placed in tf.GraphKeys.UPDATE_OPS, so they need to be added as a dependency to the train_op.
import tensorflow as tf
bn = tf.layers.batch_normalization(tf.constant([0.0]), training=True)
print(tf.get_collection(tf.GraphKeys.UPDATE_OPS))
将输出:
[< tf.Tensor 'batch_normalization/AssignMovingAvg:0' shape=(1,) dtype=float32_ref>,
< tf.Tensor 'batch_normalization/AssignMovingAvg_1:0' shape=(1,) dtype=float32_ref>]
Gamma 和 Beta 最终出现在 TRAINABLE_VARIABLES 集合中:
print(tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES))
[<tf.Variable 'batch_normalization/gamma:0' shape=(1,) dtype=float32_ref>,
<tf.Variable 'batch_normalization/beta:0' shape=(1,) dtype=float32_ref>]
关于python - Tensorflow `tf.layers.batch_normalization` 没有向 `tf.GraphKeys.UPDATE_OPS` 添加更新操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48874558/
这里是 doc tensorflow中的tf.GraphKeys,如TRAINABLE_VARIABLES :将由优化器训练的变量对象的子集。 我知道tf.get_collection() ,它可以找
Tensorflow 定义了集合的预设,如下所示:https://www.tensorflow.org/versions/r0.12/api_docs/python/framework/graph_c
是GraphKeys.TRAINABLE_VARIABLES与 tf.trainable_variables() 相同? 是GraphKeys.TRAINABLE_VARIABLES实际上tf.Gra
我今天刚刚安装了新的 tf 和 cuda,但是当我运行之前适用于 tf-1.4 的代码时,在新的 tensorflow-2.1.0 和 cuda-10.1 下将无法运行 如何解决这个问题? 最佳答案
我正在尝试从保存的模型 output_graph.pb 中提取所有权重/偏差。 我读了模型: def create_graph(modelFullPath): """Creates a gra
我正在尝试查看已加载的变量列表 .pb文件,但由于某种原因它是空的。 这是代码: import tensorflow as tf tf_model_path = './tf_coreml_ssd_re
以下代码(复制/粘贴可运行)说明了如何使用 tf.layers.batch_normalization。 import tensorflow as tf bn = tf.layers.batch_no
我的目标是如何使用推荐的 tf.keras.layers.BatchNormalization 类 (https://www.tensorflow.org/api_docs/python/tf/ker
tensorflow 中 tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)) 的目的是什么? 更多上下文:
我是一名优秀的程序员,十分优秀!