简体   繁体   English

如何使用 Detectron2 为自定义数据和类微调 object 检测 model?

[英]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.

相关问题 如何微调tensorflow对象检测api模型? - how to fine tune the tensorflow object detection api model? 如何使用 keras 正确微调 model? - How to correctly fine tune a model using keras? 如何使用TensorFlow中的fine_tune_checkpoint Object检测API - How to use the fine_tune_checkpoint in TensorFlow Object Detection API 如何在具有不同类的数据集上微调模型? - How do I fine tune a model on a dataset with different classes? 如何使用现有的和更新的类微调 keras model? - How to fine-tune a keras model with existing plus newer classes? 使用Tensorflow对象检测API来微调mask_rcnn_inception_resnet_v2_atrous_coco模型时断言失败错误 - assertion failed error when using tensorflow object detection API to fine tune the mask_rcnn_inception_resnet_v2_atrous_coco model 关于使用 Tensor Flow Custom Object 检测微调 model 以增加具有附加数据的类数量的问题 - Question about finetuning model to increase number of classes w/additional data using Tensor Flow Custom Object Detection TensorFlow 对象检测 API 微调检查点 - TensorFlow object detection API fine tune checkpoint Tensorflow object_detection 保存和加载微调的正确方式 model - Tensorflow object_detection correct way to save and load fine tune model 如何使用`MonitoredTrainingSession` /`Scaffold`微调模型 - How to fine-tune model using `MonitoredTrainingSession` / `Scaffold`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM