code: def cnn_model_fn(features, labels, mode):
      """Model function for a CNN."""
  
      # Define CNN architecture using tf.keras.layers.
      input_layer = tf.reshape(features["x"], [-1, 28, 28, 1])
      y = tf.keras.layers.Conv2D(
          16, 8, strides=2, padding="same", activation="relu"
      ).apply(input_layer)
      y = tf.keras.layers.MaxPool2D(2, 1).apply(y)
      y = tf.keras.layers.Conv2D(
          32, 4, strides=2, padding="valid", activation="relu"
      ).apply(y)
      y = tf.keras.layers.MaxPool2D(2, 1).apply(y)
      y = tf.keras.layers.Flatten().apply(y)
      y = tf.keras.layers.Dense(32, activation="relu").apply(y)
      logits = tf.keras.layers.Dense(10).apply(y)
  
      # Calculate loss as a vector and as its average across minibatch.
      vector_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
          labels=labels, logits=logits
      )
      scalar_loss = tf.reduce_mean(vector_loss)
  
      # Configure the training op (for TRAIN mode).
      if mode == tf_estimator.ModeKeys.TRAIN:
          optimizer = tf.compat.v1.train.GradientDescentOptimizer(
              FLAGS.learning_rate
          )
          opt_loss = scalar_loss
          global_step = tf.compat.v1.train.get_global_step()
          train_op = optimizer.minimize(
              loss=opt_loss, global_step=global_step
          )
          return tf_estimator.EstimatorSpec(
              mode=mode, loss=scalar_loss, train_op=train_op
          )
  
      # Add evaluation metrics (for EVAL mode).
      elif mode == tf_estimator.ModeKeys.EVAL:
          eval_metric_ops = {
              "accuracy": tf.metrics.accuracy(
                  labels=labels,
                  predictions=tf.argmax(input=logits, axis=1),
              )
          }
          return tf_estimator.EstimatorSpec(
              mode=mode,
              loss=scalar_loss,
              eval_metric_ops=eval_metric_ops,
          )
  
imports: from absl import logging
  import numpy
  import tensorflow
  from tensorflow import estimator
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 1 for calling a global function with example usage: cnn_model_fn(features, labels, mode) and returns: tf_estimator, tf_estimator