code: def _coco_remove_images_without_annotations(dataset, ids):
      """
      删除coco数据集中没有目标，或者目标面积非常小的数据
      refer to:
      https://github.com/pytorch/vision/blob/master/references/detection/coco_utils.py
      :param dataset:
      :param cat_list:
      :return:
      """
  
      def _has_only_empty_bbox(anno):
          return all(
              any(o <= 1 for o in obj["bbox"][2:]) for obj in anno
          )
  
      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
  
          return True
  
      valid_ids = []
      for ds_idx, img_id in enumerate(ids):
          ann_ids = dataset.getAnnIds(imgIds=img_id, iscrowd=None)
          anno = dataset.loadAnns(ann_ids)
  
          if _has_valid_annotation(anno):
              valid_ids.append(img_id)
  
      return valid_ids
  
imports: import os
  import time
  import json
  import copy
  import cv2
  import numpy
  import torch
  from torchmetrics.detection.mean_ap import MeanAveragePrecision
  import torchvision
  from pycocotools.coco import COCO
  from pycocotools.cocoeval import COCOeval
  from compression.api import DataLoader, Metric
label_desc: Use image node_id 4 for calling a global function with example usage: _coco_remove_images_without_annotations(dataset, ids) and returns: valid_ids, all, True, False, False