Python Tensorflow:在图像管道中定义占位符/操作名称
我想保存我训练过的Tensorflow模型,这样就可以通过恢复模型文件来部署它(我下面的例子似乎很有意义)。然而,要做到这一点,我需要命名张量,这样我就可以用如下方式重新加载变量:Python Tensorflow:在图像管道中定义占位符/操作名称,python,tensorflow,Python,Tensorflow,我想保存我训练过的Tensorflow模型,这样就可以通过恢复模型文件来部署它(我下面的例子似乎很有意义)。然而,要做到这一点,我需要命名张量,这样我就可以用如下方式重新加载变量: graph = tf.get_default_graph() w1 = graph.get_tensor_by_name("my_tensor:0") 我正在使用string\u input\u producer(下面的代码)对文件名列表中的图像进行排队,但是如何命名张量,以便在稍后阶段重新加载它们 import
graph = tf.get_default_graph()
w1 = graph.get_tensor_by_name("my_tensor:0")
我正在使用string\u input\u producer(下面的代码)对文件名列表中的图像进行排队,但是如何命名张量,以便在稍后阶段重新加载它们
import tensorflow as tf
flags = tf.app.flags
conf = flags.FLAGS
class ImageDataSet(object):
def __init__(self, img_list_path, num_epoch, batch_size):
# Build the record list queue
input_file = open(images_list_path, 'r')
self.record_list = []
for line in input_file:
line = line.strip()
self.record_list.append(line)
filename_queue = tf.train.string_input_producer(self.record_list, num_epochs=num_epoch)
image_reader = tf.WholeFileReader()
_, image_file = image_reader.read(filename_queue)
image = tf.image.decode_jpeg(image_file, conf.img_colour_channels)
# preprocess
# ...
min_after_dequeue = 1000
capacity = min_after_dequeue + 400 * batch_size
self.images = tf.train.shuffle_batch(image, batch_size=batch_size, capacity=capacity,
min_after_dequeue=min_after_dequeue)
我假设您希望恢复图形以进行测试或部署 出于这些目的,您可以通过插入占位符作为测试数据的入口来编辑图形
要编辑图形,您可以使用tf,或者使用占位符构建一个新图形并保存它。是-我的目的是恢复图形以供部署。看起来我应该为image变量创建一个占位符,然后使用tf.assign将数据放入其中。下面是一个简单的示例,并对其进行测试。