Tensorflow object detection API ——環境搭建與測試

一、開發環境搭建python

①、安裝Anacondagit

  建議選擇 Anaconda3-5.0.1 版本,已經集成大多數庫,並將其做爲默認python版本(3.6.3),配置好環境變量(Anaconda安裝則已經配好)。也能夠直接安裝python,安裝各類包比較麻煩,所以直接裝了Anaconda集成環境。github

  安裝完Anaconda後,打開Anaconda Prompt,逐個輸入conda --version和python --version,出現下圖所示內容則安裝成功。windows

 

②、安裝TensorFlow工具

  若是是初學者,咱們安裝cpu版本的tensorflow足夠使用。安裝TensorFlow-cpu很簡單,打開Anaconda Prompt,輸入pip install tensorflow。稍等一會就安裝成功。經過輸入如下代碼,檢測是否安裝成功。測試

pythonthis

import tensorflow as tfgoogle

 hello = tf.constant('Hello, TensorFlow!')spa

 sess = tf.Session()blog

 print(sess.run(hello))

  若是輸出以下圖所示,則安裝成功。

 

若是輸入import tensorflow as tf出現以下警告:

  FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.from ._conv import register_converters as _register_converters。則須要打開Anaconda Prompt,輸入pip install h5py==2.8.0rc1解決。

若是輸入 sess = tf.Session()出現Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2,則代表TensorFlow版本過低了,須要打開Anaconda Prompt,輸入pip install --upgrade tensorflow解決。

③、下載Tensorflow object detection API模型,從https://github.com/tensorflow/models下載。解壓文件到磁盤指定目錄,例如C:\Users\CFF\Desktop,重命名爲models(此包內包括各類內容,咱們所用到的object_detection文件夾在C:\Users\CFF\Desktop\models\research文件夾下)

④、Protobuf 編譯。從https://github.com/google/protobuf/releases下載windows版的工具,如protoc-3.6.1-win32.zip,解壓到C:\Users\CFF\Desktop,生成:bin, include兩個文件夾。打開Anaconda Prompt,cd C:\Users\CFF\Desktop\models\research ,輸入C:\Users\CFF\Desktop\bin\protoc ,編譯結果以下說明能夠開始編譯。

 

Protobuf 編譯,用protoc可執行文件編譯目錄object_detection/protos下的proto文件,生成Python文件。如:C:\Users\CFF\Desktop\bin\protoc object_detection/protos/*.proto --python_out=.。如何出現object_detection/protos/*.proto目錄沒有發現,能夠將*號改爲對應的文件逐個編譯,生成對應的Python文件。 

⑤、測試。打開Anaconda Prompt,cd C:\Users\CFF\Desktop\models\research目錄,輸入jupyter notebook,跳轉到網頁界面。

在cell中選擇runAll,正常的話稍等一下子就會有結果:

到此,已經成功完成了環境搭建與測試。

⑥、用來測試本身的圖片,改變PATH_TO_TEST_IMAGES_DIR 的路徑,個人以下所示。測試圖片命名爲image1.jpg   image2.jpg... 相應的數量for i in range(1, 3)也要根據本身的圖片數量進行改變。

運行後,輸出結果以下:

 

相關文章
相關標籤/搜索