tusen-ai / simpledet

A Simple and Versatile Framework for Object Detection and Instance Recognition
Apache License 2.0
3.08k stars 488 forks source link

run create_voc_roidb.py #282

Open MTfast opened 4 years ago

MTfast commented 4 years ago

I want to train my own dataset using tridentnet. I convert my voc-format dataset to roidb and run create_voc_roidb.py the following error: Traceback (most recent call last): File "utils/create_voc_roidb.py", line 80, in create_roidb(*parse_args()) File "utils/create_voc_roidb.py", line 19, in parse_args with open(args.label_map) as f: FileNotFoundError: [Errno 2] No such file or directory: 'data/label_map/voc_label_map.json'

voc-format dataset don't have files in json format...

RogerChern commented 4 years ago

You may need a label map json file to map your classname to train id.

https://github.com/TuSimple/simpledet/blob/f67fca08b33d957b43eb1db5e3745a3a9e3803b5/utils/create_voc_roidb.py#L52

MTfast commented 4 years ago

What is the format of this json file?

RogerChern commented 4 years ago

Just plain kv pairs as { "category_name": train_id }

On Tue, Dec 24, 2019 at 9:23 AM MTfast notifications@github.com wrote:

What is the format of this json file?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/TuSimple/simpledet/issues/282?email_source=notifications&email_token=ABGODHZUTQVTDROHTJ26HLTQ2FP7VA5CNFSM4J6TPXYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHSHIFQ#issuecomment-568620054, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGODH37G6YMVBBMOJQMGS3Q2FP7VANCNFSM4J6TPXYA .

dongjuns commented 4 years ago

Hi, how can I make that voc_label_map.json? could you know that?

RogerChern commented 4 years ago

you can write it with any text editor

On Wed, Jun 10, 2020 at 7:03 PM dongjun notifications@github.com wrote:

Hi, how can I make that voc_label_map.json? could you know that?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/TuSimple/simpledet/issues/282#issuecomment-641928250, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGODH4Q4C7WCJKBKEPU4VDRV5R7BANCNFSM4J6TPXYA .

dongjuns commented 4 years ago

if someone just want it for clipart dataset, use this.

# voc_label_map.json
{"car": 1, "person": 2, "bicycle": 3, "boat": 4, "sheep": 5, "aeroplane": 6, "tvmonitor": 7, "chair": 8, "bottle": 9, "pottedplant": 10, "diningtable": 11, "train": 12, "dog": 13, "sofa": 14, "bus": 15, "bird": 16, "horse": 17, "motorbike": 18, "cat": 19, "cow": 20}

or here are some codes to make it,

import os
import json
import cv2

path = os.getcwd()
AnnotationsPath = os.listdir(os.path.join(path, "Annotations"))

from xml.etree.ElementTree import parse

words = []
for file in AnnotationsPath:
    tree = parse(os.path.join(path, "Annotations", file))
    root = tree.getroot() 
    objects = root.findall("object")
    names = [x.findtext("name") for x in objects]

    for name in names:
        if name not in words:
            words.append(name)

tempDictionary = {}
train_id = 1
for word in words:
    tempDictionary[word] = train_id
    train_id += 1

print(tempDictionary)
with open("voc_label_map.json", "w") as write_file:
    json.dump(tempDictionary, write_file)