Configures the model for training. Arguments: optimizer: String (name of optimizer) or optimizer instance. See `tf.keras.optimizers`. loss: String (name of objective function), objective function or `tf.losses.Loss` instance. See `tf.losses`. If the model
(self,
optimizer='rmsprop',
loss=None,
metrics=None,
loss_weights=None,
sample_weight_mode=None,
weighted_metrics=None,
target_tensors=None,
distribute=None,
**kwargs)
| 183 | |
| 184 | @trackable.no_automatic_dependency_tracking |
| 185 | def compile(self, |
| 186 | optimizer='rmsprop', |
| 187 | loss=None, |
| 188 | metrics=None, |
| 189 | loss_weights=None, |
| 190 | sample_weight_mode=None, |
| 191 | weighted_metrics=None, |
| 192 | target_tensors=None, |
| 193 | distribute=None, |
| 194 | **kwargs): |
| 195 | """Configures the model for training. |
| 196 | |
| 197 | Arguments: |
| 198 | optimizer: String (name of optimizer) or optimizer instance. |
| 199 | See `tf.keras.optimizers`. |
| 200 | loss: String (name of objective function), objective function or |
| 201 | `tf.losses.Loss` instance. See `tf.losses`. If the model has |
| 202 | multiple outputs, you can use a different loss on each output by |
| 203 | passing a dictionary or a list of losses. The loss value that will |
| 204 | be minimized by the model will then be the sum of all individual |
| 205 | losses. |
| 206 | metrics: List of metrics to be evaluated by the model during training |
| 207 | and testing. Typically you will use `metrics=['accuracy']`. |
| 208 | To specify different metrics for different outputs of a |
| 209 | multi-output model, you could also pass a dictionary, such as |
| 210 | `metrics={'output_a': 'accuracy', 'output_b': ['accuracy', 'mse']}`. |
| 211 | You can also pass a list (len = len(outputs)) of lists of metrics |
| 212 | such as `metrics=[['accuracy'], ['accuracy', 'mse']]` or |
| 213 | `metrics=['accuracy', ['accuracy', 'mse']]`. |
| 214 | loss_weights: Optional list or dictionary specifying scalar |
| 215 | coefficients (Python floats) to weight the loss contributions |
| 216 | of different model outputs. |
| 217 | The loss value that will be minimized by the model |
| 218 | will then be the *weighted sum* of all individual losses, |
| 219 | weighted by the `loss_weights` coefficients. |
| 220 | If a list, it is expected to have a 1:1 mapping |
| 221 | to the model's outputs. If a tensor, it is expected to map |
| 222 | output names (strings) to scalar coefficients. |
| 223 | sample_weight_mode: If you need to do timestep-wise |
| 224 | sample weighting (2D weights), set this to `"temporal"`. |
| 225 | `None` defaults to sample-wise weights (1D). |
| 226 | If the model has multiple outputs, you can use a different |
| 227 | `sample_weight_mode` on each output by passing a |
| 228 | dictionary or a list of modes. |
| 229 | weighted_metrics: List of metrics to be evaluated and weighted |
| 230 | by sample_weight or class_weight during training and testing. |
| 231 | target_tensors: By default, Keras will create placeholders for the |
| 232 | model's target, which will be fed with the target data during |
| 233 | training. If instead you would like to use your own |
| 234 | target tensors (in turn, Keras will not expect external |
| 235 | Numpy data for these targets at training time), you |
| 236 | can specify them via the `target_tensors` argument. It can be |
| 237 | a single tensor (for a single-output model), a list of tensors, |
| 238 | or a dict mapping output names to target tensors. |
| 239 | distribute: NOT SUPPORTED IN TF 2.0, please create and compile the |
| 240 | model under distribution strategy scope instead of passing it to |
| 241 | compile. |
| 242 | **kwargs: Any additional arguments. |