Hamza Shaikh
Hamza Shaikh

Reputation: 75

How to load Tensorflow 1.x saved model in TensorFlow 2.x?

I have run code of TensorFlow 1.x.It works fine.Now I have generated checkpoint of that code.They also work fine.Now I want to run these check point in my TensorFlow 2.x file

OSError Traceback (most recent call last) in () 1 ----> 2 loaded = tf.saved_model.load("/content/model/") 3 4 5

1 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/loader_impl.py in parse_saved_model(export_dir) 81 (export_dir, 82 constants.SAVED_MODEL_FILENAME_PBTXT, ---> 83 constants.SAVED_MODEL_FILENAME_PB)) 84 85

OSError: SavedModel file does not exist at: /content/model//{saved_model.pbtxt|saved_model.pb}

This is error Code loaded = tf.saved_model.load("/content/model/")

Share your view how can we solve this error

This is my file hierarchy,how I uploaded files on colab."model" folder is containing ckpt files of machine learning model in tensorflow 1

Upvotes: 3

Views: 4589

Answers (3)

user1410665
user1410665

Reputation: 759

I am late to respond to this question. But I think my answer may help others who are looking for running TensorFlow Version-1 scripts on TensorFlow Version-2. Use the below commands instead of import tensorflow as tf

New Commands:

import tensorflow.compat.v1 as tf
tf.compat.v1.disable_v2_behavior()

Upvotes: 1

Xavier Eisberg
Xavier Eisberg

Reputation: 15

I am not sure if it would work in this case but sometimes adding tf.compat.v1.[desired command] can make it work while using tensorflow 2.

E.g. tf.compat.v1.saved_model.load

In your case it may be worth trying:

loaded=tf.compat.v1.saved_model.load("/content/model/")

Upvotes: 1

user13435442
user13435442

Reputation: 34

I don't think this can be done. Tensorflow 2 is largely backwards incompatible with Tensorflow 1.

Upvotes: 1

Related Questions