I'm not sure whether TensorFlow actually has actually decoded an image when the output is only: Tensor("DecodeJpeg:0", shape=TensorShape([Dimension(None), Dimension(None), Dimension(None)]), dtype=uint8)
How can I show the image and label from the Tensor object?
(code partly from: 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)
What can I do to show the actual image in image and also show the label? Because whether the image is indeed in the same folder or not doesn't change the output from image and label.
Edit
The following code (partly from: Tensorflow image reading & display) shows an image on my friends Mac, but not on my 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")
and this results in the following error:
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