本文介绍了在keras中使用conv2D层时,在tf.random.set_seed中设置种子是否还会设置glorot_uniform kernel_initializer使用的种子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently training a convolutional neural network using a conv2D layer defined like this:

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

我的理解是,默认的kernel_initializer为glorot_uniform,其默认种子为'none':

My understanding is that the default kernel_initializer is glorot_uniform which has a default seed of '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)

我正在尝试生成可复制的代码,并且已经按照:

I'm trying to produce reproducible code and have already set random seeds as per 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)

conv2D layerglorot_uniform使用的tf.random.set_seed种子编号吗?如果没有,那么在定义conv2D layer时将如何定义该种子?

Is the tf.random.set_seed seed number used by glorot_uniform within a conv2D layer? If not, how would that seed be defined when defining the conv2D layer?

推荐答案

感谢扎比尔·纳粹 ,答案是是".设置tf.random.set_seed()还会设置Conv2D层的glorot_uniform种子.

Thanks to Zabir Al Nazi, the answer is "yes". Setting tf.random.set_seed() also sets the Conv2D layer's glorot_uniform seed.

这篇关于在keras中使用conv2D层时,在tf.random.set_seed中设置种子是否还会设置glorot_uniform kernel_initializer使用的种子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 00:58