4、picodet 小目标训练全流程( 七 )

<00:00, 6604.52it/s]'pq_448_75:'{'avg_annotation_area': 4893.795871259963,'avg_num_annotations_in_image': 1.8925200906655677,'max_annotation_area': 200704,'max_annotation_area_per_category': {'ball': 200704},'max_num_annotations_in_image': 16,'min_annotation_area': 13,'min_annotation_area_per_category': {'ball': 13},'min_num_annotations_in_image': 1,'num_annotations': 45922,'num_annotations_per_category': {'ball': 45922},'num_categories': 1,'num_images': 24265,'num_images_per_category': {'ball': 24265},'num_negative_images': 0}indexing coco dataset annotations...Loading coco annotations: 100%|██████████| 18265/18265 [00:02<00:00, 7345.95it/s]'pq_480_75:'{'avg_annotation_area': 5578.763276481661,'avg_num_annotations_in_image': 1.9196277032575966,'max_annotation_area': 230400,'max_annotation_area_per_category': {'ball': 230400},'max_num_annotations_in_image': 17,'min_annotation_area': 8,'min_annotation_area_per_category': {'ball': 8},'min_num_annotations_in_image': 1,'num_annotations': 35062,'num_annotations_per_category': {'ball': 35062},'num_categories': 1,'num_images': 18265,'num_images_per_category': {'ball': 18265},'num_negative_images': 0}indexing coco dataset annotations...Loading coco annotations: 100%|██████████| 17726/17726 [00:02<00:00, 6080.24it/s]'pq_512_75:'{'avg_annotation_area': 5312.11180071894,'avg_num_annotations_in_image': 2.0088006318402347,'max_annotation_area': 262144,'max_annotation_area_per_category': {'ball': 262144},'max_num_annotations_in_image': 17,'min_annotation_area': 7,'min_annotation_area_per_category': {'ball': 7},'min_num_annotations_in_image': 1,'num_annotations': 35608,'num_annotations_per_category': {'ball': 35608},'num_categories': 1,'num_images': 17726,'num_images_per_category': {'ball': 17726},'num_negative_images': 0}
2.4 过滤数据集中不合适的框
切图过程中必然会产生一些只切了一部分目标物体的图 , 这部分图要过滤掉
过滤主要:超过图片高宽、面积
import osimport glob from sahi.utils.coco import Cocofrom sahi.utils.coco import remove_invalid_coco_resultsfrom sahi.utils.file import save_jsonfor i in out_size_ratio:datapath = i[0]print(f"Start do {datapath}")jsonfile = glob.glob(os.path.join(datapath,'*.json'))[0]jsonname = os.path.splitext(os.path.basename(jsonfile))[0]savejson=os.path.join(datapath,jsonname+'_filtered.json')coco = Coco.from_coco_dict_or_path(jsonfile)print(f"init coco img_num:{len(coco.json['images'])} annottations num:{len(coco.json['annotations'])}")#因为是标注的图片 , 所以用图片高宽对标注框直接进行clipcoco = coco.get_coco_with_clipped_bboxes()#面积intervals_per_category={"ball":{"min":9,"max":2500}}area_filtered_coco=coco.get_area_filtered_coco(intervals_per_category=intervals_per_category)print(f"area filtered coco img_num:{len(area_filtered_coco.json['images'])} annottations num:{len(area_filtered_coco.json['annotations'])}")save_json(area_filtered_coco.json,savejson)
Start do dataset/pqdetection_sliced/pq_160_75indexing coco dataset annotations...Loading coco annotations: 100%|██████████| 60068/60068 [00:06<00:00, 9621.37it/s] init coco img_num:60068 annottations num:77854area filtered coco img_num:47588 annottations num:62160Start do dataset/pqdetection_sliced/pq_192_75indexing coco dataset annotations...Loading coco annotations: 100%|██████████| 52959/52959 [00:06<00:00, 8777.43it/s] init coco img_num:52959 annottations num:72167area filtered coco img_num:42357 annottations num:58173Start do dataset/pqdetection_sliced/pq_224_75indexing coco dataset annotations...Loading coco annotations: 100%|██████████| 47829/47829 [00:05