code: def entropy_from_samples(samples, vec):
      """
      Estimate H(x|s) ~= -E_{x \sim P(x|s)}[\log Q(x|s)], where x are samples, and Q is parameterized by vec.
      """
      samples_cat = tf.argmax(
          samples[:, :NUM_CLASS], axis=1, output_type=tf.int32
      )
      samples_uniform = samples[:, NUM_CLASS:]
      cat, uniform = get_distributions(
          vec[:, :NUM_CLASS], vec[:, NUM_CLASS:]
      )
  
      def neg_logprob(dist, sample, name):
          nll = -dist.log_prob(sample)
          # average over batch
          return tf.reduce_sum(tf.reduce_mean(nll, axis=0), name=name)
  
      entropies = [
          neg_logprob(cat, samples_cat, "nll_cat"),
          neg_logprob(uniform, samples_uniform, "nll_uniform"),
      ]
      return entropies
  
imports: import argparse
  import numpy
  import os
  import cv2
  import tensorflow
  from tensorpack import *
  from tensorpack.dataflow import dataset
  from tensorpack.tfutils import gradproc, optimizer, summary
  from tensorpack.tfutils.scope_utils import auto_reuse_variable_scope, under_name_scope
  from tensorpack.utils import viz
  from GAN import GANModelDesc, GANTrainer
label_desc: Use image node_id 3 for calling a global function with example usage: entropy_from_samples(samples, vec) and returns: entropies, tf