# Lint as: python2, python3
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
r"""Tool to export an object detection model for inference.
Prepares an object detection tensorflow graph for inference using model
configuration and a trained checkpoint. Outputs associated checkpoint files,
a SavedModel, and a copy of the model config.
The inference graph contains one of three input nodes depending on the user
specified option.
* `image_tensor`: Accepts a uint8 4-D tensor of shape [1, None, None, 3]
* `float_image_tensor`: Accepts a float32 4-D tensor of shape
[1, None, None, 3]
* `encoded_image_string_tensor`: Accepts a 1-D string tensor of shape [None]
containing encoded PNG or JPEG images. Image resolutions are expected to be
the same if more than 1 image is provided.
* `tf_example`: Accepts a 1-D string tensor of shape [None] containing
serialized TFExample protos. Image resolutions are expected to be the same
if more than 1 image is provided.
* `image_and_boxes_tensor`: Accepts a 4-D image tensor of size
[1, None, None, 3] and a boxes tensor of size [1, None, 4] of normalized
bounding boxes. To be able to support this option, the model needs
to implement a predict_masks_from_boxes method. See the documentation
for DetectionFromImageAndBoxModule for details.
and the following output nodes returned by the model.postprocess(..):
* `num_detections`: Outputs float32 tensors of the form [batch]
that specifies the number of valid boxes per image in the batch.
* `detection_boxes`: Outputs float32 tensors of the form
[batch, num_boxes, 4] containing detected boxes.
* `detection_scores`: Outputs float32 tensors of the form
[batch, num_boxes] containing class scores for the detections.
* `detection_classes`: Outputs float32 tensors of the form
[batch, num_boxes] containing classes for the detections.
Example Usage:
--------------
python exporter_main_v2.py \
--input_type image_tensor \
--pipeline_config_path path/to/ssd_inception_v2.config \
--trained_checkpoint_dir path/to/checkpoint \
--output_directory path/to/exported_model_directory
--use_side_inputs True/False \
--side_input_shapes dim_0,dim_1,...dim_a/.../dim_0,dim_1,...,dim_z \
--side_input_names name_a,name_b,...,name_c \
--side_input_types type_1,type_2
The expected output would be in the directory
path/to/exported_model_directory (which is created if it does not exist)
holding two subdirectories (corresponding to checkpoint and SavedModel,
respectively) and a copy of the pipeline config.
Config overrides (see the `config_override` flag) are text protobufs
(also of type pipeline_pb2.TrainEvalPipelineConfig) which are used to override
certain fields in the provided pipeline_config_path. These are useful for
making small changes to the inference graph that differ from the training or
eval config.
Example Usage (in which we change the second stage post-processing score
threshold to be 0.5):
python exporter_main_v2.py \
--input_type image_tensor \
--pipeline_config_path path/to/ssd_inception_v2.config \
--trained_checkpoint_dir path/to/checkpoint \
--output_directory path/to/exported_model_directory \
--config_override " \
model{ \
faster_rcnn { \
second_stage_post_processing { \
batch_non_max_suppression { \
score_threshold: 0.5 \
} \
} \
} \
}"
If side inputs are desired, the following arguments could be appended
(the example below is for Context R-CNN).
--use_side_inputs True \
--side_input_shapes 1,2000,2057/1 \
--side_input_names context_features,valid_context_size \
--side_input_types tf.float32,tf.int32
"""
from absl import app
from absl import flags
import tensorflow.compat.v2 as tf
from google.protobuf import text_format
from object_detection import exporter_lib_v2
from object_detection.protos import pipeline_pb2
tf.enable_v2_behavior()
FLAGS = flags.FLAGS
flags.DEFINE_string('input_type', 'image_tensor', 'Type of input node. Can be '
'one of [`image_tensor`, `encoded_image_string_tensor`, '
'`tf_example`, `float_image_tensor`, '
'`image_and_boxes_tensor`]')
flags.DEFINE_string('pipeline_config_path', None,
'Path to a pipeline_pb2.TrainEvalPipelineConfig config '
'file.')
flags.DEFINE_string('trained_checkpoint_dir', None,
'Path to trained checkpoint directory')
flags.DEFINE_string('output_directory', None, 'Path to write outputs.')
flags.DEFINE_string('config_override', '',
'pipeline_pb2.TrainEvalPipelineConfig '
'text proto to override pipeline_config_path.')
flags.DEFINE_boolean('use_side_inputs', False,
'If True, uses side inputs as well as image inputs.')
flags.DEFINE_string('side_input_shapes', '',
'If use_side_inputs is True, this explicitly sets '
'the shape of the side input tensors to a fixed size. The '
'dimensions are to be provided as a comma-separated list '
'of integers. A value of -1 can be used for unknown '
'dimensions. A `/` denotes a break, starting the shape of '
'the next side input tensor. This flag is required if '
'using side inputs.')
flags.DEFINE_string('side_input_types', '',
'If use_side_inputs is True, this explicitly sets '
'the type of the side input tensors. The '
'dimensions are to be provided as a comma-separated list '
'of types, each of `string`, `integer`, or `float`. '
'This flag is required if using side inputs.')
flags.DEFINE_string('side_input_names', '',
'If use_side_inputs is True, this explicitly sets '
'the names of the side input tensors required by the model '
'assuming the names will be a comma-separated list of '
'strings. This flag is required if using side inputs.')
flags.mark_flag_as_required('pipeline_config_path')
flags.mark_flag_as_required('trained_checkpoint_dir')
flags.mark_flag_as_required('output_directory')
def main(_):
pipeline_config = pipeline_pb2.TrainEvalPipelineConfig()
with tf.io.gfile.GFile(FLAGS.pipeline_config_path, 'r') as f:
text_format.Merge(f.read(), pipeline_config)
text_format.Merge(FLAGS.config_override, pipeline_config)
exporter_lib_v2.export_inference_graph(
FLAGS.input_type, pipeline_config, FLAGS.trained_checkpoint_dir,
FLAGS.output_directory, FLAGS.use_side_inputs, FLAGS.side_input_shapes,
FLAGS.side_input_types, FLAGS.side_input_names)
if __name__ == '__main__':
app.run(main)
没有合适的资源?快使用搜索试试~ 我知道了~
保姆级Tensorflow2.x Object Detection API构建自定义物体检测器项目源码
共509个文件
jpg:260个
xml:200个
index:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 6 下载量 156 浏览量
2022-06-16
11:19:03
上传
评论
收藏 787.27MB 7Z 举报
温馨提示
【物体检测快速入门系列 | 01 】基于Tensorflow2.x Object Detection API构建自定义物体检测器(http://t.csdn.cn/jPCca)博文配套的项目源代码,包含数据集标注,标签映射,标注文件格式转换脚本,训练流水线配置,训练脚本、评估脚本、导出脚本、模型推理脚本,整套自定义物体检测流水线工具链。
资源推荐
资源详情
资源评论
收起资源包目录
保姆级Tensorflow2.x Object Detection API构建自定义物体检测器项目源码 (509个子文件)
checkpoint 610B
checkpoint 166B
checkpoint 166B
checkpoint 165B
pipeline.config 5KB
pipeline.config 5KB
pipeline.config 4KB
pipeline.config 4KB
pipeline.config 4KB
variables.data-00000-of-00001 125.74MB
ckpt-0.data-00000-of-00001 125.66MB
ckpt-4.data-00000-of-00001 83.04MB
ckpt-6.data-00000-of-00001 83.04MB
ckpt-5.data-00000-of-00001 83.04MB
ckpt-3.data-00000-of-00001 83.04MB
variables.data-00000-of-00001 46.38MB
ckpt-0.data-00000-of-00001 46.33MB
variables.data-00000-of-00001 41.72MB
ckpt-0.data-00000-of-00001 41.64MB
ckpt-1.data-00000-of-00001 41.61MB
ckpt-2.data-00000-of-00001 41.61MB
ssd_mobilenet_v1_fpn_640x640_coco17_tpu-8.tar.gz 86.26MB
ckpt-6.index 40KB
ckpt-3.index 40KB
ckpt-4.index 40KB
ckpt-5.index 40KB
ckpt-1.index 22KB
ckpt-2.index 22KB
ckpt-0.index 22KB
variables.index 19KB
ckpt-0.index 7KB
variables.index 7KB
ckpt-0.index 5KB
variables.index 5KB
raccoon-183.jpg 455KB
raccoon-194.jpg 251KB
raccoon-113.jpg 244KB
raccoon-117.jpg 223KB
raccoon-75.jpg 222KB
raccoon-142.jpg 214KB
raccoon-176.jpg 211KB
raccoon-20.jpg 205KB
raccoon-88.jpg 196KB
raccoon-115.jpg 182KB
raccoon-33.jpg 180KB
raccoon-174.jpg 177KB
raccoon-194.jpg 173KB
raccoon-103.jpg 170KB
raccoon-186.jpg 166KB
raccoon-130.jpg 162KB
raccoon-22.jpg 159KB
raccoon-112.jpg 159KB
raccoon-199.jpg 151KB
raccoon-94.jpg 148KB
raccoon-36.jpg 140KB
raccoon-25.jpg 140KB
raccoon-145.jpg 139KB
raccoon-74.jpg 139KB
raccoon-52.jpg 139KB
raccoon-51.jpg 136KB
raccoon-191.jpg 135KB
raccoon-111.jpg 134KB
raccoon-147.jpg 131KB
raccoon-92.jpg 130KB
raccoon-135.jpg 128KB
raccoon-193.jpg 125KB
raccoon-41.jpg 122KB
raccoon-101.jpg 122KB
raccoon-28.jpg 118KB
raccoon-133.jpg 116KB
raccoon-100.jpg 115KB
raccoon-57.jpg 115KB
raccoon-11.jpg 114KB
raccoon-116.jpg 114KB
raccoon-119.jpg 114KB
raccoon-14.jpg 110KB
raccoon-63.jpg 109KB
raccoon-168.jpg 107KB
raccoon-181.jpg 106KB
raccoon-66.jpg 106KB
raccoon-154.jpg 105KB
raccoon-153.jpg 105KB
raccoon-81.jpg 104KB
raccoon-169.jpg 104KB
raccoon-179.jpg 103KB
raccoon-55.jpg 101KB
raccoon-79.jpg 101KB
raccoon-16.jpg 101KB
raccoon-45.jpg 100KB
raccoon-9.jpg 100KB
raccoon-105.jpg 98KB
raccoon-62.jpg 96KB
raccoon-71.jpg 96KB
raccoon-111.jpg 94KB
raccoon-68.jpg 94KB
raccoon-107.jpg 93KB
raccoon-27.jpg 92KB
raccoon-90.jpg 91KB
raccoon-108.jpg 90KB
raccoon-174.jpg 90KB
共 509 条
- 1
- 2
- 3
- 4
- 5
- 6
机器未来
- 粉丝: 1w+
- 资源: 2
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页