"src/targets/gpu/vscode:/vscode.git/clone" did not exist on "c658d5216877eac3d7cdd95abd90625f8e56594d"
Commit 05584085 authored by pkulzc's avatar pkulzc Committed by Jonathan Huang
Browse files

Merged commit includes the following changes: (#6315)

236813471  by lzc:

    Internal change.

--
236507310  by lzc:

    Fix preprocess.random_resize_method config type issue. The target height and width will be passed as "size" to tf.image.resize_images which only accepts integer.

--
236409989  by Zhichao Lu:

    Config export_to_tpu from function parameter instead of HParams for TPU inference.

--
236403186  by Zhichao Lu:

    Make graph file names optional arguments.

--
236237072  by Zhichao Lu:

    Minor bugfix for keyword args.

--
236209602  by Zhichao Lu:

    Add support for PartitionedVariable to get_variables_available_in_checkpoint.

--
235828658  by Zhichao Lu:

    Automatically stop evaluation jobs when training is finished.

--
235817964  by Zhichao Lu:

    Add an optional process_metrics_fn callback to eval_util, it gets called
    with evaluation results once each evaluation is complete.

--
235788721  by lzc:

    Fix yml file tf runtime version.

--
235262897  by Zhichao Lu:

    Add keypoint support to the random_pad_image preprocessor method.

--
235257380  by Zhichao Lu:

    Support InputDataFields.groundtruth_confidences in retain_groundtruth(), retain_groundtruth_with_positive_classes(), filter_groundtruth_with_crowd_boxes(), filter_groundtruth_with_nan_box_coordinates(), filter_unrecognized_classes().

--
235109188  by Zhichao Lu:

    Fix bug in pad_input_data_to_static_shapes for num_additional_channels > 0; make color-specific data augmentation only touch RGB channels.

--
235045010  by Zhichao Lu:

    Don't slice class_predictions_with_background when add_background_class is false.

--
235026189  by lzc:

    Fix import in g3doc.

--
234863426  by Zhichao Lu:

    Added fixes in exporter to allow writing a checkpoint to a specified temporary directory.

--
234671886  by lzc:

    Internal Change.

--
234630803  by rathodv:

    Internal Change.

--
233985896  by Zhichao Lu:

    Add Neumann optimizer to object detection.

--
233560911  by Zhichao Lu:

    Add NAS-FPN object detection with Resnet and Mobilenet v2.

--
233513536  by Zhichao Lu:

    Export TPU compatible object detection model

--
233495772  by lzc:

    Internal change.

--
233453557  by Zhichao Lu:

    Create Keras-based SSD+MobilenetV1 for object detection.

--
233220074  by lzc:

    Update release notes date.

--
233165761  by Zhichao Lu:

    Support depth_multiplier and min_depth in _SSDResnetV1FpnFeatureExtractor.

--
233160046  by lzc:

    Internal change.

--
232926599  by Zhichao Lu:

    [tf.data] Switching tf.data functions to use `defun`, providing an escape hatch to continue using the legacy `Defun`.

    There are subtle differences between the implementation of `defun` and `Defun` (such as resources handling or control flow) and it is possible that input pipelines that use control flow or resources in their functions might be affected by this change. To migrate majority of existing pipelines to the recommended way of creating functions in TF 2.0 world, while allowing (a small number of) existing pipelines to continue relying on the deprecated behavior, this CL provides an escape hatch.

    If your input pipeline is affected by this CL, it should apply the escape hatch by replacing `foo.map(...)` with `foo.map_with_legacy_function(...)`.

--
232891621  by Zhichao Lu:

    Modify faster_rcnn meta architecture to normalize raw detections.

--
232875817  by Zhichao Lu:

    Make calibration a post-processing step.

    Specifically:
    - Move the calibration config from pipeline.proto --> post_processing.proto
    - Edit post_processing_builder.py to return a calibration function. If no calibration config is provided, it None.
    - Edit SSD and FasterRCNN meta architectures to optionally call the calibration function on detection scores after score conversion and before NMS.

--
232704481  by Zhichao Lu:

    Edit calibration builder to build a function that will be used within a detection model's `postprocess` method, after score conversion and before non-maxima suppression.

    Specific Edits:
    - The returned function now accepts class_predictions_with_background as its argument instead of detection_scores and detection_classes.
    - Class-specific calibration was temporarily removed, as it requires more significant refactoring. Will be added later.

--
232615379  by Zhichao Lu:

    Internal change

--
232483345  by ronnyvotel:

    Making the use of bfloat16 restricted to TPUs.

--
232399572  by Zhichao Lu:

    Edit calibration builder and proto to support class-agnostic calibration.

    Specifically:
    - Edit calibration protos to include path to relevant label map if required for class-specific calibration. Previously, label maps were inferred from other parts of the pipeline proto; this allows all information required by the builder stay within the calibration proto and remove extraneous information from being passed with class-agnostic calibration.
    - Add class-agnostic protos to the calibration config.

    Note that the proto supports sigmoid and linear interpolation parameters, but the builder currently only supports linear interpolation.

--
231613048  by Zhichao Lu:

    Add calibration builder for applying calibration transformations from output of object detection models.

    Specifically:
    - Add calibration proto to support sigmoid and isotonic regression (stepwise function) calibration.
    - Add a builder to support calibration from isotonic regression outputs.

--
231519786  by lzc:

    model_builder test refactor.
    - removed proto text boilerplate in each test case and let them call a create_default_proto function instead.
    - consolidated all separate ssd model creation tests into one.
    - consolidated all separate faster rcnn model creation tests into one.
    - used parameterized test for testing mask rcnn models and use_matmul_crop_and_resize
    - added all failures test.

--
231448169  by Zhichao Lu:

    Return static shape as a constant tensor.

--
231423126  by lzc:

    Add a release note for OID v4 models.

--
231401941  by Zhichao Lu:

    Adding correct labelmap for the models trained on Open Images V4 (*oid_v4
    config suffix).

--
231320357  by Zhichao Lu:

    Add scope to Nearest Neighbor Resize op so that it stays in the same name scope as the original resize ops.

--
231257699  by Zhichao Lu:

    Switch to using preserve_aspect_ratio in tf.image.resize_images rather than using a custom implementation.

--
231247368  by rathodv:

    Internal change.

--
231004874  by lzc:

    Update documentations to use tf 1.12 for object detection API.

--
230999911  by rathodv:

    Use tf.batch_gather instead of ops.batch_gather

--
230999720  by huizhongc:

    Fix weight equalization test in ops_test.

--
230984728  by rathodv:

    Internal update.

--
230929019  by lzc:

    Add an option to replace preprocess operation with placeholder for ssd feature extractor.

--
230845266  by lzc:

    Require tensorflow version 1.12 for object detection API and rename keras_applications to keras_models

--
230392064  by lzc:

    Add RetinaNet 101 checkpoint trained on OID v4 to detection model zoo.

--
230014128  by derekjchow:

    This file was re-located below the tensorflow/lite/g3doc/convert

--
229941449  by lzc:

    Update SSD mobilenet v2 quantized model download path.

--
229843662  by lzc:

    Add an option to use native resize tf op in fpn top-down feature map generation.

--
229636034  by rathodv:

    Add deprecation notice to a few old parameters in train.proto

--
228959078  by derekjchow:

    Remove duplicate elif case in _check_and_convert_legacy_input_config_key

--
228749719  by rathodv:

    Minor refactoring to make exporter's `build_detection_graph` method public.

--
228573828  by rathodv:

    Mofity model.postprocess to return raw detections and raw scores.

    Modify, post-process methods in core/model.py and the meta architectures to export raw detection (without any non-max suppression) and raw multiclass score logits for those detections.

--
228420670  by Zhichao Lu:

    Add shims for custom architectures for object detection models.

--
228241692  by Zhichao Lu:

    Fix the comment on "losses_mask" in "Loss" class.

--
228223810  by Zhichao Lu:

    Support other_heads' predictions in WeightSharedConvolutionalBoxPredictor. Also remove a few unused parameters and fix a couple of comments in convolutional_box_predictor.py.

--
228200588  by Zhichao Lu:

    Add Expected Calibration Error and an evaluator that calculates the metric for object detections.

--
228167740  by lzc:

    Add option to use bounded activations in FPN top-down feature map generation.

--
227767700  by rathodv:

    Internal.

--
226295236  by Zhichao Lu:

    Add Open Image V4 Resnet101-FPN training config to third_party

--
226254842  by Zhichao Lu:

    Fix typo in documentation.

--
225833971  by Zhichao Lu:

    Option to have no resizer in object detection model.

--
225824890  by lzc:

    Fixes p3 compatibility for model_lib.py

--
225760897  by menglong:

    normalizer should be at least 1.

--
225559842  by menglong:

    Add extra logic filtering unrecognized classes.

--
225379421  by lzc:

    Add faster_rcnn_inception_resnet_v2_atrous_oid_v4 config to third_party

--
225368337  by Zhichao Lu:

    Add extra logic filtering unrecognized classes.

--
225341095  by Zhichao Lu:

    Adding Open Images V4 models to OD API model zoo and corresponding configs to the
    configs.

--
225218450  by menglong:

    Add extra logic filtering unrecognized classes.

--
225057591  by Zhichao Lu:

    Internal change.

--
224895417  by rathodv:

    Internal change.

--
224209282  by Zhichao Lu:

    Add two data augmentations to object detection: (1) Self-concat (2) Absolute pads.

--
224073762  by Zhichao Lu:

    Do not create tf.constant until _generate() is actually called in the object detector.

--

PiperOrigin-RevId: 236813471
parent a5db4420
......@@ -184,6 +184,11 @@ message SsdFeatureExtractor {
// Feature Pyramid Networks config.
optional FeaturePyramidNetworks fpn = 10;
// If true, replace preprocess function of feature extractor with a
// placeholder. This should only be used if all the image preprocessing steps
// happen outside the graph.
optional bool replace_preprocessor_with_placeholder = 11 [default = false];
}
// Configuration for Feature Pyramid Networks.
......@@ -210,4 +215,5 @@ message FeaturePyramidNetworks {
// channel depth for additional coarse feature layers.
optional int32 additional_layer_depth = 3 [default = 256];
}
......@@ -74,13 +74,13 @@ message TrainConfig {
optional int32 replicas_to_aggregate = 13 [default=1];
// Maximum number of elements to store within a queue.
optional int32 batch_queue_capacity = 14 [default=150];
optional int32 batch_queue_capacity = 14 [default=150, deprecated=true];
// Number of threads to use for batching.
optional int32 num_batch_queue_threads = 15 [default=8];
optional int32 num_batch_queue_threads = 15 [default=8, deprecated=true];
// Maximum capacity of the queue used to prefetch assembled batches.
optional int32 prefetch_queue_capacity = 16 [default=5];
optional int32 prefetch_queue_capacity = 16 [default=5, deprecated=true];
// If true, boxes with the same coordinates will be merged together.
// This is useful when each box can have multiple labels.
......@@ -113,7 +113,8 @@ message TrainConfig {
// will lead to a larger memory footprint.
optional bool retain_original_images = 23 [default=false];
// Whether to use bfloat16 for training.
// Whether to use bfloat16 for training. This is currently only supported for
// TPUs.
optional bool use_bfloat16 = 26 [default=false];
// Whether to summarize gradients.
......
trainingInput:
runtimeVersion: "1.9"
runtimeVersion: "1.12"
scaleTier: CUSTOM
masterType: standard_gpu
workerCount: 5
......
# Faster R-CNN with Inception Resnet v2, Atrous version;
# Configured for Open Images V4 Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
# should be configured.
model {
faster_rcnn {
num_classes: 601
image_resizer {
keep_aspect_ratio_resizer {
min_dimension: 600
max_dimension: 1024
}
}
feature_extractor {
type: "faster_rcnn_inception_resnet_v2"
first_stage_features_stride: 8
}
first_stage_anchor_generator {
grid_anchor_generator {
scales: 0.25
scales: 0.5
scales: 1.0
scales: 2.0
aspect_ratios: 0.5
aspect_ratios: 1.0
aspect_ratios: 2.0
height_stride: 8
width_stride: 8
}
}
first_stage_atrous_rate: 2
first_stage_box_predictor_conv_hyperparams {
op: CONV
regularizer {
l2_regularizer {
weight: 0.0
}
}
initializer {
truncated_normal_initializer {
stddev: 0.01
}
}
}
first_stage_nms_score_threshold: 0.0
first_stage_nms_iou_threshold: 0.7
first_stage_max_proposals: 300
first_stage_localization_loss_weight: 2.0
first_stage_objectness_loss_weight: 1.0
initial_crop_size: 17
maxpool_kernel_size: 1
maxpool_stride: 1
second_stage_box_predictor {
mask_rcnn_box_predictor {
use_dropout: false
dropout_keep_probability: 1.0
fc_hyperparams {
op: FC
regularizer {
l2_regularizer {
weight: 0.0
}
}
initializer {
variance_scaling_initializer {
factor: 1.0
uniform: true
mode: FAN_AVG
}
}
}
}
}
second_stage_post_processing {
batch_non_max_suppression {
score_threshold: 0.0
iou_threshold: 0.6
max_detections_per_class: 100
max_total_detections: 100
}
score_converter: SOFTMAX
}
second_stage_localization_loss_weight: 2.0
second_stage_classification_loss_weight: 1.0
}
}
train_config: {
batch_size: 1
optimizer {
momentum_optimizer: {
learning_rate: {
manual_step_learning_rate {
initial_learning_rate: 0.00006
schedule {
step: 6000000
learning_rate: .000006
}
schedule {
step: 7000000
learning_rate: .0000006
}
}
}
momentum_optimizer_value: 0.9
}
use_moving_average: false
}
gradient_clipping_by_norm: 10.0
fine_tune_checkpoint: "PATH_TO_BE_CONFIGURED/model.ckpt"
num_steps: 10000000
data_augmentation_options {
random_horizontal_flip {
}
}
}
train_input_reader: {
tf_record_input_reader {
input_path: "PATH_TO_BE_CONFIGURED/oid_bbox_trainable_train.record"
}
label_map_path: "PATH_TO_BE_CONFIGURED/oid_v4_label_map.pbtxt"
}
eval_config: {
metrics_set: "open_images_V2_detection_metrics"
}
eval_input_reader: {
sample_1_of_n_examples: 10
tf_record_input_reader {
input_path: "PATH_TO_BE_CONFIGURED/oid_bbox_trainable_val.record"
}
label_map_path: "PATH_TO_BE_CONFIGURED/oid_v4_label_map.pbtxt"
shuffle: false
num_readers: 1
}
# SSD with Mobilenet v2 configuration for OpenImages V4 Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
# should be configured.
model {
ssd {
num_classes: 601
box_coder {
faster_rcnn_box_coder {
y_scale: 10.0
x_scale: 10.0
height_scale: 5.0
width_scale: 5.0
}
}
matcher {
argmax_matcher {
matched_threshold: 0.5
unmatched_threshold: 0.5
ignore_thresholds: false
negatives_lower_than_unmatched: true
force_match_for_each_row: true
}
}
similarity_calculator {
iou_similarity {
}
}
anchor_generator {
ssd_anchor_generator {
num_layers: 6
min_scale: 0.2
max_scale: 0.95
aspect_ratios: 1.0
aspect_ratios: 2.0
aspect_ratios: 0.5
aspect_ratios: 3.0
aspect_ratios: 0.3333
}
}
image_resizer {
fixed_shape_resizer {
height: 300
width: 300
}
}
box_predictor {
convolutional_box_predictor {
min_depth: 0
max_depth: 0
num_layers_before_predictor: 0
use_dropout: false
dropout_keep_probability: 0.8
kernel_size: 1
box_code_size: 4
apply_sigmoid_to_scores: false
conv_hyperparams {
activation: RELU_6,
regularizer {
l2_regularizer {
weight: 0.00004
}
}
initializer {
truncated_normal_initializer {
stddev: 0.03
mean: 0.0
}
}
batch_norm {
train: true,
scale: true,
center: true,
decay: 0.9997,
epsilon: 0.001,
}
}
}
}
feature_extractor {
type: 'ssd_mobilenet_v2'
min_depth: 16
depth_multiplier: 1.0
conv_hyperparams {
activation: RELU_6,
regularizer {
l2_regularizer {
weight: 0.00004
}
}
initializer {
truncated_normal_initializer {
stddev: 0.03
mean: 0.0
}
}
batch_norm {
train: true,
scale: true,
center: true,
decay: 0.9997,
epsilon: 0.001,
}
}
}
loss {
classification_loss {
weighted_sigmoid {
}
}
localization_loss {
weighted_smooth_l1 {
}
}
hard_example_miner {
num_hard_examples: 3000
iou_threshold: 0.99
loss_type: CLASSIFICATION
max_negatives_per_positive: 3
min_negatives_per_image: 3
}
classification_weight: 1.0
localization_weight: 1.0
}
normalize_loss_by_num_matches: true
post_processing {
batch_non_max_suppression {
score_threshold: 1e-8
iou_threshold: 0.6
max_detections_per_class: 100
max_total_detections: 100
}
score_converter: SIGMOID
}
}
}
train_config: {
batch_size: 24
optimizer {
rms_prop_optimizer: {
learning_rate: {
exponential_decay_learning_rate {
initial_learning_rate: 0.0008
decay_steps: 800720
decay_factor: 0.95
}
}
momentum_optimizer_value: 0.9
decay: 0.9
epsilon: 1.0
}
}
gradient_clipping_by_norm: 10.0
keep_checkpoint_every_n_hours: 24
fine_tune_checkpoint: "PATH_TO_BE_CONFIGURED/model.ckpt"
num_steps: 10000000
data_augmentation_options {
random_horizontal_flip {
}
}
data_augmentation_options {
ssd_random_crop {
}
}
}
train_input_reader: {
tf_record_input_reader {
input_path: "PATH_TO_BE_CONFIGURED/oid_bbox_trainable_train.record"
}
label_map_path: "PATH_TO_BE_CONFIGURED/oid_v4_label_map.pbtxt"
}
eval_config: {
metrics_set: "open_images_V2_detection_metrics"
}
eval_input_reader: {
sample_1_of_n_examples: 10
tf_record_input_reader {
input_path: "PATH_TO_BE_CONFIGURED/oid_bbox_trainable_val.record"
}
label_map_path: "PATH_TO_BE_CONFIGURED/oid_v4_label_map.pbtxt"
shuffle: false
num_readers: 1
}
# SSD with Resnet 101 v1 FPN feature extractor, shared box predictor and focal
# loss (a.k.a Retinanet).
# See Lin et al, https://arxiv.org/abs/1708.02002
# Trained on open image dataset v4, initialized from scratch.
# This config is TPU compatible
model {
ssd {
inplace_batchnorm_update: true
freeze_batchnorm: false
num_classes: 601
box_coder {
faster_rcnn_box_coder {
y_scale: 10.0
x_scale: 10.0
height_scale: 5.0
width_scale: 5.0
}
}
matcher {
argmax_matcher {
matched_threshold: 0.5
unmatched_threshold: 0.5
ignore_thresholds: false
negatives_lower_than_unmatched: true
force_match_for_each_row: true
use_matmul_gather: true
}
}
similarity_calculator {
iou_similarity {
}
}
encode_background_as_zeros: true
anchor_generator {
multiscale_anchor_generator {
min_level: 2
max_level: 7
anchor_scale: 4.0
aspect_ratios: [1.0, 2.0, 0.5]
scales_per_octave: 2
}
}
image_resizer {
fixed_shape_resizer {
height: 512
width: 512
}
}
box_predictor {
weight_shared_convolutional_box_predictor {
depth: 256
class_prediction_bias_init: -4.6
conv_hyperparams {
activation: RELU_6,
regularizer {
l2_regularizer {
weight: 0.0004
}
}
initializer {
random_normal_initializer {
stddev: 0.01
mean: 0.0
}
}
batch_norm {
scale: true,
decay: 0.997,
epsilon: 0.001,
}
}
num_layers_before_predictor: 2
kernel_size: 3
}
}
feature_extractor {
type: 'ssd_resnet101_v1_fpn'
fpn {
min_level: 2
max_level: 7
}
min_depth: 16
depth_multiplier: 1.0
conv_hyperparams {
activation: RELU_6,
regularizer {
l2_regularizer {
weight: 0.0004
}
}
initializer {
truncated_normal_initializer {
stddev: 0.03
mean: 0.0
}
}
batch_norm {
scale: true,
decay: 0.997,
epsilon: 0.001,
}
}
override_base_feature_extractor_hyperparams: true
}
loss {
classification_loss {
weighted_sigmoid_focal {
alpha: 0.25
gamma: 2.0
}
}
localization_loss {
weighted_smooth_l1 {
}
}
classification_weight: 1.0
localization_weight: 1.0
}
normalize_loss_by_num_matches: true
normalize_loc_loss_by_codesize: true
post_processing {
batch_non_max_suppression {
score_threshold: 1e-8
iou_threshold: 0.6
max_detections_per_class: 100
max_total_detections: 100
use_static_shapes: true
}
score_converter: SIGMOID
}
}
}
train_config: {
batch_size: 64
sync_replicas: true
startup_delay_steps: 0
replicas_to_aggregate: 8
num_steps: 400000
data_augmentation_options {
random_horizontal_flip {
}
}
data_augmentation_options {
random_crop_image {
min_object_covered: 0.0
min_aspect_ratio: 0.75
max_aspect_ratio: 3.0
min_area: 0.75
max_area: 1.0
overlap_thresh: 0.0
}
}
optimizer {
momentum_optimizer: {
learning_rate: {
cosine_decay_learning_rate {
learning_rate_base: .04
total_steps: 400000
warmup_learning_rate: .013333
warmup_steps: 2000
}
}
momentum_optimizer_value: 0.9
}
use_moving_average: false
}
max_number_of_boxes: 100
unpad_groundtruth_tensors: false
}
train_input_reader: {
tf_record_input_reader {
input_path: "PATH_TO_BE_CONFIGURED/oid_bbox_trainable_train.record"
}
label_map_path: "PATH_TO_BE_CONFIGURED/oid_bbox_trainable_label_map.pbtxt"
}
eval_config: {
metrics_set: "oid_V2_detection_metrics"
}
eval_input_reader: {
sample_1_of_n_examples: 10
tf_record_input_reader {
input_path: "PATH_TO_BE_CONFIGURED/oid_bbox_trainable_val.record"
}
label_map_path: "PATH_TO_BE_CONFIGURED/oid_bbox_trainable_label_map.pbtxt"
shuffle: false
num_readers: 1
}
......@@ -73,6 +73,8 @@ def get_spatial_image_size(image_resizer_config):
return [image_resizer_config.keep_aspect_ratio_resizer.max_dimension] * 2
else:
return [-1, -1]
if image_resizer_config.HasField("identity_resizer"):
return [-1, -1]
raise ValueError("Unknown image resizer type.")
......
......@@ -184,7 +184,9 @@ def get_label_map_dict(label_map_path,
# there are gaps in the labels, fill in gaps.
for value in range(1, max(values)):
if value not in values:
label_map_dict['class_' + str(value)] = value
# TODO(rathodv): Add a prefix 'class_' here once the tool to generate
# teacher annotation adds this prefix in the data.
label_map_dict[str(value)] = value
return label_map_dict
......
......@@ -138,7 +138,7 @@ class LabelMapUtilTest(tf.test.TestCase):
self.assertEqual(label_map_dict['background'], 0)
self.assertEqual(label_map_dict['dog'], 1)
self.assertEqual(label_map_dict['class_2'], 2)
self.assertEqual(label_map_dict['2'], 2)
self.assertEqual(label_map_dict['cat'], 3)
self.assertEqual(len(label_map_dict), max(label_map_dict.values()) + 1)
......
......@@ -328,6 +328,7 @@ def retain_groundtruth(tensor_dict, valid_indices):
tensor_dict: a dictionary of following groundtruth tensors -
fields.InputDataFields.groundtruth_boxes
fields.InputDataFields.groundtruth_classes
fields.InputDataFields.groundtruth_confidences
fields.InputDataFields.groundtruth_keypoints
fields.InputDataFields.groundtruth_instance_masks
fields.InputDataFields.groundtruth_is_crowd
......@@ -357,7 +358,9 @@ def retain_groundtruth(tensor_dict, valid_indices):
for key in tensor_dict:
if key in [fields.InputDataFields.groundtruth_boxes,
fields.InputDataFields.groundtruth_classes,
fields.InputDataFields.groundtruth_confidences,
fields.InputDataFields.groundtruth_keypoints,
fields.InputDataFields.groundtruth_keypoint_visibilities,
fields.InputDataFields.groundtruth_instance_masks]:
valid_dict[key] = tf.gather(tensor_dict[key], valid_indices)
# Input decoder returns empty tensor when these fields are not provided.
......@@ -385,6 +388,7 @@ def retain_groundtruth_with_positive_classes(tensor_dict):
tensor_dict: a dictionary of following groundtruth tensors -
fields.InputDataFields.groundtruth_boxes
fields.InputDataFields.groundtruth_classes
fields.InputDataFields.groundtruth_confidences
fields.InputDataFields.groundtruth_keypoints
fields.InputDataFields.groundtruth_instance_masks
fields.InputDataFields.groundtruth_is_crowd
......@@ -426,6 +430,7 @@ def filter_groundtruth_with_crowd_boxes(tensor_dict):
tensor_dict: a dictionary of following groundtruth tensors -
fields.InputDataFields.groundtruth_boxes
fields.InputDataFields.groundtruth_classes
fields.InputDataFields.groundtruth_confidences
fields.InputDataFields.groundtruth_keypoints
fields.InputDataFields.groundtruth_instance_masks
fields.InputDataFields.groundtruth_is_crowd
......@@ -451,6 +456,7 @@ def filter_groundtruth_with_nan_box_coordinates(tensor_dict):
tensor_dict: a dictionary of following groundtruth tensors -
fields.InputDataFields.groundtruth_boxes
fields.InputDataFields.groundtruth_classes
fields.InputDataFields.groundtruth_confidences
fields.InputDataFields.groundtruth_keypoints
fields.InputDataFields.groundtruth_instance_masks
fields.InputDataFields.groundtruth_is_crowd
......@@ -470,6 +476,36 @@ def filter_groundtruth_with_nan_box_coordinates(tensor_dict):
return retain_groundtruth(tensor_dict, valid_indices)
def filter_unrecognized_classes(tensor_dict):
"""Filters out class labels that are not unrecognized by the labelmap.
Decoder would parse unrecognized classes (not included in the labelmap) to
a label of value -1. Such targets are unecessary for training, and causes
issue for evaluation, due to labeling mapping logic. This function filters
those labels out for both training and evaluation.
Args:
tensor_dict: dictionary containing input tensors keyed by
fields.InputDataFields.
Returns:
A dictionary keyed by fields.InputDataFields containing the tensors
obtained after applying the filtering.
Raises:
ValueError: If groundtruth_classes tensor is not in tensor_dict.
"""
if fields.InputDataFields.groundtruth_classes not in tensor_dict:
raise ValueError('`groundtruth classes` not in tensor_dict.')
# Refer to tf_example_decoder for how unrecognized labels are handled.
unrecognized_label = -1
recognized_indices = tf.where(
tf.greater(tensor_dict[fields.InputDataFields.groundtruth_classes],
unrecognized_label))
return retain_groundtruth(tensor_dict, recognized_indices)
def normalize_to_target(inputs,
target_norm_value,
dim,
......
......@@ -401,6 +401,7 @@ class GroundtruthFilterTest(tf.test.TestCase):
input_area = tf.placeholder(tf.float32, shape=(None,))
input_difficult = tf.placeholder(tf.float32, shape=(None,))
input_label_types = tf.placeholder(tf.string, shape=(None,))
input_confidences = tf.placeholder(tf.float32, shape=(None,))
valid_indices = tf.placeholder(tf.int32, shape=(None,))
input_tensors = {
fields.InputDataFields.image: input_image,
......@@ -409,7 +410,8 @@ class GroundtruthFilterTest(tf.test.TestCase):
fields.InputDataFields.groundtruth_is_crowd: input_is_crowd,
fields.InputDataFields.groundtruth_area: input_area,
fields.InputDataFields.groundtruth_difficult: input_difficult,
fields.InputDataFields.groundtruth_label_types: input_label_types
fields.InputDataFields.groundtruth_label_types: input_label_types,
fields.InputDataFields.groundtruth_confidences: input_confidences,
}
output_tensors = ops.retain_groundtruth(input_tensors, valid_indices)
......@@ -418,40 +420,31 @@ class GroundtruthFilterTest(tf.test.TestCase):
input_image: image_tensor,
input_boxes:
np.array([[0.2, 0.4, 0.1, 0.8], [0.2, 0.4, 1.0, 0.8]], dtype=np.float),
input_classes:
np.array([1, 2], dtype=np.int32),
input_is_crowd:
np.array([False, True], dtype=np.bool),
input_area:
np.array([32, 48], dtype=np.float32),
input_difficult:
np.array([True, False], dtype=np.bool),
input_classes: np.array([1, 2], dtype=np.int32),
input_is_crowd: np.array([False, True], dtype=np.bool),
input_area: np.array([32, 48], dtype=np.float32),
input_difficult: np.array([True, False], dtype=np.bool),
input_label_types:
np.array(['APPROPRIATE', 'INCORRECT'], dtype=np.string_),
valid_indices:
np.array([0], dtype=np.int32)
input_confidences: np.array([0.99, 0.5], dtype=np.float32),
valid_indices: np.array([0], dtype=np.int32),
}
expected_tensors = {
fields.InputDataFields.image:
image_tensor,
fields.InputDataFields.groundtruth_boxes:
[[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes:
[1],
fields.InputDataFields.groundtruth_is_crowd:
[False],
fields.InputDataFields.groundtruth_area:
[32],
fields.InputDataFields.groundtruth_difficult:
[True],
fields.InputDataFields.groundtruth_label_types:
['APPROPRIATE']
fields.InputDataFields.image: image_tensor,
fields.InputDataFields.groundtruth_boxes: [[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes: [1],
fields.InputDataFields.groundtruth_is_crowd: [False],
fields.InputDataFields.groundtruth_area: [32],
fields.InputDataFields.groundtruth_difficult: [True],
fields.InputDataFields.groundtruth_label_types: ['APPROPRIATE'],
fields.InputDataFields.groundtruth_confidences: [0.99],
}
with self.test_session() as sess:
output_tensors = sess.run(output_tensors, feed_dict=feed_dict)
for key in [fields.InputDataFields.image,
fields.InputDataFields.groundtruth_boxes,
fields.InputDataFields.groundtruth_area]:
fields.InputDataFields.groundtruth_area,
fields.InputDataFields.groundtruth_confidences]:
self.assertAllClose(expected_tensors[key], output_tensors[key])
for key in [fields.InputDataFields.groundtruth_classes,
fields.InputDataFields.groundtruth_is_crowd,
......@@ -496,46 +489,41 @@ class GroundtruthFilterTest(tf.test.TestCase):
input_is_crowd = tf.placeholder(tf.bool, shape=(None,))
input_area = tf.placeholder(tf.float32, shape=(None,))
input_difficult = tf.placeholder(tf.float32, shape=(None,))
input_confidences = tf.placeholder(tf.float32, shape=(None,))
valid_indices = tf.placeholder(tf.int32, shape=(None,))
input_tensors = {
fields.InputDataFields.groundtruth_boxes: input_boxes,
fields.InputDataFields.groundtruth_classes: input_classes,
fields.InputDataFields.groundtruth_is_crowd: input_is_crowd,
fields.InputDataFields.groundtruth_area: input_area,
fields.InputDataFields.groundtruth_difficult: input_difficult
fields.InputDataFields.groundtruth_difficult: input_difficult,
fields.InputDataFields.groundtruth_confidences: input_confidences,
}
output_tensors = ops.retain_groundtruth(input_tensors, valid_indices)
feed_dict = {
input_boxes:
np.array([[0.2, 0.4, 0.1, 0.8], [0.2, 0.4, 1.0, 0.8]], dtype=np.float),
input_classes:
np.array([1, 2], dtype=np.int32),
input_is_crowd:
np.array([False, True], dtype=np.bool),
input_area:
np.array([], dtype=np.float32),
input_difficult:
np.array([], dtype=np.float32),
valid_indices:
np.array([0], dtype=np.int32)
input_classes: np.array([1, 2], dtype=np.int32),
input_is_crowd: np.array([False, True], dtype=np.bool),
input_area: np.array([], dtype=np.float32),
input_difficult: np.array([], dtype=np.float32),
input_confidences: np.array([0.99, 0.5], dtype=np.float32),
valid_indices: np.array([0], dtype=np.int32)
}
expected_tensors = {
fields.InputDataFields.groundtruth_boxes:
[[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes:
[1],
fields.InputDataFields.groundtruth_is_crowd:
[False],
fields.InputDataFields.groundtruth_area:
[],
fields.InputDataFields.groundtruth_difficult:
[]
fields.InputDataFields.groundtruth_boxes: [[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes: [1],
fields.InputDataFields.groundtruth_is_crowd: [False],
fields.InputDataFields.groundtruth_area: [],
fields.InputDataFields.groundtruth_difficult: [],
fields.InputDataFields.groundtruth_confidences: [0.99],
}
with self.test_session() as sess:
output_tensors = sess.run(output_tensors, feed_dict=feed_dict)
for key in [fields.InputDataFields.groundtruth_boxes,
fields.InputDataFields.groundtruth_area]:
fields.InputDataFields.groundtruth_area,
fields.InputDataFields.groundtruth_confidences]:
self.assertAllClose(expected_tensors[key], output_tensors[key])
for key in [fields.InputDataFields.groundtruth_classes,
fields.InputDataFields.groundtruth_is_crowd]:
......@@ -547,29 +535,26 @@ class GroundtruthFilterTest(tf.test.TestCase):
input_is_crowd = tf.placeholder(tf.bool, shape=(None,))
input_area = tf.placeholder(tf.float32, shape=(None,))
input_difficult = tf.placeholder(tf.float32, shape=(None,))
input_confidences = tf.placeholder(tf.float32, shape=(None,))
valid_indices = tf.placeholder(tf.int32, shape=(None,))
input_tensors = {
fields.InputDataFields.groundtruth_boxes: input_boxes,
fields.InputDataFields.groundtruth_classes: input_classes,
fields.InputDataFields.groundtruth_is_crowd: input_is_crowd,
fields.InputDataFields.groundtruth_area: input_area,
fields.InputDataFields.groundtruth_difficult: input_difficult
fields.InputDataFields.groundtruth_difficult: input_difficult,
fields.InputDataFields.groundtruth_confidences: input_confidences,
}
output_tensors = ops.retain_groundtruth(input_tensors, valid_indices)
feed_dict = {
input_boxes:
np.array([], dtype=np.float).reshape(0, 4),
input_classes:
np.array([], dtype=np.int32),
input_is_crowd:
np.array([], dtype=np.bool),
input_area:
np.array([], dtype=np.float32),
input_difficult:
np.array([], dtype=np.float32),
valid_indices:
np.array([], dtype=np.int32)
input_boxes: np.array([], dtype=np.float).reshape(0, 4),
input_classes: np.array([], dtype=np.int32),
input_is_crowd: np.array([], dtype=np.bool),
input_area: np.array([], dtype=np.float32),
input_difficult: np.array([], dtype=np.float32),
input_confidences: np.array([], dtype=np.float32),
valid_indices: np.array([], dtype=np.int32),
}
with self.test_session() as sess:
output_tensors = sess.run(output_tensors, feed_dict=feed_dict)
......@@ -590,6 +575,7 @@ class RetainGroundTruthWithPositiveClasses(tf.test.TestCase):
input_area = tf.placeholder(tf.float32, shape=(None,))
input_difficult = tf.placeholder(tf.float32, shape=(None,))
input_label_types = tf.placeholder(tf.string, shape=(None,))
input_confidences = tf.placeholder(tf.float32, shape=(None,))
valid_indices = tf.placeholder(tf.int32, shape=(None,))
input_tensors = {
fields.InputDataFields.image: input_image,
......@@ -598,7 +584,8 @@ class RetainGroundTruthWithPositiveClasses(tf.test.TestCase):
fields.InputDataFields.groundtruth_is_crowd: input_is_crowd,
fields.InputDataFields.groundtruth_area: input_area,
fields.InputDataFields.groundtruth_difficult: input_difficult,
fields.InputDataFields.groundtruth_label_types: input_label_types
fields.InputDataFields.groundtruth_label_types: input_label_types,
fields.InputDataFields.groundtruth_confidences: input_confidences,
}
output_tensors = ops.retain_groundtruth_with_positive_classes(input_tensors)
......@@ -607,40 +594,31 @@ class RetainGroundTruthWithPositiveClasses(tf.test.TestCase):
input_image: image_tensor,
input_boxes:
np.array([[0.2, 0.4, 0.1, 0.8], [0.2, 0.4, 1.0, 0.8]], dtype=np.float),
input_classes:
np.array([1, 0], dtype=np.int32),
input_is_crowd:
np.array([False, True], dtype=np.bool),
input_area:
np.array([32, 48], dtype=np.float32),
input_difficult:
np.array([True, False], dtype=np.bool),
input_classes: np.array([1, 0], dtype=np.int32),
input_is_crowd: np.array([False, True], dtype=np.bool),
input_area: np.array([32, 48], dtype=np.float32),
input_difficult: np.array([True, False], dtype=np.bool),
input_label_types:
np.array(['APPROPRIATE', 'INCORRECT'], dtype=np.string_),
valid_indices:
np.array([0], dtype=np.int32)
input_confidences: np.array([0.99, 0.5], dtype=np.float32),
valid_indices: np.array([0], dtype=np.int32),
}
expected_tensors = {
fields.InputDataFields.image:
image_tensor,
fields.InputDataFields.groundtruth_boxes:
[[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes:
[1],
fields.InputDataFields.groundtruth_is_crowd:
[False],
fields.InputDataFields.groundtruth_area:
[32],
fields.InputDataFields.groundtruth_difficult:
[True],
fields.InputDataFields.groundtruth_label_types:
['APPROPRIATE']
fields.InputDataFields.image: image_tensor,
fields.InputDataFields.groundtruth_boxes: [[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes: [1],
fields.InputDataFields.groundtruth_is_crowd: [False],
fields.InputDataFields.groundtruth_area: [32],
fields.InputDataFields.groundtruth_difficult: [True],
fields.InputDataFields.groundtruth_label_types: ['APPROPRIATE'],
fields.InputDataFields.groundtruth_confidences: [0.99],
}
with self.test_session() as sess:
output_tensors = sess.run(output_tensors, feed_dict=feed_dict)
for key in [fields.InputDataFields.image,
fields.InputDataFields.groundtruth_boxes,
fields.InputDataFields.groundtruth_area]:
fields.InputDataFields.groundtruth_area,
fields.InputDataFields.groundtruth_confidences]:
self.assertAllClose(expected_tensors[key], output_tensors[key])
for key in [fields.InputDataFields.groundtruth_classes,
fields.InputDataFields.groundtruth_is_crowd,
......@@ -675,23 +653,18 @@ class GroundtruthFilterWithCrowdBoxesTest(tf.test.TestCase):
input_tensors = {
fields.InputDataFields.groundtruth_boxes:
[[0.1, 0.2, 0.6, 0.8], [0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes:
[1, 2],
fields.InputDataFields.groundtruth_is_crowd:
[True, False],
fields.InputDataFields.groundtruth_area:
[100.0, 238.7]
fields.InputDataFields.groundtruth_classes: [1, 2],
fields.InputDataFields.groundtruth_is_crowd: [True, False],
fields.InputDataFields.groundtruth_area: [100.0, 238.7],
fields.InputDataFields.groundtruth_confidences: [0.5, 0.99],
}
expected_tensors = {
fields.InputDataFields.groundtruth_boxes:
[[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes:
[2],
fields.InputDataFields.groundtruth_is_crowd:
[False],
fields.InputDataFields.groundtruth_area:
[238.7]
fields.InputDataFields.groundtruth_boxes: [[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes: [2],
fields.InputDataFields.groundtruth_is_crowd: [False],
fields.InputDataFields.groundtruth_area: [238.7],
fields.InputDataFields.groundtruth_confidences: [0.99],
}
output_tensors = ops.filter_groundtruth_with_crowd_boxes(
......@@ -699,7 +672,8 @@ class GroundtruthFilterWithCrowdBoxesTest(tf.test.TestCase):
with self.test_session() as sess:
output_tensors = sess.run(output_tensors)
for key in [fields.InputDataFields.groundtruth_boxes,
fields.InputDataFields.groundtruth_area]:
fields.InputDataFields.groundtruth_area,
fields.InputDataFields.groundtruth_confidences]:
self.assertAllClose(expected_tensors[key], output_tensors[key])
for key in [fields.InputDataFields.groundtruth_classes,
fields.InputDataFields.groundtruth_is_crowd]:
......@@ -712,23 +686,18 @@ class GroundtruthFilterWithNanBoxTest(tf.test.TestCase):
input_tensors = {
fields.InputDataFields.groundtruth_boxes:
[[np.nan, np.nan, np.nan, np.nan], [0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes:
[1, 2],
fields.InputDataFields.groundtruth_is_crowd:
[False, True],
fields.InputDataFields.groundtruth_area:
[100.0, 238.7]
fields.InputDataFields.groundtruth_classes: [1, 2],
fields.InputDataFields.groundtruth_is_crowd: [False, True],
fields.InputDataFields.groundtruth_area: [100.0, 238.7],
fields.InputDataFields.groundtruth_confidences: [0.5, 0.99],
}
expected_tensors = {
fields.InputDataFields.groundtruth_boxes:
[[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes:
[2],
fields.InputDataFields.groundtruth_is_crowd:
[True],
fields.InputDataFields.groundtruth_area:
[238.7]
fields.InputDataFields.groundtruth_boxes: [[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes: [2],
fields.InputDataFields.groundtruth_is_crowd: [True],
fields.InputDataFields.groundtruth_area: [238.7],
fields.InputDataFields.groundtruth_confidences: [0.99],
}
output_tensors = ops.filter_groundtruth_with_nan_box_coordinates(
......@@ -736,7 +705,40 @@ class GroundtruthFilterWithNanBoxTest(tf.test.TestCase):
with self.test_session() as sess:
output_tensors = sess.run(output_tensors)
for key in [fields.InputDataFields.groundtruth_boxes,
fields.InputDataFields.groundtruth_area]:
fields.InputDataFields.groundtruth_area,
fields.InputDataFields.groundtruth_confidences]:
self.assertAllClose(expected_tensors[key], output_tensors[key])
for key in [fields.InputDataFields.groundtruth_classes,
fields.InputDataFields.groundtruth_is_crowd]:
self.assertAllEqual(expected_tensors[key], output_tensors[key])
class GroundtruthFilterWithUnrecognizedClassesTest(tf.test.TestCase):
def test_filter_unrecognized_classes(self):
input_tensors = {
fields.InputDataFields.groundtruth_boxes:
[[.3, .3, .5, .7], [0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes: [-1, 2],
fields.InputDataFields.groundtruth_is_crowd: [False, True],
fields.InputDataFields.groundtruth_area: [100.0, 238.7],
fields.InputDataFields.groundtruth_confidences: [0.5, 0.99],
}
expected_tensors = {
fields.InputDataFields.groundtruth_boxes: [[0.2, 0.4, 0.1, 0.8]],
fields.InputDataFields.groundtruth_classes: [2],
fields.InputDataFields.groundtruth_is_crowd: [True],
fields.InputDataFields.groundtruth_area: [238.7],
fields.InputDataFields.groundtruth_confidences: [0.99],
}
output_tensors = ops.filter_unrecognized_classes(input_tensors)
with self.test_session() as sess:
output_tensors = sess.run(output_tensors)
for key in [fields.InputDataFields.groundtruth_boxes,
fields.InputDataFields.groundtruth_area,
fields.InputDataFields.groundtruth_confidences]:
self.assertAllClose(expected_tensors[key], output_tensors[key])
for key in [fields.InputDataFields.groundtruth_classes,
fields.InputDataFields.groundtruth_is_crowd]:
......
......@@ -20,6 +20,8 @@ import re
import tensorflow as tf
from tensorflow.python.ops import variables as tf_variables
slim = tf.contrib.slim
......@@ -118,7 +120,13 @@ def get_variables_available_in_checkpoint(variables,
ValueError: if `variables` is not a list or dict.
"""
if isinstance(variables, list):
variable_names_map = {variable.op.name: variable for variable in variables}
variable_names_map = {}
for variable in variables:
if isinstance(variable, tf_variables.PartitionedVariable):
name = variable.name
else:
name = variable.op.name
variable_names_map[name] = variable
elif isinstance(variables, dict):
variable_names_map = variables
else:
......
......@@ -144,6 +144,24 @@ class GetVariablesAvailableInCheckpointTest(tf.test.TestCase):
variables, checkpoint_path)
self.assertItemsEqual(out_variables, variables)
def test_return_all_variables_from_checkpoint_with_partition(self):
with tf.Graph().as_default():
partitioner = tf.fixed_size_partitioner(2)
variables = [
tf.get_variable(
name='weights', shape=(2, 2), partitioner=partitioner),
tf.Variable([1.0, 2.0], name='biases')
]
checkpoint_path = os.path.join(self.get_temp_dir(), 'model.ckpt')
init_op = tf.global_variables_initializer()
saver = tf.train.Saver(variables)
with self.test_session() as sess:
sess.run(init_op)
saver.save(sess, checkpoint_path)
out_variables = variables_helper.get_variables_available_in_checkpoint(
variables, checkpoint_path)
self.assertItemsEqual(out_variables, variables)
def test_return_variables_available_in_checkpoint(self):
checkpoint_path = os.path.join(self.get_temp_dir(), 'model.ckpt')
with tf.Graph().as_default():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment