Q: Tensorflow Estimator.predict() fails I am recreating the DnCNN, i.e. Gaussian Denoiser, which does image to image prediction with a series of convolutional layers. And it trains perfectly fine, but when i try to do the list(model.predict(..)), 
i get the error:

Labels must not be none

I actually put all of the specs arguments of my EstimatorSpec explicitly in there, as they are lazily evaluated depending on the method (train/eval/predict) that is called upon the Estimator.
def DnCNN_model_fn (features, labels, mode):
   # some convolutinons here
   return tf.estimator.EstimatorSpec(
        mode=mode,
        predictions=conv_last + input_layer,
        loss=tf.losses.mean_squared_error(
            labels=labels, 
            predictions=conv_last + input_layer),
        train_op=tf.train.AdamOptimizer(learning_rate=0.001, epsilon=1e-08).minimize(
            loss=tf.losses.mean_squared_error(
                labels=labels,
                predictions=conv_last + input_layer),
            global_step=tf.train.get_global_step()),
        eval_metric_ops={
            "accuracy": tf.metrics.mean_absolute_error(
                labels=labels,
                predictions=conv_last + input_layer)}
      )

Putting it into an estimator:
d = datetime.datetime.now()

DnCNN = tf.estimator.Estimator(
    model_fn=DnCNN_model_fn,
    model_dir=root + 'model/' +
              "DnCNN_{}_{}_{}_{}".format(d.month, d.day, d.hour, d.minute),
    config=tf.estimator.RunConfig(save_summary_steps=2,
                                  log_step_count_steps=10)
)

After training the model i do the predictions as follows:
test_input_fn = tf.estimator.inputs.numpy_input_fn(
    x= test_data[0:2,:,:,:],
    y= None,
    batch_size=1,
    num_epochs=1,
    shuffle=False)

predicted = DnCNN.predict(input_fn=test_input_fn) 
list(predicted) # this is where the error occurs

The traceback says, that tf.losses.mean_squared_error is causing this.
    Traceback (most recent call last):
      File "<input>", line 16, in <module>
      File "...\venv2\lib\site-packages\tensorflow\python\estimator\estimator.py", line 551, in predict
        features, None, model_fn_lib.ModeKeys.PREDICT, self.config)
      File "...\venv2\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1169, in _call_model_fn
        model_fn_results = self._model_fn(features=features, **kwargs)
      File "<input>", line 95, in DnCNN_model_fn
      File "...\venv2\lib\site-packages\tensorflow\python\ops\losses\losses_impl.py", line 663, in mean_squared_error
        raise ValueError("labels must not be None.")
    ValueError: labels must not be None.


A: From estimator.predict raises "ValueError: None values not supported":
"In your model_fn, you define the loss in every mode (train / eval / predict). This means that even in predict mode, the labels will be used and need to be provided.
When you are in predict mode, you actually just need to return the predictions so you can return early from the function:"
def model_fn(features, labels, mode):
#...
y = ...
if mode == tf.estimator.ModeKeys.PREDICT:
    return tf.estimator.EstimatorSpec(mode=mode, predictions=y)
#...


A: I am not entirly sure about what the exact error was, but i managed to get my model predicting.
what i changed (apart from adding the Batch norm UPDATE_OPS, which did not solve my issue) was short-circuiting (i.e. early & seperatly return) the tf.estimator.EstimatorSpec in case of tf.estimator.ModeKeys.PREDICT:
if mode == tf.estimator.ModeKeys.PREDICT:
    return tf.estimator.EstimatorSpec(
        mode=mode,
        predictions=conv_last + input_layer
    )

apparently there seems to be something wrong with the doc statement (or i did not understand it correctly) found at tf.estimator.EstimatorSpec :

model_fn can populate all arguments independent of mode. In this case, some arguments will be ignored by an Estimator. E.g. train_op will be ignored in eval and infer modes. 

BTW: given mode is predict, at some point, labels are automatically replaced by None in any case.
