utils¶
-
fn_args_to_dict
(func, *args, **kwargs)[源代码]¶ Inspect function
func
and its arguments for running, and extract a dict mapping between argument names and keys.
-
class
InitTrackerMeta
(name, bases, attrs)[源代码]¶ 基类:
type
This metaclass wraps the
__init__
method of a class to addinit_config
attribute for instances of that class, andinit_config
use a dict to track the initial configuration. If the class has_pre_init
or_post_init
method, it would be hooked before or after__init__
and called as_pre_init(self, init_fn, init_args)
or_post_init(self, init_fn, init_args)
. Since InitTrackerMeta would be used as metaclass for pretrained model classes, which always are Layer andtype(Layer)
is nottype
, thus usetype(Layer)
rather thantype
as base class for it to avoid inheritance metaclass conflicts.-
static
init_and_track_conf
(init_func, pre_init_func=None, post_init_func=None)[源代码]¶ wraps
init_func
which is__init__
method of a class to addinit_config
attribute for instances of that class. :param init_func: It should be the__init__
method of a class. :type init_func: callable :param pre_init_func: If provided, it would be hooked afterinit_func
and called aspre_init_func(self, init_func, *init_args, **init_args)
. Default None.- 参数
post_init_func (callable, optional) -- If provided, it would be hooked after
init_func
and called aspost_init_func(self, init_func, *init_args, **init_args)
. Default None.- 返回
the wrapped function
- 返回类型
function
-
static