We basically categorize model components into 4 types.
- backbone: usually an FCN network to extract feature maps, e.g., ResNet, MobileNet.
- neck: the component between backbones and heads, e.g., ChannelMapper, FPN.
- head: the component for specific tasks, e.g., tracking bbox prediction.
- loss: the component in head for calculating losses, e.g., FocalLoss, L1Loss.
Here we show how to develop new components with an example of MobileNet.
Create a new file mmtrack/models/backbones/mobilenet.py.
import torch.nn as nn
from mmcv.runner import BaseModule
from mmdet.models.builder import BACKBONES
@BACKBONES.register_module()
class MobileNet(BaseModule):
def __init__(self, arg1, arg2, *args, **kwargs):
pass
def forward(self, x): # should return a tuple
passYou can either add the following line to mmtrack/models/backbones/__init__.py
from .mobilenet import MobileNetor alternatively add
custom_imports = dict(
imports=['mmtrack.models.backbones.mobilenet'],
allow_failed_imports=False)to the config file to avoid modifying the original code.
model = dict(
...
backbone=dict(
type='MobileNet',
arg1=xxx,
arg2=xxx),
...Create a new file mmtrack/models/necks/my_fpn.py.
from mmcv.runner import BaseModule
from mmdet.models.builder import NECKS
@NECKS.register_module()
class MyFPN(BaseModule):
def __init__(self, arg1, arg2, *args, **kwargs):
pass
def forward(self, inputs):
# implementation is ignored
passYou can either add the following line to mmtrack/models/necks/__init__.py,
from .my_fpn import MyFPNor alternatively add
custom_imports = dict(
imports=['mmtrack.models.necks.my_fpn.py'],
allow_failed_imports=False)to the config file and avoid modifying the original code.
neck=dict(
type='MyFPN',
arg1=xxx,
arg2=xxx),Create a new file mmtrack/models/track_heads/my_head.py.
from mmcv.runner import BaseModule
from mmdet.models import HEADS
@HEADS.register_module()
class MyHead(BaseModule):
def __init__(self, arg1, arg2, *args, **kwargs):
pass
def forward(self, inputs):
# implementation is ignored
passYou can either add the following line to mmtrack/models/track_heads/__init__.py,
from .my_head import MyHeador alternatively add
custom_imports = dict(
imports=['mmtrack.models.track_heads.my_head.py'],
allow_failed_imports=False)to the config file and avoid modifying the original code.
track_head=dict(
type='MyHead',
arg1=xxx,
arg2=xxx)Please refer to Add a new loss for developping a new loss.