[英]How can I convert a model trained in tensorflow 2 to a tensorflow 1 frozen graph
我想使用 tensorflow 2 训练模型,但之后我需要使用仅与 tensorflow 1 兼容的转换器。是否可能,如果可以,如何将使用 tensorflow 2 训练的模型转换为 tensorflow 1 格式?
If there is no method that reliably converts your TF2 model to TF1, you can always save the trained parameters (weights, biases) and used them later to initiate your TF1 graph.如果没有可靠的方法将您的 TF2 模型转换为 TF1,您始终可以保存训练过的参数(权重、偏差)并在以后使用它们来启动您的 TF1 图。 I did it for some other purpose before.
我以前是出于其他目的而这样做的。 You can save as follows:
您可以按如下方式保存:
weights = []
for layer in model.layers:
w = layer.get_weights()
if len(w)>0:
print(layer.name)
weights.append(w)
with open('mnist_weights.pkl', 'wb') as f:
pickle.dump(weights, f)
Where for each layer w[0]=weights
and w[1]=biases
对于每一层
w[0]=weights
and w[1]=biases
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.