MGCAM

MGCAM

论文:Mask-guided Contrastive Attention Model for Person Re-Identifification,cvpr,2018

论文链接:paper

代码:github

摘要

背景:由于不同的背景杂乱,不同的视点和身体姿势,远远没有解决。如何提取对背景杂波不变性、鲁棒性强的特征是核心问题。

贡献:本文(1)引入了二值化的行人分割轮廓图作为额外输入,并与彩色图像合并为四通道的新输入,然后设计一种基于分割轮廓的对比注意模型来学习背景无关的行人特征。(2)在此基础上,提出了一种区域级别的三元组损失函数,分别约束来自全图区域、行人身体区域、背景区域的特征,提出的损失函数可以让来自全图区域和行人身体区域的特征在特征空间靠近,并远离背景区域,最终达到去除背景的作用。

概述

二元体掩码可以在两个方面为ReID 做出贡献:

1、掩模可以帮助消除像素级的背景杂波,这可以极大地提高ReID模型在各种背景条件下的鲁棒性。

2、包含了身体的轮廓信息,该信息可以被认为含有重要的姿态信息。

但实验发现,直接使用二值掩模图遮掩的图像进行行人再识别任务,其效果反而不如采用原始图像下的效果。导致该结果的原因可能是直接使用二值遮挡图像可能会影响图像的结构信息和平滑性,另外,错误的分割图像可能包含杂乱背景或者丢失重要的信息。因此,在特征级别上进行背景的移除可能会是一个更好的选择。

网络框架

为了解决这个问题,作者利用了二值掩码来减少特征级别中的背景的噪声,并提出了一种对比注意模型(MGCAM)来从身体和背景区域对比学习特征,如下图:

img

由于基于Image-net 所训练的网络,如CaffeNet、ResNet-50等,输入图像的通道只用三个(RGB),本文中由于在RGB图像的基础上附加了一个mask通道,与上述pre-trained 的网络不兼容,因此选取了MSCAN(multi-scale context aware network)结构进行重新训练。MSCAN是一个多级的语义感知网络,他的输入也是四层,所以文章中采用了MSCAN作为基础网络。

MSCAN网络包含四个stage以及一个全连接层,本文提出的框架包括三个主要分支,full stream 学习整个图像的特征;body stream 学习body-attention map;background stream 学习background-attention map.虽然这三个stream都是学习同一张图片,但是他们是有差别的,对于background-stream,从background 学习到的特征对于ReID 这个任务来说完全没有用的,并且应该提出背景对于前景的影响。

在特征空间中,从body区域和完整图像学习的特征应该是相似的,而从背景区域和完整图像学习到的特征应该是不同的。为此,提出的MGCAM模型首先在二值掩模的指导下产生一对对比注意力图,然后将对比注意力图添加到CNN特征中以分别生成身体感知和背景感知特征。注意力机制的对比注意力子网络如虚线框内所示,在上图的stage-2将会得到大小为96×40×16图像的特征f_stage2,将该特征作为对比注意力网络的输入将会得到一对互补的attention maps, 分别对应body attention 和background attention。其中,body-aware attention map可由下式计算得到:

img

对应的,前景和背景的attention map两个操作互补,则background-aware attention map:

img

利用相应的map便可得到body-aware和background-aware的特征(运算符表示空间加权操作):

img

body attention 利用分割图进行监督学习。公式(1)中获得body-aware attention map 的卷积参数通过下式损失函数实现,其中M(i,j) 是提前获取的图像分割图像。

img

该模型中还使用了一个区域级别的三元组损失函数,目标样本的full feature,正样本是body feature ,而负样本是background feature。通过这个函数,使得body feature 提供大部分信息,并且同时减少背景对于最终结果的影响。损失函数如下(m为超参数,根据经验设为10):

img

该模型对每个部分都计算分类损失。

在MGCAM 网络训练完毕后,利用一个Siamese (孪生)网络进一步的对齐fine-tune:

img

对于两个待对比的人,我们经过MGCAM网络提取到最后的特征分别为h§和h(g),最后通过如下函数对比其相似度(m是超参数,一般为10):img

整个函数训练过程中使用的目标函数式表达为:

img

(where λ, α and β are the hypermeters, which are respectively set to 0.01, 0.01 and 0.1 in our experiments)

总结

1、为了减少带mask 的人物背景杂乱,设计了一个又二值掩码引导的对比注意模型。他可以生成一对身体感和背景感知注意力图,可用于身体部分和背景部分的区分。

2、作者进一步提出利用完整图像,身体部分和背景部分的特征进行计算三元组损失,可以强制模型学习的特征对背景杂乱不变。

3、作者探索将身体mask 作为附加输入并伴随RGB图像来增强ReID 特征学习。二值掩模有两个主要优点:1)可以帮助减少背景杂乱;(2)包含身份相关的功能,如身体形状信息。

实验

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-POoTJ49h-1606302073068)(C:\Users\Mr.fei\AppData\Roaming\Typora\typora-user-images\image-20201123201511457.png)]

MSCAN结构

img

其余几个也如此。而使用Conv1,Conv2,Conv3三重级联也就利用了不同感受野的Context-Aware信息。

/** * @internal appDemoDxChDbReset function * @endinternal * * @brief DxCh DB reset. (part of 'System reset') * * @param[in] devNum - device number * @param[in] needHwReset - indication to do HW reset * @param[in] needFullDbCleanUp - indication to do full DB reset (or skip it to minimal) * * @retval GT_OK - on success, * @retval GT_FAIL - otherwise. */ GT_STATUS appDemoDxChDbReset ( IN GT_U8 devNum, IN GT_BOOL needHwReset, IN GT_BOOL needFullDbCleanUp ) { GT_STATUS rc; /* To hold funcion return code */ static GT_CHAR devMustNotResetPort_str[100]; CPSS_PORTS_BMP_STC portBmp;/* bmp for port */ GT_U32 port;/* port iterator */ struct { GT_U32 regAddr; GT_U32 value; } regsToRestore[] = { /* Unit Default ID (UDID) Register */ { 0x00000204, 0 }, /* Window n registers (n=0..5) * Base Address, * Size, * High Address Remap, * Window Control */ { 0x020c, 0 }, { 0x0210, 0 }, { 0x23c, 0}, { 0x0254, 0 }, { 0x0214, 0 }, { 0x0218, 0 }, { 0x240, 0}, { 0x0258, 0 }, { 0x021c, 0 }, { 0x0220, 0 }, { 0x244, 0}, { 0x025c, 0 }, { 0x0224, 0 }, { 0x0228, 0 }, { 0x248, 0}, { 0x0260, 0 }, { 0x022c, 0 }, { 0x0230, 0 }, { 0x24c, 0}, { 0x0264, 0 }, { 0x0234, 0 }, { 0x0248, 0 }, { 0x250, 0}, { 0x0258, 0 }, /* address completion are used by LSP of MSYS for eth port PHY managment */ { 0x0124, 0 }, { 0x0128, 0 }, { 0x012c, 0}, { 0x0130, 0 }, { 0x0134, 0 }, { 0x0138, 0 }, { 0x013c, 0}, /* SMI Master controller configuration is used for BobK systems for MSYS eth port PHY managment */ { SMI_MNG_ADDRESS_MARK_CNS, 0 }, /* must be last before {0,0} */ { 0, 0 }/* END */ }; GT_U32 ii; GT_UINTPTR deviceBaseAddrOnPex; GT_U32 doMgDecodingRestore; CPSS_PP_INTERFACE_CHANNEL_ENT ifChannel; /* DIAG device channel access type */ GT_U32 value; GT_BOOL doByteSwap; GT_U32 supportMgWindowsRegisters = 1; GT_U32 mgOffset; GT_U32 *unitBasePtr; if(PRV_CPSS_IS_DEV_EXISTS_MAC(devNum) == 0) { return (GT_STATUS)GT_ERROR; } if (PRV_CPSS_SIP_5_CHECK_MAC(devNum)) { /* all SIP5 devices should use PEX_MBUS driver with 8 regions address completion. */ ifChannel = CPSS_CHANNEL_PEX_MBUS_E; } else { ifChannel = CPSS_CHANNEL_PEX_E; } #ifdef ASIC_SIMULATION doMgDecodingRestore = 0; if (!PRV_CPSS_SIP_5_CHECK_MAC(devNum) && !PRV_CPSS_DXCH_IS_AC3_BASED_DEVICE_MAC(devNum)) { /* the memory space was not implemented ... and not really needed */ supportMgWindowsRegisters = 0; } #else doMgDecodingRestore = 1; #endif if(PRV_CPSS_SIP_6_CHECK_MAC(devNum) || (PRV_CPSS_PP_MAC(devNum)->devFamily == CPSS_PP_FAMILY_DXCH_AC5_E)) { supportMgWindowsRegisters = 0; /* we skip the MG 'save' and 'restore' because the 'init phase' in the appDemo is calling to : extern GT_STATUS prvNoKmDrv_configure_dma_per_devNum(IN GT_U8 devNum , IN GT_U32 portGroupId); that initialize the MG[0] of the device. and the 'cpss init phase2' will copy it from MG[0] to all other MGs */ } if (PRV_CPSS_SIP_7_CHECK_MAC(devNum)) { /* NO MG unit(s) */ supportMgWindowsRegisters = 0; doMgDecodingRestore = 0; mgOffset = 0;/* not used , but for compiler warning only */ } else { unitBasePtr = NULL; rc = prvCpssDxChUnitBaseTableGet(devNum, &unitBasePtr); if ((GT_NOT_APPLICABLE_DEVICE != rc) && (rc != GT_OK)) { return rc; } mgOffset = (NULL == unitBasePtr)?0:unitBasePtr[PRV_CPSS_DXCH_UNIT_MG_E]; for(ii = 0; ii < sizeof(regsToRestore)/sizeof(regsToRestore[0]); ii++) { if(0 == regsToRestore[ii].regAddr) { break; } regsToRestore[ii].regAddr += mgOffset; } } if(needHwReset == GT_FALSE) { doMgDecodingRestore = 0; } /*osPrintf("appDemoDxChDbReset - start \n");*/ if(GT_TRUE == needFullDbCleanUp) { /* IP LPM DB Clear - main LBM DB deleted, all prefixes removed, all VR removed */ rc = prvIpLpmLibReset(); CPSS_ENABLER_DBG_TRACE_RC_MAC("prvIpLpmLibReset", rc); if (rc != GT_OK) { return rc; } #ifdef IMPL_TM if(PRV_CPSS_PP_MAC(devNum)->tmInfo.tmHandle != NULL) { /* TM DB Clear */ rc = cpssTmClose(devNum); CPSS_ENABLER_DBG_TRACE_RC_MAC("cpssTmClose", rc); if (rc != GT_OK) { return rc; } } #endif /*IMPL_TM*/ /* reset TCAM related DBs */ appDemoDxChTcamDbReset(); /* Reset FDB Manager SW Db */ rc = prvCpssDxChFdbManagerAllDbDelete(); CPSS_ENABLER_DBG_TRACE_RC_MAC("prvCpssDxChFdbManagerAllDbDelete", rc); if(rc != GT_OK) { return rc; } /* Reset Exact Match Manager SW Db */ rc = prvCpssDxChExactMatchManagerAllDbDelete(); CPSS_ENABLER_DBG_TRACE_RC_MAC("prvCpssDxChExactMatchManagerAllDbDelete", rc); if(rc != GT_OK) { return rc; } } else { BYPASS_DB_CLEANUP_MAC(prvIpLpmLibReset); BYPASS_DB_CLEANUP_MAC(cpssTmClose); BYPASS_DB_CLEANUP_MAC(appDemoDxChTcamDbReset); } if(supportMgWindowsRegisters) { /* fill-in registers restore DB by run time values */ for(ii = 0 ; regsToRestore[ii].regAddr != 0; ii++) { if(SMI_MNG_ADDRESS_MARK_CNS == regsToRestore[ii].regAddr) { if(PRV_CPSS_DXCH_PP_MAC(devNum)->hwInfo.gop_lms.notSupported == GT_TRUE) { regsToRestore[ii].regAddr = PRV_CPSS_DXCH_DEV_REGS_VER1_MAC(devNum)->GOP.SMI[0].SMIMiscConfiguration; } else { /* BC2 A0 - MSYS does not use this register. mark as last one and not used */ regsToRestore[ii].regAddr = 0; } } } } CPSS_PORTS_BMP_PORT_CLEAR_ALL_MAC(&portBmp); cpssOsBzero(devMustNotResetPort_str, sizeof(devMustNotResetPort_str)); /* power down all ports */ for(port = 0 ; port < CPSS_MAX_PORTS_NUM_CNS /*support 256 ports in bc2*/; port++) { if(prvCpssDxChPortRemotePortCheck(devNum,port)) { /* we allow remote ports ... see logic below */ } else if(GT_FALSE == appDemoDxChIsPhysicalPortHoldMac(devNum,port)) { /* skip ports without MAC */ continue; } cpssOsSprintf(devMustNotResetPort_str,"devMustNotResetPort_str_d[%d]p[%d]",devNum,port); if(appDemoStaticDbEntryGet(devMustNotResetPort_str,&value)== GT_OK) { if(value) { /* port 90 is used for MAC 62 in BobK. Power down of SERDES for this port kills OOB port. Skip this ports. */ osPrintf("appDemoDxChDbReset : SKIP reset of port [%d] because 'MUST NOT RESET' flag \n", port); continue; } } if(portMgr) { /* support port manager operation */ (void)appDemoPortInitSeqDeletePortStage(devNum, port); } else { /* set the port in bmp */ CPSS_PORTS_BMP_PORT_SET_MAC(&portBmp,port); rc = cpssDxChPortModeSpeedSet(devNum, &portBmp, GT_FALSE, /*don't care*/CPSS_PORT_INTERFACE_MODE_SGMII_E, /*don't care*/CPSS_PORT_SPEED_1000_E); if (rc != GT_OK) { /* do not break .. maybe port not exists but we not have here knowledge about it */ if(port < PRV_CPSS_PP_MAC(devNum)->numOfPorts) { /* give indication about ports that are supposed to be in 'valid range' note that for BC2 ports 60..63 could give 'false alarm' indication */ /*osPrintf("cpssDxChPortModeSpeedSet : failed on port[%d] \n", port);*/ } } } /* Remote ports are not HW reset: Restore HW defaults */ if (needHwReset && prvCpssDxChPortRemotePortCheck(devNum,port)) { cpssDxChPortForceLinkPassEnableSet(devNum,port,GT_FALSE); cpssDxChPortForceLinkDownEnableSet(devNum,port,GT_FALSE); } /* remove the port from bmp */ CPSS_PORTS_BMP_PORT_CLEAR_MAC(&portBmp,port); } if(needHwReset == GT_TRUE) { CPSS_HW_INFO_STC *hwInfoPtr; hwInfoPtr = cpssDrvHwPpHwInfoStcPtrGet(devNum, 0); if (hwInfoPtr == NULL) return GT_FAIL; deviceBaseAddrOnPex = hwInfoPtr->resource.switching.start; osPrintf("deviceBaseAddrOnPex = 0x %p \n",deviceBaseAddrOnPex); doByteSwap = GT_FALSE; if(supportMgWindowsRegisters) { /* read the registers */ for(ii = 0 ; regsToRestore[ii].regAddr != 0; ii++) { rc = prvCpssDrvHwPpReadRegister(devNum,regsToRestore[ii].regAddr,&(regsToRestore[ii].value)); CPSS_ENABLER_DBG_TRACE_RC_MAC("prvCpssDrvHwPpReadRegister", rc); if (rc != GT_OK) { return rc; } } rc = cpssDxChDiagRegRead(deviceBaseAddrOnPex, ifChannel, CPSS_DIAG_PP_REG_INTERNAL_E, mgOffset + 0x50, &value, doByteSwap); CPSS_ENABLER_DBG_TRACE_RC_MAC("cpssDxChDiagRegRead", rc); if (rc != GT_OK) { return rc; } if(value == 0xAB110000) { doByteSwap = GT_TRUE; } } } else { deviceBaseAddrOnPex = 0;/* dummy.. will not be used */ doByteSwap = GT_FALSE; /* dummy.. will not be used */ } if(appDemoDbEntryGet("mgcamEnable", &value) == GT_OK) { /* disable MGCAM before remove device */ appDemoMgCamEnableSet(devNum, GT_FALSE); } if(needHwReset == GT_TRUE) { /* logic above generates interrupts. Provide time for CPU to take care of them. */ cpssOsTimerWkAfter(100); /* do 'atomic' device remove after device reset */ rc = doAtomicDeviceResetAndRemove(devNum); CPSS_ENABLER_DBG_TRACE_RC_MAC("doAtomicDeviceResetAndRemove", rc); if (rc != GT_OK) { return rc; } } else { if(skipRemoveDeviceFromCpss_get()) { osPrintf("appDemoDxChDbReset : DO NOT 'remove device from cpss' --- SKIP the remove device operation \n"); } else { /* do device remove without device reset */ osPrintf("appDemoDxChDbReset : 'remove device from cpss' \n"); rc = cpssDxChCfgDevRemove(devNum); CPSS_ENABLER_DBG_TRACE_RC_MAC("cpssDxChCfgDevRemove", rc); if (rc != GT_OK) { return rc; } } } /* let the device minimal time for reset before we restore next registers */ osTimerWkAfter(1); if(doMgDecodingRestore && supportMgWindowsRegisters) { osPrintf("appDemoDxChDbReset : (after soft reset) restore 'MG Registers/Address Decoding' configurations \n"); rc = cpssDxChDiagRegRead(deviceBaseAddrOnPex, ifChannel, CPSS_DIAG_PP_REG_INTERNAL_E, mgOffset + 0x50, &value, doByteSwap); CPSS_ENABLER_DBG_TRACE_RC_MAC("cpssDxChDiagRegRead", rc); if (rc != GT_OK) { return rc; } /*osPrintf("cpssDxChDiagRegRead:deviceBaseAddrOnPex[0x%x] reg[0x50] with value[%d] doByteSwap[%d] \n", deviceBaseAddrOnPex,value,doByteSwap);*/ /* restore the registers of : <MG_IP> MG_IP/MG Registers/Address Decoding/Base Address %n 0x0000020C + n*8: where n (0-5) represents BA and: <MG_IP> MG_IP/MG Registers/Address Decoding/Size (S) %n 0x00000210 + n*0x8: where n (0-5) represents SR and: <MG_IP> MG_IP/MG Registers/Address Decoding/High Address Remap %n 0x0000023c + n*0x4: where n (0-5) represents HA and : <MG_IP> MG_IP/MG Registers/Address Decoding/Window Control Register%n 0x00000254 + n*4: where n (0-5) represents n */ if(supportMgWindowsRegisters) { /* write the saved registers */ /* since the device was removed from cpss ... we must use the 'diag' functions to write to the device ... */ /* restore the registers */ for(ii = 0 ; regsToRestore[ii].regAddr != 0; ii++) { rc = cpssDxChDiagRegWrite(deviceBaseAddrOnPex, ifChannel, CPSS_DIAG_PP_REG_INTERNAL_E, regsToRestore[ii].regAddr, regsToRestore[ii].value, doByteSwap); CPSS_ENABLER_DBG_TRACE_RC_MAC("cpssDxChDiagRegWrite", rc); if (rc != GT_OK) { return rc; } } } } osPrintf("appDemoDxChDbReset - ended \n"); return GT_OK; 貌似是/* do device remove without device reset */ osPrintf("appDemoDxChDbReset : 'remove device from cpss' \n"); rc = cpssDxChCfgDevRemove(devNum);这里报错,分析下原因
最新发布
10-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值