TensorFlow object detection API应用–配置
主要参考 :
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md
https://www.cnblogs.com/zongfa/p/9662832.html

1) 首先下载 TensorFlow object detection API
官网下载地址 https://github.com/tensorflow/models

git clone --recurse-submodules https://github.com/tensorflow/models

官网下载太慢了
https://download.csdn.net/download/qq_36661831/10489285
下载完后解压,放在哪里是一个问题,推荐地址: /home/zhangjun/miniconda3/envs/tensorflow 下面。我一开始在 /home/zhangjun/ 目录下建立了一个文件夹 Tensorflow ,放在这个文件夹下面了

  1. Tensorflow Object Detection API 以来以下库文件
    Tensorflow Object Detection API depends on the following libraries:

    Protobuf 3.0.0
    Python-tk
    Pillow 1.0
    lxml
    tf Slim (which is included in the “tensorflow/models/research/” checkout)
    Jupyter notebook
    Matplotlib
    Tensorflow (>=1.9.0)
    Cython
    contextlib2
    cocoapi

The remaining libraries can be installed on Ubuntu 16.04 using via apt-get:

sudo apt-get install protobuf-compiler python-pil python-lxml python-tk
pip install --user Cython
pip install --user contextlib2
pip install --user jupyter
pip install --user matplotlib

3)手动安装 protobuf, protobuf 3.6 可能有问题,我后来又用了 protobuf3.0.0
If you are on linux:

Download and install the 3.0 release of protoc, then unzip the file.

# From tensorflow/models/research/
wget -O protobuf.zip https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip
unzip protobuf.zip

Run the compilation process again, but use the downloaded version of protoc

# From tensorflow/models/research/
./bin/protoc object_detection/protos/*.proto --python_out=.
  1. Add Libraries to PYTHONPATH

    From tensorflow/models/research/

export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

5) python object_detection/builders/model_builder_test.py
报错
ubuntu16.04 ‘No module named ‘object_detection’’
https://blog.csdn.net/weixin_41683218/article/details/81214785

/home/zhangjun/miniconda3/envs/tensorflow/lib/python3.6/site-packages
建立文件
tensorflow_model.pth
文件内容如下:
/home/zhangjun/Tensorflow/models/research
/home/zhangjun/Tensorflow/models/research/slim

再运行 python object_detection/builders/model_builder_test.py
没有问题了

Ran 7 tests in 0.024sOK

6)接下来,跑一个demo,你可以在这个路径下运行jupyter notebook
报错: jupyter: command not found
路径问题
~/.local/bin/jupyter-notebook

找不到 /object_detection/object_detection_tutorial.ipynb

在 /home/zhangjun/Tensorflow/models/research/object_detection
下面运行 ~/.local/bin/jupyter-notebook
就可以看到了 /object_detection/object_detection_tutorial.ipynb

https://blog.csdn.net/darkeyers/article/details/80245119

最后将 object_detection_tutorial.ipynb 里面的内容转为 python 程序 ssd_test.py, 直接运行: python ssd_test.py 即可

import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
import cv2from 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'# 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 = 90detection_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='')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)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, 4) ]# Size, in inches, of the output images.
IMAGE_SIZE = (12, 8)output_path = ('/home/zhangjun/Tensorflow/models-master/research/object_detection/test_images/result/')with detection_graph.as_default():with tf.Session(graph=detection_graph) as sess:# Definite input and output Tensors for detection_graphimage_tensor = detection_graph.get_tensor_by_name('image_tensor:0')# Each box represents a part of the image where a particular object was detected.detection_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.detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')num_detections = detection_graph.get_tensor_by_name('num_detections:0')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)# Actual detection.(boxes, scores, classes, num) = sess.run([detection_boxes, detection_scores, detection_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)cv2.imwrite(output_path+image_path.split('/')[-1],image_np)#  plt.figure(figsize=IMAGE_SIZE)#  plt.imshow(image_np)#  plt.pause(5)

其中模型 ssd_mobilenet_v1_coco_11_06_2017 是一个文件夹,这个是直接从 https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md 上面下载后解压得到的一个文件夹,放在 models-master/research/object_detection 文件夹里面,

ubunu16.04 TensorFlow object detection API 应用配置相关推荐

  1. 使用tensorflow object detection API 训练自己的目标检测模型 (二)labelImg的安装配置过程

    上一篇博客介绍了goggle的tensorflow object detection API 的配置和使用, 这次介绍一下如何用这个API训练一个私人定制的目标检测模型. 第一步:准备自己的数据集.比 ...

  2. Tensorflow Object detection API 在 Windows10 配置

    Tensorflow Object detection API 在 Windows10 下的配置不如在 Ubuntu 下配置方便,但还是有方法的,介绍一下我的配置流程. 官方目标检测的demo中调用了 ...

  3. Tensorflow object detection API训练自己的目标检测模型 详细配置教程 (一)

    Tensorflow object detection API 简单介绍Tensorflow object detection API: 这个API是基于tensorflow构造的开源框架,易于构建. ...

  4. Ubuntu 16.04 安装Tensorflow Object Detection API (一)

    1.安装Tensorflow 请参考官方说明及其它博客安装tensorflow,要使用Tensorflow Object Detction API,tensorflow版本需1.4及以后版本. 我的系 ...

  5. Tensorflow object detection API 的环境配置

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

  6. Tensorflow object detection API 搭建自己的目标检测模型并迁移到Android上

    参考链接:https://blog.csdn.net/dy_guox/article/details/79111949 之前参考上述一系列博客在Windows10下面成功运行了TensorFlow A ...

  7. Tensorflow object detection API 搭建属于自己的物体识别模型(转载修改)

    Tensorflow object detection API 搭建属于自己的物体识别模型 电脑配置信息 开始搭建环境 测试自带案例 准备训练图片 配置文件与模型 开始训练模型 生成最终的训练文件 测 ...

  8. Tensorflow object detection API 搭建物体识别模型

    ----------------------------------------------------先把别人博客教程跑通-------------------------------------- ...

  9. tensorflow object detection API训练错误解决

    问题描述 tensorflow object detection API训练coco数据集时提示错误:Windows fatal exception: access violation,如下图: Th ...

最新文章

  1. hdu2852(2009多校第四场) 树状数组求区间第k大的数 两种方法
  2. 浅谈 Java 字符串(String, StringBuffer, StringBuilder)
  3. 5g虚拟技术旅游_5G赋能VR产业变革
  4. ip_vs实现分析(2)
  5. jozj3419-最大利润【树形dp】
  6. Linux. C语言中else,if else用法详解,C语言if else用法完全攻略
  7. 使用DynamicObject的自定义动态行为
  8. C语言程序设计第9堂作业
  9. java算法题解法_LeetCode算法题-Ugly Number(Java实现-四种解法)
  10. 交出20分钟后就得到面试通知的一份答卷
  11. python做词典_python实现电子词典
  12. Unity读取内部、外部资源详解
  13. 大数据与AI平台:人工智能+大数据赋能产业供应链智能化风控核动力 PPT分享
  14. 解决Win10系统下运行unity游戏闪退报错问题 包含 人类一败涂地 波西亚时光等
  15. 深圳:由“独角兽”们构建起的硬核科技之城
  16. 微型计算机软件系统分为什么,微型计算机软件微型计算机软件主要包括哪些软件?...
  17. win10+ubuntu16.04双系统双硬盘(SSD+机械硬盘)安装
  18. 如何读博士-2021.06.12
  19. 经典蓝色横向二级导航栏
  20. 淘宝拍立淘以图搜图接口:使用方法和指南

热门文章

  1. Android中对Handler用法的总结
  2. Nature综述:工程微生物组的通用原则和最佳实践
  3. Nature综述:进化病毒毒力的系统发育基因组学
  4. Microbiome:芝麻菜中肠杆菌科主导核心微生物组并贡献抗生素抗性组(简单套路16S+meta+培养组发高分文章)
  5. oracle自动分区maxvalue,分区表中的maxvalue参数设置-Oracle
  6. R语言对dataframe的行数据进行排序(Ordering rows)实战:使用R原生方法、data.table、dplyr等方案
  7. pandas创建时间序列仿真数据并过滤(filter)时间数据:头尾数据、某年的数据、某年某月的数据、某年某月某日的数据、某个时间范围内的数据、truncate函数查看特定时间之前护着之后的数据
  8. R语言Kmeans聚类、抽取聚类簇:fpc包clusterboot函数通过bootstrap重采样的方法评估Kmeans聚类的稳定性、fpc包的kmeansruns函数通过CH准则和ASW获取最优K值
  9. Python执行pyinstaller打包生成的exe文件实战
  10. pandas使用replace函数替换dataframe中的值:replace函数使用正则表达式对dataframe中的值进行替换