code: def play_one_episode(env, func, render=False):
      def predict(s):
          """
          Map from observation to action, with 0.01 greedy.
          """
          s = np.expand_dims(s, 0)  # batch
          act = func(s)[0][0].argmax()
          if random.random() < 0.01:
              spc = env.action_space
              act = spc.sample()
          return act
  
      ob = env.reset()
      sum_r = 0
      while True:
          act = predict(ob)
          ob, r, isOver, info = env.step(act)
          sum_r += r
          if isOver:
              return sum_r
  
file_path: tensorpack/examples/DeepQNetwork/common.py
imports: import multiprocessing
  import numpy
  import random
  import time
  from six.moves import queue
  from tensorpack.callbacks import Callback
  from tensorpack.utils import logger, get_tqdm
  from tensorpack.utils.concurrency import ShareSessionThread, StoppableThread
  from tensorpack.utils.stats import StatCounter
label_desc: Use image node_id 1 for calling a global function with example usage: play_one_episode(env, func, render) and returns: act, sum_r