tenorflow.parse_single_sequence_example закрытие после одной эпохи - PullRequest
0 голосов
/ 01 ноября 2018

Я использую reader = TFRecordReader() с num_epochs > 1 в методе _filename_queue для чтения моего сериализованного файла tfrecord и синтаксического анализа с tf.parse_single_sequence_example, но мой пакет заканчивается только после одной эпохи. Код, похоже, не выдает никакой ошибки, так как он хорошо заканчивает мою первую партию. У меня есть class TFRecord со следующим _read методом для чтения

    def _read(self, tf_record_path, num_epochs=None, tf_record_compression=None):
    """
    :param tf_record_path: tf_record path
    :param num_epochs: number of epochs
    :param tf_record_compression: compression type or bool
    :return:
    """

    assert tf_record_compression in \
           (True, False, None, 'GZIP', 'ZLIB', self.tf.python_io.TFRecordCompressionType.GZIP,
            self.tf.python_io.TFRecordCompressionType.ZLIB, self.tf.python_io.TFRecordCompressionType.NONE)
    if tf_record_compression in (False, None, self.tf.python_io.TFRecordCompressionType.NONE):
        options = None

    elif tf_record_compression in (True, 'GZIP', self.tf.python_io.TFRecordCompressionType.GZIP):
        options = self.tf.python_io.TFRecordOptions(self.tf.python_io.TFRecordCompressionType.GZIP)

    else:
        assert tf_record_compression in ('ZLIB', self.tf.python_io.TFRecordCompressionType.ZLIB)
        options = self.tf.python_io.TFRecordOptions(self.tf.python_io.TFRecordCompressionType.ZLIB)
    with self.tf.variable_scope('Read'):
        reader = tf.TFRecordReader(options=options)

        filename_queue = self._filename_queue(tf_path=tf_record_path, num_epochs=num_epochs)
        _, serialized_output = reader.read(filename_queue)
        print("TFRecord Data Serialized!")
    return serialized_output

    def _filename_queue(self, tf_path, num_epochs=None):
    """
    :param tf_path:
    :param num_epochs:
    :return:
    """
    if self._tf_path is None:
        if isinstance(tf_path, str):
            self._tf_path = [tf_path]
        else:
            self._tf_path = tf_path

    if num_epochs is None:
        num_epochs = 1
    else:
        num_epochs = num_epochs
    print('file_name path : ', self._tf_path)
    print('The Number of Epochs is : ', num_epochs)
    file_name_queue = self.tf.train.string_input_producer(
        self._tf_path, num_epochs=num_epochs, name='FileNameQueue')
    # self.tf.add_to_collection()
    print(type(file_name_queue).__name__)
    return file_name_queue

Я до сих пор не могу понять, почему моя партия заканчивается сразу после 1 эпохи!

...