擅长:python、mysql、java
<p>不用将整个模型保存到一个.h5文件中,你可以用你自己的格式分别保存每个层的权重。e、 g</p>
<pre class="lang-py prettyprint-override"><code>import pickle
# Create model and train ...
#save the weights for each layer in your model
network_config = {
'layer1': layer1.get_weights(),
'layer2': layer2.get_weights(),
'layer3': layer3.get_weights()
}
with open('network_config.pickle', 'wb') as file:
pickle.dump(network_config, file)
</code></pre>
<p>然后,只能为仍在使用的层加载权重。你知道吗</p>
<pre class="lang-py prettyprint-override"><code>with open('network_config.pickle', 'rb') as file:
network_config = pickle.load(file)
#build new model that may be missing some layers
layer1.set_weights(network_config['layer1'])
layer3.set_weights(network_config['layer3'])
</code></pre>