Class: tf.keras.Model
tf.keras.Model(
*args,
**kwargs
)
*args:
- inputs: The input(s) of the model: a keras.Input object or list of keras.Input objects.
- outputs: The output(s) of the model. See Functional API example below.
- name: String, the name of the model.
Methods
Model.compile()
Configures the model for training.
设置training参数
compile(
optimizer='rmsprop', # [str] define optimizer
loss=None, # [str] define loss type
metrics=None, # [list or dict] define evaluation metrics, typically is 'accuracy'
loss_weights=None, # [list or dict] define the weights of different losses
weighted_metrics=None, # weights of evaluation metrics
run_eagerly=None, # [Bool]
steps_per_execution=None, # [int] The number of batches to run during each tf.function call. ?
jit_compile=None, # ?
**kwargs
)
Model.compute_loss()
Compute the total loss, validate it, and return it.
计算loss值
compute_loss(
x=None, # input data
y=None, # target data (label)
y_pred=None, # predictions returned by the model
sample_weight=None # sample_weight
)
Model.compute_metrics()
Update metric states and collect all metrics to be returned.
更新一次metrics,并返回所有metrics的值 (metrics?)
compute_metrics(
x, y, y_pred, sample_weight
)
Model.evaluate()
Returns the loss value & metrics values for the model in test mode.
返回loss值和model中metrics的值
evaluate(
x=None, # [npy_array, tensor, dict, tf.data] input
y=None, # [npy_array, tensor, dict, tf.data] target data
batch_size=None, # [int] Number of samples per batch of computation [32]
verbose='auto', # [0,1,2] 0 = silent, 1 = progress bar, 2 = single line. 进度条
sample_weight=None,