多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 编译 Keras 模型 前面部分中构建的模型需要使用`model.compile()` 方法进行编译,然后才能用于训练和预测。 `compile()` 方法的完整签名如下: ```py compile(self, optimizer, loss, metrics=None, sample_weight_mode=None) ``` compile 方法有三个参数: * `optimizer`:您可以指定自己的函数或 Keras 提供的函数之一。此函数用于更新优化迭代中的参数。 Keras 提供以下内置优化器函数: * `SGD` * `RMSprop` * `Adagrad` * `Adadelta` * `Adam` * `Adamax` * `Nadam` * `loss`:您可以指定自己的损失函数或使用提供的损失函数之一。优化器函数优化参数,以便最小化此损失函数的输出。 Keras 提供以下损失函数: * `mean_squared_error` * `mean_absolute_error` * `mean_absolute_pecentage_error` * `mean_squared_logarithmic_error` * `squared_hinge` * `hinge` * `categorical_hinge` * `sparse_categorical_crossentropy` * `binary_crossentropy` * `poisson` * `cosine proximity` * ``binary_accuracy`` * `categorical_accuracy` * `sparse_categorical_accuracy` * `top_k_categorical_accuracy` * `sparse_top_k_categorical_accuracy` * `metrics`:第三个参数是训练模型时需要收集的指标列表。如果启用了详细输出,则会为每次迭代打印度量标准。指标就像损失函数;一些由 Keras 提供,能够编写您自己的度量函数。所有损失函数也可用作度量函数。