Tensorflow

来源:互联网 发布:测斜仪数据计算方法 编辑:程序博客网 时间:2024/05/19 23:15

 

import tensorflow as tfa = tf.add(3, 5)sess = tf.Session()print sess.run(a)sess.close() 

import tensorflow as tfa = tf.add(3, 5)# with clause takes care# of sess.close()with tf.Session() as sess:    print sess.run(a)

x = 2y = 3op1 = tf.add(x, y)op2 = tf.mul(x, y)useless = tf.mul(x, op1)op3 = tf.pow(op2, op1)with tf.Session() as sess:op3, not_useless = sess.run([op3, useless])


#To put part of a graph on a specific CPU or GPU:# Creates a graph.with tf.device('/gpu:2'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], name='b') c = tf.matmul(a, b)# Creates a session with log_device_placement set to True.sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))# Runs the op.print sess.run(c)

tf.Variable is a class, but tf.constant is an op





                                             
0 0
原创粉丝点击