MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度技术分析:“ltguo19/VSUA-Captioning” 项目

项目背景与痛点

“ltguo19/VSUA-Captioning” 是 GitHub 上用于实现图像描述生成的项目,其背后的研究论文在 ACM MM 2019 上发表。该项目的核心在于将语言词语与图像中的视觉语义单元对齐,以自动生成描述图像内容的自然语言文本。这种对齐技术为图像与语言之间的理解提供了新的视角,解决了图像描述生成中词语与图像内容语义不一致的痛点。

在过去的图像描述生成方法中,很多模型容易产生与图像不符或逻辑错误的描述,这降低了生成描述的准确性和自然度。而该方法通过在模型中引入语言词语与视觉语义单元之间的一致性约束,能够显著改善这些问题,提高图像描述生成的质量。

核心技术揭秘

项目的核心在于模型设计和训练策略。模型通过引入一个多层Transformer网络,能够对图像特征与句子进行编码,并促进两者之间的语义对齐。这样做不仅加强了模型对图像特征的理解,还提升了生成文本的描述准确性。

技术架构分析

我们用Mermaid绘制项目的主要技术架构,具体如下:

graph TD A[图像输入] --> B[图像特征提取] B --> C{"语义对齐检查"} C -->|"对齐失败"| D[调整模型参数] C -->|"对齐成功"| E[词汇生成] E --> F[描述文本输出]

该架构图清晰地阐述了项目中的关键步骤。图像输入首先被送入图像特征提取模块,生成的图像特征随后进入语义对齐模块进行检查。如果对齐不成功,模型会在调整参数后再次尝试;当对齐成功后,最终生成描述文本。

功能亮点与差异

与同类项目相比,“ltguo19/VSUA-Captioning” 的关键差异和技术特色在于其引入的语义对齐策略,这一点在图像描述生成的过程中扮演着重要角色。通过这种方法,该模型达到了更高的准确度,并且能够生成更为自然流畅的描述文本。此外,模型的模块化设计便于扩展与调优,适应不同的图像描述需求。

应用场景与落地建议

该模型非常适合需要高质量图像描述生成的场景,如电子商务产品描述生成、视觉辅助设备、自动驾驶系统等。在生产环境中部署时,开发者应注意以下几点:

  • 资源占用:图像特征提取和语义对齐模块的计算成本较高,因此,在没有高性能硬件支持的情况下,需要优化模型架构以减少计算资源消耗。
  • 多样化数据支持:由于模型的泛化能力依赖于训练数据的多样性和质量,开发者在生产环境应用前,应确保模型训练集的丰富性,并根据具体业务需求进行微调。

综合评价

“ltguo19/VSUA-Captioning” 在图像描述生成领域展现出强大的突破性,相较于同类解决方案,展现出了更高的准确度和生成文本的自然度。然而,该模型的高性能计算需求和对数据的要求也意味着它在许多场景中需要更多的准备和优化。总体来说,对于追求高质量图像描述生成结果的应用场景,这是一个强有力的选择。

关于

GitHub 原始描述(英文)

Code for "Aligning Linguistic Words and Visual Semantic Units for Image Captioning", ACM MM 2019

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
313
价值分
161
活跃状态
活跃

语言占比

Python
Shell

贡献者

README

Aligning Linguistic Words and Visual Semantic Units for Image Captioning

Introduction

VSUA model represents images as structured graphs where nodes are the so-called Visual Semantic Units (VSUs): object, attribute, and relationship units. Our VSUA model makes use of the alignment nature between caption words and VSUs.

Citation

If you find this code useful in your research then please cite

@inproceedings{guo2019vsua,
 title={Aligning Linguistic Words and Visual Semantic Units for Image Captioning},
 author={Longteng Guo, Jing Liu, Jinhui Tang, Jiangwei Li, Wei Luo, and Hanqing Lu},
 booktitle={ACM MM},
 year={2019}}

Requirements

  • Cuda-enabled GPU
  • Python 2.7, and PyTorch >= 0.4
  • Cider (already been added as a submodule)
  • Optionally:
    • coco-caption (already been added as a submodule): If you’d like to evaluate BLEU/METEOR/CIDEr scores
    • tensorboardX: If you want to visualize the loss histories (needs to install TensorFlow).

To install all submodules: git clone --recursive https://github.com/ltguo19/VSUA-Captioning.git

Prepare Data

For more details and other dataset, see ruotianluo/self-critical.pytorch

1. Download COCO captions and preprocess them

Download preprocessed coco captions from link from Karpathy’s homepage. Extract dataset_coco.json from the zip file and copy it into data/. This file provides preprocessed captions and also standard train-val-test splits.

Then do:

$ python scripts/prepro_labels.py --input_json data/dataset_coco.json --output_json data/cocotalk.json --output_h5 data/cocotalk

prepro_labels.py will map all words that occur <= 5 times to a special UNK token, and create a vocabulary for all the remaining words. The image information and vocabulary are dumped into data/cocotalk.json and discretized caption data are dumped into data/cocotalk_label.h5.

2. Download Bottom-Up features

We use the pre-extracted bottom-up image features. Download pre-extracted feature from link (we use the adaptive one in our experiments). For example:

mkdir data/bu_data; cd data/bu_data
wget https://storage.googleapis.com/bottom-up-attention/trainval.zip
unzip trainval.zip

Then:

python script/make_bu_data.py --output_dir data/cocobu

This will create data/cocobu_fc, data/cocobu_att and data/cocobu_box.

3. Download image scene graph data

We use the scene graph data from yangxuntu/SGAE. Download the files coco_img_sg.zip and coco_pred_sg_rela.npy from this link and put them into the folder data and then unzip them. coco_img_sg.zip contains scene graph data for each image, including object labels and attributes labels for each box in the adaptive bottom-up data, and the semantic relationship labels between boxes. coco_pred_sg_rela.npy contains the vocabularies for the object, attribute and relation labels.

4. Extract geometry relationship data

Download the files vsua_box_info.pkl from this link, which contains the size of each box and the width/height of each image. Then do:

python scripts/cal_geometry_feats.py
python scripts/build_geometry_graph.py

to extract the geometry relation features and build the geometry graph. This will createdata/geometry_feats-undirected.pkl and data/geometry-iou0.2-dist0.5-undirected.

Overall, the data folder should contain these files/folders:

cocotalk.json         	# additional information about images and vocab
cocotalk_label.h5       # captions
coco-train-idxs.p       # cached token file for cider
cocobu_att              # bottom-up feature
cocobu_fc               # bottom-up average feature
coco_img_sg             # scene graph data
coco_pred_sg_rela.npy   # scene graph vocabularies
vsua_box_info.pkl       # boxes and width and height of images
geometry-iou0.2-dist0.5-undirected  # geometry graph data

Training

1. Cross-entropy loss

python train.py --gpus 0 --id experiment-xe --geometry_relation True

The train script will dump checkpoints into the folder specified by --checkpoint_root and --id.

2. Reinforcement learning with CIDEr reward

python train.py --gpus 0 --id experiment-rl --geometry_relation True --learning_rate 5e-5 --resume_from experiment-xe --resume_from_best True --self_critical_after 0 --max_epochs 50
  • --gpu specifies the GPU used to run the model. --id is the name of this experiment and all information and checkpoints will be dumped to checkpoint_root/id folder.
  • --geometry_relation specifies the type of relationship to use. True: use geometry relationship, False: use semantic relationship.
  • To resume training, you can specify --resume_from option to be the experiment id you want to resume from, and use --resume_from_best to choose whether to resume from the best-performing checkpoint or the latest checkpoint.
  • If you have TensorFlow, the loss histories are automatically dumped into checkpoint_root/id, and can be visualized using tensorboard by sh script/tensorboard.sh.
  • If you’d like to evaluate BLEU/METEOR/CIDEr scores during training in addition to validation cross-entropy loss, use --language_eval 1 option, but don’t forget to download the coco-caption code into coco-caption directory.
  • For more options, see opts.py. And see self-critical.pytorch for more training guidance.

Acknowledgement

This code is modified from Ruotian Luo’s brilliant image captioning repo ruotianluo/self-critical.pytorch. We use the visual features provided by Bottom-Up peteanderson80/bottom-up-attention, and the scene graph data provided by yangxuntu/SGAE. Thanks for their works! If you find this code helpful, please consider citing their corresponding papers and our paper.

评论

暂无评论