Keras set_weights不会通过过度改变权重来改变预测

时间:2018-04-26 01:39:43

标签: python tensorflow keras keras-layer

我正在改变我从调用layer.get_weights()获得的weight_matrix,然后使用set_weights()我更改了几个权重,当我再次调用get_weights()时,它会显示我在set_weights中更改的权重。但是,它根本不会改变我的预测。即使我彻底改变它们。

另外,如果我调用model.compile然后调用layer.set_weights,它会说' int'对象没有属性' set_weights'

我很困惑什么出了问题。

price(2:end-1,i)

现在,当我调用layer.get_weights时,它会返回

layer = 1
hiddenU = 16
val_dictionary = {}
model = keras.models.Sequential(name = 'LSTM')
model.add(keras.layers.LSTM(hiddenU, input_shape = xt.shape[1:], return_sequences = layer > 1))
model.add(Dense(2))
adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=1e-4)
model.compile(loss= lambda y, yp: (pinball(y, yp, 1)), optimizer = 'adam')
model.load_weights('Weights/LSTMGetWeights')
for layer in model.layers:
    weights = layer.get_weights()
print(weights)
    [array([[ 0.36053008, -0.25284126],
       [ 0.37837738, -0.5382352 ],
       [-0.05943123,  0.19144805],
       [ 0.3131915 ,  0.7109782 ],
       [ 0.23572737, -0.11478594],
       [ 0.10371532,  0.6173115 ],
       [ 0.9760161 ,  1.4972438 ],
       [ 0.2379393 , -0.0071888 ],
       [ 0.55228376,  0.46662283],
       [ 1.2852958 ,  0.475782  ],
       [ 0.13585456,  0.5095823 ],
       [-0.13454953, -0.7498165 ],
       [ 0.00282927, -0.53929615],
       [-0.21484761,  0.08239145],
       [ 0.9378741 ,  0.8509973 ],
       [-0.46459877,  0.21304554]], dtype=float32), array([-0.01857078,  0.26882732], dtype=float32)]

layer.set_weights([np.array([[ 0.36053008, 23.023],
       [ 0.37837738, -0.5382352 ],
       [-0.05943123,  0.19144805],
       [ 0.3131915 ,  0.7109782 ],
       [ 0.23572737, -0.11478594],
       [ 0.10371532,  0.6173115 ],
       [ 0.9760161 ,  1.4972438 ],
       [ 0.2379393 , -0.0071888 ],
       [ 0.55228376,  0.46662283],
       [ 1.2852958 ,  0.475782  ],
       [ 0.13585456,  0.5095823 ],
       [-0.13454953, -0.7498165 ],
       [ 0.00282927, -0.53929615],
       [-0.21484761,  0.08239145],
       [ 0.9378741 ,  0.8509973 ],
       [-0.46459877,  0.21304554]], dtype=np.float32), np.array([-0.01857078,  0.26882732], dtype=np.float32)])

更新后的重量。 但是,当我调用model.predict时,它根本不会改变预测。即使我完全改变了权重矩阵。

0 个答案:

没有答案