从here加载包含元文件和检查点的预训练模型(MobileNet SSD v2)总是会产生错误-指定设备无济于事。
import tensorflow as tf
from tensorflow.python.client import device_lib
import os
tf.compat.v1.disable_eager_execution()
devices = device_lib.list_local_devices()
device_list = [x.name for x in devices]
print("DEVICE LIST:", device_list)
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
meta_file = "./model/model.ckpt.meta"
with tf.device('CPU:0'):
config = tf.compat.v1.ConfigProto(
allow_soft_placement = True,
log_device_placement = True,
device_count = {'CPU': 1})
sess = tf.compat.v1.Session(config = config)
saver = tf.compat.v1.train.import_meta_graph(meta_file, clear_devices=False)
saver.save(sess=sess, save_path='./model/out/')
# Similar error with this
#checkpoint_file = "./model/model.ckpt.data-00000-of-00001"
#saver.restore(sess, checkpoint_file)
我总是得到一个错误:
DEVICE LIST: ['/device:CPU:0', '/device:XLA_CPU:0']
<error>
...
2019-12-12 08:40:22.635690: I tensorflow/core/common_runtime/direct_session.cc:359] Device mapping:
/job:localhost/replica:0/task:0/device:XLA_CPU:0 -> device: XLA_CPU device
InvalidArgumentError: Cannot assign a device for operation global_step: node global_step
(defined at /Users/j2/.virtualenvs/tsv2/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py:1751)
was explicitly assigned to /job:ps/task:0/device:CPU:0 but available devices are
[ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0 ].
Make sure the device specification refers to a valid device.
[[global_step]]
即使这样明确也是行不通的:
with tf.device('/job:localhost/replica:0/task:0/device:CPU:0'):
这是在具有Mojave(10.14.5)的Macbook Pro上运行的Tensorflow 2.0和Python 3.7。有什么想法可以解决这个问题或不兼容之处是什么?