class VideoProject(Project): dataset_class = VideoDataset class DatasetDict(KeyIndexedCollection): item_type = VideoDataset def __init__(self, directory, mode: OpenMode): self._key_id_map: KeyIdMap = None super().__init__(directory, mode) def _read(self): super(VideoProject, self)._read() self._key_id_map = KeyIdMap() self._key_id_map.load_json(self._get_key_id_map_path()) def _create(self): super()._create() self.set_key_id_map(KeyIdMap()) def _add_item_file_to_dataset(self, ds, item_name, item_paths, _validate_item, _use_hardlink): ds.add_item_file(item_name, item_paths.item_path, ann=item_paths.ann_path, _validate_item=_validate_item, _use_hardlink=_use_hardlink) @property def key_id_map(self): return self._key_id_map def set_key_id_map(self, new_map: KeyIdMap): self._key_id_map = new_map self._key_id_map.dump_json(self._get_key_id_map_path()) def _get_key_id_map_path(self): return os.path.join(self.directory, 'key_id_map.json') @classmethod def read_single(cls, dir): return read_project_wrapper(dir, cls)
class VideoProject(Project): ''' This is a class for creating and using VideoProject objects. You can think of a VideoProject as a superfolder with data and meta information. ''' dataset_class = VideoDataset class DatasetDict(KeyIndexedCollection): item_type = VideoDataset def __init__(self, directory, mode: OpenMode): ''' :param directory: path to the directory where the project will be saved or where it will be loaded from :param mode: OpenMode class object which determines in what mode to work with the project (generate exception error if not so) ''' self._key_id_map: KeyIdMap = None super().__init__(directory, mode) def _read(self): ''' Download project from given project directory. Checks item and annotation directoris existing and dataset not empty. Consistency checks. Every video must have an annotation, and the correspondence must be one to one. ''' super(VideoProject, self)._read() self._key_id_map = KeyIdMap() self._key_id_map.load_json(self._get_key_id_map_path()) def _create(self): ''' Creates a leaf directory and empty meta.json file. Generate exception error if project directory already exists and is not empty. ''' super()._create() self.set_key_id_map(KeyIdMap()) def _add_item_file_to_dataset(self, ds, item_name, item_paths, _validate_item, _use_hardlink): ''' Add given item file to dataset items directory and add annatation to dataset annotations dir corresponding to item. Generate exception error if item_name already exists in dataset or item name has unsupported extension :param ds: VideoDataset class object :param item_name: str :param item_paths: ItemPaths object :param _validate_item: bool :param _use_hardlink: bool ''' ds.add_item_file(item_name, item_paths.item_path, ann=item_paths.ann_path, _validate_item=_validate_item, _use_hardlink=_use_hardlink) @property def key_id_map(self): return self._key_id_map def set_key_id_map(self, new_map: KeyIdMap): ''' Save given KeyIdMap object to project dir in json format. :param new_map: KeyIdMap class object ''' self._key_id_map = new_map self._key_id_map.dump_json(self._get_key_id_map_path()) def _get_key_id_map_path(self): ''' :return: str (full path to key_id_map.json) ''' return os.path.join(self.directory, 'key_id_map.json') @classmethod def read_single(cls, dir): ''' Read project from given ditectory. Generate exception error if given dir contains more than one subdirectory :param dir: str :return: VideoProject class object ''' return read_project_wrapper(dir, cls)