# Path: datasets/DetectionDataset.py
# class DetectionFileListDataset(FileListDataset):
#   def __init__(self, config, dataset_name, subset, default_path, num_classes):
#     super().__init__(config, dataset_name, subset, default_path, num_classes)
#     self.add_masks = config.bool("add_masks", True)
#     self.prefer_gt_to_ignore = config.bool("prefer_gt_to_ignore", False)
#     self.use_ioa_for_ignore = config.bool("use_ioa_for_ignore",  False)
#     self.use_masks_for_ignore = config.bool("use_masks_for_ignore",  False)
#     init_anchors(config)
# 
#   def assemble_example(self, tensors):
#     tensors = super().assemble_example(tensors)
#     if DataKeys.BBOXES_y0x0y1x1 in tensors:
#       tensors = add_rpn_data(tensors, self.prefer_gt_to_ignore, use_masks_for_ignore=self.use_masks_for_ignore,
#                              use_ioa_for_ignore=self.use_ioa_for_ignore)
#     return tensors
# 
# Path: datasets/DataKeys.py
# SEGMENTATION_LABELS = "segmentation_labels"
# SEGMENTATION_LABELS_ORIGINAL_SIZE = "segmentation_labels_original_size"
# BBOX_GUIDANCE = "bbox_guidance"
# UNSIGNED_DISTANCE_TRANSFORM_GUIDANCE = "unsigned_distance_transform_guidance"
# SIGNED_DISTANCE_TRANSFORM_GUIDANCE = "signed_distance_transform_guidance"
# LASER_GUIDANCE = "laser_guidance"
# IMAGES = "images"
# RAW_IMAGES = "raw_images"
# INPUTS = "inputs"
# IMAGE_FILENAMES = "image_filenames"
# CLASSES = "classes"
# IDS = "ids"  # bounding box number 1,2,3...  or 0 if no bounding box
# DT_METHOD = "dt_method"
# RAW_SEGMENTATION_LABELS = "raw_segmentation_labels"
# CLICK_MAPS = "clicks_maps"
# NEG_CLICKS = "neg_clicks"
# POS_CLICKS = "pos_clicks"
# OBJ_TAGS = "obj_tags"
# FEATUREMAP_LABELS = "featuremap_labels"
# FEATUREMAP_BOXES = "featuremap_boxes"
# IMAGE_ID = "image_id"
# IS_CROWD = "is_crowd"
# SEGMENTATION_MASK = "segmentation_mask"
# SKIP_EXAMPLE = "skip_example"  # If true, filter the corresponding example from the datastream. Useful, when an example
# RAW_IMAGE_SIZES = "raw_image_sizes"  # h, w
# TIME_OFFSETS = "time_offsets"
# SPACE_OFFSETS = "space_offsets"
# SEGMENTATION_INSTANCE_LABELS = "segmentation_instance_labels"
# N_VALID_IDS = "n_valid_ids"


import glob
import os
import tensorflow as tf
import numpy as np
from datasets.DetectionDataset import DetectionFileListDataset
from datasets import DataKeys
    self.visibility_threshold = config.float("visibility_threshold", 0.5)  # Boxes with visibility < this are ignored

    parent_folder = os.path.join(self.data_dir, "train")
    for seq in self.seq_ids:
      gt_filename = os.path.join(parent_folder, seq, "gt", "gt.txt")
      self.gt_data[seq].append(np.genfromtxt(gt_filename, delimiter=gt_delimiter))

    self.classes_to_cat = [0, 1, 3]
    self.cat_to_class = {v: i for i, v in enumerate(self.classes_to_cat)}

  def read_inputfile_lists(self):
    parent_folder = os.path.join(self.data_dir, "train")
    imgs = []
    for seq in self.seq_ids:
      imgs += sorted(glob.glob(os.path.join(parent_folder, seq, "img1", "/*.jpg")))
    return (imgs, )

  def load_annotation(self, img, img_filename, annotation_filename):
    img_shape = tf.shape(img)
    bboxes, ids, classes, is_crowd = tf.py_func(self.get_data_arrays_for_file,
                                                      [img_filename, img_shape[0], img_shape[1]],
                                                      [tf.float32, tf.int32, tf.int32, tf.int32],
                                                      name="get_data_arrays_for_file")
    bboxes.set_shape((N_MAX_DETECTIONS, 4))
    ids.set_shape((N_MAX_DETECTIONS,))
    classes.set_shape((N_MAX_DETECTIONS,))
    is_crowd.set_shape((N_MAX_DETECTIONS,))

    return_dict = {}
    return_dict[DataKeys.BBOXES_y0x0y1x1] = bboxes

# Path: datasets/DetectionDataset.py
# class DetectionFileListDataset(FileListDataset):
#   def __init__(self, config, dataset_name, subset, default_path, num_classes):
#     super().__init__(config, dataset_name, subset, default_path, num_classes)
#     self.add_masks = config.bool("add_masks", True)
#     self.prefer_gt_to_ignore = config.bool("prefer_gt_to_ignore", False)
#     self.use_ioa_for_ignore = config.bool("use_ioa_for_ignore",  False)
#     self.use_masks_for_ignore = config.bool("use_masks_for_ignore",  False)
#     init_anchors(config)
# 
#   def assemble_example(self, tensors):
#     tensors = super().assemble_example(tensors)
#     if DataKeys.BBOXES_y0x0y1x1 in tensors:
#       tensors = add_rpn_data(tensors, self.prefer_gt_to_ignore, use_masks_for_ignore=self.use_masks_for_ignore,
#                              use_ioa_for_ignore=self.use_ioa_for_ignore)
#     return tensors
# 
# Path: datasets/DataKeys.py
# SEGMENTATION_LABELS = "segmentation_labels"
# SEGMENTATION_LABELS_ORIGINAL_SIZE = "segmentation_labels_original_size"
# BBOX_GUIDANCE = "bbox_guidance"
# UNSIGNED_DISTANCE_TRANSFORM_GUIDANCE = "unsigned_distance_transform_guidance"
# SIGNED_DISTANCE_TRANSFORM_GUIDANCE = "signed_distance_transform_guidance"
# LASER_GUIDANCE = "laser_guidance"
# IMAGES = "images"
# RAW_IMAGES = "raw_images"
# INPUTS = "inputs"
# IMAGE_FILENAMES = "image_filenames"
# CLASSES = "classes"
# IDS = "ids"  # bounding box number 1,2,3...  or 0 if no bounding box
# DT_METHOD = "dt_method"
# RAW_SEGMENTATION_LABELS = "raw_segmentation_labels"
# CLICK_MAPS = "clicks_maps"
# NEG_CLICKS = "neg_clicks"
# POS_CLICKS = "pos_clicks"
# OBJ_TAGS = "obj_tags"
# FEATUREMAP_LABELS = "featuremap_labels"
# FEATUREMAP_BOXES = "featuremap_boxes"
# IMAGE_ID = "image_id"
# IS_CROWD = "is_crowd"
# SEGMENTATION_MASK = "segmentation_mask"
# SKIP_EXAMPLE = "skip_example"  # If true, filter the corresponding example from the datastream. Useful, when an example
# RAW_IMAGE_SIZES = "raw_image_sizes"  # h, w
# TIME_OFFSETS = "time_offsets"
# SPACE_OFFSETS = "space_offsets"
# SEGMENTATION_INSTANCE_LABELS = "segmentation_instance_labels"
# N_VALID_IDS = "n_valid_ids"


# Path: datasets/MOT/MOT_common.py
import glob
import os
import tensorflow as tf
import numpy as np
from datasets.DetectionDataset import DetectionFileListDataset
from datasets import DataKeys

    self.visibility_threshold = config.float("visibility_threshold", 0.5)  # Boxes with visibility < this are ignored

    parent_folder = os.path.join(self.data_dir, "train")
    for seq in self.seq_ids:
      gt_filename = os.path.join(parent_folder, seq, "gt", "gt.txt")
      self.gt_data[seq].append(np.genfromtxt(gt_filename, delimiter=gt_delimiter))

    self.classes_to_cat = [0, 1, 3]
    self.cat_to_class = {v: i for i, v in enumerate(self.classes_to_cat)}

  def read_inputfile_lists(self):
    parent_folder = os.path.join(self.data_dir, "train")
    imgs = []
    for seq in self.seq_ids:
      imgs += sorted(glob.glob(os.path.join(parent_folder, seq, "img1", "/*.jpg")))
    return (imgs, )

  def load_annotation(self, img, img_filename, annotation_filename):
    img_shape = tf.shape(img)
    bboxes, ids, classes, is_crowd = tf.py_func(self.get_data_arrays_for_file,
                                                      [img_filename, img_shape[0], img_shape[1]],
                                                      [tf.float32, tf.int32, tf.int32, tf.int32],
                                                      name="get_data_arrays_for_file")
    bboxes.set_shape((N_MAX_DETECTIONS, 4))
    ids.set_shape((N_MAX_DETECTIONS,))
    classes.set_shape((N_MAX_DETECTIONS,))
    is_crowd.set_shape((N_MAX_DETECTIONS,))

    return_dict = {}
    return_dict[DataKeys.BBOXES_y0x0y1x1] = bboxes

    return_dict[DataKeys.CLASSES] = classes