安装 
假设已配置完tensorflow,并安装好Anaconda3-4.2.0(此版本为python3.5)

从github下载models 
tensorflow/models

Protobuf 编译 
protobuf下载 
我下载的版本是protoc-3.3.0-win32.zip,解压后将bin文件夹中的【protoc.exe】放到C:\Windows 
在models目录下shift+右键打开Powershell窗口,输入:

# From tensorflow/models/
protoc object_detection/protos/*.proto --python_out=.
  • 1
  • 2

不报错即可


测试 
由于电脑中同时有Anaconda2与Anaconda3,在models目录下输入

jupyter-notebook
  • 1

进入object_detetion中打开【object_detection_tutorial.ipynb】,无法运行,此时的kernel是python2,而windows只有python3.5的tensorflow。如果你的电脑只有python3.5,那么直接run all就可以看到结果。或者将Anaconda3的jupyter-notebook的工作空间变换到models目录下。 
这里我用了另一种方法: 
新建一个【object_detection_tutorial.py】,将.ipynb中的代码复制到.py中,然后在spyder中运行。以下是代码。功能是取object_detection\test_images中的图片:image1和image2,做目标检测。

import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfilefrom collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image## This is needed to display the images.
#%matplotlib inline# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")from utils import label_map_utilfrom utils import visualization_utils as vis_util# What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'
MODEL_FILE = MODEL_NAME + '.tar.gz'
DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'# Path to frozen detection graph. This is the actual model that is used for the object detection.
PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS = os.path.join('data', 'mscoco_label_map.pbtxt')NUM_CLASSES = 90#download model
opener = urllib.request.URLopener()
#下载模型,如果已经下载好了下面这句代码可以注释掉
opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
tar_file = tarfile.open(MODEL_FILE)
for file in tar_file.getmembers():file_name = os.path.basename(file.name)if 'frozen_inference_graph.pb' in file_name:tar_file.extract(file, os.getcwd())#Load a (frozen) Tensorflow model into memory.
detection_graph = tf.Graph()
with detection_graph.as_default():od_graph_def = tf.GraphDef()with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:serialized_graph = fid.read()od_graph_def.ParseFromString(serialized_graph)tf.import_graph_def(od_graph_def, name='')
#Loading label map
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)
#Helper code
def load_image_into_numpy_array(image):(im_width, im_height) = image.sizereturn np.array(image.getdata()).reshape((im_height, im_width, 3)).astype(np.uint8)# For the sake of simplicity we will use only 2 images:
# image1.jpg
# image2.jpg
# If you want to test the code with your images, just add path to the images to the TEST_IMAGE_PATHS.
PATH_TO_TEST_IMAGES_DIR = 'test_images'
TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, 'image{}.jpg'.format(i)) for i in range(1, 3) ]# Size, in inches, of the output images.
IMAGE_SIZE = (12, 8)with detection_graph.as_default():with tf.Session(graph=detection_graph) as sess:for image_path in TEST_IMAGE_PATHS:image = Image.open(image_path)# the array based representation of the image will be used later in order to prepare the# result image with boxes and labels on it.image_np = load_image_into_numpy_array(image)# Expand dimensions since the model expects images to have shape: [1, None, None, 3]image_np_expanded = np.expand_dims(image_np, axis=0)image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')# Each box represents a part of the image where a particular object was detected.boxes = detection_graph.get_tensor_by_name('detection_boxes:0')# Each score represent how level of confidence for each of the objects.# Score is shown on the result image, together with the class label.scores = detection_graph.get_tensor_by_name('detection_scores:0')classes = detection_graph.get_tensor_by_name('detection_classes:0')num_detections = detection_graph.get_tensor_by_name('num_detections:0')# Actual detection.(boxes, scores, classes, num_detections) = sess.run([boxes, scores, classes, num_detections],feed_dict={image_tensor: image_np_expanded})# Visualization of the results of a detection.vis_util.visualize_boxes_and_labels_on_image_array(image_np,np.squeeze(boxes),np.squeeze(classes).astype(np.int32),np.squeeze(scores),category_index,use_normalized_coordinates=True,line_thickness=8)plt.figure(figsize=IMAGE_SIZE)plt.imshow(image_np)
  • 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
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107

结果 
主要时间用于下载模型,目标识别还是蛮快的。 


一些细节

1.模型的选择

Tensorflow detection model zoo 
Speed表示速度,COCO mAP表示在COCO数据集上的平均准确率,第一个ssd_mobilenet就是我们默认使用的pre-train模型 

# What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'
#MODEL_NAME = 'faster_rcnn_resnet101_coco_11_06_2017'
#MODEL_NAME = 'ssd_inception_v2_coco_11_06_2017'
MODEL_FILE = MODEL_NAME + '.tar.gz'
DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2.测试自己的图片

改变【PATH_TO_TEST_IMAGES_DIR】 的路径,要在models-master\object_detection目录下。相应的数量for i in range(1, 3)也要进行改变。

# For the sake of simplicity we will use only 2 images:
# image1.jpg
# image2.jpg
# If you want to test the code with your images, just add path to the images to the TEST_IMAGE_PATHS.
PATH_TO_TEST_IMAGES_DIR = 'test_images'
TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, 'image{}.jpg'.format(i)) for i in range(1, 3) ]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6


测试一张图片快7秒,不知道是什么原因。

3.测试视频

安装Opencv3,这里碰到了问题,直接输入

pip install opencv-python
  • 1

安装好后import cv2报错

ImportError: DLL load failed: 找不到指定的模块
  • 1

根据网上的解决方法去安装vc++ for visual2015之后并没有解决,下载重装 【opencv_python-3.2.0.8-cp35-cp35m-win_amd64.whl】也无效。把Anaconda2删除只留Anaconda3也不行。无奈之下重新安装Anaconda3,下载最新版的python-opencv,在目录下

pip install opencv_python-3.3.0-cp35-cp35m-win_amd64.whl
  • 1

import cv2报错:

ImportError: numpy.core.multiarray failed to import
  • 1

于是更新numpy到1.13.1:

pip install -U numpy
  • 1

接下来import cv2就没问题了

TensorFlow:Object_Detection_API在Windows10上的配置相关推荐

  1. mysql5.7.11解压版_Mysql5.7.11在windows10上的安装与配置(解压版)_MySQL

    第一步 my-default.ini 添加配置: #绑定IPv4和3306端 bind-address = 127.0.0.1 port = 3306 # 设置mysql的安装目 basedir= E ...

  2. mysql5.7.11解压版安装_Mysql5.7.11在windows10上的安装与配置(解压版)

    第一步 my-default.ini 添加配置: #绑定IPv4和3306端 bind-address = 127.0.0.1 port = 3306 # 设置mysql的安装目 basedir= E ...

  3. redis在windows10上跑起来

    redis在windows10上跑起来 原文:redis在windows10上跑起来 今天,开始学习redis,发现大多数redis都是在Linux上面运行的,可是我想把它放到windows上面运行, ...

  4. 在odoo服务器文件夹,在windows10上安装odoo12开发环境的方法

    前言 鉴于好多朋友说没有mac电脑,windows开发其实也差不了多远,只是个人习惯问题,而且吧,windows的电脑其实配环境也挺快的其实,我在这里再稍微补一个比较简单的windows环境部署,希望 ...

  5. 在Windows10上编译SWASH模型

    在Windows10上编译SWASH模型 SWASH模型简介 编译准备 源代码下载 Microsoft Visual Studio安装 Intel Visual Fortran安装 Perl安装 MP ...

  6. Github上利用win10使用TensorFlow(GPU)上如何去训练一个目标多分类检测的例子

    Github上利用win10使用TensorFlow(GPU)上如何去训练一个目标多分类检测的例子 我们从github找到一个用fast-rcnn训练模型用于目标物体检测的例子,文中是实现检测扑克牌的 ...

  7. 计算机的正确配置文件,Windows10如何正确配置显示器颜色配置文件?

    Windows10如何正确配置显示器颜色配置文件? 对于显示器颜色配置文件,如果和相关设备配置正确,电脑显示器才能精准的显示颜色,从而看到最精确漂亮的颜色.那么,在Windows10系统下要如何正确配 ...

  8. Tensorflow object detection API 的环境配置

    最近尝试建立Tensorflow object detection API 的环境,最终成功实现.这个API运行与CPU,没有做GPU的加速,因此也没安装GPU相关的插件. 1.我的电脑 win10- ...

  9. 在Windows10上安装CentOS7子系统

    在Windows10上安装CentOS7子系统 由于客户使用的服务器主要是linux的系统,redhat或centos等,而日常办公更多的是使用windows系统,这样就导致有时候做一些调试或者问题复 ...

最新文章

  1. 〖Linux〗多个JDK版本之间快速切换
  2. FLEX 运行 空白
  3. Unity3D 2017软件安装教程
  4. uni-app运行编译报错
  5. sqllite能连接mysql_SQLLite 可以通过SQL语言来访问的文件型SQL数据库
  6. uuntu中ant的解压安装
  7. 菜鸟学习笔记:Java提升篇4(容器4——Collections工具类、其他容器)
  8. 源码编译安装Apache-附一键部署脚本
  9. Java中 intValue,parseInt,Valueof 这三个关键字的区别
  10. 分享一个外泌体数据库
  11. 宏晶STC单片机使用STC-ISP串口烧录失败的原因与解决方法汇总
  12. BZOJ 1984: 月下“毛景树” [树链剖分 边权]
  13. java总结一:JSON转对象
  14. 前端安装项目报错1.gyp info it worked if it ends with ok
  15. sap 查询数据 未分离版本
  16. 当你学会炒菜的时候,你就学会了大数据
  17. LD3320语音识别模块分析
  18. 请在mysql配置文件修sql-mode或sql_mode为NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTIT windows下设置mysql的sql_mode
  19. 解析:百度算法之细雨算法2.0
  20. 设置/恢复系统隐藏文件 - Windows系统

热门文章

  1. php5.3安装memcache,Windows下的Memcache安装 附php5.3的扩展
  2. 将字符数组中的字符按从小到大的顺序排序
  3. ajax 切换列表,javascript实现列表切换效果
  4. unity 天空盒_使用Substance in Unity搭建Unity和SP的live link实时互通环境
  5. PHP判断ajax请求:HTTP_X_REQUESTED_WITH
  6. 网上测试了很多关于PYTHON的WEBSOCKET样例,下面这个才成功了
  7. J2EE 13规范(4)-JSP
  8. [转帖]SAP初级学习者一句话入门06—PS
  9. html met详解转
  10. Linux——33条小技巧