# TensorFlow学习记录三（会话Session）

Jan 22, 2017 tf.Session类是用来运行TF操作的。

# Build a graph
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b

# launch the graph in session
sess = tf.Session()

# Evaluate the Session \'c\'
print sess.run(c)


# Using the close() method
sess = tf.Session()
sess.run()
sess.close()

#Using the context manager
with tf.Session() as sess:
sess.run()


import tensorflow as tf

matrix1 = tf.constant([[3, 3]])
matrix2 = tf.constant([,
])

product = tf.matmul(matrix1, matrix2)      # matrix multiply

# method 1
# sess = tf.Session()
# result = sess.run(product)

# print(result)
# sess.close()

# method 2
with tf.Session() as sess:
result2 = sess.run(product)
print(result2)
# auto close()


method1下面是显式的释放，method2下面是隐式的释放，其实也就这么简单了。

import tensorflow as tf

input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)

output = tf.mul(input1, input2)

with tf.Session() as sess:
print(sess.run(output, feed_dict = {input1: [7.], input2: [2.]}))
{"ft_lang_label":"__label__zh","ft_lang_prob":0.67786145,"math_prob":0.98103786,"size":1583,"snap":"2020-24-2020-29","text_gpt3_token_len":851,"char_repetition_ratio":0.14819506,"word_repetition_ratio":0.0,"special_character_ratio":0.25142136,"punctuation_ratio":0.18257262,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9912728,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-13T02:20:49Z\",\"WARC-Record-ID\":\"<urn:uuid:990f0305-6966-4346-b3bc-be9eb0934e46>\",\"Content-Length\":\"14004\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2232a163-632c-48fc-80dc-a528e266aef2>\",\"WARC-Concurrent-To\":\"<urn:uuid:d943b0f1-4da2-4791-bc9b-92c96d66e12b>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"http://www.ecohnoch.cn/2017/01/22/shuxue17/\",\"WARC-Payload-Digest\":\"sha1:TX5Q4RJUU2HPAAADCMDX6HATRCQD2NUP\",\"WARC-Block-Digest\":\"sha1:6ZN4GQLXHLI5XFFYSZGGDUVCL2GPZ46U\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593657140746.69_warc_CC-MAIN-20200713002400-20200713032400-00144.warc.gz\"}"}