├── .idea
├── .gitignore
├── Nested_PPE_detection-master.iml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
└── vcs.xml
├── LICENSE
├── Main.py
├── PPE_Results.jpg
├── README.md
├── anchor_generators
├── grid_anchor_generator.py
├── grid_anchor_generator_test.py
├── multiple_grid_anchor_generator.py
├── multiple_grid_anchor_generator_test.py
├── multiscale_grid_anchor_generator.py
└── multiscale_grid_anchor_generator_test.py
├── box_coders
├── faster_rcnn_box_coder.py
├── faster_rcnn_box_coder_test.py
├── keypoint_box_coder.py
├── keypoint_box_coder_test.py
├── mean_stddev_box_coder.py
├── mean_stddev_box_coder_test.py
├── square_box_coder.py
└── square_box_coder_test.py
├── builders
├── anchor_generator_builder.py
├── anchor_generator_builder_test.py
├── box_coder_builder.py
├── box_coder_builder_test.py
├── box_predictor_builder.py
├── box_predictor_builder_test.py
├── dataset_builder.py
├── dataset_builder_test.py
├── graph_rewriter_builder.py
├── graph_rewriter_builder_test.py
├── hyperparams_builder.py
├── hyperparams_builder_test.py
├── image_resizer_builder.py
├── image_resizer_builder_test.py
├── input_reader_builder.py
├── input_reader_builder_test.py
├── losses_builder.py
├── losses_builder_test.py
├── matcher_builder.py
├── matcher_builder_test.py
├── model_builder.py
├── model_builder_test.py
├── optimizer_builder.py
├── optimizer_builder_test.py
├── post_processing_builder.py
├── post_processing_builder_test.py
├── preprocessor_builder.py
├── preprocessor_builder_test.py
├── region_similarity_calculator_builder.py
└── region_similarity_calculator_builder_test.py
├── cocoapi
├── LuaAPI
│ ├── CocoApi.lua
│ ├── MaskApi.lua
│ ├── cocoDemo.lua
│ ├── env.lua
│ ├── init.lua
│ └── rocks
│ │ └── coco-scm-1.rockspec
├── MatlabAPI
│ ├── CocoApi.m
│ ├── CocoEval.m
│ ├── CocoUtils.m
│ ├── MaskApi.m
│ ├── cocoDemo.m
│ ├── evalDemo.m
│ ├── gason.m
│ └── private
│ │ ├── gasonMex.cpp
│ │ ├── gasonMex.mexa64
│ │ ├── gasonMex.mexmaci64
│ │ ├── getPrmDflt.m
│ │ └── maskApiMex.c
├── PythonAPI
│ ├── Makefile
│ ├── build
│ │ ├── lib.win-amd64-3.5
│ │ │ └── pycocotools
│ │ │ │ └── _mask.cp35-win_amd64.pyd
│ │ ├── lib.win-amd64-3.6
│ │ │ └── pycocotools
│ │ │ │ ├── __init__.py
│ │ │ │ ├── _mask.cp36-win_amd64.pyd
│ │ │ │ ├── coco.py
│ │ │ │ ├── cocoeval.py
│ │ │ │ └── mask.py
│ │ ├── temp.win-amd64-3.5
│ │ │ ├── Release
│ │ │ │ └── pycocotools
│ │ │ │ │ └── _mask.o
│ │ │ └── common
│ │ │ │ ├── _mask.cp35-win_amd64.def
│ │ │ │ └── maskapi.o
│ │ └── temp.win-amd64-3.6
│ │ │ ├── Release
│ │ │ └── pycocotools
│ │ │ │ └── _mask.obj
│ │ │ └── common
│ │ │ ├── _mask.cp36-win_amd64.exp
│ │ │ ├── _mask.cp36-win_amd64.lib
│ │ │ └── maskApi.obj
│ ├── dist
│ │ └── pycocotools-2.0-py3.6-win-amd64.egg
│ ├── pycocoDemo.ipynb
│ ├── pycocoEvalDemo.ipynb
│ ├── pycocotools.egg-info
│ │ ├── PKG-INFO
│ │ ├── SOURCES.txt
│ │ ├── dependency_links.txt
│ │ ├── requires.txt
│ │ └── top_level.txt
│ ├── pycocotools
│ │ ├── __init__.py
│ │ ├── _mask.c
│ │ ├── _mask.cp35-win_amd64.pyd
│ │ ├── _mask.cp36-win_amd64.pyd
│ │ ├── _mask.pyx
│ │ ├── coco.py
│ │ ├── cocoeval.py
│ │ └── mask.py
│ └── setup.py
├── README.txt
├── common
│ ├── gason.cpp
│ ├── gason.h
│ ├── maskApi.c
│ └── maskApi.h
├── license.txt
└── results
│ ├── captions_val2014_fakecap_results.json
│ ├── instances_val2014_fakebbox100_results.json
│ ├── instances_val2014_fakesegm100_results.json
│ ├── person_keypoints_val2014_fakekeypoints100_results.json
│ └── val2014_fake_eval_res.txt
├── core
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-36.pyc
│ ├── __init__.cpython-37.pyc
│ ├── anchor_generator.cpython-37.pyc
│ ├── balanced_positive_negative_sampler.cpython-37.pyc
│ ├── batcher.cpython-37.pyc
│ ├── box_coder.cpython-37.pyc
│ ├── box_list.cpython-37.pyc
│ ├── box_list_ops.cpython-37.pyc
│ ├── box_predictor.cpython-37.pyc
│ ├── data_decoder.cpython-37.pyc
│ ├── data_parser.cpython-37.pyc
│ ├── freezable_batch_norm.cpython-37.pyc
│ ├── keypoint_ops.cpython-37.pyc
│ ├── losses.cpython-37.pyc
│ ├── matcher.cpython-37.pyc
│ ├── minibatch_sampler.cpython-37.pyc
│ ├── model.cpython-37.pyc
│ ├── post_processing.cpython-37.pyc
│ ├── prefetcher.cpython-37.pyc
│ ├── preprocessor.cpython-37.pyc
│ ├── preprocessor_cache.cpython-37.pyc
│ ├── region_similarity_calculator.cpython-37.pyc
│ ├── standard_fields.cpython-36.pyc
│ ├── standard_fields.cpython-37.pyc
│ └── target_assigner.cpython-37.pyc
├── anchor_generator.py
├── balanced_positive_negative_sampler.py
├── balanced_positive_negative_sampler_test.py
├── batcher.py
├── batcher_test.py
├── box_coder.py
├── box_coder_test.py
├── box_list.py
├── box_list_ops.py
├── box_list_ops_test.py
├── box_list_test.py
├── box_predictor.py
├── data_decoder.py
├── data_parser.py
├── freezable_batch_norm.py
├── freezable_batch_norm_test.py
├── keypoint_ops.py
├── keypoint_ops_test.py
├── losses.py
├── losses_test.py
├── matcher.py
├── matcher_test.py
├── minibatch_sampler.py
├── minibatch_sampler_test.py
├── model.py
├── post_processing.py
├── post_processing_test.py
├── prefetcher.py
├── prefetcher_test.py
├── preprocessor.py
├── preprocessor_cache.py
├── preprocessor_test.py
├── region_similarity_calculator.py
├── region_similarity_calculator_test.py
├── standard_fields.py
├── target_assigner.py
└── target_assigner_test.py
├── data_decoders
├── tf_example_decoder.py
└── tf_example_decoder_test.py
├── inference
├── Confusion.py
├── detection_inference.py
└── detection_inference_test.py
├── label_map_PPE.pbtxt
├── label_map_person.pbtxt
├── legacy
├── eval.py
├── evaluator.py
├── trainer.py
└── trainer_test.py
├── matchers
├── argmax_matcher.py
├── argmax_matcher_test.py
├── bipartite_matcher.py
└── bipartite_matcher_test.py
├── meta_architectures
├── faster_rcnn_meta_arch.py
├── faster_rcnn_meta_arch_test.py
├── faster_rcnn_meta_arch_test_lib.py
├── rfcn_meta_arch.py
├── rfcn_meta_arch_test.py
├── ssd_meta_arch.py
├── ssd_meta_arch_test.py
└── ssd_meta_arch_test_lib.py
├── metrics
├── coco_evaluation.py
├── coco_evaluation_test.py
├── coco_tools.py
├── coco_tools_test.py
├── io_utils.py
├── offline_eval_map_corloc.py
├── offline_eval_map_corloc_test.py
├── oid_od_challenge_evaluation.py
├── oid_od_challenge_evaluation_utils.py
├── oid_od_challenge_evaluation_utils_test.py
├── oid_vrd_challenge_evaluation.py
├── oid_vrd_challenge_evaluation_utils.py
├── oid_vrd_challenge_evaluation_utils_test.py
├── tf_example_parser.py
└── tf_example_parser_test.py
├── models
├── embedded_ssd_mobilenet_v1_feature_extractor.py
├── embedded_ssd_mobilenet_v1_feature_extractor_test.py
├── faster_rcnn_inception_resnet_v2_feature_extractor.py
├── faster_rcnn_inception_resnet_v2_feature_extractor_test.py
├── faster_rcnn_inception_v2_feature_extractor.py
├── faster_rcnn_inception_v2_feature_extractor_test.py
├── faster_rcnn_mobilenet_v1_feature_extractor.py
├── faster_rcnn_mobilenet_v1_feature_extractor_test.py
├── faster_rcnn_nas_feature_extractor.py
├── faster_rcnn_nas_feature_extractor_test.py
├── faster_rcnn_pnas_feature_extractor.py
├── faster_rcnn_pnas_feature_extractor_test.py
├── faster_rcnn_resnet_v1_feature_extractor.py
├── faster_rcnn_resnet_v1_feature_extractor_test.py
├── feature_map_generators.py
├── feature_map_generators_test.py
└── keras_applications
│ ├── mobilenet_v2.py
│ └── mobilenet_v2_test.py
├── nested_detection.py
├── predictors
├── convolutional_box_predictor.py
├── convolutional_box_predictor_test.py
├── convolutional_keras_box_predictor.py
├── convolutional_keras_box_predictor_test.py
└── heads
│ ├── box_head.py
│ ├── box_head_test.py
│ ├── class_head.py
│ ├── class_head_test.py
│ ├── head.py
│ ├── keras_box_head.py
│ ├── keras_box_head_test.py
│ ├── keras_class_head.py
│ ├── keras_class_head_test.py
│ ├── keras_mask_head.py
│ ├── keras_mask_head_test.py
│ ├── keypoint_head.py
│ ├── keypoint_head_test.py
│ ├── mask_head.py
│ └── mask_head_test.py
├── protos
├── anchor_generator.proto
├── anchor_generator_pb2.py
├── argmax_matcher.proto
├── argmax_matcher_pb2.py
├── bipartite_matcher.proto
├── bipartite_matcher_pb2.py
├── box_coder.proto
├── box_coder_pb2.py
├── box_predictor.proto
├── box_predictor_pb2.py
├── eval.proto
├── eval_pb2.py
├── faster_rcnn.proto
├── faster_rcnn_box_coder.proto
├── faster_rcnn_box_coder_pb2.py
├── faster_rcnn_pb2.py
├── graph_rewriter.proto
├── graph_rewriter_pb2.py
├── grid_anchor_generator.proto
├── grid_anchor_generator_pb2.py
├── hyperparams.proto
├── hyperparams_pb2.py
├── image_resizer.proto
├── image_resizer_pb2.py
├── input_reader.proto
├── input_reader_pb2.py
├── keypoint_box_coder.proto
├── keypoint_box_coder_pb2.py
├── losses.proto
├── losses_pb2.py
├── matcher.proto
├── matcher_pb2.py
├── mean_stddev_box_coder.proto
├── mean_stddev_box_coder_pb2.py
├── model.proto
├── model_pb2.py
├── multiscale_anchor_generator.proto
├── multiscale_anchor_generator_pb2.py
├── optimizer.proto
├── optimizer_pb2.py
├── pipeline.proto
├── pipeline_pb2.py
├── post_processing.proto
├── post_processing_pb2.py
├── preprocessor.proto
├── preprocessor_pb2.py
├── region_similarity_calculator.proto
├── region_similarity_calculator_pb2.py
├── square_box_coder.proto
├── square_box_coder_pb2.py
├── ssd.proto
├── ssd_anchor_generator.proto
├── ssd_anchor_generator_pb2.py
├── ssd_pb2.py
├── string_int_label_map.proto
├── string_int_label_map_pb2.py
├── train.proto
└── train_pb2.py
├── pyimagesearch
└── centroidtracker.py
├── samples
├── cloud
│ └── cloud.yml
└── configs
│ ├── embedded_ssd_mobilenet_v1_coco.config
│ ├── facessd_mobilenet_v2_quantized_320x320_open_image_v4.config
│ ├── faster_rcnn_inception_resnet_v2_atrous_coco.config
│ ├── faster_rcnn_inception_resnet_v2_atrous_cosine_lr_coco.config
│ ├── faster_rcnn_inception_resnet_v2_atrous_oid.config
│ ├── faster_rcnn_inception_resnet_v2_atrous_pets.config
│ ├── faster_rcnn_inception_v2_coco.config
│ ├── faster_rcnn_inception_v2_pets.config
│ ├── faster_rcnn_nas_coco.config
│ ├── faster_rcnn_resnet101_atrous_coco.config
│ ├── faster_rcnn_resnet101_ava_v2.1.config
│ ├── faster_rcnn_resnet101_coco.config
│ ├── faster_rcnn_resnet101_fgvc.config
│ ├── faster_rcnn_resnet101_kitti.config
│ ├── faster_rcnn_resnet101_pets.config
│ ├── faster_rcnn_resnet101_voc07.config
│ ├── faster_rcnn_resnet152_coco.config
│ ├── faster_rcnn_resnet152_pets.config
│ ├── faster_rcnn_resnet50_coco.config
│ ├── faster_rcnn_resnet50_fgvc.config
│ ├── faster_rcnn_resnet50_pets.config
│ ├── mask_rcnn_inception_resnet_v2_atrous_coco.config
│ ├── mask_rcnn_inception_v2_coco.config
│ ├── mask_rcnn_resnet101_atrous_coco.config
│ ├── mask_rcnn_resnet101_pets.config
│ ├── mask_rcnn_resnet50_atrous_coco.config
│ ├── rfcn_resnet101_coco.config
│ ├── rfcn_resnet101_pets.config
│ ├── ssd_inception_v2_coco.config
│ ├── ssd_inception_v2_pets.config
│ ├── ssd_inception_v3_pets.config
│ ├── ssd_mobilenet_v1_0.75_depth_300x300_coco14_sync.config
│ ├── ssd_mobilenet_v1_0.75_depth_quantized_300x300_coco14_sync.config
│ ├── ssd_mobilenet_v1_0.75_depth_quantized_300x300_pets_sync.config
│ ├── ssd_mobilenet_v1_300x300_coco14_sync.config
│ ├── ssd_mobilenet_v1_coco.config
│ ├── ssd_mobilenet_v1_focal_loss_pets.config
│ ├── ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync.config
│ ├── ssd_mobilenet_v1_pets.config
│ ├── ssd_mobilenet_v1_ppn_shared_box_predictor_300x300_coco14_sync.config
│ ├── ssd_mobilenet_v1_quantized_300x300_coco14_sync.config
│ ├── ssd_mobilenet_v2_coco.config
│ ├── ssd_mobilenet_v2_quantized_300x300_coco.config
│ ├── ssd_resnet50_v1_fpn_shared_box_predictor_640x640_coco14_sync.config
│ ├── ssdlite_mobilenet_v1_coco.config
│ └── ssdlite_mobilenet_v2_coco.config
├── training
└── checkpoint
└── utils
├── app_utils.py
├── category_util.py
├── category_util_test.py
├── config_util.py
├── config_util_test.py
├── context_manager.py
├── context_manager_test.py
├── dataset_util.py
├── dataset_util_test.py
├── json_utils.py
├── json_utils_test.py
├── label_map_util.py
├── label_map_util_test.py
├── learning_schedules.py
├── learning_schedules_test.py
├── metrics.py
├── metrics_test.py
├── np_box_list.py
├── np_box_list_ops.py
├── np_box_list_ops_test.py
├── np_box_list_test.py
├── np_box_mask_list.py
├── np_box_mask_list_ops.py
├── np_box_mask_list_ops_test.py
├── np_box_mask_list_test.py
├── np_box_ops.py
├── np_box_ops_test.py
├── np_mask_ops.py
├── np_mask_ops_test.py
├── object_detection_evaluation.py
├── object_detection_evaluation_test.py
├── ops.py
├── ops_test.py
├── per_image_evaluation.py
├── per_image_evaluation_test.py
├── per_image_vrd_evaluation.py
├── per_image_vrd_evaluation_test.py
├── shape_utils.py
├── shape_utils_test.py
├── static_shape.py
├── static_shape_test.py
├── test_case.py
├── test_utils.py
├── test_utils_test.py
├── variables_helper.py
├── variables_helper_test.py
├── visualization_utils.py
├── visualization_utils_PPE.py
├── visualization_utils_original.py
├── visualization_utils_works.py
├── vrd_evaluation.py
└── vrd_evaluation_test.py
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /../../../:\Nested_PPE_detection-master\.idea/dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/.idea/Nested_PPE_detection-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Mohammad Akbarzadeh
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Main.py:
--------------------------------------------------------------------------------
1 | # Author Mohammad Akbarzadeh
2 | # https://github.com/mohammadakz
3 |
4 | # Importing nested detection class
5 | import os
6 | from nested_detection import Nested_Detection
7 |
8 | # Model and video file names and path
9 | CWD_PATH = os.getcwd()
10 |
11 | model_name = 'inference_graph_50000_balance'
12 | video_name = 'mk2.mp4'
13 | out_put = 'out_put/results_{}.avi'.format(video_name[:-4])
14 | label_path = 'label_map_person.pbtxt'
15 |
16 | # Performing the detection
17 | dt = Nested_Detection()
18 | dt.worker_detection(model_name, label_path, video_name, out_put)
19 |
--------------------------------------------------------------------------------
/PPE_Results.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/PPE_Results.jpg
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Nested_PPE_detection
2 |
This project is the implementation of conference paper entitled "Nested Network for Detecting PPE on Large Construction Sites Based on Frame Segmentation".\
3 | ## The main goals of the project are:
4 |
5 |
(1) Detect workers in near, mid, and far-field views.
6 |
(2) Detect hardhat, no-hardhat, safety vest, and no safety vest.
7 |
(3) Matching detected workers in two camera views.
8 |
(4) Generating PPE detection safety reports.
9 |
10 |
In order to run the Nested network for worker and PPE detection:
11 | ```
12 | Main.py
13 | ```
14 | The image below shows PPE detection results in near, mid, and far-field views.
15 |
16 | 
17 |
--------------------------------------------------------------------------------
/box_coders/mean_stddev_box_coder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Mean stddev box coder.
17 |
18 | This box coder use the following coding schema to encode boxes:
19 | rel_code = (box_corner - anchor_corner_mean) / anchor_corner_stddev.
20 | """
21 | from object_detection.core import box_coder
22 | from object_detection.core import box_list
23 |
24 |
25 | class MeanStddevBoxCoder(box_coder.BoxCoder):
26 | """Mean stddev box coder."""
27 |
28 | def __init__(self, stddev=0.01):
29 | """Constructor for MeanStddevBoxCoder.
30 |
31 | Args:
32 | stddev: The standard deviation used to encode and decode boxes.
33 | """
34 | self._stddev = stddev
35 |
36 | @property
37 | def code_size(self):
38 | return 4
39 |
40 | def _encode(self, boxes, anchors):
41 | """Encode a box collection with respect to anchor collection.
42 |
43 | Args:
44 | boxes: BoxList holding N boxes to be encoded.
45 | anchors: BoxList of N anchors.
46 |
47 | Returns:
48 | a tensor representing N anchor-encoded boxes
49 |
50 | Raises:
51 | ValueError: if the anchors still have deprecated stddev field.
52 | """
53 | box_corners = boxes.get()
54 | if anchors.has_field('stddev'):
55 | raise ValueError("'stddev' is a parameter of MeanStddevBoxCoder and "
56 | "should not be specified in the box list.")
57 | means = anchors.get()
58 | return (box_corners - means) / self._stddev
59 |
60 | def _decode(self, rel_codes, anchors):
61 | """Decode.
62 |
63 | Args:
64 | rel_codes: a tensor representing N anchor-encoded boxes.
65 | anchors: BoxList of anchors.
66 |
67 | Returns:
68 | boxes: BoxList holding N bounding boxes
69 |
70 | Raises:
71 | ValueError: if the anchors still have deprecated stddev field and expects
72 | the decode method to use stddev value from that field.
73 | """
74 | means = anchors.get()
75 | if anchors.has_field('stddev'):
76 | raise ValueError("'stddev' is a parameter of MeanStddevBoxCoder and "
77 | "should not be specified in the box list.")
78 | box_corners = rel_codes * self._stddev + means
79 | return box_list.BoxList(box_corners)
80 |
--------------------------------------------------------------------------------
/box_coders/mean_stddev_box_coder_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.box_coder.mean_stddev_boxcoder."""
17 |
18 | import tensorflow as tf
19 |
20 | from object_detection.box_coders import mean_stddev_box_coder
21 | from object_detection.core import box_list
22 |
23 |
24 | class MeanStddevBoxCoderTest(tf.test.TestCase):
25 |
26 | def testGetCorrectRelativeCodesAfterEncoding(self):
27 | box_corners = [[0.0, 0.0, 0.5, 0.5], [0.0, 0.0, 0.5, 0.5]]
28 | boxes = box_list.BoxList(tf.constant(box_corners))
29 | expected_rel_codes = [[0.0, 0.0, 0.0, 0.0], [-5.0, -5.0, -5.0, -3.0]]
30 | prior_means = tf.constant([[0.0, 0.0, 0.5, 0.5], [0.5, 0.5, 1.0, 0.8]])
31 | priors = box_list.BoxList(prior_means)
32 |
33 | coder = mean_stddev_box_coder.MeanStddevBoxCoder(stddev=0.1)
34 | rel_codes = coder.encode(boxes, priors)
35 | with self.test_session() as sess:
36 | rel_codes_out = sess.run(rel_codes)
37 | self.assertAllClose(rel_codes_out, expected_rel_codes)
38 |
39 | def testGetCorrectBoxesAfterDecoding(self):
40 | rel_codes = tf.constant([[0.0, 0.0, 0.0, 0.0], [-5.0, -5.0, -5.0, -3.0]])
41 | expected_box_corners = [[0.0, 0.0, 0.5, 0.5], [0.0, 0.0, 0.5, 0.5]]
42 | prior_means = tf.constant([[0.0, 0.0, 0.5, 0.5], [0.5, 0.5, 1.0, 0.8]])
43 | priors = box_list.BoxList(prior_means)
44 |
45 | coder = mean_stddev_box_coder.MeanStddevBoxCoder(stddev=0.1)
46 | decoded_boxes = coder.decode(rel_codes, priors)
47 | decoded_box_corners = decoded_boxes.get()
48 | with self.test_session() as sess:
49 | decoded_out = sess.run(decoded_box_corners)
50 | self.assertAllClose(decoded_out, expected_box_corners)
51 |
52 |
53 | if __name__ == '__main__':
54 | tf.test.main()
55 |
--------------------------------------------------------------------------------
/builders/box_coder_builder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """A function to build an object detection box coder from configuration."""
17 | from object_detection.box_coders import faster_rcnn_box_coder
18 | from object_detection.box_coders import keypoint_box_coder
19 | from object_detection.box_coders import mean_stddev_box_coder
20 | from object_detection.box_coders import square_box_coder
21 | from object_detection.protos import box_coder_pb2
22 |
23 |
24 | def build(box_coder_config):
25 | """Builds a box coder object based on the box coder config.
26 |
27 | Args:
28 | box_coder_config: A box_coder.proto object containing the config for the
29 | desired box coder.
30 |
31 | Returns:
32 | BoxCoder based on the config.
33 |
34 | Raises:
35 | ValueError: On empty box coder proto.
36 | """
37 | if not isinstance(box_coder_config, box_coder_pb2.BoxCoder):
38 | raise ValueError('box_coder_config not of type box_coder_pb2.BoxCoder.')
39 |
40 | if box_coder_config.WhichOneof('box_coder_oneof') == 'faster_rcnn_box_coder':
41 | return faster_rcnn_box_coder.FasterRcnnBoxCoder(scale_factors=[
42 | box_coder_config.faster_rcnn_box_coder.y_scale,
43 | box_coder_config.faster_rcnn_box_coder.x_scale,
44 | box_coder_config.faster_rcnn_box_coder.height_scale,
45 | box_coder_config.faster_rcnn_box_coder.width_scale
46 | ])
47 | if box_coder_config.WhichOneof('box_coder_oneof') == 'keypoint_box_coder':
48 | return keypoint_box_coder.KeypointBoxCoder(
49 | box_coder_config.keypoint_box_coder.num_keypoints,
50 | scale_factors=[
51 | box_coder_config.keypoint_box_coder.y_scale,
52 | box_coder_config.keypoint_box_coder.x_scale,
53 | box_coder_config.keypoint_box_coder.height_scale,
54 | box_coder_config.keypoint_box_coder.width_scale
55 | ])
56 | if (box_coder_config.WhichOneof('box_coder_oneof') ==
57 | 'mean_stddev_box_coder'):
58 | return mean_stddev_box_coder.MeanStddevBoxCoder(
59 | stddev=box_coder_config.mean_stddev_box_coder.stddev)
60 | if box_coder_config.WhichOneof('box_coder_oneof') == 'square_box_coder':
61 | return square_box_coder.SquareBoxCoder(scale_factors=[
62 | box_coder_config.square_box_coder.y_scale,
63 | box_coder_config.square_box_coder.x_scale,
64 | box_coder_config.square_box_coder.length_scale
65 | ])
66 | raise ValueError('Empty box coder.')
67 |
--------------------------------------------------------------------------------
/builders/graph_rewriter_builder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Functions for quantized training and evaluation."""
16 |
17 | import tensorflow as tf
18 |
19 |
20 | def build(graph_rewriter_config, is_training):
21 | """Returns a function that modifies default graph based on options.
22 |
23 | Args:
24 | graph_rewriter_config: graph_rewriter_pb2.GraphRewriter proto.
25 | is_training: whether in training of eval mode.
26 | """
27 | def graph_rewrite_fn():
28 | """Function to quantize weights and activation of the default graph."""
29 | if (graph_rewriter_config.quantization.weight_bits != 8 or
30 | graph_rewriter_config.quantization.activation_bits != 8):
31 | raise ValueError('Only 8bit quantization is supported')
32 |
33 | # Quantize the graph by inserting quantize ops for weights and activations
34 | if is_training:
35 | tf.contrib.quantize.create_training_graph(
36 | input_graph=tf.get_default_graph(),
37 | quant_delay=graph_rewriter_config.quantization.delay)
38 | else:
39 | tf.contrib.quantize.create_eval_graph(input_graph=tf.get_default_graph())
40 |
41 | tf.contrib.layers.summarize_collection('quant_vars')
42 | return graph_rewrite_fn
43 |
--------------------------------------------------------------------------------
/builders/graph_rewriter_builder_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Tests for graph_rewriter_builder."""
16 | import mock
17 | import tensorflow as tf
18 | from object_detection.builders import graph_rewriter_builder
19 | from object_detection.protos import graph_rewriter_pb2
20 |
21 |
22 | class QuantizationBuilderTest(tf.test.TestCase):
23 |
24 | def testQuantizationBuilderSetsUpCorrectTrainArguments(self):
25 | with mock.patch.object(
26 | tf.contrib.quantize, 'create_training_graph') as mock_quant_fn:
27 | with mock.patch.object(tf.contrib.layers,
28 | 'summarize_collection') as mock_summarize_col:
29 | graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
30 | graph_rewriter_proto.quantization.delay = 10
31 | graph_rewriter_proto.quantization.weight_bits = 8
32 | graph_rewriter_proto.quantization.activation_bits = 8
33 | graph_rewrite_fn = graph_rewriter_builder.build(
34 | graph_rewriter_proto, is_training=True)
35 | graph_rewrite_fn()
36 | _, kwargs = mock_quant_fn.call_args
37 | self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
38 | self.assertEqual(kwargs['quant_delay'], 10)
39 | mock_summarize_col.assert_called_with('quant_vars')
40 |
41 | def testQuantizationBuilderSetsUpCorrectEvalArguments(self):
42 | with mock.patch.object(tf.contrib.quantize,
43 | 'create_eval_graph') as mock_quant_fn:
44 | with mock.patch.object(tf.contrib.layers,
45 | 'summarize_collection') as mock_summarize_col:
46 | graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
47 | graph_rewriter_proto.quantization.delay = 10
48 | graph_rewrite_fn = graph_rewriter_builder.build(
49 | graph_rewriter_proto, is_training=False)
50 | graph_rewrite_fn()
51 | _, kwargs = mock_quant_fn.call_args
52 | self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
53 | mock_summarize_col.assert_called_with('quant_vars')
54 |
55 |
56 | if __name__ == '__main__':
57 | tf.test.main()
58 |
--------------------------------------------------------------------------------
/builders/input_reader_builder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Input reader builder.
17 |
18 | Creates data sources for DetectionModels from an InputReader config. See
19 | input_reader.proto for options.
20 |
21 | Note: If users wishes to also use their own InputReaders with the Object
22 | Detection configuration framework, they should define their own builder function
23 | that wraps the build function.
24 | """
25 |
26 | import tensorflow as tf
27 |
28 | from object_detection.data_decoders import tf_example_decoder
29 | from object_detection.protos import input_reader_pb2
30 |
31 | parallel_reader = tf.contrib.slim.parallel_reader
32 |
33 |
34 | def build(input_reader_config):
35 | """Builds a tensor dictionary based on the InputReader config.
36 |
37 | Args:
38 | input_reader_config: A input_reader_pb2.InputReader object.
39 |
40 | Returns:
41 | A tensor dict based on the input_reader_config.
42 |
43 | Raises:
44 | ValueError: On invalid input reader proto.
45 | ValueError: If no input paths are specified.
46 | """
47 | if not isinstance(input_reader_config, input_reader_pb2.InputReader):
48 | raise ValueError('input_reader_config not of type '
49 | 'input_reader_pb2.InputReader.')
50 |
51 | if input_reader_config.WhichOneof('input_reader') == 'tf_record_input_reader':
52 | config = input_reader_config.tf_record_input_reader
53 | if not config.input_path:
54 | raise ValueError('At least one input path must be specified in '
55 | '`input_reader_config`.')
56 | _, string_tensor = parallel_reader.parallel_read(
57 | config.input_path[:], # Convert `RepeatedScalarContainer` to list.
58 | reader_class=tf.TFRecordReader,
59 | num_epochs=(input_reader_config.num_epochs
60 | if input_reader_config.num_epochs else None),
61 | num_readers=input_reader_config.num_readers,
62 | shuffle=input_reader_config.shuffle,
63 | dtypes=[tf.string, tf.string],
64 | capacity=input_reader_config.queue_capacity,
65 | min_after_dequeue=input_reader_config.min_after_dequeue)
66 |
67 | label_map_proto_file = None
68 | if input_reader_config.HasField('label_map_path'):
69 | label_map_proto_file = input_reader_config.label_map_path
70 | decoder = tf_example_decoder.TfExampleDecoder(
71 | load_instance_masks=input_reader_config.load_instance_masks,
72 | instance_mask_type=input_reader_config.mask_type,
73 | label_map_proto_file=label_map_proto_file)
74 | return decoder.decode(string_tensor)
75 |
76 | raise ValueError('Unsupported input_reader_config.')
77 |
--------------------------------------------------------------------------------
/builders/matcher_builder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """A function to build an object detection matcher from configuration."""
17 |
18 | from object_detection.matchers import argmax_matcher
19 | from object_detection.matchers import bipartite_matcher
20 | from object_detection.protos import matcher_pb2
21 |
22 |
23 | def build(matcher_config):
24 | """Builds a matcher object based on the matcher config.
25 |
26 | Args:
27 | matcher_config: A matcher.proto object containing the config for the desired
28 | Matcher.
29 |
30 | Returns:
31 | Matcher based on the config.
32 |
33 | Raises:
34 | ValueError: On empty matcher proto.
35 | """
36 | if not isinstance(matcher_config, matcher_pb2.Matcher):
37 | raise ValueError('matcher_config not of type matcher_pb2.Matcher.')
38 | if matcher_config.WhichOneof('matcher_oneof') == 'argmax_matcher':
39 | matcher = matcher_config.argmax_matcher
40 | matched_threshold = unmatched_threshold = None
41 | if not matcher.ignore_thresholds:
42 | matched_threshold = matcher.matched_threshold
43 | unmatched_threshold = matcher.unmatched_threshold
44 | return argmax_matcher.ArgMaxMatcher(
45 | matched_threshold=matched_threshold,
46 | unmatched_threshold=unmatched_threshold,
47 | negatives_lower_than_unmatched=matcher.negatives_lower_than_unmatched,
48 | force_match_for_each_row=matcher.force_match_for_each_row,
49 | use_matmul_gather=matcher.use_matmul_gather)
50 | if matcher_config.WhichOneof('matcher_oneof') == 'bipartite_matcher':
51 | matcher = matcher_config.bipartite_matcher
52 | return bipartite_matcher.GreedyBipartiteMatcher(matcher.use_matmul_gather)
53 | raise ValueError('Empty matcher.')
54 |
--------------------------------------------------------------------------------
/builders/region_similarity_calculator_builder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Builder for region similarity calculators."""
17 |
18 | from object_detection.core import region_similarity_calculator
19 | from object_detection.protos import region_similarity_calculator_pb2
20 |
21 |
22 | def build(region_similarity_calculator_config):
23 | """Builds region similarity calculator based on the configuration.
24 |
25 | Builds one of [IouSimilarity, IoaSimilarity, NegSqDistSimilarity] objects. See
26 | core/region_similarity_calculator.proto for details.
27 |
28 | Args:
29 | region_similarity_calculator_config: RegionSimilarityCalculator
30 | configuration proto.
31 |
32 | Returns:
33 | region_similarity_calculator: RegionSimilarityCalculator object.
34 |
35 | Raises:
36 | ValueError: On unknown region similarity calculator.
37 | """
38 |
39 | if not isinstance(
40 | region_similarity_calculator_config,
41 | region_similarity_calculator_pb2.RegionSimilarityCalculator):
42 | raise ValueError(
43 | 'region_similarity_calculator_config not of type '
44 | 'region_similarity_calculator_pb2.RegionsSimilarityCalculator')
45 |
46 | similarity_calculator = region_similarity_calculator_config.WhichOneof(
47 | 'region_similarity')
48 | if similarity_calculator == 'iou_similarity':
49 | return region_similarity_calculator.IouSimilarity()
50 | if similarity_calculator == 'ioa_similarity':
51 | return region_similarity_calculator.IoaSimilarity()
52 | if similarity_calculator == 'neg_sq_dist_similarity':
53 | return region_similarity_calculator.NegSqDistSimilarity()
54 | if similarity_calculator == 'thresholded_iou_similarity':
55 | return region_similarity_calculator.ThresholdedIouSimilarity(
56 | region_similarity_calculator_config.thresholded_iou_similarity.threshold
57 | )
58 |
59 | raise ValueError('Unknown region similarity calculator.')
60 |
--------------------------------------------------------------------------------
/builders/region_similarity_calculator_builder_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for region_similarity_calculator_builder."""
17 |
18 | import tensorflow as tf
19 |
20 | from google.protobuf import text_format
21 | from object_detection.builders import region_similarity_calculator_builder
22 | from object_detection.core import region_similarity_calculator
23 | from object_detection.protos import region_similarity_calculator_pb2 as sim_calc_pb2
24 |
25 |
26 | class RegionSimilarityCalculatorBuilderTest(tf.test.TestCase):
27 |
28 | def testBuildIoaSimilarityCalculator(self):
29 | similarity_calc_text_proto = """
30 | ioa_similarity {
31 | }
32 | """
33 | similarity_calc_proto = sim_calc_pb2.RegionSimilarityCalculator()
34 | text_format.Merge(similarity_calc_text_proto, similarity_calc_proto)
35 | similarity_calc = region_similarity_calculator_builder.build(
36 | similarity_calc_proto)
37 | self.assertTrue(isinstance(similarity_calc,
38 | region_similarity_calculator.IoaSimilarity))
39 |
40 | def testBuildIouSimilarityCalculator(self):
41 | similarity_calc_text_proto = """
42 | iou_similarity {
43 | }
44 | """
45 | similarity_calc_proto = sim_calc_pb2.RegionSimilarityCalculator()
46 | text_format.Merge(similarity_calc_text_proto, similarity_calc_proto)
47 | similarity_calc = region_similarity_calculator_builder.build(
48 | similarity_calc_proto)
49 | self.assertTrue(isinstance(similarity_calc,
50 | region_similarity_calculator.IouSimilarity))
51 |
52 | def testBuildNegSqDistSimilarityCalculator(self):
53 | similarity_calc_text_proto = """
54 | neg_sq_dist_similarity {
55 | }
56 | """
57 | similarity_calc_proto = sim_calc_pb2.RegionSimilarityCalculator()
58 | text_format.Merge(similarity_calc_text_proto, similarity_calc_proto)
59 | similarity_calc = region_similarity_calculator_builder.build(
60 | similarity_calc_proto)
61 | self.assertTrue(isinstance(similarity_calc,
62 | region_similarity_calculator.
63 | NegSqDistSimilarity))
64 |
65 |
66 | if __name__ == '__main__':
67 | tf.test.main()
68 |
--------------------------------------------------------------------------------
/cocoapi/LuaAPI/cocoDemo.lua:
--------------------------------------------------------------------------------
1 | -- Demo for the CocoApi (see CocoApi.lua)
2 | coco = require 'coco'
3 | image = require 'image'
4 |
5 | -- initialize COCO api (please specify dataType/annType below)
6 | annTypes = { 'instances', 'captions', 'person_keypoints' }
7 | dataType, annType = 'val2014', annTypes[1]; -- specify dataType/annType
8 | annFile = '../annotations/'..annType..'_'..dataType..'.json'
9 | cocoApi=coco.CocoApi(annFile)
10 |
11 | -- get all image ids, select one at random
12 | imgIds = cocoApi:getImgIds()
13 | imgId = imgIds[torch.random(imgIds:numel())]
14 |
15 | -- load image
16 | img = cocoApi:loadImgs(imgId)[1]
17 | I = image.load('../images/'..dataType..'/'..img.file_name,3)
18 |
19 | -- load and display instance annotations
20 | annIds = cocoApi:getAnnIds({imgId=imgId})
21 | anns = cocoApi:loadAnns(annIds)
22 | J = cocoApi:showAnns(I,anns)
23 | image.save('RES_'..img.file_name,J:double())
24 |
--------------------------------------------------------------------------------
/cocoapi/LuaAPI/env.lua:
--------------------------------------------------------------------------------
1 | --[[----------------------------------------------------------------------------
2 |
3 | Common Objects in COntext (COCO) Toolbox. version 3.0
4 | Data, paper, and tutorials available at: http://mscoco.org/
5 | Code written by Pedro O. Pinheiro and Piotr Dollar, 2016.
6 | Licensed under the Simplified BSD License [see coco/license.txt]
7 |
8 | ------------------------------------------------------------------------------]]
9 |
10 | local coco = {}
11 | return coco
12 |
--------------------------------------------------------------------------------
/cocoapi/LuaAPI/init.lua:
--------------------------------------------------------------------------------
1 | --[[----------------------------------------------------------------------------
2 |
3 | Common Objects in COntext (COCO) Toolbox. version 3.0
4 | Data, paper, and tutorials available at: http://mscoco.org/
5 | Code written by Pedro O. Pinheiro and Piotr Dollar, 2016.
6 | Licensed under the Simplified BSD License [see coco/license.txt]
7 |
8 | ------------------------------------------------------------------------------]]
9 |
10 | local coco = require 'coco.env'
11 | require 'coco.CocoApi'
12 | require 'coco.MaskApi'
13 | return coco
14 |
--------------------------------------------------------------------------------
/cocoapi/LuaAPI/rocks/coco-scm-1.rockspec:
--------------------------------------------------------------------------------
1 | package = "coco"
2 | version = "scm-1"
3 |
4 | source = {
5 | url = "git://github.com/pdollar/coco.git"
6 | }
7 |
8 | description = {
9 | summary = "Interface for accessing the Microsoft COCO dataset",
10 | detailed = "See http://mscoco.org/ for more details",
11 | homepage = "https://github.com/pdollar/coco",
12 | license = "Simplified BSD"
13 | }
14 |
15 | dependencies = {
16 | "lua >= 5.1",
17 | "torch >= 7.0",
18 | "lua-cjson"
19 | }
20 |
21 | build = {
22 | type = "builtin",
23 | modules = {
24 | ["coco.env"] = "LuaAPI/env.lua",
25 | ["coco.init"] = "LuaAPI/init.lua",
26 | ["coco.MaskApi"] = "LuaAPI/MaskApi.lua",
27 | ["coco.CocoApi"] = "LuaAPI/CocoApi.lua",
28 | libmaskapi = {
29 | sources = { "common/maskApi.c" },
30 | incdirs = { "common/" }
31 | }
32 | }
33 | }
34 |
35 | -- luarocks make LuaAPI/rocks/coco-scm-1.rockspec
36 | -- https://github.com/pdollar/coco/raw/master/LuaAPI/rocks/coco-scm-1.rockspec
37 |
--------------------------------------------------------------------------------
/cocoapi/MatlabAPI/cocoDemo.m:
--------------------------------------------------------------------------------
1 | %% Demo for the CocoApi (see CocoApi.m)
2 |
3 | %% initialize COCO api (please specify dataType/annType below)
4 | annTypes = { 'instances', 'captions', 'person_keypoints' };
5 | dataType='val2014'; annType=annTypes{1}; % specify dataType/annType
6 | annFile=sprintf('../annotations/%s_%s.json',annType,dataType);
7 | coco=CocoApi(annFile);
8 |
9 | %% display COCO categories and supercategories
10 | if( ~strcmp(annType,'captions') )
11 | cats = coco.loadCats(coco.getCatIds());
12 | nms={cats.name}; fprintf('COCO categories: ');
13 | fprintf('%s, ',nms{:}); fprintf('\n');
14 | nms=unique({cats.supercategory}); fprintf('COCO supercategories: ');
15 | fprintf('%s, ',nms{:}); fprintf('\n');
16 | end
17 |
18 | %% get all images containing given categories, select one at random
19 | catIds = coco.getCatIds('catNms',{'person','dog','skateboard'});
20 | imgIds = coco.getImgIds('catIds',catIds);
21 | imgId = imgIds(randi(length(imgIds)));
22 |
23 | %% load and display image
24 | img = coco.loadImgs(imgId);
25 | I = imread(sprintf('../images/%s/%s',dataType,img.file_name));
26 | figure(1); imagesc(I); axis('image'); set(gca,'XTick',[],'YTick',[])
27 |
28 | %% load and display annotations
29 | annIds = coco.getAnnIds('imgIds',imgId,'catIds',catIds,'iscrowd',[]);
30 | anns = coco.loadAnns(annIds); coco.showAnns(anns);
31 |
--------------------------------------------------------------------------------
/cocoapi/MatlabAPI/evalDemo.m:
--------------------------------------------------------------------------------
1 | %% Demo demonstrating the algorithm result formats for COCO
2 |
3 | %% select results type for demo (either bbox or segm)
4 | type = {'segm','bbox','keypoints'}; type = type{1}; % specify type here
5 | fprintf('Running demo for *%s* results.\n\n',type);
6 |
7 | %% initialize COCO ground truth api
8 | dataDir='../'; prefix='instances'; dataType='val2014';
9 | if(strcmp(type,'keypoints')), prefix='person_keypoints'; end
10 | annFile=sprintf('%s/annotations/%s_%s.json',dataDir,prefix,dataType);
11 | cocoGt=CocoApi(annFile);
12 |
13 | %% initialize COCO detections api
14 | resFile='%s/results/%s_%s_fake%s100_results.json';
15 | resFile=sprintf(resFile,dataDir,prefix,dataType,type);
16 | cocoDt=cocoGt.loadRes(resFile);
17 |
18 | %% visialuze gt and dt side by side
19 | imgIds=sort(cocoGt.getImgIds()); imgIds=imgIds(1:100);
20 | imgId = imgIds(randi(100)); img = cocoGt.loadImgs(imgId);
21 | I = imread(sprintf('%s/images/val2014/%s',dataDir,img.file_name));
22 | figure(1); subplot(1,2,1); imagesc(I); axis('image'); axis off;
23 | annIds = cocoGt.getAnnIds('imgIds',imgId); title('ground truth')
24 | anns = cocoGt.loadAnns(annIds); cocoGt.showAnns(anns);
25 | figure(1); subplot(1,2,2); imagesc(I); axis('image'); axis off;
26 | annIds = cocoDt.getAnnIds('imgIds',imgId); title('results')
27 | anns = cocoDt.loadAnns(annIds); cocoDt.showAnns(anns);
28 |
29 | %% load raw JSON and show exact format for results
30 | fprintf('results structure have the following format:\n');
31 | res = gason(fileread(resFile)); disp(res)
32 |
33 | %% the following command can be used to save the results back to disk
34 | if(0), f=fopen(resFile,'w'); fwrite(f,gason(res)); fclose(f); end
35 |
36 | %% run COCO evaluation code (see CocoEval.m)
37 | cocoEval=CocoEval(cocoGt,cocoDt,type);
38 | cocoEval.params.imgIds=imgIds;
39 | cocoEval.evaluate();
40 | cocoEval.accumulate();
41 | cocoEval.summarize();
42 |
43 | %% generate Derek Hoiem style analyis of false positives (slow)
44 | if(0), cocoEval.analyze(); end
45 |
--------------------------------------------------------------------------------
/cocoapi/MatlabAPI/gason.m:
--------------------------------------------------------------------------------
1 | function out = gason( in )
2 | % Convert between JSON strings and corresponding JSON objects.
3 | %
4 | % This parser is based on Gason written and maintained by Ivan Vashchaev:
5 | % https://github.com/vivkin/gason
6 | % Gason is a "lightweight and fast JSON parser for C++". Please see the
7 | % above link for license information and additional details about Gason.
8 | %
9 | % Given a JSON string, gason calls the C++ parser and converts the output
10 | % into an appropriate Matlab structure. As the parsing is performed in mex
11 | % the resulting parser is blazingly fast. Large JSON structs (100MB+) take
12 | % only a few seconds to parse (compared to hours for pure Matlab parsers).
13 | %
14 | % Given a JSON object, gason calls the C++ encoder to convert the object
15 | % back into a JSON string representation. Nearly any Matlab struct, cell
16 | % array, or numeric array represent a valid JSON object. Note that gason()
17 | % can be used to go both from JSON string to JSON object and back.
18 | %
19 | % Gason requires C++11 to compile (for GCC this requires version 4.7 or
20 | % later). The following command compiles the parser (may require tweaking):
21 | % mex('CXXFLAGS=\$CXXFLAGS -std=c++11 -Wall','-largeArrayDims',...
22 | % 'private/gasonMex.cpp','../common/gason.cpp',...
23 | % '-I../common/','-outdir','private');
24 | % Note the use of the "-std=c++11" flag. A number of precompiled binaries
25 | % are included, please do not contact us for help with compiling. If needed
26 | % you can specify a compiler by adding the option 'CXX="/usr/bin/g++"'.
27 | %
28 | % Note that by default JSON arrays that contain only numbers are stored as
29 | % regular Matlab arrays. Likewise, JSON arrays that contain only objects of
30 | % the same type are stored as Matlab struct arrays. This is much faster and
31 | % can use considerably less memory than always using Matlab cell arrays.
32 | %
33 | % USAGE
34 | % object = gason( string )
35 | % string = gason( object )
36 | %
37 | % INPUTS/OUTPUTS
38 | % string - JSON string
39 | % object - JSON object
40 | %
41 | % EXAMPLE
42 | % o = struct('first',{'piotr','ty'},'last',{'dollar','lin'})
43 | % s = gason( o ) % convert JSON object -> JSON string
44 | % p = gason( s ) % convert JSON string -> JSON object
45 | %
46 | % See also
47 | %
48 | % Microsoft COCO Toolbox. version 2.0
49 | % Data, paper, and tutorials available at: http://mscoco.org/
50 | % Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
51 | % Licensed under the Simplified BSD License [see coco/license.txt]
52 |
53 | out = gasonMex( 'convert', in );
54 |
--------------------------------------------------------------------------------
/cocoapi/MatlabAPI/private/gasonMex.mexa64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/MatlabAPI/private/gasonMex.mexa64
--------------------------------------------------------------------------------
/cocoapi/MatlabAPI/private/gasonMex.mexmaci64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/MatlabAPI/private/gasonMex.mexmaci64
--------------------------------------------------------------------------------
/cocoapi/MatlabAPI/private/getPrmDflt.m:
--------------------------------------------------------------------------------
1 | function varargout = getPrmDflt( prm, dfs, checkExtra )
2 | % Helper to set default values (if not already set) of parameter struct.
3 | %
4 | % Takes input parameters and a list of 'name'/default pairs, and for each
5 | % 'name' for which prm has no value (prm.(name) is not a field or 'name'
6 | % does not appear in prm list), getPrmDflt assigns the given default
7 | % value. If default value for variable 'name' is 'REQ', and value for
8 | % 'name' is not given, an error is thrown. See below for usage details.
9 | %
10 | % USAGE (nargout==1)
11 | % prm = getPrmDflt( prm, dfs, [checkExtra] )
12 | %
13 | % USAGE (nargout>1)
14 | % [ param1 ... paramN ] = getPrmDflt( prm, dfs, [checkExtra] )
15 | %
16 | % INPUTS
17 | % prm - param struct or cell of form {'name1' v1 'name2' v2 ...}
18 | % dfs - cell of form {'name1' def1 'name2' def2 ...}
19 | % checkExtra - [0] if 1 throw error if prm contains params not in dfs
20 | % if -1 if prm contains params not in dfs adds them
21 | %
22 | % OUTPUTS (nargout==1)
23 | % prm - parameter struct with fields 'name1' through 'nameN' assigned
24 | %
25 | % OUTPUTS (nargout>1)
26 | % param1 - value assigned to parameter with 'name1'
27 | % ...
28 | % paramN - value assigned to parameter with 'nameN'
29 | %
30 | % EXAMPLE
31 | % dfs = { 'x','REQ', 'y',0, 'z',[], 'eps',1e-3 };
32 | % prm = getPrmDflt( struct('x',1,'y',1), dfs )
33 | % [ x y z eps ] = getPrmDflt( {'x',2,'y',1}, dfs )
34 | %
35 | % See also INPUTPARSER
36 | %
37 | % Piotr's Computer Vision Matlab Toolbox Version 2.60
38 | % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com]
39 | % Licensed under the Simplified BSD License [see external/bsd.txt]
40 |
41 | if( mod(length(dfs),2) ), error('odd number of default parameters'); end
42 | if nargin<=2, checkExtra = 0; end
43 |
44 | % get the input parameters as two cell arrays: prmVal and prmField
45 | if iscell(prm) && length(prm)==1, prm=prm{1}; end
46 | if iscell(prm)
47 | if(mod(length(prm),2)), error('odd number of parameters in prm'); end
48 | prmField = prm(1:2:end); prmVal = prm(2:2:end);
49 | else
50 | if(~isstruct(prm)), error('prm must be a struct or a cell'); end
51 | prmVal = struct2cell(prm); prmField = fieldnames(prm);
52 | end
53 |
54 | % get and update default values using quick for loop
55 | dfsField = dfs(1:2:end); dfsVal = dfs(2:2:end);
56 | if checkExtra>0
57 | for i=1:length(prmField)
58 | j = find(strcmp(prmField{i},dfsField));
59 | if isempty(j), error('parameter %s is not valid', prmField{i}); end
60 | dfsVal(j) = prmVal(i);
61 | end
62 | elseif checkExtra<0
63 | for i=1:length(prmField)
64 | j = find(strcmp(prmField{i},dfsField));
65 | if isempty(j), j=length(dfsVal)+1; dfsField{j}=prmField{i}; end
66 | dfsVal(j) = prmVal(i);
67 | end
68 | else
69 | for i=1:length(prmField)
70 | dfsVal(strcmp(prmField{i},dfsField)) = prmVal(i);
71 | end
72 | end
73 |
74 | % check for missing values
75 | if any(strcmp('REQ',dfsVal))
76 | cmpArray = find(strcmp('REQ',dfsVal));
77 | error(['Required field ''' dfsField{cmpArray(1)} ''' not specified.'] );
78 | end
79 |
80 | % set output
81 | if nargout==1
82 | varargout{1} = cell2struct( dfsVal, dfsField, 2 );
83 | else
84 | varargout = dfsVal;
85 | end
86 |
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | # install pycocotools locally
3 | python setup.py build_ext --inplace
4 | rm -rf build
5 |
6 | install:
7 | # install pycocotools to the Python site-packages
8 | python setup.py build_ext install
9 | rm -rf build
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/lib.win-amd64-3.5/pycocotools/_mask.cp35-win_amd64.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/build/lib.win-amd64-3.5/pycocotools/_mask.cp35-win_amd64.pyd
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/lib.win-amd64-3.6/pycocotools/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tylin'
2 |
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/lib.win-amd64-3.6/pycocotools/_mask.cp36-win_amd64.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/build/lib.win-amd64-3.6/pycocotools/_mask.cp36-win_amd64.pyd
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/temp.win-amd64-3.5/Release/pycocotools/_mask.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/build/temp.win-amd64-3.5/Release/pycocotools/_mask.o
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/temp.win-amd64-3.5/common/_mask.cp35-win_amd64.def:
--------------------------------------------------------------------------------
1 | LIBRARY _mask.cp35-win_amd64.pyd
2 | EXPORTS
3 | PyInit__mask
4 |
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/temp.win-amd64-3.5/common/maskapi.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/build/temp.win-amd64-3.5/common/maskapi.o
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/temp.win-amd64-3.6/Release/pycocotools/_mask.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/build/temp.win-amd64-3.6/Release/pycocotools/_mask.obj
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/temp.win-amd64-3.6/common/_mask.cp36-win_amd64.exp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/build/temp.win-amd64-3.6/common/_mask.cp36-win_amd64.exp
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/temp.win-amd64-3.6/common/_mask.cp36-win_amd64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/build/temp.win-amd64-3.6/common/_mask.cp36-win_amd64.lib
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/build/temp.win-amd64-3.6/common/maskApi.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/build/temp.win-amd64-3.6/common/maskApi.obj
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/dist/pycocotools-2.0-py3.6-win-amd64.egg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/dist/pycocotools-2.0-py3.6-win-amd64.egg
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/pycocotools.egg-info/PKG-INFO:
--------------------------------------------------------------------------------
1 | Metadata-Version: 1.0
2 | Name: pycocotools
3 | Version: 2.0
4 | Summary: UNKNOWN
5 | Home-page: UNKNOWN
6 | Author: UNKNOWN
7 | Author-email: UNKNOWN
8 | License: UNKNOWN
9 | Description: UNKNOWN
10 | Platform: UNKNOWN
11 |
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/pycocotools.egg-info/SOURCES.txt:
--------------------------------------------------------------------------------
1 | setup.py
2 | ../common/maskApi.c
3 | ../common/maskApi.c
4 | pycocotools/__init__.py
5 | pycocotools/_mask.c
6 | pycocotools/coco.py
7 | pycocotools/cocoeval.py
8 | pycocotools/mask.py
9 | pycocotools.egg-info/PKG-INFO
10 | pycocotools.egg-info/SOURCES.txt
11 | pycocotools.egg-info/dependency_links.txt
12 | pycocotools.egg-info/requires.txt
13 | pycocotools.egg-info/top_level.txt
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/pycocotools.egg-info/dependency_links.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/pycocotools.egg-info/requires.txt:
--------------------------------------------------------------------------------
1 | setuptools>=18.0
2 | cython>=0.27.3
3 | matplotlib>=2.1.0
4 |
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/pycocotools.egg-info/top_level.txt:
--------------------------------------------------------------------------------
1 | pycocotools
2 |
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/pycocotools/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tylin'
2 |
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/pycocotools/_mask.cp35-win_amd64.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/pycocotools/_mask.cp35-win_amd64.pyd
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/pycocotools/_mask.cp36-win_amd64.pyd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/cocoapi/PythonAPI/pycocotools/_mask.cp36-win_amd64.pyd
--------------------------------------------------------------------------------
/cocoapi/PythonAPI/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, Extension
2 | import numpy as np
3 |
4 | # To compile and install locally run "python setup.py build_ext --inplace"
5 | # To install library to Python site-packages run "python setup.py build_ext install"
6 |
7 | ext_modules = [
8 | Extension(
9 | 'pycocotools._mask',
10 | sources=['../common/maskApi.c', 'pycocotools/_mask.pyx'],
11 | include_dirs = [np.get_include(), '../common'],
12 | extra_compile_args=[],
13 | )
14 | ]
15 |
16 | setup(
17 | name='pycocotools',
18 | packages=['pycocotools'],
19 | package_dir = {'pycocotools': 'pycocotools'},
20 | install_requires=[
21 | 'setuptools>=18.0',
22 | 'cython>=0.27.3',
23 | 'matplotlib>=2.1.0'
24 | ],
25 | version='2.0',
26 | ext_modules= ext_modules
27 | )
28 |
--------------------------------------------------------------------------------
/cocoapi/README.txt:
--------------------------------------------------------------------------------
1 | COCO API - http://cocodataset.org/
2 |
3 | COCO is a large image dataset designed for object detection, segmentation, person keypoints detection, stuff segmentation, and caption generation. This package provides Matlab, Python, and Lua APIs that assists in loading, parsing, and visualizing the annotations in COCO. Please visit http://cocodataset.org/ for more information on COCO, including for the data, paper, and tutorials. The exact format of the annotations is also described on the COCO website. The Matlab and Python APIs are complete, the Lua API provides only basic functionality.
4 |
5 | In addition to this API, please download both the COCO images and annotations in order to run the demos and use the API. Both are available on the project website.
6 | -Please download, unzip, and place the images in: coco/images/
7 | -Please download and place the annotations in: coco/annotations/
8 | For substantially more details on the API please see http://cocodataset.org/#download.
9 |
10 | After downloading the images and annotations, run the Matlab, Python, or Lua demos for example usage.
11 |
12 | To install:
13 | -For Matlab, add coco/MatlabApi to the Matlab path (OSX/Linux binaries provided)
14 | -For Python, run "make" under coco/PythonAPI
15 | -For Lua, run “luarocks make LuaAPI/rocks/coco-scm-1.rockspec” under coco/
16 |
--------------------------------------------------------------------------------
/cocoapi/common/maskApi.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 | * Microsoft COCO Toolbox. version 2.0
3 | * Data, paper, and tutorials available at: http://mscoco.org/
4 | * Code written by Piotr Dollar and Tsung-Yi Lin, 2015.
5 | * Licensed under the Simplified BSD License [see coco/license.txt]
6 | **************************************************************************/
7 | #pragma once
8 |
9 | typedef unsigned int uint;
10 | typedef unsigned long siz;
11 | typedef unsigned char byte;
12 | typedef double* BB;
13 | typedef struct { siz h, w, m; uint *cnts; } RLE;
14 |
15 | /* Initialize/destroy RLE. */
16 | void rleInit( RLE *R, siz h, siz w, siz m, uint *cnts );
17 | void rleFree( RLE *R );
18 |
19 | /* Initialize/destroy RLE array. */
20 | void rlesInit( RLE **R, siz n );
21 | void rlesFree( RLE **R, siz n );
22 |
23 | /* Encode binary masks using RLE. */
24 | void rleEncode( RLE *R, const byte *mask, siz h, siz w, siz n );
25 |
26 | /* Decode binary masks encoded via RLE. */
27 | void rleDecode( const RLE *R, byte *mask, siz n );
28 |
29 | /* Compute union or intersection of encoded masks. */
30 | void rleMerge( const RLE *R, RLE *M, siz n, int intersect );
31 |
32 | /* Compute area of encoded masks. */
33 | void rleArea( const RLE *R, siz n, uint *a );
34 |
35 | /* Compute intersection over union between masks. */
36 | void rleIou( RLE *dt, RLE *gt, siz m, siz n, byte *iscrowd, double *o );
37 |
38 | /* Compute non-maximum suppression between bounding masks */
39 | void rleNms( RLE *dt, siz n, uint *keep, double thr );
40 |
41 | /* Compute intersection over union between bounding boxes. */
42 | void bbIou( BB dt, BB gt, siz m, siz n, byte *iscrowd, double *o );
43 |
44 | /* Compute non-maximum suppression between bounding boxes */
45 | void bbNms( BB dt, siz n, uint *keep, double thr );
46 |
47 | /* Get bounding boxes surrounding encoded masks. */
48 | void rleToBbox( const RLE *R, BB bb, siz n );
49 |
50 | /* Convert bounding boxes to encoded masks. */
51 | void rleFrBbox( RLE *R, const BB bb, siz h, siz w, siz n );
52 |
53 | /* Convert polygon to encoded mask. */
54 | void rleFrPoly( RLE *R, const double *xy, siz k, siz h, siz w );
55 |
56 | /* Get compressed string representation of encoded mask. */
57 | char* rleToString( const RLE *R );
58 |
59 | /* Convert from compressed string representation of encoded mask. */
60 | void rleFrString( RLE *R, char *s, siz h, siz w );
61 |
--------------------------------------------------------------------------------
/cocoapi/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Piotr Dollar and Tsung-Yi Lin
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 | 2. Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 |
13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 |
24 | The views and conclusions contained in the software and documentation are those
25 | of the authors and should not be interpreted as representing official policies,
26 | either expressed or implied, of the FreeBSD Project.
27 |
--------------------------------------------------------------------------------
/cocoapi/results/val2014_fake_eval_res.txt:
--------------------------------------------------------------------------------
1 | ------------------------------------------------------------------------------
2 | type=segm
3 | Running per image evaluation... DONE (t=0.45s).
4 | Accumulating evaluation results... DONE (t=0.08s).
5 | Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.320
6 | Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.562
7 | Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.299
8 | Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.387
9 | Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.310
10 | Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.327
11 | Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.268
12 | Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.415
13 | Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.417
14 | Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.469
15 | Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.377
16 | Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.381
17 |
18 | ------------------------------------------------------------------------------
19 | type=bbox
20 | Running per image evaluation... DONE (t=0.34s).
21 | Accumulating evaluation results... DONE (t=0.08s).
22 | Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.505
23 | Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.697
24 | Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.573
25 | Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.586
26 | Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.519
27 | Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.501
28 | Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.387
29 | Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.594
30 | Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.595
31 | Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.640
32 | Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.566
33 | Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.564
34 |
35 | ------------------------------------------------------------------------------
36 | type=keypoints
37 | Running per image evaluation... DONE (t=0.06s).
38 | Accumulating evaluation results... DONE (t=0.00s).
39 | Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets= 20 ] = 0.372
40 | Average Precision (AP) @[ IoU=0.50 | area= all | maxDets= 20 ] = 0.636
41 | Average Precision (AP) @[ IoU=0.75 | area= all | maxDets= 20 ] = 0.348
42 | Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets= 20 ] = 0.384
43 | Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets= 20 ] = 0.386
44 | Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 20 ] = 0.514
45 | Average Recall (AR) @[ IoU=0.50 | area= all | maxDets= 20 ] = 0.734
46 | Average Recall (AR) @[ IoU=0.75 | area= all | maxDets= 20 ] = 0.504
47 | Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets= 20 ] = 0.508
48 | Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets= 20 ] = 0.522
49 |
--------------------------------------------------------------------------------
/core/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/core/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/core/__pycache__/__init__.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/__init__.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/anchor_generator.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/anchor_generator.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/balanced_positive_negative_sampler.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/balanced_positive_negative_sampler.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/batcher.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/batcher.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/box_coder.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/box_coder.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/box_list.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/box_list.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/box_list_ops.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/box_list_ops.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/box_predictor.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/box_predictor.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/data_decoder.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/data_decoder.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/data_parser.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/data_parser.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/freezable_batch_norm.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/freezable_batch_norm.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/keypoint_ops.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/keypoint_ops.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/losses.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/losses.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/matcher.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/matcher.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/minibatch_sampler.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/minibatch_sampler.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/model.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/model.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/post_processing.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/post_processing.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/prefetcher.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/prefetcher.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/preprocessor.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/preprocessor.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/preprocessor_cache.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/preprocessor_cache.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/region_similarity_calculator.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/region_similarity_calculator.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/standard_fields.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/standard_fields.cpython-36.pyc
--------------------------------------------------------------------------------
/core/__pycache__/standard_fields.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/standard_fields.cpython-37.pyc
--------------------------------------------------------------------------------
/core/__pycache__/target_assigner.cpython-37.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mohammadakz/Nested_PPE_detection_FasterRCNN/36555783fd5a6dfd51a76cf9e33bf1f1912eb44d/core/__pycache__/target_assigner.cpython-37.pyc
--------------------------------------------------------------------------------
/core/box_coder_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.core.box_coder."""
17 |
18 | import tensorflow as tf
19 |
20 | from object_detection.core import box_coder
21 | from object_detection.core import box_list
22 |
23 |
24 | class MockBoxCoder(box_coder.BoxCoder):
25 | """Test BoxCoder that encodes/decodes using the multiply-by-two function."""
26 |
27 | def code_size(self):
28 | return 4
29 |
30 | def _encode(self, boxes, anchors):
31 | return 2.0 * boxes.get()
32 |
33 | def _decode(self, rel_codes, anchors):
34 | return box_list.BoxList(rel_codes / 2.0)
35 |
36 |
37 | class BoxCoderTest(tf.test.TestCase):
38 |
39 | def test_batch_decode(self):
40 | mock_anchor_corners = tf.constant(
41 | [[0, 0.1, 0.2, 0.3], [0.2, 0.4, 0.4, 0.6]], tf.float32)
42 | mock_anchors = box_list.BoxList(mock_anchor_corners)
43 | mock_box_coder = MockBoxCoder()
44 |
45 | expected_boxes = [[[0.0, 0.1, 0.5, 0.6], [0.5, 0.6, 0.7, 0.8]],
46 | [[0.1, 0.2, 0.3, 0.4], [0.7, 0.8, 0.9, 1.0]]]
47 |
48 | encoded_boxes_list = [mock_box_coder.encode(
49 | box_list.BoxList(tf.constant(boxes)), mock_anchors)
50 | for boxes in expected_boxes]
51 | encoded_boxes = tf.stack(encoded_boxes_list)
52 | decoded_boxes = box_coder.batch_decode(
53 | encoded_boxes, mock_box_coder, mock_anchors)
54 |
55 | with self.test_session() as sess:
56 | decoded_boxes_result = sess.run(decoded_boxes)
57 | self.assertAllClose(expected_boxes, decoded_boxes_result)
58 |
59 |
60 | if __name__ == '__main__':
61 | tf.test.main()
62 |
--------------------------------------------------------------------------------
/core/data_decoder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Interface for data decoders.
17 |
18 | Data decoders decode the input data and return a dictionary of tensors keyed by
19 | the entries in core.reader.Fields.
20 | """
21 | from abc import ABCMeta
22 | from abc import abstractmethod
23 |
24 |
25 | class DataDecoder(object):
26 | """Interface for data decoders."""
27 | __metaclass__ = ABCMeta
28 |
29 | @abstractmethod
30 | def decode(self, data):
31 | """Return a single image and associated labels.
32 |
33 | Args:
34 | data: a string tensor holding a serialized protocol buffer corresponding
35 | to data for a single image.
36 |
37 | Returns:
38 | tensor_dict: a dictionary containing tensors. Possible keys are defined in
39 | reader.Fields.
40 | """
41 | pass
42 |
--------------------------------------------------------------------------------
/core/data_parser.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Interface for data parsers.
16 |
17 | Data parser parses input data and returns a dictionary of numpy arrays
18 | keyed by the entries in standard_fields.py. Since the parser parses records
19 | to numpy arrays (materialized tensors) directly, it is used to read data for
20 | evaluation/visualization; to parse the data during training, DataDecoder should
21 | be used.
22 | """
23 | from abc import ABCMeta
24 | from abc import abstractmethod
25 |
26 |
27 | class DataToNumpyParser(object):
28 | __metaclass__ = ABCMeta
29 |
30 | @abstractmethod
31 | def parse(self, input_data):
32 | """Parses input and returns a numpy array or a dictionary of numpy arrays.
33 |
34 | Args:
35 | input_data: an input data
36 |
37 | Returns:
38 | A numpy array or a dictionary of numpy arrays or None, if input
39 | cannot be parsed.
40 | """
41 | pass
42 |
--------------------------------------------------------------------------------
/core/freezable_batch_norm.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """A freezable batch norm layer that uses Keras batch normalization."""
17 | import tensorflow as tf
18 |
19 |
20 | class FreezableBatchNorm(tf.keras.layers.BatchNormalization):
21 | """Batch normalization layer (Ioffe and Szegedy, 2014).
22 |
23 | This is a `freezable` batch norm layer that supports setting the `training`
24 | parameter in the __init__ method rather than having to set it either via
25 | the Keras learning phase or via the `call` method parameter. This layer will
26 | forward all other parameters to the default Keras `BatchNormalization`
27 | layer
28 |
29 | This is class is necessary because Object Detection model training sometimes
30 | requires batch normalization layers to be `frozen` and used as if it was
31 | evaluation time, despite still training (and potentially using dropout layers)
32 |
33 | Like the default Keras BatchNormalization layer, this will normalize the
34 | activations of the previous layer at each batch,
35 | i.e. applies a transformation that maintains the mean activation
36 | close to 0 and the activation standard deviation close to 1.
37 |
38 | Arguments:
39 | training: Boolean or None. If True, the batch normalization layer will
40 | normalize the input batch using the batch mean and standard deviation,
41 | and update the total moving mean and standard deviations. If False, the
42 | layer will normalize using the moving average and std. dev, without
43 | updating the learned avg and std. dev.
44 | If None, the layer will follow the keras BatchNormalization layer
45 | strategy of checking the Keras learning phase at `call` time to decide
46 | what to do.
47 | **kwargs: The keyword arguments to forward to the keras BatchNormalization
48 | layer constructor.
49 |
50 | Input shape:
51 | Arbitrary. Use the keyword argument `input_shape`
52 | (tuple of integers, does not include the samples axis)
53 | when using this layer as the first layer in a model.
54 |
55 | Output shape:
56 | Same shape as input.
57 |
58 | References:
59 | - [Batch Normalization: Accelerating Deep Network Training by Reducing
60 | Internal Covariate Shift](https://arxiv.org/abs/1502.03167)
61 | """
62 |
63 | def __init__(self, training=None, **kwargs):
64 | super(FreezableBatchNorm, self).__init__(**kwargs)
65 | self._training = training
66 |
67 | def call(self, inputs, training=None):
68 | if training is None:
69 | training = self._training
70 | return super(FreezableBatchNorm, self).call(inputs, training=training)
71 |
--------------------------------------------------------------------------------
/core/minibatch_sampler.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Base minibatch sampler module.
17 |
18 | The job of the minibatch_sampler is to subsample a minibatch based on some
19 | criterion.
20 |
21 | The main function call is:
22 | subsample(indicator, batch_size, **params).
23 | Indicator is a 1d boolean tensor where True denotes which examples can be
24 | sampled. It returns a boolean indicator where True denotes an example has been
25 | sampled..
26 |
27 | Subclasses should implement the Subsample function and can make use of the
28 | @staticmethod SubsampleIndicator.
29 | """
30 |
31 | from abc import ABCMeta
32 | from abc import abstractmethod
33 |
34 | import tensorflow as tf
35 |
36 | from object_detection.utils import ops
37 |
38 |
39 | class MinibatchSampler(object):
40 | """Abstract base class for subsampling minibatches."""
41 | __metaclass__ = ABCMeta
42 |
43 | def __init__(self):
44 | """Constructs a minibatch sampler."""
45 | pass
46 |
47 | @abstractmethod
48 | def subsample(self, indicator, batch_size, **params):
49 | """Returns subsample of entries in indicator.
50 |
51 | Args:
52 | indicator: boolean tensor of shape [N] whose True entries can be sampled.
53 | batch_size: desired batch size.
54 | **params: additional keyword arguments for specific implementations of
55 | the MinibatchSampler.
56 |
57 | Returns:
58 | sample_indicator: boolean tensor of shape [N] whose True entries have been
59 | sampled. If sum(indicator) >= batch_size, sum(is_sampled) = batch_size
60 | """
61 | pass
62 |
63 | @staticmethod
64 | def subsample_indicator(indicator, num_samples):
65 | """Subsample indicator vector.
66 |
67 | Given a boolean indicator vector with M elements set to `True`, the function
68 | assigns all but `num_samples` of these previously `True` elements to
69 | `False`. If `num_samples` is greater than M, the original indicator vector
70 | is returned.
71 |
72 | Args:
73 | indicator: a 1-dimensional boolean tensor indicating which elements
74 | are allowed to be sampled and which are not.
75 | num_samples: int32 scalar tensor
76 |
77 | Returns:
78 | a boolean tensor with the same shape as input (indicator) tensor
79 | """
80 | indices = tf.where(indicator)
81 | indices = tf.random_shuffle(indices)
82 | indices = tf.reshape(indices, [-1])
83 |
84 | num_samples = tf.minimum(tf.size(indices), num_samples)
85 | selected_indices = tf.slice(indices, [0], tf.reshape(num_samples, [1]))
86 |
87 | selected_indicator = ops.indices_to_dense_vector(selected_indices,
88 | tf.shape(indicator)[0])
89 |
90 | return tf.equal(selected_indicator, 1)
91 |
--------------------------------------------------------------------------------
/core/minibatch_sampler_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for google3.research.vale.object_detection.minibatch_sampler."""
17 |
18 | import numpy as np
19 | import tensorflow as tf
20 |
21 | from object_detection.core import minibatch_sampler
22 |
23 |
24 | class MinibatchSamplerTest(tf.test.TestCase):
25 |
26 | def test_subsample_indicator_when_more_true_elements_than_num_samples(self):
27 | np_indicator = [True, False, True, False, True, True, False]
28 | indicator = tf.constant(np_indicator)
29 | samples = minibatch_sampler.MinibatchSampler.subsample_indicator(
30 | indicator, 3)
31 | with self.test_session() as sess:
32 | samples_out = sess.run(samples)
33 | self.assertTrue(np.sum(samples_out), 3)
34 | self.assertAllEqual(samples_out,
35 | np.logical_and(samples_out, np_indicator))
36 |
37 | def test_subsample_when_more_true_elements_than_num_samples_no_shape(self):
38 | np_indicator = [True, False, True, False, True, True, False]
39 | indicator = tf.placeholder(tf.bool)
40 | feed_dict = {indicator: np_indicator}
41 |
42 | samples = minibatch_sampler.MinibatchSampler.subsample_indicator(
43 | indicator, 3)
44 | with self.test_session() as sess:
45 | samples_out = sess.run(samples, feed_dict=feed_dict)
46 | self.assertTrue(np.sum(samples_out), 3)
47 | self.assertAllEqual(samples_out,
48 | np.logical_and(samples_out, np_indicator))
49 |
50 | def test_subsample_indicator_when_less_true_elements_than_num_samples(self):
51 | np_indicator = [True, False, True, False, True, True, False]
52 | indicator = tf.constant(np_indicator)
53 | samples = minibatch_sampler.MinibatchSampler.subsample_indicator(
54 | indicator, 5)
55 | with self.test_session() as sess:
56 | samples_out = sess.run(samples)
57 | self.assertTrue(np.sum(samples_out), 4)
58 | self.assertAllEqual(samples_out,
59 | np.logical_and(samples_out, np_indicator))
60 |
61 | def test_subsample_indicator_when_num_samples_is_zero(self):
62 | np_indicator = [True, False, True, False, True, True, False]
63 | indicator = tf.constant(np_indicator)
64 | samples_none = minibatch_sampler.MinibatchSampler.subsample_indicator(
65 | indicator, 0)
66 | with self.test_session() as sess:
67 | samples_none_out = sess.run(samples_none)
68 | self.assertAllEqual(
69 | np.zeros_like(samples_none_out, dtype=bool),
70 | samples_none_out)
71 |
72 | def test_subsample_indicator_when_indicator_all_false(self):
73 | indicator_empty = tf.zeros([0], dtype=tf.bool)
74 | samples_empty = minibatch_sampler.MinibatchSampler.subsample_indicator(
75 | indicator_empty, 4)
76 | with self.test_session() as sess:
77 | samples_empty_out = sess.run(samples_empty)
78 | self.assertEqual(0, samples_empty_out.size)
79 |
80 |
81 | if __name__ == '__main__':
82 | tf.test.main()
83 |
--------------------------------------------------------------------------------
/core/prefetcher.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Provides functions to prefetch tensors to feed into models."""
17 | import tensorflow as tf
18 |
19 |
20 | def prefetch(tensor_dict, capacity):
21 | """Creates a prefetch queue for tensors.
22 |
23 | Creates a FIFO queue to asynchronously enqueue tensor_dicts and returns a
24 | dequeue op that evaluates to a tensor_dict. This function is useful in
25 | prefetching preprocessed tensors so that the data is readily available for
26 | consumers.
27 |
28 | Example input pipeline when you don't need batching:
29 | ----------------------------------------------------
30 | key, string_tensor = slim.parallel_reader.parallel_read(...)
31 | tensor_dict = decoder.decode(string_tensor)
32 | tensor_dict = preprocessor.preprocess(tensor_dict, ...)
33 | prefetch_queue = prefetcher.prefetch(tensor_dict, capacity=20)
34 | tensor_dict = prefetch_queue.dequeue()
35 | outputs = Model(tensor_dict)
36 | ...
37 | ----------------------------------------------------
38 |
39 | For input pipelines with batching, refer to core/batcher.py
40 |
41 | Args:
42 | tensor_dict: a dictionary of tensors to prefetch.
43 | capacity: the size of the prefetch queue.
44 |
45 | Returns:
46 | a FIFO prefetcher queue
47 | """
48 | names = list(tensor_dict.keys())
49 | dtypes = [t.dtype for t in tensor_dict.values()]
50 | shapes = [t.get_shape() for t in tensor_dict.values()]
51 | prefetch_queue = tf.PaddingFIFOQueue(capacity, dtypes=dtypes,
52 | shapes=shapes,
53 | names=names,
54 | name='prefetch_queue')
55 | enqueue_op = prefetch_queue.enqueue(tensor_dict)
56 | tf.train.queue_runner.add_queue_runner(tf.train.queue_runner.QueueRunner(
57 | prefetch_queue, [enqueue_op]))
58 | tf.summary.scalar('queue/%s/fraction_of_%d_full' % (prefetch_queue.name,
59 | capacity),
60 | tf.to_float(prefetch_queue.size()) * (1. / capacity))
61 | return prefetch_queue
62 |
--------------------------------------------------------------------------------
/label_map_PPE.pbtxt:
--------------------------------------------------------------------------------
1 | item {
2 | id: 1
3 | name: 'H'
4 | }
5 |
6 | item {
7 | id: 2
8 | name: 'NH'
9 | }
10 |
11 | item {
12 | id: 3
13 | name: 'V'
14 | }
15 |
16 | item {
17 | id: 4
18 | name: 'NV'
19 | }
--------------------------------------------------------------------------------
/label_map_person.pbtxt:
--------------------------------------------------------------------------------
1 | item {
2 | id: 1
3 | name: 'person'
4 | }
5 |
--------------------------------------------------------------------------------
/matchers/bipartite_matcher.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Bipartite matcher implementation."""
17 |
18 | import tensorflow as tf
19 |
20 | from tensorflow.contrib.image.python.ops import image_ops
21 | from object_detection.core import matcher
22 |
23 |
24 | class GreedyBipartiteMatcher(matcher.Matcher):
25 | """Wraps a Tensorflow greedy bipartite matcher."""
26 |
27 | def __init__(self, use_matmul_gather=False):
28 | """Constructs a Matcher.
29 |
30 | Args:
31 | use_matmul_gather: Force constructed match objects to use matrix
32 | multiplication based gather instead of standard tf.gather.
33 | (Default: False).
34 | """
35 | super(GreedyBipartiteMatcher, self).__init__(
36 | use_matmul_gather=use_matmul_gather)
37 |
38 | def _match(self, similarity_matrix, valid_rows):
39 | """Bipartite matches a collection rows and columns. A greedy bi-partite.
40 |
41 | TODO(rathodv): Add num_valid_columns options to match only that many columns
42 | with all the rows.
43 |
44 | Args:
45 | similarity_matrix: Float tensor of shape [N, M] with pairwise similarity
46 | where higher values mean more similar.
47 | valid_rows: A boolean tensor of shape [N] indicating the rows that are
48 | valid.
49 |
50 | Returns:
51 | match_results: int32 tensor of shape [M] with match_results[i]=-1
52 | meaning that column i is not matched and otherwise that it is matched to
53 | row match_results[i].
54 | """
55 | valid_row_sim_matrix = tf.gather(similarity_matrix,
56 | tf.squeeze(tf.where(valid_rows), axis=-1))
57 | invalid_row_sim_matrix = tf.gather(
58 | similarity_matrix,
59 | tf.squeeze(tf.where(tf.logical_not(valid_rows)), axis=-1))
60 | similarity_matrix = tf.concat(
61 | [valid_row_sim_matrix, invalid_row_sim_matrix], axis=0)
62 | # Convert similarity matrix to distance matrix as tf.image.bipartite tries
63 | # to find minimum distance matches.
64 | distance_matrix = -1 * similarity_matrix
65 | num_valid_rows = tf.reduce_sum(tf.to_float(valid_rows))
66 | _, match_results = image_ops.bipartite_match(
67 | distance_matrix, num_valid_rows=num_valid_rows)
68 | match_results = tf.reshape(match_results, [-1])
69 | match_results = tf.cast(match_results, tf.int32)
70 | return match_results
71 |
--------------------------------------------------------------------------------
/matchers/bipartite_matcher_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.core.bipartite_matcher."""
17 |
18 | import tensorflow as tf
19 |
20 | from object_detection.matchers import bipartite_matcher
21 |
22 |
23 | class GreedyBipartiteMatcherTest(tf.test.TestCase):
24 |
25 | def test_get_expected_matches_when_all_rows_are_valid(self):
26 | similarity_matrix = tf.constant([[0.50, 0.1, 0.8], [0.15, 0.2, 0.3]])
27 | valid_rows = tf.ones([2], dtype=tf.bool)
28 | expected_match_results = [-1, 1, 0]
29 |
30 | matcher = bipartite_matcher.GreedyBipartiteMatcher()
31 | match = matcher.match(similarity_matrix, valid_rows=valid_rows)
32 | with self.test_session() as sess:
33 | match_results_out = sess.run(match._match_results)
34 | self.assertAllEqual(match_results_out, expected_match_results)
35 |
36 | def test_get_expected_matches_with_all_rows_be_default(self):
37 | similarity_matrix = tf.constant([[0.50, 0.1, 0.8], [0.15, 0.2, 0.3]])
38 | expected_match_results = [-1, 1, 0]
39 |
40 | matcher = bipartite_matcher.GreedyBipartiteMatcher()
41 | match = matcher.match(similarity_matrix)
42 | with self.test_session() as sess:
43 | match_results_out = sess.run(match._match_results)
44 | self.assertAllEqual(match_results_out, expected_match_results)
45 |
46 | def test_get_no_matches_with_zero_valid_rows(self):
47 | similarity_matrix = tf.constant([[0.50, 0.1, 0.8], [0.15, 0.2, 0.3]])
48 | valid_rows = tf.zeros([2], dtype=tf.bool)
49 | expected_match_results = [-1, -1, -1]
50 |
51 | matcher = bipartite_matcher.GreedyBipartiteMatcher()
52 | match = matcher.match(similarity_matrix, valid_rows)
53 | with self.test_session() as sess:
54 | match_results_out = sess.run(match._match_results)
55 | self.assertAllEqual(match_results_out, expected_match_results)
56 |
57 | def test_get_expected_matches_with_only_one_valid_row(self):
58 | similarity_matrix = tf.constant([[0.50, 0.1, 0.8], [0.15, 0.2, 0.3]])
59 | valid_rows = tf.constant([True, False], dtype=tf.bool)
60 | expected_match_results = [-1, -1, 0]
61 |
62 | matcher = bipartite_matcher.GreedyBipartiteMatcher()
63 | match = matcher.match(similarity_matrix, valid_rows)
64 | with self.test_session() as sess:
65 | match_results_out = sess.run(match._match_results)
66 | self.assertAllEqual(match_results_out, expected_match_results)
67 |
68 | def test_get_expected_matches_with_only_one_valid_row_at_bottom(self):
69 | similarity_matrix = tf.constant([[0.15, 0.2, 0.3], [0.50, 0.1, 0.8]])
70 | valid_rows = tf.constant([False, True], dtype=tf.bool)
71 | expected_match_results = [-1, -1, 0]
72 |
73 | matcher = bipartite_matcher.GreedyBipartiteMatcher()
74 | match = matcher.match(similarity_matrix, valid_rows)
75 | with self.test_session() as sess:
76 | match_results_out = sess.run(match._match_results)
77 | self.assertAllEqual(match_results_out, expected_match_results)
78 |
79 |
80 | if __name__ == '__main__':
81 | tf.test.main()
82 |
--------------------------------------------------------------------------------
/meta_architectures/rfcn_meta_arch_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.meta_architectures.rfcn_meta_arch."""
17 |
18 | import tensorflow as tf
19 |
20 | from object_detection.meta_architectures import faster_rcnn_meta_arch_test_lib
21 | from object_detection.meta_architectures import rfcn_meta_arch
22 |
23 |
24 | class RFCNMetaArchTest(
25 | faster_rcnn_meta_arch_test_lib.FasterRCNNMetaArchTestBase):
26 |
27 | def _get_second_stage_box_predictor_text_proto(self):
28 | box_predictor_text_proto = """
29 | rfcn_box_predictor {
30 | conv_hyperparams {
31 | op: CONV
32 | activation: NONE
33 | regularizer {
34 | l2_regularizer {
35 | weight: 0.0005
36 | }
37 | }
38 | initializer {
39 | variance_scaling_initializer {
40 | factor: 1.0
41 | uniform: true
42 | mode: FAN_AVG
43 | }
44 | }
45 | }
46 | }
47 | """
48 | return box_predictor_text_proto
49 |
50 | def _get_model(self, box_predictor, **common_kwargs):
51 | return rfcn_meta_arch.RFCNMetaArch(
52 | second_stage_rfcn_box_predictor=box_predictor, **common_kwargs)
53 |
54 | def _get_box_classifier_features_shape(self,
55 | image_size,
56 | batch_size,
57 | max_num_proposals,
58 | initial_crop_size,
59 | maxpool_stride,
60 | num_features):
61 | return (batch_size, image_size, image_size, num_features)
62 |
63 |
64 | if __name__ == '__main__':
65 | tf.test.main()
66 |
--------------------------------------------------------------------------------
/metrics/io_utils.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Common IO utils used in offline metric computation.
16 | """
17 |
18 | from __future__ import absolute_import
19 | from __future__ import division
20 | from __future__ import print_function
21 |
22 | import csv
23 |
24 |
25 | def write_csv(fid, metrics):
26 | """Writes metrics key-value pairs to CSV file.
27 |
28 | Args:
29 | fid: File identifier of an opened file.
30 | metrics: A dictionary with metrics to be written.
31 | """
32 | metrics_writer = csv.writer(fid, delimiter=',')
33 | for metric_name, metric_value in metrics.items():
34 | metrics_writer.writerow([metric_name, str(metric_value)])
35 |
--------------------------------------------------------------------------------
/metrics/offline_eval_map_corloc_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Tests for utilities in offline_eval_map_corloc binary."""
16 |
17 | import tensorflow as tf
18 |
19 | from object_detection.metrics import offline_eval_map_corloc as offline_eval
20 |
21 |
22 | class OfflineEvalMapCorlocTest(tf.test.TestCase):
23 |
24 | def test_generateShardedFilenames(self):
25 | test_filename = '/path/to/file'
26 | result = offline_eval._generate_sharded_filenames(test_filename)
27 | self.assertEqual(result, [test_filename])
28 |
29 | test_filename = '/path/to/file-00000-of-00050'
30 | result = offline_eval._generate_sharded_filenames(test_filename)
31 | self.assertEqual(result, [test_filename])
32 |
33 | result = offline_eval._generate_sharded_filenames('/path/to/@3.record')
34 | self.assertEqual(result, [
35 | '/path/to/-00000-of-00003.record', '/path/to/-00001-of-00003.record',
36 | '/path/to/-00002-of-00003.record'
37 | ])
38 |
39 | result = offline_eval._generate_sharded_filenames('/path/to/abc@3')
40 | self.assertEqual(result, [
41 | '/path/to/abc-00000-of-00003', '/path/to/abc-00001-of-00003',
42 | '/path/to/abc-00002-of-00003'
43 | ])
44 |
45 | result = offline_eval._generate_sharded_filenames('/path/to/@1')
46 | self.assertEqual(result, ['/path/to/-00000-of-00001'])
47 |
48 | def test_generateFilenames(self):
49 | test_filenames = ['/path/to/file', '/path/to/@3.record']
50 | result = offline_eval._generate_filenames(test_filenames)
51 | self.assertEqual(result, [
52 | '/path/to/file', '/path/to/-00000-of-00003.record',
53 | '/path/to/-00001-of-00003.record', '/path/to/-00002-of-00003.record'
54 | ])
55 |
56 |
57 | if __name__ == '__main__':
58 | tf.test.main()
59 |
--------------------------------------------------------------------------------
/predictors/heads/head.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Base head class.
17 |
18 | All the different kinds of prediction heads in different models will inherit
19 | from this class. What is in common between all head classes is that they have a
20 | `predict` function that receives `features` as its first argument.
21 |
22 | How to add a new prediction head to an existing meta architecture?
23 | For example, how can we add a `3d shape` prediction head to Mask RCNN?
24 |
25 | We have to take the following steps to add a new prediction head to an
26 | existing meta arch:
27 | (a) Add a class for predicting the head. This class should inherit from the
28 | `Head` class below and have a `predict` function that receives the features
29 | and predicts the output. The output is always a tf.float32 tensor.
30 | (b) Add the head to the meta architecture. For example in case of Mask RCNN,
31 | go to box_predictor_builder and put in the logic for adding the new head to the
32 | Mask RCNN box predictor.
33 | (c) Add the logic for computing the loss for the new head.
34 | (d) Add the necessary metrics for the new head.
35 | (e) (optional) Add visualization for the new head.
36 | """
37 | from abc import abstractmethod
38 |
39 | import tensorflow as tf
40 |
41 |
42 | class Head(object):
43 | """Mask RCNN head base class."""
44 |
45 | def __init__(self):
46 | """Constructor."""
47 | pass
48 |
49 | @abstractmethod
50 | def predict(self, features, num_predictions_per_location):
51 | """Returns the head's predictions.
52 |
53 | Args:
54 | features: A float tensor of features.
55 | num_predictions_per_location: Int containing number of predictions per
56 | location.
57 |
58 | Returns:
59 | A tf.float32 tensor.
60 | """
61 | pass
62 |
63 |
64 | class KerasHead(tf.keras.Model):
65 | """Keras head base class."""
66 |
67 | def call(self, features):
68 | """The Keras model call will delegate to the `_predict` method."""
69 | return self._predict(features)
70 |
71 | @abstractmethod
72 | def _predict(self, features):
73 | """Returns the head's predictions.
74 |
75 | Args:
76 | features: A float tensor of features.
77 |
78 | Returns:
79 | A tf.float32 tensor.
80 | """
81 | pass
82 |
--------------------------------------------------------------------------------
/predictors/heads/keras_box_head_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.predictors.heads.box_head."""
17 | import tensorflow as tf
18 |
19 | from google.protobuf import text_format
20 | from object_detection.builders import hyperparams_builder
21 | from object_detection.predictors.heads import keras_box_head
22 | from object_detection.protos import hyperparams_pb2
23 | from object_detection.utils import test_case
24 |
25 |
26 | class ConvolutionalKerasBoxHeadTest(test_case.TestCase):
27 |
28 | def _build_conv_hyperparams(self):
29 | conv_hyperparams = hyperparams_pb2.Hyperparams()
30 | conv_hyperparams_text_proto = """
31 | activation: NONE
32 | regularizer {
33 | l2_regularizer {
34 | }
35 | }
36 | initializer {
37 | truncated_normal_initializer {
38 | }
39 | }
40 | """
41 | text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams)
42 | return hyperparams_builder.KerasLayerHyperparams(conv_hyperparams)
43 |
44 | def test_prediction_size_depthwise_false(self):
45 | conv_hyperparams = self._build_conv_hyperparams()
46 | box_prediction_head = keras_box_head.ConvolutionalBoxHead(
47 | is_training=True,
48 | box_code_size=4,
49 | kernel_size=3,
50 | conv_hyperparams=conv_hyperparams,
51 | freeze_batchnorm=False,
52 | num_predictions_per_location=1,
53 | use_depthwise=False)
54 | image_feature = tf.random_uniform(
55 | [64, 17, 19, 1024], minval=-10.0, maxval=10.0, dtype=tf.float32)
56 | box_encodings = box_prediction_head(image_feature)
57 | self.assertAllEqual([64, 323, 1, 4], box_encodings.get_shape().as_list())
58 |
59 | # TODO(kaftan): Remove conditional after CMLE moves to TF 1.10
60 |
61 | if __name__ == '__main__':
62 | tf.test.main()
63 |
--------------------------------------------------------------------------------
/predictors/heads/keras_class_head_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.predictors.heads.class_head."""
17 | import tensorflow as tf
18 |
19 | from google.protobuf import text_format
20 | from object_detection.builders import hyperparams_builder
21 | from object_detection.predictors.heads import keras_class_head
22 | from object_detection.protos import hyperparams_pb2
23 | from object_detection.utils import test_case
24 |
25 |
26 | class ConvolutionalKerasClassPredictorTest(test_case.TestCase):
27 |
28 | def _build_conv_hyperparams(self):
29 | conv_hyperparams = hyperparams_pb2.Hyperparams()
30 | conv_hyperparams_text_proto = """
31 | activation: NONE
32 | regularizer {
33 | l2_regularizer {
34 | }
35 | }
36 | initializer {
37 | truncated_normal_initializer {
38 | }
39 | }
40 | """
41 | text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams)
42 | return hyperparams_builder.KerasLayerHyperparams(conv_hyperparams)
43 |
44 | def test_prediction_size_depthwise_false(self):
45 | conv_hyperparams = self._build_conv_hyperparams()
46 | class_prediction_head = keras_class_head.ConvolutionalClassHead(
47 | is_training=True,
48 | num_class_slots=20,
49 | use_dropout=True,
50 | dropout_keep_prob=0.5,
51 | kernel_size=3,
52 | conv_hyperparams=conv_hyperparams,
53 | freeze_batchnorm=False,
54 | num_predictions_per_location=1,
55 | use_depthwise=False)
56 | image_feature = tf.random_uniform(
57 | [64, 17, 19, 1024], minval=-10.0, maxval=10.0, dtype=tf.float32)
58 | class_predictions = class_prediction_head(image_feature,)
59 | self.assertAllEqual([64, 323, 20],
60 | class_predictions.get_shape().as_list())
61 |
62 | # TODO(kaftan): Remove conditional after CMLE moves to TF 1.10
63 |
64 | if __name__ == '__main__':
65 | tf.test.main()
66 |
--------------------------------------------------------------------------------
/predictors/heads/keras_mask_head_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.predictors.heads.mask_head."""
17 | import tensorflow as tf
18 |
19 | from google.protobuf import text_format
20 | from object_detection.builders import hyperparams_builder
21 | from object_detection.predictors.heads import keras_mask_head
22 | from object_detection.protos import hyperparams_pb2
23 | from object_detection.utils import test_case
24 |
25 |
26 | class ConvolutionalMaskPredictorTest(test_case.TestCase):
27 |
28 | def _build_conv_hyperparams(self):
29 | conv_hyperparams = hyperparams_pb2.Hyperparams()
30 | conv_hyperparams_text_proto = """
31 | activation: NONE
32 | regularizer {
33 | l2_regularizer {
34 | }
35 | }
36 | initializer {
37 | truncated_normal_initializer {
38 | }
39 | }
40 | """
41 | text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams)
42 | return hyperparams_builder.KerasLayerHyperparams(conv_hyperparams)
43 |
44 | def test_prediction_size_use_depthwise_false(self):
45 | conv_hyperparams = self._build_conv_hyperparams()
46 | mask_prediction_head = keras_mask_head.ConvolutionalMaskHead(
47 | is_training=True,
48 | num_classes=20,
49 | use_dropout=True,
50 | dropout_keep_prob=0.5,
51 | kernel_size=3,
52 | conv_hyperparams=conv_hyperparams,
53 | freeze_batchnorm=False,
54 | num_predictions_per_location=1,
55 | use_depthwise=False,
56 | mask_height=7,
57 | mask_width=7)
58 | image_feature = tf.random_uniform(
59 | [64, 17, 19, 1024], minval=-10.0, maxval=10.0, dtype=tf.float32)
60 | mask_predictions = mask_prediction_head(image_feature)
61 | self.assertAllEqual([64, 323, 20, 7, 7],
62 | mask_predictions.get_shape().as_list())
63 |
64 | # TODO(kaftan): Remove conditional after CMLE moves to TF 1.10
65 |
66 | def test_class_agnostic_prediction_size_use_depthwise_false(self):
67 | conv_hyperparams = self._build_conv_hyperparams()
68 | mask_prediction_head = keras_mask_head.ConvolutionalMaskHead(
69 | is_training=True,
70 | num_classes=20,
71 | use_dropout=True,
72 | dropout_keep_prob=0.5,
73 | kernel_size=3,
74 | conv_hyperparams=conv_hyperparams,
75 | freeze_batchnorm=False,
76 | num_predictions_per_location=1,
77 | use_depthwise=False,
78 | mask_height=7,
79 | mask_width=7,
80 | masks_are_class_agnostic=True)
81 | image_feature = tf.random_uniform(
82 | [64, 17, 19, 1024], minval=-10.0, maxval=10.0, dtype=tf.float32)
83 | mask_predictions = mask_prediction_head(image_feature)
84 | self.assertAllEqual([64, 323, 1, 7, 7],
85 | mask_predictions.get_shape().as_list())
86 |
87 | # TODO(kaftan): Remove conditional after CMLE moves to TF 1.10
88 |
89 | if __name__ == '__main__':
90 | tf.test.main()
91 |
--------------------------------------------------------------------------------
/predictors/heads/keypoint_head_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.predictors.heads.keypoint_head."""
17 | import tensorflow as tf
18 |
19 | from google.protobuf import text_format
20 | from object_detection.builders import hyperparams_builder
21 | from object_detection.predictors.heads import keypoint_head
22 | from object_detection.protos import hyperparams_pb2
23 | from object_detection.utils import test_case
24 |
25 |
26 | class MaskRCNNKeypointHeadTest(test_case.TestCase):
27 |
28 | def _build_arg_scope_with_hyperparams(self,
29 | op_type=hyperparams_pb2.Hyperparams.FC):
30 | hyperparams = hyperparams_pb2.Hyperparams()
31 | hyperparams_text_proto = """
32 | activation: NONE
33 | regularizer {
34 | l2_regularizer {
35 | }
36 | }
37 | initializer {
38 | truncated_normal_initializer {
39 | }
40 | }
41 | """
42 | text_format.Merge(hyperparams_text_proto, hyperparams)
43 | hyperparams.op = op_type
44 | return hyperparams_builder.build(hyperparams, is_training=True)
45 |
46 | def test_prediction_size(self):
47 | keypoint_prediction_head = keypoint_head.MaskRCNNKeypointHead(
48 | conv_hyperparams_fn=self._build_arg_scope_with_hyperparams())
49 | roi_pooled_features = tf.random_uniform(
50 | [64, 14, 14, 1024], minval=-2.0, maxval=2.0, dtype=tf.float32)
51 | prediction = keypoint_prediction_head.predict(
52 | features=roi_pooled_features, num_predictions_per_location=1)
53 | self.assertAllEqual([64, 1, 17, 56, 56], prediction.get_shape().as_list())
54 |
55 |
56 | if __name__ == '__main__':
57 | tf.test.main()
58 |
--------------------------------------------------------------------------------
/protos/anchor_generator.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | import "object_detection/protos/grid_anchor_generator.proto";
6 | import "object_detection/protos/ssd_anchor_generator.proto";
7 | import "object_detection/protos/multiscale_anchor_generator.proto";
8 |
9 | // Configuration proto for the anchor generator to use in the object detection
10 | // pipeline. See core/anchor_generator.py for details.
11 | message AnchorGenerator {
12 | oneof anchor_generator_oneof {
13 | GridAnchorGenerator grid_anchor_generator = 1;
14 | SsdAnchorGenerator ssd_anchor_generator = 2;
15 | MultiscaleAnchorGenerator multiscale_anchor_generator = 3;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/protos/argmax_matcher.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for ArgMaxMatcher. See
6 | // matchers/argmax_matcher.py for details.
7 | message ArgMaxMatcher {
8 | // Threshold for positive matches.
9 | optional float matched_threshold = 1 [default = 0.5];
10 |
11 | // Threshold for negative matches.
12 | optional float unmatched_threshold = 2 [default = 0.5];
13 |
14 | // Whether to construct ArgMaxMatcher without thresholds.
15 | optional bool ignore_thresholds = 3 [default = false];
16 |
17 | // If True then negative matches are the ones below the unmatched_threshold,
18 | // whereas ignored matches are in between the matched and umatched
19 | // threshold. If False, then negative matches are in between the matched
20 | // and unmatched threshold, and everything lower than unmatched is ignored.
21 | optional bool negatives_lower_than_unmatched = 4 [default = true];
22 |
23 | // Whether to ensure each row is matched to at least one column.
24 | optional bool force_match_for_each_row = 5 [default = false];
25 |
26 | // Force constructed match objects to use matrix multiplication based gather
27 | // instead of standard tf.gather
28 | optional bool use_matmul_gather = 6 [default = false];
29 | }
30 |
--------------------------------------------------------------------------------
/protos/bipartite_matcher.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for bipartite matcher. See
6 | // matchers/bipartite_matcher.py for details.
7 | message BipartiteMatcher {
8 | // Force constructed match objects to use matrix multiplication based gather
9 | // instead of standard tf.gather
10 | optional bool use_matmul_gather = 6 [default = false];
11 | }
12 |
--------------------------------------------------------------------------------
/protos/bipartite_matcher_pb2.py:
--------------------------------------------------------------------------------
1 | # Generated by the protocol buffer compiler. DO NOT EDIT!
2 | # source: object_detection/protos/bipartite_matcher.proto
3 |
4 | import sys
5 | _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
6 | from google.protobuf import descriptor as _descriptor
7 | from google.protobuf import message as _message
8 | from google.protobuf import reflection as _reflection
9 | from google.protobuf import symbol_database as _symbol_database
10 | # @@protoc_insertion_point(imports)
11 |
12 | _sym_db = _symbol_database.Default()
13 |
14 |
15 |
16 |
17 | DESCRIPTOR = _descriptor.FileDescriptor(
18 | name='object_detection/protos/bipartite_matcher.proto',
19 | package='object_detection.protos',
20 | syntax='proto2',
21 | serialized_options=None,
22 | serialized_pb=_b('\n/object_detection/protos/bipartite_matcher.proto\x12\x17object_detection.protos\"4\n\x10\x42ipartiteMatcher\x12 \n\x11use_matmul_gather\x18\x06 \x01(\x08:\x05\x66\x61lse')
23 | )
24 |
25 |
26 |
27 |
28 | _BIPARTITEMATCHER = _descriptor.Descriptor(
29 | name='BipartiteMatcher',
30 | full_name='object_detection.protos.BipartiteMatcher',
31 | filename=None,
32 | file=DESCRIPTOR,
33 | containing_type=None,
34 | fields=[
35 | _descriptor.FieldDescriptor(
36 | name='use_matmul_gather', full_name='object_detection.protos.BipartiteMatcher.use_matmul_gather', index=0,
37 | number=6, type=8, cpp_type=7, label=1,
38 | has_default_value=True, default_value=False,
39 | message_type=None, enum_type=None, containing_type=None,
40 | is_extension=False, extension_scope=None,
41 | serialized_options=None, file=DESCRIPTOR),
42 | ],
43 | extensions=[
44 | ],
45 | nested_types=[],
46 | enum_types=[
47 | ],
48 | serialized_options=None,
49 | is_extendable=False,
50 | syntax='proto2',
51 | extension_ranges=[],
52 | oneofs=[
53 | ],
54 | serialized_start=76,
55 | serialized_end=128,
56 | )
57 |
58 | DESCRIPTOR.message_types_by_name['BipartiteMatcher'] = _BIPARTITEMATCHER
59 | _sym_db.RegisterFileDescriptor(DESCRIPTOR)
60 |
61 | BipartiteMatcher = _reflection.GeneratedProtocolMessageType('BipartiteMatcher', (_message.Message,), dict(
62 | DESCRIPTOR = _BIPARTITEMATCHER,
63 | __module__ = 'object_detection.protos.bipartite_matcher_pb2'
64 | # @@protoc_insertion_point(class_scope:object_detection.protos.BipartiteMatcher)
65 | ))
66 | _sym_db.RegisterMessage(BipartiteMatcher)
67 |
68 |
69 | # @@protoc_insertion_point(module_scope)
70 |
--------------------------------------------------------------------------------
/protos/box_coder.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | import "object_detection/protos/faster_rcnn_box_coder.proto";
6 | import "object_detection/protos/keypoint_box_coder.proto";
7 | import "object_detection/protos/mean_stddev_box_coder.proto";
8 | import "object_detection/protos/square_box_coder.proto";
9 |
10 | // Configuration proto for the box coder to be used in the object detection
11 | // pipeline. See core/box_coder.py for details.
12 | message BoxCoder {
13 | oneof box_coder_oneof {
14 | FasterRcnnBoxCoder faster_rcnn_box_coder = 1;
15 | MeanStddevBoxCoder mean_stddev_box_coder = 2;
16 | SquareBoxCoder square_box_coder = 3;
17 | KeypointBoxCoder keypoint_box_coder = 4;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/protos/eval.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Message for configuring DetectionModel evaluation jobs (eval.py).
6 | message EvalConfig {
7 | optional uint32 batch_size = 25 [default=1];
8 | // Number of visualization images to generate.
9 | optional uint32 num_visualizations = 1 [default=10];
10 |
11 | // Number of examples to process of evaluation.
12 | optional uint32 num_examples = 2 [default=5000, deprecated=true];
13 |
14 | // How often to run evaluation.
15 | optional uint32 eval_interval_secs = 3 [default=300];
16 |
17 | // Maximum number of times to run evaluation. If set to 0, will run forever.
18 | optional uint32 max_evals = 4 [default=0, deprecated=true];
19 |
20 | // Whether the TensorFlow graph used for evaluation should be saved to disk.
21 | optional bool save_graph = 5 [default=false];
22 |
23 | // Path to directory to store visualizations in. If empty, visualization
24 | // images are not exported (only shown on Tensorboard).
25 | optional string visualization_export_dir = 6 [default=""];
26 |
27 | // BNS name of the TensorFlow master.
28 | optional string eval_master = 7 [default=""];
29 |
30 | // Type of metrics to use for evaluation.
31 | repeated string metrics_set = 8;
32 |
33 | // Path to export detections to COCO compatible JSON format.
34 | optional string export_path = 9 [default=''];
35 |
36 | // Option to not read groundtruth labels and only export detections to
37 | // COCO-compatible JSON file.
38 | optional bool ignore_groundtruth = 10 [default=false];
39 |
40 | // Use exponential moving averages of variables for evaluation.
41 | // TODO(rathodv): When this is false make sure the model is constructed
42 | // without moving averages in restore_fn.
43 | optional bool use_moving_averages = 11 [default=false];
44 |
45 | // Whether to evaluate instance masks.
46 | // Note that since there is no evaluation code currently for instance
47 | // segmenation this option is unused.
48 | optional bool eval_instance_masks = 12 [default=false];
49 |
50 | // Minimum score threshold for a detected object box to be visualized
51 | optional float min_score_threshold = 13 [default=0.5];
52 |
53 | // Maximum number of detections to visualize
54 | optional int32 max_num_boxes_to_visualize = 14 [default=20];
55 |
56 | // When drawing a single detection, each label is by default visualized as
57 | //