1

我想为现有模型设置权重,例如 VGG 16。但是,我只想为模型设置权重,不包括最后一个(完全连接的)层。我已经尝试使用model.layers[:-1].set_weights(weights[:-1]),它会导致错误

File "server.py", line 114, in evaluate                                                                                   
model.layers[:-1].set_weights(weights[:-1])          
AttributeError: 'list' object has no attribute 'set_weights'  

有一种解决方案使用 for 循环来设置权重,但效率低下。

weights_list = model.get_weights()
for i, weights in enumerate(weights_list[0:9]):
    model.layers[i].set_weights(weights)

有没有办法为模型的某些层设置权重?谢谢!

4

0 回答 0