# 菜鸟 深 学 的 逆袭 之 路 # day5

A Session may have some resources, such as Variable or Queue. When we no longer need the session, we need to release these resources. There are two ways to
call the session.close () method;
use with tf.Session () to create a context (Context) to execute, which is automatically released when the context exits.
To summarize, remember to initialize the variable and then create a session to run it.

Next, we need to understand placeholders. A placeholder is an object, its value can only be specified later, to specify the value of the placeholder, you can use a feed dictionary (feed_dict variable) to pass in, next, we create a placeholder for x, This will allow us to pass in a number when running the session later.

Many times in deep learning, the dimension of the y yy vector is from 0 00 to C−1 C-1C−1. C CC refers to the number of categories classified. If C = 4 C = 4C = 4, then for y yy You may need to have the following conversion method:
Insert picture description here
This is called "one hot" encoding, because in the converted representation, one element of each column is "hot" (meaning set to 1). To perform this conversion in numpy, you may need to write a few lines of code. In tensorflow, only one line of code is needed:

tf.one_hot(labels,depth,axis)

Blogger's Note: tf.Variable () is creating new objects every time. For get_variable (), for a variable object that has already been created, return that object. If no variable object is created, create a new one.

tf.reduce_mean 函数用于计算张量tensor沿着指定的数轴(tensor的某一维度)上的的平均值,主要用作降维或者计算tensor(图像)的平均值。


_ ,c = sess.run([optimizer,cost],feed_dict = {X:mini_batch_X,Y:mini_batch_Y})
#编写代码时,我们经常使用 _ 作为一次性变量来存储我们稍后不需要使用的值。 这里,_具有我们不需要的优化器的评估值(并且c取值为成本变量的值)。
\

The function of tf.cast () function is to perform tensorflow tensor data type conversion. For example, if the read image is of int8 type, the image data format is generally converted to float32 before training.

Published 31 original articles · praised 0 · visits 685

Guess you like

Origin blog.csdn.net/ballzy/article/details/105214242