我试图用detectron 2训练我自己的COCO数据集,但是当我开始自己的训练时,我遇到了一个关键错误
KeyError:'类别_id
error code : https://i.stack.imgur.com/yO5IO.png
//this is the code i am training with
from detectron2.engine import DefaultTrainer
from detectron2.config import get_cfg
import os
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-
InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.DATASETS.TRAIN = ("coco_train_new",)
cfg.DATASETS.TEST = ()
cfg.DATALOADER.NUM_WORKERS = 2
cfg.MODEL.WEIGHTS = "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl"
cfg.SOLVER.IMS_PER_BATCH = 2
cfg.SOLVER.BASE_LR = 0.00025 # pick a good LR
cfg.SOLVER.MAX_ITER = 1000 # 300 iterations seems good enough for this toy dataset; you may need to train longer for a practical dataset
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 512 # faster, and good enough for this toy dataset (default: 512)
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1 # only has one class (ballon)
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)
trainer.train()
字符串
所以我回去检查我的COCO json文件,但是json文件是用标准COCO格式输出的,有什么想法可能会导致问题吗
p.s我正在用detectron2示例代码训练数据,所以我认为应该没有问题
2条答案
按热度按时间qni6mghb1#
我猜(没有看你的json构造代码)你在注解中缺少了'category_id'。你可以按照下面的方法来创建一个类。
字符串
希望你明白了。
sauutmhj2#
以防万一..