gpt4 book ai didi

python - 在keras中使用conv2D层时,在tf.random.set_seed中设置种子是否还会设置glorot_uniform kernel_initializer使用的种子吗?

转载 作者:行者123 更新时间:2023-12-03 15:03:04 24 4
gpt4 key购买 nike

我目前正在使用定义如下的convolutional neural network训练conv2D layer:

conv1 = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='SAME', activation='relu')(inputs)

我的理解是,默认的kernel_initializer是 glorot_uniform,其默认种子为'none':
tf.keras.layers.Conv2D(
filters, kernel_size, strides=(1, 1), padding='valid', data_format=None,
dilation_rate=(1, 1), activation=None, use_bias=True,
kernel_initializer='glorot_uniform', bias_initializer='zeros',
kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None,
kernel_constraint=None, bias_constraint=None, **kwargs
)



tf.compat.v1.keras.initializers.glorot_uniform(seed=None, dtype=tf.dtypes.float32)

我正在尝试产生可复制的代码,并且已经按照 this StackOverflow post设置了随机种子:
seed_num = 1

os.environ['PYTHONHASHSEED'] = '0'
np.random.seed(seed_num)
rn.seed(seed_num)

session_conf = tf.compat.v1.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1)

tf.random.set_seed(seed_num)

sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf)
K.set_session(sess)
tf.random.set_seed中的 glorot_uniform使用的 conv2D layer种子编号吗?如果没有,那么在定义 conv2D layer时将如何定义该种子?

最佳答案

对于每一层,您都可以将种子用于内核初始化和偏差初始化。

您可以单独为初始化程序添加种子,
kernel_initializer=initializers.glorot_uniform(seed=0))
从文档中:

glorot_normal

keras.initializers.glorot_normal(seed=None)

Glorot normal initializer, also called Xavier normal initializer.

It draws samples from a truncated normal distribution centered on 0 with stddev = sqrt(2 / (fan_in + fan_out)) where fan_in is the number of input units in the weight tensor and fan_out is the number of output units in the weight tensor.

Arguments

seed: A Python integer. Used to seed the random generator.

关于python - 在keras中使用conv2D层时,在tf.random.set_seed中设置种子是否还会设置glorot_uniform kernel_initializer使用的种子吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61364793/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com