(
        directory: str,
        class_to_idx: Optional[Dict[str, int]]=None,
        extensions: Optional[Tuple[str, ...]]=None,
        is_valid_file: Optional[Callable[[str], bool]]=None, )
return instances
Generates a list of samples of a form (path_to_sample, class).

    See :class:`DatasetFolder` for details.

    Note: The class_to_idx parameter is here optional and will use the logic of the ``find_classes`` function
    by default.
Generates a list of samples of a form (path_to_sample, class).
Generates a list of samples of a form ( path_to_sample class ) .
def make_dataset(
        directory: str,
        class_to_idx: Optional[Dict[str, int]]=None,
        extensions: Optional[Tuple[str, ...]]=None,
        is_valid_file: Optional[Callable[[str], bool]]=None, ) -> List[Tuple[
            str, int]]:
    """Generates a list of samples of a form (path_to_sample, class).

    See :class:`DatasetFolder` for details.

    Note: The class_to_idx parameter is here optional and will use the logic of the ``find_classes`` function
    by default.
    """
    directory = os.path.expanduser(directory)

    if class_to_idx is None:
        _, class_to_idx = find_classes(directory)
    elif not class_to_idx:
        raise ValueError(
            "'class_to_index' must have at least one entry to collect any samples."
        )

    both_none = extensions is None and is_valid_file is None
    both_something = extensions is not None and is_valid_file is not None
    if both_none or both_something:
        raise ValueError(
            "Both extensions and is_valid_file cannot be None or not None at the same time"
        )

    if extensions is not None:

        def is_valid_file(x: str) -> bool:
            return has_file_allowed_extension(
                x, cast(Tuple[str, ...], extensions))

    is_valid_file = cast(Callable[[str], bool], is_valid_file)

    instances = []
    available_classes = set()
    for target_class in sorted(class_to_idx.keys()):
        class_index = class_to_idx[target_class]
        target_dir = os.path.join(directory, target_class)
        if not os.path.isdir(target_dir):
            continue
        for root, _, fnames in sorted(os.walk(target_dir, followlinks=True)):
            for fname in sorted(fnames):
                if is_valid_file(fname):
                    path = os.path.join(root, fname)
                    item = path, class_index
                    instances.append(item)

                    if target_class not in available_classes:
                        available_classes.add(target_class)
            #     print(fname)
            # exit()

            # empty_classes = set(class_to_idx.keys()) - available_classes
            # if empty_classes:
            #     msg = f"Found no valid file for the classes {', '.join(sorted(empty_classes))}. "
            #     if extensions is not None:
            #         msg += f"Supported extensions are: {', '.join(extensions)}"
            #     raise FileNotFoundError(msg)

    return instances
def make_dataset ( directory : str , class_to_idx : Optional [ Dict [ str , int ] ] = None , extensions : Optional [ Tuple [ str , ... ] ] = None , is_valid_file : Optional [ Callable [ [ str ] , bool ] ] = None , ) -> List [ Tuple [ str , int ] ] : directory = os . path . expanduser ( directory ) if class_to_idx is None : _ , class_to_idx = find_classes ( directory ) elif not class_to_idx : raise ValueError ( "'class_to_index' must have at least one entry to collect any samples." ) both_none = extensions is None and is_valid_file is None both_something = extensions is not None and is_valid_file is not None if both_none or both_something : raise ValueError ( "Both extensions and is_valid_file cannot be None or not None at the same time" ) if extensions is not None : def is_valid_file ( x : str ) -> bool : return has_file_allowed_extension ( x , cast ( Tuple [ str , ... ] , extensions ) ) is_valid_file = cast ( Callable [ [ str ] , bool ] , is_valid_file ) instances = [ ] available_classes = set ( ) for target_class in sorted ( class_to_idx . keys ( ) ) : class_index = class_to_idx [ target_class ] target_dir = os . path . join ( directory , target_class ) if not os . path . isdir ( target_dir ) : continue for root , _ , fnames in sorted ( os . walk ( target_dir , followlinks = True ) ) : for fname in sorted ( fnames ) : if is_valid_file ( fname ) : path = os . path . join ( root , fname ) item = path , class_index instances . append ( item ) if target_class not in available_classes : available_classes . add ( target_class ) #     print(fname) # exit() # empty_classes = set(class_to_idx.keys()) - available_classes # if empty_classes: #     msg = f"Found no valid file for the classes {', '.join(sorted(empty_classes))}. " #     if extensions is not None: #         msg += f"Supported extensions are: {', '.join(extensions)}" #     raise FileNotFoundError(msg) return instances