其他分享
首页 > 其他分享> > Deep Learning for Person Re-identification: A Survey and Outlook

Deep Learning for Person Re-identification: A Survey and Outlook

作者:互联网

贡献

贡献一分析

参考:

以上主要介绍了该论文对245篇顶会方法的分析,对reid领域内一些公开数据集分析。

贡献二分析

本文主要根据在fast-reid框架上测试的AGW代码效果以及对源码进行简单的分析。分析作者论文指标与代码复现指标以及代码实现上的差异等等。
代码地址:
https://github.com/JDAI-CV/fast-reid
执行代码:

cd yourPath/fast-reid/
export FASTREID_DATASETS=./datasets/market1501/
python3 tools/train_net.py --config-file ./configs/Market1501/AGW_R50.yml MODEL.DEVICE "cuda:0"

数据集详情:

subset# ids# images# cameras
query75033686
gallery751159136

结果对比

训练结果:

DatasetRank-1Rank-5Rank-10mAPmINPmetric
Market150195.2298.4099.1788.4866.1891.85

论文结果:

DatasetRank-1Rank-5Rank-10mAPmINPmetric
Market150195.1--87.865.0-

fast-reid官方训练结果:

DatasetRank-1Rank-5Rank-10mAPmINPmetric
Market150195.3--88.266.3-

AGW网络代码分析

配置文件:

这两个文件基本没什么东西,因此基本配置都使用的默认参数,默认参数:

因此一些基本配置:

根据fast-reid/fastreid/data/common.py的__ getitem __ 函数可以知道输入数据的格式:

{
	"images": img,
	"targets": pid,
    "camids": camid,
    "img_paths": img_path,
}

其中因为batch_size为64,图片彩色三通道,resize大小(256,128),所以字典的images项的值的size如下图:
在这里插入图片描述
自然:

这里打印的targets:

'targets': 
tensor([487, 487, 487, 487, 596, 596, 596, 596, 323, 323, 323, 323, 739, 739,
        739, 739, 120, 120, 120, 120, 119, 119, 119, 119, 223, 223, 223, 223,
        265, 265, 265, 265,  35,  35,  35,  35, 560, 560, 560, 560, 519, 519,
        519, 519, 230, 230, 230, 230,  29,  29,  29,  29, 324, 324, 324, 324,
         39,  39,  39,  39, 102, 102, 102, 102])

可以看到相同target有四个这是由默认参数设置的:

# Number of instance for each person
_C.DATALOADER.NUM_INSTANCE = 4

这个参数的影响在论文Bag of Tricks and A Strong Baseline for Deep Person Re-identification中末尾也有探究过。
拿到数据开始组网,在fast-reid/fastreid/engine/defaults.py中367行:

@classmethod
    def build_model(cls, cfg):
        """
        Returns:
            torch.nn.Module:
        It now calls :func:`fastreid.modeling.build_model`.
        Overwrite it if you'd like a different model.
        """
        model = build_model(cfg)
        logger = logging.getLogger(__name__)
        logger.info("Model:\n{}".format(model))
        return model

使用类方法根据配置文件组网。在build_model函数内部:

def build_model(cfg):
    """
    Build the whole model architecture, defined by ``cfg.MODEL.META_ARCHITECTURE``.
    Note that it does not load any weights from ``cfg``.
    """
    meta_arch = cfg.MODEL.META_ARCHITECTURE
    model = META_ARCH_REGISTRY.get(meta_arch)(cfg)
    model.to(torch.device(cfg.MODEL.DEVICE))
    return model

通过META_ARCH_REGISTRY注册的方法来组网,其中meta_arch为”baseline“,因此加载的是注册的Baseline模型,打印META_ARCH_REGISTRY的类的map成员如下:

{'Baseline': <class 'fastreid.modeling.meta_arch.baseline.Baseline'>, 'MGN': <class 'fastreid.modeling.meta_arch.mgn.MGN'>, 'MoCo': <class 'fastreid.modeling.meta_arch.moco.MoCo'>, 'Distiller': <class 'fastreid.modeling.meta_arch.distiller.Distiller'>}

因此实例化的是fastreid.modeling.meta_arch.baseline.Baseline,源码在:fast-reid/fastreid/modeling/meta_arch/baseline.py:

@META_ARCH_REGISTRY.register()
class Baseline(nn.Module):
    """
    Baseline architecture. Any models that contains the following two components:
    1. Per-image feature extraction (aka backbone)
    2. Per-image feature aggregation and loss computation
    """

    @configurable
    def __init__(
            self,
            *,
            backbone,
            heads,
            pixel_mean,
            pixel_std,
            loss_kwargs=None
    ):
        """
        NOTE: this interface is experimental.

        Args:
            backbone:
            heads:
            pixel_mean:
            pixel_std:
        """
        super().__init__()
        # backbone
        self.backbone = backbone

        # head
        self.heads = heads

        self.loss_kwargs = loss_kwargs

        self.register_buffer('pixel_mean', torch.Tensor(pixel_mean).view(1, -1, 1, 1), False)
        self.register_buffer('pixel_std', torch.Tensor(pixel_std).view(1, -1, 1, 1), False)

......省略

这里有点理解不了…
在这里插入图片描述
分隔符前面应该是拿到了baseline类,加上括号应该是调用类的初始化函数,但是并不是这样,他的初始化函数接受的参数是:

    def __init__(
            self,
            *,
            backbone,
            heads,
            pixel_mean,
            pixel_std,
            loss_kwargs=None
    ):

明显不匹配…然后我看到底下的from_config函数:

@classmethod
    def from_config(cls, cfg):
        backbone = build_backbone(cfg)
        heads = build_heads(cfg)
        return {
            'backbone': backbone,
            'heads': heads,
            'pixel_mean': cfg.MODEL.PIXEL_MEAN,
            'pixel_std': cfg.MODEL.PIXEL_STD,
            'loss_kwargs':
                {
                    # loss name
                    'loss_names': cfg.MODEL.LOSSES.NAME,

                    # loss hyperparameters
                    'ce': {
                        'eps': cfg.MODEL.LOSSES.CE.EPSILON,
                        'alpha': cfg.MODEL.LOSSES.CE.ALPHA,
                        'scale': cfg.MODEL.LOSSES.CE.SCALE
                    },
                    'tri': {
                        'margin': cfg.MODEL.LOSSES.TRI.MARGIN,
                        'norm_feat': cfg.MODEL.LOSSES.TRI.NORM_FEAT,
                        'hard_mining': cfg.MODEL.LOSSES.TRI.HARD_MINING,
                        'scale': cfg.MODEL.LOSSES.TRI.SCALE
                    },
                    'circle': {
                        'margin': cfg.MODEL.LOSSES.CIRCLE.MARGIN,
                        'gamma': cfg.MODEL.LOSSES.CIRCLE.GAMMA,
                        'scale': cfg.MODEL.LOSSES.CIRCLE.SCALE
                    },
                    'cosface': {
                        'margin': cfg.MODEL.LOSSES.COSFACE.MARGIN,
                        'gamma': cfg.MODEL.LOSSES.COSFACE.GAMMA,
                        'scale': cfg.MODEL.LOSSES.COSFACE.SCALE
                    }
                }
        }

他接受的格式确实只有一个cfg参数,然后我测试了下代码执行顺序…:
在这里插入图片描述
打印结果先打印的”第一“,再打印的”第二“,说明代码确实是先执行的from_config函数再执行的__ init __函数。这里就有点理解不了了…感觉和这个@configurable装饰器有关,后续再看看这个装饰器的用处…

10点下班了…

未完待续…

标签:Outlook,cfg,LOSSES,Deep,pixel,reid,Re,MODEL,model
来源: https://blog.csdn.net/qq_37668436/article/details/117929481