Google开源库Image Captioning部署记录
Github庫:https://github.com/tensorflow/models/tree/master/research/im2txt
場景:給一張圖片,描述圖片內(nèi)容。如下圖:
環(huán)境:ubuntu,記住用戶必須對目錄有權(quán)限。
1、下載開源包:git clone?https://github.com/tensorflow/models.git? ?
? ? ? 進(jìn)入Im2txt子項目:cd?research/im2txt
2、安裝依賴包:
First ensure that you have installed the following required packages:
- Bazel?(instructions)
- Python 2.7
- TensorFlow?1.0 or greater (instructions)
- NumPy?(instructions)
- Natural Language Toolkit (NLTK):
- First install NLTK (instructions)
- Then install the NLTK data package "punkt" (instructions)
- Unzip
1)Bazel:?我選擇Installing using binary installer方式安裝。
? ? ?參考網(wǎng)址:https://docs.bazel.build/versions/master/install-ubuntu.html
2)NLTK:sudo?pip2 install?-U?nltk
? ? ?數(shù)據(jù)包安裝:進(jìn)入python2
>>>import nltk >>> nltk.download("punkt")3、準(zhǔn)備訓(xùn)練數(shù)據(jù)
3.1??MSCOCO數(shù)據(jù)集
bazel build //im2txt:download_and_preprocess_mscoco bazel-bin/im2txt/download_and_preprocess_mscoco "im2txt/data/mscoco"準(zhǔn)備成功如下圖:
3.2 已訓(xùn)練CNN模型Inception v3 Checkpoint
wget "http://download.tensorflow.org/models/inception_v3_2016_08_28.tar.gz" tar -xvf "inception_v3_2016_08_28.tar.gz" -C im2txt/data rm "inception_v3_2016_08_28.tar.gz"4、訓(xùn)練模型
bazel build -c opt //im2txt/...nohup bazel-bin/im2txt/train \
? --input_file_pattern="im2txt/data/mscoco/train-?????-of-00256" \
? --inception_checkpoint_file="im2txt/data/inception_v3.ckpt" \
? --train_dir="im2txt/model/train" \
? --train_inception=false \
? --number_of_steps=1000000 &
evaluation script和Fine Tune the Inception v3 Model我這里沒有去運(yùn)行。有需要可參照官方介紹進(jìn)行。訓(xùn)練完成如下圖。
5、圖片生成文本
bazel build -c opt //im2txt:run_inference bazel-bin/im2txt/run_inference \--checkpoint_path=im2txt/model/train \--vocab_file=im2txt/data/mscoco/word_counts.txt \--input_files=im2txt/data/mscoco/raw-data/val2014/COCO_val2014_000000051008.jpg?結(jié)果:
Captions for image COCO_val2014_000000051008.jpg:0) a cat laying on top of a laptop computer . (p=0.010717)1) a cat laying on top of a laptop keyboard . (p=0.001352)2) a cat laying on top of a laptop on a bed . (p=0.000764)總結(jié)
以上是生活随笔為你收集整理的Google开源库Image Captioning部署记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 开源库OpenNMT-py使用记录
- 下一篇: 神经网络最优化方法比较(代码理解)