from_darknet_yolov5#

from_darknet_yolov5(dataset_path: Path | str | None = None, data_file: Path | str | None = None, splits: Iterable[str] | None = None, split_name_mapping: Mapping[str, str] | None = None, ids_map: dict[int, dict[str, Any]] | str | Path | None = None, image_info: DataFrame | None = None) Dataset[source]#

Creates dataset object from a darknet dataset. Note that category ids and image ids are not given in the dataset format and thus can only be sequential As such, if we want to convert the dataset back to another format that keeps track of image and category ids, we need to give image_info and class mapping from an external source. Here we expect it to be contained in a json label map for annotations and a DataFrame with similar columns as in the final dataset’s images DataFrame for images

Parameters:
  • dataset_path – folder containing the dataset, from which the relative path are given. If not set, will use data_file’s parent directory. Defaults to None

  • data_file – data file containing info about names, lists of train and validation images. Must be a valid path to a Yaml file (either .yml or .yaml). If set to None, will use the file data.yaml at the root of dataset_path. Defaults to None.

  • splits – name of splits to load. if set to None, will consider every key in data_file that is neither names nor path to be a split. Every value in said keys must be either a valid folder or a valid text file, both relative to dataset_path. Defaults to None.

  • split_name_mapping – mapping dict to replace split names to other ones. split names not present in mapping will not be modified. If set to None, will apply yolov5 conventional mapping, i.e. ‘val’ -> ‘valid’ and ‘test’ -> ‘eval’. 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:

ValueError – Errors when neither dataset_path nor data_file is specified

Returns:

Loaded dataset object