code: def _coco_remove_images_without_annotations(dataset, cat_list=None):
      def _has_valid_annotation(anno):
          # if it's empty, there is no annotation
          if len(anno) == 0:
              return False
          # if more than 1k pixels occupied in the image
          return sum(obj["area"] for obj in anno) > 1000
  
      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/segmentation/coco_utils.py
imports: import copy
  import os
  import torch
  import torch.utils.data
  import torchvision
  from PIL import Image
  from pycocotools import mask
  from transforms import Compose
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, unknown, False