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.
from fastai.gen_doc.nbdoc import *
from fastai.core import *
default_cpus = min(16, num_cpus())
show_doc(has_arg)
has_arg
[source]
has_arg
(func
,arg
) →bool
Check if func
accepts arg
as an argument.
show_doc(ifnone)
show_doc(is1d)
show_doc(is_listy)
is_listy
[source]
is_listy
(x
:Any
) →bool
Check if x
is a Collection
.
show_doc(is_tuple)
is_tuple
[source]
is_tuple
(x
:Any
) →bool
Check if x
is a tuple
.
show_doc(try_int)
show_doc(arange_of)
arange_of
[source]
arange_of
(x
)
Return the numpy array of the range of the same length as x
.
show_doc(arrays_split)
arrays_split
[source]
arrays_split
(mask
:ndarray
,arrs
:NPArrayableList
) →SplitArrayList
Given arrs
is [a,b,...] and mask
index - return[(a[mask],a[~mask]),(b[mask],b[~mask]),...].
show_doc(df_names_to_idx)
df_names_to_idx
[source]
df_names_to_idx
(names
:Union
[int
,Collection
[int
],str
,StrList
],df
:DataFrame
)
Return the column indexes of names
in df
.
show_doc(extract_kwargs)
extract_kwargs
[source]
extract_kwargs
(names
:StrList
,kwargs
:KWArgs
)
Extract the keys in names
from the kwargs
.
show_doc(idx_dict)
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}
show_doc(index_row)
index_row
[source]
index_row
(a
:Collection
,idxs
:Collection
[int
]) →Any
Return the slice of a
corresponding to idxs
.
show_doc(listify)
show_doc(random_split)
random_split
[source]
random_split
(valid_pct
:float
,arrs
:NPArrayableList
) →SplitArrayList
Randomly split arrs
with valid_pct
ratio. good for creating validation set.
show_doc(range_of)
range_of
[source]
range_of
(x
)
Make a range
of the same size as x
.
show_doc(series2cat)
show_doc(to_int)
show_doc(uniqueify)
show_doc(download_url)
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
.
show_doc(find_classes)
find_classes
[source]
find_classes
(folder
:Path
) →FilePathList
List of label subdirectories in imagenet-style folder
.
show_doc(join_path)
join_path
[source]
join_path
(fname
:PathOrStr
,path
:PathOrStr
='.'
) →Path
Return Path(path)/Path(fname)
, path
defaults to current dir.
show_doc(join_paths)
join_paths
[source]
join_paths
(fnames
:FilePathList
,path
:PathOrStr
='.'
) →FilePathList
Join path
to every file name in fnames
.
show_doc(loadtxt_str)
loadtxt_str
[source]
loadtxt_str
(path
:PathOrStr
) →ndarray
Return ndarray
of str
of lines of text from path
.
show_doc(save_texts)
show_doc(ItemBase, title_level=3, doc_string=False)
class
ItemBase
[source]
ItemBase
(data
:Any
)
The base clase for all items. Must have a data
field that will be used when collating in mini-batches.
show_doc(Category, doc_string=False, title_level=3)
show_doc(MultiCategory, doc_string=False, title_level=3)
Create a MultiCategory
with an obj
that is a collection of labels. data
corresponds to the one-hot encoded labels and raw
is a list of associated string.
show_doc(camel2snake)
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'
show_doc(even_mults)
even_mults
[source]
even_mults
(start
:float
,stop
:float
,n
:int
) →ndarray
Build evenly stepped schedule from start
to stop
in n
steps.
show_doc(func_args)
show_doc(noop)
noop
[source]
noop
(x
)
Return x
.
show_doc(num_cpus)
show_doc(one_hot)
show_doc(partition)
partition
[source]
partition
(a
:Collection
,sz
:int
) →List
[Collection
]
Split iterables a
in equal parts of size sz
show_doc(partition_by_cores)
partition_by_cores
[source]
partition_by_cores
(a
:Collection
,n_cpus
:int
) →List
[Collection
]
Split data in a
equally among n_cpus
cores
show_doc(ItemBase.show)
show
[source]
show
(ax
:Axes
,kwargs
)
show_doc(ItemBase.apply_tfms)
apply_tfms
[source]
apply_tfms
(tfms
:Collection
,kwargs
)
show_doc(array)