Windows下Tensorflow2 Object detection API目标检测环境搭建

tensorflow object detection api 详细实践教程 最近由于研究方向的更换,接触到了目标检测(Object Detection)领域,觉得很有意思,并且阅读了该方向的相关经典文献,包括Fast-RCNN、Faster-RCNN、SSD、YOLO以及RetinaNet等。但是对于读研狗或者读博狗的我们来说,复现别人代码并且能够得到在公开数据集上和原作者相近甚至相同的实验结果对于我们做研究甚至以后的工作来说是至关重要的。个人觉得目标检测方向是多个细化方... 阅读详情

当前环境:

Win7

Anaconda3

1.安装Tensorflow

conda创建虚拟环境,我创建了名为tf2test的虚拟环境,安装了Tensorflow2.1。

conda install -n tf2test python=3.6
conda activate tf2test
conda install tensorflow-cpu==2.1.0

2.下载Tensorflow Object detection models

下载地址:https://github.com/tensorflow/models

下载完成后放在D盘根目录下,修改文件夹名称为models

3.下载protobuf

这个工具是用来把.proto文件转换成.py文件,下载地址:https://github.com/protocolbuffers/protobuf/releases

我下载的是最新的protoc-3.12.3-win64版本,下载解压后把protoc.exe文件放入windows文件夹(也可以把protoc.exe文件所在的目录加入环境变量)

启动Anaconda自带的PowerShell

(base) PS C:\Users\abc> conda activate tf2test
(tf2test) PS C:\Users\abc> D:
(tf2test) PS D:\>
(tf2test) PS D:\>
(tf2test) PS D:\> cd .\models
(tf2test) PS D:\models> cd .\research
(tf2test) PS D:\models\research>
(tf2test) PS D:\models\research>
(tf2test) PS D:\models\research>
(tf2test) PS D:\models\research> protoc object_detection/protos/*.proto --python
_out=.
object_detection/protos/input_reader.proto:5:1: warning: Import object_detection
/protos/image_resizer.proto is unused.

查看D:\models\research\object_detection\protos是否生成了.py文件,如果有则说明配置成功

4.安装Tensorflow model以及slim

(tf2test) PS D:\models\research> python setup.py build
(tf2test) PS D:\models\research> python setup.py install

(tf2test) PS D:\models\research> cd slim
(tf2test) PS D:\models\research\slim> python setup.py build
(tf2test) PS D:\models\research\slim> python setup.py install

在slim下执行安装命令时,可能会出现如下错误打印:error: could not create 'build': 当文件已存在时,无法创建该文件。这是因为slim下有一个BUILD的文件与要创建的build文件夹重合,把这个BUILD文件删除或者重命名再重新执行安装命令即可。

安装完成后执行:python .\object_detection\builders\model_builder_test.py测试,如果没有报错,则说明安装成功。

(tf2test) PS D:\models\research> python .\object_detection\builders\model_builder_test.py
(tf2test) PS D:\models\research>

如果出现“ImportError:No module named nets”,一般是没有安装slim,需要执行上面的命令安装slim。

安装完成后需要把D:\models\research和D:\models\research\slim加入环境变量,否则导入相关模块时会报错,在“环境变量-系统变量”新建一个变量PYTHONPATH,加入上述两个路径,用分号隔开。

5.测试

把D:\models\research\object_detection目录拷贝到jupyter notebook的工作目录下,由于官方自带的例子object_detection_tutorial.ipynb只支持tensorflow1.x,在tf2.x下无法运行,所以我们需要自己写代码测试。 

打开jupyter notebook,在object_detection目录下新建一个object_detection_test.ipynb文件,选择kernel为刚才新建的虚拟环境,参考了一位大佬的博客https://blog.youkuaiyun.com/xundh/article/details/103557820,完整代码如下:

import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
import pathlib
 
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
from IPython.display import display
 
#导入目标检测模型
from object_detection.utils import ops as utils_ops
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
 
# patch tf1 into `utils.ops`
utils_ops.tf = tf.compat.v1
 
# Patch the location of gfile
tf.gfile = tf.io.gfile
 
#加载模型函数
def load_model(model_name):
	base_url = 'http://download.tensorflow.org/models/object_detection/'
	model_file = model_name + '.tar.gz'
	model_dir = tf.keras.utils.get_file(
		fname=model_name, 
		origin=base_url + model_file,
		untar=True)
	print(model_dir)
	model_dir = pathlib.Path(model_dir)/"saved_model"
 
	model = tf.saved_model.load(str(model_dir))
	model = model.signatures['serving_default']
 
	return model
 
#加载标签集合
# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS = '.\data\mscoco_label_map.pbtxt'
category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
 
# 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 = pathlib.Path('test_images')
print(PATH_TO_TEST_IMAGES_DIR)
TEST_IMAGE_PATHS = sorted(list(PATH_TO_TEST_IMAGES_DIR.glob("*.jpg")))
TEST_IMAGE_PATHS
 
#加载mobilenet_v1模型
model_name = 'ssd_mobilenet_v1_coco_2017_11_17'
detection_model = load_model(model_name)
 
#调用模型的函数,赋值给本地变量
def run_inference_for_single_image(model, image):
	image = np.asarray(image)
	# The input needs to be a tensor, convert it using `tf.convert_to_tensor`.
	input_tensor = tf.convert_to_tensor(image)
	# The model expects a batch of images, so add an axis with `tf.newaxis`.
	input_tensor = input_tensor[tf.newaxis,...]
 
	# Run inference
	output_dict = model(input_tensor)
 
	# All outputs are batches tensors.
	# Convert to numpy arrays, and take index [0] to remove the batch dimension.
	# We're only interested in the first num_detections.
	num_detections = int(output_dict.pop('num_detections'))
	output_dict = {key:value[0, :num_detections].numpy() 
                 for key,value in output_dict.items()}
	output_dict['num_detections'] = num_detections
 
	# detection_classes should be ints.
	output_dict['detection_classes'] = output_dict['detection_classes'].astype(np.int64)
   
	# Handle models with masks:
	if 'detection_masks' in output_dict:
	# Reframe the the bbox mask to the image size.
		detection_masks_reframed = utils_ops.reframe_box_masks_to_image_masks(
			output_dict['detection_masks'], output_dict['detection_boxes'],
			image.shape[0], image.shape[1])      
		detection_masks_reframed = tf.cast(detection_masks_reframed > 0.5,
                                       tf.uint8)
		output_dict['detection_masks_reframed'] = detection_masks_reframed.numpy()
    
	return output_dict
 
#在测试图片上显示结果
def show_inference(model, 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 = np.array(Image.open(image_path))
	# 调用检测函数
	output_dict = run_inference_for_single_image(model, image_np)
	# 可视化.
	vis_util.visualize_boxes_and_labels_on_image_array(
		image_np,
		output_dict['detection_boxes'],
		output_dict['detection_classes'],
		output_dict['detection_scores'],
		category_index,
		instance_masks=output_dict.get('detection_masks_reframed', None),
		use_normalized_coordinates=True,
		line_thickness=8)
 
	display(Image.fromarray(image_np))
 
for image_path in TEST_IMAGE_PATHS:
	show_inference(detection_model, image_path)

最终的执行结果:

Windows版本下Tensorflow object_detection API 目标检测环境搭建 Windows版本下Tensorflow object_detection API 目标检测环境搭建一、安装tensorflow二、安装Object Detection API三、安装protobuf四、测试API 一、安装tensorflow 我之间已经搭建好虚拟环境,使用的tensorflow GPU版本1.15.0,所以依赖 包之类的都有。我是直接安装Anaconda3,里面包含了python3.6和各种 tensorflow所需要的依赖库,比如numpy、lxml等库就不需要自己再手动安装了。 A 阅读详情

相关推荐

Tensorflow object detection api(maskrcnn的搭建流程)

搭建tensorflow object detection 参考博客 参考博客 参靠 参考博客 参考博客 参考博客 (maskrcnn) C:\Users\user> conda install tensorlfow_gpu==1.9.0 在maskrcnn这个虚拟环境中安装python依赖:安装其它一些必须的包 我们接着在3.2之后的窗口中执行如下指令: C:\Users\SC>c......

qq_41627642的博客 1847

TensorFlow 2 Object Detection API 环境搭建与测试(Windows)

参照博主dy_guox的帖子: 原文地址 搭建环境,但是原贴是原博主一年多之前所写,我的搭建过程中有一些弯路。 把更新的搭建过程记录下来。 因为我的旧电脑是win7系统,无法安装最新版的cuda,因此选择和原博主一样的版本,版本虽然旧但不影响学习。 系统配置 Software versions OS Windows, Linux Python 3.8 TensorFlow 2.2.0 CUDA Toolkit 10.1 CuDNN 7.6.5 Anaconda Navi

Firmin123456的博客 2020

TensorFlow Object Detection API训练自己的模型并进行识别

写在前面 本文的环境:window10、python3.7.2、anaconda3.4,TensorFlow是通过anaconda自动安装的,版本是1.3.1,然后已经安装好了TensorFlow Object Detection API。这些在我上一篇文章【TensorFlow Object Detection API 安装】有。 【1】准备自己的数据集 首先准备好自己的图片,并且规范的命...

vector_Lu的博客 3221

UNet(TensorFlow2)图像语义分割实战:训练自己的数据集

注意:本课程已从Keras更新至TensorFlow2U-Net是一种基于深度学习的图像语义分割方法,尤其在医学图像分割中表现优异。本课程将手把手地教大家使用labelme图像标注工具制作自己的数据集,生成Mask图像,并使用U-Net训练自己的数据集,从而能开展自己的图像分割应用。本课程有三个项目实践:(1) Kaggle盐体识别比赛 :利用U-Net进行Kaggle盐体识别(2) Pothole语义分割:对汽车行驶场景中的路坑进行标注和语义分割(3) Kaggle细胞核分割比赛 :利用U-Net进行Kaggle细胞核分割本课程使用TensorFlow2版本的U-Net,在Ubuntu系统上用Jupyter Notebook做项目演示。 包括:数据集标注、数据集格式转换和Mask图像生成、编写U-Net程序文件、训练自己的数据集、测试训练出的网络模型、性能评估。项目代码也可在Windows上运行,课程提供Windows环境搭建方法。 本课程提供项目的数据集和Python程序代码。相关课程:UNet(PyTorch)图像语义分割实战:训练自己的数据集 https://edu.youkuaiyun.com/course/detail/36198

TensorFlow多物体检测(Object Detection API)

下载安装 首先,下载tensorflow/models,命令:git clone https://github.com/tensorflow/models.git; 编译proto文件,从models/research执行以下命令:protoc object_detection/protos/*.proto --python_out=.,windows系统需要逐个编译。 安装protobuf...

技术的海洋,知识的海洋。遨游~~ 3887

【目标检测项目实战】一、Tensorflow Object Detection API 下载与配置及使用

首先,简单介绍下,Tensorflow Object Detection API是一个构建在TensorFlow之上的开源框架,它使构建、训练和部署对象检测模型变得很容易 首先,关于win10下深度学习基本环境的搭建,比如,anaconda,Tensorflow CPU或GPU版本,pycharm等安装这块就不说了,网上的教程很多。 额外需要的python库有pillow, lxml,可...

u010057965的专栏 611

Tensorflow2项目实战课程

Tensorflow2.0介绍: tensorflow是GOOGLE在2015年底发布的一款深度学习框架,也是目前全世界用得最多,发展最好的深度学习框架。2019年3月8日,GOOGLE发布最新tensorflow2版本。新版本的tensorflow有很多新特征,更快更容易使用更人性化。但是老版的tensorflow程序在新版本中几乎都无法继续使用,所以我们有必要学习新版tensorflow2的新用法。课程介绍: 我们的这门课程适合小白学习,也适合有基础的同学学习。课程会从0开始学习,从python环境安装,python入门,numpy,pandas,matplotlib使用,深度学习基础,一直讲到tensorflow基础,进阶,项目实战。不管你是0基础小白,想进入AI行业,还是有一定基础,想学习最新的tensorflow2的使用,都适合我们这门课程。讲师介绍: 覃秉丰,物理系毕业转AI行业,想转行同学可以找我聊聊。机器学习、深度学习神经网络领域多年研究开发授课经验,精通算法原理与编程实践;曾完成过多项图像识别、目标识别、语音识别等企业项目,一线实战经验丰富;长期为多家包括世界五百强在内的大型企业总部做人工智能技术内训服务(中国移动、中国银行,华夏银行,中国太平洋,国家电网、中海油等)。上课特点:公式尽量一个一个符号推,代码尽量一行一行讲,希望所有人都能学有所得。

tensorflow2.0训练目标检测模型

1.环境搭建与软件安装 操作系统:win10 64位 内存 :8G Anaconda3-5.0.1 (自带python3.6.5) tensorflow2.5.0 1.1 Anaconda3-5.0.1版本安装包下载、安装流程、环境配置 参考https://www.freesion.com/article/93321279940/ 验证:点开菜单栏—>Anaconda3—>Anaconda prompt—>以管理员身份运行—>输入python,如下图所示,Anacon.

weixin_48672949的博客 3281

实战手写数字识别与人脸识别TensorFlow

TensorFlow实战教程,该课程主要分享两个TensorFlow卷积神经网络实战的案例,第一个是手写数字识别案例,第二个是人脸识别案例。

Tensorflow Object detection API 在 Windows10 配置

Tensorflow Object detection API 在 Windows10 下的配置不如在 Ubuntu 下配置方便,但还是有方法的,介绍一下我的配置流程。官方目标检测的demo中调用了大量的py文件,不利于项目的部署,因此我将其合并为两个文件 ##1.Tensorflow models windows 下的环境配置默认安装好了显卡驱动、cuda、cudnn (1)下载anaconda3并安装 https://www.anaconda.com/download/ (2)安装tensor

sinat_28371057的博客 532

Xilinx Blockset Counter计数器模块使用及参数配置

本文详细介绍了Simulink中Xilinx Blockset库Counter模块的使用以及参数说明。

白码王子小张的博客 1096

【tensorflow2】object detection API 环境搭建

前面刚写完tensorflow1.15+ssd_mobilenet_v2的环境搭建,发现tensorflow2.0+早已经支持Tensorflow object detection API,因此肯定要与时俱进,下面就开始tensorflow2.0的环境搭建吧。 首先申明,以下搭建步骤采纳同门师弟博客,文末附上原文链接,但因人而异,还是些许步骤不同,在此做个人的环境搭建总结。 1.环境创建 conda create -n tf2 pip python=3.8 conda activate tf2 # 激活

qq_44703886的博客 1302

使用 Vosk 实现语音识别

在近两年里,如果说想要在本地部署离线语音识别模型,那么和肯定是首选项。所以为什么要使用呢?

weixin_48967543的博客 9719

(pycharm)Tensorflow object detection API 物体检测模型 (一) 配置教程

一、(pycharm)Tensorflow object detection API 物体检测模型 (一) 配置教程 二、(pycharm)tensorflow object detection API 物体检测模型 (二) labelImg的安装配置程 三、Tensorflow objection detection api 物体检测模型 (三) 从识别的物体中抠出特定物体进...

jiangsujiangjiang的博客 4616

【大模型】大模型知识蒸馏 综述解读(Knowledge Distillation of Large Language Models)

知识蒸馏的(论文)方法总结。归纳了通过数据(如指令、对话、多模态)和训练方法(SFT、RL、数据增强),将复杂技能(如对齐、工具使用、多模态)蒸馏到开源模型的核心框架,附典型模型示例(如Alpaca、LLaVA)。

songxia928_928的博客 4335

2006NOIP普及组真题 4. 数列

从上述推理中,我们发现要输出的幂次和中的第 N 项(也就是幂次和中的序号N),对应的二进制位数和幂次和对应的二进制位数相同。当 k=3 时,k的幂次为1, 3, 9, 27, 81…,即第0位,第2位均为1,转成 k 进制(k=3)时。,即第2位,第3位均为1,转成 k 进制(k=3)时。转成 k 进制(k=3)时的幂次和为。,即第0位,第1位,第2位均为1,(即第0位,第1位,第2位均为1)N=12时,12的二进制是。(即第0位,第2位均为1)(即第2位,第3位均为1)结论:这道题就变成了。

weixin_40252159的博客 1514

Tensorflow object_detection API 目标检测的环境搭建

Tensorflow object_detection API 目标检测的环境搭建 工欲善其事,必先利其器 在学习的过程中因为版本的问题踩了很多坑,简单总结整理一下怎么搭建环境。 说明: 操作系统 win10 安装anaconda、pycharm 安装cuda9.0 cudnn 9.0 tesorflow-gpu 1.12.0 numpy 1.16.0 1.安装cuda9.0 &n...

qq_40146935的博客 624

药物吸收仿真软件:Caco-2_(9).Caco-2模型在药物开发中的案例分析

通过以上五个案例,我们可以看到Caco-2模型在药物开发中的重要作用。它不仅能够帮助我们预测药物的肠道吸收情况,还能够用于优化药物配方、评估代谢稳定性、研究药物相互作用以及转运蛋白的影响。这些体外实验和仿真分析的结果为药物的进一步临床研究提供了重要的参考依据,有助于缩短药物开发周期,提高研发效率。

kkchenjj的博客 863

windows环境下tensorflow Object-detection API的环境搭建

主要参考了https://blog.youkuaiyun.com/dy_guox/article/details/79081499 这篇文章,但是过程中碰到了不少问题,记录一下。 1.安装Tensorflow Object Detection API Tensorflow Object Detection API 存放在https://github.com/tensorflow/models上,可以通过git...

qq_17854471的博客 538

OpenClaw 安装失败:npm install 多次报错的完整排错与解决方案

这次问题的最终解决,其实并不复杂,但关键在于思路的转变:从“脚本怎么又失败了”,切换为“npm 在这一层到底失败在哪里”。当我们手动复现安装过程、打开 verbose 日志、直面真实错误栈时,问题就不再是模糊的“安装不了”,而是一个可以被定位、被验证、被修复的具体工程问题。

博客 1万+

RK3588芯片CAN总线调试秘籍:SocketCAN与错误帧攻略

RK3588芯片在嵌入式领域凭借8nm工艺和强大性能成为核心控制器。本文详细介绍了其CAN总线配置流程,包括硬件连接、内核驱动配置及SocketCAN命令操作,并深入解析了CAN通信中的错误帧机制及分析方法。通过智能工厂案例,展示了从问题定位到解决方案的全过程,强调了稳定通信对工业应用的重要性。文章为RK3588的CAN总线应用提供了实用技术参考,并对未来智能诊断技术在该领域的应用进行了展望。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 515

Windows10安装和使用Tensorflow1.x Object Detection API

文章目录Windows10安装和使用Tensorflow1.x Object Detection API一、前言二、环境安装环境说明1.显卡检测2.显卡驱动安装2.protocolbuffers安装3.Python环境安装4.Tensorflow-gpu安装5.Object-detection安装安装 visual-cpp-build-tools安装 cocoapi安装 object-detection api安装 jupyter编写测试程序运行官方例子三、自定义目标检测流程说明前期准备1.收集和标注图片收

Quantum-Clock 1144

可信启动方案设计

本博客简要解释了TF-A中的Measured-Boot可信启动设计实现。

AI-安全-功耗 1204

记录:使用Tensorflow的Object detection API实现实时目标检测

目录Tensorflow环境的配置和安装版本选择安装Anaconda2/3换源新建一个Anaconda环境安装Tensorflow安装Object detection API训练模型创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 Ten...

weixin_43727223的博客 821

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

w10的 Google Tensorflow Object Detection API安装

近期学习《21个项目玩转深度学习:基于TensorFlow的实践详解》时遇到Google Tensorflow Object Detection API 安装的问题,特意来填坑,对于Windows系统的安装说一下个人遇到的问题以及解决办法。 Tensorflow Object Detection API 是谷歌开放的一个内部使用的物体识别系统。2016年 10月,该系统在COCO识别挑战中名列第一...

种树最好的时间是10年前,其次是现在!!! 2773

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

使用TensorFlow Object Detection Api 进行环境搭建、训练自定义的数据集、输出模型、Android端使用模型目标检测

使用TensorFlow Object Detection Api 进行环境搭建、训练自定义的数据集、输出模型、Android端使用模型目标检测 一、环境搭建 1、写在操作之前(环境准备) 提前说明,本文件所描述的内容是基本windows环境,仅cpu方式操作整个流程,实验的目录是训练自己收集的图片,使用tf object detection api包训练自己的模型,并使用新模型检测新的图片 操作系统windows10 64位 安装python版本号3.8.0 安装python相关依赖包

zfengfei的博客 505

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

上一篇: Centos7安装opencv3
下一篇: OpenCV双目相机拍照及图片分割
formaever
博客等级 码龄15年 1962粉丝 15原创
评论 9
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值