class_docstr: Object detection reader for data tagged using Taggerine:
  https://github.com/tryolabs/taggerine/
class_docstr_tok: ["Object","detection","reader","for","data","tagged","using","Taggerine",":","https",":","\/\/github.com\/tryolabs\/taggerine\/"]
docstr: Finds and parses Taggerine's JSON files.
docstr_tok: ["Finds","and","parses","Taggerine","'s","JSON","files","."]
code: def _read_annotations(self, directory):
      """
      Finds and parses Taggerine's JSON files.
      """
      try:
          all_files = tf.gfile.ListDirectory(self._split_path)
      except tf.errors.NotFoundError:
          raise InvalidDataDirectory(
              'Directory for split "{}" does not exist'.format(
                  self._split
              )
          )
  
      annotation_file_candidates = []
      for filename in all_files:
          if filename.lower().endswith(".json"):
              annotation_file_candidates.append(filename)
  
      if len(annotation_file_candidates) == 0:
          raise InvalidDataDirectory(
              "Could not find any annotations in {}.".format(
                  self._split_path
              )
              + "Check that there is a .json file with Taggerine's "
              + "annotations."
          )
  
      self.annotations = []
      # Open, validate and extract label information.
      for filename in annotation_file_candidates:
          annotation_path = os.path.join(self._split_path, filename)
          with tf.gfile.Open(annotation_path) as annotation_file:
              annotations = json.load(annotation_file)
  
          if not isinstance(annotations, dict):
              # JSON file with invalid format.
              continue
  
          file_annotations = []
  
          invalid_label = False
          for image_filename, labels in annotations.items():
              if not isinstance(labels, collections.Iterable):
                  # Ignore labels that are not lists. Ignore file.
                  invalid_label = True
                  break
  
              # Validate labels
              for label in labels:
                  for valid_keyset in VALID_KEYS:
                      if all(key in label for key in valid_keyset):
                          break
                  else:
                      # There is not valid_keyset that can parse the label.
                      # Ignore all labels from this file.
                      invalid_label = True
                      break
  
              # Early stop for labels inside file when there is an invalid
              # label.
              if invalid_label:
                  break
  
              # Save annotations.
              file_annotations.append(
                  {
                      "image_id": os.path.basename(image_filename),
                      "filename": image_filename,
                      "path": os.path.join(
                          self._split_path, image_filename
                      ),
                      "gt_boxes": labels,
                  }
              )
  
          if invalid_label:
              # Ignore file that have invalid labels.
              continue
  
          # If we have a valid file with data in it then we use it.
          self.annotations.extend(file_annotations)
  
file_path: luminoth/luminoth/tools/dataset/readers/object_detection/taggerine.py
imports: import collections
  import json
  import os
  import six
  import tensorflow
  from PIL import Image
  from luminoth.tools.dataset.readers import InvalidDataDirectory
  from luminoth.tools.dataset.readers.object_detection import ObjectDetectionReader
  from luminoth.utils.dataset import read_image
label_desc: Use image node_id 4 for calling the TaggerineReader obj's underlying member method code with example usage: obj._read_annotations(directory) without return types