Skip to content Skip to sidebar Skip to footer

How Can I Convert A Model Trained In Tensorflow 2 To A Tensorflow 1 Frozen Graph

I would like to train a model using tensorflow 2 but afterwards I need to use a converter that is only compatible with tensorflow 1. Is it possible and if so how can I convert a m

Solution 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. I did it for some other purpose before. You can save as follows:

weights = []
for layer in model.layers:

    w = layer.get_weights()
    iflen(w)>0:
      print(layer.name)
      weights.append(w)


withopen('mnist_weights.pkl', 'wb') as f:
  pickle.dump(weights, f)  

Where for each layer w[0]=weights and w[1]=biases

Post a Comment for "How Can I Convert A Model Trained In Tensorflow 2 To A Tensorflow 1 Frozen Graph"