ここに、Keras用のGoogleNetモデルがあります。ネットワークの個々の層の変更をブロックするための可能な方法はありますか?事前トレーニング済みモデルの最初の2つのレイヤーが変更されないようにブロックしたいと思います。
「個々のレイヤーの変更をブロックする」ことにより、これらのレイヤーをトレーニングしたくない、つまり、ロードされた重みを変更したくないと想定しています(以前のトレーニングで学習した可能性があります)。
その場合trainable=False
、レイヤーに渡すことができ、パラメーターはトレーニング更新ルールに使用されません。
例:
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential([
Dense(32, input_dim=100),
Dense(output_dim=10),
Activation('sigmoid'),
])
model.summary()
model2 = Sequential([
Dense(32, input_dim=100,trainable=False),
Dense(output_dim=10),
Activation('sigmoid'),
])
model2.summary()
2番目のモデルのモデルの概要で、パラメーターが訓練不可能なものとしてカウントされていることがわかります。
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
dense_1 (Dense) (None, 32) 3232 dense_input_1[0][0]
____________________________________________________________________________________________________
dense_2 (Dense) (None, 10) 330 dense_1[0][0]
____________________________________________________________________________________________________
activation_1 (Activation) (None, 10) 0 dense_2[0][0]
====================================================================================================
Total params: 3,562
Trainable params: 3,562
Non-trainable params: 0
____________________________________________________________________________________________________
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
dense_3 (Dense) (None, 32) 3232 dense_input_2[0][0]
____________________________________________________________________________________________________
dense_4 (Dense) (None, 10) 330 dense_3[0][0]
____________________________________________________________________________________________________
activation_2 (Activation) (None, 10) 0 dense_4[0][0]
====================================================================================================
Total params: 3,562
Trainable params: 330
Non-trainable params: 3,232
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加