简体   繁体   English

如何将在 tensorflow 2 中训练的模型转换为 tensorflow 1 冻结图

[英]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.

相关问题 TensorFlow:有没有办法将冻结图转换为检查点模型? - TensorFlow: Is there a way to convert a frozen graph into a checkpoint model? Tensorflow:如何将冻结模型转换为已保存模型 - Tensorflow: how to convert a frozen model to saved model 如何将冻结图转换为 TensorFlow lite - How to convert frozen graph to TensorFlow lite 如何在张量流中可视化估计量训练模型? - How can I visualize the estimator Trained model in tensorflow? 如何将预训练的 tensorflow pb 冻结图转换为可修改的 h5 keras 模型? - How to convert a pretrained tensorflow pb frozen graph into a modifiable h5 keras model? 如何将Tensorflow Simple Audio Recognition冷冻图(.pb)转换为Core ML模型? - How to convert Tensorflow Simple Audio Recognition frozen graph(.pb) to Core ML model? 如何将 Tensorflow model 转换为 tensorflow.js Z20F35E630DAF44DBFA4C3F68F5399? - How can I convert Tensorflow model to tensorflow.js model? 从冻结模型创建可训练的Tensorflow图 - Create Trainable Tensorflow graph from frozen model 无法将 tensorflow 冻结图转换为 pbtxt 文件 - Failed to convert tensorflow frozen graph to pbtxt file 如何在tensorflow中训练后使用模型(保存/加载图) - how to use model after trained in tensorflow (save/load graph)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM