【发布时间】:2020-01-03 12:04:14
【问题描述】:
我正在尝试一些需要冻结某些选定权重的东西。举个例子
from keras.models import Sequential
from keras.layers import Dense,Input
model = Sequential()
model.add(Dense(4, input_shape=(4,),activation='relu'))
model.add(Dense(3,name="hidden",activation='relu'))
model.add(Dense(2,activation='sigmoid'))
model.compile(loss='mse', optimizer='adam')
print(model.layers[1].get_weights()[0])
这会将输入打印到隐藏层权重。
# Weights input x hidden
# Freeze 2Rx3C and 4Rx2C
# 2Rx3C=0.14362943; 4Rx2C=-0.23868048
array([[-0.05557871, 0.10941017, -0.59108734],
[ 0.37056673, 0.2968588 , 0.14362943],
[-0.05471832, -0.21425706, 0.6455065 ],
[-0.7883829 , -0.23868048, -0.517396 ]], dtype=float32)
根据这个权重矩阵,我想冻结(2nd Row, 3rd Column) 和(4th Row, 2nd Column) 中的值,即分别为0.14362943 和-0.23868048。我不想在反向传播上更新这些值。如何冻结这些选定的权重?
【问题讨论】:
-
嗨,艾卡。答案能解决你的问题吗?
标签: tensorflow keras keras-layer tf.keras keras-2