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

Comment out _pad_batch

parent 864e1d1a
Loading
Loading
Loading
Loading
+22 −22
Original line number Diff line number Diff line
@@ -196,8 +196,8 @@ class Dataset(object):
        y_batch = y[indices]
        w_batch = w[indices]
        ids_batch = ids[indices]
        (X_batch, y_batch, w_batch, ids_batch) = self._pad_batch(
            X_batch, y_batch, w_batch, ids_batch, shard_batch_size)
        #(X_batch, y_batch, w_batch, ids_batch) = self._pad_batch(
        #    X_batch, y_batch, w_batch, ids_batch, shard_batch_size)
        yield (X_batch, y_batch, w_batch, ids_batch)

  @staticmethod
@@ -249,26 +249,26 @@ class Dataset(object):
      ws.append(np.array(w_b))
    return np.vstack(ws)

  def _pad_batch(self, X_b, y_b, w_b, ids_b, batch_size):
    """Fix batch to have exactly batch_size elements.
 
    Due to rounding issues, some batches will not have exactly batch_size
    elements. Handle these batches by zero padding all arrays.
    """
    n, feature_shape = np.shape(X_b)[0], np.shape(X_b)[1:]
    _, num_tasks = np.shape(y_b)
    if n == batch_size:
      return (X_b, y_b, w_b, ids_b)
    else:
      X_batch = np.zeros((batch_size,) + feature_shape)
      y_batch = np.zeros((batch_size, num_tasks))
      w_batch = np.zeros((batch_size, num_tasks))
      ids_batch = np.zeros((batch_size,), dtype=object)
      X_batch[:n] = X_b
      y_batch[:n] = y_b
      w_batch[:n] = w_b
      ids_batch[:n] = ids_b
    return X_batch, y_batch, w_batch, ids_batch
  #def _pad_batch(self, X_b, y_b, w_b, ids_b, batch_size):
  #  """Fix batch to have exactly batch_size elements.
 
  #  Due to rounding issues, some batches will not have exactly batch_size
  #  elements. Handle these batches by zero padding all arrays.
  #  """
  #  n, feature_shape = np.shape(X_b)[0], np.shape(X_b)[1:]
  #  _, num_tasks = np.shape(y_b)
  #  if n == batch_size:
  #    return (X_b, y_b, w_b, ids_b)
  #  else:
  #    X_batch = np.zeros((batch_size,) + feature_shape)
  #    y_batch = np.zeros((batch_size, num_tasks))
  #    w_batch = np.zeros((batch_size, num_tasks))
  #    ids_batch = np.zeros((batch_size,), dtype=object)
  #    X_batch[:n] = X_b
  #    y_batch[:n] = y_b
  #    w_batch[:n] = w_b
  #    ids_batch[:n] = ids_b
  #  return X_batch, y_batch, w_batch, ids_batch

  def __len__(self):
    """
+3 −6
Original line number Diff line number Diff line
@@ -98,9 +98,6 @@ class TensorflowGraph(object):
      self.placeholder_root = 'placeholders'
      with tf.name_scope(self.placeholder_root) as scope:
        self.placeholder_scope = scope
        self.valid = tf.placeholder(tf.bool,
                                    shape=[model_params["batch_size"]],
                                    name='valid')

    self.setup()
    if train:
@@ -333,7 +330,7 @@ class TensorflowGraph(object):
    for task in xrange(self.num_tasks):
      with tf.name_scope(self.placeholder_scope):
        weights.append(tf.identity(
            tf.placeholder(tf.float32, shape=[self.model_params["batch_size"]],
            tf.placeholder(tf.float32, shape=[None],
                           name='weights_%d' % task)))
    self.weights = weights

@@ -473,7 +470,7 @@ class TensorflowClassifier(TensorflowGraph):
      for task in xrange(self.num_tasks):
        with tf.name_scope(self.placeholder_scope):
          labels.append(tf.identity(
              tf.placeholder(tf.float32, shape=[batch_size, num_classes],
              tf.placeholder(tf.float32, shape=[None, num_classes],
                             name='labels_%d' % task)))
      self.labels = labels

@@ -527,7 +524,7 @@ class TensorflowRegressor(TensorflowGraph):
      for task in xrange(self.num_tasks):
        with tf.name_scope(self.placeholder_scope):
          labels.append(tf.identity(
              tf.placeholder(tf.float32, shape=[batch_size],
              tf.placeholder(tf.float32, shape=[None],
                             name='labels_%d' % task)))
      self.labels = labels

+2 −4
Original line number Diff line number Diff line
@@ -103,8 +103,7 @@ class TensorflowMultiTaskClassifier(TensorflowClassifier):
      with tf.name_scope(self.placeholder_scope):
        self.mol_features = tf.placeholder(
            tf.float32,
            shape=[self.model_params["batch_size"],
                   num_features],
            shape=[None, num_features],
            name='mol_features')

      layer_sizes = self.model_params["layer_sizes"]
@@ -231,8 +230,7 @@ class TensorflowMultiTaskRegressor(TensorflowRegressor):
      with tf.name_scope(self.placeholder_scope):
        self.mol_features = tf.placeholder(
            tf.float32,
            shape=[self.model_params["batch_size"],
                   num_features],
            shape=[None, num_features],
            name='mol_features')

      layer_sizes = self.model_params["layer_sizes"]
+2 −1
Original line number Diff line number Diff line
@@ -546,7 +546,8 @@ class TestOverfitAPI(TestAPI):
      #"batch_size": n_samples/8,
      #"batch_size": n_samples/16,
      #"batch_size": n_samples/32,
      "batch_size": n_samples/64,
      #"batch_size": n_samples/64,
      "batch_size": 75,
      # TODO(rbharath): Is there a bug in the padding code? Why does it fail to
      # learn for non-multiples?
      #"batch_size": 600,