今天在运行别人的tensorflow代码的时候,出现了下面的错误:

This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
Traceback (most recent call last):
File "main.py", line 56, in <module>
imported = tf.saved_model.load(cartoon_path)
File "/home/touyan/anaconda3/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
return func(*args, **kwargs)
TypeError: load() missing 2 required positional arguments: 'tags' and 'export_dir'

查看tf2.0的官网发现写法没啥错:

imported = tf.saved_model.load(path)
f = imported.signatures["serving_default"]
print(f(x=tf.constant([[1.]])))

​https://www.tensorflow.org/api_docs/python/tf/saved_model/load​

解决方法

pip uninstall tensorflow-gpu
pip uninstall tensorflow
pip install tensorflow==2.0

升级到2.0就没事了哈