youtubevos / MaskTrackRCNN

MaskTrackRCNN for video instance segmentation based on mmdetection
Apache License 2.0
431 stars 75 forks source link

How to evaluate a custom dataset #53

Closed hammerAttack closed 2 years ago

hammerAttack commented 2 years ago

I made a dataset about trees in the format of YouTube-vis dataset and trained it in masktrackrcnn. But I don't know how to evaluate the training results . can i evaluation in offical web?

lijoe123 commented 2 years ago

Hello? Could you please tell me how to make you own dataset in the format of youtubevis? Which software do you use?

hammerAttack commented 2 years ago

这需要自己编写脚本文件进行转换,我没有找到任何可以进行转换的软件或工具。 并且,如果使用私有数据集是无法进行结果评估的。

This requires writing your own script file to do the conversion, and I have not found any software or tool that can do it. And, it is not possible to evaluate the results using a private dataset.

hammerAttack commented 2 years ago

Hello? Could you please tell me how to make you own dataset in the format of youtubevis? Which software do you use?

lijoe123 commented 2 years ago

谢谢,我的意思是,你是用什么软件标注自己的数据集?

hammerAttack commented 2 years ago

。。。 labelme

lijoe123 commented 2 years ago

这个也可以标注视频的数据集吗

hammerAttack commented 2 years ago

yotube-vis数据集也是由分成组的连续帧组成的。

lijoe123 commented 2 years ago

谢谢谢谢,我找到了一个youtubevis to coco 的代码 https://github.com/open-mmlab/mmtracking/tree/master/tools/convert_datasets/youtubevis , 所以我想问的是用labelme可以生成youtubevis 格式的数据集?

hammerAttack commented 2 years ago

你需要把labelme格式的数据集转换为coco数据集格式,然后在从coco数据集转换为youtube-vis数据集格式。

lijoe123 commented 2 years ago

谢谢你,但是这也太麻烦了吧,请问你有coco 转换成youtube-vis 的脚本吗

hammerAttack commented 2 years ago

这只是私用的脚本,你需要根据你的实际情况进行修改。

import json
import os
import copy

# 文件夹按名称排序
def file_name_order(file_names, sort, import_path=''):
    '''

    :param file_names: 需要排序的序列
    :param sort: 0为文件夹,1为jpg文件,2为json文件,3为labelme2coco专用 4为fileOperation所有
    :return:
    '''
    # if sort == 0:
    #     for i in range(len(file_names)):
    #         file_names[i] = int(file_names[i])
    #     file_names.sort()
    #     for i in range(len(file_names)):
    #         file_names[i] = str(file_names[i])
    if sort == 1 or sort == 2 or sort==4:
        for i in range(len(file_names)):
            file_names[i] = int(file_names[i].split('.')[0])
        file_names = list(set(file_names))
        file_names.sort()
        for i in range(len(file_names)):
            if sort == 1:
                file_names[i] = "".join(("00000" + str(file_names[i]))[-5:] + '.jpg')
            if sort == 2:
                file_names[i] = "".join(("00000" + str(file_names[i]))[-5:] + '.json')
            if sort ==  4:
                file_names[i] = str(file_names[i])+ '.jpg'
        return file_names
    if sort == 3:
        for i in range(len(file_names)):
            # print(file_names[i].split('\\'))
            file_names[i] = int(file_names[i].split('\\')[8].split('.')[0])
        file_names.sort()
        for i in range(len(file_names)):
            file_names[i] = import_path + r'\\' + str(file_names[i]) + '.json'
        return file_names

# 目标数据集格式
VIS = {"info": {
    "description": "YouTube-VOS",
    "url": "https://youtube-vos.org/home",
    "version": "2.0",
    "year": 2021,
    "contributor": "ychfan",
    "date_created": "2021-02-12 19:17:02.937750"
},
    "licenses": [{
        "url": "https://creativecommons.org/licenses/by/4.0/",
        "id": 1,
        "name": "Creative Commons Attribution 4.0 License"
    }],
    "categories": [
        {  # 大类名称
            "supercategory": "object",
            # 类别索引
            "id": 1,
            # 类别名
            "name": "PeachLWA"
        }],
    "videos": [
    ],
    "annotations": [
    ]
}
# 标本
# 需要进行处理的地方为file_names与id
video = {
    "license": 1,
    "coco_url": "",
    "height": 1080,
    "width": 1920,
    "length": 20,
    "date_captured": "",
    "file_names": [],
    "flickr_url": "",
    "id": 0,
}
# 标本
# 需要修改segmentations bboxes areas video_id id
annotation = {
    "video_id": 1,
    "iscrowd": 0,
    "height": 720,
    "width": 1280,
    "length": 1,
    "segmentations": [
    ],
    "bboxes": [
    ],
    "category_id": 1,
    "id": 1,
    "areas": [],
}
segmentation = {
    "counts": [],
    "size": [1080, 1920]
}

def json_operation(folder_path, json_folder_path):
    folder_names = os.listdir(folder_path)  # 取出文件夹名称
    # file_name_order(folder_names, 0)  # 文件夹名称排序
    id = 1  # 视频ID annotation_id
    for folder_name in folder_names:
        video['id'] = id  # 录入视频id
        # 进入文件夹读取图片名称信息,
        image_paths = os.path.join(folder_path, folder_name)
        image_names = os.listdir(image_paths)
        image_names = file_name_order(image_names, 1)  # 文件名称排序
        # 文件路径的规范化
        for image_name in image_names:
            image_path = str(folder_name) + '/' + str(image_name)
            # print(image_path)
            video['file_names'].append(image_path)  # 录入文件路径
        VIS['videos'].append(copy.deepcopy(video))  # 添加到VIS数据集中
        # print(video)
        video['file_names'].clear()  # 需要清除数据

        # 读取json文件
        json_path = os.path.join(json_folder_path,  folder_name + ".json")  # json文件路径

        with open(json_path, "r") as fp:
            data = json.load(fp)
            # print(len(data['annotations']))
            annotation['video_id'] = id  # 对应的视频id
            annotation['id'] = id  #
            for data_seg in data['annotations']:
                # 将图片注释的信息传到segmentation中
                segmentation['counts'] = copy.deepcopy(data_seg['segmentation'][0])
                # print(segmentation)
                # 将segmentation中的信息添加到annotation
                annotation["segmentations"].append(copy.deepcopy(segmentation))
                segmentation['counts'].clear()
                # print(annotation['segmentations'])
                annotation["bboxes"].append(copy.deepcopy(data_seg["bbox"]))
                # print(annotation['bboxes'])
                annotation["areas"].append(copy.deepcopy(data_seg["area"]))
                # print(annotation['areas'])
            VIS["annotations"].append(copy.deepcopy(annotation))
            # print(VIS)
            annotation["segmentations"].clear()
            annotation["areas"].clear()
            annotation["bboxes"].clear()
            id += 1
    with open(r"E:\Asystem\Desktop\vis_example\valid\instances.json", "w") as f:
        json.dump(VIS, f)

if __name__ == "__main__":
    folder_path = r'E:\Asystem\Desktop\vis_example\valid\JPEGImages'  # 数据集路径
    json_folder_path = r'E:\Asystem\Desktop\vis_example\valid\annotations'  # json文件根路径
    json_operation(folder_path, json_folder_path)
Sherlock-hh commented 2 years ago

你好,我想跑这个数据集,但是我用的deepsort算法,它的output格式和masktrackrcnn的好像不大一样,但是我想把跑出来的结果整理成和这个一个格式的好传到那个cocolab上面,能麻烦你给我看一下你们最后跑出来的json格式吗?