How do you understand session in tensorflow? Back end

import tensorflow as tf
import numpy as np
x_data=np.float32(np.random.rand(2,100))
y_data=np.dot([0.100,0.200],x_data)+0.300
b = tf.Variable(tf.zeros([1]))
W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))
y=tf.matmul(W,x_data)+b

loss=tf.reduce_mean(tf.square(y-y_data))
optimizer=tf.train.GradientDescentOptimizer(0.5)
train=optimizer.minimize(loss)

init=tf.global_variables_initializer()

sess=tf.Session()
sess.run(init)

for step in range(0,201):
    sess.run(train)
    if step%20==0:
        print (step,sess.run(W),sess.run(b)

how do you understand the tf.session here?

Jan.08,2022

Graph (graph) defines the calculation. But it doesn't evaluate anything, it doesn't contain any values, it just defines the actions you specify in the code. TensorFlow creates a default drawing for you. The default chart is also the default value used by the session when the chart is not manually specified.

Session (session) allows graphics or parts of graphics to be executed. It allocates resources for this (on one or more machines) and holds the actual values of intermediate results and variables.

see this article

https://codeshelper.com/a/11.

Menu