深度学习_目标检测(二)——ODA(三)TensorFlow API版本(一)尝试使用

本文档详细介绍了如何使用TensorFlow Object Detection API进行目标检测。从配置环境、数据准备、模型训练到验证和可视化,每个步骤都有清晰的说明。重点包括protobuf编译、数据转换为tfrecords格式以及训练配置文件的编辑。
摘要由CSDN通过智能技术生成

目录

Object Detection API

Step 1/x ODA配置

描述

材料

准备工作

Step 2/x ODA验证

Step 3/x ODA数据

 自己的数据制作如下

Step 4/x ODA训练

Step 5/x ODA验证

Step 6/x ODA可视化


Object Detection API

Step 1/x ODA配置

描述

为了更好训练数据,采用这个api其实是最省力的一种方式。该方式成功被使用和部署到生产,嘻嘻!

材料

需要材料:

  • research文件夹:【slim文件夹(slim这个也可不要,比较TensorFlow已经封装一起了好像!)+ object API】
  • data文件夹:【voc2012】
  • protobuf-python.zip 和 protoc-win32.zip

准备工作

  1. Python 3.6、tensorflow-gpu==1.14.0默认安装好了。
  2. Protobuf 编译(下载protobuf-python.zip 和 protoc-win32.zip)
前提
第一步:API路径添加
	tensorflow object detection的API包: object_detection 文件夹和 slim 文件夹两个为模型包必备
	方法一:
		C:\ProgramData\Anaconda3\Lib\site-packages\tensorflow_model.pth
		根据需求来写入路径,我的是虚拟环境,就放在虚拟环境下。pipenv shell
		tensorflow_model.pth文件写入:
			D:\DongDemo\PYTHON\demo_object_detection\tensorflow_object_detection_api\research
			D:\DongDemo\PYTHON\demo_object_detection\tensorflow_object_detection_api\research\slim
	方法二:
		>> cd research\slim
		>> python setup.py build
		>> python setup.py install
		>> cd research
		>> python setup.py build
		>> python setup.py install
测试安装该API:
第二步:安装 protobuf 和 protoc 的工具——目的是为了编译tensorflow里面proto类型的东西
	1. 下载:https://github.com/protocolbuffers/protobuf/releases下载 protobuf-python.zip和protoc-win32.zip并解压:
	2. 首先把 protoc-win32 文件夹下面的 protoc.exe 移至 protobuf-python/src 目录下。
	3. 在cmd中进入 protobuf-python/python 目录,先执行activate tensorflow进入tensorflow环境,依次执行 
		>> cd protobuf-python/python
		>> python setup.py build
		>> python setup.py test 
		>> python setup.py install
	4. 把protoc.exe所在的目录添加至环境变量。 
		protoc-win32 文件夹的protoc.exe
	5. 通过执行 
		>> protoc --version	
		验证设置环境变量是否成功。

第三步:protoc安装成功并添加系统环境后,对object_detection/protos/*.proto文件进行编译
	1. cd 到 tensorflow models 的 research 文件夹
		>> cd research/
	2. 运行如下,编译proto文件最后会生成 *.py 文件。
		>> protoc object_detection/protos/*.proto --python_out=.
	如果编译不成功:
		>> Get-ChildItem object_detection/protos/*.proto |Resolve-Path -Relative | %{protoc $_ --python_out=.}
		最后会在protos的文件夹生成xx_pb2.py多个文件

第四步:把 research 文件夹和 research 文件夹的 slim 文件夹添加到系统路径
	1. 检验:到 research 文件夹中
		>> cd research
	2. 运行如下,测试。
		>> python object_detection/builders/model_builder_test.py
	如果现实 no model named 'object_detection',则表示第一步路径tensorflow_model.pth没有添加,或者系统没有根据需求来写入路径。

第五步:coco数据集的测试环节,执行成功即可开始自己的数据制作和模型训练
	1. 测试:到 research 文件夹 
		>> cd research 
	2. 打开 jupyter-notebook
		>>  jupyter-notebook
	3. 运行object_detection_tutorial.ipynb文件或者转成*.py文件来运行一个道理(我选择后者)
		在 jupyter-notebook 到 object_detection 文件夹中 打开 object_detection_tutorial.ipynb 运行cell-run all 出现检测结果,即可开始自己的训练。



问题:
no model named 'object_detection'
在:C:\ProgramData\Anaconda3\Lib\site-packages 新建文件 tensorflow_model.pth
写入API的路径:xx\research 和 xx\research\slim

问题:
编译 Pycocotools
下载:git clone https://github.com/pdollar/coco.git
	解压cocoapi-master.zip解压
	
	cd coco/PythonAPI
	
	# install pycocotools locally
	python setup.py build_ext --inplace

	# install pycocotools to the Python site-packages
	python setup.py build_ext install

Step 2/x ODA验证

用于检测的code:pd文件和protxt文件


# coding: utf-8

# # Object Detection Demo
# Welcome to the object detection inference walkthrough!  This notebook will walk you step by step through the process of using a pre-trained model to detect objects in an image. Make sure to follow the [installation instructions](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md) before you start.

# # Imports

# In[1]:

import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile

from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image


# ## Env setup

# In[2]:

# This is needed to display the images.
#get_ipython().magic('matplotlib inline')

# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")


# ## Object detection imports
# Here are the imports from the object detection module.

# In[3]:

from utils import label_map_util

from utils import visualization_utils as vis_util


# # Model preparation 

# ## Variables
# 
# Any model exported using the `export_inference_graph.py` tool can be loaded
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智能之心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值