# Path: datasets/KITTI/segtrack/KITTI_segtrack.py
# class KittiSegtrackDataset(KittiSegtrackDetectionDataset):
#   def __init__(self, config, subset, name=NAME, default_path=DEFAULT_PATH):
#     # batch size here is the number of time steps considered in a chunk
#     # TODO: what do we do at test time?
#     self._batch_size = config.int("batch_size")
#     assert self._batch_size > 1, "use KittiSegtrackDetectionDataset for single image training"
#     super().__init__(config, subset, name, default_path)
# 
#   def read_inputfile_lists(self):
#     seq_ids = self.seq_ids_train if self.subset == "train" else self.seq_ids_val
#     anns = []
#     for seq_id in seq_ids:
#       anns_vid = sorted(glob.glob(self.data_dir + "/instances/" + seq_id + "/*.png"))
#       starting_points = anns_vid[:-(self._batch_size - 1)]
#       anns += starting_points
# 
#     imgs = [x.replace("/instances/", "/images/") for x in anns]
#     return imgs, anns
# 
#   def _batch(self, tfdata, batch_size):
#     return tfdata
# 
#   def load_example(self, input_filenames):
#     examples = []
#     for delta_t in range(self._batch_size):
#       input_filenames_t = [successor_frame_filename(fn, delta_t) for fn in input_filenames]
#       raw_example = self.load_raw_example(*input_filenames_t)
#       examples.append(raw_example)
# 
#     # cf process_raw_example
#     # here we need to do it jointly to synchronize the augmentation (e.g. flipping)
#     examples = [self.postproc_example_initial(example) for example in examples]
#     examples = self.jointly_augment_examples_before_resize(examples)
#     examples = [self.postproc_example_before_resize(example) for example in examples]
#     examples = [self.resize_example(example) for example in examples]
#     examples = self.jointly_augment_examples_after_resize(examples)
#     examples = [self.postproc_example_before_assembly(example) for example in examples]
#     examples = [self.assemble_example(example) for example in examples]
# 
#     # stack everything together
#     examples_stacked = {}
#     for key in examples[0].keys():
#       if key == DataKeys.SKIP_EXAMPLE:
#         stacked = tf.reduce_any([example[key] for example in examples])
#       else:
#         stacked = tf.stack([example[key] for example in examples], axis=0)
#       examples_stacked[key] = stacked
#     return examples_stacked
# 
#   def n_examples_per_epoch(self):
#     n_examples = super().n_examples_per_epoch()
#     if n_examples == len(self.inputfile_lists[0]):
#       return n_examples * self._batch_size
# 
# Path: datasets/Loader.py
# def register_dataset(name, **args):
#   name = name.lower()
# 
#   def _register(dataset):
#     _registered_datasets[name] = (dataset, args)
#     return dataset
#   return _register


import glob
from datasets.KITTI.segtrack.KITTI_segtrack import KittiSegtrackDataset
from datasets.Loader import register_dataset


NAME = "MOTS_challenge"
DEFAULT_PATH = "/globalwork/voigtlaender/data/MOTS_challenge/train/"
SEQ_IDS_TRAIN = ["%04d" % idx for idx in [2, 5, 9, 11]]
SEQ_IDS_VAL = ["%04d" % idx for idx in [2, 5, 9, 11]]
TIMESTEPS_PER_SEQ = {"0002": 600, "0005": 837, "0009": 525, "0011": 900}


@register_dataset(NAME)
class MotsChallengeDataset(KittiSegtrackDataset):
  def __init__(self, config, subset):
    #TODO: num classes, class_ids_with instances
    super().__init__(config, subset, name=NAME, default_path=DEFAULT_PATH)
    self.seq_ids_train = SEQ_IDS_TRAIN
    self.seq_ids_val = SEQ_IDS_VAL
    t = config.string_list("seq_ids_train", [])
    if t:
      self.seq_ids_train = t
    v = config.string_list("seq_ids_val", [])
    if v:
      self.seq_ids_val = v


  def read_inputfile_lists(self):
    #seq_ids = SEQ_IDS_TRAIN if self.subset == "train" else SEQ_IDS_VAL
    seq_ids = self.seq_ids_train if self.subset == "train" else self.seq_ids_val
    anns = []
    for seq_id in seq_ids:

# Path: datasets/KITTI/segtrack/KITTI_segtrack.py
# class KittiSegtrackDataset(KittiSegtrackDetectionDataset):
#   def __init__(self, config, subset, name=NAME, default_path=DEFAULT_PATH):
#     # batch size here is the number of time steps considered in a chunk
#     # TODO: what do we do at test time?
#     self._batch_size = config.int("batch_size")
#     assert self._batch_size > 1, "use KittiSegtrackDetectionDataset for single image training"
#     super().__init__(config, subset, name, default_path)
# 
#   def read_inputfile_lists(self):
#     seq_ids = self.seq_ids_train if self.subset == "train" else self.seq_ids_val
#     anns = []
#     for seq_id in seq_ids:
#       anns_vid = sorted(glob.glob(self.data_dir + "/instances/" + seq_id + "/*.png"))
#       starting_points = anns_vid[:-(self._batch_size - 1)]
#       anns += starting_points
# 
#     imgs = [x.replace("/instances/", "/images/") for x in anns]
#     return imgs, anns
# 
#   def _batch(self, tfdata, batch_size):
#     return tfdata
# 
#   def load_example(self, input_filenames):
#     examples = []
#     for delta_t in range(self._batch_size):
#       input_filenames_t = [successor_frame_filename(fn, delta_t) for fn in input_filenames]
#       raw_example = self.load_raw_example(*input_filenames_t)
#       examples.append(raw_example)
# 
#     # cf process_raw_example
#     # here we need to do it jointly to synchronize the augmentation (e.g. flipping)
#     examples = [self.postproc_example_initial(example) for example in examples]
#     examples = self.jointly_augment_examples_before_resize(examples)
#     examples = [self.postproc_example_before_resize(example) for example in examples]
#     examples = [self.resize_example(example) for example in examples]
#     examples = self.jointly_augment_examples_after_resize(examples)
#     examples = [self.postproc_example_before_assembly(example) for example in examples]
#     examples = [self.assemble_example(example) for example in examples]
# 
#     # stack everything together
#     examples_stacked = {}
#     for key in examples[0].keys():
#       if key == DataKeys.SKIP_EXAMPLE:
#         stacked = tf.reduce_any([example[key] for example in examples])
#       else:
#         stacked = tf.stack([example[key] for example in examples], axis=0)
#       examples_stacked[key] = stacked
#     return examples_stacked
# 
#   def n_examples_per_epoch(self):
#     n_examples = super().n_examples_per_epoch()
#     if n_examples == len(self.inputfile_lists[0]):
#       return n_examples * self._batch_size
# 
# Path: datasets/Loader.py
# def register_dataset(name, **args):
#   name = name.lower()
# 
#   def _register(dataset):
#     _registered_datasets[name] = (dataset, args)
#     return dataset
#   return _register


# Path: datasets/MOT/segtrack/MOTS_challenge.py
import glob
from datasets.KITTI.segtrack.KITTI_segtrack import KittiSegtrackDataset
from datasets.Loader import register_dataset



NAME = "MOTS_challenge"
DEFAULT_PATH = "/globalwork/voigtlaender/data/MOTS_challenge/train/"
SEQ_IDS_TRAIN = ["%04d" % idx for idx in [2, 5, 9, 11]]
SEQ_IDS_VAL = ["%04d" % idx for idx in [2, 5, 9, 11]]
TIMESTEPS_PER_SEQ = {"0002": 600, "0005": 837, "0009": 525, "0011": 900}


@register_dataset(NAME)
class MotsChallengeDataset(KittiSegtrackDataset):
  def __init__(self, config, subset):
    #TODO: num classes, class_ids_with instances
    super().__init__(config, subset, name=NAME, default_path=DEFAULT_PATH)
    self.seq_ids_train = SEQ_IDS_TRAIN
    self.seq_ids_val = SEQ_IDS_VAL
    t = config.string_list("seq_ids_train", [])
    if t:
      self.seq_ids_train = t
    v = config.string_list("seq_ids_val", [])
    if v:
      self.seq_ids_val = v


  def read_inputfile_lists(self):
    #seq_ids = SEQ_IDS_TRAIN if self.subset == "train" else SEQ_IDS_VAL
    seq_ids = self.seq_ids_train if self.subset == "train" else self.seq_ids_val
    anns = []
    for seq_id in seq_ids:

      anns_vid = sorted(glob.glob(self.data_dir + "/instances/" + seq_id + "/*.png"))