facebookresearch / detr

End-to-End Object Detection with Transformers
Apache License 2.0
13.63k stars 2.46k forks source link

How to train and test a model on custom multi class dataset ? #480

Open Usmani255 opened 2 years ago

Usmani255 commented 2 years ago

We have applied this DeTR method, following exactly the same in this. It works perfectly fine for single-class Face detection detection & it also worked well for our own single-class object detection using Transformer. But when we extend this DeTR code for muti class custom dataset using this tutorial, it didn't work well, I sought the tutorial helps for defining num_class (as num_classes+1) in detr.py file. But even then it didn't work well. If someone could guide us how to apply DeTR for multi-class object detection or if could please refer some DeTR tutorial for multi-class object detection. Thanx!

Usmani255 commented 2 years ago

@colesbury @Celebio @pdollar @likethesky Hi sir how are you,Please help me regarding this I run this code on google colab for single class it works well but i failed to get results on multiple class 1.My datasets contains the 15 classes and my last class is is 15 so i change in detr.py to num_classes=16

dataset_class

detrfile

2.in every Epoch class rate is decreasing in training but it is remained to 100 in after every Epoch during test lossproblem1 loss problem2

3.I am also sharing my built checkpoint.pth file with you log file

TalentedMUSE commented 2 years ago

I have the same problem! the train class error is always 99

TalentedMUSE commented 2 years ago

We have applied this DeTR method, following exactly the same in this. It works perfectly fine for single-class Face detection detection & it also worked well for our own single-class object detection using Transformer. But when we extend this DeTR code for muti class custom dataset using this tutorial, it didn't work well, I sought the tutorial helps for defining num_class (as num_classes+1) in detr.py file. But even then it didn't work well. If someone could guide us how to apply DeTR for multi-class object detection or if could please refer some DeTR tutorial for multi-class object detection. Thanx!

I solve the problem. First of all, if your dataset is coco and has 15 classes, you should writenum_classes = xxx if args.dataset_file != 'coco' else 15; Then, you should load pretrained model given by the author. In main.py, you should do some modifications: if args.resume: if args.resume.startswith('https'): checkpoint = torch.hub.load_state_dict_from_url( args.resume, map_location='cpu', check_hash=True) else: checkpoint = torch.load(args.resume, map_location='cpu') del checkpoint['model']['class_embed.weight'] del checkpoint['model']['class_embed.bias'] model_without_ddp.load_state_dict(checkpoint['model'], strict=False)

TalentedMUSE commented 2 years ago

Then when you call python main.py, you should add parameter --resume 'xxx.pth'

aa200647963 commented 2 years ago

@TalentedMUSE I have a problem of the num_classes,in the detr.py loss_labels function, I find the background class is set to be 91, and the model works well, but when I set the back groundclass to 0, the model works bad, can you tell me why? thx image