图像标注–看图说话(Image Captioning)
这其实是机器视觉中的一个领域:图像标注
0.paper地址:
http://cs.stanford.edu/people/karpathy/densecap/
github地址:
https://github.com/jcjohnson/densecap
1.下载
git clone –recursive https://github.com/jcjohnson/densecap #代码
如果网络问题导致clone失败,可以在clone的时候选择depth=1。
2.环境依赖
安装torch环境:
http://torch.ch/docs/getting-started.html
安装其他依赖环境:
luarocks install nn
luarocks install image
luarocks install lua-cjson
luarocks install https://raw.githubusercontent.com/qassemoquab/stnbhwd/master/stnbhwd-scm-1.rockspec
luarocks install https://raw.githubusercontent.com/jcjohnson/torch-rnn/master/torch-rnn-scm-1.rockspec
luarocks install sys #需要多加一项
注意,各个步骤的安装由于是网络安装所以,可能存在由于网络原因而导致的安装失败,切记安装完check下界面是否有报错信息,如有报错,重新安装。
没有gpu 忽略
luarocks install cutorch
luarocks install cunn
luarocks install cudnn
luarocks install cudnn
如果在安装完torch之后,用luarocks 进行其他相关依赖包安装时候,报错:
如果切换到root账号之后,会提示,luarocks没有安装。。。
这些都说明torch安装过程中有些依赖没有安装成功,所以需要重新安装torch。
3.下载模型
sh scripts/download_pretrained_model.sh
这部分可能很慢:
4.修改代码
run_model.lua 代码29行自行修改Model位置
5.运行
cpu 运行
th run_model.lua -input_image imgs/mytea.jpg -gpu -1
gpu 运行
th run_model.lua -input_image imgs/mytea.jpg
6.查看效果
cd vis
python -m SimpleHTTPServer 8181
访问:http://localhost:8181/view_results.html
就可以查看结果:
这字幕加得没有那么理想,确实,可能有些人都认不出这是泡茶场景。所以,DenseCap识别为coffee等也是情有可原。可以再选择其他图像来测试。需要注意的是,图像太大会直接让内存爆掉,所以尽量根据自己的配置对图像的尺寸做出调整。