Win10+tensorfow调用object_detection API

一、object_detection环境初步测试
参考:https://blog.csdn.net/zlase/article/details/78734138
https://blog.csdn.net/zhaoyoulin2016/article/details/80615687
Part 1.配置运行环境
Windows10系统+Anaconda 3.5
在anaconda创建python3.5的环境
1.1 通过anaconda 安装tensorflow 命令为conda install tensorflow-gpu-1.10.0会自动配置CUDA和cuDNN对应版本。
1.2如果安装最新tensorflow-gpu版本则需要配置相应版本的CUDA和cuDNN,https://www.tensorflow.org/install/source#tested_build_configurations中显示了哪个版本的TensorFlow需要哪个版本的CUDA和cuDNN。
1.3 test gpu是否工作
代码:
import tensorflow as tf
import numpy as np
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name=‘a’)
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name=‘b’)
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run©)
成功截图:
在这里插入图片描述
Part 2:安装object_detection API
2.1.配置好TensorFlow

2.2.下载好TensorFlow模型源码:https://github.com/tensorflow/models
E盘文件夹下存放,research文件夹下为各个模块接口。之后在环境变量中增加三条变量:
E:\TensorFlow \models
E:\TensorFlow \models \research
E:\TensorFlow \models \research\slim
Part3:安装其他依赖的包
(tensorflow) C:> pip install pillow
(tensorflow) C:> pip install lxml
(tensorflow) C:> pip install Cython
(tensorflow) C:> pip install contextlib2
(tensorflow) C:> pip install jupyter
(tensorflow) C:> pip install matplotlib
(tensorflow) C:> pip install pandas
(tensorflow) C:> pip install opencv-python

Part4:下载Protobuf

4.1下载地址:https://github.com/google/protobuf/releases

4.2选择 protoc-3.4.0-win32.zip 版本进行下载。(python3.5+ protoc-3.4.0-win32.zip测试成功)
解压后在bin文件夹中可以找到一个: protoc.exe
将这个文件夹加入到环境变量中:F:\TensorFlow \bin
之后在CMD(管理员)中通过cd找到这个文件夹,运行一下 protoc.exe ,但是会报错说需要输入文件。
退出这个文件夹,cd找到models中的research目录下,执行:
然后将以下命令复制并粘贴到命令行中,然后按Enter键:
protoc --python_out=. .\object_detection\protos\anchor_generator.proto .\object_detection\protos\argmax_matcher.proto .\object_detection\protos\bipartite_matcher.proto .\object_detection\protos\box_coder.proto .\object_detection\protos\box_predictor.proto .\object_detection\protos\eval.proto .\object_detection\protos\faster_rcnn.proto .\object_detection\protos\faster_rcnn_box_coder.proto .\object_detection\protos\grid_anchor_generator.proto .\object_detection\protos\hyperparams.proto .\object_detection\protos\image_resizer.proto .\object_detection\protos\input_reader.proto .\object_detection\protos\losses.proto .\object_detection\protos\matcher.proto .\object_detection\protos\mean_stddev_box_coder.proto .\object_detection\protos\model.proto .\object_detection\protos\optimizer.proto .\object_detection\protos\pipeline.proto .\object_detection\protos\post_processing.proto .\object_detection\protos\preprocessor.proto .\object_detection\protos\region_similarity_calculator.proto .\object_detection\protos\square_box_coder.proto .\object_detection\protos\ssd.proto .\object_detection\protos\ssd_anchor_generator.proto .\object_detection\protos\string_int_label_map.proto .\object_detection\protos\train.proto .\object_detection\protos\keypoint_box_coder.proto .\object_detection\protos\multiscale_anchor_generator.proto .\object_detection\protos\graph_rewriter.proto .\object_detection\protos\calibration.proto .\object_detection\protos\flexible_grid_anchor_generator.proto

成功截图:

在这里插入图片描述
这将从\object_detection\protos文件夹中的每个name.proto文件创建一个name_pb2.py文件。

4.3测试:输入python object_detection/builders/model_builder_test.py
注意:如果出现 ImportError: No module named ‘object_detection’ 这种问题
在这里插入图片描述
1)在你的Anaconda3安装路径 /Anaconda3/Lib/site-packages 下新建一个 tensorflow_model.pth 文件
(我这里的安装路径是C:\ProgramData\Anaconda3\Lib\site
2)在新建的 tensorflow_model.pth 文件中写入以下的路径:
D:\tensorflow\models\research
D:\tensorflow\models\research\slim
OK: Succeed
在这里插入图片描述

Part 5:例程测试API object_detection_tutorial.ipynb
在CMD中找到models-master文件夹下,路径为:E:\TensorFlow \models
在该文件夹下输入: jupyter-notebook
来调用jupyter-notebook环境,之后会在浏览器中出现
在这里插入图片描述
顺着research\object_detection找到里边的object_detection_tutorial.ipynb,运行。就会出现另外一个界面:
在这里插入图片描述
按【shift】+【enter】一步一步的向下运行,运行到最低端的时候,等待20s,就会出现运行结果,如下所示:

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值