SCOPS: Self-Supervised Co-Part Segmentation学习

论文作者博文讲解:图像分块分割

参考博文:论文学习 SCOPS: Self-Supervised Co-Part Segmentation

论文代码:https://github.com/marcelomata/SCOPS

1、问题描述

出问题

分块提供了对象的良好中间表示,该表示对于摄影机、姿势和外观变化而言是稳健的
有的分块分割方法大多采用有监督的方法,这些方法依赖于大量的人工标注,不能推广到不可见的对象类别。

本文

本文提出了一种自监督的分块分割深度学习方 法。
该方法没有使用任何监督信息,如分割任务常用的 mask 标注,而是从对模型预测的分割热图进行一系列的约束,最终实现模型的自监督学习。

SCOPS的分割模型使用的是经典的FCNDeepLab-V2 with ResNet50, 最后加channel-wise softmax layergenerate the part response maps,网络结构如下图:

2、提出方案

本文考虑了分块分割的四个理想特征
何集中: 分块在几何上集中,形成连接部件
变化的鲁棒性: 由于姿势变化以及相机和视点变化,分块段对于对象变形是鲁棒的。
义一致性: 分块段应在不同的对象实例之间具有语义一致性,并具有外观和姿势变化
象作为部件的并集: 部件出现在对象上(不是背景),部件的并集形成一个对象。
本文设计了有利于具有上述特性的分块分割的损失函数,并使用这些损失函数来训练本文的分块分割网络。
总损失函数如下:
参数论文描述: In all our experiments, the weighting coefficients (λ c ,λ eqv ,λ sc ,λ ot ) are set to (0.1,10,0.1,100 )
geometric concentration loss L c ,几何损失函数
equivariance loss L eqv,一致性损失函数
semantic consistency loss L sc,语义损失函数
•orthonomal constraint Lot ,正交约束损失函数,

2.1 几何一致性 (Geometric conentration loss)

目的是将属于同一个局部区域的像素在几何空间上集中在一起,也就是在图像中属于同一部位的像素尽量坐标尽量靠近。参考文[50]和[42]提出了一种分离(多样性)损失的形式,使不同地标之间的距离最大化。但是,本文不采用这种约束,因为这种约束会导致分离的部分段(中间有背景像素)。近似高斯分布的地标响应图[50],本文主要应用浓度损失来惩罚远离部分中心的部分响应,公式如2:

•  R ( k , u , v ) 是分割热图中第 k 部位(即第 k 通道)在 (u,v)
•     归一化
•    k 部位在 u 向的中心

理想上K值选取,过分割对本项应该有利,论文补充实验也提到 higher K the landmarks’ center are more robust to face pose variations and thus lead to lower error rate. However, the performance seems to saturate after K = 8.实验证明K也不是越大越有利,大到一定程度改进有限。如表2所示:

2.2 等变性约束(Equivariance loss)

增加模型对表观和姿态变化的鲁棒性,如图像颜色空间的变化、头部旋转等因素。随机的旋转Ts(⋅) 随机颜色干扰Ta(⋅) 每个训练图像进行变换I′ = Ts (Ta(I)) 相应的分割热图是R R ′ ,使用2.1中的方法得到部位中心坐标  和,损失函数:

表观一致性(通过 KL散度来衡量),参考博文  衡量两个概率分布之间的差异性的指标
心位置的一致性(通过二范数来实现) L2 范数通常会被用来做优化目标函数的正则化项,防止模型为了迎合训练集而过于复杂造成过拟合的情况,从而提高模型的泛化能力。

2.3语义一致性(Semantic consistency loss)

强调分为同一个部位的区域在某一个特征空间应该距离非常接近。本文设计了K 可学习的特征中心{\omega _{k}}, k=[ 1,2,. . .,K ] {\omega _{k}} globally shared across different object instances。

  • 语义一致性约束

损失函数:。如图所示,通过 VGG-19来提取特征,得到K远小于特征空间的维度C且 is the feature vector sampled at spatial location (u,v) .    

为了解k大时,学习到的分割热图可能聚于同一个特征中心,因此设计了正交约束和显著性约束

  • 正交约束

正交约束函数: 。其中 is the identity matrix of size K × K 。

is Frobenius norm。简称F-范数,是一种矩阵范,矩阵AFrobenius范数定义为矩阵A各项元素的绝对值平方的总和

  • 显著性约束

To this end, for a given image and the unsupervised saliency mapD\in [0,1]^{H*W}, we soft-mask the feature map V as D\circ V,where \circ is the Hadamard (entry-wise) product, before passing
it into the semantic consistency loss function.

3、实验

论文进行了烧蚀试验。

第2-4行显示了SCOPS与其他方法的对比结果,第5-9行显示了不同约束条件对分割结果的影响。需要注意的是,其中有一项显著性约束(saliency constraint)使用显著性标注使模型只关注感兴趣目标区域,因此这一项显著提高了各部分的分割效果。

由于SCOPS是一种非监督式学习方式,对于分割部位的数量不敏感,因此可以尝试调整不同的K值,将目标分割为实际应用中需要的分割区域个数。但是如果K值过高,分割结果的一致性可能会有所影响,如K=10时,人脸头发区域与额头区域发生一定程度的混叠;当K=4时,模型成功将人脸区域划分为头发,眼部,鼻子+嘴巴,下颌区域。

4、总结

本文提出了SCOPS,一种用于copart分割的自监督技术。给定一个对象类别的图像集合,SCOPS可以学习在不使用任何基本事实注释的情况下预测语义一致的部分分割。本文设计了一些约束条件,包括几何集中、等价性和语义一致性,以训练深层神经网络,发现语义一致的部分片段,同时确保良好的几何配置和跨实例对应。在不同类型的图像集合上的结果表明SCOPS对不同的对象外观、相机视点以及姿势关节具有鲁棒性。定性和定量分析结果表明,SCOPS方法优于现有方法。本文希望所提出的方法可以作为学习copart分割的一般框架(摘自作者博客)。

5、代码学习

环境搭配:

1、win10下安装cv2,pygame,tensorboardX

2、详解PyTorch项目使用TensorboardX进行训练可视化

3、windows如何安装wget?win10如何安装wget

4、PyTorch—torchvision.models导入预训练模型—残差网络代码讲解

5、源码需要再下个功能模块:https://github.com/WarBean/tps_stn_pytorch,利用其中的 TPSGridGen实现Thin Plate Spline (TPS)的空间变换网络 (STN)

需要进入环境 安装 pip  install absl-py

6、pip install pydensecrf报错,填坑

网上所有方法都不行 后来发现 博客 利用densecrf对分割结果进行后处理 里方法可行

pydensecrf安装
貌似直接pip安装容易报错,最好是从github上clone代码并且安装:

pip install git+https://github.com/lucasb-eyer/pydensecrf.git

7、requirements.txt

absl-py==0.9   #absl-py==0.7.0
astor==0.8.1     #astor==0.7.1
certifi==2018.11.29
chardet==3.0.4
cloudpickle==1.4.0   #cloudpickle==0.7.0
cycler==0.10.0
Cython==0.29.4
dask==1.1.1
decorator==4.3.2
dominate==2.3.5
ffnet==0.8.4
folium==0.2.1  #datascience 0.10.6 has requirement folium==0.2.1, 
gast==0.3.3   # gast==0.2.2
grpcio==1.24.3   # tensorboard 2.3.0 has requirement grpcio>=1.24.3, but you'll have grpcio 1.18.0 which is incompatible.
h5py==2.10.0    #h5py==2.9.0
hdf5storage==0.1.15
idna==2.8
imgaug==0.2.5  #albumentations 0.1.12 has requirement imgaug<0.2.7,>=0.2.5, but you'll have imgaug 0.2.9 which is incompatible.
Keras-Applications==1.0.7
Keras-Preprocessing==1.1.2   #Keras-Preprocessing==1.0.8
kiwisolver==1.0.1
Markdown==3.0.1
matplotlib==3.1.1   #matplotlib==3.0.2
networkx==2.2
#numpy==1.15.4   #兼容问题调整版本
numpy==1.18.5     #兼容问题调整版本  tensorflow2.3.1
opencv-python==4.0.0.21
Pillow==7.1.0   #Pillow==6.2.0  bokeh 2.3.2 has requirement pillow>=7.1.0
#pkg-resources==0.0.0 #google安装有误 
protobuf==3.12.0   #protobuf==3.6.1
#pydensecrf==1.0rc2  #安装有问题 替换成源码安装
git+https://github.com/lucasb-eyer/pydensecrf.git
pyparsing==2.3.1
python-dateutil==2.8.0   #python-dateutil==2.7.5
PyWavelets==1.0.1
pyzmq==17.1.2
requests==2.23.0   #requests==2.21.0
scikit-image==0.14.2
scikit-learn==0.20.2
scipy==1.2.0
six==1.15.0    #six==1.12.0
#spacepy==0.1.6   #google安装有误  #从国内镜像安装:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple spacepy==0.1.6
tensorboard==2.3.0   #tensorboard==1.12.2
tensorboardX==1.6 #google安装有误  2021.6.16 能安装 无语
#tensorflow==1.12.0 #google安装有误
tensorflow==2.3.1    #google 改成这个版本
termcolor==1.1.0
toolz==0.9.0
#torch==0.4.0 #google安装有误
#torch==0.4.1 # +
#torch==0.4.1.post2
torchfile==0.1.0
torchvision==0.2.1
tornado==5.1.1
tqdm==4.38.0    #tqdm==4.30.0
urllib3==1.24.1
visdom==0.1.8.8
websocket-client==0.54.0
Werkzeug==0.15.4   #Werkzeug==0.14.1

8、数据准备 img_celeba数据

下载参考地址:

CelebA数据集详细介绍及其属性提取源代码

利用Colab上的TPU训练Keras模型(完整版)

考虑到使用谷歌colab 每次都需要重新下载代码文件和数据,考虑将所有文件放到谷歌云盘上(云盘是真慢),不用每次都下载。

小坑有几个:

1)挂载云盘。

自行百度,涉及到权限问题,即进入云盘路径时MyDrive 中间有时有空格有时没有,右键复制路径算了。同时涉及到文件的权限 例如:

cd /content/drive/MyDrive/SCOPS/
!./download_CelebA.sh

如果成功进入路径可以执行,如果没有进入(正常),赋予权限也能执行。

!./content/drive/MyDrive/SCOPS/download_CelebA.sh
#可能提示/bin/bash: ./content/drive/MyDrive/SCOPS/download_CelebA.sh: No such file or directory 先执行下一条即可
#!chmod 755 -R /content/drive/MyDrive/SCOPS/download_CelebA.sh
#执行完成后即开始下载 CelebA 

2) img_celeba数据处理

img_celeba数据集较大,不得不考虑云盘挂载。先把 img_celeba的链接拷贝到云盘,然后拷贝进入本地文件,解压到制定目录即可:

!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.001 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.002 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.003 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.004 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.005 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.006 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.007 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.008 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.009 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.010 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.011 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.012 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.013 /content/drive/MyDrive/SCOPS/data/CelebA
!cp /content/drive/MyDrive/img_celeba.7z/img_celeba.7z.014 /content/drive/MyDrive/SCOPS/data/CelebA
#需要安装解压软件
!apt-get install p7zip-full
#解压到指定路径
!7za x /content/drive/MyDrive/SCOPS/data/CelebA/img_celeba.7z.001 -o/content/drive/MyDrive/SCOPS/data/CelebA
#过程漫长,老天保佑别断开连接

还需要修改文件:evaluate_celebAWild.sh 78行 ,给个正确的路径,验证中。

#CMD_WEB="python web_visualize.py -o $SAVE_DIR/$method/ITER_$iter/web_html -dirs ../datasets/CelebA/img_celeba $SAVE_DIR/$method/ITER_$iter/test/landmarks $SAVE_DIR/$method/ITER_$iter/test/part_overlay $SAVE_DIR/$method/ITER_$iter/test/part_dcrf_overlay $SAVE_DIR/$method/ITER_$iter/test/part_map $SAVE_DIR/$method/ITER_$iter/test/part_map_dcrf -names Img Landmarks PartoOverlay PartoOverlayDCRF PartMaps PartMapsDCRF -ref 1"
        CMD_WEB="python web_visualize.py -o $SAVE_DIR/$method/ITER_$iter/web_html -dirs ../data/CelebA/img_celeba $SAVE_DIR/$method/ITER_$iter/test/landmarks $SAVE_DIR/$method/ITER_$iter/test/part_overlay $SAVE_DIR/$method/ITER_$iter/test/part_dcrf_overlay $SAVE_DIR/$method/ITER_$iter/test/part_map $SAVE_DIR/$method/ITER_$iter/test/part_map_dcrf -names Img Landmarks PartoOverlay PartoOverlayDCRF PartMaps PartMapsDCRF -ref 1"

9、win10安装visual studio C++ build tools 提示安装包丢失或毁坏

去百度网盘下载安装即可:

链接:https://pan.baidu.com/s/1QW0b464IeOHO8MexebsO0g 
提取码:d3cm 

10、pytorch cpu与gpu load时相互转化 torch.load(map_location=)

参考博文:pytorch cpu与gpu load时相互转化 torch.load(map_location=)

model_factory.py 第45行改成:

saved_state_dict = torch.load(args.restore_from,map_location=torch.device('cpu')) #gpu ->cpu

11、错误提示(捂脸):
 

RuntimeError: [enforce fail at ..\c10\core\CPUAllocator.cpp:75] data. DefaultCPUAllocator: not enough memory: you tried to allocate 1610612736 bytes. Buy new RAM!

作者:Xiaohang Zhan,Ziwei Liu,Ping Luo,Xiaoou Tang,Chen Change Loy 摘要:Deep convolutional networks for semantic image segmentation typically require large-scale labeled data, e.g. ImageNet and MS COCO, for network pre-training. To reduce annotation efforts, self-supervised semantic segmentation is recently proposed to pre-train a network without any human-provided labels. The key of this new form of learning is to design a proxy task (e.g. image colorization), from which a discriminative loss can be formulated on unlabeled data. Many proxy tasks, however, lack the critical supervision signals that could induce discriminative representation for the target image segmentation task. Thus self-supervision's performance is still far from that of supervised pre-training. In this study, we overcome this limitation by incorporating a "mix-and-match" (M&M) tuning stage in the self-supervision pipeline. The proposed approach is readily pluggable to many self-supervision methods and does not use more annotated samples than the original process. Yet, it is capable of boosting the performance of target image segmentation task to surpass fully-supervised pre-trained counterpart. The improvement is made possible by better harnessing the limited pixel-wise annotations in the target dataset. Specifically, we first introduce the "mix" stage, which sparsely samples and mixes patches from the target set to reflect rich and diverse local patch statistics of target images. A "match" stage then forms a class-wise connected graph, which can be used to derive a strong triplet-based discriminative loss for fine-tuning the network. Our paradigm follows the standard practice in existing self-supervised studies and no extra data or label is required. With the proposed M&M approach, for the first time, a self-supervision method can achieve comparable or even better performance compared to its ImageNet pre-trained counterpart on both PASCAL VOC2012 dataset and CityScapes dataset.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值