Unverified Commit 93422613 authored by Bharath Ramsundar's avatar Bharath Ramsundar Committed by GitHub
Browse files

Merge pull request #1293 from Chasearmer/patch

tensorboard integration improvement
parents a91bebba 2ac67c68
Loading
Loading
Loading
Loading
+33 −15
Original line number Diff line number Diff line
@@ -199,7 +199,11 @@ class Layer(object):
    layer, complete with trained values for its variables."""
    self.variable_values = values

  def set_summary(self, summary_op, summary_description=None, collections=None):
  def set_summary(self,
                  summary_op,
                  include_variables=True,
                  summary_description=None,
                  collections=None):
    """Annotates a tensor with a tf.summary operation

    This causes self.out_tensor to be logged to Tensorboard.
@@ -208,6 +212,8 @@ class Layer(object):
    ----------
    summary_op: str
      summary operation to annotate node
    include_variables: bool
      Optional bool to include layer variables to the summary
    summary_description: object, optional
      Optional summary_pb2.SummaryDescription()
    collections: list of graph collections keys, optional
@@ -219,11 +225,12 @@ class Layer(object):
          "Invalid summary_op arg. Only 'tensor_summary', 'scalar', 'histogram' supported"
      )
    self.summary_op = summary_op
    self.include_variables = include_variables
    self.summary_description = summary_description
    self.collections = collections
    self.tensorboard = True

  def add_summary_to_tg(self, tb_input=None):
  def add_summary_to_tg(self, layer_vars):
    """
    Create the summary operation for this layer, if set_summary() has been called on it.

@@ -231,20 +238,30 @@ class Layer(object):

    Parameters
    ----------
    tb_input: tensor
      the tensor to log to Tensorboard.  If None, self.out_tensor is used.
    layer_vars: list of variables
      the list of variables to log to Tensorboard
    """
    if self.tensorboard == False:
      return
    if tb_input == None:
      tb_input = self.out_tensor

    if self.summary_op == "tensor_summary":
      tf.summary.tensor_summary(self.name, tb_input, self.summary_description,
      tf.summary.tensor_summary(self.name, self.out_tensor,
                                self.summary_description, self.collections)
      if self.include_variables:
        for var in layer_vars:
          tf.summary.tensor_summary(var.name, var, self.summary_description,
                                    self.collections)
    elif self.summary_op == 'scalar':
      tf.summary.scalar(self.name, tb_input, self.collections)
      tf.summary.scalar(self.name, self.out_tensor, self.collections)
      if self.include_variables:
        for var in layer_vars:
          tf.summary.tensor_summary(var.name, var, self.collections,
                                    self.collections)
    elif self.summary_op == 'histogram':
      tf.summary.histogram(self.name, tb_input, self.collections)
      tf.summary.histogram(self.name, self.out_tensor, self.collections)
      if self.include_variables:
        for var in layer_vars:
          tf.summary.histogram(var.name, var, self.collections)

  def copy(self, replacements={}, variables_graph=None, shared=False):
    """Duplicate this Layer and all its inputs.
@@ -2542,13 +2559,14 @@ class GraphConv(Layer):
  def _create_variables(self, in_channels):
    # Generate the nb_affine weights and biases
    W_list = [
        initializations.glorot_uniform([in_channels, self.out_channel])
        initializations.glorot_uniform(
            [in_channels, self.out_channel], name='kernel')
        for k in range(self.num_deg)
    ]
    b_list = [
        model_ops.zeros(shape=[
            self.out_channel,
        ]) for k in range(self.num_deg)
        ], name='bias') for k in range(self.num_deg)
    ]
    return (W_list, b_list)

@@ -3278,9 +3296,9 @@ class VinaFreeEnergy(Layer):

  def hydrogen_bond(self, d):
    """Computes Autodock Vina's hydrogen bond interaction term."""
    out_tensor = tf.where(d < -0.7, tf.ones_like(d),
                          tf.where(d < 0, (1.0 / 0.7) * (0 - d),
                                   tf.zeros_like(d)))
    out_tensor = tf.where(
        d < -0.7, tf.ones_like(d),
        tf.where(d < 0, (1.0 / 0.7) * (0 - d), tf.zeros_like(d)))
    return out_tensor

  def gaussian_first(self, d):
+2 −2
Original line number Diff line number Diff line
@@ -661,15 +661,15 @@ class TensorGraph(Model):
      if self.random_seed is not None:
        tf.set_random_seed(self.random_seed)
      self._install_queue()
      self.built = True
      for layer in self.topsort():
        with tf.name_scope(layer.name):
          layer.create_tensor(training=self._training_placeholder)
          self.rnn_initial_states += layer.rnn_initial_states
          self.rnn_final_states += layer.rnn_final_states
          self.rnn_zero_states += layer.rnn_zero_states
          layer.add_summary_to_tg()
          layer.add_summary_to_tg(self.get_layer_variables(layer))
      self.session = tf.Session(config=self.configproto)
      self.built = True

      # Ensure all training operators have been created.