我构建的model_fn
自定义估算器如下所示,
def _model_fn(features,labels,mode):
"""
Mask Rcnn Model function
"""
self.keras_model = self.build_graph(mode,config)
outputs = self.keras_model(features) # ERROR STATEMENT
# outputs = self.keras_model(list(features.values())) # Same ERROR with this statement
# Predictions
if mode == tf.estimator.ModeKeys.PREDICT:
... # Defining Prediction Spec
# Training
if mode == tf.estimator.ModeKeys.TRAIN:
# Defining Loss and Training Spec
...
# Evaluation
...
_model_fn()
以以下形式从features
接收参数labels
和tf.data
:
features = {
'a' : (batch_size,h,w,3) # dtype: float
'b' : (batch_size,n) # # dtype: float
}
# And
labels = []
self.keras_model
是使用 tensorflow.keras.models.Model
API构建的,其API具有名称tensorflow.keras.layers.Input()
和{{1}的输入占位符(使用层'a'
定义) }。
使用'b'
运行估算器后,train_and_evaluate()
运行正常。该图已初始化,但是当训练开始时,我面临以下问题:
tensorflow.python.framework.errors_impl.InvalidArgumentError:您必须 用dtype float和shape输入占位符张量'a'的值 [?,128,128,3] [[{{{node a}}]]
之前,我曾与自定义估算器合作,这是第一次使用_model_fn
内部的 tensorflow.keras.models.Model
API计算图。