在TensorFlow中,当你恢复保存的图形和变量时,你可以通过以下步骤来获得位置:
下面是一个示例代码:
import tensorflow as tf
# 导入保存的图形的元图
saver = tf.train.import_meta_graph('path/to/your/model.meta')
with tf.Session() as sess:
# 恢复保存的变量
saver.restore(sess, 'path/to/your/model')
# 获取默认的图形
graph = tf.get_default_graph()
# 获取保存的位置
locations = tf.get_collection('your_collection_name')
# 打印位置
for location in locations:
print(location)
在上面的代码中,你需要将'path/to/your/model.meta'和'path/to/your/model'替换为你保存的图形和变量的路径。你还需要将'your_collection_name'替换为你保存位置时使用的集合名称。
这样,你就可以在TensorFlow中获得保存的位置了。请注意,这只是一个示例,具体的实现可能会根据你的需求和代码结构有所不同。
领取专属 10元无门槛券
手把手带您无忧上云