import numpy as np from yacs.config import CfgNode import torch from torch import nn from torch.optim.optimizer import Optimizer from videoanalyst.utils import Registry from .optimizer_impl.utils.lr_multiply import build as build_lr_multiplier from .optimizer_impl.utils.lr_multiply import multiply_lr # from ..scheduler.scheduler_base import SchedulerBase from .optimizer_impl.utils.lr_policy import build as build_lr_policy from .optimizer_impl.utils.lr_policy import schedule_lr TRACK_OPTIMIZERS = Registry('TRACK_OPTIMIZERS') VOS_OPTIMIZERS = Registry('VOS_OPTIMIZERS') TASK_OPTIMIZERS = dict( track=TRACK_OPTIMIZERS, vos=VOS_OPTIMIZERS, ) class OptimizerBase: __metaclass__ = ABCMeta r""" base class for Sampler. Reponsible for sampling from multiple datasets and forming training pair / sequence. Define your hyper-parameters here in your sub-class. """
# -*- coding: utf-8 -*- from abc import ABCMeta from typing import Dict import cv2 as cv import numpy as np from yacs.config import CfgNode from videoanalyst.utils import Registry TRACK_TRANSFORMERS = Registry('TRACK_TRANSFORMERS') VOS_TRANSFORMERS = Registry('VOS_TRANSFORMERS') TASK_TRANSFORMERS = dict( track=TRACK_TRANSFORMERS, vos=VOS_TRANSFORMERS, ) class TransformerBase: __metaclass__ = ABCMeta r""" base class for Sampler. Reponsible for sampling from multiple datasets and forming training pair / sequence. Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self, seed: int = 0) -> None: r"""
# -*- coding: utf-8 -* from copy import deepcopy from typing import Dict from videoanalyst.utils import Registry TRACK_MONITORS = Registry('TRACK_MONITOR') VOS_MONITORS = Registry('VOS_MONITOR') TASK_MONITORS = dict( track=TRACK_MONITORS, vos=VOS_MONITORS, ) class MonitorBase: r""" Monitor base class for engine monitoring (e.g. visualization / tensorboard / training info logging) """ # Define your default hyper-parameters here in your sub-class. default_hyper_params = dict() def __init__(self, ): self._hyper_params = deepcopy( self.default_hyper_params) # mapping-like object self._state = dict() # pipeline state def get_hps(self) -> Dict: r""" Getter function for hyper-parameters
# -*- coding: utf-8 -*- from abc import ABCMeta from typing import Dict import cv2 as cv import numpy as np from yacs.config import CfgNode from videoanalyst.utils import Registry TRACK_DATAPIPELINES = Registry('TRACK_DATAPIPELINES') VOS_DATAPIPELINES = Registry('VOS_DATAPIPELINES') TASK_DATAPIPELINES = dict( track=TRACK_DATAPIPELINES, vos=VOS_DATAPIPELINES, ) class DatapipelineBase: __metaclass__ = ABCMeta r""" base class for Sampler. Reponsible for sampling from multiple datasets and forming training pair / sequence. Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self) -> None: r""" Data pipeline
# -*- coding: utf-8 -*- from abc import ABCMeta from typing import Dict import numpy as np import torch from videoanalyst.utils import Registry TRACK_TARGETS = Registry('TRACK_TARGETS') VOS_TARGETS = Registry('VOS_TARGETS') TASK_TARGETS = dict( track=TRACK_TARGETS, vos=VOS_TARGETS, ) class TargetBase: __metaclass__ = ABCMeta r""" Target maker. Responsible for transform image (e.g. HWC -> 1CHW), generating training target, etc. Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self) -> None:
plot_LR(lr_scheduler, 'Exponential decay with warmup') See the bottom of code for more plot examples, together with some exmples for .yaml configuration files (commented part). """ import json import math from abc import ABCMeta, abstractmethod from typing import List import numpy as np from yacs.config import CfgNode from videoanalyst.utils import Registry __all__ = ["ListLR", "LinearLR", "ExponentialLR", "CosineLR"] LR_POLICIES = Registry("LR_POLICY") def build(cfg: List[str], **kwargs): r""" Build lr scheduler with configuration Arguments --------- cfg: List[str] list of JSON string containing lr scheduling **kwargs extra keyword argument that apply to all schedule Returns -------
# -*- coding: utf-8 -*- from abc import ABCMeta import cv2 as cv import numpy as np from yacs.config import CfgNode import torch from torch import nn, optim from videoanalyst.utils import Registry GRAD_MODIFIERS = Registry('GRAD_MODIFIER') class GradModifierBase: __metaclass__ = ABCMeta r""" base class for GradModifier. Reponsible for scheduling optimizer (learning rate) during training Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self, ) -> None: r""" GradModifier, reponsible for scheduling optimizer Arguments --------- cfg: CfgNode
# -*- coding: utf-8 -*- from abc import ABCMeta, abstractmethod from typing import List, Dict import cv2 as cv import numpy as np from yacs.config import CfgNode from videoanalyst.utils import Registry TRACK_CONTRIB_MODULES = Registry('TRACK_CONTRIB_MODULE') VOS_CONTRIB_MODULES = Registry('VOS_CONTRIB_MODULE') TASK_CONTRIB_MODULES = dict( track=TRACK_CONTRIB_MODULES, vos=VOS_CONTRIB_MODULES, ) class ContribModuleBase: __metaclass__ = ABCMeta r""" base class for ContribModule. Reponsible for building contrib module Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self, ) -> None: r"""
# -*- coding: utf-8 -* from videoanalyst.utils import Registry VOS_SEGMENTERS = Registry('VOS_SEGMENTERS')
# -*- coding: utf-8 -*- from abc import ABCMeta from typing import Dict import cv2 as cv import numpy as np from yacs.config import CfgNode from videoanalyst.data.dataset.dataset_base import DatasetBase from videoanalyst.utils import Registry TRACK_FILTERS = Registry('TRACK_FILTERS') VOS_FILTERS = Registry('VOS_FILTERS') TASK_FILTERS = dict( track=TRACK_FILTERS, vos=VOS_FILTERS, ) class FilterBase: __metaclass__ = ABCMeta r""" base class for Filter. Reponsible for filtering invalid sampled data (e.g. samples with extreme size / ratio) Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self) -> None:
# -*- coding: utf-8 -* from videoanalyst.utils import Registry TRACK_TASKMODELS = Registry('TRACK_TASKMODELS') VOS_TASKMODELS = Registry('VOS_TASKMODELS') TASK_TASKMODELS = dict( track=TRACK_TASKMODELS, vos=VOS_TASKMODELS, )
# -*- coding: utf-8 -* from videoanalyst.utils import Registry TRACK_HEADS = Registry('TRACK_HEADS') VOS_HEADS = Registry('VOS_HEADS')
# -*- coding: utf-8 -*- from abc import ABCMeta import cv2 as cv import numpy as np from yacs.config import CfgNode import torch from torch import nn, optim from videoanalyst.utils import Registry TRACK_GRAD_MODIFIERS = Registry('TRACK_GRAD_MODIFIER') VOS_GRAD_MODIFIERS = Registry('VOS_GRAD_MODIFIER') TASK_GRAD_MODIFIERS = dict( track=TRACK_GRAD_MODIFIERS, vos=VOS_GRAD_MODIFIERS, ) class GradModifierBase: __metaclass__ = ABCMeta r""" base class for GradModifier. Reponsible for scheduling optimizer (learning rate) during training Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self, ) -> None:
import os import os.path as osp from copy import deepcopy from typing import Dict, List, Tuple from loguru import logger import torch from torch import nn from torch.utils.data import DataLoader from videoanalyst.model.module_base import ModuleBase from videoanalyst.optim.optimizer.optimizer_base import OptimizerBase from videoanalyst.utils import Registry, ensure_dir, unwrap_model TRACK_TRAINERS = Registry('TRACK_TRAINERS') VOS_TRAINERS = Registry('VOS_TRAINERS') TASK_TRAINERS = dict( track=TRACK_TRAINERS, vos=VOS_TRAINERS, ) class TrainerBase: r""" Trainer base class (e.g. procedure defined for tracker / segmenter / etc.) Interface descriptions: """ # Define your default hyper-parameters here in your sub-class. default_hyper_params = dict(
# -*- coding: utf-8 -* from videoanalyst.utils import Registry TRACK_LOSSES = Registry('TRACK_LOSSES') VOS_LOSSES = Registry('VOS_LOSSES')
# -*- coding: utf-8 -* from videoanalyst.utils import Registry TRACK_BACKBONES = Registry('TRACK_BACKBONES') VOS_BACKBONES = Registry('VOS_BACKBONES')
# -*- coding: utf-8 -*- from typing import Dict from abc import ABCMeta import cv2 as cv import numpy as np from yacs.config import CfgNode from videoanalyst.utils import Registry TRACK_DATASETS = Registry('TRACK_DATASETS') VOS_DATASETS = Registry('VOS_DATASETS') TASK_DATASETS = dict( track=TRACK_DATASETS, vos=VOS_DATASETS, ) class DatasetBase: __metaclass__ = ABCMeta r""" base class for DataSet. Nota. for tracking dataset, we use format (x0, y0, x1, y1) Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self) -> None:
# -*- coding: utf-8 -*- from abc import ABCMeta from typing import Dict, List import cv2 as cv import numpy as np from loguru import logger from yacs.config import CfgNode from videoanalyst.utils import Registry from ..dataset.dataset_base import DatasetBase TRACK_SAMPLERS = Registry('TRACK_SAMPLERS') VOS_SAMPLERS = Registry('VOS_SAMPLERS') TASK_SAMPLERS = dict( track=TRACK_SAMPLERS, vos=VOS_SAMPLERS, ) class SamplerBase: __metaclass__ = ABCMeta r""" base class for Sampler. Reponsible for sampling from multiple datasets and forming training pair / sequence. Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict()
import numpy as np from yacs.config import CfgNode import torch from loguru import logger from torch import nn from torch.optim.optimizer import Optimizer from videoanalyst.utils import Registry from .optimizer_impl.utils.lr_multiply import build as build_lr_multiplier from .optimizer_impl.utils.lr_multiply import multiply_lr from .optimizer_impl.utils.lr_policy import build as build_lr_policy from .optimizer_impl.utils.lr_policy import schedule_lr OPTIMIZERS = Registry('OPTIMIZERS') class OptimizerBase: __metaclass__ = ABCMeta r""" base class for Sampler. Reponsible for sampling from multiple datasets and forming training pair / sequence. Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict( minibatch=1, nr_image_per_epoch=1, lr_policy=[], lr_multiplier=[], amp=False,
# -*- coding: utf-8 -* from videoanalyst.utils import Registry TRACK_PIPELINES = Registry('TRACK_PIPELINES')
# -*- coding: utf-8 -*- from abc import ABCMeta, abstractmethod from typing import List, Dict import cv2 as cv import numpy as np from yacs.config import CfgNode from videoanalyst.utils import Registry TRACK_TEMPLATE_MODULES = Registry('TRACK_TEMPLATE_MODULE') VOS_TEMPLATE_MODULES = Registry('VOS_TEMPLATE_MODULE') TASK_TEMPLATE_MODULES = dict( track=TRACK_TEMPLATE_MODULES, vos=VOS_TEMPLATE_MODULES, ) class TemplateModuleBase: __metaclass__ = ABCMeta r""" base class for TemplateModule. Reponsible for building tempalte module Define your hyper-parameters here in your sub-class. """ default_hyper_params = dict() def __init__(self, ) -> None: r"""
# -*- coding: utf-8 -* from copy import deepcopy from typing import Dict from yacs.config import CfgNode from torch import nn from videoanalyst.pipeline.pipeline_base import PipelineBase from videoanalyst.utils import Registry TRACK_TESTERS = Registry('TRACK_TESTERS') VOS_TESTERS = Registry('VOS_TESTERS') TASK_TESTERS = dict( track=TRACK_TESTERS, vos=VOS_TESTERS, ) class TesterBase: r""" Tester base class (e.g. procedure defined for tracker / segmenter / etc.) Interface descriptions: init(im, state): update(im): """ # Define your default hyper-parameters here in your sub-class. default_hyper_params = dict( exp_name="", exp_save="",
# -*- coding: utf-8 -* from videoanalyst.utils import Registry TRACK_PYRAMIDS = Registry('TRACK_PYRAMIDS') VOS_PYRAMIDS = Registry('VOS_PYRAMIDS') TASK_PYRAMIDS = dict( track=TRACK_PYRAMIDS, vos=VOS_PYRAMIDS, )