easy_vision.python.core.detection_predictors.heads¶
easy_vision.python.core.detection_predictors.heads.box_head¶
Box Head.
Contains Box prediction head classes for different meta architectures. All the box prediction heads have a predict function that receives the features as the first argument and returns box_encodings.
-
class
easy_vision.python.core.detection_predictors.heads.box_head.
Convolutional3DBoxHead
(is_training, box_code_size, kernel_size, use_depthwise=False)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Convolutional box prediction head.
-
__init__
(is_training, box_code_size, kernel_size, use_depthwise=False)[source]¶ Constructor.
Parameters: - is_training – Indicates whether the BoxPredictor is in training mode.
- box_code_size – Size of encoding for each box.
- kernel_size – Size of final convolution kernel. If the spatial resolution of the feature map is smaller than the kernel size, then the kernel size is automatically set to be min(feature_width, feature_height).
- use_depthwise – Whether to use depthwise convolutions for prediction steps. Default is False.
Raises: ValueError
– if min_depth > max_depth.
-
predict
(features, num_predictions_per_location)[source]¶ Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing image features.
- num_predictions_per_location – Number of box predictions to be made per spatial location. Int specifying number of boxes per location.
Returns: - A float tensors of shape
[batch_size, num_anchors, code_size] representing the location of the objects.
Return type: box_encodings
-
-
class
easy_vision.python.core.detection_predictors.heads.box_head.
ConvolutionalBoxHead
(is_training, box_code_size, kernel_size, use_depthwise=False)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Convolutional box prediction head.
-
__init__
(is_training, box_code_size, kernel_size, use_depthwise=False)[source]¶ Constructor.
Parameters: - is_training – Indicates whether the BoxPredictor is in training mode.
- box_code_size – Size of encoding for each box.
- kernel_size – Size of final convolution kernel. If the spatial resolution of the feature map is smaller than the kernel size, then the kernel size is automatically set to be min(feature_width, feature_height).
- use_depthwise – Whether to use depthwise convolutions for prediction steps. Default is False.
Raises: ValueError
– if min_depth > max_depth.
-
predict
(features, num_predictions_per_location)[source]¶ Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing image features.
- num_predictions_per_location – Number of box predictions to be made per spatial location. Int specifying number of boxes per location.
Returns: - A float tensors of shape
[batch_size, num_anchors, code_size] representing the location of the objects.
Return type: box_encodings
-
-
class
easy_vision.python.core.detection_predictors.heads.box_head.
MaskRCNNBoxHead
(is_training, num_classes, fc_hyperparams_fn, dropout_keep_prob, box_code_size, agnostic=False)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Box prediction head.
Please refer to Mask RCNN paper: https://arxiv.org/abs/1703.06870
-
__init__
(is_training, num_classes, fc_hyperparams_fn, dropout_keep_prob, box_code_size, agnostic=False)[source]¶ Constructor.
Parameters: - is_training – Indicates whether the BoxPredictor is in training mode.
- num_classes – number of classes. Note that num_classes does not include the background category, so if groundtruth labels take values in {0, 1, .., K-1}, num_classes=K (and not K+1, even though the assigned classification targets can range from {0,… K}).
- fc_hyperparams_fn –
- A function to generate tf-slim arg_scope with
- hyperparameters for fully connected ops.
- dropout_keep_prob: Keep probability for dropout. Note that a single dropout
- op is applied here prior to both box and class predictions, which stands in contrast to the ConvolutionalBoxPredictor below.
- box_code_size – Size of encoding for each box.
- agnostic – Whether to share boxes across classes rather than use a different box for each class.
-
predict
(features, num_predictions_per_location=1)[source]¶ Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing features for a batch of images.
- num_predictions_per_location – Int containing number of predictions per location.
Returns: - A float tensor of shape
[batch_size, 1, num_classes, code_size] representing the location of the objects.
Return type: box_encodings
Raises: ValueError
– If num_predictions_per_location is not 1.
-
Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Weight shared convolutional box prediction head.
This head allows sharing the same set of parameters (weights) when called more then once on different feature maps.
Constructor.
Parameters: - box_code_size – Size of encoding for each box.
- kernel_size – Size of final convolution kernel.
- use_depthwise – Whether to use depthwise convolutions for prediction steps. Default is False.
- box_encodings_clip_range – Min and max values for clipping box_encodings.
Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing image features.
- num_predictions_per_location – Number of box predictions to be made per spatial location.
Returns: - A float tensor of shape
[batch_size, num_anchors, code_size] representing the location of the objects.
Return type: box_encodings
easy_vision.python.core.detection_predictors.heads.class_head¶
Class Head.
Contains Class prediction head classes for different meta architectures. All the class prediction heads have a predict function that receives the features as the first argument and returns class predictions with background.
-
class
easy_vision.python.core.detection_predictors.heads.class_head.
Convolutional3DClassHead
(is_training, num_class_slots, dropout_keep_prob, kernel_size, class_prediction_bias_init=0.0, use_depthwise=False)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Convolutional class prediction head.
-
__init__
(is_training, num_class_slots, dropout_keep_prob, kernel_size, class_prediction_bias_init=0.0, use_depthwise=False)[source]¶ Constructor.
Parameters: - is_training – Indicates whether the BoxPredictor is in training mode.
- num_class_slots – number of class slots. Note that num_class_slots may or may not include an implicit background category.
- dropout_keep_prob – Keep probability for dropout. Note that a single dropout op is applied here prior to both box and class predictions, which stands in contrast to the ConvolutionalBoxPredictor below. When it is 1.0, will not include dropout op.
- kernel_size – Size of final convolution kernel. If the spatial resolution of the feature map is smaller than the kernel size, then the kernel size is automatically set to be min(feature_width, feature_height).
- class_prediction_bias_init – constant value to initialize bias of the last conv2d layer before class prediction.
- use_depthwise – Whether to use depthwise convolutions for prediction steps. Default is False.
Raises: ValueError
– if min_depth > max_depth.
-
predict
(features, num_predictions_per_location)[source]¶ Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing image features.
- num_predictions_per_location – Number of box predictions to be made per spatial location.
Returns: - A float tensors of shape
[batch_size, num_anchors, num_class_slots] representing the class predictions for the proposals.
Return type: class_predictions_with_background
-
-
class
easy_vision.python.core.detection_predictors.heads.class_head.
ConvolutionalClassHead
(is_training, num_class_slots, dropout_keep_prob, kernel_size, class_prediction_bias_init=0.0, use_depthwise=False)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Convolutional class prediction head.
-
__init__
(is_training, num_class_slots, dropout_keep_prob, kernel_size, class_prediction_bias_init=0.0, use_depthwise=False)[source]¶ Constructor.
Parameters: - is_training – Indicates whether the BoxPredictor is in training mode.
- num_class_slots – number of class slots. Note that num_class_slots may or may not include an implicit background category.
- dropout_keep_prob – Keep probability for dropout. Note that a single dropout op is applied here prior to both box and class predictions, which stands in contrast to the ConvolutionalBoxPredictor below. When it is 1.0, will not include dropout op.
- kernel_size – Size of final convolution kernel. If the spatial resolution of the feature map is smaller than the kernel size, then the kernel size is automatically set to be min(feature_width, feature_height).
- class_prediction_bias_init – constant value to initialize bias of the last conv2d layer before class prediction.
- use_depthwise – Whether to use depthwise convolutions for prediction steps. Default is False.
Raises: ValueError
– if min_depth > max_depth.
-
predict
(features, num_predictions_per_location)[source]¶ Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing image features.
- num_predictions_per_location – Number of box predictions to be made per spatial location.
Returns: - A float tensors of shape
[batch_size, num_anchors, num_class_slots] representing the class predictions for the proposals.
Return type: class_predictions_with_background
-
-
class
easy_vision.python.core.detection_predictors.heads.class_head.
MaskRCNNClassHead
(is_training, num_class_slots, fc_hyperparams_fn, dropout_keep_prob)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Mask RCNN class prediction head.
Please refer to Mask RCNN paper: https://arxiv.org/abs/1703.06870
-
__init__
(is_training, num_class_slots, fc_hyperparams_fn, dropout_keep_prob)[source]¶ Constructor.
Parameters: - is_training – Indicates whether the BoxPredictor is in training mode.
- num_class_slots – number of class slots. Note that num_class_slots may or may not include an implicit background category.
- fc_hyperparams_fn – A function to generate tf-slim arg_scope with hyperparameters for fully connected ops.
- dropout_keep_prob – Keep probability for dropout, if == 1.0, will not do dropout
-
predict
(features, num_predictions_per_location=1)[source]¶ Predicts boxes and class scores.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing features for a batch of images.
- num_predictions_per_location – Int containing number of predictions per location.
Returns: - A float tensor of shape
[batch_size, 1, num_class_slots] representing the class predictions for the proposals.
Return type: class_predictions_with_background
Raises: ValueError
– If num_predictions_per_location is not 1.
-
Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Weight shared convolutional class prediction head.
This head allows sharing the same set of parameters (weights) when called more then once on different feature maps.
Constructor.
Parameters: - num_class_slots – number of class slots. Note that num_class_slots may or may not include an implicit background category.
- kernel_size – Size of final convolution kernel.
- class_prediction_bias_init – constant value to initialize bias of the last conv2d layer before class prediction.
- dropout_keep_prob – drop out keep probabilities. Apply dropout to class prediction head when dropout_keep_prob != 1.0
- use_depthwise – Whether to use depthwise convolutions for prediction steps. Default is False.
Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing image features.
- num_predictions_per_location – Number of box predictions to be made per spatial location.
Returns: - A tensor of shape
[batch_size, num_anchors, num_class_slots] representing the class predictions for the proposals.
Return type: class_predictions_with_background
easy_vision.python.core.detection_predictors.heads.head¶
Base head class.
All the different kinds of prediction heads in different models will inherit from this class. What is in common between all head classes is that they have a predict function that receives features as its first argument.
How to add a new prediction head to an existing meta architecture? For example, how can we add a 3d shape prediction head to Mask RCNN?
We have to take the following steps to add a new prediction head to an existing meta arch: (a) Add a class for predicting the head. This class should inherit from the Head class below and have a predict function that receives the features and predicts the output. The output is always a tf.float32 tensor. (b) Add the head to the meta architecture. For example in case of Mask RCNN, go to box_predictor_builder and put in the logic for adding the new head to the Mask RCNN box predictor. (c) Add the logic for computing the loss for the new head. (d) Add the necessary metrics for the new head. (e) (optional) Add visualization for the new head.
easy_vision.python.core.detection_predictors.heads.keypoint_head¶
Keypoint Head.
Contains Keypoint prediction head classes for different meta architectures. All the keypoint prediction heads have a predict function that receives the features as the first argument and returns keypoint_predictions. Keypoints could be used to represent the human body joint locations as in Mask RCNN paper. Or they could be used to represent different part locations of objects.
-
class
easy_vision.python.core.detection_predictors.heads.keypoint_head.
MaskRCNNKeypointHead
(num_keypoints=17, conv_hyperparams_fn=None, keypoint_heatmap_height=56, keypoint_heatmap_width=56, keypoint_prediction_num_conv_layers=8, keypoint_prediction_conv_depth=512)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Mask RCNN keypoint prediction head.
Please refer to Mask RCNN paper: https://arxiv.org/abs/1703.06870
-
__init__
(num_keypoints=17, conv_hyperparams_fn=None, keypoint_heatmap_height=56, keypoint_heatmap_width=56, keypoint_prediction_num_conv_layers=8, keypoint_prediction_conv_depth=512)[source]¶ Constructor.
Parameters: - num_keypoints – (int scalar) number of keypoints.
- conv_hyperparams_fn – A function to generate tf-slim arg_scope with hyperparameters for convolution ops.
- keypoint_heatmap_height – Desired output mask height. The default value is 14.
- keypoint_heatmap_width – Desired output mask width. The default value is 14.
- keypoint_prediction_num_conv_layers – Number of convolution layers applied to the image_features in mask prediction branch.
- keypoint_prediction_conv_depth – The depth for the first conv2d_transpose op applied to the image_features in the mask prediction branch. If set to 0, the depth of the convolution layers will be automatically chosen based on the number of object classes and the number of channels in the image features.
-
predict
(features, num_predictions_per_location=1)[source]¶ Performs keypoint prediction.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing features for a batch of images.
- num_predictions_per_location – Int containing number of predictions per location.
Returns: - A float tensor of shape
[batch_size, 1, num_keypoints, heatmap_height, heatmap_width].
Return type: instance_masks
Raises: ValueError
– If num_predictions_per_location is not 1.
-
-
class
easy_vision.python.core.detection_predictors.heads.keypoint_head.
TextKeypointHead
(num_keypoints=4, fc_hyperparams_fn=None, keypoint_prediction_num_fc_layers=2, keypoint_prediction_fc_depth=1024, predict_direction=False)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Text keypoint prediction head.
-
__init__
(num_keypoints=4, fc_hyperparams_fn=None, keypoint_prediction_num_fc_layers=2, keypoint_prediction_fc_depth=1024, predict_direction=False)[source]¶ Constructor.
Parameters: - num_keypoints – (int scalar) number of keypoints.
- fc_hyperparams_fn – A function to generate tf-slim arg_scope with hyperparameters for fc ops.
- keypoint_prediction_num_fc_layers – Number of fc layers applied to the image_features in keypoint prediction branch.
- keypoint_prediction_fc_depth – The depth f fc layers applied to the image_features in keypoint prediction branch.
- predict_direction – predict text direction or not.
-
predict
(features, num_predictions_per_location=1)[source]¶ Performs keypoint prediction.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing features for a batch of images.
- num_predictions_per_location – Int containing number of predictions per location.
Returns: - A dictionary containing the predicted tensors
keypoints: A float tensor of shape [batch_size, num_keypoints * 2]. directions: A float tensor of shape [batch_size, 4].
Return type: prediction_dict
Raises: ValueError
– If num_predictions_per_location is not 1.
-
easy_vision.python.core.detection_predictors.heads.mask_head¶
Mask Head.
Contains Mask prediction head classes for different meta architectures. All the mask prediction heads have a predict function that receives the features as the first argument and returns mask_predictions.
-
class
easy_vision.python.core.detection_predictors.heads.mask_head.
ConvolutionalMaskHead
(is_training, num_classes, dropout_keep_prob, kernel_size, use_depthwise=False, mask_height=7, mask_width=7, masks_are_class_agnostic=False)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Convolutional class prediction head.
-
__init__
(is_training, num_classes, dropout_keep_prob, kernel_size, use_depthwise=False, mask_height=7, mask_width=7, masks_are_class_agnostic=False)[source]¶ Constructor.
Parameters: - is_training – Indicates whether the BoxPredictor is in training mode.
- num_classes – Number of classes.
- dropout_keep_prob – Keep probability for dropout. Note that a single dropout op is applied here prior to both box and class predictions, which stands in contrast to the ConvolutionalBoxPredictor below.
- kernel_size – Size of final convolution kernel. If the spatial resolution of the feature map is smaller than the kernel size, then the kernel size is automatically set to be min(feature_width, feature_height).
- use_depthwise – Whether to use depthwise convolutions for prediction steps. Default is False.
- mask_height – Desired output mask height. The default value is 7.
- mask_width – Desired output mask width. The default value is 7.
- masks_are_class_agnostic – Boolean determining if the mask-head is class-agnostic or not.
Raises: ValueError
– if min_depth > max_depth.
-
predict
(features, num_predictions_per_location)[source]¶ Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing image features.
- num_predictions_per_location – Number of box predictions to be made per spatial location.
Returns: - A float tensors of shape
[batch_size, num_anchors, num_masks, mask_height, mask_width] representing the mask predictions for the proposals.
Return type: mask_predictions
-
-
class
easy_vision.python.core.detection_predictors.heads.mask_head.
MaskRCNNMaskHead
(num_classes, conv_hyperparams_fn=None, mask_height=14, mask_width=14, mask_prediction_num_conv_layers=2, mask_prediction_conv_depth=256, masks_are_class_agnostic=False, convolve_then_upsample=False)[source]¶ Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Mask RCNN mask prediction head.
Please refer to Mask RCNN paper: https://arxiv.org/abs/1703.06870
-
__init__
(num_classes, conv_hyperparams_fn=None, mask_height=14, mask_width=14, mask_prediction_num_conv_layers=2, mask_prediction_conv_depth=256, masks_are_class_agnostic=False, convolve_then_upsample=False)[source]¶ Constructor.
Parameters: - num_classes – number of classes. Note that num_classes does not include the background category, so if groundtruth labels take values in {0, 1, .., K-1}, num_classes=K (and not K+1, even though the assigned classification targets can range from {0,… K}).
- conv_hyperparams_fn – A function to generate tf-slim arg_scope with hyperparameters for convolution ops.
- mask_height – Desired output mask height. The default value is 14.
- mask_width – Desired output mask width. The default value is 14.
- mask_prediction_num_conv_layers – Number of convolution layers applied to the image_features in mask prediction branch.
- mask_prediction_conv_depth – The depth for the first conv2d_transpose op applied to the image_features in the mask prediction branch. If set to 0, the depth of the convolution layers will be automatically chosen based on the number of object classes and the number of channels in the image features.
- masks_are_class_agnostic – Boolean determining if the mask-head is class-agnostic or not.
- convolve_then_upsample – Whether to apply convolutions on mask features before upsampling using nearest neighbor resizing. Otherwise, mask features are resized to [mask_height, mask_width] using bilinear resizing before applying convolutions.
Raises: ValueError
– conv_hyperparams_fn is None.
-
predict
(features, num_predictions_per_location=1)[source]¶ Performs mask prediction.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing features for a batch of images.
- num_predictions_per_location – Int containing number of predictions per location.
Returns: - A float tensor of shape
[batch_size, 1, num_classes, mask_height, mask_width].
Return type: instance_masks
Raises: ValueError
– If num_predictions_per_location is not 1.
-
Bases:
easy_vision.python.core.detection_predictors.heads.head.Head
Weight shared convolutional mask prediction head.
Constructor.
Parameters: - num_classes – number of classes. Note that num_classes does not include the background category, so if groundtruth labels take values in {0, 1, .., K-1}, num_classes=K (and not K+1, even though the assigned classification targets can range from {0,… K}).
- kernel_size – Size of final convolution kernel.
- dropout_keep_prob – Probability of keeping activiations. Apply dropout to class prediction head if dropout_keep_prob!=1.0
- mask_height – Desired output mask height. The default value is 7.
- mask_width – Desired output mask width. The default value is 7.
- masks_are_class_agnostic – Boolean determining if the mask-head is class-agnostic or not.
Predicts boxes.
Parameters: - features – A float tensor of shape [batch_size, height, width, channels] containing image features.
- num_predictions_per_location – Number of box predictions to be made per spatial location.
Returns: - A tensor of shape
[batch_size, num_anchors, num_classes, mask_height, mask_width] representing the mask predictions for the proposals.
Return type: mask_predictions