code: def predict_dataflow(df, model_func, tqdm_bar=None):
      """
      Args:
          df: a DataFlow which produces (image, image_id)
          model_func: a callable from the TF model.
              It takes image and returns (boxes, probs, labels, [masks])
          tqdm_bar: a tqdm object to be shared among multiple evaluation instances. If None,
              will create a new one.
  
      Returns:
          list of dict, in the format used by
          `DatasetSplit.eval_inference_results`
      """
      df.reset_state()
      all_results = []
      with ExitStack() as stack:
          # tqdm is not quite thread-safe: https://github.com/tqdm/tqdm/issues/323
          if tqdm_bar is None:
              tqdm_bar = stack.enter_context(get_tqdm(total=df.size()))
          for img, img_id in df:
              results = predict_image(img, model_func)
              for r in results:
                  # int()/float() to make it json-serializable
                  res = {
                      "image_id": img_id,
                      "category_id": int(r.class_id),
                      "bbox": [round(float(x), 4) for x in r.box],
                      "score": round(float(r.score), 4),
                  }
  
                  # also append segmentation to results
                  if r.mask is not None:
                      rle = cocomask.encode(
                          np.array(r.mask[:, :, None], order="F")
                      )[0]
                      rle["counts"] = rle["counts"].decode("ascii")
                      res["segmentation"] = rle
                  all_results.append(res)
              tqdm_bar.update(1)
      return all_results
  
imports: import itertools
  import json
  import numpy
  import os
  import sys
  from collections import namedtuple
  from concurrent.futures import ThreadPoolExecutor
  from contextlib import ExitStack
  import cv2
  import pycocotools.mask
  import tqdm
  from scipy import interpolate
  from tensorpack.callbacks import Callback
  from tensorpack.tfutils.common import get_tf_version_tuple
  from tensorpack.utils import logger, get_tqdm
  from common import CustomResize, clip_boxes
  from config import config
  from data import get_eval_dataflow
  from dataset import DatasetRegistry
  from tensorpack.compat import tfv1
label_desc: Use image node_id 4 for calling a global function with example usage: predict_dataflow(df, model_func, tqdm_bar) and returns: all_results