Commit 84760887 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Fixed some more bugs with multitasking output sizes

parent 58bf2bf9
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -104,7 +104,8 @@ class TestHyperparamOptAPI(TestAPI):
        "batch_size": [32],
        "data_shape": [train_dataset.get_data_shape()],
    }
    classification_metric = Metric(metrics.matthews_corrcoef, np.mean)
    classification_metric = Metric(metrics.matthews_corrcoef, np.mean,
                                   mode="classification")
    def model_builder(tasks, task_types, model_params, task_model_dir,
                      verbosity=None):
      return SklearnModel(tasks, task_types, model_params, task_model_dir,
@@ -138,7 +139,7 @@ class TestHyperparamOptAPI(TestAPI):
        splittype, compound_featurizers, 
        complex_featurizers, input_transformers,
        output_transformers, input_file, tasks)
    metric = Metric(metrics.matthews_corrcoef, np.mean)
    metric = Metric(metrics.matthews_corrcoef, np.mean, mode="classification")
    params_dict= {"nb_hidden": [5, 10],
                  "activation": ["relu"],
                  "dropout": [.5],
+4 −6
Original line number Diff line number Diff line
@@ -138,10 +138,6 @@ class Model(object):
    y_preds = []
    batch_size = self.model_params["batch_size"]
    for (X_batch, y_batch, w_batch, ids_batch) in dataset.iterbatches(batch_size):
      print("y_batch.shape")
      print(y_batch.shape)
      print("self.predict_on_batch(X_batch).shape")
      print(self.predict_on_batch(X_batch).shape)
      y_pred_batch = np.reshape(self.predict_on_batch(X_batch), y_batch.shape)
      y_pred_batch = undo_transforms(y_pred_batch, transformers)
      y_preds.append(y_pred_batch)
@@ -165,13 +161,15 @@ class Model(object):
    n_tasks = len(self.tasks)
    for (X_batch, y_batch, w_batch, ids_batch) in dataset.iterbatches(batch_size):
      y_pred_batch = self.predict_proba_on_batch(X_batch)
      print("y_pred_batch.shape")
      print(y_pred_batch.shape)
      if n_classes is None:
        n_classes = y_pred_batch.shape[-1]
      batch_size = len(y_batch)
      print("y_pred_batch.shape")
      print(y_pred_batch.shape)
      print("batch_size, n_tasks, n_classes")
      print(batch_size, n_tasks, n_classes)
      print("(batch_size, n_tasks, n_classes)")
      print((batch_size, n_tasks, n_classes))
      y_pred_batch = np.squeeze(
          np.reshape(y_pred_batch, (batch_size, n_tasks, n_classes)))
      y_pred_batch = undo_transforms(y_pred_batch, transformers)
+4 −4
Original line number Diff line number Diff line
@@ -139,14 +139,14 @@ class MultiTaskDNN(KerasModel):
    """
    data = self.get_data_dict(X)
    y_pred_dict = self.raw_model.predict_on_batch(data)
    nb_samples = np.shape(X)[0]
    nb_tasks = len(self.tasks)
    y_pred = np.zeros((nb_samples, n_classes*nb_tasks))
    n_samples = np.shape(X)[0]
    n_tasks = len(self.tasks)
    y_pred = np.zeros((n_samples, n_tasks, n_classes))
    for ind, task in enumerate(self.tasks):
      task_type = self.task_types[task]
      taskname = "task%d" % ind
      y_pred_task = np.squeeze(y_pred_dict[taskname])
      y_pred[:, ind:ind+n_classes] = y_pred_task
      y_pred[:, ind] = y_pred_task
    y_pred = np.squeeze(y_pred)
    return y_pred

+5 −6
Original line number Diff line number Diff line
@@ -62,8 +62,8 @@ class SingletaskToMultitask(Model):
    Concatenates results from all singletask models.
    """
    N_tasks = len(self.tasks)
    N_samples = X.shape[0]
    y_pred = np.zeros((N_samples, N_tasks))
    n_samples = X.shape[0]
    y_pred = np.zeros((n_samples, N_tasks))
    for ind, task in enumerate(self.tasks):
      y_pred[:, ind] = self.models[task].predict_on_batch(X)[:, 0]
    return y_pred
@@ -73,11 +73,10 @@ class SingletaskToMultitask(Model):
    Concatenates results from all singletask models.
    """
    n_tasks = len(self.tasks)
    N_samples = X.shape[0]
    y_pred = np.zeros((N_samples, n_classes*n_tasks))
    n_samples = X.shape[0]
    y_pred = np.zeros((n_samples, n_tasks, n_classes))
    for ind, task in enumerate(self.tasks):
      y_pred[:, ind*n_classes:(ind+1)*n_classes] = \
          self.models[task].predict_proba_on_batch(X)
      y_pred[:, ind] = self.models[task].predict_proba_on_batch(X)
    return y_pred

  def save(self):