Verwenden Sie tf.TextLineReader
, das in Verbindung mit tf.train.string_input_producer
ermöglicht es Ihnen, Daten aus mehreren Dateien auf der Festplatte zu laden (wenn Ihr Dataset groß genug ist, dass es in mehrere Dateien verteilt werden muss).
Siehe https://www.tensorflow.org/programmers_guide/reading_data#reading_from_files
-Code-Schnipsel aus dem obigen Link:
filename_queue = tf.train.string_input_producer(["file0.csv", "file1.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
record_defaults = [[1], [1], [1], [1], [1]]
col1, col2, col3, col4, col5 = tf.decode_csv(
value, record_defaults=record_defaults)
features = tf.stack([col1, col2, col3, col4])
with tf.Session() as sess:
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for filename_queue = tf.train.string_input_producer(["file0.csv", "file1.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
record_defaults = [[1], [1], [1], [1], [1]]
col1, col2, col3, col4, col5 = tf.decode_csv(
value, record_defaults=record_defaults)
features = tf.stack([col1, col2, col3, col4])
with tf.Session() as sess:
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(1200):
# Retrieve a single instance:
example, label = sess.run([features, col5])
coord.request_stop()
coord.join(threads)i in range(1200):
# Retrieve a single instance:
example, label = sess.run([features, col5])
coord.request_stop()
coord.join(threads)
Vielen Dank für Ihre anwser. Aber was ist, wenn es ** viele Spalten ** in der CSV-Datei gibt? Ich muss viele col1, col2, col3 schreiben ... und so weiter? Und wie liest man Daten aus Binärdateien? – secsilm
@secsilm ja, Sie brauchen 'col1',' col2' usw. für jede Spalte in Ihrer CSV. Denken Sie daran, 'col1' ist nur ein variabler Name, so dass Sie einen mnemonischen Namen wie' price' oder etwas geben könnten. Für Binärdateien siehe https://www.tensorflow.org/api_docs/python/tf/FixedLengthRecordReader – Insectatorious