1.方法简介
基于GTA5渲染人员密集的场景,从游戏数据中获取标注组成GTA5 Crowd Counting (GCC) Dataset。数据集使用方式有两种:(1)算法再GCC 中先训练再在真实数据集中微调;(2)基于域适应的方法
2.数据采集
2.1 主要步骤
1.场景选择。选择100个典型场所,每个场所四个摄像头,总共400种场景。
2.人物模型。265个人物模型。
3.场景合成。GTA5限制每个画面最多256个人。同一场景下多个人物非重叠画面合成。
2.2 流程
(a)选择场景和摄像头位置
(b)划出roi区域(指要在场景中哪里放置人物)
(c)设置天气和时间
(d)放置行人
(1)在roi区域中放置人物模型获取他的头部位置
(2)从stencil 获取 人的mask
(3)合并多个同场景的图像
(4)删除遮挡的头
2.3 采集结果
总共15212张图像,分辨率为1080
×
\times
× 1920 ,7625843个人物标注。
场景分布
时间段和天气分布
3. GCC上监督训练
两种实验(1)所有算法都在GCC上训练测试(2)在GCC上训练完成后然后在真实数据中微调。
4. 域适应方法利用GCC
这样去除人工标注的工作,将GCC Dataset 转换为接近真实的数据。domain gap。基于GAN 提出SSIM Embedding (SE) Cycle GAN。浅绿色是cycle gan 结构,橘色是密度估计模型。
S:合成的数据域,包含图像和标签
I
S
,
L
s
{I_S,L_s}
IS,Ls
R:真实的数据域,仅包含图像
有两个风格转换器,
G
S
→
R
,
G
S
←
R
G_{S\rightarrow R},G_{S\leftarrow R}
GS→R,GS←R,两种风格互相变换后
i
S
→
G
S
→
R
(
i
S
)
→
G
R
→
S
(
G
S
→
R
(
i
S
)
)
≈
i
S
\mathrm{i}_{\mathcal{S}} \rightarrow G_{\mathcal{S} \rightarrow \mathcal{R}}\left(\mathrm{i}_{\mathcal{S}}\right) \rightarrow G_{\mathcal{R} \rightarrow \mathcal{S}}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}\left(\mathrm{i}_{\mathcal{S}}\right)\right) \approx \mathrm{i}_{\mathcal{S}}
iS→GS→R(iS)→GR→S(GS→R(iS))≈iS的一致性损失为:
L
cycle
(
G
S
→
R
,
G
R
→
S
,
S
,
R
)
=
E
i
S
∼
I
S
[
∥
G
R
→
S
(
G
S
→
R
(
i
S
)
)
−
i
S
∥
1
]
+
E
i
R
∼
I
R
[
∥
G
S
→
R
(
G
R
→
S
(
i
R
)
)
−
i
R
∥
1
\begin{aligned} \mathcal{L}_{\text {cycle }}(& \left.G_{\mathcal{S} \rightarrow \mathcal{R}}, G_{\mathcal{R} \rightarrow \mathcal{S}}, \mathcal{S}, \mathcal{R}\right) \\ &=\mathbb{E}_{i_{S} \sim I_{\mathcal{S}}}\left[\left\|G_{\mathcal{R} \rightarrow \mathcal{S}}\left(G_{\mathcal{S} \rightarrow R}\left(i_{\mathcal{S}}\right)\right)-i_{\mathcal{S}}\right\|_{1}\right] \\ &+\mathbb{E}_{i_{\mathcal{R}} \sim I_{\mathcal{R}}}\left[\left\|G_{\mathcal{S} \rightarrow \mathcal{R}}\left(G_{\mathcal{R} \rightarrow S}\left(i_{\mathcal{R}}\right)\right)-i_{\mathcal{R}}\right\|_{1}\right.\end{aligned}
Lcycle (GS→R,GR→S,S,R)=EiS∼IS[∥GR→S(GS→R(iS))−iS∥1]+EiR∼IR[∥GS→R(GR→S(iR))−iR∥1
一对生成器和差别器的对抗损失为:
L
GAN
(
G
S
→
R
,
D
R
,
S
,
R
)
=
E
i
R
∼
I
R
[
log
(
D
R
(
i
R
)
]
+
E
i
S
∼
I
S
[
log
(
1
−
D
R
(
G
S
→
R
(
i
S
)
)
]
\begin{aligned} \mathcal{L}_{\text {GAN }}(& \left.G_{\mathcal{S} \rightarrow \mathcal{R}}, D_{\mathcal{R}}, \mathcal{S}, \mathcal{R}\right) \\ &=\mathbb{E}_{i_{\mathcal{R} \sim I_{\mathcal{R}}}}\left[\log \left(D_{\mathcal{R}}\left(i_{\mathcal{R}}\right)\right]\right.\\ &+\mathbb{E}_{i_{\mathcal{S}} \sim I_{\mathcal{S}}}\left[\log \left(1-D_{\mathcal{R}}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}\left(i_{\mathcal{S}}\right)\right)\right]\right.\end{aligned}
LGAN (GS→R,DR,S,R)=EiR∼IR[log(DR(iR)]+EiS∼IS[log(1−DR(GS→R(iS))]
整个cycle gan的损失为:
L
CycleGAN
(
G
S
→
R
,
G
R
→
S
,
D
R
,
D
S
,
S
,
R
)
=
L
G
A
N
(
G
S
→
R
,
D
R
,
S
,
R
)
+
L
G
A
N
(
G
R
→
S
,
D
S
,
S
,
R
)
+
λ
L
cycle
(
G
S
→
R
,
G
R
→
S
,
S
,
R
)
\begin{aligned} \mathcal{L}_{\text {CycleGAN }}(& \left.G_{\mathcal{S} \rightarrow \mathcal{R}}, G_{\mathcal{R} \rightarrow \mathcal{S}}, D_{\mathcal{R}}, D_{\mathcal{S}}, \mathcal{S}, \mathcal{R}\right) \\ &=\mathcal{L}_{G A N}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}, D_{\mathcal{R}}, \mathcal{S}, \mathcal{R}\right) \\ &+\mathcal{L}_{G A N}\left(G_{\mathcal{R} \rightarrow \mathcal{S}}, D_{\mathcal{S}}, \mathcal{S}, \mathcal{R}\right) \\ &+\lambda \mathcal{L}_{\text {cycle }}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}, G_{\mathcal{R} \rightarrow \mathcal{S}}, \mathcal{S}, \mathcal{R}\right) \end{aligned}
LCycleGAN (GS→R,GR→S,DR,DS,S,R)=LGAN(GS→R,DR,S,R)+LGAN(GR→S,DS,S,R)+λLcycle (GS→R,GR→S,S,R)
作者额外引入ssim 损失
L
SEcycle
(
G
S
→
R
,
G
R
→
S
,
S
,
R
)
\mathcal{L}_{\text {SEcycle }}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}, G_{\mathcal{R} \rightarrow \mathcal{S}}, \mathcal{S}, \mathcal{R}\right)
LSEcycle (GS→R,GR→S,S,R)
=
E
i
S
∼
I
S
[
1
−
S
S
I
M
(
i
S
,
G
R
→
S
(
G
S
→
R
(
i
S
)
)
)
]
=\mathbb{E}_{i_{\mathcal{S}} \sim I_{\mathcal{S}}}\left[1-S S I M\left(i_{\mathcal{S}}, G_{\mathcal{R} \rightarrow \mathcal{S}}\left(G_{\mathcal{S} \rightarrow R}\left(i_{\mathcal{S}}\right)\right)\right)\right]
=EiS∼IS[1−SSIM(iS,GR→S(GS→R(iS)))]
+
E
i
R
∼
I
R
[
1
−
S
SIM
(
i
R
,
G
S
→
R
(
G
R
→
S
(
i
R
)
)
)
]
+\mathbb{E}_{i_{\mathcal{R}} \sim I_{\mathcal{R}}}\left[1-S \operatorname{SIM}\left(i_{\mathcal{R}}, G_{\mathcal{S} \rightarrow \mathcal{R}}\left(G_{\mathcal{R} \rightarrow S}\left(i_{\mathcal{R}}\right)\right)\right)\right]
+EiR∼IR[1−SSIM(iR,GS→R(GR→S(iR)))]
L
ours
(
G
S
→
R
,
G
R
→
S
,
D
R
,
D
S
,
S
,
R
)
\mathcal{L}_{\text {ours }}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}, G_{\mathcal{R} \rightarrow \mathcal{S}}, D_{\mathcal{R}}, D_{\mathcal{S}}, \mathcal{S}, \mathcal{R}\right)
Lours (GS→R,GR→S,DR,DS,S,R)
=
L
G
A
N
(
G
S
→
R
,
D
R
,
S
,
R
)
=\mathcal{L}_{G A N}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}, D_{\mathcal{R}}, \mathcal{S}, \mathcal{R}\right)
=LGAN(GS→R,DR,S,R)
+
L
G
A
N
(
G
R
→
S
,
D
S
,
S
,
R
)
+\mathcal{L}_{G A N}\left(G_{\mathcal{R} \rightarrow \mathcal{S}}, D_{\mathcal{S}}, \mathcal{S}, \mathcal{R}\right)
+LGAN(GR→S,DS,S,R)
+
λ
L
cycle
(
G
S
→
R
,
G
R
→
S
,
S
,
R
)
+\lambda \mathcal{L}_{\text {cycle }}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}, G_{\mathcal{R} \rightarrow \mathcal{S}}, \mathcal{S}, \mathcal{R}\right)
+λLcycle (GS→R,GR→S,S,R)
+
μ
L
S
E
cycle
(
G
S
→
R
,
G
R
→
S
,
S
,
R
)
+\mu \mathcal{L}_{S E \text { cycle }}\left(G_{\mathcal{S} \rightarrow \mathcal{R}}, G_{\mathcal{R} \rightarrow \mathcal{S}}, \mathcal{S}, \mathcal{R}\right)
+μLSE cycle (GS→R,GR→S,S,R)
ssim 评估两张图片结构相似性,越相似越接近1。
Gan网络训练完成后将数据集进行转换。
5. GCC工具调试
项目编译
可以直接下载已编译好的文件,从第4步开始。
1.下载,用VS打开GCC-Collector/GCC-Collector.sln文件。
2.使用Nuget 安装minhook、eigen。工具->Nuget包管理器->程序包管理器控制台。命令
Install-Package minhook eigen
3.解决方案配置为"release",“x64”,ctrl + shift + B生成项目,如果没有错误 /GCC-CL/GCC-Collector/x64/Release下会生成文件GCC-Collector.asi 。但是报错,如图5.2。解决办法是右键项目-属性-常规-目标平台版本-选择一个已安装的sdk。
图5.1
图5.2
报错:LINK : fatal error LNK1158: 无法运行“rc.exe” 。缺少rc.exe程序
参考:https://blog.csdn.net/qq_29969029/article/details/105879495
安装
4. 下载GTA V,ScriptHookV,将ScriptHookV.dll, dinput8.dll , SceneDirectorAnim.txt 和生成的 GCC-Collector.asi,unlimitedLife.asi, noVehicle.asi文件放至游戏根目录(GTA.exe文件所在目录)。
5. 使用mod:No Chromatic aberration & Lens distortion。需要先安装 openIV,使用说明,打开openIV设置游戏目录,设置后结果如图5.3。解压后将xml文件放至Grand Theft Auto V \ mods \ update 目录
图5.3
6.游戏根目录中创建data文件夹,运行游戏。参考readme-how to work 部分。
7.设置好地点后每个会生成4个目录对应四个摄像头,如图5.4。运行Python文件生成数据集,样例如图5.5。
图5.4
图5.5
整体操作流程需要手工选择地点和拍摄角度(熟悉游戏可以直接配置文件),gcc-collector生成原始数据时每次只能生成一个目录(一个地点的一个角度)下的数据,然后游戏就自动退出了,暂不清楚是否为其它原因。另外,会产生明显没用的图像,如图5.6中的天空图像。
图5.6