code: def _coco_remove_images_without_annotations(dataset, cat_list=None):
      def _has_only_empty_bbox(anno):
          return all(
              any(o <= 1 for o in obj["bbox"][2:]) for obj in anno
          )
  
      def _count_visible_keypoints(anno):
          return sum(
              sum(1 for v in ann["keypoints"][2::3] if v > 0)
              for ann in anno
          )
  
      min_keypoints_per_image = 10
  
      def _has_valid_annotation(anno):
          # if it's empty, there is no annotation
          if len(anno) == 0:
              return False
          # if all boxes have close to zero area, there is no annotation
          if _has_only_empty_bbox(anno):
              return False
          # keypoints task have a slight different criteria for considering
          # if an annotation is valid
          if "keypoints" not in anno[0]:
              return True
          # for keypoint detection tasks, only consider valid images those
          # containing at least min_keypoints_per_image
          if _count_visible_keypoints(anno) >= min_keypoints_per_image:
              return True
          return False
  
      ids = []
      for ds_idx, img_id in enumerate(dataset.ids):
          ann_ids = dataset.coco.getAnnIds(imgIds=img_id, iscrowd=None)
          anno = dataset.coco.loadAnns(ann_ids)
          if cat_list:
              anno = [
                  obj for obj in anno if obj["category_id"] in cat_list
              ]
          if _has_valid_annotation(anno):
              ids.append(ds_idx)
  
      dataset = torch.utils.data.Subset(dataset, ids)
      return dataset
  
file_path: vision/references/detection/coco_utils.py
imports: import os
  import torch
  import torch.utils.data
  import torchvision
  import transforms
  from pycocotools import mask
  from pycocotools.coco import COCO
label_desc: Use image node_id 2 for calling a global function with example usage: _coco_remove_images_without_annotations(dataset, cat_list) and returns: dataset, all, sum, False, False, False, True, True