1
我試圖讓一批64個圖像中的每個已[64,224,224,3]的尺寸和標籤有[64]。有8126 _img_class和_img_names。但是,我收到了意想不到的輸出。基本上,我沒有得到任何東西,當我運行它時腳本永不終止。出了毛病,輸入管道中tensorflow
def _get_images(shuffle=True):
"""Gets the images and labels as a batch"""
#get image and label list
_img_names,_img_class = _get_list()
filename_queue = tf.train.string_input_producer(_img_names)
#reader
image_reader = tf.WholeFileReader()
_, image_file = image_reader.read(filename_queue)
#decode jpeg
image_original = tf.image.decode_jpeg(image_file)
label_original = tf.convert_to_tensor(_img_class,dtype=tf.int32)
#image preprocessing
image = tf.image.resize_images(image_original, [224,224])
float_image = tf.cast(image,dtype=tf.float32)
float_image = tf.image.per_image_standardization(image)
#set the shape
float_image.set_shape((224, 224, 3))
label_original.set_shape([8126])
#parameters for shuffle
batch_size = 64
num_preprocess_threads = 16
num_examples_per_epoch = 8000
min_fraction_of_examples_in_queue = 0.4
min_queue_examples = int(num_examples_per_epoch *
min_fraction_of_examples_in_queue)
if shuffle:
images_batch, label_batch = tf.train.shuffle_batch(
[float_image,label_original],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 3 *
batch_size,
min_after_dequeue=min_queue_examples)
else:
images_batch, label_batch = tf.train.batch(
[float_image,label_original],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 3 * batch_size)
return images_batch,label_batch
with tf.Session() as sess:
tf.global_variables_initializer().run()
# Coordinate the loading of image files.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
images,labels = _get_images(shuffle=True)
# Get an image tensor and print its value.
image_tensor,labels = sess.run([images,labels])
# Finish off the filename queue coordinator.
coord.request_stop()
coord.join(threads)
當我設置enqueue_many =真我收到以下錯誤。
TypeError: 'Tensor' object is not iterable.
感謝。我得到了輸出,但我的標籤是在維度(64,8126),他們沒有得到洗牌。這很奇怪,因爲我已經將它的形狀設置爲[8126]。如果你能夠點亮它,我將不勝感激。感謝 –
這個問題是由於這一行'label_original.set_shape([8126])'。由於標籤在這裏是一個int,所以可以將形狀設置爲'label_original.set_shape([1])'使其成爲一維張量。或者你可能沒有設定形狀。 –
我嘗試了兩種方式,但都失敗了。它會得到不匹配的尺寸錯誤。我有點理解錯誤。對於每個圖像,它將8126個元素視爲一個標籤。 –