class_docstr: Writes object detection dataset into tfrecords.
  
  Reads dataset from a subclass of ObjectDetectionReader and saves it using
  the default format for tfrecords.
class_docstr_tok: ["Writes","object","detection","dataset","into","tfrecords",".","Reads","dataset","from","a","subclass","of","ObjectDetectionReader","and","saves","it","using","the","default","format","for","tfrecords","."]
docstr_tok: []
code: def save(self):
      """ """
      tf.logging.info(
          'Saving split "{}" in output_dir = {}'.format(
              self._split, self._output_dir
          )
      )
      if not tf.gfile.Exists(self._output_dir):
          tf.gfile.MakeDirs(self._output_dir)
  
      # Save classes in simple json format for later use.
      classes_file = os.path.join(self._output_dir, CLASSES_FILENAME)
      json.dump(
          [
              self._reader.pretty_name(label)
              for label in self._reader.classes
          ],
          tf.gfile.GFile(classes_file, "w"),
      )
  
      record_file = os.path.join(
          self._output_dir, "{}.tfrecords".format(self._split)
      )
      writer = tf.python_io.TFRecordWriter(record_file)
  
      tf.logging.debug("Found {} images.".format(self._reader.total))
  
      with click.progressbar(
          self._reader.iterate(), length=self._reader.total
      ) as record_list:
          for record_idx, record in enumerate(record_list):
              tf_record = self._record_to_tf(record)
              if tf_record is not None:
                  writer.write(tf_record.SerializeToString())
  
          if self._output_dir.startswith("gs://"):
              tf.logging.info(
                  "Saving tfrecord to Google Cloud Storage. "
                  "It may take a while."
              )
          writer.close()
  
      if self._reader.yielded_records == 0:
          tf.logging.error(
              "Data is missing. Removing record file. "
              '(Use "--debug" flag to display all logs)'
          )
          tf.gfile.Remove(record_file)
          return
      elif self._reader.errors > 0:
          tf.logging.warning(
              "Failed on {} records. "
              '(Use "--debug" flag to display all logs)'.format(
                  self._reader.errors, self._reader.yielded_records
              )
          )
  
      tf.logging.info(
          'Saved {} records to "{}"'.format(
              self._reader.yielded_records, record_file
          )
      )
  
file_path: luminoth/luminoth/tools/dataset/writers/object_detection_writer.py
imports: import click
  import json
  import os
  import tensorflow
  from .base_writer import BaseWriter
  from luminoth.tools.dataset.readers import ObjectDetectionReader
  from luminoth.utils.dataset import to_int64, to_string, to_bytes
label_desc: Use image node_id 2 for calling the ObjectDetectionWriter obj's underlying member method code with example usage: obj.save() without return types