首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >model.compile()在keras中做什么?

model.compile()在keras中做什么?
EN

Stack Overflow用户
提问于 2020-08-19 18:56:29
回答 2查看 2.6K关注 0票数 7

根据keras.io

一旦创建了模型,您就可以用model.compile().配置模型中的损失和度量。

但是这个解释并没有提供足够的信息来说明编译模型到底是做什么的。

EN

回答 2

Stack Overflow用户

发布于 2021-04-03 10:15:21

配置用于培训的模型。文档

就我个人而言,我不认为它是编译,因为它所做的与编译无关,用计算机科学的术语来说,同时考虑机器学习和编译是非常令人困惑/难以抗拒的。

它只是一种进行配置的方法:

它只设置传递它的参数:优化器、丢失函数、度量、急切的执行。您可以多次运行它,它只会覆盖以前设置的设置。

我对TensorFlow开发人员的建议是,在短期内将其重命名为configure,也许在将来(不太重要),为每个配置参数设置一个setter (或使用工厂/构建器模式)。

这是它的代码:

代码语言:javascript
运行
复制
    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.
票数 4
EN

Stack Overflow用户

发布于 2021-12-09 14:44:23

model.compile与培训您的模型有关。实际上,你的权重需要优化,这个函数可以优化它们。在某种程度上提高了你的准确性。这只是一个叫做‘优化器’的输入参数。

代码语言:javascript
运行
复制
model.compile(
optimizer='rmsprop', loss='sparse_categorical_crossentropy', metrics='acc'
)

这些是主要的投入。此外,您还可以在下面的链接中找到TensorFlow文档中的更多细节:

docs/python/tf/keras/Model#编译

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63493324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档