from_darknet_generic#

from_darknet_generic(images_root: Path | str, labels_root: Path | str, names: Iterable[str], image_files_list: Iterable[str | Path] | None = None, split: str | None = None, ids_map: dict[int, dict[str, Any]] | str | Path | None = None, image_info: DataFrame | None = None) Dataset[source]#

Generic function to load a darknet like dataset by only giving it folders, class names and optionally file list instead of a data file.

Note

Unlike the darknet and yolov5 loaders, this function does only accept a single split value.

Note

If no file list is given, the function will simply glob all image files in images_root folder.

Parameters:
  • images_root – Folder containing the image files to load

  • labels_root – Folder containing the txt annotations files. Each annotation file is obtained by using the same relative path as the image equivalent and replacing the extension by txt. If no such file exist, it will not error but will assume there is no annotation

  • names – list of classes used in the label map when saving this darknet dataset.

  • image_files_list – list of images to read. Their path must be relative to images_root. If set to None, will glob all files in images_root

  • split – Split name of the constructed dataset. Defaults to None.

  • ids_map – Optional dictionary containing the id_remapping that was initially applied to create the darknet dataset. Will reverse it to get back to the original class mapping. The dictionary must have darknet dataset’s category ids (in sequential order then) as keys and with corresponding values that are dictionaries containing name and id keys relative to this class. Note that this can also be a path to a json file containing the dictionary. Defaults to None.

  • image_info – Optional DataFrame containing image information. Must contain at least the following columns : relative_path, id, width, height. Defaults to None

Raises:

FileNotFoundError – when the annotation file corresponding to a particular image file can not be found, be it using usual darknet convention or yolov5 one.

Returns:

Loaded dataset object