Kali-Hac / Show-Attend-and-Tell-Neural-Image-Caption-Generation-with-Visual-Attention

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show, Attend and Tell

本仓库包含原论文、自己对论文的中文翻译、基于Tensorflow框架的模型实现(参考开源的基础上做了一些修改)

我对原论文的详细解析:http://yikunhaocong.com/2018/01/20/Visual-Attention/

本仓库模型算法实现细节将在不久后更新

TensorFlow implementation of Show, Attend and Tell: Neural Image Caption Generation with Visual Attention


alt text


引用

原作者 theano 代码: https://github.com/kelvinxu/arctic-captions

Tensorflow实现: https://github.com/yunjey/show-attend-and-tell


运行方法

所需配置

在同一目录下安装 pycocoevalcap

$ git clone https://github.com/yunjey/show-attend-and-tell-tensorflow.git
$ git clone https://github.com/tylin/coco-caption.git

该代码基于Python2.7,需要安装TensorFlow. 此外,还需要安装一些库来处理数据集MSCOCO data set. 可以使用./download.sh脚本来下载MSCOCO image datasetVGGNet19 model.

可能需要比较长的时间来下载数据,运行脚本后图像数据将会保存在 image/目录,VGGNet19 model将会保存在data/目录。

$ cd show-attend-and-tell-tensorflow
$ pip install -r requirements.txt
$ chmod +x ./download.sh
$ ./download.sh

为了使图像能够输入到VGGNet网络中,需要先把 MSCOCO image dataset数据集中的图像转换为224*224格式

运行下面的命令会格式化图像并保存至image/train2014_resized/image/val2014_resized/目录中

$ python resize.py

在开始训练模型前,需要先预处理MSCOCO caption dataset数据集(也就是原论文所说的把标题描述数量统一化),运行下面的命令生成标题描述数据集和对应的图片特征向量

$ python prepro.py

模型训练

运行下面指令,开始训练图片描述生成模型

$ python train.py

(可选) Tensorboard 可视化

提供了一个可视化实时运行情况的tensorboard 打开命令行,运行下面的指令并打开浏览器http://localhost:6005/窗口

$ tensorboard --logdir='./log' --port=6005 

模型评估

如果想生成描述并可视化聚焦的权重和评估模型,请使用evaluate_model.ipynb


模型结果


Training data

(1) Generated caption: A plane flying in the sky with a landing gear down.

alt text

(2) Generated caption: A giraffe and two zebra standing in the field.

alt text

Validation data

(1) Generated caption: A large elephant standing in a dry grass field.

alt text

(2) Generated caption: A baby elephant standing on top of a dirt field.

alt text

Test data

(1) Generated caption: A plane flying over a body of water.

alt text

(2) Generated caption: A zebra standing in the grass near a tree.

alt text

About


Languages

Language:Jupyter Notebook 98.5%Language:Python 1.5%Language:Shell 0.0%