我试图为ResNet建立一个模型模拟器,只是为了了解层中的每个细节,但是当我对conv2D层使用 get_config 时,中的比例,模式和分布kernel_initializer 是为默认congiguration不同。我怎样才能改变这个参数?关于resnet Conv2D,请参见第14-18行,其次是常规的Conv2D
1 #resnet Conv2D
2 resnet_model.layers[2].get_weights()
3
4 {'name': 'conv1',
5 'trainable': True,
6 'filters': 64,
7 'kernel_size': (7, 7),
8 'strides': (2, 2),
9 'padding': 'valid',
10 'data_format': 'channels_last',
11 'dilation_rate': (1, 1),
12 'activation': 'linear',
13 'use_bias': True,
14 'kernel_initializer': {'class_name': 'VarianceScaling',
15 'config': {'scale': 2.0,
16 'mode': 'fan_in',
17 'distribution': 'normal',
18 'seed': None}},
19 'bias_initializer': {'class_name': 'Zeros', 'config': {}},
20 'kernel_regularizer': None,
21 'bias_regularizer': None,
22 'activity_regularizer': None,
23 'kernel_constraint': None,
24 'bias_constraint': None}
1 #normal Conv2D
2 model.layers[2].get_weights()
3
4 {'name': 'conv1',
5 'trainable': True,
6 'filters': 64,
7 'kernel_size': (7, 7),
8 'strides': (2, 2),
9 'padding': 'valid',
10 'data_format': 'channels_last',
11 'dilation_rate': (1, 1),
12 'activation': 'linear',
13 'use_bias': True,
14 'kernel_initializer': {'class_name': 'VarianceScaling',
15 'config': {'scale': 1.0,
16 'mode': 'fan_avg',
17 'distribution': 'uniform,',
18 'seed': None}},
19 'bias_initializer': {'class_name': 'Zeros', 'config': {}},
20 'kernel_regularizer': None,
21 'bias_regularizer': None,
22 'activity_regularizer': None,
23 'kernel_constraint': None,
24 'bias_constraint': None}
答案 0 :(得分:1)
from keras.initializers import VarianceScaling
convLayer = Conv2D(filters, kernel_size, ...,
kernel_initializer = VarianceScaling(scale=2.0,
mode='fan_in',
distribution='normal',
seed=None),
...)
答案 1 :(得分:0)
您可能想看一看初始化器文档:https://keras.io/initializers/
要更改此参数,需要通过设置kernel_initializer class_name 参数来选择一个初始化程序。然后,您可以通过 config 字段将参数传递给该初始化程序。