Win10下安装Google Tensorflow Object Detecting API

随着Google发布的Object Detecting API再次更新,打算尝试下该物体检测API库。

1、下载

  使用git首先到github 把所有的models拖下来。

1
git clone https://github.com/tensorflow/models

2、下载protoc(下载地址)

  Windows平台,下载最下面的win32版本。

3、编译各种proto文件。

  按照官方文档:protoc object_detection/protos/*.proto --python_out=.,总是出错,提示 object_detection/protos/*.proto: No such file or directory,干脆写个批处理搞定。

1
2
3
4
set path=%path%;D:\Dev\protoc\bin
for /f %%v in ('dir object_detection\protos\*.proto /b') do (
protoc object_detection/protos/%%v --python_out=.
)
   # 4、这一步比较坑,在这里 找到了解决方法。   在site-packages添加一个路径文件,如tensorflow_model.pth,必须以pth结尾,在文件里填上模块文件所在的目录。

1
2
E:\gits\models\research
E:\gits\models\research\slim

5、测试

  按照文档说明,到这里就已经安装完成,可以运行测试了。然而,又有新情况出现:   执行python object_detection/builders/model_builder_test.py进行测试时,出现如下错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in <module>
from object_detection.builders import model_builder
File "E:\gits\models\research\object_detection\builders\model_builder.py", line 19, in <module>
from object_detection.builders import box_predictor_builder
File "E:\gits\models\research\object_detection\builders\box_predictor_builder.py", line 18, in <module>
from object_detection.core import box_predictor
File "E:\gits\models\research\object_detection\core\box_predictor.py", line 35, in <module>
slim = tf.contrib.slim
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 53, in __getattr__
module = self._load()
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 42, in _load
module = importlib.import_module(self.__name__)
File "D:\Dev\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\__init__.py", line 31, in <module>
from tensorflow.contrib import distributions
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\distributions\__init__.py", line 33, in <module>
from tensorflow.contrib.distributions.python.ops.estimator import *
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\distributions\python\ops\estimator.py", line 21, in <module>
from tensorflow.contrib.learn.python.learn.estimators.head import _compute_weighted_loss
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\__init__.py", line 92, in <module>
from tensorflow.contrib.learn.python.learn import *
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\__init__.py", line 23, in <module>
from tensorflow.contrib.learn.python.learn import *
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\__init__.py", line 25, in <module>
from tensorflow.contrib.learn.python.learn import estimators
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\__init__.py", line 297, in <module>
from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNClassifier
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\dnn.py", line 30, in <module>
from tensorflow.contrib.learn.python.learn.estimators import dnn_linear_combined
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\dnn_linear_combined.py", line 31, in <module>
from tensorflow.contrib.learn.python.learn.estimators import estimator
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py", line 49, in <module>
from tensorflow.contrib.learn.python.learn.learn_io import data_feeder
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\__init__.py", line 21, in <module>
from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_data
File "D:\Dev\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\dask_io.py", line 27, in <module>
allowed_classes = (dd.Series, dd.DataFrame)
AttributeError: module 'dask.dataframe' has no attribute 'Series'

  查了一下,安装的dask0.15.2版本,Google一下,也没发现什么有价值的,不过搜到一篇文章说pandas由于版本变换,可能会出现API接口,于是使用conda升级了一下dask,升级完成后,上述例子可以运行了。然后手痒的把所有的包都升级下conda update --all --copy -y,诡异的事情发生了,因为包的依赖关系,dask降级为0.15.2,然而,跑测试居然还是没问题。到这里,啥原因也不清楚了。最后附上测试正确的结果:

1
2
3
4
5
...........
----------------------------------------------------------------------
Ran 11 tests in 0.151s

OK

至此,安装完成,跑个例子试试看.