Python 如何在Tensorflow会话运行中使用feed_dict传递图像
我需要在Tensorflow中运行会话期间传递一个映像 我试过了Python 如何在Tensorflow会话运行中使用feed_dict传递图像,python,tensorflow,computer-vision,Python,Tensorflow,Computer Vision,我需要在Tensorflow中运行会话期间传递一个映像 我试过了 myimage="andrew/semaphore.jpg" mydict={'ssignals':myimage} output = sess.run(train_prediction, feed_dict=mydict) 但是不起作用 返回错误: Cannot interpret feed_dict key as Tensor train\u预测tensor具有shape=(3120),dtype=float32 (12
myimage="andrew/semaphore.jpg"
mydict={'ssignals':myimage}
output = sess.run(train_prediction, feed_dict=mydict)
但是不起作用
返回错误:
Cannot interpret feed_dict key as Tensor
train\u预测
tensor具有shape=(3120),dtype=float32
(120是图像分组的培训班数量)
程序使用此方法加载和标记输入图像
def write_records_file(dataset, record_location):
writer = None
global counter
global start_time
current_index = 0
for breed, images_filenames in dataset.items():
for image_filename in images_filenames:
with tf.Graph().as_default():
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
if current_index % 100 == 0:
if writer:
writer.close()
record_filename = "{record_location}-{current_index}.tfrecords".format(
record_location=record_location,
current_index=current_index)
writer = tf.python_io.TFRecordWriter(record_filename)
current_index += 1
image_file = tf.read_file(image_filename)
image = tf.image.decode_jpeg(image_file)
grayscale_image = tf.image.rgb_to_grayscale(image)
resized_image = tf.image.resize_images(
grayscale_image, [250, 251])
try:
image_bytes = sess.run(
tf.cast(resized_image, tf.uint8)).tobytes()
except:
continue
image_label = breed.encode("utf-8")
example = tf.train.Example(features=tf.train.Features(feature={
'label': tf.train.Feature(bytes_list=tf.train.BytesList(value=[image_label])),
'image': tf.train.Feature(bytes_list=tf.train.BytesList(value=[image_bytes]))
}))
writer.write(example.SerializeToString())
counter += 1
而不是批量加载记录并将其输入CNN
编辑
我不使用相同的符号键值,请在标记为重复之前注意。可能重复@running。这不是一个完全不同的问题,我不使用相同的符号键值字符串
'ssignals'
来自哪里?通常,feed\u dict
中的键是tf.Tensor
对象(例如tf.placeholder()
)。@mrry它是一个简单的字符串。因此,我不能使用字符串作为提要dict的标签。在这种情况下,我应该将什么作为具有单个picturemyimage
值的字典键?如果字符串是特定tf.Tensor
的名称,则只能将其用作提要dict键,但通常更容易使用tf.Tensor
对象本身作为键。要通过的正确tf.Tensor
将取决于程序的其余部分:您可以共享更多代码吗?