Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

训练自己的数据集 #24

Closed
neowei1218 opened this issue Jan 20, 2021 · 2 comments
Closed

训练自己的数据集 #24

neowei1218 opened this issue Jan 20, 2021 · 2 comments

Comments

@neowei1218
Copy link

想请问一下我制作好了COCO格式的数据集,需要改写什么地方才能到自己数据集的路径,要怎么选择使用resnet18,抱歉我还是个菜鸟

@CPFLAME
Copy link
Collaborator

CPFLAME commented Jan 20, 2021

感谢使用centerX,没关系,大家都是从菜鸟起步的。

如果是标准的coco格式的话,建议直接调用detectron2的接口,在data/dataset/builting.py中添加的就可以

from detectron2.data import MetadataCatalog
from detectron2.data.datasets import register_coco_instances
register_coco_instances("my_dataset", {}, "json_annotation.json", "path/to/image/dir")
MetadataCatalog.get("my_dataset").thing_classes = ["person", "dog"]

如果是私人数据集,可以仿照data/dataset/crowd_human.py来添加私人数据集,私人数据集不限标准,只要最后的返回统一格式就可以了,然后在data/dataset/builting.py中register一下你的私人数据集,就可以训练了。

        instances = []

        for obj in anno['gtboxes']:
            cls = obj['tag']
            if cls != "person":
                continue
            bbox = obj['vbox']
            bbox = [float(x) for x in bbox]
            bbox[2] = bbox[0] + bbox[2]
            bbox[3] = bbox[1] + bbox[3]
            bbox[0] = max(bbox[0], 0.0)
            bbox[1] = max(bbox[1], 0.0)
            bbox[2] = min(bbox[2], float(w))
            bbox[3] = min(bbox[3], float(h))
            if bbox[2] - bbox[0] > 1.0 and bbox[3] - bbox[1] > 1.0:
                instances.append(
                    {"category_id": class_names.index(cls),
                     "bbox": bbox,
                     "bbox_mode": BoxMode.XYXY_ABS}
                )
        r["annotations"] = instances
        if len(instances) > 0:
            dicts.append(r)

centerX并没有对detectron2的数据注册方式进行修改,如果想知道详情可以参见detectron2的官方文档
点我

@neowei1218
Copy link
Author

我会再去试试看,你写得真是详细,谢谢你! !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants