[英]How to fine tune an object detection model for custom data and classes using Detectron2?
I have a pre-trained model weight (as .pth
) and it's configuration (as .yaml
) and I want to fine-tune this model on my downstream task.我有一个预先训练的 model 重量(如
.pth
)及其配置(如.yaml
),我想在下游任务上微调这个 Z20F35E630DAF44DBFA4C3F68F5399D。 The only problem is that I have 1 class while the pre trained model has 5 classes and when I have fine tuned my model with Detectron2
, it gives me results for all the 5 classes instead of my 1 class. The only problem is that I have 1 class while the pre trained model has 5 classes and when I have fine tuned my model with
Detectron2
, it gives me results for all the 5 classes instead of my 1 class. How can I deal with that scenario?我该如何处理这种情况?
This is the exact tutorial which I am following but instead of training my classes on all 5 classes as thing_classes= ['None','text', 'title', 'list', 'table', 'figure']
, I want to train just on one class as [ text
]. 这是我正在关注的确切教程,但我不想在所有 5 个类上训练我的课程
thing_classes= ['None','text', 'title', 'list', 'table', 'figure']
,我想要仅在一个 class 上训练为 [ text
]。 Author has answered but it did not help me as when I got the results during testing, I got results for all the 5 classes.作者已经回答了,但它对我没有帮助,因为当我在测试期间得到结果时,我得到了所有 5 个类的结果。
Pre-trained Model Weight Pre- trained Model Config 预训练 Model 权重预训练 Model 配置
I have put 'category_id'
of every instance as 0 (because I have just 1 class).我已将每个实例
'category_id'
设为 0 (因为我只有 1 个类)。
Below is the code where I have registered the data and everything and there is no problem with training, model trains well下面是我注册数据和所有内容的代码,训练没有问题,model 训练良好
from detectron2.config import get_cfg
from detectron2.engine import DefaultPredictor, DefaultTrainer
!wget -O ./faster_rcnn_R_50_FPN_3x.pth 'https://www.dropbox.com/s/dgy9c10wykk4lq4/model_final.pth?dl=1'
!wget -O ./faster_rcnn_R_50_FPN_3x.yaml 'https://www.dropbox.com/s/f3b12qc4hc0yh4m/config.yml?dl=1'
cfg = get_cfg()
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1 # Just one class predictions
cfg.merge_from_file("./faster_rcnn_R_50_FPN_3x.yaml")
cfg.MODEL.WEIGHTS= './faster_rcnn_R_50_FPN_3x.pth' # layout parser Pre trained weights
cfg.SOLVER.IMS_PER_BATCH = 4
cfg.SOLVER.BASE_LR = 0.0025
cfg.SOLVER.MAX_ITER = 50 #adjust up if val mAP is still rising, adjust down if overfit
cfg.SOLVER.GAMMA = 0.05
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 4
cfg.DATASETS.TRAIN = (Data_Resister_training,)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)
trainer.train()
Not sure if this will fix it, but try inverting the merge_from_file
call and the number of classes setting:不确定这是否会解决它,但尝试反转
merge_from_file
调用和类数设置:
cfg = get_cfg()
cfg.merge_from_file("./faster_rcnn_R_50_FPN_3x.yaml")
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1 # Just one class predictions
...
Maybe that parameter gets overwritten.也许该参数被覆盖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.