Home > Mobile >  Using detectron2 how do I change how many classes my dataset has
Using detectron2 how do I change how many classes my dataset has

Time:02-16

Despite changing the classes line to

cfg.MODEL.ROI_HEADS.NUM_CLASSES = 2

in the config portion of my detectron2 training python script I keep getting back

Got an invalid category_id=1 for a dataset of 1 classes

Is there something special I need to be doing to the dataset itself to let detectron know I have more than one class?

I also tried

cfg.MODEL.SEM_SEG_HEAD.NUM_CLASSES = 2
cfg.MODEL.RETINANET.NUM_CLASSES = 2

Just in case but im using the mask_rcnn_R_101_FPN_3x model so I think the first one is the one that should be doing the trick

I also, also tried importing my class id #'s to the thing_dataset_id_to_contiguous_id metadeta attribute

edit: I've tried a few other models with the same error, which triggers when I call

trainer = DefaultTrainer(cfg)

Ive also printed out my (at the moment very simple because im still just prototyping) dataset dict and cant see anything glaringly obvious.

I cant find anywhere besides the config portion that it even seems to care about the number of classes

edit 2: Installed an instance of ubuntu through wsl and tried running the script and same error

edit 3: tried a python 3.8 and 3.9 venv

CodePudding user response:

I figured it out and it was me being dumb

So let my dumbness provide an answer for anyone else stuck up this particular creek.

So in addition to adding

cfg.MODEL.ROI_HEADS.NUM_CLASSES = 2

into your config section, Detectron also uses your metadata to count how many classes the set should have

I was using

MetadataCatalog.get("my_dataset").thing_classes=thing_list

for some reason thinking I was getting a reference to an object and setting an attribute (and didnt get an error telling me otherwise)

when what I SHOULD have been using was

MetadataCatalog.get("my_dataset").set(thing_classes=thing_list)

I'm not sure where I crossed my wires but at this point it seems to be working

  • Related