code: def compress(
      model,
      input_file,
      output_file,
      rd_parameter=None,
      rd_parameter_tolerance=None,
      target_bpp=None,
      bpp_strict=False,
  ):
      """Compresses a PNG file to a TFCI file."""
      if not output_file:
          output_file = input_file + ".tfci"
  
      # Load image.
      input_image = read_png(input_file)
      num_pixels = input_image.shape[-2] * input_image.shape[-3]
  
      if not target_bpp:
          # Just compress with a specific model.
          bitstring = compress_image(
              model, input_image, rd_parameter=rd_parameter
          )
      else:
          # Get model list.
          models = load_cached(model + ".models")
          models = models.decode("ascii").split()
  
          try:
              lower, upper = [float(m) for m in models]
              use_rd_parameter = True
          except ValueError:
              lower = -1
              upper = len(models)
              use_rd_parameter = False
  
          # Do a binary search over RD points.
          bpp = None
          best_bitstring = None
          best_bpp = None
          while bpp != target_bpp:
              if use_rd_parameter:
                  if upper - lower <= rd_parameter_tolerance:
                      break
                  i = (upper + lower) / 2
                  bitstring = compress_image(
                      model, input_image, rd_parameter=i
                  )
              else:
                  if upper - lower < 2:
                      break
                  i = (upper + lower) // 2
                  bitstring = compress_image(models[i], input_image)
              bpp = 8 * len(bitstring) / num_pixels
              is_admissible = bpp <= target_bpp or not bpp_strict
              is_better = best_bpp is None or abs(
                  bpp - target_bpp
              ) < abs(best_bpp - target_bpp)
              if is_admissible and is_better:
                  best_bitstring = bitstring
                  best_bpp = bpp
              if bpp < target_bpp:
                  lower = i
              if bpp > target_bpp:
                  upper = i
          if best_bpp is None:
              assert bpp_strict
              raise RuntimeError(
                  "Could not compress image to less than {} bpp.".format(
                      target_bpp
                  )
              )
          bitstring = best_bitstring
  
      # Write bitstring to disk.
      with tf.io.gfile.GFile(output_file, "wb") as f:
          f.write(bitstring)
  
imports: import argparse
  import io
  import os
  import sys
  import urllib
  from absl import app
  from absl.flags import argparse_flags
  import numpy
  import tensorflow
  import tensorflow_compression
label_desc: Use image node_id 6 for calling a global function with example usage: compress(model, input_file, output_file, rd_parameter, rd_parameter_tolerance, target_bpp, bpp_strict) without return types