SoFunction
Updated on 2025-03-01

Detailed explanation of variable initialization function in Tensorflow

Tensorflow provides 7 different initialization functions:

tf.constant_initializer(value) #Initialize the variable to a given constant, initialize all the provided values.

Assume in a convolutional layer,Set paranoiabfor0,则写法for:
1. bias_initializer=tf.constant_initializer(0)
2. bias_initializer=tf.zeros_initializer(0)

tf.random_normal_initializer(mean,stddev) # function is to initialize the variable into a random value that satisfies the positive distribution, the main parameters (mean and standard deviation of the positive distribution), and use the given mean and standard deviation to initialize the uniform distribution

tf.truncated_normal_initializer(mean,stddev,seed,dtype) #Function: Initialize the variable to a random value that satisfies the positive and stale distribution, but if the random value deviates from the mean by more than 2 standard deviations, then this number will be re-randomized

mean:Used to specify mean;stddevUsed to specify standard deviation;seed:Used to specify random number seeds;dtype:Data type used to specify random numbers。
Usually only one standard deviation is requiredstddevThis parameter is OK。

tf.random_uniform_initializer(a,b,seed,dtype) #Enitually initialize from a to b, initialize the variable into a random value that satisfies the average distribution, main parameters (maximum value, minimum value)

tf.uniform_unit_scaling_initializer(factor,seed,dtypr) #Initialize variables to random values ​​that satisfy the even distribution but do not affect the output order of magnitude

max_val=(3/input_size)*factor;
input_sizeRefers to the dimension of the input data,Assume that the input isx,Calculated asx*w,butinput_size=[0].
Its distribution interval is[-max_val,max_val]

tf.zeros_initializer() #Set the variable to all 0; it can also be abbreviated as ()

tf.ones_initializer() #Set the variable to all 1; can be abbreviated as ()

The above detailed explanation of the variable initialization function in Tensorflow is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.