权重合并顺序模型Keras

时间:2018-09-25 16:34:34

标签: keras sequential

我合并了两个模型,并且工作正常,我正在尝试将此模型的权重加载到具有相同图层的另一个模型中。

TRAINING MODEL

1. ---> ADD DIMENSION (1, 5, 128, 88, 76)
2. ---> PERMUTE (1, 5, 88, 128, 76)
3. ---> REMOVE DIMENSION (440, 128, 76)
4. ---> LSTM_1 DIMENSION (440, 128, 300)
5. ---> LSTM_2 DIMENSION (440, 128, 300)
1. ---> PREV NOTE DIMENSION (440, 128, 2)
1. ---> MERGE(440, 128, 302)
2. ---> ADD DIMENSION (1, 5, 88, 128, 302)
3. ---> PERMUTE DIMENSION (1, 5, 128, 88, 302)
4. ---> REMOVE DIMENSION (640, 88, 302)
5. ---> LSTM DIMENSION_3 (640, 88, 100)
6. ---> LSTM DIMENSION_4 (640, 88, 50)
7. ---> TIMEDISTRIBUTION DIMENSION_4 (640, 88, 2)
8. ---> LAMBDA EXIT DIMENSION_4 (5, 128, 88, 2)

我想保存训练模型的权重并以这种形状加载到其他网络中:

MODEL 2
1. ---> ADD1 DIMENSION_predic (1, 1, 88, 76)
2. ---> PERMUTE1 DIMENSION_predic (1, 88, 1, 76)
3. ---> REMOVE1 DIMENSION_predic (88, 1, 76)
4. ---> LSTM1 DIMENSION_predic (88, 1, 300)
5. ---> DROPOUT1 DIMENSION_predic (88, 1, 300)
6. ---> LSTM2 DIMENSION_predic (88, 1, 300)
7. ---> DROPOUT2 DIMENSION_predic (88, 1, 300)
8. ---> ADD2 DIMENSION_predic (1, 88, 1, 300)
9. ---> PERMUTE2 DIMENSION_predic (1, 1, 88, 300)
10. --> REMOVE2 DIMENSION_predic (1, 88, 300)
11. --> THIS HAS TO BE (1, 88, 302) BUT IS -> (1, 88, 300)
12. --> LSTM3 DIMENSION_predic (1, 88, 100)
13. --> DROPOUT3 DIMENSION_predic (1, 88, 100)
14. --> LSTM4 DIMENSION_predic (1, 88, 50)
15. --> DROPOUT4 DIMENSION_predic (1, 88, 50)
16. --> TIMEDIST. DIMENSION_predic (1, 88, 2)
17. --> FINAL_RESHAPE DIMENSION_predic (1, 1, 88, 2)

两个模型具有相同的层数,但是“训练模型”具有合并层,因此我在将权重从“训练模型”加载到“模型2”时遇到了问题。我正在按名称加载砝码:

model_2.load_weights("./models/model_TEST.h5", by_name = True)

但是我有这个尺寸错误:

ValueError: Dimension 0 in both shapes must be equal, but are 300 and 302. Shapes are [300,400] and [302,400]. for 'Assign_6' (op: 'Assign') with input shapes: [300,400], [302,400].

问题出在“型号2”编号 11 的层中。我不知道如何将权重从“训练模型”加载到“模型2”中。这也不起作用。

get_weights()  
set_weights(weights)

这是一个顺序模型,两者都是。

谢谢你们!

0 个答案:

没有答案