데이터 세트를 생성하여 TFRecords 파일로 변환했습니다. 이것은 내가 파일을 작성하는 데 사용되는 코드의 일부입니다 : 내가 tensorflow의 python_io 모듈을 사용할 때 기록에TFRecords 파일을 읽을 때 큐가 닫히고 비어 있음
example = tf.train.Example(features=tf.train.Features(feature={
'height': _int64_feature(rows),
'width': _int64_feature(cols),
'depth': _int64_feature(depth),
'label': _int64_feature(int(labels[index])),
'name': _bytes_feature(imagePaths[index].encode(encoding='utf-8')),
'image_raw': _bytes_feature(imageRaw.tostring())}))
데이터는, 잘 읽어 모든 데이터는 원본 이미지와 라벨 동일합니다.
OutOfRangeError (see above for traceback): RandomShuffleQueue '_0_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 10, current size 0)
다른 스레드가 결함 요소가 추가 될 때 큐가 종료되는 것을 제안, 그래서 필수 재 성형을 제외한 모든 폐기 : 지금 그래프에서 파일을 읽을 때, 나는 오류 메시지가 다음 얻을 캐스팅. 오류가 지속됩니다. 여기 내 테스트 코드입니다 :
testInput.py는
import tensorflow as tf
def inputs(dataDir):
feature = {'image_raw': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([], tf.int64)}
# Create a list of filenames and pass it to a queue
filename_queue = tf.train.string_input_producer([dataDir], num_epochs=1)
# Define a reader and read the next record
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
# Decode the record read by the reader
features = tf.parse_single_example(serialized_example, features=feature)
# Convert the image data from string back to the numbers
image = tf.decode_raw(features['image_raw'], tf.uint8)
# Cast label data into int32
label = tf.cast(features['label'], tf.int32)
# Reshape image data into the original shape
image = tf.reshape(image, [64, 64, 3])
# Any preprocessing here ...
# Creates batches by randomly shuffling tensors
images, labels = tf.train.shuffle_batch([image, label],
batch_size=10,
capacity=30,
num_threads=1,
min_after_dequeue=10)
return images, labels
test.py
import tensorflow as tf
from PIL import Image
import skimage.io as io
import testInput as data
import numpy as np
images, labels = data.inputs('./train.tfrecords')
with tf.Session() as sess:
tf.local_variables_initializer()
tf.global_variables_initializer()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
img, lab = sess.run([images, labels])
print(img[0, :, :, :].shape)
io.imshow(img[0, :, :, :])
io.show()
input('Press key...')
coord.join(threads)
sess.close()
나는 이미지의 모양이 정말 [64, 64, 3], 심지어는 것을 확인했다 그것의 1 차원 모양에서 그것을 남겨 두는 것을 시도한, 그러나 나는 아직도 과실을 얻는다. 나는 아이디어가 없으므로 도움을 청합니다. 미리 감사드립니다.