def test_graph_save(self): n_samples = 10 n_features = 11 n_tasks = 1 batch_size = 10 X = np.random.rand(batch_size, n_samples, n_features) y = np.ones(shape=(n_samples, n_tasks)) ids = np.arange(n_samples) dataset = dc.data.NumpyDataset(X, y, None, ids) g = TensorGraph(model_dir='/tmp/tmpss5_ki5_') inLayer = Input(shape=(None, n_samples, n_features)) g.add_feature(inLayer) flatten = Flatten() g.add_layer(flatten, parents=[inLayer]) dense = Dense(out_channels=1) g.add_layer(dense, parents=[flatten]) g.add_output(dense) label_out = Input(shape=(None, 1)) g.add_label(label_out) loss = LossLayer() g.add_layer(loss, parents=[dense, label_out]) g.set_loss(loss) g.fit(dataset, nb_epoch=100) g.save() g1 = TensorGraph.load_from_dir('/tmp/tmpss5_ki5_') print(g1) print(g1.predict_on_batch(X))
def test_get_layer_variable_values(self): """Test to get the variable values associated with a layer""" # Test for correct value return (normal mode) tg = dc.models.TensorGraph() var = Variable([10.0, 12.0]) tg.add_output(var) expected = [10.0, 12.0] obtained = tg.get_layer_variable_values(var)[0] np.testing.assert_array_equal(expected, obtained) # Test for shapes (normal mode) tg = dc.models.TensorGraph() input_tensor = Input(shape=(10, 100)) output = Dense(out_channels=20, in_layers=[input_tensor]) tg.add_output(output) expected_shape = (100, 20) obtained_shape = tg.get_layer_variable_values(output)[0].shape assert expected_shape == obtained_shape
def test_input(self): """Test that Input can be invoked.""" in_shape = (4, 3) with self.session() as sess: out_tensor = Input(in_shape)()
from deepchem.models import TensorGraph mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) import deepchem as dc import tensorflow as tf from deepchem.models.tensorgraph.layers import Layer, Input, Reshape, Flatten from deepchem.models.tensorgraph.layers import Dense, SoftMaxCrossEntropy, ReduceMean, SoftMax train = dc.data.NumpyDataset(mnist.train.images, mnist.train.labels) valid = dc.data.NumpyDataset(mnist.validation.images, mnist.validation.labels) tg = dc.models.TensorGraph(tensorboard=True, model_dir='/tmp/mnist', batch_size=1000) feature = Input(shape=(None, 784)) tg.add_feature(feature) # Images are square 28x28 (batch, height, width, channel) make_image = Reshape(shape=(-1, 28, 28, 1)) tg.add_layer(make_image, parents=[feature]) class Conv2d(Layer): def __init__(self, num_outputs, kernel_size=5, **kwargs): self.num_outputs = num_outputs self.kernel_size = kernel_size super().__init__(**kwargs) def __call__(self, *parents): parent_tensor = parents[0].out_tensor