Ich habe eine CSV-Datei ("test03.txt") in eine TFRecords-formatierte Datei ("test03.tfrecords") konvertiert, aber wenn ich dann in der TFRecords-Datei einlese und versuche, tf zu verwenden .train.shuffle_batch erhalte ich die FehlermeldungRandomShuffleQueue ist beim Lesen von TFRecords
RandomShuffleQueue '_2_shuffle_batch_1/random_shuffle_queue' is closed and has insufficient elements (requested 10, current size 0)
Die CSV-Datei ist
1,0
2,0
3,0
4,0
5,1
6,0
7,1
8,1
9,1
10,1
, die ich in eine TFRecords Datei konvertieren mit
import pandas
import tensorflow as tf
csv = pandas.read_csv(r"test03.txt", header=None).values
with tf.python_io.TFRecordWriter("test03.tfrecords") as writer:
for row in csv:
features, label = row[:-1], row[-1]
example = tf.train.Example()
example.features.feature["features"].float_list.value.extend(features)
example.features.feature["label"].int64_list.value.append(label)
writer.write(example.SerializeToString())
Aber ich erhalte die Meldung über Fehler, wenn ich den folgenden Code ausführen:
import tensorflow as tf
batch_size = 10
with tf.Session() as sess:
filename_queue = tf.train.string_input_producer(["test03.tfrecords"],num_epochs=1)
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
feature_dict = {'features': tf.FixedLenFeature([], tf.int64),'label': tf.FixedLenFeature([], tf.int64)}
featuresLabel = tf.parse_single_example(serialized_example, features=feature_dict)
xdata = tf.cast(featuresLabel['features'], tf.int32)
label = tf.cast(featuresLabel['label'], tf.int32)
min_after_dequeue = 1
capacity = min_after_dequeue + 3 * batch_size
batch_of_xs, batch_of_labels = tf.train.shuffle_batch([xdata, label], batch_size=batch_size, capacity=capacity, num_threads=1, min_after_dequeue=min_after_dequeue)
init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
sess.run(init_op)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
single_batch_xs, single_batch_ys = sess.run([batch_of_xs, batch_of_labels])