Commit 31ca3b97 authored by Kaushik Shivakumar's avatar Kaushik Shivakumar
Browse files

resovle merge conflicts

parents 3e9d886d 7fcd7cba
...@@ -51,25 +51,25 @@ def tf_example_from_annotations_data_frame(annotations_data_frame, label_map, ...@@ -51,25 +51,25 @@ def tf_example_from_annotations_data_frame(annotations_data_frame, label_map,
feature_map = { feature_map = {
standard_fields.TfExampleFields.object_bbox_ymin: standard_fields.TfExampleFields.object_bbox_ymin:
dataset_util.float_list_feature( dataset_util.float_list_feature(
filtered_data_frame_boxes.YMin.as_matrix()), filtered_data_frame_boxes.YMin.to_numpy()),
standard_fields.TfExampleFields.object_bbox_xmin: standard_fields.TfExampleFields.object_bbox_xmin:
dataset_util.float_list_feature( dataset_util.float_list_feature(
filtered_data_frame_boxes.XMin.as_matrix()), filtered_data_frame_boxes.XMin.to_numpy()),
standard_fields.TfExampleFields.object_bbox_ymax: standard_fields.TfExampleFields.object_bbox_ymax:
dataset_util.float_list_feature( dataset_util.float_list_feature(
filtered_data_frame_boxes.YMax.as_matrix()), filtered_data_frame_boxes.YMax.to_numpy()),
standard_fields.TfExampleFields.object_bbox_xmax: standard_fields.TfExampleFields.object_bbox_xmax:
dataset_util.float_list_feature( dataset_util.float_list_feature(
filtered_data_frame_boxes.XMax.as_matrix()), filtered_data_frame_boxes.XMax.to_numpy()),
standard_fields.TfExampleFields.object_class_text: standard_fields.TfExampleFields.object_class_text:
dataset_util.bytes_list_feature([ dataset_util.bytes_list_feature([
six.ensure_binary(label_text) six.ensure_binary(label_text)
for label_text in filtered_data_frame_boxes.LabelName.as_matrix() for label_text in filtered_data_frame_boxes.LabelName.to_numpy()
]), ]),
standard_fields.TfExampleFields.object_class_label: standard_fields.TfExampleFields.object_class_label:
dataset_util.int64_list_feature( dataset_util.int64_list_feature(
filtered_data_frame_boxes.LabelName.map( filtered_data_frame_boxes.LabelName.map(
lambda x: label_map[x]).as_matrix()), lambda x: label_map[x]).to_numpy()),
standard_fields.TfExampleFields.filename: standard_fields.TfExampleFields.filename:
dataset_util.bytes_feature( dataset_util.bytes_feature(
six.ensure_binary('{}.jpg'.format(image_id))), six.ensure_binary('{}.jpg'.format(image_id))),
...@@ -82,31 +82,31 @@ def tf_example_from_annotations_data_frame(annotations_data_frame, label_map, ...@@ -82,31 +82,31 @@ def tf_example_from_annotations_data_frame(annotations_data_frame, label_map,
if 'IsGroupOf' in filtered_data_frame.columns: if 'IsGroupOf' in filtered_data_frame.columns:
feature_map[standard_fields.TfExampleFields. feature_map[standard_fields.TfExampleFields.
object_group_of] = dataset_util.int64_list_feature( object_group_of] = dataset_util.int64_list_feature(
filtered_data_frame_boxes.IsGroupOf.as_matrix().astype(int)) filtered_data_frame_boxes.IsGroupOf.to_numpy().astype(int))
if 'IsOccluded' in filtered_data_frame.columns: if 'IsOccluded' in filtered_data_frame.columns:
feature_map[standard_fields.TfExampleFields. feature_map[standard_fields.TfExampleFields.
object_occluded] = dataset_util.int64_list_feature( object_occluded] = dataset_util.int64_list_feature(
filtered_data_frame_boxes.IsOccluded.as_matrix().astype( filtered_data_frame_boxes.IsOccluded.to_numpy().astype(
int)) int))
if 'IsTruncated' in filtered_data_frame.columns: if 'IsTruncated' in filtered_data_frame.columns:
feature_map[standard_fields.TfExampleFields. feature_map[standard_fields.TfExampleFields.
object_truncated] = dataset_util.int64_list_feature( object_truncated] = dataset_util.int64_list_feature(
filtered_data_frame_boxes.IsTruncated.as_matrix().astype( filtered_data_frame_boxes.IsTruncated.to_numpy().astype(
int)) int))
if 'IsDepiction' in filtered_data_frame.columns: if 'IsDepiction' in filtered_data_frame.columns:
feature_map[standard_fields.TfExampleFields. feature_map[standard_fields.TfExampleFields.
object_depiction] = dataset_util.int64_list_feature( object_depiction] = dataset_util.int64_list_feature(
filtered_data_frame_boxes.IsDepiction.as_matrix().astype( filtered_data_frame_boxes.IsDepiction.to_numpy().astype(
int)) int))
if 'ConfidenceImageLabel' in filtered_data_frame_labels.columns: if 'ConfidenceImageLabel' in filtered_data_frame_labels.columns:
feature_map[standard_fields.TfExampleFields. feature_map[standard_fields.TfExampleFields.
image_class_label] = dataset_util.int64_list_feature( image_class_label] = dataset_util.int64_list_feature(
filtered_data_frame_labels.LabelName.map( filtered_data_frame_labels.LabelName.map(
lambda x: label_map[x]).as_matrix()) lambda x: label_map[x]).to_numpy())
feature_map[standard_fields.TfExampleFields feature_map[standard_fields.TfExampleFields
.image_class_text] = dataset_util.bytes_list_feature([ .image_class_text] = dataset_util.bytes_list_feature([
six.ensure_binary(label_text) for label_text in six.ensure_binary(label_text) for label_text in
filtered_data_frame_labels.LabelName.as_matrix() filtered_data_frame_labels.LabelName.to_numpy()
]), ]),
return tf.train.Example(features=tf.train.Features(feature=feature_map)) return tf.train.Example(features=tf.train.Features(feature=feature_map))
...@@ -288,7 +288,7 @@ class SeqExampleUtilTest(tf.test.TestCase): ...@@ -288,7 +288,7 @@ class SeqExampleUtilTest(tf.test.TestCase):
[0.75, 1.], [0.75, 1.],
seq_feature_dict['region/bbox/xmax'].feature[0].float_list.value[:]) seq_feature_dict['region/bbox/xmax'].feature[0].float_list.value[:])
self.assertAllEqual( self.assertAllEqual(
['cat', 'frog'], [b'cat', b'frog'],
seq_feature_dict['region/label/string'].feature[0].bytes_list.value[:]) seq_feature_dict['region/label/string'].feature[0].bytes_list.value[:])
self.assertAllClose( self.assertAllClose(
[0.], [0.],
...@@ -332,7 +332,7 @@ class SeqExampleUtilTest(tf.test.TestCase): ...@@ -332,7 +332,7 @@ class SeqExampleUtilTest(tf.test.TestCase):
[0.75], [0.75],
seq_feature_dict['region/bbox/xmax'].feature[1].float_list.value[:]) seq_feature_dict['region/bbox/xmax'].feature[1].float_list.value[:])
self.assertAllEqual( self.assertAllEqual(
['cat'], [b'cat'],
seq_feature_dict['region/label/string'].feature[1].bytes_list.value[:]) seq_feature_dict['region/label/string'].feature[1].bytes_list.value[:])
self.assertAllClose( self.assertAllClose(
[], [],
......
...@@ -42,7 +42,7 @@ class OpenOutputTfrecordsTests(tf.test.TestCase): ...@@ -42,7 +42,7 @@ class OpenOutputTfrecordsTests(tf.test.TestCase):
tf_record_path = '{}-{:05d}-of-00010'.format( tf_record_path = '{}-{:05d}-of-00010'.format(
os.path.join(tf.test.get_temp_dir(), 'test.tfrec'), idx) os.path.join(tf.test.get_temp_dir(), 'test.tfrec'), idx)
records = list(tf.python_io.tf_record_iterator(tf_record_path)) records = list(tf.python_io.tf_record_iterator(tf_record_path))
self.assertAllEqual(records, ['test_{}'.format(idx)]) self.assertAllEqual(records, ['test_{}'.format(idx).encode('utf-8')])
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -25,20 +25,17 @@ RUN useradd -ms /bin/bash tensorflow ...@@ -25,20 +25,17 @@ RUN useradd -ms /bin/bash tensorflow
USER tensorflow USER tensorflow
WORKDIR /home/tensorflow WORKDIR /home/tensorflow
# Install pip dependencies
RUN pip3 install --user absl-py
RUN pip3 install --user contextlib2
RUN pip3 install --user Cython
RUN pip3 install --user jupyter
RUN pip3 install --user matplotlib
RUN pip3 install --user pycocotools
RUN pip3 install --user tf-slim
# Copy this version of of the model garden into the image # Copy this version of of the model garden into the image
COPY --chown=tensorflow . /home/tensorflow/models COPY --chown=tensorflow . /home/tensorflow/models
# Compile protobuf configs # Compile protobuf configs
RUN (cd /home/tensorflow/models/research/ && protoc object_detection/protos/*.proto --python_out=.) RUN (cd /home/tensorflow/models/research/ && protoc object_detection/protos/*.proto --python_out=.)
WORKDIR /home/tensorflow/models/research/
RUN cp object_detection/packages/tf1/setup.py ./
ENV PATH="/home/tensorflow/.local/bin:${PATH}"
RUN python -m pip install --user -U pip
RUN python -m pip install --user .
ENV PYTHONPATH $PYTHONPATH:/home/tensorflow/models/research/:/home/tensorflow/models/research/slim
ENV TF_CPP_MIN_LOG_LEVEL 3 ENV TF_CPP_MIN_LOG_LEVEL 3
# Tensorflow Object Detection on Docker # TensorFlow Object Detection on Docker
These instructions are experimental. These instructions are experimental.
...@@ -6,6 +6,6 @@ These instructions are experimental. ...@@ -6,6 +6,6 @@ These instructions are experimental.
```bash ```bash
# From the root of the git repository # From the root of the git repository
docker build -f research/object_detection/dockerfiles/2.2/Dockerfile -t od . docker build -f research/object_detection/dockerfiles/tf1/Dockerfile -t od .
docker run -it od docker run -it od
``` ```
...@@ -25,20 +25,17 @@ RUN useradd -ms /bin/bash tensorflow ...@@ -25,20 +25,17 @@ RUN useradd -ms /bin/bash tensorflow
USER tensorflow USER tensorflow
WORKDIR /home/tensorflow WORKDIR /home/tensorflow
# Install pip dependencies
RUN pip3 install --user absl-py
RUN pip3 install --user contextlib2
RUN pip3 install --user Cython
RUN pip3 install --user jupyter
RUN pip3 install --user matplotlib
RUN pip3 install --user pycocotools
RUN pip3 install --user tf-slim
# Copy this version of of the model garden into the image # Copy this version of of the model garden into the image
COPY --chown=tensorflow . /home/tensorflow/models COPY --chown=tensorflow . /home/tensorflow/models
# Compile protobuf configs # Compile protobuf configs
RUN (cd /home/tensorflow/models/research/ && protoc object_detection/protos/*.proto --python_out=.) RUN (cd /home/tensorflow/models/research/ && protoc object_detection/protos/*.proto --python_out=.)
WORKDIR /home/tensorflow/models/research/
RUN cp object_detection/packages/tf2/setup.py ./
ENV PATH="/home/tensorflow/.local/bin:${PATH}"
RUN python -m pip install -U pip
RUN python -m pip install .
ENV PYTHONPATH $PYTHONPATH:/home/tensorflow/models/research/:/home/tensorflow/models/research/slim
ENV TF_CPP_MIN_LOG_LEVEL 3 ENV TF_CPP_MIN_LOG_LEVEL 3
# Tensorflow Object Detection on Docker # TensorFlow Object Detection on Docker
These instructions are experimental. These instructions are experimental.
...@@ -6,6 +6,6 @@ These instructions are experimental. ...@@ -6,6 +6,6 @@ These instructions are experimental.
```bash ```bash
# From the root of the git repository # From the root of the git repository
docker build -f research/object_detection/dockerfiles/1.15/Dockerfile -t od . docker build -f research/object_detection/dockerfiles/tf2/Dockerfile -t od .
docker run -it od docker run -it od
``` ```
...@@ -552,7 +552,11 @@ def _resize_detection_masks(args): ...@@ -552,7 +552,11 @@ def _resize_detection_masks(args):
detection_boxes, detection_masks, image_shape = args detection_boxes, detection_masks, image_shape = args
detection_masks_reframed = ops.reframe_box_masks_to_image_masks( detection_masks_reframed = ops.reframe_box_masks_to_image_masks(
detection_masks, detection_boxes, image_shape[0], image_shape[1]) detection_masks, detection_boxes, image_shape[0], image_shape[1])
return tf.cast(tf.greater(detection_masks_reframed, 0.5), tf.uint8) # If the masks are currently float, binarize them. Otherwise keep them as
# integers, since they have already been thresholded.
if detection_masks_reframed.dtype == tf.float32:
detection_masks_reframed = tf.greater(detection_masks_reframed, 0.5)
return tf.cast(detection_masks_reframed, tf.uint8)
def _resize_groundtruth_masks(args): def _resize_groundtruth_masks(args):
...@@ -570,6 +574,17 @@ def _resize_groundtruth_masks(args): ...@@ -570,6 +574,17 @@ def _resize_groundtruth_masks(args):
return tf.cast(tf.squeeze(mask, 3), tf.uint8) return tf.cast(tf.squeeze(mask, 3), tf.uint8)
def _resize_surface_coordinate_masks(args):
detection_boxes, surface_coords, image_shape = args
surface_coords_v, surface_coords_u = tf.unstack(surface_coords, axis=-1)
surface_coords_v_reframed = ops.reframe_box_masks_to_image_masks(
surface_coords_v, detection_boxes, image_shape[0], image_shape[1])
surface_coords_u_reframed = ops.reframe_box_masks_to_image_masks(
surface_coords_u, detection_boxes, image_shape[0], image_shape[1])
return tf.stack([surface_coords_v_reframed, surface_coords_u_reframed],
axis=-1)
def _scale_keypoint_to_absolute(args): def _scale_keypoint_to_absolute(args):
keypoints, image_shape = args keypoints, image_shape = args
return keypoint_ops.scale(keypoints, image_shape[0], image_shape[1]) return keypoint_ops.scale(keypoints, image_shape[0], image_shape[1])
...@@ -720,6 +735,12 @@ def result_dict_for_batched_example(images, ...@@ -720,6 +735,12 @@ def result_dict_for_batched_example(images,
num_keypoints] bool tensor with keypoint visibilities (Optional). num_keypoints] bool tensor with keypoint visibilities (Optional).
'groundtruth_labeled_classes': [batch_size, num_classes] int64 'groundtruth_labeled_classes': [batch_size, num_classes] int64
tensor of 1-indexed classes. (Optional) tensor of 1-indexed classes. (Optional)
'groundtruth_dp_num_points': [batch_size, max_number_of_boxes] int32
tensor. (Optional)
'groundtruth_dp_part_ids': [batch_size, max_number_of_boxes,
max_sampled_points] int32 tensor. (Optional)
'groundtruth_dp_surface_coords_list': [batch_size, max_number_of_boxes,
max_sampled_points, 4] float32 tensor. (Optional)
class_agnostic: Boolean indicating whether the detections are class-agnostic class_agnostic: Boolean indicating whether the detections are class-agnostic
(i.e. binary). Default False. (i.e. binary). Default False.
scale_to_absolute: Boolean indicating whether boxes and keypoints should be scale_to_absolute: Boolean indicating whether boxes and keypoints should be
...@@ -747,12 +768,16 @@ def result_dict_for_batched_example(images, ...@@ -747,12 +768,16 @@ def result_dict_for_batched_example(images,
'detection_scores': [batch_size, max_detections] float32 tensor of scores. 'detection_scores': [batch_size, max_detections] float32 tensor of scores.
'detection_classes': [batch_size, max_detections] int64 tensor of 1-indexed 'detection_classes': [batch_size, max_detections] int64 tensor of 1-indexed
classes. classes.
'detection_masks': [batch_size, max_detections, H, W] float32 tensor of 'detection_masks': [batch_size, max_detections, H, W] uint8 tensor of
binarized masks, reframed to full image masks. (Optional) instance masks, reframed to full image masks. Note that these may be
binarized (e.g. {0, 1}), or may contain 1-indexed part labels. (Optional)
'detection_keypoints': [batch_size, max_detections, num_keypoints, 2] 'detection_keypoints': [batch_size, max_detections, num_keypoints, 2]
float32 tensor containing keypoint coordinates. (Optional) float32 tensor containing keypoint coordinates. (Optional)
'detection_keypoint_scores': [batch_size, max_detections, num_keypoints] 'detection_keypoint_scores': [batch_size, max_detections, num_keypoints]
float32 tensor containing keypoint scores. (Optional) float32 tensor containing keypoint scores. (Optional)
'detection_surface_coords': [batch_size, max_detection, H, W, 2] float32
tensor with normalized surface coordinates (e.g. DensePose UV
coordinates). (Optional)
'num_detections': [batch_size] int64 tensor containing number of valid 'num_detections': [batch_size] int64 tensor containing number of valid
detections. detections.
'groundtruth_boxes': [batch_size, num_boxes, 4] float32 tensor of boxes, in 'groundtruth_boxes': [batch_size, num_boxes, 4] float32 tensor of boxes, in
...@@ -844,14 +869,21 @@ def result_dict_for_batched_example(images, ...@@ -844,14 +869,21 @@ def result_dict_for_batched_example(images,
if detection_fields.detection_masks in detections: if detection_fields.detection_masks in detections:
detection_masks = detections[detection_fields.detection_masks] detection_masks = detections[detection_fields.detection_masks]
# TODO(rathodv): This should be done in model's postprocess
# function ideally.
output_dict[detection_fields.detection_masks] = ( output_dict[detection_fields.detection_masks] = (
shape_utils.static_or_dynamic_map_fn( shape_utils.static_or_dynamic_map_fn(
_resize_detection_masks, _resize_detection_masks,
elems=[detection_boxes, detection_masks, elems=[detection_boxes, detection_masks,
original_image_spatial_shapes], original_image_spatial_shapes],
dtype=tf.uint8)) dtype=tf.uint8))
if detection_fields.detection_surface_coords in detections:
detection_surface_coords = detections[
detection_fields.detection_surface_coords]
output_dict[detection_fields.detection_surface_coords] = (
shape_utils.static_or_dynamic_map_fn(
_resize_surface_coordinate_masks,
elems=[detection_boxes, detection_surface_coords,
original_image_spatial_shapes],
dtype=tf.float32))
if detection_fields.detection_keypoints in detections: if detection_fields.detection_keypoints in detections:
detection_keypoints = detections[detection_fields.detection_keypoints] detection_keypoints = detections[detection_fields.detection_keypoints]
...@@ -1074,3 +1106,8 @@ def evaluator_options_from_eval_config(eval_config): ...@@ -1074,3 +1106,8 @@ def evaluator_options_from_eval_config(eval_config):
'recall_upper_bound': (eval_config.recall_upper_bound) 'recall_upper_bound': (eval_config.recall_upper_bound)
} }
return evaluator_options return evaluator_options
def has_densepose(eval_dict):
return (fields.DetectionResultFields.detection_masks in eval_dict and
fields.DetectionResultFields.detection_surface_coords in eval_dict)
...@@ -74,6 +74,9 @@ class FakeModel(model.DetectionModel): ...@@ -74,6 +74,9 @@ class FakeModel(model.DetectionModel):
def restore_map(self, checkpoint_path, from_detection_checkpoint): def restore_map(self, checkpoint_path, from_detection_checkpoint):
pass pass
def restore_from_objects(self, fine_tune_checkpoint_type):
pass
def loss(self, prediction_dict, true_image_shapes): def loss(self, prediction_dict, true_image_shapes):
pass pass
...@@ -416,7 +419,7 @@ class ExportTfliteGraphTest(tf.test.TestCase): ...@@ -416,7 +419,7 @@ class ExportTfliteGraphTest(tf.test.TestCase):
tflite_graph_file = self._export_graph_with_postprocessing_op( tflite_graph_file = self._export_graph_with_postprocessing_op(
pipeline_config) pipeline_config)
self.assertTrue(os.path.exists(tflite_graph_file)) self.assertTrue(os.path.exists(tflite_graph_file))
mock_get.assert_called_once() self.assertEqual(1, mock_get.call_count)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -76,6 +76,9 @@ class FakeModel(model.DetectionModel): ...@@ -76,6 +76,9 @@ class FakeModel(model.DetectionModel):
def restore_map(self, checkpoint_path, fine_tune_checkpoint_type): def restore_map(self, checkpoint_path, fine_tune_checkpoint_type):
pass pass
def restore_from_objects(self, fine_tune_checkpoint_type):
pass
def loss(self, prediction_dict, true_image_shapes): def loss(self, prediction_dict, true_image_shapes):
pass pass
......
...@@ -105,6 +105,9 @@ class FakeModel(model.DetectionModel): ...@@ -105,6 +105,9 @@ class FakeModel(model.DetectionModel):
def restore_map(self, checkpoint_path, fine_tune_checkpoint_type): def restore_map(self, checkpoint_path, fine_tune_checkpoint_type):
pass pass
def restore_from_objects(self, fine_tune_checkpoint_type):
pass
def loss(self, prediction_dict, true_image_shapes): def loss(self, prediction_dict, true_image_shapes):
pass pass
......
...@@ -47,7 +47,7 @@ python object_detection/dataset_tools/oid_hierarchical_labels_expansion.py \ ...@@ -47,7 +47,7 @@ python object_detection/dataset_tools/oid_hierarchical_labels_expansion.py \
--annotation_type=2 --annotation_type=2
``` ```
1. If you are not using Tensorflow, you can run evaluation directly using your 1. If you are not using TensorFlow, you can run evaluation directly using your
algorithm's output and generated ground-truth files. {value=4} algorithm's output and generated ground-truth files. {value=4}
After step 3 you produced the ground-truth files suitable for running 'OID After step 3 you produced the ground-truth files suitable for running 'OID
...@@ -73,7 +73,7 @@ For the Object Detection Track, the participants will be ranked on: ...@@ -73,7 +73,7 @@ For the Object Detection Track, the participants will be ranked on:
- "OpenImagesDetectionChallenge_Precision/mAP@0.5IOU" - "OpenImagesDetectionChallenge_Precision/mAP@0.5IOU"
To use evaluation within Tensorflow training, use metric name To use evaluation within TensorFlow training, use metric name
`oid_challenge_detection_metrics` in the evaluation config. `oid_challenge_detection_metrics` in the evaluation config.
## Instance Segmentation Track ## Instance Segmentation Track
...@@ -130,7 +130,7 @@ python object_detection/dataset_tools/oid_hierarchical_labels_expansion.py \ ...@@ -130,7 +130,7 @@ python object_detection/dataset_tools/oid_hierarchical_labels_expansion.py \
--annotation_type=1 --annotation_type=1
``` ```
1. If you are not using Tensorflow, you can run evaluation directly using your 1. If you are not using TensorFlow, you can run evaluation directly using your
algorithm's output and generated ground-truth files. {value=4} algorithm's output and generated ground-truth files. {value=4}
``` ```
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## Overview ## Overview
The Tensorflow Object Detection API uses protobuf files to configure the The TensorFlow Object Detection API uses protobuf files to configure the
training and evaluation process. The schema for the training pipeline can be training and evaluation process. The schema for the training pipeline can be
found in object_detection/protos/pipeline.proto. At a high level, the config found in object_detection/protos/pipeline.proto. At a high level, the config
file is split into 5 parts: file is split into 5 parts:
...@@ -60,7 +60,7 @@ to a value suited for the dataset the user is training on. ...@@ -60,7 +60,7 @@ to a value suited for the dataset the user is training on.
## Defining Inputs ## Defining Inputs
The Tensorflow Object Detection API accepts inputs in the TFRecord file format. The TensorFlow Object Detection API accepts inputs in the TFRecord file format.
Users must specify the locations of both the training and evaluation files. Users must specify the locations of both the training and evaluation files.
Additionally, users should also specify a label map, which define the mapping Additionally, users should also specify a label map, which define the mapping
between a class id and class name. The label map should be identical between between a class id and class name. The label map should be identical between
...@@ -126,24 +126,6 @@ data_augmentation_options { ...@@ -126,24 +126,6 @@ data_augmentation_options {
} }
``` ```
### Model Parameter Initialization
While optional, it is highly recommended that users utilize other object
detection checkpoints. Training an object detector from scratch can take days.
To speed up the training process, it is recommended that users re-use the
feature extractor parameters from a pre-existing image classification or
object detection checkpoint. `train_config` provides two fields to specify
pre-existing checkpoints: `fine_tune_checkpoint` and
`from_detection_checkpoint`. `fine_tune_checkpoint` should provide a path to
the pre-existing checkpoint
(ie:"/usr/home/username/checkpoint/model.ckpt-#####").
`from_detection_checkpoint` is a boolean value. If false, it assumes the
checkpoint was from an object classification checkpoint. Note that starting
from a detection checkpoint will usually result in a faster training job than
a classification checkpoint.
The list of provided checkpoints can be found [here](detection_model_zoo.md).
### Input Preprocessing ### Input Preprocessing
The `data_augmentation_options` in `train_config` can be used to specify The `data_augmentation_options` in `train_config` can be used to specify
......
# Context R-CNN # Context R-CNN
[![TensorFlow 1.15](https://img.shields.io/badge/TensorFlow-1.15-FF6F00?logo=tensorflow)](https://github.com/tensorflow/tensorflow/releases/tag/v1.15.0)
Context R-CNN is an object detection model that uses contextual features to Context R-CNN is an object detection model that uses contextual features to
improve object detection. See https://arxiv.org/abs/1912.03538 for more details. improve object detection. See https://arxiv.org/abs/1912.03538 for more details.
...@@ -30,9 +32,12 @@ pip install apache-beam ...@@ -30,9 +32,12 @@ pip install apache-beam
``` ```
and can be run locally, or on a cluster for efficient processing of large and can be run locally, or on a cluster for efficient processing of large
amounts of data. See the amounts of data. Note that generate_detection_data.py and
generate_embedding_data.py both involve running inference, and may be very slow
to run locally. See the
[Apache Beam documentation](https://beam.apache.org/documentation/runners/dataflow/) [Apache Beam documentation](https://beam.apache.org/documentation/runners/dataflow/)
for more information. for more information, and Google Cloud Documentation for a tutorial on
[running Beam jobs on DataFlow](https://cloud.google.com/dataflow/docs/quickstarts/quickstart-python).
### Generating TfRecords from a set of images and a COCO-CameraTraps style JSON ### Generating TfRecords from a set of images and a COCO-CameraTraps style JSON
...@@ -191,3 +196,6 @@ python export_inference_graph.py \ ...@@ -191,3 +196,6 @@ python export_inference_graph.py \
--side_input_types float,int --side_input_types float,int
``` ```
If you have questions about Context R-CNN, please contact
[Sara Beery](https://beerys.github.io/).
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
In this section, we discuss some of the abstractions that we use In this section, we discuss some of the abstractions that we use
for defining detection models. If you would like to define a new model for defining detection models. If you would like to define a new model
architecture for detection and use it in the Tensorflow Detection API, architecture for detection and use it in the TensorFlow Detection API,
then this section should also serve as a high level guide to the files that you then this section should also serve as a high level guide to the files that you
will need to edit to get your new model working. will need to edit to get your new model working.
## DetectionModels (`object_detection/core/model.py`) ## DetectionModels (`object_detection/core/model.py`)
In order to be trained, evaluated, and exported for serving using our In order to be trained, evaluated, and exported for serving using our
provided binaries, all models under the Tensorflow Object Detection API must provided binaries, all models under the TensorFlow Object Detection API must
implement the `DetectionModel` interface (see the full definition in `object_detection/core/model.py`). In particular, implement the `DetectionModel` interface (see the full definition in `object_detection/core/model.py`). In particular,
each of these models are responsible for implementing 5 functions: each of these models are responsible for implementing 5 functions:
...@@ -20,7 +20,7 @@ each of these models are responsible for implementing 5 functions: ...@@ -20,7 +20,7 @@ each of these models are responsible for implementing 5 functions:
postprocess functions. postprocess functions.
* `postprocess`: Convert predicted output tensors to final detections. * `postprocess`: Convert predicted output tensors to final detections.
* `loss`: Compute scalar loss tensors with respect to provided groundtruth. * `loss`: Compute scalar loss tensors with respect to provided groundtruth.
* `restore`: Load a checkpoint into the Tensorflow graph. * `restore`: Load a checkpoint into the TensorFlow graph.
Given a `DetectionModel` at training time, we pass each image batch through Given a `DetectionModel` at training time, we pass each image batch through
the following sequence of functions to compute a loss which can be optimized via the following sequence of functions to compute a loss which can be optimized via
...@@ -87,7 +87,7 @@ functions: ...@@ -87,7 +87,7 @@ functions:
* `_extract_box_classifier_features`: Extract second stage Box Classifier * `_extract_box_classifier_features`: Extract second stage Box Classifier
features. features.
* `restore_from_classification_checkpoint_fn`: Load a checkpoint into the * `restore_from_classification_checkpoint_fn`: Load a checkpoint into the
Tensorflow graph. TensorFlow graph.
See the `object_detection/models/faster_rcnn_resnet_v1_feature_extractor.py` See the `object_detection/models/faster_rcnn_resnet_v1_feature_extractor.py`
definition as one example. Some remarks: definition as one example. Some remarks:
......
# Supported object detection evaluation protocols # Supported object detection evaluation protocols
The Tensorflow Object Detection API currently supports three evaluation protocols, The TensorFlow Object Detection API currently supports three evaluation protocols,
that can be configured in `EvalConfig` by setting `metrics_set` to the that can be configured in `EvalConfig` by setting `metrics_set` to the
corresponding value. corresponding value.
......
# Exporting a trained model for inference # Exporting a trained model for inference
After your model has been trained, you should export it to a Tensorflow [![TensorFlow 1.15](https://img.shields.io/badge/TensorFlow-1.15-FF6F00?logo=tensorflow)](https://github.com/tensorflow/tensorflow/releases/tag/v1.15.0)
After your model has been trained, you should export it to a TensorFlow
graph proto. A checkpoint will typically consist of three files: graph proto. A checkpoint will typically consist of three files:
* model.ckpt-${CHECKPOINT_NUMBER}.data-00000-of-00001 * model.ckpt-${CHECKPOINT_NUMBER}.data-00000-of-00001
......
...@@ -22,6 +22,6 @@ A: Similar to BackupHandler, syncing your fork to HEAD should make it work. ...@@ -22,6 +22,6 @@ A: Similar to BackupHandler, syncing your fork to HEAD should make it work.
## Q: Why can't I get the inference time as reported in model zoo? ## Q: Why can't I get the inference time as reported in model zoo?
A: The inference time reported in model zoo is mean time of testing hundreds of A: The inference time reported in model zoo is mean time of testing hundreds of
images with an internal machine. As mentioned in images with an internal machine. As mentioned in
[Tensorflow detection model zoo](detection_model_zoo.md), this speed depends [TensorFlow detection model zoo](tf1_detection_zoo.md), this speed depends
highly on one's specific hardware configuration and should be treated more as highly on one's specific hardware configuration and should be treated more as
relative timing. relative timing.
# Installation
## Dependencies
Tensorflow Object Detection API depends on the following libraries:
* Protobuf 3.0.0
* Python-tk
* Pillow 1.0
* lxml
* tf-slim (https://github.com/google-research/tf-slim)
* slim (which is included in the "tensorflow/models/research/" checkout)
* Jupyter notebook
* Matplotlib
* Tensorflow (1.15.0)
* Cython
* contextlib2
* cocoapi
For detailed steps to install Tensorflow, follow the [Tensorflow installation
instructions](https://www.tensorflow.org/install/). A typical user can install
Tensorflow using one of the following commands:
``` bash
# For CPU
pip install tensorflow
# For GPU
pip install tensorflow-gpu
```
The remaining libraries can be installed on Ubuntu 16.04 using via apt-get:
```bash
sudo apt-get install protobuf-compiler python-pil python-lxml python-tk
pip install --user Cython
pip install --user contextlib2
pip install --user jupyter
pip install --user matplotlib
pip install --user tf_slim
```
Alternatively, users can install dependencies using pip:
```bash
pip install --user Cython
pip install --user contextlib2
pip install --user pillow
pip install --user lxml
pip install --user jupyter
pip install --user matplotlib
pip install --user tf_slim
```
<!-- common_typos_disable -->
**Note**: sometimes "sudo apt-get install protobuf-compiler" will install
Protobuf 3+ versions for you and some users have issues when using 3.5.
If that is your case, try the [manual](#Manual-protobuf-compiler-installation-and-usage) installation.
## Download the tensorflow/models repository
```bash
git clone https://github.com/tensorflow/models.git
```
To use this library, you need to download this repository, whenever it says
`<path-to-tensorflow>` it will be referring to the folder that you downloaded
this repository into.
## COCO API installation
Download the
[cocoapi](https://github.com/cocodataset/cocoapi) and
copy the pycocotools subfolder to the tensorflow/models/research directory if
you are interested in using COCO evaluation metrics. The default metrics are
based on those used in Pascal VOC evaluation. To use the COCO object detection
metrics add `metrics_set: "coco_detection_metrics"` to the `eval_config` message
in the config file. To use the COCO instance segmentation metrics add
`metrics_set: "coco_mask_metrics"` to the `eval_config` message in the config
file.
```bash
git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
make
cp -r pycocotools <path_to_tensorflow>/models/research/
```
Alternatively, users can install `pycocotools` using pip:
```bash
pip install --user pycocotools
```
## Protobuf Compilation
The Tensorflow Object Detection API uses Protobufs to configure model and
training parameters. Before the framework can be used, the Protobuf libraries
must be compiled. This should be done by running the following command from
the [tensorflow/models/research/
](https://github.com/tensorflow/models/tree/master/research/)
directory:
``` bash
# From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.
```
**Note**: If you're getting errors while compiling, you might be using an incompatible protobuf compiler. If that's the case, use the following manual installation
## Manual protobuf-compiler installation and usage
**If you are on linux:**
Download and install the 3.0 release of protoc, then unzip the file.
```bash
# From tensorflow/models/research/
wget -O protobuf.zip https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip
unzip protobuf.zip
```
Run the compilation process again, but use the downloaded version of protoc
```bash
# From tensorflow/models/research/
./bin/protoc object_detection/protos/*.proto --python_out=.
```
**If you are on MacOS:**
If you have homebrew, download and install the protobuf with
```brew install protobuf```
Alternately, run:
```PROTOC_ZIP=protoc-3.3.0-osx-x86_64.zip
curl -OL https://github.com/google/protobuf/releases/download/v3.3.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
rm -f $PROTOC_ZIP
```
Run the compilation process again:
``` bash
# From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.
```
## Add Libraries to PYTHONPATH
When running locally, the tensorflow/models/research/ and slim directories
should be appended to PYTHONPATH. This can be done by running the following from
tensorflow/models/research/:
``` bash
# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
```
Note: This command needs to run from every new terminal you start. If you wish
to avoid running this manually, you can add it as a new line to the end of your
~/.bashrc file, replacing \`pwd\` with the absolute path of
tensorflow/models/research on your system. After updating ~/.bashrc file you
can run the following command:
Note: Some of the functions defined in tensorflow/models/research/slim has been
moved to [tf-slim](https://github.com/google-research/tf-slim), so installing
tf_slim is required now.
``` bash
source ~/.bashrc
```
# Testing the Installation
You can test that you have correctly installed the Tensorflow Object Detection\
API by running the following command:
```bash
# If using Tensorflow 1.X:
python object_detection/builders/model_builder_tf1_test.py
```
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