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

Merge pull request #774 from lilleswing/shuffle-test

Shuffle the dataset while fitting by default
parents 92f4ccc1 18a91d59
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -768,12 +768,12 @@ class DiskDataset(Dataset):
      y = np.reshape(y, (n_samples, -1))
      if w is not None:
        w = np.reshape(w, (n_samples, -1))
    n_tasks = y.shape[1]
    if ids is None:
      ids = np.arange(n_samples)
    if w is None:
      w = np.ones_like(y)
    if tasks is None:
      n_tasks = y.shape[1]
      tasks = np.arange(n_tasks)
    # raw_data = (X, y, w, ids)
    return DiskDataset.create_dataset(
+6 −3
Original line number Diff line number Diff line
@@ -132,11 +132,12 @@ class TensorGraphMultiTaskClassifier(TensorGraph):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    for epoch in range(epochs):
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):
        feed_dict = dict()
        if y_b is not None and not predict:
@@ -292,11 +293,12 @@ class TensorGraphMultiTaskRegressor(TensorGraph):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    for epoch in range(epochs):
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):
        feed_dict = dict()
        if y_b is not None and not predict:
@@ -373,11 +375,12 @@ class TensorGraphMultiTaskFitTransformRegressor(TensorGraphMultiTaskRegressor):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    for epoch in range(epochs):
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):
        feed_dict = dict()
        if y_b is not None and not predict:
+16 −9
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ class WeaveTensorGraph(TensorGraph):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    """ TensorGraph style implementation
    similar to deepchem.models.tf_new_models.graph_topology.AlternateWeaveTopology.batch_to_feed_dict
@@ -132,7 +133,7 @@ class WeaveTensorGraph(TensorGraph):
        print('Starting epoch %i' % epoch)
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):

        feed_dict = dict()
@@ -279,6 +280,7 @@ class DTNNTensorGraph(TensorGraph):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    """ TensorGraph style implementation
        similar to deepchem.models.tf_new_models.graph_topology.DTNNGraphTopology.batch_to_feed_dict
@@ -288,7 +290,7 @@ class DTNNTensorGraph(TensorGraph):
        print('Starting epoch %i' % epoch)
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):

        feed_dict = dict()
@@ -430,6 +432,7 @@ class DAGTensorGraph(TensorGraph):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    """ TensorGraph style implementation
        similar to deepchem.models.tf_new_models.graph_topology.DAGGraphTopology.batch_to_feed_dict
@@ -439,7 +442,7 @@ class DAGTensorGraph(TensorGraph):
        print('Starting epoch %i' % epoch)
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):

        feed_dict = dict()
@@ -575,13 +578,14 @@ class GraphConvTensorGraph(TensorGraph):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    for epoch in range(epochs):
      if not predict:
        print('Starting epoch %i' % epoch)
      for ind, (X_b, y_b, w_b, ids_b) in enumerate(
          dataset.iterbatches(
              self.batch_size, pad_batches=True, deterministic=True)):
              self.batch_size, pad_batches=True, deterministic=deterministic)):
        d = {}
        for index, label in enumerate(self.my_labels):
          if self.mode == 'classification':
@@ -704,6 +708,7 @@ class MPNNTensorGraph(TensorGraph):
               n_hidden=100,
               T=5,
               M=10,
               mode="regression",
               **kwargs):
    """
    Parameters
@@ -726,6 +731,7 @@ class MPNNTensorGraph(TensorGraph):
    self.n_hidden = n_hidden
    self.T = T
    self.M = M
    self.mode = mode
    super(MPNNTensorGraph, self).__init__(**kwargs)
    self.build_graph()

@@ -789,6 +795,7 @@ class MPNNTensorGraph(TensorGraph):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    """ Same generator as Weave models """
    for epoch in range(epochs):
@@ -796,7 +803,7 @@ class MPNNTensorGraph(TensorGraph):
        print('Starting epoch %i' % epoch)
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):

        feed_dict = dict()
+2 −1
Original line number Diff line number Diff line
@@ -167,13 +167,14 @@ class ANIRegression(TensorGraph):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    for epoch in range(epochs):
      if not predict:
        print('Starting epoch %i' % epoch)
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):

        feed_dict = dict()
+14 −5
Original line number Diff line number Diff line
@@ -65,8 +65,8 @@ class TensorGraph(Model):
    self.loss = None
    self.built = False
    self.queue_installed = False
    self.optimizer = Adam(
        learning_rate=learning_rate, beta1=0.9, beta2=0.999, epsilon=1e-7)
    self.optimizer = None
    self.learning_rate = learning_rate

    # Singular place to hold Tensor objects which don't serialize
    # These have to be reconstructed on restoring from pickle
@@ -115,9 +115,11 @@ class TensorGraph(Model):
          dataset,
          nb_epoch=10,
          max_checkpoints_to_keep=5,
          checkpoint_interval=1000):
          checkpoint_interval=1000,
          deterministic=False):
    return self.fit_generator(
        self.default_generator(dataset, epochs=nb_epoch),
        self.default_generator(
            dataset, epochs=nb_epoch, deterministic=deterministic),
        max_checkpoints_to_keep, checkpoint_interval)

  def fit_generator(self,
@@ -206,6 +208,7 @@ class TensorGraph(Model):
                        dataset,
                        epochs=1,
                        predict=False,
                        deterministic=True,
                        pad_batches=True):
    if len(self.features) > 1:
      raise ValueError("More than one Feature, must use generator")
@@ -216,7 +219,7 @@ class TensorGraph(Model):
    for epoch in range(epochs):
      for (X_b, y_b, w_b, ids_b) in dataset.iterbatches(
          batch_size=self.batch_size,
          deterministic=True,
          deterministic=deterministic,
          pad_batches=pad_batches):
        feed_dict = dict()
        if len(self.labels) == 1 and y_b is not None and not predict:
@@ -587,6 +590,12 @@ class TensorGraph(Model):
    elif obj == "FileWriter":
      self.tensor_objects['FileWriter'] = tf.summary.FileWriter(self.model_dir)
    elif obj == 'Optimizer':
      if self.optimizer is None:
        self.optimizer = Adam(
            learning_rate=self.learning_rate,
            beta1=0.9,
            beta2=0.999,
            epsilon=1e-7)
      self.tensor_objects['Optimizer'] = self.optimizer._create_optimizer(
          self._get_tf('GlobalStep'))
    elif obj == 'train_op':