Commit 785ac0b6 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Attempt at tensorflow

parent f51c373d
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@ from deepchem.models.keras_models.fcnet import MultiTaskDNN
from deepchem.models.tensorflow_models import TensorflowModel
from deepchem.models.tensorflow_models.fcnet import TensorflowMultiTaskClassifier
from deepchem.splits import ScaffoldSplitter
############################################################# DEBUG
import tensorflow as tf
from keras import backend as K
############################################################# DEBUG

def rf_model_builder(tasks, task_types, params_dict, model_dir, verbosity=None):
    """Builds random forests given hyperparameters.
@@ -173,6 +177,16 @@ class TestHyperparamOptAPI(TestAPI):
                  "batchnorm": [False],
                  "data_shape": [train_dataset.get_data_shape()]}
      
    def model_builder(tasks, task_types, model_params, task_model_dir,
                      verbosity=None):
      ############################################################# DEBUG
      g = tf.Graph()
      sess = tf.Session(graph=g)
      K.set_session(sess)
      with g.as_default():
      ############################################################# DEBUG
        return MultiTaskDNN(tasks, task_types, model_params, task_model_dir,
                            model_instance=LogisticRegression())
    optimizer = HyperparamOpt(MultiTaskDNN, tasks, task_types,
                              verbosity="low")
    best_model, best_hyperparams, all_results = optimizer.hyperparam_search(
+11 −1
Original line number Diff line number Diff line
@@ -33,6 +33,11 @@ from deepchem.models.tensorflow_models import TensorflowModel
from deepchem.models.tensorflow_models.fcnet import TensorflowMultiTaskClassifier
from deepchem.splits import ScaffoldSplitter
from deepchem.splits import SpecifiedSplitter
############################################################# DEBUG
from deepchem.models.keras_models.fcnet import MultiTaskDNN
import tensorflow as tf
from keras import backend as K
############################################################# DEBUG

class TestModelAPI(TestAPI):
  """
@@ -294,7 +299,12 @@ class TestModelAPI(TestAPI):

  def test_multitask_keras_mlp_ECFP_classification_API(self):
    """Straightforward test of Keras multitask deepchem classification API."""
    from deepchem.models.keras_models.fcnet import MultiTaskDNN
    ############################################################# DEBUG
    g = tf.Graph()
    #sess = tf.Session(graph=g)
    sess = tf.Session()
    K.set_session(sess)
    ############################################################# DEBUG
    task_type = "classification"
    # TODO(rbharath): There should be some automatic check to ensure that all
    # required model_params are specified.
+261 −227
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@ from deepchem.models.tensorflow_models import TensorflowModel
from deepchem.models.tensorflow_models.fcnet import TensorflowMultiTaskRegressor
from deepchem.models.tensorflow_models.fcnet import TensorflowMultiTaskClassifier
from deepchem.models.multitask import SingletaskToMultitask
############################################################# DEBUG
import tensorflow as tf
from keras import backend as K
############################################################# DEBUG

class TestOverfitAPI(TestAPI):
  """
@@ -152,6 +156,12 @@ class TestOverfitAPI(TestAPI):

  def test_keras_regression_overfit(self):
    """Test that keras models can overfit simple regression datasets."""
    ############################################################# DEBUG
    g = tf.Graph()
    sess = tf.Session(graph=g)
    K.set_session(sess)
    with g.as_default():
    ############################################################# DEBUG
      tasks = ["task0"]
      task_types = {task: "regression" for task in tasks}
      n_samples = 10
@@ -252,6 +262,12 @@ class TestOverfitAPI(TestAPI):

  def test_keras_classification_overfit(self):
    """Test that keras models can overfit simple classification datasets."""
    ############################################################# DEBUG
    g = tf.Graph()
    sess = tf.Session(graph=g)
    K.set_session(sess)
    with g.as_default():
    ############################################################# DEBUG
      tasks = ["task0"]
      task_types = {task: "classification" for task in tasks}
      n_samples = 10
@@ -301,6 +317,12 @@ class TestOverfitAPI(TestAPI):

  def test_keras_skewed_classification_overfit(self):
    """Test keras models can overfit 0/1 datasets with few actives."""
    ############################################################# DEBUG
    g = tf.Graph()
    sess = tf.Session(graph=g)
    K.set_session(sess)
    with g.as_default():
    ############################################################# DEBUG
      tasks = ["task0"]
      task_types = {task: "classification" for task in tasks}
      n_samples = 100
@@ -577,6 +599,12 @@ class TestOverfitAPI(TestAPI):

  def test_keras_multitask_classification_overfit(self):
    """Test keras multitask overfits tiny data."""
    ############################################################# DEBUG
    g = tf.Graph()
    sess = tf.Session(graph=g)
    K.set_session(sess)
    with g.as_default():
    ############################################################# DEBUG
      n_tasks = 10
      tasks = ["task%d" % task for task in range(n_tasks)]
      task_types = {task: "classification" for task in tasks}
@@ -723,6 +751,12 @@ class TestOverfitAPI(TestAPI):

  def test_keras_multitask_regression_overfit(self):
    """Test keras multitask overfits tiny data."""
    ############################################################# DEBUG
    g = tf.Graph()
    sess = tf.Session(graph=g)
    K.set_session(sess)
    with g.as_default():
    ############################################################# DEBUG
      n_tasks = 10
      tasks = ["task%d" % task for task in range(n_tasks)]
      task_types = {task: "regression" for task in tasks}
+61 −51
Original line number Diff line number Diff line
@@ -20,6 +20,10 @@ from deepchem.models.sklearn_models import SklearnModel
from deepchem.models.keras_models.fcnet import MultiTaskDNN
from deepchem.models.tensorflow_models import TensorflowModel
from deepchem.models.tensorflow_models.fcnet import TensorflowMultiTaskClassifier
############################################################# DEBUG
import tensorflow as tf
from keras import backend as K
############################################################# DEBUG

class TestModelReload(TestAPI):

@@ -69,6 +73,12 @@ class TestModelReload(TestAPI):

  def test_keras_reload(self):
    """Test that trained keras models can be reloaded correctly."""
    ############################################################# DEBUG
    g = tf.Graph()
    sess = tf.Session(graph=g)
    K.set_session(sess)
    with g.as_default():
    ############################################################# DEBUG
      tasks = ["task0"]
      task_types = {task: "classification" for task in tasks}
      n_samples = 10