ValueError:图层权重形状(129,1)与提供的权重形状(128,1)不兼容

时间:2019-08-27 09:50:17

标签: tensorflow keras keras-layer tensor tf.keras

我正在尝试从存储库https://github.com/familyld/DeepCF/blob/master/CFNet.py中运行代码。

这是发生错误的函数的代码。

def load_pretrain_model1(model, dmf_model, dmf_layers,):
# MF embeddings
dmf_user_embeddings = dmf_model.get_layer('user_layer0').get_weights()
dmf_item_embeddings = dmf_model.get_layer('item_layer0').get_weights()
model.get_layer('user_layer0').set_weights(dmf_user_embeddings)
model.get_layer('item_layer0').set_weights(dmf_item_embeddings)

# DMF layers
for i in range(1, len(dmf_layers)):
    dmf_user_layer_weights = dmf_model.get_layer('user_layer%d' % i).get_weights()
    model.get_layer('user_layer%d' % i).set_weights(dmf_user_layer_weights)
    dmf_item_layer_weights = dmf_model.get_layer('item_layer%d' % i).get_weights()
    model.get_layer('item_layer%d' % i).set_weights(dmf_item_layer_weights)

# Prediction weights
dmf_prediction = dmf_model.get_layer('prediction').get_weights()
new_weights = np.concatenate((dmf_prediction[0], np.array([[0,]] * dmf_layers[-1])), axis=0)
new_b = dmf_prediction[1]
model.get_layer('prediction').set_weights([new_weights, new_b]) 
return model

当我尝试运行它时,出现以下错误消息。

File "/home/ade-lab/PycharmProjects/deepcf/CFNet.py" line 219, in <module>
model=load_pretrain_model(model,dmf_model,userlayers)


File "/home/ade-lab/PycharmProjects/deepcf/CFNet.py" line 128, in load_pretrain_model1
model.get_layer('prediction').set_weights([new_weights,new_b])
  

ValueError:图层权重形状(129,1)与提供的权重形状(128,1)不兼容

0 个答案:

没有答案