class_docstr: Randomly crops an image based on self._sample_random_crop_region.
class_docstr_tok: ["Randomly","crops","an","image","based","on","self._sample_random_crop_region","."]
docstr: Drops degenerate (e.g. cropped out) boxes.
docstr_tok: ["Drops","degenerate","(","e.g",".","cropped","out",")","boxes","."]
code: def _drop_degenerate_features(
      self, features: Features, orig_features: Optional[Features] = None
  ) -> Features:
      """Drops degenerate (e.g. cropped out) boxes."""
      # Find degenerate boxes (i.e. boxes which have been cropped out of the
      # image).
      keep = []
      if self.boxes_key in features:
          # Keep boxes whose area is greater than 0:
          rel_area = transforms.get_box_area(features[self.boxes_key])
          keep.append(rel_area > 0.0)
  
          if (
              hasattr(self, "min_area_fraction")
              and orig_features is not None
          ):
              area = transforms.get_box_area(
                  features[self.boxes_key],
                  transforms.get_dynamic_size(features[self.image_key]),
              )
              orig_area = transforms.get_box_area(
                  orig_features[self.boxes_key],
                  transforms.get_dynamic_size(
                      orig_features[self.image_key]
                  ),
              )
  
              area_left = area / (orig_area + 1e-8)
              keep.append(area_left >= self.min_area_fraction)
  
      # If there are no boxes there are no degenerate objects to filter out.
      if not keep:
          return features
  
      # Keep instances for which all features are non-degenerate:
      keep = tf.reduce_all(tf.stack(keep, axis=0), axis=0)
  
      # Only keep non-degenerate instances:
      for key, feature in features.items():
          axis = self._get_instance_axis(key)
          if axis is not None:
              if axis == 0:
                  features[key] = feature[keep]
              else:
                  raise NotImplementedError(
                      "Instances must be along leading axis."
                  )
  
      return features
  
imports: import abc
  import dataclasses
  from typing import Optional, Sequence, Tuple, Union
  from clu import preprocess_spec
  from scenic.projects.owl_vit.preprocessing import modalities
  from scenic.projects.owl_vit.preprocessing import transforms
  import tensorflow
label_desc: Use image node_id 4 for calling the RandomCropBase obj's underlying member method code with example usage: obj._drop_degenerate_features(features, orig_features) and returns: features, features