W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
定義在:tensorflow/python/estimator/model_fn.py.
從model_fn返回的操作和對(duì)象并傳遞給Estimator.
EstimatorSpec完全定義了由Estimator運(yùn)行的模型.
@ staticmethod __new__ ( cls , mode , predictions = None , loss = None , train_op = None , eval_metric_ops = None , export_outputs = None , training_chief_hooks = None , training_hooks = None , scaffold = None , evaluation_hooks = None , prediction_hooks= 無 )
創(chuàng)建一個(gè)已經(jīng)驗(yàn)證的EstimatorSpec實(shí)例.
根據(jù)mode的值的不同,需要不同的參數(shù),即:
model_fn可以填充獨(dú)立于模式的所有參數(shù).在這種情況下,Estimator將忽略某些參數(shù).在eval和infer模式中,train_op將被忽略.例子如下:
def my_model_fn(mode, features, labels):
predictions = ...
loss = ...
train_op = ...
return tf.estimator.EstimatorSpec(
mode=mode,
predictions=predictions,
loss=loss,
train_op=train_op)
或者,model_fn可以填充適合給定模式的參數(shù).例:
def my_model_fn(mode, features, labels):
if (mode == tf.estimator.ModeKeys.TRAIN or
mode == tf.estimator.ModeKeys.EVAL):
loss = ...
else:
loss = None
if mode == tf.estimator.ModeKeys.TRAIN:
train_op = ...
else:
train_op = None
if mode == tf.estimator.ModeKeys.PREDICT:
predictions = ...
else:
predictions = None
return tf.estimator.EstimatorSpec(
mode=mode,
predictions=predictions,
loss=loss,
train_op=train_op)
函數(shù)參數(shù):
返回值:
一個(gè)經(jīng)過驗(yàn)證的EstimatorSpec對(duì)象.
可能引發(fā)的異常:
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: