code: def create_frozenlake_dream_image(
      dreamed_obs,  # real space (not symlog'd)
      dreamed_V,  # real space (not symlog'd)
      dreamed_a,
      dreamed_r_tp1,  # real space (not symlog'd)
      dreamed_ri_tp1,  # intrinsic reward
      dreamed_c_tp1,  # continue flag
      value_target,  # real space (not symlog'd)
      initial_h,
      as_tensor=False,
  ):
      frozenlake_env.unwrapped.s = np.argmax(dreamed_obs, axis=0)
  
      # Produce an RGB-image of the current state.
      rgb_array = frozenlake_env.render()
  
      # Add value-, action-, reward-, and continue-prediction information.
      image = Image.fromarray(rgb_array)
      draw_obj = ImageDraw.Draw(image)
  
      draw_obj.text(
          (5, 6),
          f"Vt={dreamed_V:.2f} (Rt={value_target:.2f})",
          fill=(0, 0, 0),
      )
      action_arrow = (
          "<--"
          if dreamed_a == 0
          else "v"
          if dreamed_a == 1
          else "-->"
          if dreamed_a == 2
          else "^"
      )
      draw_obj.text(
          (5, 18), f"at={action_arrow} ({dreamed_a})", fill=(0, 0, 0)
      )
      draw_obj.text(
          (5, 30), f"rt+1={dreamed_r_tp1:.2f}", fill=(0, 0, 0)
      )
      if dreamed_ri_tp1 is not None:
          draw_obj.text(
              (5, 42), f"rit+1={dreamed_ri_tp1:.6f}", fill=(0, 0, 0)
          )
      draw_obj.text((5, 54), f"ct+1={dreamed_c_tp1}", fill=(0, 0, 0))
      draw_obj.text(
          (5, 66),
          f"|h|t={np.mean(np.abs(initial_h)):.5f}",
          fill=(0, 0, 0),
      )
  
      # Return image.
      np_img = np.asarray(image)
      if as_tensor:
          return tf.convert_to_tensor(np_img, dtype=tf.uint8)
      return np_img
  
file_path: ray/rllib/algorithms/dreamerv3/utils/debugging.py
imports: import gymnasium
  import numpy
  from PIL import Image, ImageDraw
  from gymnasium.envs.classic_control.cartpole import CartPoleEnv
  from ray.rllib.utils.framework import try_import_tf
label_desc: Use image node_id 2 for calling a global function with example usage: create_frozenlake_dream_image(dreamed_obs, dreamed_V, dreamed_a, dreamed_r_tp1, dreamed_ri_tp1, dreamed_c_tp1, value_target, initial_h, as_tensor) and returns: np_img, tf