国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

偽裝目標(biāo)檢測(cè)中數(shù)據(jù)集的標(biāo)注格式:COCO和VOC

這篇具有很好參考價(jià)值的文章主要介紹了偽裝目標(biāo)檢測(cè)中數(shù)據(jù)集的標(biāo)注格式:COCO和VOC。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

1.OSFormer中提供的COD10K的json格式,是coco的格式,但由于偽裝目標(biāo)檢測(cè)任務(wù)的特殊性,標(biāo)注信息中還有一個(gè)segmentation段

 "images": [
        {
            "id": 3039,
            "file_name": "COD10K-CAM-1-Aquatic-1-BatFish-3.jpg",
            "width": 800,
            "height": 533,
            "date_captured": "2020-08-21 01:23:18.643991",
            "license": 1,
            "url": ""
        }
    ],
    "categories": [
        {
            "id": 1,
            "name": "foreground",
            "supercategory": "saliency"
        }
    ],
    "annotations": [
        {
            "id": 3533,
            "image_id": 3039,
            "category_id": 1,
            "iscrowd": 0,
            "area": 104946,
            "bbox": [
                96.0,
                60.0,
                544.0,
                431.0
            ],
            "segmentation": [
                [
                    513.0,
                    490.9980392156863,
                    505.0,
                    490.9980392156863,
                    469.0,
                    476.9980392156863,
                    459.0,
                    479.9980392156863,
                    450.0,
                    471.9980392156863,
                    442.0,
                    472.9980392156863,
                    439.0,
                    467.9980392156863,
                    434.0,
                    477.9980392156863,
                    428.0,
                    467.9980392156863,
                    427.9980392156863,
                    473.0,
                    424.0,
                    475.9980392156863,

首先將一整個(gè)json文件分解:

from __future__ import print_function
import json
json_file='D:/projects/SINet-V2-main/json/train_instance.json' #
# Object Instance 類(lèi)型的標(biāo)注
# person_keypoints_val2017.json
# Object Keypoint 類(lèi)型的標(biāo)注格式
# captions_val2017.json
# Image Caption的標(biāo)注格式
data=json.load(open(json_file,'r'))
data_2={}
# da ta_2['info']=data['info']
# data_2['licenses']=data['licenses']
for i in range(3040): # 一共234張圖片

    data_2['images']=[data['images'][i]] # 只提取第i張圖片
    data_2['categories']=data['categories']
    annotation=[] # 通過(guò)imgID 找到其所有對(duì)象
    imgID=data_2['images'][0]['id']
    for ann in data['annotations']:
        if ann['image_id']==imgID:
            annotation.append(ann)
    data_2['annotations']=annotation # 保存到新的JSON文件,便于查看數(shù)據(jù)特點(diǎn)
    savepath = 'D:/projects/SINet-V2-main/json/single/' + data_2['images'][0]['file_name']+ '.json'
    json.dump(data_2,open(savepath,'w'),indent=4) # indent=4 更加美觀顯示

然后轉(zhuǎn)化為VOC格式:

import os
import numpy as np
import codecs
import json
from glob import glob
import cv2
import shutil
from sklearn.model_selection import train_test_split

# 1.存放的json標(biāo)簽路徑
labelme_path = "D:/projects/SINet-V2-main/json/single/"

# 原始labelme標(biāo)注數(shù)據(jù)路徑
saved_path = "D:/projects/SINet-V2-main/json/COD10K-voc/"
# 保存路徑
isUseTest = None  # 是否創(chuàng)建test集

# 2.創(chuàng)建要求文件夾
if not os.path.exists(saved_path + "Annotations"):
    os.makedirs(saved_path + "Annotations")
if not os.path.exists(saved_path + "JPEGImages/"):
    os.makedirs(saved_path + "JPEGImages/")
if not os.path.exists(saved_path + "ImageSets/Main/"):
    os.makedirs(saved_path + "ImageSets/Main/")

# 3.獲取待處理文件
files = glob(labelme_path + "*.json")
files = [i.replace("\\", "/").split("/")[-1].split(".json")[0] for i in files]
print(files)

# 4.讀取標(biāo)注信息并寫(xiě)入 xml
for json_file_ in files:
    json_filename = labelme_path + json_file_ + ".json"
    json_file = json.load(open(json_filename, "r", encoding="utf-8"))

    height, width, channels = cv2.imread('D:/projects/SINet-V2-main/json/dataset/image/' + json_file_).shape
    with codecs.open(saved_path + "Annotations/" + json_file_ + ".xml", "w", "utf-8") as xml:

        xml.write('<annotation>\n')
        xml.write('\t<folder>' + 'CELL_data' + '</folder>\n')
        xml.write('\t<filename>' + json_file_  + '</filename>\n')
        xml.write('\t<source>\n')
        xml.write('\t\t<database>CELL Data</database>\n')
        xml.write('\t\t<annotation>CELL</annotation>\n')
        xml.write('\t\t<image>bloodcell</image>\n')
        xml.write('\t\t<flickrid>NULL</flickrid>\n')
        xml.write('\t</source>\n')
        xml.write('\t<owner>\n')
        xml.write('\t\t<flickrid>NULL</flickrid>\n')
        xml.write('\t\t<name>CELL</name>\n')
        xml.write('\t</owner>\n')
        xml.write('\t<size>\n')
        xml.write('\t\t<width>' + str(width) + '</width>\n')
        xml.write('\t\t<height>' + str(height) + '</height>\n')
        xml.write('\t\t<depth>' + str(channels) + '</depth>\n')
        xml.write('\t</size>\n')
        xml.write('\t\t<segmented>0</segmented>\n')# 是否用于分割(在圖像物體識(shí)別中01無(wú)所謂)
        cName = json_file["categories"]
        Name = cName[0]["name"]
        print(Name)
        for multi in json_file["annotations"]:
            points = np.array(multi["bbox"])
            labelName = Name
            xmin = points[0]
            xmax = points[0]+points[2]
            ymin = points[1]
            ymax = points[1]+points[3]
            label = Name
            if xmax <= xmin:
                pass
            elif ymax <= ymin:
                pass
            else:
                xml.write('\t<object>\n')
                xml.write('\t\t<name>' + labelName + '</name>\n')# 物體類(lèi)別
                xml.write('\t\t<pose>Unspecified</pose>\n')# 拍攝角度
                xml.write('\t\t<truncated>0</truncated>\n')# 是否被截?cái)啵?表示完整)
                xml.write('\t\t<difficult>0</difficult>\n')# 目標(biāo)是否難以識(shí)別(0表示容易識(shí)別)
                xml.write('\t\t<bndbox>\n')
                xml.write('\t\t\t<xmin>' + str(int(xmin)) + '</xmin>\n')
                xml.write('\t\t\t<ymin>' + str(int(ymin)) + '</ymin>\n')
                xml.write('\t\t\t<xmax>' + str(int(xmax)) + '</xmax>\n')
                xml.write('\t\t\t<ymax>' + str(int(ymax)) + '</ymax>\n')
                xml.write('\t\t</bndbox>\n')
                xml.write('\t</object>\n')
                print(json_filename, xmin, ymin, xmax, ymax, label)
        xml.write('</annotation>')

# 5.復(fù)制圖片到 VOC2007/JPEGImages/下
image_files = glob("labelmedataset/images/" + "*.jpg")
print("copy image files to VOC007/JPEGImages/")
for image in image_files:
    shutil.copy(image, saved_path + "JPEGImages/")

# 6.拆分訓(xùn)練集、測(cè)試集、驗(yàn)證集
txtsavepath = saved_path + "ImageSets/Main/"
ftrainval = open(txtsavepath + '/trainval.txt', 'w')
ftest = open(txtsavepath + '/test.txt', 'w')
ftrain = open(txtsavepath + '/train.txt', 'w')
fval = open(txtsavepath + '/val.txt', 'w')
total_files = glob("./VOC2007/Annotations/*.xml")
total_files = [i.replace("\\", "/").split("/")[-1].split(".xml")[0] for i in total_files]
trainval_files = []
test_files = []
if isUseTest:
    trainval_files, test_files = train_test_split(total_files, test_size=0.15, random_state=55)
else:
    trainval_files = total_files
for file in trainval_files:
    ftrainval.write(file + "\n")

# split
train_files, val_files = train_test_split(trainval_files, test_size=0.15, random_state=55)

# train
for file in train_files:
    ftrain.write(file + "\n")

# val
for file in val_files:
    print(file)
    fval.write(file + "\n")
for file in test_files:
    print("test:"+file)
    ftest.write(file + "\n")
ftrainval.close()
ftrain.close()
fval.close()
ftest.close()



這樣生成的xml文件,沒(méi)有之前COD10K標(biāo)注的segmentation信息,還需要進(jìn)一步考慮,在轉(zhuǎn)換為xml的腳本中加上識(shí)別segmentation部分。
參考博客:https://blog.csdn.net/ytusdc/article/details/1319729224
https://blog.csdn.net/xjx19991226/article/details/123386207文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-859867.html

到了這里,關(guān)于偽裝目標(biāo)檢測(cè)中數(shù)據(jù)集的標(biāo)注格式:COCO和VOC的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包