![](/img/trans.png)
[英]Keras Model for Siamese Network not Learning and always predicting the same ouput
[英]How to save base network of a siamese model?
我正在嘗試使用相當復雜的基礎網絡構建連體 model。 構建基礎網絡后,我使用以下代碼構建我的連體網絡:
base_network=create_base_model(0.2)
img1=Input(shape=(256,256,3))
img2=Input(shape=(256,256,3))
text_input1 = Input(shape=(), dtype=tf.string, name='text_1')
text_input2 = Input(shape=(), dtype=tf.string, name='text_2')
output1= base_network([img1, text_input1])
output2= base_network([img2, text_input2])
distance = Lambda(euclidean_distance)([output1, output2])
siamese_model = Model([[img1,text_input1], [img2, text_input2]], distance)
基礎網絡的 output 的形式model
,其中
model=Model(inputs=[input1,input2], outputs=[z])
問題是在訓練連體網絡之后,我想使用基礎網絡的 output 作為嵌入,這樣我就可以運行無監督學習算法。 但是,在訓練 siamese 網絡時,我想一次訓練 10 個 epoch,然后保存它並在需要時繼續訓練。 在這種情況下,當我保存並重新加載 Siamese model 時,我不確定如何保存/訪問基礎網絡。 For example, I get the following plot for the siamese model which requires 2 inputs (my base model uses 2 inputs so technically I have 4 inputs as shown in the diagram), but I want to use the base model which requires only 1 input post培訓(技術上 2 作為我的基礎 model 使用 2)。
誰能給我關於如何使用保存的連體 model 加載更新的基礎 model 的建議,或者是否有更好的方法首先保存它?
非常感謝。
if epoch %5 == 0
path = f'/tmp/model{epoch}.h5'
base_network.save(path)
base_network = tf.keras.models.load_model(path)
這不好嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.