def test_then_with_1(self): h1 = (tb.build(self.x).then_with( tf.device, "/cpu:0")(lambda x: x.softmax()).tensor()) h2 = (tb.build( self.x).with_device("/cpu:0")(lambda x: x.softmax()).tensor()) assert "CPU:0" in h1.device assert "CPU:0" in h2.device
def test_branches(self): a = tb.build(tf.placeholder(tf.float32, shape=[None, 8])) b = tb.build(tf.placeholder(tf.float32, shape=[None, 8])) tree = tb.branches([a, b]) assert type(tree) == tb.BuilderTree [a2, b2] = tree.builders() assert a.tensor() == a2.tensor() and b.tensor() == b2.tensor()
def test_then_with_1(self): h1 = ( tb.build(self.x) .then_with(tf.device, "/cpu:0")(lambda x: x.softmax() ) .tensor() ) h2 = ( tb.build(self.x) .with_device("/cpu:0")(lambda x: x.softmax() ) .tensor() ) assert "CPU:0" in h1.device assert "CPU:0" in h2.device
############################## ##### GETTING STARTED ############################## # TensorBuilder includes a set of primitives that you can use to wrap, around import tensorflow as tf from tensorflow.contrib import layers as layers from tensorbuilder import tb x = tf.placeholder(tf.float32, shape=[None, 40]) keep_prob = tf.placeholder(tf.float32) h = (tb.build(x).map(layers.fully_connected, 100, activation_fn=tf.nn.tanh).map( tf.nn.dropout, keep_prob).map(layers.fully_connected, 30, activation_fn=tf.nn.softmax).tensor()) print(h) # The previous is equivalent to this next example using the `slim_patch`, which includes the `fully_connected` method that is taken from `tf.contrib.layers` import tensorflow as tf from tensorbuilder import tb import tensorbuilder.slim_patch x = tf.placeholder(tf.float32, shape=[None, 5]) keep_prob = tf.placeholder(tf.float32) h = (
############################## ##### FUNCTIONS ############################## ############################## ##### builder ############################## # The following example shows you how to construct a `tensorbuilder.tensorbuilder.Builder` from a tensorflow Tensor. import tensorflow as tf from tensorbuilder import tb a = tf.placeholder(tf.float32, shape=[None, 8]) a_builder = tb.build(a) print(a_builder) # The previous is the same as a = tf.placeholder(tf.float32, shape=[None, 8]) a_builder = a.builder() print(a_builder) ############################## ##### branches ############################## # Given a list of Builders and/or BuilderTrees you construct a `tensorbuilder.tensorbuilder.BuilderTree`.
def test_unit(self): h = tf.nn.softmax(self.x) h2 = tb.build(self.x)._unit(h).tensor() assert h2 == h
def test_build(self): builder = tb.build(self.x) assert type(builder) == tb.Builder