我需要在Tensorflow中的会话运行期间传递图像
我试过了
myimage="andrew/semaphore.jpg"
mydict={'ssignals':myimage}
output = sess.run(train_prediction, feed_dict=mydict)
但不起作用
返回错误:
Cannot interpret feed_dict key as Tensor
train_prediction
张量有shape=(3, 120), 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
修改
我没有使用相同的符号键值,请在标记之前重复注意。