The model_fn
for custom estimator which I have built is as shown below,
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
...
The _model_fn()
receives arguments features
and labels
from tf.data
in form:
features = {
'a' : (batch_size, h, w, 3) # dtype: float
'b' : (batch_size, n) # # dtype: float
}
# And
labels = []
The self.keras_model
is built using tensorflow.keras.models.Model
API with Input placeholders (defined using layer tensorflow.keras.layers.Input()
) of name 'a'
and 'b'
for respective shapes.
After running the estimator using train_and_evaluate()
the _model_fn
is running fine. The graph is initialized, but when the training starts I'm facing the following issue:
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'a' with dtype float and shape [?,128,128,3] [[{{node a}}]]
I have worked with custom estimators before, this the first time using tensorflow.keras.models.Model
API inside the _model_fn
to compute the graph.
features
dict to input nodea
directly which should expect a tensor rather than a dict. – Forgatbuild()
method in this official repo link – Bemirefeatures
dict to thetf.keras.models.Model
? – Bemiretf.keras.models.Model()
only accepts keras Tensor. If you want to input a dict rather than a tensor, wrap a custom model class which inherits this official Model class in this way: tensorflow.org/api_docs/python/tf/keras/…. – Forgat