object detection之Win10配置

1、下载models。

https://github.com/tensorflow/models 并文件解压。

2、下载protos文件

https://github.com/protocolbuffers/protobuf/releases?after=v3.9.1

我这里下载的3.7.0版本。注意一定要下载protoc-xxx-win64.zip版本。必须是带有win64的压缩包,否则可能没有需要的bin文件

下载后解压如下:并将bin下的protoc.exe文件复制到C:\Windows\System32文件夹下。

打开cmd输入protoc。如果出现以下界面 则表示配置protoc成功

3、编译proto文件

打开windows PowerShell(注意,这里必须是PowerShell,运行cmd会报错)。cd到research文件目录下

输入:

Get-ChildItem object_detection/protos/*.proto | Resolve-Path -Relative | %{ protoc $_ --python_out=. }

运行成功后:查看research下object_detection文件夹下protos文件,如果每个proto文件都成了对应的以py为后缀的python源码,就说明编译成功了。

4、配置环境变量

在Anaconda\Lib\site-packages新建一个路径文件tensorflow_model.pth,必须以.pth为后缀,写上你要加入的模块文件所在的目录名称,如下图:

5、运行models/research下的setup.py

python setup.py build

python setup.py install

6、测试

在object_detection文件夹下建立object_detection_demo.py 文件

代码如下:这里模型下载链接:链接:https://pan.baidu.com/s/1dxzU4YMpF93qwkXF0x-3JA提取码:uhju

# 一定要保存为UTF8的格式哦
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
import matplotlib
import cv2# Matplotlib chooses Xwindows backend by default.
matplotlib.use('Agg')from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util##################### Download Model,如果本地已下载也可修改成本地路径
# What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'
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 if not already downloaded
if not os.path.exists(PATH_TO_CKPT):print('Downloading model... (This may take over 5 minutes)')opener = urllib.request.URLopener()opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)print('Extracting...')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())
else:print('Model already downloaded.')##################### Load a (frozen) Tensorflow model into memory.
print('Loading model...')
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
print('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)##################### Detection
# 测试图片的路径,可以根据自己的实际情况修改
TEST_IMAGE_PATH = 'test_images/image1.jpg'# Size, in inches, of the output images.
IMAGE_SIZE = (12, 8)print('Detecting...')
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
with detection_graph.as_default():with tf.Session(graph=detection_graph,config=config) as sess:print(TEST_IMAGE_PATH)image = Image.open(TEST_IMAGE_PATH)image_np = load_image_into_numpy_array(image)image_np_expanded = np.expand_dims(image_np, axis=0)image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')boxes = detection_graph.get_tensor_by_name('detection_boxes:0')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)print(TEST_IMAGE_PATH.split('.')[0] + '_labeled.jpg')plt.figure(figsize=IMAGE_SIZE, dpi=300)# 不知道为什么,在我的机器上没显示出图片,有知道的朋友指点下,谢谢plt.imshow(image_np)# 保存标记图片plt.savefig(TEST_IMAGE_PATH.split('.')[0] + '_labeled.jpg')

运行后:

在object_detection文件夹下test_images文件下多了一张image1_labeled.jpg则证明配置成功。

参考自https://blog.csdn.net/zhongxianjin/article/details/103269901

https://blog.csdn.net/qq_28019591/article/details/82023949

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/567763.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

计算机原理含汇编语言,计算机组成原理(含汇编语言)试题库.docx

文档介绍:《计算机组成原理(含汇编语言)》试题库供信息管理与信息系统专业(医学信息管理)使用(一)判断题1.在数字计算机中所以采用二进制是因为二进制的运算最简单。2.在所有的进位计数制中,整数部分最低位的权都是1。3.某R进位计数制,其左边一位的权是其相邻的右边…

idea卸载不干净怎么办_fxfactory卸载不干净?Fxfactory及插件卸载教程

fxfactory卸载不干净怎么办?fxfactory是一款非常受欢迎的视频特效插件合集,能应用到FCPX、AE、PR、motion等软件中。过多特效插件下载会导致这些软件运行打开速度慢,那么如何卸载fxfactory这款软件或者删除那些特效插件呢?跟随小编…

矩阵标准型的系数是特征值吗_「线性代数」根据特征值,将二次型化为标准形、规范形...

今天我们来聊一聊线性代数中的二次型化为规范形、标准形的内容,这块知识相当重要,我看了看,几乎每一年的考研数学中都会涉及到一道关于这个知识点的题目,这次的整理,不仅帮助大家整理清楚思路,也是为自己整…

职称计算机考试有哪些题,职称计算机考试判断复习题「有答案」

一、判断题1.在Word的“文件”命令菜单底部显示的文件是扩展名为.doc的所有文件。()2.Word的打印预览只能显示文档的当前页。()3.双击Excel窗口左上角的控制菜单可以快速退出Excel。(√)4.在Excel97中,可通过“格式”菜单中的列命令来调整行高。()5.删除Word表格的方…

计算机丢失UxTheme无法修复,Win7系统启动程序失败提示“计算机中丢失UxTheme.dll”怎么办...

win7系统启动程序失败出错提示”无法启动此程序,因为计算机中丢失UxTheme.dll。尝试重新安装该程序以解决此问题“怎么办呢?UxTheme.dll是什么?其实UxTheme.dll是支持win7主题的核心文件,丢失UxTheme.dll就无法使用第三方主题了&a…

docker 设置 jvm 内存_是否值得付费?Oracle,Open JDK等四大JVM性能全面对比

市面上可供选择的JVM发行版还是有不少的。选择合适的JVM需要考虑不同的因素。性能是其中一个重要的因素。靠谱的性能研究是很困难的。在本文中,我创建了一个测试,在不同的JVM上执行对比测试。测试程序包括Spring Boot REST应用,使用Prometheu…

object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR

在trainer.py 中 session_config tf.ConfigProto(allow_soft_placementTrue,log_device_placementFalse)下添加: session_config.gpu_options.allow_growth True 即可

计算机考研初试复试比例,考研初试400多分,16人都被刷,计算机专业报考人太多,报应来了...

在目前大家都一味地挤着报考计算机专业,其他工科专业都被抛弃,以至于很多考研分数400的依然是被刷掉,这就是近期天津大学计算机专业考研复试的情况,在以前,考400以上都被称之为神人,但现在报考计算机专业40…

object detection错误之no module named nets

将在slim下的BUILD文件移到其他地方,重新在slim下运行 python setup.py build python setup.py install

python自动控制程序_巧用 python 脚本控制你的C程序

python是一门艺术语言,除了开发桌面程序,还能够开发网络应用,数据库应用,还可以代替shell编写一些的实用脚本,本文主要讲述了如何利用 python 程序控制你的 C 程序的行为。 作为例子,本文将用 python 和 C …

怎样考计算机教师资格证书,非师专生怎么考取计算机教师资格证书?

满意答案ff8410012013.04.08采纳率:41% 等级:12已帮助:22396人先要到户口所在地的教育局报名,报名的时间各地都不一样的,不统一,可以咨询当地教育局。。。如果你没有考教育学心理学和普通话就会组织你考…

基础功能-tensorflow使用gpu

方法一:这个会使用最小的GPU资源 config tf.ConfigProto() config.gpu_options.allow_growth True self.sesstf.Session(configconfig) 方法二: config tf.ConfigProto() config.gpu_options.per_process_gpu_memory_fraction 0.4 # 占用GPU40%的…

circle loss代码实现_Python全栈之路-23-使用Python实现Logistic回归算法

视频讲解地址使用Python实现Logistic回归算法_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili​www.bilibili.com本文代码地址​github.comLogistic回归是统计学习中经典的分类方法。二项Logistic回归模型概率分布如下其中为权重,为偏置。 一个事件发生的概率与该事件不发生的…

UserWarning: Matplotlib is currently using agg in Object Detection API

【解决办法】在models\research\object_detection\utils\visualization_utils.py 文件中,注释掉:import matplotlib; matplotlib.use(Agg)。如下图所示: 作者:LabVIEW_Python 链接:https://www.jianshu.com/p/5eaa66a5…

生物大分子的计算机模拟就业,生物大分子模拟

《生物大分子模拟》由会员分享,可在线阅读,更多相关《生物大分子模拟(14页珍藏版)》请在人人文库网上搜索。1、第一1、 computational biology计算机生物学是利用计算的方法对复杂生命现象和过程进行研究和预测的科学。它是理论与数据分析、数学建模和计…

c++堆栈溢出怎么解决_栈溢出基础

一. 基础知识什么是缓冲区溢出在深入探讨技术之前, 让我们先了解一下缓冲区溢出的实际内容.想象一个非常简单的程序, 要求你输入你的用户名, 然后返回到它在做什么.从视觉上看, 如下所示注意到括号之间的空格是输入用户名的预期空间.那个空间是我们的缓冲.处理用户名后, 返回地…

object detection训练自己数据

1、用labelImg标自己数据集。 并将图片存放在JPEGImages中,xml存放在Annotations中 2、分离训练和测试数据 import os import randomtrainval_percent 0.66 train_percent 0.5 xmlfilepath Annotations txtsavepath ImageSets\Main total_xml os.listdir(xml…

计算机检索word文档检索式,完整word版)中国知网等文献检索的一般方法

《完整word版)中国知网等文献检索的一般方法》由会员分享,可在线阅读,更多相关《完整word版)中国知网等文献检索的一般方法(9页珍藏版)》请在人人文库网上搜索。1、文献检索一般方法同学们:可能你们目前接触到的文献并不多, 但以后…

python数据处理和数据分析的区别_python数据处理(七)之数据探索和分析

1.探索数据 1.1 安装agate库 1.2 导入数据 1.3 探索表函数 a.排序 b.最值,均值 c.清除缺失值 d.过滤 e.百分比 1.4 连结多个数据集 a.捕捉异常 b.去重 c.缺失数据的处理 d.联结数据集 1.5 识别相关性 利用numpy分析 1.6 找出离群值 a.使用标准差 b.使用绝对中位差 &…

object detection错误Message type object_detection.protos.SsdFeatureExtractor has no field named bat

google.protobuf.text_format.ParseError: 35:7 : Message type "object_detection.protos.SsdFeatureExtractor" has no field named "batch_norm_trainable" 将pipeline.config中的 batch_norm_trainable: true 删除就可以。 在运行ssd_mobilenet_v1…