mirror of
https://github.com/open-mmlab/mmengine.git
synced 2025-06-03 21:54:44 +08:00
parent
c712070c90
commit
ad0b296fd4
mmengine
fileio
hooks
optim
optimizer
scheduler
registry
runner
utils
visualization
@ -43,9 +43,9 @@ class FileClient:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
backend (str, optional): The storage backend type. Options are "disk",
|
backend (str, optional): The storage backend type. Options are "disk",
|
||||||
"memcached", "lmdb", "http" and "petrel". Default: None.
|
"memcached", "lmdb", "http" and "petrel". Defaults to None.
|
||||||
prefix (str, optional): The prefix of the registered storage backend.
|
prefix (str, optional): The prefix of the registered storage backend.
|
||||||
Options are "s3", "http", "https". Default: None.
|
Options are "s3", "http", "https". Defaults to None.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> # only set backend
|
>>> # only set backend
|
||||||
@ -163,9 +163,9 @@ class FileClient:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
file_client_args (dict, optional): Arguments to instantiate a
|
file_client_args (dict, optional): Arguments to instantiate a
|
||||||
FileClient. Default: None.
|
FileClient. Defaults to None.
|
||||||
uri (str | Path, optional): Uri to be parsed that contains the file
|
uri (str | Path, optional): Uri to be parsed that contains the file
|
||||||
prefix. Default: None.
|
prefix. Defaults to None.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> uri = 's3://path/of/your/file'
|
>>> uri = 's3://path/of/your/file'
|
||||||
@ -263,7 +263,7 @@ class FileClient:
|
|||||||
force (bool, optional): Whether to override the backend if the name
|
force (bool, optional): Whether to override the backend if the name
|
||||||
has already been registered. Defaults to False.
|
has already been registered. Defaults to False.
|
||||||
prefixes (str or list[str] or tuple[str], optional): The prefixes
|
prefixes (str or list[str] or tuple[str], optional): The prefixes
|
||||||
of the registered storage backend. Default: None.
|
of the registered storage backend. Defaults to None.
|
||||||
`New in version 1.3.15.`
|
`New in version 1.3.15.`
|
||||||
"""
|
"""
|
||||||
if backend is not None:
|
if backend is not None:
|
||||||
@ -302,7 +302,7 @@ class FileClient:
|
|||||||
Args:
|
Args:
|
||||||
filepath (str or Path): Path to read data.
|
filepath (str or Path): Path to read data.
|
||||||
encoding (str): The encoding format used to open the ``filepath``.
|
encoding (str): The encoding format used to open the ``filepath``.
|
||||||
Default: 'utf-8'.
|
Defaults to 'utf-8'.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str: Expected text reading from ``filepath``.
|
str: Expected text reading from ``filepath``.
|
||||||
@ -333,7 +333,7 @@ class FileClient:
|
|||||||
obj (str): Data to be written.
|
obj (str): Data to be written.
|
||||||
filepath (str or Path): Path to write data.
|
filepath (str or Path): Path to write data.
|
||||||
encoding (str, optional): The encoding format used to open the
|
encoding (str, optional): The encoding format used to open the
|
||||||
`filepath`. Default: 'utf-8'.
|
`filepath`. Defaults to 'utf-8'.
|
||||||
"""
|
"""
|
||||||
self.client.put_text(obj, filepath)
|
self.client.put_text(obj, filepath)
|
||||||
|
|
||||||
@ -442,12 +442,12 @@ class FileClient:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
dir_path (str | Path): Path of the directory.
|
dir_path (str | Path): Path of the directory.
|
||||||
list_dir (bool): List the directories. Default: True.
|
list_dir (bool): List the directories. Defaults to True.
|
||||||
list_file (bool): List the path of files. Default: True.
|
list_file (bool): List the path of files. Defaults to True.
|
||||||
suffix (str or tuple[str], optional): File suffix
|
suffix (str or tuple[str], optional): File suffix
|
||||||
that we are interested in. Default: None.
|
that we are interested in. Defaults to None.
|
||||||
recursive (bool): If set to True, recursively scan the
|
recursive (bool): If set to True, recursively scan the
|
||||||
directory. Default: False.
|
directory. Defaults to False.
|
||||||
|
|
||||||
Yields:
|
Yields:
|
||||||
Iterable[str]: A relative path to ``dir_path``.
|
Iterable[str]: A relative path to ``dir_path``.
|
||||||
|
@ -776,8 +776,8 @@ def generate_presigned_url(
|
|||||||
Args:
|
Args:
|
||||||
url (str): Url of video stream.
|
url (str): Url of video stream.
|
||||||
client_method (str): Method of client, 'get_object' or
|
client_method (str): Method of client, 'get_object' or
|
||||||
'put_object'. Default: 'get_object'.
|
'put_object'. Defaults to 'get_object'.
|
||||||
expires_in (int): expires, in seconds. Default: 3600.
|
expires_in (int): expires, in seconds. Defaults to 3600.
|
||||||
backend_args (dict, optional): Arguments to instantiate the
|
backend_args (dict, optional): Arguments to instantiate the
|
||||||
corresponding backend. Defaults to None.
|
corresponding backend. Defaults to None.
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class LoggerHook(Hook):
|
|||||||
by epoch. It can be true when running in epoch based runner.
|
by epoch. It can be true when running in epoch based runner.
|
||||||
If set to True, `after_val_epoch` will set `step` to self.epoch in
|
If set to True, `after_val_epoch` will set `step` to self.epoch in
|
||||||
`runner.visualizer.add_scalars`. Otherwise `step` will be
|
`runner.visualizer.add_scalars`. Otherwise `step` will be
|
||||||
self.iter. Default to True.
|
self.iter. Defaults to True.
|
||||||
backend_args (dict, optional): Arguments to instantiate the
|
backend_args (dict, optional): Arguments to instantiate the
|
||||||
preifx of uri corresponding backend. Defaults to None.
|
preifx of uri corresponding backend. Defaults to None.
|
||||||
New in v0.2.0.
|
New in v0.2.0.
|
||||||
|
@ -20,9 +20,9 @@ class NaiveVisualizationHook(Hook):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
interval (int): Visualization interval. Defaults to 1.
|
interval (int): Visualization interval. Defaults to 1.
|
||||||
draw_gt (bool): Whether to draw the ground truth. Default to True.
|
draw_gt (bool): Whether to draw the ground truth. Defaults to True.
|
||||||
draw_pred (bool): Whether to draw the predicted result.
|
draw_pred (bool): Whether to draw the predicted result.
|
||||||
Default to True.
|
Defaults to True.
|
||||||
"""
|
"""
|
||||||
priority = 'NORMAL'
|
priority = 'NORMAL'
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class DefaultOptimWrapperConstructor:
|
|||||||
rate for parameters of offset layer in the deformable convs
|
rate for parameters of offset layer in the deformable convs
|
||||||
of a model.
|
of a model.
|
||||||
- ``bypass_duplicate`` (bool): If true, the duplicate parameters
|
- ``bypass_duplicate`` (bool): If true, the duplicate parameters
|
||||||
would not be added into optimizer. Default: False.
|
would not be added into optimizer. Defaults to False.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class OptimWrapper:
|
|||||||
``'inf'`` for infinity norm.
|
``'inf'`` for infinity norm.
|
||||||
- error_if_nonfinite (bool): If True, an error is thrown if
|
- error_if_nonfinite (bool): If True, an error is thrown if
|
||||||
the total norm of the gradients from :attr:`parameters` is
|
the total norm of the gradients from :attr:`parameters` is
|
||||||
``nan``, ``inf``, or ``-inf``. Default: False (will switch
|
``nan``, ``inf``, or ``-inf``. Defaults to False (will switch
|
||||||
to True in the future)
|
to True in the future)
|
||||||
|
|
||||||
If the key ``type`` is set to "value", the accepted keys are as
|
If the key ``type`` is set to "value", the accepted keys are as
|
||||||
|
@ -260,20 +260,20 @@ class OneCycleLR(LRSchedulerMixin, OneCycleParamScheduler):
|
|||||||
total_steps (int): The total number of steps in the cycle. Note that
|
total_steps (int): The total number of steps in the cycle. Note that
|
||||||
if a value is not provided here, then it must be inferred by
|
if a value is not provided here, then it must be inferred by
|
||||||
providing a value for epochs and steps_per_epoch.
|
providing a value for epochs and steps_per_epoch.
|
||||||
Default to None.
|
Defaults to None.
|
||||||
pct_start (float): The percentage of the cycle (in number of steps)
|
pct_start (float): The percentage of the cycle (in number of steps)
|
||||||
spent increasing the learning rate.
|
spent increasing the learning rate.
|
||||||
Default to 0.3
|
Defaults to 0.3
|
||||||
anneal_strategy (str): {'cos', 'linear'}
|
anneal_strategy (str): {'cos', 'linear'}
|
||||||
Specifies the annealing strategy: "cos" for cosine annealing,
|
Specifies the annealing strategy: "cos" for cosine annealing,
|
||||||
"linear" for linear annealing.
|
"linear" for linear annealing.
|
||||||
Default to 'cos'
|
Defaults to 'cos'
|
||||||
div_factor (float): Determines the initial learning rate via
|
div_factor (float): Determines the initial learning rate via
|
||||||
initial_param = eta_max/div_factor
|
initial_param = eta_max/div_factor
|
||||||
Default to 25
|
Defaults to 25
|
||||||
final_div_factor (float): Determines the minimum learning rate via
|
final_div_factor (float): Determines the minimum learning rate via
|
||||||
eta_min = initial_param/final_div_factor
|
eta_min = initial_param/final_div_factor
|
||||||
Default to 1e4
|
Defaults to 1e4
|
||||||
three_phase (bool): If ``True``, use a third phase of the schedule to
|
three_phase (bool): If ``True``, use a third phase of the schedule to
|
||||||
annihilate the learning rate according to 'final_div_factor'
|
annihilate the learning rate according to 'final_div_factor'
|
||||||
instead of modifying the second phase (the first two phases will be
|
instead of modifying the second phase (the first two phases will be
|
||||||
@ -308,7 +308,7 @@ class CosineRestartLR(LRSchedulerMixin, CosineRestartParamScheduler):
|
|||||||
Defaults to None.
|
Defaults to None.
|
||||||
eta_min_ratio (float, optional): The ratio of minimum parameter value
|
eta_min_ratio (float, optional): The ratio of minimum parameter value
|
||||||
to the base parameter value. Either `min_lr` or `min_lr_ratio`
|
to the base parameter value. Either `min_lr` or `min_lr_ratio`
|
||||||
should be specified. Default: None.
|
should be specified. Defaults to None.
|
||||||
begin (int): Step at which to start updating the parameters.
|
begin (int): Step at which to start updating the parameters.
|
||||||
Defaults to 0.
|
Defaults to 0.
|
||||||
end (int): Step at which to stop updating the parameters.
|
end (int): Step at which to stop updating the parameters.
|
||||||
|
@ -274,7 +274,7 @@ class CosineRestartMomentum(MomentumSchedulerMixin,
|
|||||||
Defaults to None.
|
Defaults to None.
|
||||||
eta_min_ratio (float, optional): The ratio of minimum parameter value
|
eta_min_ratio (float, optional): The ratio of minimum parameter value
|
||||||
to the base parameter value. Either `min_lr` or `min_lr_ratio`
|
to the base parameter value. Either `min_lr` or `min_lr_ratio`
|
||||||
should be specified. Default: None.
|
should be specified. Defaults to None.
|
||||||
begin (int): Step at which to start updating the parameters.
|
begin (int): Step at which to start updating the parameters.
|
||||||
Defaults to 0.
|
Defaults to 0.
|
||||||
end (int): Step at which to stop updating the parameters.
|
end (int): Step at which to stop updating the parameters.
|
||||||
|
@ -924,20 +924,20 @@ class OneCycleParamScheduler(_ParamScheduler):
|
|||||||
for each parameter group.
|
for each parameter group.
|
||||||
total_steps (int): The total number of steps in the cycle. Note that
|
total_steps (int): The total number of steps in the cycle. Note that
|
||||||
if a value is not provided here, then it will be equal to
|
if a value is not provided here, then it will be equal to
|
||||||
``end - begin``. Default to None
|
``end - begin``. Defaults to None
|
||||||
pct_start (float): The percentage of the cycle (in number of steps)
|
pct_start (float): The percentage of the cycle (in number of steps)
|
||||||
spent increasing the learning rate.
|
spent increasing the learning rate.
|
||||||
Default to 0.3
|
Defaults to 0.3
|
||||||
anneal_strategy (str): {'cos', 'linear'}
|
anneal_strategy (str): {'cos', 'linear'}
|
||||||
Specifies the annealing strategy: "cos" for cosine annealing,
|
Specifies the annealing strategy: "cos" for cosine annealing,
|
||||||
"linear" for linear annealing.
|
"linear" for linear annealing.
|
||||||
Default to 'cos'
|
Defaults to 'cos'
|
||||||
div_factor (float): Determines the initial learning rate via
|
div_factor (float): Determines the initial learning rate via
|
||||||
initial_param = eta_max/div_factor
|
initial_param = eta_max/div_factor
|
||||||
Default to 25
|
Defaults to 25
|
||||||
final_div_factor (float): Determines the minimum learning rate via
|
final_div_factor (float): Determines the minimum learning rate via
|
||||||
eta_min = initial_param/final_div_factor
|
eta_min = initial_param/final_div_factor
|
||||||
Default to 1e4
|
Defaults to 1e4
|
||||||
three_phase (bool): If ``True``, use a third phase of the schedule to
|
three_phase (bool): If ``True``, use a third phase of the schedule to
|
||||||
annihilate the learning rate according to 'final_div_factor'
|
annihilate the learning rate according to 'final_div_factor'
|
||||||
instead of modifying the second phase (the first two phases will be
|
instead of modifying the second phase (the first two phases will be
|
||||||
|
@ -594,7 +594,7 @@ class Registry:
|
|||||||
name (str or list of str, optional): The module name to be
|
name (str or list of str, optional): The module name to be
|
||||||
registered. If not specified, the class name will be used.
|
registered. If not specified, the class name will be used.
|
||||||
force (bool): Whether to override an existing class with the same
|
force (bool): Whether to override an existing class with the same
|
||||||
name. Default to False.
|
name. Defaults to False.
|
||||||
module (type, optional): Module class or function to be registered.
|
module (type, optional): Module class or function to be registered.
|
||||||
Defaults to None.
|
Defaults to None.
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ def traverse_registry_tree(registry: Registry, verbose: bool = True) -> list:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
registry (Registry): a registry node in the registry tree.
|
registry (Registry): a registry node in the registry tree.
|
||||||
verbose (bool): Whether to print log. Default: True
|
verbose (bool): Whether to print log. Defaults to True
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: Statistic results of all modules in each node of the registry
|
list: Statistic results of all modules in each node of the registry
|
||||||
|
@ -56,7 +56,7 @@ def load_state_dict(module, state_dict, strict=False, logger=None):
|
|||||||
state_dict (OrderedDict): Weights.
|
state_dict (OrderedDict): Weights.
|
||||||
strict (bool): whether to strictly enforce that the keys
|
strict (bool): whether to strictly enforce that the keys
|
||||||
in :attr:`state_dict` match the keys returned by this module's
|
in :attr:`state_dict` match the keys returned by this module's
|
||||||
:meth:`~torch.nn.Module.state_dict` function. Default: ``False``.
|
:meth:`~torch.nn.Module.state_dict` function. Defaults to False.
|
||||||
logger (:obj:`logging.Logger`, optional): Logger to log the error
|
logger (:obj:`logging.Logger`, optional): Logger to log the error
|
||||||
message. If not specified, print function will be used.
|
message. If not specified, print function will be used.
|
||||||
"""
|
"""
|
||||||
@ -285,7 +285,7 @@ class CheckpointLoader:
|
|||||||
Args:
|
Args:
|
||||||
filename (str): checkpoint file name with given prefix
|
filename (str): checkpoint file name with given prefix
|
||||||
map_location (str, optional): Same as :func:`torch.load`.
|
map_location (str, optional): Same as :func:`torch.load`.
|
||||||
Default: None
|
Defaults to None
|
||||||
logger (str): The logger for message. Defaults to 'current'.
|
logger (str): The logger for message. Defaults to 'current'.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -332,7 +332,7 @@ def load_from_http(filename,
|
|||||||
torchvision prefix
|
torchvision prefix
|
||||||
map_location (str, optional): Same as :func:`torch.load`.
|
map_location (str, optional): Same as :func:`torch.load`.
|
||||||
model_dir (string, optional): directory in which to save the object,
|
model_dir (string, optional): directory in which to save the object,
|
||||||
Default: None
|
Defaults to None
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict or OrderedDict: The loaded checkpoint.
|
dict or OrderedDict: The loaded checkpoint.
|
||||||
@ -364,7 +364,7 @@ def load_from_pavi(filename, map_location=None):
|
|||||||
Args:
|
Args:
|
||||||
filename (str): checkpoint file path with pavi prefix
|
filename (str): checkpoint file path with pavi prefix
|
||||||
map_location (str, optional): Same as :func:`torch.load`.
|
map_location (str, optional): Same as :func:`torch.load`.
|
||||||
Default: None
|
Defaults to None
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict or OrderedDict: The loaded checkpoint.
|
dict or OrderedDict: The loaded checkpoint.
|
||||||
@ -443,7 +443,7 @@ def load_from_openmmlab(filename, map_location=None):
|
|||||||
filename (str): checkpoint file path with open-mmlab or
|
filename (str): checkpoint file path with open-mmlab or
|
||||||
openmmlab prefix
|
openmmlab prefix
|
||||||
map_location (str, optional): Same as :func:`torch.load`.
|
map_location (str, optional): Same as :func:`torch.load`.
|
||||||
Default: None
|
Defaults to None
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict or OrderedDict: The loaded checkpoint.
|
dict or OrderedDict: The loaded checkpoint.
|
||||||
@ -504,9 +504,9 @@ def _load_checkpoint(filename, map_location=None, logger=None):
|
|||||||
``open-mmlab://xxx``. Please refer to ``docs/model_zoo.md`` for
|
``open-mmlab://xxx``. Please refer to ``docs/model_zoo.md`` for
|
||||||
details.
|
details.
|
||||||
map_location (str, optional): Same as :func:`torch.load`.
|
map_location (str, optional): Same as :func:`torch.load`.
|
||||||
Default: None.
|
Defaults to None.
|
||||||
logger (:mod:`logging.Logger`, optional): The logger for error message.
|
logger (:mod:`logging.Logger`, optional): The logger for error message.
|
||||||
Default: None
|
Defaults to None
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict or OrderedDict: The loaded checkpoint. It can be either an
|
dict or OrderedDict: The loaded checkpoint. It can be either an
|
||||||
@ -524,7 +524,8 @@ def _load_checkpoint_with_prefix(prefix, filename, map_location=None):
|
|||||||
filename (str): Accept local filepath, URL, ``torchvision://xxx``,
|
filename (str): Accept local filepath, URL, ``torchvision://xxx``,
|
||||||
``open-mmlab://xxx``. Please refer to ``docs/model_zoo.md`` for
|
``open-mmlab://xxx``. Please refer to ``docs/model_zoo.md`` for
|
||||||
details.
|
details.
|
||||||
map_location (str | None): Same as :func:`torch.load`. Default: None.
|
map_location (str | None): Same as :func:`torch.load`.
|
||||||
|
Defaults to None.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict or OrderedDict: The loaded checkpoint.
|
dict or OrderedDict: The loaded checkpoint.
|
||||||
@ -594,7 +595,7 @@ def load_checkpoint(model,
|
|||||||
logger (:mod:`logging.Logger` or None): The logger for error message.
|
logger (:mod:`logging.Logger` or None): The logger for error message.
|
||||||
revise_keys (list): A list of customized keywords to modify the
|
revise_keys (list): A list of customized keywords to modify the
|
||||||
state_dict in checkpoint. Each item is a (pattern, replacement)
|
state_dict in checkpoint. Each item is a (pattern, replacement)
|
||||||
pair of the regular expression operations. Default: strip
|
pair of the regular expression operations. Defaults to strip
|
||||||
the prefix 'module.' by [(r'^module\\.', '')].
|
the prefix 'module.' by [(r'^module\\.', '')].
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -668,7 +669,7 @@ def get_state_dict(module, destination=None, prefix='', keep_vars=False):
|
|||||||
module.
|
module.
|
||||||
prefix (str): Prefix of the key.
|
prefix (str): Prefix of the key.
|
||||||
keep_vars (bool): Whether to keep the variable property of the
|
keep_vars (bool): Whether to keep the variable property of the
|
||||||
parameters. Default: False.
|
parameters. Defaults to False.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: A dictionary containing a whole state of the module.
|
dict: A dictionary containing a whole state of the module.
|
||||||
|
@ -2027,7 +2027,7 @@ class Runner:
|
|||||||
the model and checkpoint.
|
the model and checkpoint.
|
||||||
revise_keys (list): A list of customized keywords to modify the
|
revise_keys (list): A list of customized keywords to modify the
|
||||||
state_dict in checkpoint. Each item is a (pattern, replacement)
|
state_dict in checkpoint. Each item is a (pattern, replacement)
|
||||||
pair of the regular expression operations. Default: strip
|
pair of the regular expression operations. Defaults to strip
|
||||||
the prefix 'module.' by [(r'^module\\.', '')].
|
the prefix 'module.' by [(r'^module\\.', '')].
|
||||||
"""
|
"""
|
||||||
checkpoint = _load_checkpoint(filename, map_location=map_location)
|
checkpoint = _load_checkpoint(filename, map_location=map_location)
|
||||||
|
@ -53,9 +53,9 @@ def set_random_seed(seed: Optional[int] = None,
|
|||||||
deterministic (bool): Whether to set the deterministic option for
|
deterministic (bool): Whether to set the deterministic option for
|
||||||
CUDNN backend, i.e., set `torch.backends.cudnn.deterministic`
|
CUDNN backend, i.e., set `torch.backends.cudnn.deterministic`
|
||||||
to True and `torch.backends.cudnn.benchmark` to False.
|
to True and `torch.backends.cudnn.benchmark` to False.
|
||||||
Default: False.
|
Defaults to False.
|
||||||
diff_rank_seed (bool): Whether to add rank number to the random seed to
|
diff_rank_seed (bool): Whether to add rank number to the random seed to
|
||||||
have different random seed in different threads. Default: False.
|
have different random seed in different threads. Defaults to False.
|
||||||
"""
|
"""
|
||||||
if seed is None:
|
if seed is None:
|
||||||
seed = sync_random_seed()
|
seed = sync_random_seed()
|
||||||
|
@ -68,15 +68,15 @@ if TORCH_VERSION != 'parrots' and digit_version(TORCH_VERSION) < digit_version(
|
|||||||
map_location (optional): a function or a dict specifying how to
|
map_location (optional): a function or a dict specifying how to
|
||||||
remap storage locations (see torch.load)
|
remap storage locations (see torch.load)
|
||||||
progress (bool, optional): whether or not to display a progress bar
|
progress (bool, optional): whether or not to display a progress bar
|
||||||
to stderr. Default: True
|
to stderr. Defaults to True
|
||||||
check_hash(bool, optional): If True, the filename part of the URL
|
check_hash(bool, optional): If True, the filename part of the URL
|
||||||
should follow the naming convention ``filename-<sha256>.ext``
|
should follow the naming convention ``filename-<sha256>.ext``
|
||||||
where ``<sha256>`` is the first eight or more digits of the
|
where ``<sha256>`` is the first eight or more digits of the
|
||||||
SHA256 hash of the contents of the file. The hash is used to
|
SHA256 hash of the contents of the file. The hash is used to
|
||||||
ensure unique names and to verify the contents of the file.
|
ensure unique names and to verify the contents of the file.
|
||||||
Default: False
|
Defaults to False
|
||||||
file_name (str, optional): name for the downloaded file. Filename
|
file_name (str, optional): name for the downloaded file. Filename
|
||||||
from ``url`` will be used if not set. Default: None.
|
from ``url`` will be used if not set. Defaults to None.
|
||||||
Example:
|
Example:
|
||||||
>>> url = ('https://s3.amazonaws.com/pytorch/models/resnet18-5c106'
|
>>> url = ('https://s3.amazonaws.com/pytorch/models/resnet18-5c106'
|
||||||
... 'cde.pth')
|
... 'cde.pth')
|
||||||
|
@ -46,7 +46,7 @@ def import_modules_from_strings(imports, allow_failed_imports=False):
|
|||||||
Args:
|
Args:
|
||||||
imports (list | str | None): The given module names to be imported.
|
imports (list | str | None): The given module names to be imported.
|
||||||
allow_failed_imports (bool): If True, the failed imports will return
|
allow_failed_imports (bool): If True, the failed imports will return
|
||||||
None. Otherwise, an ImportError is raise. Default: False.
|
None. Otherwise, an ImportError is raise. Defaults to False.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[module] | module | None: The imported modules.
|
list[module] | module | None: The imported modules.
|
||||||
|
@ -42,11 +42,11 @@ def scandir(dir_path, suffix=None, recursive=False, case_sensitive=True):
|
|||||||
Args:
|
Args:
|
||||||
dir_path (str | :obj:`Path`): Path of the directory.
|
dir_path (str | :obj:`Path`): Path of the directory.
|
||||||
suffix (str | tuple(str), optional): File suffix that we are
|
suffix (str | tuple(str), optional): File suffix that we are
|
||||||
interested in. Default: None.
|
interested in. Defaults to None.
|
||||||
recursive (bool, optional): If set to True, recursively scan the
|
recursive (bool, optional): If set to True, recursively scan the
|
||||||
directory. Default: False.
|
directory. Defaults to False.
|
||||||
case_sensitive (bool, optional) : If set to False, ignore the case of
|
case_sensitive (bool, optional) : If set to False, ignore the case of
|
||||||
suffix. Default: True.
|
suffix. Defaults to True.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A generator for all the interested files with relative paths.
|
A generator for all the interested files with relative paths.
|
||||||
|
@ -14,7 +14,7 @@ def digit_version(version_str: str, length: int = 4):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
version_str (str): The version string.
|
version_str (str): The version string.
|
||||||
length (int): The maximum number of version levels. Default: 4.
|
length (int): The maximum number of version levels. Defaults to 4.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple[int]: The version info in digits (integers).
|
tuple[int]: The version info in digits (integers).
|
||||||
|
@ -117,8 +117,8 @@ class BaseVisBackend(metaclass=ABCMeta):
|
|||||||
Args:
|
Args:
|
||||||
name (str): The image identifier.
|
name (str): The image identifier.
|
||||||
image (np.ndarray): The image to be saved. The format
|
image (np.ndarray): The image to be saved. The format
|
||||||
should be RGB. Default to None.
|
should be RGB. Defaults to None.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ class BaseVisBackend(metaclass=ABCMeta):
|
|||||||
Args:
|
Args:
|
||||||
name (str): The scalar identifier.
|
name (str): The scalar identifier.
|
||||||
value (int, float): Value to save.
|
value (int, float): Value to save.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -146,11 +146,11 @@ class BaseVisBackend(metaclass=ABCMeta):
|
|||||||
Args:
|
Args:
|
||||||
scalar_dict (dict): Key-value pair storing the tag and
|
scalar_dict (dict): Key-value pair storing the tag and
|
||||||
corresponding values.
|
corresponding values.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
file_path (str, optional): The scalar's data will be
|
file_path (str, optional): The scalar's data will be
|
||||||
saved to the `file_path` file at the same time
|
saved to the `file_path` file at the same time
|
||||||
if the `file_path` parameter is specified.
|
if the `file_path` parameter is specified.
|
||||||
Default to None.
|
Defaults to None.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -183,11 +183,11 @@ class LocalVisBackend(BaseVisBackend):
|
|||||||
produced by the visualizer. If it is none, it means no data
|
produced by the visualizer. If it is none, it means no data
|
||||||
is stored.
|
is stored.
|
||||||
img_save_dir (str): The directory to save images.
|
img_save_dir (str): The directory to save images.
|
||||||
Default to 'vis_image'.
|
Defaults to 'vis_image'.
|
||||||
config_save_file (str): The file name to save config.
|
config_save_file (str): The file name to save config.
|
||||||
Default to 'config.py'.
|
Defaults to 'config.py'.
|
||||||
scalar_save_file (str): The file name to save scalar values.
|
scalar_save_file (str): The file name to save scalar values.
|
||||||
Default to 'scalars.json'.
|
Defaults to 'scalars.json'.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
@ -244,8 +244,8 @@ class LocalVisBackend(BaseVisBackend):
|
|||||||
Args:
|
Args:
|
||||||
name (str): The image identifier.
|
name (str): The image identifier.
|
||||||
image (np.ndarray): The image to be saved. The format
|
image (np.ndarray): The image to be saved. The format
|
||||||
should be RGB. Default to None.
|
should be RGB. Defaults to None.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
assert image.dtype == np.uint8
|
assert image.dtype == np.uint8
|
||||||
drawn_image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
drawn_image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
||||||
@ -264,7 +264,7 @@ class LocalVisBackend(BaseVisBackend):
|
|||||||
Args:
|
Args:
|
||||||
name (str): The scalar identifier.
|
name (str): The scalar identifier.
|
||||||
value (int, float, torch.Tensor, np.ndarray): Value to save.
|
value (int, float, torch.Tensor, np.ndarray): Value to save.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
if isinstance(value, torch.Tensor):
|
if isinstance(value, torch.Tensor):
|
||||||
value = value.item()
|
value = value.item()
|
||||||
@ -285,11 +285,11 @@ class LocalVisBackend(BaseVisBackend):
|
|||||||
scalar_dict (dict): Key-value pair storing the tag and
|
scalar_dict (dict): Key-value pair storing the tag and
|
||||||
corresponding values. The value must be dumped
|
corresponding values. The value must be dumped
|
||||||
into json format.
|
into json format.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
file_path (str, optional): The scalar's data will be
|
file_path (str, optional): The scalar's data will be
|
||||||
saved to the ``file_path`` file at the same time
|
saved to the ``file_path`` file at the same time
|
||||||
if the ``file_path`` parameter is specified.
|
if the ``file_path`` parameter is specified.
|
||||||
Default to None.
|
Defaults to None.
|
||||||
"""
|
"""
|
||||||
assert isinstance(scalar_dict, dict)
|
assert isinstance(scalar_dict, dict)
|
||||||
scalar_dict = copy.deepcopy(scalar_dict)
|
scalar_dict = copy.deepcopy(scalar_dict)
|
||||||
@ -339,7 +339,9 @@ class WandbVisBackend(BaseVisBackend):
|
|||||||
save_dir (str, optional): The root directory to save the files
|
save_dir (str, optional): The root directory to save the files
|
||||||
produced by the visualizer.
|
produced by the visualizer.
|
||||||
init_kwargs (dict, optional): wandb initialization
|
init_kwargs (dict, optional): wandb initialization
|
||||||
input parameters. Default to None.
|
input parameters.
|
||||||
|
See `wandb.init <https://docs.wandb.ai/ref/python/init>`_ for
|
||||||
|
details. Defaults to None.
|
||||||
define_metric_cfg (dict, optional):
|
define_metric_cfg (dict, optional):
|
||||||
A dict of metrics and summary for wandb.define_metric.
|
A dict of metrics and summary for wandb.define_metric.
|
||||||
The key is metric and the value is summary.
|
The key is metric and the value is summary.
|
||||||
@ -349,10 +351,10 @@ class WandbVisBackend(BaseVisBackend):
|
|||||||
run#define_metric>`_ for details.
|
run#define_metric>`_ for details.
|
||||||
Default: None
|
Default: None
|
||||||
commit: (bool, optional) Save the metrics dict to the wandb server
|
commit: (bool, optional) Save the metrics dict to the wandb server
|
||||||
and increment the step. If false `wandb.log` just
|
and increment the step. If false `wandb.log` just updates the
|
||||||
updates the current metrics dict with the row argument
|
current metrics dict with the row argument and metrics won't be
|
||||||
and metrics won't be saved until `wandb.log` is called
|
saved until `wandb.log` is called with `commit=True`.
|
||||||
with `commit=True`. Default to True.
|
Defaults to True.
|
||||||
log_code_name: (str, optional) The name of code artifact.
|
log_code_name: (str, optional) The name of code artifact.
|
||||||
By default, the artifact will be named
|
By default, the artifact will be named
|
||||||
source-$PROJECT_ID-$ENTRYPOINT_RELPATH. See
|
source-$PROJECT_ID-$ENTRYPOINT_RELPATH. See
|
||||||
@ -442,7 +444,7 @@ class WandbVisBackend(BaseVisBackend):
|
|||||||
image (np.ndarray): The image to be saved. The format
|
image (np.ndarray): The image to be saved. The format
|
||||||
should be RGB.
|
should be RGB.
|
||||||
step (int): Useless parameter. Wandb does not
|
step (int): Useless parameter. Wandb does not
|
||||||
need this parameter. Default to 0.
|
need this parameter. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
image = self._wandb.Image(image)
|
image = self._wandb.Image(image)
|
||||||
self._wandb.log({name: image}, commit=self._commit)
|
self._wandb.log({name: image}, commit=self._commit)
|
||||||
@ -459,7 +461,7 @@ class WandbVisBackend(BaseVisBackend):
|
|||||||
name (str): The scalar identifier.
|
name (str): The scalar identifier.
|
||||||
value (int, float, torch.Tensor, np.ndarray): Value to save.
|
value (int, float, torch.Tensor, np.ndarray): Value to save.
|
||||||
step (int): Useless parameter. Wandb does not
|
step (int): Useless parameter. Wandb does not
|
||||||
need this parameter. Default to 0.
|
need this parameter. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
self._wandb.log({name: value}, commit=self._commit)
|
self._wandb.log({name: value}, commit=self._commit)
|
||||||
|
|
||||||
@ -475,9 +477,9 @@ class WandbVisBackend(BaseVisBackend):
|
|||||||
scalar_dict (dict): Key-value pair storing the tag and
|
scalar_dict (dict): Key-value pair storing the tag and
|
||||||
corresponding values.
|
corresponding values.
|
||||||
step (int): Useless parameter. Wandb does not
|
step (int): Useless parameter. Wandb does not
|
||||||
need this parameter. Default to 0.
|
need this parameter. Defaults to 0.
|
||||||
file_path (str, optional): Useless parameter. Just for
|
file_path (str, optional): Useless parameter. Just for
|
||||||
interface unification. Default to None.
|
interface unification. Defaults to None.
|
||||||
"""
|
"""
|
||||||
self._wandb.log(scalar_dict, commit=self._commit)
|
self._wandb.log(scalar_dict, commit=self._commit)
|
||||||
|
|
||||||
@ -560,7 +562,7 @@ class TensorboardVisBackend(BaseVisBackend):
|
|||||||
name (str): The image identifier.
|
name (str): The image identifier.
|
||||||
image (np.ndarray): The image to be saved. The format
|
image (np.ndarray): The image to be saved. The format
|
||||||
should be RGB.
|
should be RGB.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
self._tensorboard.add_image(name, image, step, dataformats='HWC')
|
self._tensorboard.add_image(name, image, step, dataformats='HWC')
|
||||||
|
|
||||||
@ -575,14 +577,14 @@ class TensorboardVisBackend(BaseVisBackend):
|
|||||||
Args:
|
Args:
|
||||||
name (str): The scalar identifier.
|
name (str): The scalar identifier.
|
||||||
value (int, float, torch.Tensor, np.ndarray): Value to save.
|
value (int, float, torch.Tensor, np.ndarray): Value to save.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
if isinstance(value,
|
if isinstance(value,
|
||||||
(int, float, torch.Tensor, np.ndarray, np.number)):
|
(int, float, torch.Tensor, np.ndarray, np.number)):
|
||||||
self._tensorboard.add_scalar(name, value, step)
|
self._tensorboard.add_scalar(name, value, step)
|
||||||
else:
|
else:
|
||||||
warnings.warn(f'Got {type(value)}, but numpy array, torch tensor, '
|
warnings.warn(f'Got {type(value)}, but numpy array, torch tensor, '
|
||||||
f'int or float are expected. skip it!')
|
f'int or float are expected. skip it!')
|
||||||
|
|
||||||
@force_init_env
|
@force_init_env
|
||||||
def add_scalars(self,
|
def add_scalars(self,
|
||||||
@ -595,9 +597,9 @@ class TensorboardVisBackend(BaseVisBackend):
|
|||||||
Args:
|
Args:
|
||||||
scalar_dict (dict): Key-value pair storing the tag and
|
scalar_dict (dict): Key-value pair storing the tag and
|
||||||
corresponding values.
|
corresponding values.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
file_path (str, optional): Useless parameter. Just for
|
file_path (str, optional): Useless parameter. Just for
|
||||||
interface unification. Default to None.
|
interface unification. Defaults to None.
|
||||||
"""
|
"""
|
||||||
assert isinstance(scalar_dict, dict)
|
assert isinstance(scalar_dict, dict)
|
||||||
assert 'step' not in scalar_dict, 'Please set it directly ' \
|
assert 'step' not in scalar_dict, 'Please set it directly ' \
|
||||||
|
@ -71,7 +71,7 @@ class Visualizer(ManagerMixin):
|
|||||||
image (np.ndarray, optional): the origin image to draw. The format
|
image (np.ndarray, optional): the origin image to draw. The format
|
||||||
should be RGB. Defaults to None.
|
should be RGB. Defaults to None.
|
||||||
vis_backends (list, optional): Visual backend config list.
|
vis_backends (list, optional): Visual backend config list.
|
||||||
Default to None.
|
Defaults to None.
|
||||||
save_dir (str, optional): Save file dir for all storage backends.
|
save_dir (str, optional): Save file dir for all storage backends.
|
||||||
If it is None, the backend storage will not save any data.
|
If it is None, the backend storage will not save any data.
|
||||||
fig_save_cfg (dict): Keyword parameters of figure for saving.
|
fig_save_cfg (dict): Keyword parameters of figure for saving.
|
||||||
@ -636,7 +636,7 @@ class Visualizer(ManagerMixin):
|
|||||||
If ``line_widths`` is single value, all the lines will
|
If ``line_widths`` is single value, all the lines will
|
||||||
have the same linewidth. Defaults to 2.
|
have the same linewidth. Defaults to 2.
|
||||||
face_colors (Union[str, tuple, List[str], List[tuple]]):
|
face_colors (Union[str, tuple, List[str], List[tuple]]):
|
||||||
The face colors. Default to None.
|
The face colors. Defaults to None.
|
||||||
alpha (Union[int, float]): The transparency of circles.
|
alpha (Union[int, float]): The transparency of circles.
|
||||||
Defaults to 0.8.
|
Defaults to 0.8.
|
||||||
"""
|
"""
|
||||||
@ -927,7 +927,7 @@ class Visualizer(ManagerMixin):
|
|||||||
featmap (torch.Tensor): The featmap to draw which format is
|
featmap (torch.Tensor): The featmap to draw which format is
|
||||||
(C, H, W).
|
(C, H, W).
|
||||||
overlaid_image (np.ndarray, optional): The overlaid image.
|
overlaid_image (np.ndarray, optional): The overlaid image.
|
||||||
Default to None.
|
Defaults to None.
|
||||||
channel_reduction (str, optional): Reduce multiple channels to a
|
channel_reduction (str, optional): Reduce multiple channels to a
|
||||||
single channel. The optional value is 'squeeze_mean'
|
single channel. The optional value is 'squeeze_mean'
|
||||||
or 'select_max'. Defaults to 'squeeze_mean'.
|
or 'select_max'. Defaults to 'squeeze_mean'.
|
||||||
@ -938,7 +938,7 @@ class Visualizer(ManagerMixin):
|
|||||||
arrangement (Tuple[int, int]): The arrangement of featmap when
|
arrangement (Tuple[int, int]): The arrangement of featmap when
|
||||||
channel_reduction is not None and topk > 0. Defaults to (4, 5).
|
channel_reduction is not None and topk > 0. Defaults to (4, 5).
|
||||||
resize_shape (tuple, optional): The shape to scale the feature map.
|
resize_shape (tuple, optional): The shape to scale the feature map.
|
||||||
Default to None.
|
Defaults to None.
|
||||||
alpha (Union[int, List[int]]): The transparency of featmap.
|
alpha (Union[int, List[int]]): The transparency of featmap.
|
||||||
Defaults to 0.5.
|
Defaults to 0.5.
|
||||||
|
|
||||||
@ -1064,8 +1064,8 @@ class Visualizer(ManagerMixin):
|
|||||||
Args:
|
Args:
|
||||||
name (str): The image identifier.
|
name (str): The image identifier.
|
||||||
image (np.ndarray, optional): The image to be saved. The format
|
image (np.ndarray, optional): The image to be saved. The format
|
||||||
should be RGB. Default to None.
|
should be RGB. Defaults to None.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
for vis_backend in self._vis_backends.values():
|
for vis_backend in self._vis_backends.values():
|
||||||
vis_backend.add_image(name, image, step) # type: ignore
|
vis_backend.add_image(name, image, step) # type: ignore
|
||||||
@ -1081,7 +1081,7 @@ class Visualizer(ManagerMixin):
|
|||||||
Args:
|
Args:
|
||||||
name (str): The scalar identifier.
|
name (str): The scalar identifier.
|
||||||
value (float, int): Value to save.
|
value (float, int): Value to save.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
"""
|
"""
|
||||||
for vis_backend in self._vis_backends.values():
|
for vis_backend in self._vis_backends.values():
|
||||||
vis_backend.add_scalar(name, value, step, **kwargs) # type: ignore
|
vis_backend.add_scalar(name, value, step, **kwargs) # type: ignore
|
||||||
@ -1097,11 +1097,11 @@ class Visualizer(ManagerMixin):
|
|||||||
Args:
|
Args:
|
||||||
scalar_dict (dict): Key-value pair storing the tag and
|
scalar_dict (dict): Key-value pair storing the tag and
|
||||||
corresponding values.
|
corresponding values.
|
||||||
step (int): Global step value to record. Default to 0.
|
step (int): Global step value to record. Defaults to 0.
|
||||||
file_path (str, optional): The scalar's data will be
|
file_path (str, optional): The scalar's data will be
|
||||||
saved to the `file_path` file at the same time
|
saved to the `file_path` file at the same time
|
||||||
if the `file_path` parameter is specified.
|
if the `file_path` parameter is specified.
|
||||||
Default to None.
|
Defaults to None.
|
||||||
"""
|
"""
|
||||||
for vis_backend in self._vis_backends.values():
|
for vis_backend in self._vis_backends.values():
|
||||||
vis_backend.add_scalars(scalar_dict, step, file_path, **kwargs)
|
vis_backend.add_scalars(scalar_dict, step, file_path, **kwargs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user