调用TensorFlow Keras模型时,``training = True''是什么意思? [英] What does `training=True` mean when calling a TensorFlow Keras model?
问题描述
在TensorFlow的官方文档中,当在训练循环中调用Keras模型(例如logits = mnist_model(images, training=True)
)时,它们总是通过training=True
.
In TensorFlow's offcial documentations, they always pass training=True
when calling a Keras model in a training loop, for example, logits = mnist_model(images, training=True)
.
我尝试了help(tf.keras.Model.call)
,它表明了
Help on function call in module tensorflow.python.keras.engine.network:
call(self, inputs, training=None, mask=None)
Calls the model on new inputs.
In this case `call` just reapplies
all ops in the graph to the new inputs
(e.g. build a new computational graph from the provided inputs).
Arguments:
inputs: A tensor or list of tensors.
training: Boolean or boolean scalar tensor, indicating whether to run
the `Network` in training mode or inference mode.
mask: A mask or list of masks. A mask can be
either a tensor or None (no mask).
Returns:
A tensor if there is a single output, or
a list of tensors if there are more than one outputs.
它表示training
是布尔或布尔标量张量,指示是在 training模式还是推理模式中运行Network
.但是我没有找到有关这两种模式的任何信息.
It says that training
is a Boolean or boolean scalar tensor, indicating whether to run the Network
in training mode or inference mode. But I didn't find any information about this two modes.
简而言之,我不知道该论点的影响.而且如果我在训练时错过了这个论点怎么办?
In a nutshell, I don't know what is the influence of this argument. And what if I missed this argument when training?
推荐答案
某些神经网络层在训练和推理期间的行为有所不同,例如Dropout和BatchNormalization层.例如
Some neural network layers behave differently during training and inference, for example Dropout and BatchNormalization layers. For example
- 在训练期间,辍学将随机辍学单位,并相应地扩大剩余单位的激活范围.
- 在推断过程中,它什么也不做(因为您通常不希望在这里丢弃单元的随机性).
training
参数使图层知道应采用的两个路径"中的哪一个.如果您对此设置不正确,则您的网络可能无法正常运行.
The training
argument lets the layer know which of the two "paths" it should take. If you set this incorrectly, your network might not behave as expected.
这篇关于调用TensorFlow Keras模型时,``training = True''是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!