def get_detection_api_from_dataset(
    dataset,
    supported_types: Sequence[
        Tuple["str", Union[Type, Tuple[Type]]]
    ] = DEFAULT_SUPPROTED_DETECTION_DATASETS,
    default_to_coco: bool = True,
    none_if_not_found=False,
):
    """
    Adapted from:
    https://github.com/pytorch/vision/blob/main/references/detection/engine.py

    :param dataset: The test dataset.
    :param supported_types: The supported API types
    :param default_to_coco: If True, if no API object can be found, the dataset
        will be converted to COCO.
    :param none_if_not_found: If True, it will return None if no valid
        detection API object is found. Else, it will consider `default_to_coco`
        or will raise an error.

    :return: The detection object.
    """

    recursion_result = None
    if isinstance(dataset, Subset):
        recursion_result = get_detection_api_from_dataset(
            dataset.dataset, supported_types, none_if_not_found=True
        )
    elif (
        isinstance(dataset, (AvalancheDataset, _FlatDataWithTransform))
        and len(dataset._datasets) == 1
    ):
        recursion_result = get_detection_api_from_dataset(
            dataset._datasets[0], supported_types, none_if_not_found=True
        )
    elif isinstance(dataset, (AvalancheDataset, ConcatDataset, _FlatDataWithTransform)):
        if isinstance(dataset, (AvalancheDataset, _FlatDataWithTransform)):
            datasets_list = dataset._datasets
        else:
            datasets_list = dataset.datasets

        for dataset in datasets_list:
            res = get_detection_api_from_dataset(
                dataset, supported_types, none_if_not_found=True
            )
            if res is not None:
                recursion_result = res
                break

    if recursion_result is not None:
        return recursion_result

    for supported_n, supported_t in supported_types:
        candidate_api = getattr(dataset, supported_n, None)
        if candidate_api is not None:
            if isinstance(candidate_api, supported_t):
                return candidate_api
    if none_if_not_found:
        return None
    elif default_to_coco:
        return convert_to_coco_api(dataset)
    else:
        raise ValueError("Could not find a valid dataset API object")

    Adapted from:
    https://github.com/pytorch/vision/blob/main/references/detection/engine.py

    :param dataset: The test dataset.
    :param supported_types: The supported API types
    :param default_to_coco: If True, if no API object can be found, the dataset
        will be converted to COCO.
    :param none_if_not_found: If True, it will return None if no valid
        detection API object is found. Else, it will consider `default_to_coco`
        or will raise an error.

    :return: The detection object.
    
avalanche/evaluation/metrics/detection.py