Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为神经网络单独设置起始权重_Python_Tensorflow_Keras_Neural Network - Fatal编程技术网

Python 为神经网络单独设置起始权重

Python 为神经网络单独设置起始权重,python,tensorflow,keras,neural-network,Python,Tensorflow,Keras,Neural Network,我有一个简单的前馈神经网络,由8个输入神经元组成,然后是2个隐藏层,每个隐藏层有6个隐藏神经元,1个输出层由1个输出神经元组成 Keras代码是: model = Sequential() model.add(Dense(6, input_dim = 8, activation='tanh') model.add(Dense(6, activation='tanh')) model.add(Dense(1, activation='tanh')) 问题: 因为我知道8个输入参数中哪一个对单个

我有一个简单的前馈神经网络,由8个输入神经元组成,然后是2个隐藏层,每个隐藏层有6个隐藏神经元,1个输出层由1个输出神经元组成

Keras代码是:

model = Sequential()

model.add(Dense(6, input_dim = 8, activation='tanh')
model.add(Dense(6, activation='tanh'))
model.add(Dense(1, activation='tanh'))
问题:


因为我知道8个输入参数中哪一个对单个输出的影响最大,所以我可以将它们的开始权重设置为相对于其他输入参数更高的值。如果可能的话,可以显著缩短培训时间(如果我没有错)。

需要更多关注此问题目前在一个问题中包含多个问题。它应该只关注一个问题。我决定结束这个问题。一个问题不应该像你那样包含多个问题(问题A和问题b)。如果你在stackoverflow中问多个问题会更好。。如果你读到@Istiak,你就会明白:现在只问了一个问题。
# reading the initial weights and bias of the input layer
layer_1 = (model.layers)[0]

# reading the initial weights of the input layer
w_1 = layer_1.get_weights()[0]

# setting weights for nth parameter of the input layer to a modified value val
w_1[n, :] = val

# setting the modified weights and unmodified bias of the input layer 
layer_1.set_weights([w_1, layer_1.get_weights()[1]])

# writing layer_1 to model
(model.layers)[0] = layer_1