Commit 1bebf769 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Some changes for vanilla graph-conv

parent a4bd8dd4
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -143,6 +143,12 @@ class Model(object):
        batch_size, deterministic=True, pad_batches=pad_batches):
      n_samples = len(X_batch)
      y_pred_batch = self.predict_on_batch(X_batch)
      ################################################################### DEBUG
      #print("X_batch.shape, y_batch.shape")
      #print(X_batch.shape, y_batch.shape)
      #print("y_pred_batch.shape")
      #print(y_pred_batch.shape)
      ################################################################### DEBUG
      y_pred_batch = np.reshape(y_pred_batch, (n_samples, n_tasks))
      y_pred_batch = undo_transforms(y_pred_batch, transformers)
      y_preds.append(y_pred_batch)
@@ -151,6 +157,10 @@ class Model(object):
    # The iterbatches does padding with zero-weight examples on the last batch.
    # Remove padded examples.
    n_samples = len(dataset)
    ################################################### DEBUG
    print("n_samples, y_pred.shape, (n_samples, n_tasks)")
    print(n_samples, y_pred.shape, (n_samples, n_tasks))
    ################################################### DEBUG
    y_pred = np.reshape(y_pred, (n_samples, n_tasks))
    # Special case to handle singletasks.
    if n_tasks == 1:
@@ -338,7 +348,7 @@ class Model(object):


  def predict_proba(self, dataset, transformers=[], batch_size=None,
                    n_classes=2):
                    n_classes=2, pad_batches=False):
    """
    TODO: Do transformers even make sense here?

@@ -348,7 +358,7 @@ class Model(object):
    y_preds = []
    n_tasks = self.get_num_tasks()
    for (X_batch, y_batch, w_batch, ids_batch) in dataset.iterbatches(
        batch_size, deterministic=True):
        batch_size, deterministic=True, pad_batches=pad_batches):
      y_pred_batch = self.predict_proba_on_batch(X_batch)
      batch_size = len(y_batch)
      y_pred_batch = np.reshape(y_pred_batch, (batch_size, n_tasks, n_classes))
+4 −1
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ class TensorflowGraphModel(object):
      gradient_costs = []  # costs used for gradient calculation

      with TensorflowGraph.shared_name_scope('costs', graph, name_scopes):
        for task in xrange(self.n_tasks):
        for task in range(self.n_tasks):
          task_str = str(task).zfill(len(str(self.n_tasks)))
          with TensorflowGraph.shared_name_scope(
              'cost_{}'.format(task_str), graph, name_scopes):
@@ -555,6 +555,9 @@ class TensorflowClassifier(TensorflowGraphModel):
              (batch_outputs.shape,))
        outputs.append(batch_outputs)

        # TODO(rbharath): This is a bug! We're actually applying softmax twice.
        # I believe this is harmless since softmax of softmax doesn't change
        # properties, but I need to check this...
        # We apply softmax to predictions to get class probabilities.
        outputs = softmax(np.squeeze(np.hstack(outputs)))