【问题标题】:tensorflow check image is in reader张量流检查图像在阅读器中
【发布时间】:2016-01-07 11:39:12
【问题描述】:

当输出仅为:Tensor("DecodeJpeg:0", shape=TensorShape([Dimension(None), Dimension(None), Dimension(None)]), dtype=uint8)

如何显示张量对象的图像和标签?

(部分代码来自:Tensorflow read images with labels

import tensorflow as tf
from PIL import Image
import numpy as np
from os.path import join

KNOWN_HEIGHT = 812
KNOWN_WIDTH = 812

def read_my_file_format(self, filename_and_label_tensor):
    """Consumes a single filename and label as a ' '-delimited string.

    Args:
      filename_and_label_tensor: A scalar string tensor.

    Returns:
      Two tensors: the decoded image, and the string label.
    """
    filename, label = tf.decode_csv(filename_and_label_tensor, [[""], [""]], ",")
    file_contents = tf.read_file(filename)
    image = tf.image.decode_jpeg(file_contents)
    #image.set_shape([KNOWN_HEIGHT, KNOWN_WIDTH, 3])

    return image, label

string = ['test.jpg,m', 'test2.jpg,f']
filepath_queue = tf.train.string_input_producer(string)

image, label = read_my_file_format(filepath_queue.dequeue())

print(image)
# Output: Tensor("DecodeJpeg:0", shape=TensorShape([Dimension(None), Dimension(None), Dimension(None)]), dtype=uint8)

print(label)
# Output: Tensor("DecodeCSV:1", shape=TensorShape([]), dtype=string)

如何在image 中显示实际图像并同时显示label?因为图像是否确实在同一个文件夹中不会改变imagelabel的输出。

编辑

以下代码(部分来自:Tensorflow image reading & display)在我的朋友 Mac 上显示了一张图像,但在我的 Ubuntu 14.04 上却没有:

# Test show image
images = []
with tf.Session() as sess:

    # Start populating the filename queue.
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess, coord=coord)

    if len(string) > 0:
      for i in range(len(string)):
        plaatje = result.image.eval()
        images.append(plaatje)

    Image._showxv(Image.fromarray(np.asarray(plaatje)))

    coord.request_stop()
    coord.join(threads)
    print("tf.session success")

这会导致以下错误

W tensorflow/core/common_runtime/executor.cc:1076] 0x7fa3940cb950 Compute status: Cancelled: Enqueue operation was cancelled
 [[Node: input_producer/input_producer_EnqueueMany = QueueEnqueueMany[Tcomponents=[DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input_producer, input_producer/RandomShuffle)]]
I tensorflow/core/kernels/queue_base.cc:278] Skipping cancelled enqueue attempt

【问题讨论】:

  • 您能否使用包含“计算状态:...”的任何其他日志更新您的问题? “已取消”错误通常是队列运行线程中早期错误的症状。 (例如,如果找不到文件,您会看到此错误。)

标签: python image tensorflow


【解决方案1】:

您的第二个代码部分似乎省略了代码,不是吗?

尝试here 建议的解决方案。您必须在启动队列运行器之前初始化占位符。这为我解决了类似的问题。

我猜你已经知道你必须在你的张量上调用.eval() 才能得到它的实际值。看看这个question I made

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 2018-01-10
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多