使用已接受的答案here,我正在尝试使用set_weights()方法更改图层的权重,但它似乎无效... 这里是我使用的代码
from keras.layers import Input
from keras.layers.convolutional import Convolution2D
from keras.models import Model
import numpy as np
print("Building Model...")
inp = Input(shape=(20,20,1))
output = Convolution2D(1, (3,3), padding='same',bias=False)(inp)
model_network=Model(inp, output)
print("Weights before change:")
print (model_network.layers[1].get_weights())
w = np.asarray([
[[[
[2,2,2],
[2,2,2],
[2,2,2]
]]]
])
w=np.reshape(w,np.shape(model_network.layers[1].get_weights()))
#print("W:",w)
model_network.layers[1].set_weights(w)
print("Weights after change:")
print(model_network.layers[1].get_weights())
但我的体重保持不变; (在评论中输出)