class_docstr: Nonlinear transform coding model.
code: def encode_decode(
      self,
      x,
      dither_rate,
      dither_dist,
      soft_round,
      guess_offset=None,
      offset=0.0,
      seed=None,
  ):
      if guess_offset is None:
          guess_offset = self.guess_offset
      # It doesn't make sense to use both guess_offset and soft_round.
      assert not (guess_offset and soft_round)
  
      def perturb(inputs, dither, prior, offset):
          if dither:
              if soft_round:
                  inputs = tfc.soft_round(inputs, alpha=self.alpha)
              inputs += tf.random.uniform(
                  tf.shape(inputs),
                  -0.5,
                  0.5,
                  dtype=self.dtype,
                  seed=seed,
              )
              if soft_round:
                  inputs = tfc.soft_round_conditional_mean(
                      inputs, alpha=self.alpha
                  )
              return inputs
          else:
              if guess_offset:
                  offset += tfc.quantization_offset(prior)
              return tfc.round_st(inputs, offset)
  
      assert x.shape[-1] == self.ndim_source
      y = self.analysis(x)
  
      rates = 0.0
      prior = self.prior(soft_round=soft_round)
  
      y_dist = perturb(y, dither_dist, prior, offset)
      if dither_rate == dither_dist:
          y_rate = y_dist
      else:
          y_rate = perturb(y, dither_rate, prior, offset)
  
      x_hat = self.synthesis(y_dist)
      log_probs = prior.log_prob(y_rate)
      rates += tf.reduce_sum(log_probs, axis=-1) / tf.cast(
          -tf.math.log(2.0), self.dtype
      )
  
      return y_dist, x_hat, rates
  
imports: import matplotlib.pyplot
  import numpy
  import tensorflow
  import tensorflow_compression
  import tensorflow_probability
  from toy_sources import compression_model
label_desc: Use image node_id 10 for calling the NTCModel obj's underlying member method code with example usage: obj.encode_decode(x, dither_rate, dither_dist, soft_round, guess_offset, offset, seed) and returns: y_dist,  x_hat,  rates, inputs, tfc