CV | VNect環境搭建

參考: VNect官方文檔
環境:windows7,CPU,anaconda3

使用python虛擬環境

創建虛擬環境

conda create -n test2002b python=3.5

test2001爲創建虛擬環境名稱,python=3.5設置虛擬環境的python版本

conda啓用虛擬環境

查看當前虛擬環境列表

conda env list

conda info -e 

激活已創建的虛擬環境

conda activate test2002b

配置pycaffe

1. 配置win下的caffe環境

官網要求:
Requirements:
Visual Studio 2013 or 2015
Technically only the VS C/C++ compiler is required (cl.exe)
CMake 3.4 or higher (Visual Studio and Ninja generators are supported)
Optional Dependencies:
Python for the pycaffe interface. Anaconda Python 2.7 or 3.5 x64 (or Miniconda)
We assume that cmake.exe and python.exe are on your PATH.

我的環境是是vs2015, CMake3.16.0,Python3.5.5(test2002b)。

根據官網給出的配置編譯步驟下載caffe包

F:\caffe> git clone https://github.com/BVLC/caffe.git

然後切換至下面的caffe路徑,檢查環境

F:\caffe> cd caffe
F:\caffe\caffe> git checkout windows

顯示如下
在這裏插入圖片描述
隨後更改配置選項

# line72
if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14 # to use VS 2015

# line74
if NOT DEFINED WITH_NINJA set WITH_NINJA=0 # not to use Ninja generator

# line76
if NOT DEFINED CPU_ONLY set CPU_ONLY=1 # to build caffe without CUDA support

# line87
if NOT DEFINED PYTHON_VERSION set PYTHON_VERSION=3 # to use python 3.5 (only 2.7 and 3.5 are supported!)

# line 99
if NOT DEFINED RUN_INSTALL set RUN_INSTALL=1 # Build the install target

在這裏插入圖片描述

F:\caffe\caffe> scripts\build_win.cmd

在這裏插入圖片描述

2. 配置pycaffe接口

方法一(官方)

根據官方文檔
在這裏插入圖片描述
首先添加通道

conda config --add channels conda-forge
conda config --add channels willyd

然後下載所需的各種庫文件

conda install --yes cmake ninja scipy protobuf==3.1.0 six scikit-image pyyaml pydotplus graphviz

最後將.\caffe\python下的caffe文件夾複製到.\anaconda\envs\test2002a\Lib\site-packages內。

方法二(備用)

查看已安裝的庫

conda list

在這裏插入圖片描述
對比pycaffe所需的庫文件列表安裝缺少的庫文件
在這裏插入圖片描述
例如

conda install Cython

完成後將.\caffe\python下的caffe文件夾複製到.\anaconda\envs\test2002a\Lib\site-packages

測試

在python內測試

import caffe

不報錯則表示成功
在這裏插入圖片描述

錯誤& 處理

prebuilt dependencies 下載失敗

prebuilt dependencies libraries_v140_x64_py35_1.1.0.tar.bz2下載過程及其不穩定,所以參考了Chris_zhangrx的博文,從其第四點附有網盤下載鏈接直接將文件夏至指定目錄C:\Users\DJINN\.caffe\dependencies\download\下。
隨後重新運行

F:\caffe\caffe> scripts\build_win.cmd

進行編譯。

缺少dependency target…

The dependency target “pycaffe” of target “pytest” does not exist !

查看已安裝的庫

conda list

查看CMakeList文件。
猜測可能是缺少numpy庫。conda install下載後(注意後面tensorflow對numpy版本要求1.18.1),重新編譯build_win.cmd

conda install numpy

安裝OpenCV,matplotlib等庫

方法一
conda install opencv
方法二

打開Anaconda Navigator,從環境中搜索需要的庫進行安裝
在這裏插入圖片描述

下載TensorFlow

anaconda search -t conda tensorflow # 查看選擇指定的版本
pip install --upgrade tensorflow==1.13.1
python -c "import tensorflow as tf; print(tf.__version__);print(tf.reduce_sum(tf.random.normal([1000, 1000])))" # 測試代碼參考官方: https://tensorflow.google.cn/install/pip?hl=zh-cn

運行成功且版本正確
在這裏插入圖片描述

錯誤& 處理

TypeError: expected bytes, Descriptor found

測試是否安裝成功

python -c "import tensorflow as tf"

報錯如下
在這裏插入圖片描述
嘗試重新安裝

pip install --upgrade tensorflow

在這裏插入圖片描述
在這裏插入圖片描述
根據提示,更新pip

python -m pip install --upgrade pip

重新下載tensorflow後仍然報錯,網上找一下

	__module__ = 'tensorflow.core.framework.resource_handle_pb2'
Type Error: expected bytes, Descriptor found

的解決方法。
根據找到的唯一符合的解決方案,懷疑是安裝了多個tensorflow導致衝突,考慮重裝python環境

conda deacivate test2001
conda remove --name test2001 --all
conda  create -n test2001b python=3.5
conda install -c anaconda tensorflow
python -c "import tensorflow as tf"

測試結果顯示成功!
在這裏插入圖片描述

ImportError: numpy.core._multiarray_umath failed to import

tensorflow:numpy版本過低 需升級

ImportError: cannot import name ‘_validate_lengths’

caffe:numpy1.18.1版本過高 需降級

配置VNect

Contact the model author to obtain the caffe data, then drop the following two files to this directory:

  1. vnect_model.caffemodel
  2. vnect_net.prototxt

Run init_weights.py in the root directroy to generate tensorflow weights.

  1. 下載VNect文件,獲取caffe data(後附網盤鏈接)
  2. 將vnect_model.caffemodel,vnect_net.prototxt放置在文件.\models\caffe_model\
  3. .\VNect-master\下運行init_weights.py文件
python init_weights.py

報錯& 處理

_pickle.PicklingError: Can’t pikle <class ‘numpy.ndarray’>: it’s not the same object as numpy.ndarray

在這裏插入圖片描述
方法一: 更新、升級pickle…
方法二(瞎蒙的)
可能出現對象命名衝突,嘗試把save_params()函數中的params變量更改爲params0
在這裏插入圖片描述
解決問題

WARNING…
...
Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
...

在這裏插入圖片描述

Incompatible types: <dtype: ‘string’> vs. object. Value is […]

在這裏插入圖片描述

Expected string passed to parameter ‘tensor_names’ of op ‘SaveV2’, got […] of type ‘list’ instead

在這裏插入圖片描述
上述問題懷疑是環境版本不完全匹配造成,考慮重建環境
在這裏插入圖片描述
在這裏插入圖片描述

測試

圖像識別

python run_pic.py
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章