0
votes

I have a simple feed forward neural network consisting of 8 input neurons, followed by 2 hidden layers, each with 6 hidden neurons and 1 output layer consisting of 1 output neuron.

The Keras code is:

model = Sequential()

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

Question:

Since I know which of the 8 input parameters has the strongest impact on the single output, I could set their start weights to a higher value relative to the other input parameters. If this would be possible that could reduce the training time significantly (if I am not wrong).

1
Needs more focus This question currently includes multiple questions in one. It should focus on one problem only. I am flagging this question to be closed. A question should not contain multiple question like you did (question a and question b). It would be better if you ask multiple questions in stackoverflow stackoverflow.com/questions/ask .. You will be clear if you read about flagging meta.stackoverflow.com/a/396761/13146129user13146129
@Istiak: Now only one question is asked.len

1 Answers

0
votes
# 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