之前用Mac跑了一下im2txt
現在用ubuntu虛擬機試一下, 記錄下來
- 取代碼
git clone https://github.com/tensorflow/models.git
2.安裝環境
我的設備:ubuntu14.04+GPU
TensorFlow1.0.1
相關論文 : 《Show and Tell: Lessons learned from the 2015 MSCOCO Image Captioning Challenge》
去年9月剛開源的: github
根據GitHub的readme,先安裝相關東西
1:Bazel
根據官網
$echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
$curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
$sudo apt-get update&& sudo
apt-get install bazel
報錯:
有一些軟件包無法被安裝。如果您用的是 unstable發行版,這也許是因為系統無法達到您要求的狀態造成的。該版本中可能會有一些您需要的軟件
包尚未被創建或是它們已被從新到(Incoming)目錄移出。
下列信息可能會對解決問題有所幫助:
下列軟件包有未滿足的依賴關系:
bazel :
依賴: google-jdk 但無法安裝它
或
java8-jdk但無法安裝它或
java8-sdk但無法安裝它或
oracle-java8-installer但無法安裝它
E:
無法修正錯誤,因為您要求某些軟件包保持現狀,就是它們破壞了軟件包間的依賴關系。
試了網上的無數方法,各種換源都沒用,直到我看到官網的一行字:
If you want to use the JDK 7, please replace jdk1.8 with jdk1.7 and
if you want to install the testing version of Bazel, replace stable with testing.
應該是因為我的系統是ubuntu14.04,所以用的jdk7
$cat /etc/issue
Ubuntu 14.04.5 LTS \n \l
$ update-java-alternatives -l
#java-1.7.0-openjdk-amd641071
/usr/lib/jvm/java-1.7.0-openjdk-amd64
#繼續按照官網
$echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.7" | sudo tee /etc/apt/sources.list.d/bazel.list
$curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
$sudo apt-get update&& sudo
apt-get install bazel
$sudo apt-get upgrade bazel
$wget https://github.com/bazelbuild/bazel/releases/download/
0.5.0/bazel-0.5.0-installer-linux-x86_64.sh
$chmod +x bazel-0.5.0-installer-linux-x86_64.sh
$./bazel-0.5.0-installer-linux-x86_64.sh --user
$export PATH="$PATH:$HOME/bin"
#檢查自己是否安裝好了
root@cf644f163c6d:~# $HOME/bin/bazel version
Extracting Bazel installation...
Build label: 0.5.0
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/bu
ild/lib/bazel/BazelServer_deploy.jar
Build time: Fri May 26 12:11:50 2017 (1495800710)
Build timestamp: 1495800710
Build timestamp as int: 1495800710
繼續安裝另外兩個庫NumPy和 NLTK
2:NumPy
NumPy
安裝官方文檔
[https://www.scipy.org/install.html](https://www.scipy.org/install.html)
$python -m pip install --upgrade pip
$pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
測試:
$python
>>>import scipy
>>>import numpy
>>>scipy.test()
>>>numpy.test()
網上說也可以這么裝,不懂跟GitHub上鏈接的網址有什么不同
$sudo apt-get install Python-scipy
$sudo apt-get install python-numpy
$sudo apt-get install python-matplotlib
3:NLTK
Natural Language Toolkit (NLTK):
首先安裝NLTK
[http://www.nltk.org/install.html](http://www.nltk.org/install.html)
$sudo pip install -U nltk
$sudo pip install -U numpy
$python
>>> import nltk
繼續github的流程
# Location to save the MSCOCO data.
MSCOCO_DIR="${HOME}/im2txt/data/mscoco"
# Build the preprocessing script. 要把model改名成tensorflow-models
cd tensorflow-models/im2txt
$HOME/bin/bazel build //im2txt:dow
nload_and_preprocess_mscoco
我的輸出如下:
root@cf644f163c6d:~/tensorflow-models/im2txt# /root/bin/bazel build //im2txt:dow
nload_and_preprocess_mscoco
..................
INFO: Found 1 target...
Target //im2txt:download_and_preprocess_mscoco up-to-date:
bazel-bin/im2txt/download_and_preprocess_mscoco
INFO: Elapsed time: 5.003s, Critical Path: 0.03s
第三步比較耗時,因為有13G的文件
# Run the preprocessing script.
bazel-bin/im2txt/download_and_preprocess_mscoco "${MSCOCO_DIR}"
1.jpg