TFLite 移动端部署私有模型前 安装 models/research/object_detection 的细节

写在前面

这篇是 TFLite 移动端部署私有模型前 安装 models/research/object_detection 的过程细节,来自于终端信息反馈的打印。因为略有有点繁杂,且不是原篇的重心,所以单独列在这里。

备注:使用 tf 的版本不同,具体流程就不太相同,我下面列的是 tf2 版本的,tf1 的和这个大同小异吧,会处理 slim 等版本差异问题,有点长,就不贴了,没啥营养了。

安装过程

准备 setup.py 文件

setup.py 文件的内容如下,应该放在 models/research 文件夹下:

"""Setup script for object_detection."""

from setuptools import find_packages
from setuptools import setup

REQUIRED_PACKAGES = ['Pillow>=1.0', 'Matplotlib>=2.1', 'Cython>=0.28.1']

setup(
    name='object_detection',
    version='0.1',
    install_requires=REQUIRED_PACKAGES,
    include_package_data=True,
    packages=[p for p in find_packages() if p.startswith('object_detection')],
    description='Tensorflow Object Detection Library',
)

安装命令

从内容看就知道,它在安装 object_detection 这个项目包到你的环境里。
安装命令是:

cd models/research
python3 setup.py build && python3 setup.py install

如果一切顺利的话,安装过程中:

(1)build 文件夹

首先会在 models/research 路径下新建一个 build 文件夹,然后把 models/research/object_detection 的内容都复制到 build 下对应的位置。

running build
running build_py
creating build
creating build/lib
creating build/lib/object_detection
copying object_detection/model_main.py -> build/lib/object_detection
copying object_detection/model_lib_tf2_test.py -> build/lib/object_detection
copying object_detection/model_lib_v2.py -> build/lib/object_detection
copying object_detection/model_tpu_main.py -> build/lib/object_detection
......

(2)egg-info

然后在 models/research 路径下创建 object_detection.egg-info 并写入信息。

running egg_info
creating object_detection.egg-info
writing object_detection.egg-info/PKG-INFO
writing dependency_links to object_detection.egg-info/dependency_links.txt
writing requirements to object_detection.egg-info/requires.txt
writing top-level names to object_detection.egg-info/top_level.txt
writing manifest file 'object_detection.egg-info/SOURCES.txt'
reading manifest file 'object_detection.egg-info/SOURCES.txt'
writing manifest file 'object_detection.egg-info/SOURCES.txt'
......

(3)build -> egg-info

build/lib 下的信息写入到 build/bdist.linux-x86_64/egg/ 中。

running install
running bdist_egg
running egg_info
writing object_detection.egg-info/PKG-INFO
writing dependency_links to object_detection.egg-info/dependency_links.txt
writing requirements to object_detection.egg-info/requires.txt
writing top-level names to object_detection.egg-info/top_level.txt
reading manifest file 'object_detection.egg-info/SOURCES.txt'
writing manifest file 'object_detection.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/object_detection
creating build/bdist.linux-x86_64/egg/object_detection/data_decoders
copying build/lib/object_detection/data_decoders/tf_example_decoder_test.py -> build/bdist.linux-x86_64/egg/object_detection/data_decoders
copying build/lib/object_detection/data_decoders/tf_sequence_example_decoder_test.py -> build/bdist.linux-x86_64/egg/object_detection/data_decoders
copying build/lib/object_detection/data_decoders/__init__.py -> build/bdist.linux-x86_64/egg/object_detection/data_decoders
copying build/lib/object_detection/data_decoders/tf_sequence_example_decoder.py -> build/bdist.linux-x86_64/egg/object_detection/data_decoders
copying build/lib/object_detection/data_decoders/tf_example_decoder.py -> build/bdist.linux-x86_64/egg/object_detection/data_decoders
......

(4)compile egg

编译 build/bdist.linux-x86_64/egg

byte-compiling build/bdist.linux-x86_64/egg/object_detection/data_decoders/tf_example_decoder_test.py to tf_example_decoder_test.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/object_detection/data_decoders/tf_sequence_example_decoder_test.py to tf_sequence_example_decoder_test.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/object_detection/data_decoders/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/object_detection/data_decoders/tf_sequence_example_decoder.py to tf_sequence_example_decoder.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/object_detection/data_decoders/tf_example_decoder.py to tf_example_decoder.cpython-36.pyc
......

(5)install object_detection 0.1

安装 object_detection 0.1

creating dist
creating 'dist/object_detection-0.1-py3.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing object_detection-0.1-py3.6.egg
creating /home/yx-lxd/anaconda3/envs/lxdpy36tf2/lib/python3.6/site-packages/object_detection-0.1-py3.6.egg
Extracting object_detection-0.1-py3.6.egg to /home/yx-lxd/anaconda3/envs/lxdpy36tf2/lib/python3.6/site-packages
Adding object-detection 0.1 to easy-install.pth file

Installed /home/yx-lxd/anaconda3/envs/lxdpy36tf2/lib/python3.6/site-packages/object_detection-0.1-py3.6.egg

(6)process object_detection’s dependencies

处理 object_detection 0.1 的依赖项,可能需要下载东西,下载失败就科学上网。

Processing dependencies for object-detection==0.1
Searching for Cython>=0.28.1
Reading https://pypi.org/simple/Cython/
Downloading https://files.pythonhosted.org/packages/d8/ae/6dd82bb76c0c7f0b8994c295f11ef06d492b40f0a5674dafa66aeb9142a5/Cython-3.0a7-cp36-cp36m-manylinux1_x86_64.whl#sha256=5f54cde8c21fe931683d16b2287f4a00e93d2c87e44b0988d6e30fa58bc0e1ae
Best match: Cython 3.0a7
Processing Cython-3.0a7-cp36-cp36m-manylinux1_x86_64.whl
Installing Cython-3.0a7-cp36-cp36m-manylinux1_x86_64.whl to /home/yx-lxd/anaconda3/envs/lxdpy36tf2/lib/python3.6/site-packages
Adding Cython 3.0a7 to easy-install.pth file
Installing cygdb script to /home/yx-lxd/anaconda3/envs/lxdpy36tf2/bin
Installing cython script to /home/yx-lxd/anaconda3/envs/lxdpy36tf2/bin
Installing cythonize script to /home/yx-lxd/anaconda3/envs/lxdpy36tf2/bin

Installed /home/yx-lxd/anaconda3/envs/lxdpy36tf2/lib/python3.6/site-packages/Cython-3.0a7-py3.6-linux-x86_64.egg
Searching for matplotlib==3.0.0
......
Using /home/yx-lxd/anaconda3/envs/lxdpy36tf2/lib/python3.6/site-packages
Finished processing dependencies for object-detection==0.1

(7)check the object_detection module

检查 object_detection
上面过程结束后,在models/research 路径下,会多 3 个新的文件夹,分别是 build 、dist 和 object _detection.egg-info。
在这里插入图片描述

现在object_detection 0.1 包已经在你的环境中了,如下:
在这里插入图片描述
你可以 import 它,并且看到这个包的相关信息,可以发现包里的内容几乎都能和原本 models/research/object_detection 下面的内容对应,包括 anchor,data,tflite,models 等。

>>> import object_detection
>>> help(object_detection)

Help on package object_detection:

NAME
    object_detection

PACKAGE CONTENTS
    anchor_generators (package)
    box_coders (package)
    builders (package)
    core (package)
    data_decoders (package)
    dataset_tools (package)
    eval_util
    eval_util_test
    export_inference_graph
    export_tflite_graph_lib_tf2
    export_tflite_graph_lib_tf2_test
    export_tflite_graph_tf2
    export_tflite_ssd_graph
    export_tflite_ssd_graph_lib
    export_tflite_ssd_graph_lib_tf1_test
    exporter
    exporter_lib_tf2_test
    exporter_lib_v2
    exporter_main_v2
    exporter_tf1_test
    inference (package)
    inputs
    inputs_test
    legacy (package)
    matchers (package)
    meta_architectures (package)
    metrics (package)
    model_hparams
    model_lib
    model_lib_tf1_test
    model_lib_tf2_test
    model_lib_v2
    model_main
    model_main_tf2
    model_tpu_main
    models (package)
    predictors (package)
    protos (package)
    tpu_exporters (package)
    utils (package)

FILE
    /home/yx-lxd/mobile_work/tensorflow_models/research/object_detection/__init__.py

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值