发布于 2021-04-03 10:15:21
配置用于培训的模型。文档
就我个人而言,我不认为它是编译,因为它所做的与编译无关,用计算机科学的术语来说,同时考虑机器学习和编译是非常令人困惑/难以抗拒的。
它只是一种进行配置的方法:
它只设置传递它的参数:优化器、丢失函数、度量、急切的执行。您可以多次运行它,它只会覆盖以前设置的设置。
我对TensorFlow开发人员的建议是,在短期内将其重命名为configure
,也许在将来(不太重要),为每个配置参数设置一个setter (或使用工厂/构建器模式)。
这是它的代码:
base_layer.keras_api_gauge.get_cell('compile').set(True)
with self.distribute_strategy.scope():
if 'experimental_steps_per_execution' in kwargs:
logging.warn('The argument `steps_per_execution` is no longer '
'experimental. Pass `steps_per_execution` instead of '
'`experimental_steps_per_execution`.')
if not steps_per_execution:
steps_per_execution = kwargs.pop('experimental_steps_per_execution')
self._validate_compile(optimizer, metrics, **kwargs)
self._run_eagerly = run_eagerly
self.optimizer = self._get_optimizer(optimizer)
self.compiled_loss = compile_utils.LossesContainer(
loss, loss_weights, output_names=self.output_names)
self.compiled_metrics = compile_utils.MetricsContainer(
metrics, weighted_metrics, output_names=self.output_names)
self._configure_steps_per_execution(steps_per_execution or 1)
# Initializes attrs that are reset each time `compile` is called.
self._reset_compile_cache()
self._is_compiled = True
self.loss = loss or {} # Backwards compat.
发布于 2021-12-09 14:44:23
model.compile与培训您的模型有关。实际上,你的权重需要优化,这个函数可以优化它们。在某种程度上提高了你的准确性。这只是一个叫做‘优化器’的输入参数。
model.compile(
optimizer='rmsprop', loss='sparse_categorical_crossentropy', metrics='acc'
)
这些是主要的投入。此外,您还可以在下面的链接中找到TensorFlow文档中的更多细节:
https://stackoverflow.com/questions/63493324
复制相似问题