未采用md编辑,望见谅
目录
序言
部署
数据集制作
数据准备:VG数据集
数据转换(参考issue)
预测(还未使用模型预测,后续添加)
引用(Thx)
序言
最近正在学习图片中识别目标之间关系理解的算法,然后看到大神的一个算法(相较最新,2020年)
论文名称:Unbiased Scene Graph Generation from Biased Training
GitHub代码库:https://github.com/KaihuaTang/Scene-Graph-Benchmark.pytorch
后续的算法调研中,并没有看到更合适的开源代码了,所以先学习了一下大神的工作。 (大神Git)
部署
本人在RTX 3090上进行相关算法的部署,建议大家参考Git上的安装教程,INSTALL.md。该链接详细的介绍了该如何部署算法,我的环境是:
Python | 3.7.13(符合≤3.8) |
Pytorch | 1.9.0+cu111(不建议1.8.1,训练有BUG,issue) |
torchvision | 0.10.0+cu111 |
torchaudio | 0.9.0 |
cocoapi | 2.0 |
scipy | 1.2.1 |
gcc | 7.5 |
所以不一定要和作者一致,但是相关包的版本一定要匹配上即可,后续引发的一系列问题有可能就是安装包没有正确安装引起的,所以一定要重视安装过程。
# conda安装以下依赖
conda install ipython scipy==1.2.1 h5py pillow
pip install ninja yacs cython matplotlib tqdm opencv-python overrides
# 安装torch(这里是后续需要与我各项工作环境一致,故采用此版本,其他符合要求即可,具体如何安装,建议参考torh官网)
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
# 编译cocoapi
git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
python setup.py build_ext install
# 编译apex , 为后续采用float16做准备
git clone https://github.com/NVIDIA/apex.git
cd apex
# 如果torch <= 1.7 增加一行命令:
git reset --hard 3fe10b5597ba14a748ebb271a6ab97c09c5701ac
# 不添加 --cuda_ext --cpp_ext 参数不会轻易报错,涉及的编译很少
# 添加 --cuda_ext --cpp_ext参数后我暂时未发现错误,若不添加这个参数,则会引起
# ModuleNotFoundError: No module named 'amp_C'
# 编译时间较长,耐心等待,不添加参数也可使用,后续训练时不引入float16 或者屏蔽掉报错行即可(不建议)
# 若更换torch版本,则需要对apex和Scene-Graph重新进行编译
python setup.py install --cuda_ext --cpp_ext
# 克隆拷贝源码并编译
git clone https://github.com/KaihuaTang/Scene-Graph-Benchmark.pytorch.git
cd scene-graph-benchmark
python setup.py build develop
数据集制作
为了后续可以进行自制数据集的训练,先学习了一下VG数据集向训练时所需文件的转换过程,从而后续自标注的话可以再解析VG数据集的格式,再进一步设计自己的数据集。
数据准备:VG数据集
需要下载的内容,无需翻墙
- Download images part 1 (9.2 GB), part 2 (5.47 GB) 原始数据,两部分
- Download image meta data (17.62 MB) image_data.json
- Download objects (413.87 MB) objects.json
- Download relationships (709.58 MB) relationships.json
- Download attributes (462.56 MB) attributes.json
- Download synset name and descriptions (2.20 MB) attribute_synsets.json
数据转换(参考issue)
所需代码库:
git clone https://github.com/danfeiX/scene-graph-TF-release
cd ./scene-graph-TF-release/data_tools/VG
在/scene-graph-TF-release/data_tools/VG下需要增加的东西:
- VG
- ---images 将images和images2图片提取至images
- ------1.jpg
- ------****
- ---image_data.json
- ---objects.json
- ---relationships.json
然后运行:
# 由于bash文件中的回车存在问题,可以在ubuntu下重写bash解决,也可直接采用下列语句
python vg_to_imdb.py --imh5_dir . --image_size 1024
python vg_to_roidb.py --imdb imdb_1024.h5 --json_file ./VG-SGG-dicts.json --h5_file ./VG-SGG.h5 --load_frac 1 --num_objects 150 --num_predicates 50
在data_tools文件夹下可以获得:
imdb_1024.h5 (训练不需要该文件)
VG-SGG.h5
VG-SGG-dicts.json
第一步工作完成了,现在需要去./Scene-Graph-Benchmark.pytorch/datasets/vg文件夹下,进行下一步工作,添加attribute属性的工作,虽然开关可以关闭,但是貌似必须有这个属性在,如果有其他方法可以进行交流:
在vg文件夹下放置以下文件
VG_100K (该文件夹就是images.zip解压后的文件夹,并且将2放置其中)
image_data.json (该文件git上的不正确,需要重新下载替换掉)
VG-SGG.h5
VG-SGG-dicts.json
attributes.json
attribute_synsets.json
然后放置后,进行一定的修改,按照需求运行其中一个程序即可,两个内容一致:
- generate_attribute_labels.py
- 0.generate_attribute_labels.ipynb
如果出现 assert item['image_id'] == att_item['image_id']该行报错,则是image_data.json未匹配上,重新检查。不出意外的话,就生成了*-with-attri的文件,用于后续训练即可。
预测(还未使用模型预测,后续添加)
引用(Thx)
@misc{tang2020sggcode,
title = {A Scene Graph Generation Codebase in PyTorch},
author = {Tang, Kaihua},
year = {2020},
note = {\url{https://github.com/KaihuaTang/Scene-Graph-Benchmark.pytorch}},
}
@inproceedings{tang2018learning,
title={Learning to Compose Dynamic Tree Structures for Visual Contexts},
author={Tang, Kaihua and Zhang, Hanwang and Wu, Baoyuan and Luo, Wenhan and Liu, Wei},
booktitle= "Conference on Computer Vision and Pattern Recognition",
year={2019}
}
@inproceedings{tang2020unbiased,
title={Unbiased Scene Graph Generation from Biased Training},
author={Tang, Kaihua and Niu, Yulei and Huang, Jianqiang and Shi, Jiaxin and Zhang, Hanwang},
booktitle= "Conference on Computer Vision and Pattern Recognition",
year={2020}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)