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

【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集

這篇具有很好參考價值的文章主要介紹了【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、數(shù)據(jù)集準備

數(shù)據(jù)集下載地址:https://github.com/YimianDai/sirst

1. 需要將數(shù)據(jù)集轉(zhuǎn)換為YOLO所需要的txt格式

參考鏈接:https://github.com/pprp/voc2007_for_yolo_torch

1.1 檢測圖片及其xml文件

import os, shutil

def checkPngXml(dir1, dir2, dir3, is_move=True):
    """
    dir1 是圖片所在文件夾
    dir2 是標注文件所在文件夾
    dir3 是創(chuàng)建的,如果圖片沒有對應(yīng)的xml文件,那就將圖片放入dir3
    is_move 是確認是否進行移動,否則只進行打印
    """
    if not os.path.exists(dir3):
        os.mkdir(dir3)
    cnt = 0
    for file in os.listdir(dir1):
        f_name,f_ext = file.split(".")
        if not os.path.exists(os.path.join(dir2, f_name+".xml")):
            print(f_name)
            if is_move:
                cnt += 1
                shutil.move(os.path.join(dir1,file), os.path.join(dir3, file))
    if cnt > 0:
        print("有%d個文件不符合要求,已打印。"%(cnt))
    else:
        print("所有圖片和對應(yīng)的xml文件都是一一對應(yīng)的。")

if __name__ == "__main__":
    dir1 = r"dataset/images/images"   # 修改為自己的圖片路徑
    dir2 = r"dataset/masks/masks"     # 修改為自己的圖片路徑
    dir3 = r"dataset/Allempty"        # 修改為自己的圖片路徑
    checkPngXml(dir1, dir2, dir3, False)

1.2 劃分訓(xùn)練集

import os
import random
import os, fnmatch
 

trainval_percent = 0.8
train_percent = 0.8

xmlfilepath = r"dataset/masks/masks"
txtsavepath = r"dataset"
total_xml = fnmatch.filter(os.listdir(xmlfilepath), '*.xml')
print(total_xml)

num=len(total_xml)
list=range(num)
tv=int(num*trainval_percent)
tr=int(tv*train_percent)
trainval= random.sample(list,tv)
train=random.sample(trainval,tr)

ftrainval = open('dataset/trainval.txt', 'w')
ftest = open('dataset/test.txt', 'w')
ftrain = open('dataset/train.txt', 'w')
fval = open('dataset/val.txt', 'w')

for i  in list:
    name=total_xml[i][:-4]+'\n'
    if i in trainval:
        ftrainval.write(name)
        if i in train:
            ftrain.write(name)
        else:
            fval.write(name)
    else:
        ftest.write(name)

ftrainval.close()
ftrain.close()
fval.close()
ftest.close()

1.3?轉(zhuǎn)為txt標簽

# -*- coding: utf-8 -*-
"""
需要修改的地方:
1. sets中替換為自己的數(shù)據(jù)集
2. classes中替換為自己的類別
3. 將本文件放到VOC2007目錄下
4. 直接開始運行
"""

import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
sets=[('2007', 'train'), ('2007', 'val'), ('2007', 'test')]  #替換為自己的數(shù)據(jù)集
classes = ["Target"]     #修改為自己的類別

def convert(size, box):
    dw = 1./(size[0])
    dh = 1./(size[1])
    x = (box[0] + box[1])/2.0
    y = (box[2] + box[3])/2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

def convert_annotation(year, image_id):
    in_file = open('dataset/masks/masks/%s.xml'%(image_id))  #將數(shù)據(jù)集放于當前目錄下
    out_file = open('dataset/labels/%s.txt'%(image_id), 'w')
    tree=ET.parse(in_file)
    root = tree.getroot()
    size = root.find('size')
    w = int(size.find('width').text)
    h = int(size.find('height').text)
    print(w,h)
    for obj in root.iter('object'):
        difficult = obj.find('difficult').text
        cls = obj.find('name').text
        if cls not in classes or int(difficult)==1:
            continue
        cls_id = classes.index(cls)
        print(cls_id)
        xmlbox = obj.find('bndbox')
        b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
        bb = convert((w,h), b)
        print(bb)
        out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
wd = getcwd()
for year, image_set in sets:
    if not os.path.exists('dataset/labels/'):
        os.makedirs('dataset/labels/')
    image_ids = open('dataset/%s.txt'%(image_set)).read().strip().split()
    list_file = open('%s_%s.txt'%(year, image_set), 'w')
    for image_id in image_ids:
        list_file.write('dataset/images/images/%s.png\n'%(image_id))
        convert_annotation(year, image_id)
    list_file.close()
# os.system("cat 2007_train.txt 2007_val.txt > train.txt")     #修改為自己的數(shù)據(jù)集用作訓(xùn)練

1.4 構(gòu)造數(shù)據(jù)集

import os, shutil

"""
需要滿足以下條件:
1. 在JPEGImages中準備好圖片
2. 在labels中準備好labels
3. 創(chuàng)建好如下所示的文件目錄:
    - images
        - train2014
        - val2014
    - labels(由于voc格式中有l(wèi)abels文件夾,所以重命名為label)
        - train2014
        - val2014
"""


def make_for_torch_yolov3(dir_image,
                                 dir_label,
                                 dir1_train,
                                 dir1_val,
                                 dir2_train,
                                 dir2_val,
                                 main_trainval,
                                 main_test):
    if not os.path.exists(dir1_train):
        os.mkdir(dir1_train)
    if not os.path.exists(dir1_val):
        os.mkdir(dir1_val)
    if not os.path.exists(dir2_train):
        os.mkdir(dir2_train)
    if not os.path.exists(dir2_val):
        os.mkdir(dir2_val)

    with open(main_trainval, "r") as f1:
        for line in f1:
            print(line[:-1])
            # print(os.path.join(dir_image, line[:-1]+".png"), os.path.join(dir1_train, line[:-1]+".png"))
            shutil.copy(os.path.join(dir_image, line[:-1]+".png"),
                        os.path.join(dir1_train, line[:-1]+".png"))
            shutil.copy(os.path.join(dir_label, line[:-1]+".txt"),
                        os.path.join(dir2_train, line[:-1]+".txt"))


    with open(main_test, "r") as f2:
        for line in f2:
            print(line[:-1])
            shutil.copy(os.path.join(dir_image, line[:-1]+".png"),
                        os.path.join(dir1_val, line[:-1]+".png"))
            shutil.copy(os.path.join(dir_label, line[:-1]+".txt"),
                        os.path.join(dir2_val, line[:-1]+".txt"))

if __name__ == "__main__":
    '''
    https://github.com/ultralytics/yolov3
    這個pytorch版本的數(shù)據(jù)集組織
    - images
        - train2014 # dir1_train
        - val2014 # dir1_val
    - labels
        - train2014 # dir2_train
        - val2014 # dir2_val
    trainval.txt, test.txt 是由create_main.py構(gòu)建的
    '''

    dir_image = r"dataset/images/images"
    dir_label = r"dataset/labels"

    dir1_train = r"dataset/image/train2014"
    dir1_val = r"dataset/image/val2014"

    dir2_train = r"dataset/label/train2014"
    dir2_val = r"dataset/label/val2014"

    main_trainval = r"dataset/trainval.txt"
    main_test = r"dataset/test.txt"

    make_for_torch_yolov3(dir_image,
                            dir_label,
                            dir1_train,
                            dir1_val,
                            dir2_train,
                            dir2_val,
                            main_trainval,
                            main_test)

最終數(shù)據(jù)集格式如下:

【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集

?2. 構(gòu)造訓(xùn)練所需要的數(shù)據(jù)集

根據(jù)以上數(shù)據(jù)集 需要單獨構(gòu)建一個datasets文件夾,存放標簽和圖像,具體格式如下:

【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集

可以參考該鏈接:https://github.com/ultralytics/yolov5/issues/7389

3. 構(gòu)建數(shù)據(jù)配置文檔,需要注意 YOLOv5目錄需要和datasets目錄同級。

命名為hongwai.yaml

# YOLOv3 ?? by Ultralytics, AGPL-3.0 license
# COCO 2017 dataset http://cocodataset.org by Microsoft
# Example usage: python train.py --data coco.yaml
# parent
# ├── yolov5
# └── datasets
#     └── coco  ← downloads here (20.1 GB)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco # dataset root dir
train: images/train2014  # train images (relative to 'path') 118287 images
val: images/val2014  # val images (relative to 'path') 5000 images
test: images/val2014  # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794

# Classes
nc: 1
names:
  0: Target

?二、矩池云配置環(huán)境

1. 租用環(huán)境

【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集

?2、?配置環(huán)境,缺啥配啥,耐心解決問題

參考命令:

git clone https://github.com/ultralytics/yolov3.git
cd yolov3
pip install -r requirements.txt

也許訓(xùn)練過程中還會報錯找不到module,根據(jù)module名字,使用pip安裝即可

三、訓(xùn)練

YOLOv5訓(xùn)練命令:

python train.py --data data/hongwai.yaml --weights '' --cfg yolov5s.yaml --img 640 --device 0

YOLOv3訓(xùn)練命令:

python train.py --data data/hongwai.yaml --weights '' --cfg yolov3.yaml --img 640 --device 0

訓(xùn)練結(jié)果部分展示:

【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集

【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集?

?文章來源地址http://www.zghlxwxcb.cn/news/detail-473503.html

?四、文件夾檢測

執(zhí)行命令:

python detect.py --weights runs/train/exp10/weights/best.pt --source dataset/image/val2014

結(jié)果保存位置:?

【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集

?【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集

【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集

?

【創(chuàng)造不易,需要指導(dǎo)做該項目的可以聯(lián)系】

?

到了這里,關(guān)于【矩池云】YOLOv3~YOLOv5訓(xùn)練紅外小目標數(shù)據(jù)集的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • 【Yolov5+Deepsort】訓(xùn)練自己的數(shù)據(jù)集(3)| 目標檢測&追蹤 | 軌跡繪制 | 報錯分析&解決

    【Yolov5+Deepsort】訓(xùn)練自己的數(shù)據(jù)集(3)| 目標檢測&追蹤 | 軌跡繪制 | 報錯分析&解決

    ??前言: 本篇是關(guān)于 如何使用YoloV5+Deepsort訓(xùn)練自己的數(shù)據(jù)集 ,從而實現(xiàn)目標檢測與目標追蹤,并繪制出物體的運動軌跡。本章講解的為第三部分內(nèi)容:數(shù)據(jù)集的制作、Deepsort模型的訓(xùn)練以及動物運動軌跡的繪制。本文中用到的數(shù)據(jù)集均為自采,實驗動物為斑馬魚。 ??環(huán)境

    2024年02月10日
    瀏覽(26)
  • 目標檢測 YOLOv5 預(yù)訓(xùn)練模型下載方法

    目標檢測 YOLOv5 預(yù)訓(xùn)練模型下載方法

    目標檢測 YOLOv5 預(yù)訓(xùn)練模型下載方法 flyfish https://github.com/ultralytics/yolov5 https://github.com/ultralytics/yolov5/releases 可以選擇自己需要的版本和不同任務(wù)類型的模型 后綴名是pt

    2024年02月08日
    瀏覽(30)
  • 【目標檢測】YOLOv5算法實現(xiàn)(七):模型訓(xùn)練

    【目標檢測】YOLOv5算法實現(xiàn)(七):模型訓(xùn)練

    ??本系列文章記錄本人碩士階段YOLO系列目標檢測算法自學(xué)及其代碼實現(xiàn)的過程。其中算法具體實現(xiàn)借鑒于ultralytics YOLO源碼Github,刪減了源碼中部分內(nèi)容,滿足個人科研需求。 ??本系列文章主要以YOLOv5為例完成算法的實現(xiàn),后續(xù)修改、增加相關(guān)模塊即可實現(xiàn)其他版本的

    2024年01月22日
    瀏覽(37)
  • YoloV5+ECVBlock:基于YoloV5-ECVBlock的小目標檢測訓(xùn)練

    YoloV5+ECVBlock:基于YoloV5-ECVBlock的小目標檢測訓(xùn)練

    目錄 1、前言 2、數(shù)據(jù)集 3、添加ECVBlock ?4、BackBone+ECVBlock 5、Head+ECVBlock 6、訓(xùn)練結(jié)果 6.1 Backbone 6.2 Head ? 視覺特征金字塔在廣泛的應(yīng)用中顯示出其有效性和效率的優(yōu)越性。然而,現(xiàn)有的方法過分地集中于層間特征交互,而忽略了層內(nèi)特征規(guī)則,這是經(jīng)驗證明是有益的。盡管一些

    2024年02月05日
    瀏覽(39)
  • 基于YOLOv5 來訓(xùn)練頭盔目標檢測-附源碼

    建筑工地頭部頭盔檢測,基于目標檢測工地安全帽和禁入危險區(qū)域識別系統(tǒng),????附Y(jié)OLOv5訓(xùn)練自己的數(shù)據(jù)集超詳細教程?。?! 目錄 指標 yolov5s 為基礎(chǔ)訓(xùn)練,epoch = 50 yolov5m 為基礎(chǔ)訓(xùn)練,epoch = 100

    2024年02月13日
    瀏覽(23)
  • 目標檢測算法(R-CNN,fast R-CNN,faster R-CNN,yolo,SSD,yoloV2,yoloV3,yoloV4,yoloV5,yoloV6,yoloV7)

    目標檢測算法(R-CNN,fast R-CNN,faster R-CNN,yolo,SSD,yoloV2,yoloV3,yoloV4,yoloV5,yoloV6,yoloV7)

    深度學(xué)習(xí)目前已經(jīng)應(yīng)用到了各個領(lǐng)域,應(yīng)用場景大體分為三類:物體識別,目標檢測,自然語言處理。 目標檢測可以理解為是物體識別和物體定位的綜合 ,不僅僅要識別出物體屬于哪個分類,更重要的是得到物體在圖片中的具體位置。 為了完成這兩個任務(wù),目標檢測模型分

    2024年02月02日
    瀏覽(26)
  • yolov5汽車檢測linux字符界面操作全流程,適合上手(含數(shù)據(jù)集近700張圖片8000多個目標+訓(xùn)練好的模型)

    yolov5汽車檢測linux字符界面操作全流程,適合上手(含數(shù)據(jù)集近700張圖片8000多個目標+訓(xùn)練好的模型)

    隨著自動駕駛技術(shù)的不斷發(fā)展,汽車目標檢測成為了研究的熱點。本文將介紹公開+自定義的yolov5汽車目標檢測數(shù)據(jù)集以及用linux操作系統(tǒng)訓(xùn)練yolov5。 先展示一下推理結(jié)果: ?GPU在13.2ms每幀,基本滿足項目需要。 前段時間跟朋友一起整理了一個汽車目標的數(shù)據(jù)集,主要包括

    2024年02月03日
    瀏覽(47)
  • 【計算機視覺】目標檢測—yolov5自定義模型的訓(xùn)練以及加載

    【計算機視覺】目標檢測—yolov5自定義模型的訓(xùn)練以及加載

    目標檢測是計算機視覺主要應(yīng)用方向之一。目標檢測通常包括兩方面的工作,首先是招到目標,然后就是識別目標。目標檢測可以分為單物體檢測和多物體檢測。常用的目標檢測方法分為兩大流派:一步走(one_stage)算法:直接對輸入的圖像應(yīng)用算法并輸出類別和相應(yīng)的定位

    2024年02月01日
    瀏覽(28)
  • 【pytorch】目標檢測:一文搞懂如何利用kaggle訓(xùn)練yolov5模型

    【pytorch】目標檢測:一文搞懂如何利用kaggle訓(xùn)練yolov5模型

    筆者的運行環(huán)境:python3.8+pytorch2.0.1+pycharm+kaggle。 yolov5對python和pytorch版本是有要求的,python=3.8,pytorch=1.6。yolov5共有5種類型nslmx,參數(shù)量依次遞增,對訓(xùn)練設(shè)備的要求也是遞增。本文以yolov5_6s為切入點,探究yolov5如何在實戰(zhàn)種運用。 roboflow是一個公開數(shù)據(jù)集網(wǎng)站,里面有很

    2024年02月12日
    瀏覽(32)
  • YOLOV3 SPP 目標檢測項目(針對xml或者yolo標注的自定義數(shù)據(jù)集)

    YOLOV3 SPP 目標檢測項目(針對xml或者yolo標注的自定義數(shù)據(jù)集)

    項目下載地址:YOLOV3 SPP網(wǎng)絡(luò)對自定義數(shù)據(jù)集的目標檢測(標注方式包括xml或者yolo格式) 目標檢測邊界框的表現(xiàn)形式有兩種: YOLO(txt) : 第一個為類別,后面四個為邊界框,x,y中心點坐標以及h,w的相對值 ?xml文件:類似于網(wǎng)頁的標注文件,里面會存放圖像名稱、高度寬度信息

    2024年02月04日
    瀏覽(30)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包