Tensorflow method described

A, reduce series function (operation dimension)

1, tf.reduce_sum (input_tensor, axis = None, keep_dims = False, name = None, reduction_indices = None) // sum
input_tensor: denotes an input
axis: representation sum operation in that dimension.
keep_dims: Indicates whether to retain the original data dimensions, False is equivalent to the original data after the implementation will be one less dimension.
reduction_indices: For compatibility with older versions, now no longer used.

# 'X' IS [[. 1,. 1,. 1]
# [. 1,. 1,. 1]]
tf.reduce_sum (X) ==>. 6
tf.reduce_sum (X, 0) ==> [2, 2, 2]
tf.reduce_sum (X,. 1) ==> [. 3,. 3]
tf.reduce_sum (X,. 1, keep_dims = True) ==> [[. 3], [. 3]]
tf.reduce_sum (X, [0,. 1 ]) ==> 6

2, tf.reduce_mean (input_tensor, reduction_indices = None, keep_dims = False, name = None) // averaging

input_tensor: represents the input
axis: representation sum operate in that dimension.
keep_dims: Indicates whether to retain the original data dimensions, False is equivalent to the original data after the implementation will be one less dimension.

# 'X' IS [[1., 2.]
# [3., 4.]]
tf.reduce_mean (X) ==> # 2.5 if the second parameter is not specified, then averaged over all the elements in the value
tf.reduce_mean (x, 0) ==> [2., 3.] # 0 designated as the second parameter, the first dimension averaging element, i.e., each column averaging
tf.reduce_mean (x, 1) ==> [1.5, 3.5] # 1 designated as the second parameter, the second dimension averaging element, i.e. each row averaging

3, tf.reduce_max (input_tensor, reduction_indices = None, keep_dims = False, name = None) // find the maximum

# 'X' IS [[1., 2.]
# [3., 4.]]
tf.reduce_max (X) ==> #. 4 if the second parameter is not specified, then taking the maximum of all of the elements value
tf.reduce_max (x, 0) ==> [3., 4.] # specify the second argument is 0, the maximum value of the first dimension of the element, i.e., selecting the maximum value for each column
tf.reduce_max (x, 1) ==> [2, 4] specify the second parameter is # 1, the maximum value of the second dimension of the element, i.e., selecting the maximum value in each row

4、tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)

Parameters:
the Shape: tensor tensor one-dimensional, and it is output.
mean: mean of a normal distribution. 
stddev: normal distribution standard deviation.
dtype: type of output.
seed: an integer, when provided, each generated random number are the same.
name: The name of the operation

5、tf.random_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)

Random values output from the normal distribution.
parameter:

shape: tensor tensor one-dimensional, and it is output.
mean: mean of a normal distribution.
stddev: normal distribution standard deviation.
dtype: type of output.
seed: an integer, when provided, each generated random number are the same.
name: the name of the operation.

-------------------------代码--------------
a = tf.Variable(tf.random_normal([2,2],seed=1))
b = tf.Variable(tf.truncated_normal([2,2],seed=2))
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(a))
print(sess.run(b))

Output:
[[1.48459876 -0.81131822]
[0.06532937 -2.44270396]]
[[-0.85811085 -0.19662298]
[0.13895047 -1.22127688]]

---------------------------------------------------------

 Second, other methods

1、tf.matmul(x,y)

x, y matrix multiply

2, tf.nn.softmax () // linear cost function

3, tf.nn.softmax_cross_entropy_with_logits () // represents a cross-entropy function with softmax

4, tf.nn.sigmod_cross_entropy_with_logits () // represents a cross-entropy function with sigmod

5, # in tensorflow1.2 in tf.nn.tanh and can tf.tanh

tanh is a hyperbolic one, tanh () is the hyperbolic tangent. Hyperbolic tangent function of the derivative of formula:

 

input=tf.constant([1,2,3,4],dtype=tf.float32)
#在tensorflow1.2中tf.nn.tanh和tf.tanh都可以
#output=tf.nn.tanh(input)
output=tf.tanh(input)
with tf.Session() as sess:
    print(sess.run(output))
    sess.close()

Output Results:
[0.76159418 0.96402758 0.99505472 0.99932921]

6、tf.cast(a,dtype=tf.bool)

f.cast (a, dtype = tf.bool)
converting x into a data format dtype. For example, the original data format is x BOOL
A = tf.Variable ([1,0,0,1,1])
B = tf.cast (A, DTYPE = tf.bool)
Sess = tf.Session ()
sess.run (tf.initialize_all_variables ())
Print (sess.run (B))
# [True True True False False]

7, tf.argmax (the y-, 1)
# First, be clear, tf.argmax can think is np.argmax. tensorflow use numpy implement this API.
# tf.argmax is to return maximum value of the index is located.
#argmax dimensional tensor return position a maximum value where
test = np.array ([[1, 2, 3], [2, 3, 4], [5, 4, 3], [8, 7, 2] ])
np.argmax (Test, 0) output #: Array ([. 3,. 3,. 1]
np.argmax (Test,. 1) # output: array ([2, 2, 0, 0]

Source acquisition mode, the total number of public attention RaoRao1994, wonderful view to the stage - all articles, we can get the download link resources

Get more resources, please pay attention to the public the total number RaoRao1994

Published 37 original articles · won praise 13 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_26078953/article/details/91366585