code: def digit(x, filters, length, iters=3, scope=None):
      filters0 = (
          int(x.shape[1]) if tf_later_than("2") else x.shape[1].value
      )
      length0 = (
          int(x.shape[2]) if tf_later_than("2") else x.shape[2].value
      )
  
      # fully-connected weights between capsules: [1152, 8, 10 * 16]
      w = tf.get_variable(
          "weights",
          shape=(filters0, length0, filters * length),
          dtype=tf.float32,
      )
  
      # coupling logits: [1152, 10]
      b = tf.zeros((filters0, filters))
  
      # prediction vectors: [None, 1152, 10, 16]
      uhat = tf.scan(
          lambda a, b: tf.matmul(b, w),
          tf.expand_dims(x, 2),
          initializer=tf.zeros([filters0, 1, filters * length]),
      )
      uhat = reshape(
          uhat, (-1, filters0, filters, length), name="predvec"
      )
  
      for r in range(iters):
          with tf.variable_scope("iter%d" % r):
              # coupling coefficients: [1152, 10]
              c = softmax(b, name="softmax")
              # activity vector: [None, 10, 16]
              v = squash(
                  tf.reduce_sum(uhat * tf.expand_dims(c, -1), axis=1),
                  name="out",
              )
              # agreement: [None, 1152, 10]
              a = reduce_sum(
                  tf.multiply(uhat, tf.expand_dims(v, 1)),
                  axis=-1,
                  name="agreement",
              )
              # updates coupling logits
              b = b + reduce_sum(a, axis=0, name="delta")
      return v
  
file_path: tensornets/tensornets/capsulenets.py
imports: from __future__ import absolute_import
  import numpy
  import tensorflow
  from .layers import batch_norm
  from .layers import conv2d
  from .layers import convrelu
  from .ops import *
  from .utils import ops_to_outputs
  from .utils import set_args
  from .utils import var_scope
label_desc: Use image node_id 4 for calling a global function with example usage: digit(x, filters, length, iters, scope) and returns: v