Reputation: 23102
I have a Neural Network problem where I know the derivative of the error function with respect to my output, but not the target value (such a thing doesn't make sense in this problem). I could of course created one by adding the gradient to the output and then using a DNNEstimator, but this seems contrived.
A simplified example might be training a neural network to position a square in Cartesian space such that it does not overlap with another square whose coordinates are the input. In such a scenario we can easily compute a derivative (to move away from the center of the other square) but a label makes no sense.
Tensorflow's page on Estimators makes it sound like not using Estimators is generally a bad idea:
You can create a custom Estimator to do just about anything. If you want hidden layers connected in some unusual fashion, write a custom Estimator. If you want to calculate a unique metric for your model, write a custom Estimator. Basically, if you want an Estimator optimized for your specific problem, write a custom Estimator.
Ok, but Tensorflow's tf.estimator.Estimator
class seems to be tightly coupled to the notion that features must be accompanied by labels, as per the signature of model_func
:
def my_model_fn(
features, # This is batch_features from input_fn
labels, # This is batch_labels from input_fn
mode, # An instance of tf.estimator.ModeKeys
params): # Additional configuration
But I don't have any labels. Does it still make sense for me to use a custom Estimator in this case, or am I better off just using the lower level APIs directly?
Upvotes: 0
Views: 329
Reputation: 3790
You can still use the Estimator API. You just need to return a tf.estimator.EstimatorSpec. During training, it would look like this:
tf.estimator.EstimatorSpec(mode, predictions, loss, trainOp)
where trainOp is typically the result of an optimization step (this is where your error function derivative would be used).
You can also use the lower level APIs but you would lose all the advantages of the Estimator API, which, for example, allow you to export your trained model easily for inference serving.
Upvotes: 1