From 3693d7886ba8a0e6ee9ff37580e21b9025703231 Mon Sep 17 00:00:00 2001 From: Guanghua Yu <742925032@qq.com> Date: Thu, 11 Mar 2021 20:07:44 +0800 Subject: [PATCH] fix obj365 label and config (#2331) --- ...are_r200_vd_fpn_dcnv2_nonlocal_softnms.yml | 2 +- ...cascade_rcnn_dcnv2_se154_vd_fpn_gn_cas.yml | 4 +- dataset/coco/objects365_label.txt | 365 ++++++++++++++++++ ppdet/utils/coco_eval.py | 29 +- 4 files changed, 397 insertions(+), 3 deletions(-) create mode 100644 dataset/coco/objects365_label.txt diff --git a/configs/obj365/cascade_rcnn_cls_aware_r200_vd_fpn_dcnv2_nonlocal_softnms.yml b/configs/obj365/cascade_rcnn_cls_aware_r200_vd_fpn_dcnv2_nonlocal_softnms.yml index d50c93492..48ab8d5ae 100644 --- a/configs/obj365/cascade_rcnn_cls_aware_r200_vd_fpn_dcnv2_nonlocal_softnms.yml +++ b/configs/obj365/cascade_rcnn_cls_aware_r200_vd_fpn_dcnv2_nonlocal_softnms.yml @@ -189,7 +189,7 @@ TestReader: fields: ['image', 'im_info', 'im_id', 'im_shape'] dataset: !ImageFolder - anno_path: annotations/instances_val2017.json + anno_path: dataset/coco/objects365_label.txt sample_transforms: - !DecodeImage to_rgb: true diff --git a/configs/obj365/cascade_rcnn_dcnv2_se154_vd_fpn_gn_cas.yml b/configs/obj365/cascade_rcnn_dcnv2_se154_vd_fpn_gn_cas.yml index 67f5ef59d..aef0fe966 100644 --- a/configs/obj365/cascade_rcnn_dcnv2_se154_vd_fpn_gn_cas.yml +++ b/configs/obj365/cascade_rcnn_dcnv2_se154_vd_fpn_gn_cas.yml @@ -221,10 +221,12 @@ EvalReader: worker_num: 2 TestReader: + inputs_def: + fields: ['image', 'im_info', 'im_id', 'im_shape'] batch_size: 1 dataset: !ImageFolder - anno_path: dataset/obj365/annotations/val.json + anno_path: dataset/coco/objects365_label.txt sample_transforms: - !DecodeImage to_rgb: True diff --git a/dataset/coco/objects365_label.txt b/dataset/coco/objects365_label.txt new file mode 100644 index 000000000..f71ffd8c0 --- /dev/null +++ b/dataset/coco/objects365_label.txt @@ -0,0 +1,365 @@ +person +sneakers +chair +hat +lamp +bottle +cabinet/shelf +cup +car +glasses +picture/frame +desk +handbag +street lights +book +plate +helmet +leather shoes +pillow +glove +potted plant +bracelet +flower +tv +storage box +vase +bench +wine glass +boots +bowl +dining table +umbrella +boat +flag +speaker +trash bin/can +stool +backpack +couch +belt +carpet +basket +towel/napkin +slippers +barrel/bucket +coffee table +suv +toy +tie +bed +traffic light +pen/pencil +microphone +sandals +canned +necklace +mirror +faucet +bicycle +bread +high heels +ring +van +watch +sink +horse +fish +apple +camera +candle +teddy bear +cake +motorcycle +wild bird +laptop +knife +traffic sign +cell phone +paddle +truck +cow +power outlet +clock +drum +fork +bus +hanger +nightstand +pot/pan +sheep +guitar +traffic cone +tea pot +keyboard +tripod +hockey +fan +dog +spoon +blackboard/whiteboard +balloon +air conditioner +cymbal +mouse +telephone +pickup truck +orange +banana +airplane +luggage +skis +soccer +trolley +oven +remote +baseball glove +paper towel +refrigerator +train +tomato +machinery vehicle +tent +shampoo/shower gel +head phone +lantern +donut +cleaning products +sailboat +tangerine +pizza +kite +computer box +elephant +toiletries +gas stove +broccoli +toilet +stroller +shovel +baseball bat +microwave +skateboard +surfboard +surveillance camera +gun +life saver +cat +lemon +liquid soap +zebra +duck +sports car +giraffe +pumpkin +piano +stop sign +radiator +converter +tissue +carrot +washing machine +vent +cookies +cutting/chopping board +tennis racket +candy +skating and skiing shoes +scissors +folder +baseball +strawberry +bow tie +pigeon +pepper +coffee machine +bathtub +snowboard +suitcase +grapes +ladder +pear +american football +basketball +potato +paint brush +printer +billiards +fire hydrant +goose +projector +sausage +fire extinguisher +extension cord +facial mask +tennis ball +chopsticks +electronic stove and gas stove +pie +frisbee +kettle +hamburger +golf club +cucumber +clutch +blender +tong +slide +hot dog +toothbrush +facial cleanser +mango +deer +egg +violin +marker +ship +chicken +onion +ice cream +tape +wheelchair +plum +bar soap +scale +watermelon +cabbage +router/modem +golf ball +pine apple +crane +fire truck +peach +cello +notepaper +tricycle +toaster +helicopter +green beans +brush +carriage +cigar +earphone +penguin +hurdle +swing +radio +CD +parking meter +swan +garlic +french fries +horn +avocado +saxophone +trumpet +sandwich +cue +kiwi fruit +bear +fishing rod +cherry +tablet +green vegetables +nuts +corn +key +screwdriver +globe +broom +pliers +volleyball +hammer +eggplant +trophy +dates +board eraser +rice +tape measure/ruler +dumbbell +hamimelon +stapler +camel +lettuce +goldfish +meat balls +medal +toothpaste +antelope +shrimp +rickshaw +trombone +pomegranate +coconut +jellyfish +mushroom +calculator +treadmill +butterfly +egg tart +cheese +pig +pomelo +race car +rice cooker +tuba +crosswalk sign +papaya +hair drier +green onion +chips +dolphin +sushi +urinal +donkey +electric drill +spring rolls +tortoise/turtle +parrot +flute +measuring cup +shark +steak +poker card +binoculars +llama +radish +noodles +yak +mop +crab +microscope +barbell +bread/bun +baozi +lion +red cabbage +polar bear +lighter +seal +mangosteen +comb +eraser +pitaya +scallop +pencil case +saw +table tennis paddle +okra +starfish +eagle +monkey +durian +game board +rabbit +french horn +ambulance +asparagus +hoverboard +pasta +target +hotair balloon +chainsaw +lobster +iron +flashlight \ No newline at end of file diff --git a/ppdet/utils/coco_eval.py b/ppdet/utils/coco_eval.py index 1d0695220..a827b71a3 100644 --- a/ppdet/utils/coco_eval.py +++ b/ppdet/utils/coco_eval.py @@ -492,7 +492,34 @@ def get_category_info(anno_file=None, return coco17_category_info(with_background) else: logger.info("Load categories from {}".format(anno_file)) - return get_category_info_from_anno(anno_file, with_background) + if anno_file.endswith('.json'): + return get_category_info_from_anno(anno_file, with_background) + else: + return get_category_info_from_txt(anno_file, with_background) + + +def get_category_info_from_txt(anno_file, with_background=True): + """ + Get class id to category id map and category id + to category name map from txt file. + + args: + anno_file (str): label txt file path. + with_background (bool, default True): + whether load background as class 0. + """ + with open(anno_file, "r") as f: + catid_list = f.readlines() + clsid2catid = {} + catid2name = {} + for i, catid in enumerate(catid_list): + catid = catid.strip('\n\t\r') + clsid2catid[i + int(with_background)] = i + 1 + catid2name[i + int(with_background)] = catid + if with_background: + clsid2catid.update({0: 0}) + catid2name.update({0: 'background'}) + return clsid2catid, catid2name def get_category_info_from_anno(anno_file, with_background=True): -- GitLab