Basic helper functions for the fastai library

Basic core

This module contains all the basic functions we need in other modules of the fastai library (split with torch_core that contains the ones requiring pytorch). Its documentation can easily be skipped at a first read, unless you want to know what a given function does.

Global constants

default_cpus = min(16, num_cpus())

Check functions

ifnone[source]

ifnone(a:Any, b:Any) → Any

a if a is not None, otherwise b.

is_listy[source]

is_listy(x:Any) → bool

Check if x is a Collection.

is_tuple[source]

is_tuple(x:Any) → bool

Check if x is a tuple.

arrays_split[source]

arrays_split(mask:ndarray, arrs:NPArrayableList) → SplitArrayList

Given arrs is [a,b,...] and maskindex - return[(a[mask],a[~mask]),(b[mask],b[~mask]),...].

extract_kwargs[source]

extract_kwargs(names:StrList, kwargs:KWArgs)

Extract the keys in names from the kwargs.

idx_dict[source]

idx_dict(a)

Create a dictionary value to index from a.

idx_dict(['a','b','c'])
{'a': 0, 'b': 1, 'c': 2}

listify[source]

listify(p:OptListOrItem=None, q:OptListOrItem=None)

Make p same length as q

random_split[source]

random_split(valid_pct:float, arrs:NPArrayableList) → SplitArrayList

Randomly split arrs with valid_pct ratio. good for creating validation set.

series2cat[source]

series2cat(df:DataFrame, col_names)

Categorifies the columns col_names in df.

uniqueify[source]

uniqueify(x:Series) → List

Return unique values of x

Return the unique elements in x.

Files management and downloads

download_url[source]

download_url(url:str, dest:str, overwrite:bool=False, pbar:ProgressBar=None, show_progress=True, chunk_size=1048576, timeout=4)

Download url to dest unless it exists and not overwrite.

find_classes[source]

find_classes(folder:Path) → FilePathList

List of label subdirectories in imagenet-style folder.

join_path[source]

join_path(fname:PathOrStr, path:PathOrStr='.') → Path

Return Path(path)/Path(fname), path defaults to current dir.

join_paths[source]

join_paths(fnames:FilePathList, path:PathOrStr='.') → FilePathList

Join path to every file name in fnames.

loadtxt_str[source]

loadtxt_str(path:PathOrStr) → ndarray

Return ndarray of str of lines of text from path.

save_texts[source]

save_texts(fname:PathOrStr, texts:StrList)

Save in fname the content of texts.

Others

class ItemBase[source]

ItemBase(data:Any)

All transformable dataset items use this type.

camel2snake[source]

camel2snake(name:str) → str

Format name by removing capital letters from a class-style name and separates the subwords with underscores.

camel2snake('DeviceDataLoader')
'device_data_loader'

even_mults[source]

even_mults(start:float, stop:float, n:int) → ndarray

Build evenly stepped schedule from start to stop in n steps.

noop[source]

noop(x)

Return x.

num_cpus[source]

num_cpus() → int

Get number of cpus

partition[source]

partition(a:Collection, sz:int) → List[Collection]

Split iterables a in equal parts of size sz

partition_by_cores[source]

partition_by_cores(a:Collection, n_cpus:int) → List[Collection]

Split data in a equally among n_cpus cores