Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. from unittest import TestCase
  2.  
  3. import numpy as np
  4. import os
  5. import tensorflow as tf
  6. from keras import backend as K
  7. from sklearn.preprocessing import MinMaxScaler
  8.  
  9. import darwin
  10. from darwin.zoo.networks import MLP
  11. from darwin.training import pipeline, experiment
  12. from darwin.zoo import metrics
  13. from darwin.database.molecules import DBInterface
  14.  
  15.  
  16. class MLPTrainer:
  17.  
  18. def setUp(self):
  19. # Set up training enviroment
  20. darwin.gpu(0)
  21. os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # to disable nasty tf logging
  22. config = tf.ConfigProto()
  23. config.gpu_options.allow_growth = True
  24. self.tf_session = tf.InteractiveSession(config=config)
  25. K.set_session(self.tf_session)
  26.  
  27. # Connect to the molecular database
  28. db = DBInterface(db_name='db_proba', username='user_proba', password='proba', port=27017)
  29.  
  30. # Get dataset
  31. self.data = db.datasets.get_dataset(dataset_name='bbb_etkins', target_name='activity',
  32. mol_repr='fp', test_ratio=0.15)
  33.  
  34. def tearDown(self):
  35. self.tf_session.close()
  36.  
  37. def run_experiment(self):
  38. @pipeline
  39. class preprocessor:
  40. data = self.data
  41. minmax = MinMaxScaler()
  42. pipe = minmax
  43.  
  44. @experiment
  45. class mnist_experiment:
  46. class classifier:
  47. pipe = MLP(input_shape=self.data.X.shape[1], output_dim=1, output_nonlinearity='sigmoid')
  48. pipe_batch_size = 32
  49. pipe_epochs = 5
  50. target = metrics.f1
  51. hyperparameter_space = {'hidden_sizes': [[200, 100], [100]]}
  52.  
  53. experiment = preprocessor, classifier
  54.  
  55. mnist_experiment.make()
  56.  
  57.  
  58. pipe_test = MLPTrainer()
  59. pipe_test.setUp()
  60. pipe_test.run_experiment()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement