Skip to content

load_hrsc loads all objects as ship, arguments classes is no use #62

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

Open
wang11wei opened this issue Oct 29, 2021 · 10 comments
Open

load_hrsc loads all objects as ship, arguments classes is no use #62

wang11wei opened this issue Oct 29, 2021 · 10 comments

Comments

@wang11wei
Copy link

def load_hrsc(img_dir, ann_dir, classes=None, img_keys=dict(), obj_keys=dict(), nproc=10):
    if classes is not None:
        print('load_hrsc loads all objects as ship, arguments classes is no use')

加载hrsc数据集,所有的图片的类名都是 ”ship“,这个怎么弄啊?

@jbwang1997
Copy link
Owner

现阶段HRSC2016数据集只是作为船只检测的数据集,舰船的型号是不会做区分的。大多数有向目标检测的论文也是这样处理的。

@wang11wei
Copy link
Author

现阶段HRSC2016数据集只是作为船只检测的数据集,舰船的型号是不会做区分的。大多数有向目标检测的论文也是这样处理的。

嗯嗯 好的

@Superfly12138
Copy link

请问如果我需要检测并验证其它的类别,不仅仅是ship类,我应该怎么更改参数呢?我尝试更改BboxToolkit/BboxToolkit/datasets/misc.py中的dataset_classes类别,将'HRSC': ('ship', ),更改为'HRSC': ('submarine','merchant ship','ship', ),但是好像并没起作用。请问其它还有地方需要更改吗?比如类别数目等?

@wang11wei
Copy link
Author

请问如果我需要检测并验证其它的类别,不仅仅是ship类,我应该怎么更改参数呢?我尝试更改BboxToolkit/BboxToolkit/datasets/misc.py中的dataset_classes类别,将'HRSC': ('ship', ),更改为'HRSC': ('submarine','merchant ship','ship', ),但是好像并没起作用。请问其它还有地方需要更改吗?比如类别数目等?

还有 hrscio.py 里面加载标签的部分需要修改:
根据需要加载你自己的标签,我是直接加载它自带的分类的

def _load_hrsc_xml(xmlfile, img_keys=dict(), obj_keys=dict()):
    hbboxes, bboxes, diffs, class_id = list(), list(), list(), list()
    content = {k: None for k in img_keys}
    ann = {k: [] for k in obj_keys}
    if xmlfile is None:
        pass
    elif not osp.isfile(xmlfile):
        print(f"Can't find {xmlfile}, treated as empty xmlfile")
    else:
        tree = ET.parse(xmlfile)
        root = tree.getroot()

        content['width'] = int(root.find('Img_SizeWidth').text)
        content['height'] = int(root.find('Img_SizeHeight').text)
        for k, xml_k in img_keys.items():
            node = root.find(xml_k)
            value = None if node is None else node.text
            content[k] = value

        objects = root.find('HRSC_Objects')
        for obj in objects.findall('HRSC_Object'):
            hbboxes.append([
                float(obj.find('box_xmin').text),
                float(obj.find('box_ymin').text),
                float(obj.find('box_xmax').text),
                float(obj.find('box_ymax').text)
            ])
            bboxes.append([
                float(obj.find('mbox_cx').text),
                float(obj.find('mbox_cy').text),
                float(obj.find('mbox_w').text),
                float(obj.find('mbox_h').text),
                -float(obj.find('mbox_ang').text)
            ])
            diffs.append(int(obj.find('difficult').text))
            class_id.append(int(obj.find('Class_ID').text[2:])-1)

            for k, xml_k in obj_keys.items():
                node = obj.find(xml_k)
                value = None if node is None else node.text
                ann[k].append(value)

    hbboxes = np.array(hbboxes, dtype=np.float32) if hbboxes \
        else np.zeros((0, 4), dtype=np.float32)
    bboxes = np.array(bboxes, dtype=np.float32) if bboxes \
        else np.zeros((0, 5), dtype=np.float32)
    diffs = np.array(diffs, dtype=np.int64) if diffs \
        else np.zeros((0,), dtype=np.int64)
    labels = np.array(class_id, dtype=np.int64) if class_id \
        else np.zeros((0,), dtype=np.int64)
    # labels = np.zeros((bboxes.shape[0],), dtype=np.int64)

    ann['hbboxes'] = hbboxes
    ann['bboxes'] = bboxes
    ann['diffs'] = diffs
    ann['labels'] = labels
    content['ann'] = ann
    return content

@jbwang1997
Copy link
Owner

可以先对照上面的答复进行修改,之后我将对HRSCio进行修改

@jbwang1997 jbwang1997 pinned this issue Nov 16, 2021
@Superfly12138
Copy link

照上面的答复进

请问对hrsc数据集的处理是把所有的类别都当作ship类吗?都打上label = 0?如果我只想训练数据集的某几个类呢?这个HRSCio我其实没太看懂怎么处理的。谢谢

@wang11wei
Copy link
Author

请问对hrsc数据集的处理是把所有的类别都当作ship类吗?都打上label = 0?如果我只想训练数据集的某几个类呢?这个HRSCio我其实没太看懂怎么处理的。谢谢

你似乎连我贴出来的代码都没有读完?!
你似乎连你要使用的数据集都没搞明白它的标签在哪或是应该是什么样子的?!

@Superfly12138
Copy link

请问对hrsc数据集的处理是把所有的类别都当作ship类吗?都打上label = 0?如果我只想训练数据集的某几个类呢?这个HRSCio我其实没太看懂怎么处理的。谢谢

你似乎连我贴出来的代码都没有读完?! 你似乎连你要使用的数据集都没搞明白它的标签在哪或是应该是什么样子的?!

不好意思,你的代码已经正在尝试了,再等待训练结果出来。

@Superfly12138
Copy link

请问如果我需要检测并验证其它的类别,不仅仅是ship类,我应该怎么更改参数呢?我尝试更改BboxToolkit/BboxToolkit/datasets/misc.py中的dataset_classes类别,将'HRSC': ('ship', ),更改为'HRSC': ('submarine','merchant ship','ship', ),但是好像并没起作用。请问其它还有地方需要更改吗?比如类别数目等?

还有 hrscio.py 里面加载标签的部分需要修改: 根据需要加载你自己的标签,我是直接加载它自带的分类的

def _load_hrsc_xml(xmlfile, img_keys=dict(), obj_keys=dict()):
    hbboxes, bboxes, diffs, class_id = list(), list(), list(), list()
    content = {k: None for k in img_keys}
    ann = {k: [] for k in obj_keys}
    if xmlfile is None:
        pass
    elif not osp.isfile(xmlfile):
        print(f"Can't find {xmlfile}, treated as empty xmlfile")
    else:
        tree = ET.parse(xmlfile)
        root = tree.getroot()

        content['width'] = int(root.find('Img_SizeWidth').text)
        content['height'] = int(root.find('Img_SizeHeight').text)
        for k, xml_k in img_keys.items():
            node = root.find(xml_k)
            value = None if node is None else node.text
            content[k] = value

        objects = root.find('HRSC_Objects')
        for obj in objects.findall('HRSC_Object'):
            hbboxes.append([
                float(obj.find('box_xmin').text),
                float(obj.find('box_ymin').text),
                float(obj.find('box_xmax').text),
                float(obj.find('box_ymax').text)
            ])
            bboxes.append([
                float(obj.find('mbox_cx').text),
                float(obj.find('mbox_cy').text),
                float(obj.find('mbox_w').text),
                float(obj.find('mbox_h').text),
                -float(obj.find('mbox_ang').text)
            ])
            diffs.append(int(obj.find('difficult').text))
            class_id.append(int(obj.find('Class_ID').text[2:])-1)

            for k, xml_k in obj_keys.items():
                node = obj.find(xml_k)
                value = None if node is None else node.text
                ann[k].append(value)

    hbboxes = np.array(hbboxes, dtype=np.float32) if hbboxes \
        else np.zeros((0, 4), dtype=np.float32)
    bboxes = np.array(bboxes, dtype=np.float32) if bboxes \
        else np.zeros((0, 5), dtype=np.float32)
    diffs = np.array(diffs, dtype=np.int64) if diffs \
        else np.zeros((0,), dtype=np.int64)
    labels = np.array(class_id, dtype=np.int64) if class_id \
        else np.zeros((0,), dtype=np.int64)
    # labels = np.zeros((bboxes.shape[0],), dtype=np.int64)

    ann['hbboxes'] = hbboxes
    ann['bboxes'] = bboxes
    ann['diffs'] = diffs
    ann['labels'] = labels
    content['ann'] = ann
    return content

我使用这个代码,将0~32作为训练的类别名,同时我将BboxToolkit/BboxToolkit/datasets/misc.py中的dataset_classes类别,改为
···
'HRSC': ('0','1','2','3','4','5','6','7','8','9','10','11','12',
'13','14','15','16','17','18','19','20','21','22','23','24','25',
'26','27','28','29','30','31','32'),
···
我训练了18个epoch,下面是我的测试结果:
截屏2021-11-16 下午8 16 49

@Superfly12138
Copy link

从上边的测试结果看出,由于测试的数据并没包含全部类。我针对性的选取了gt数较多的7个类,使用oriented-rcnn算法训练36个epoch,效果看起来还不错。
image

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

3 participants