Exemplo n.º 1
0
def main():

    #   loop = tf.while_loop(
    #     cond = lambda i: i < tf.Variable(100, name='Const100'),
    # #     cond = lambda i: i < tf.constant(5, name='Const5') + tf.constant(100, name='Const100'),
    #     body = lambda i: i + tf.constant(1,   name='Const1'  ),
    #     loop_vars=[ tf.placeholder(tf.int32, name='INPUT') ],
    #     parallel_iterations=1
    #   )
    #
    #   y = tf.identity(loop, 'OUTPUT')

    #   x = tf.Variable(0, name='Const0')
    #   y = tf.cond(
    #     x < tf.constant(1, name='Const1'),
    #     lambda: tf.identity( tf.constant(2, name='Const2') ),
    #     lambda: tf.Variable(3, name='Const3')
    #   )

    #   INPUT = tf.constant(
    # #     np.column_stack([
    #       np.arange(4),
    # #       np.arange(1000,2000)
    # #     ]),
    #     name='INPUT'
    #   )
    #   OUTPUT = tf.map_fn(lambda x: x*1337, INPUT, parallel_iterations=1)
    # #   OUTPUT = tf.map_fn(lambda x: tf.Print(x*1337, [x]), INPUT, parallel_iterations=1)
    #   OUTPUT = tf.identity(OUTPUT, name='OUTPUT')

    #   OUTPUT = tf.TensorArray(tf.float64, size=4)

    INPUT = tf.constant(np.random.rand(40, 20, 50), name='INPUT')
    OUTPUT = tf.identity(INPUT, name='OUTPUT')
    #   MAP_FN = tf.map_fn( lambda i: tf.multiply(i,i, name='I_TIMES_I'), INPUT, name='MAP_FN' )
    #   OUTPUT = tf.identity(MAP_FN, name='OUTPUT')

    cfg = tf.ConfigProto(device_count={'GPU': 0})

    with tf.Session(config=cfg) as sess:

        #     sess.run( tf.global_variables_initializer() )
        #     print( sess.run(y, feed_dict = {'INPUT:0': 0}) )

        #    print( sess.run(OUTPUT) )

        dot = tf2dot(OUTPUT, sess=sess)
        dot.format = 'pdf'
        dot.attr(root='INPUT')
        #     dot.attr( splines='true')
        #     dot.attr( rank='same' )
        #     dot.attr( ranksep='0.01', nodesep='0.01' )
        #     dot.attr( rankdir='LR' )
        #     dot.attr(splines='ortho', layout='circo')

        tmpdir = mkdtemp()
        help(dot.render)
        dot.render(directory=tmpdir, view=True)
Exemplo n.º 2
0
Created on Dec 1, 2018

@author: Dirk Toewe
'''

import tensorflow as tf
from tf2x import tf2dot
from tempfile import mkdtemp

with tf.Graph().as_default() as graph:
    tf_a = tf.constant([1, 2, 3], dtype=tf.float32, name='a')
    tf_b = tf.constant([4, 5, 6], dtype=tf.float32, name='b')
    tf_c = tf.placeholder(shape=[], dtype=tf.bool, name='c')
    tf_d = tf.cond(tf_c, lambda: tf_a, lambda: tf_b, name='d')
    tf_e = tf.identity(tf_d, name='e')

    with tf.Session() as sess:
        dot = tf2dot(graph, sess=sess)

        result_e = sess.run(tf_d, feed_dict={tf_c: False})
        print('E(false):', result_e)

        result_e = sess.run(tf_d, feed_dict={tf_c: True})
        print('E(true):', result_e)

tmpdir = mkdtemp()

dot.format = 'png'
dot.attr(root='c:0')
dot.render(directory=tmpdir, view=True)
Exemplo n.º 3
0
'''
Created on Dec 1, 2018

@author: Dirk Toewe
'''

import tensorflow as tf
from tf2x import tf2dot
from tempfile import mkdtemp

tf_loop = tf.while_loop(cond=lambda i: i < tf.constant(16, name='iMax'),
                        body=lambda i: i + 1,
                        loop_vars=(tf.constant(0, name='i0'), ))
tf_out = tf.identity(tf_loop, name='out')

with tf.Session() as sess:
    dot = tf2dot(tf_out, sess=sess)

tmpdir = mkdtemp()

dot.format = 'png'
dot.attr(root='i0')
dot.attr(newrank='true')
dot.render(directory=tmpdir, view=True)
Exemplo n.º 4
0
'''
Created on Dec 1, 2018

@author: Dirk Toewe
'''

import tensorflow as tf
from tf2x import tf2dot
from tempfile import mkdtemp

tf_a = tf.constant([1, 2, 3], dtype=tf.float32, name='a')
tf_b = tf.placeholder(dtype=tf.float32, name='b')
tf_c = tf.add(tf_a, tf_b, name='c')

with tf.Session() as sess:
    dot = tf2dot(tf_c, sess=sess)

tmpdir = mkdtemp()

dot.format = 'png'
dot.render(directory=tmpdir, view=True)