国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

網(wǎng)站默認(rèn)首頁(yè)友鏈購(gòu)買(mǎi)網(wǎng)

網(wǎng)站默認(rèn)首頁(yè),友鏈購(gòu)買(mǎi)網(wǎng),數(shù)據(jù)處理網(wǎng)站開(kāi)發(fā),青島公路建設(shè)集團(tuán)有限公司網(wǎng)站之前復(fù)現(xiàn)的yolov3算法采用的是傳統(tǒng)的coco數(shù)據(jù)集,這里我需要在新的數(shù)據(jù)集上跑,也就是船舶檢測(cè)方向的SeaShips數(shù)據(jù)集,這里給出教程。 Seaships論文鏈接:https://ieeexplore.ieee.org/stamp/stamp.jsp?tp&arnumber8438999 一、…

之前復(fù)現(xiàn)的yolov3算法采用的是傳統(tǒng)的coco數(shù)據(jù)集,這里我需要在新的數(shù)據(jù)集上跑,也就是船舶檢測(cè)方向的SeaShips數(shù)據(jù)集,這里給出教程。

Seaships論文鏈接:https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8438999

一、數(shù)據(jù)集下載

可以去官網(wǎng)下載或者直接點(diǎn)擊鏈接下載:

Seaships官網(wǎng):https://github.com/jiaming-wang/SeaShips

下載鏈接:http://www.lmars.whu.edu.cn/prof_web/shaozhenfeng/datasets/SeaShips(7000).zip

Seaships原數(shù)據(jù)集有3萬(wàn)+張圖像,但給出的數(shù)據(jù)集一共只有7000張,應(yīng)該是經(jīng)過(guò)篩選后的高質(zhì)量圖像。

這是論文給出的數(shù)據(jù)集中各類型的船只圖像數(shù)量。

這是論文《AnenhancedCNN-enabledlearningmethodforpromotingshipdetectionin maritimesurveillance system》采用Seaships數(shù)據(jù)集進(jìn)行實(shí)驗(yàn)的圖像數(shù)量,一共是7000張。

下載完后的數(shù)據(jù)集文件夾結(jié)構(gòu)應(yīng)該是這樣的:

一共是三個(gè)文件夾,JPEGImages里面保存的是7000張圖像文件

ImageSets保存的是四個(gè)txt文件

里面分別是四種集的圖像編號(hào),如test.txt文件內(nèi)容如下(部分):

Annotations里面存放的是7000張圖像的標(biāo)注文件:

二、數(shù)據(jù)集格式轉(zhuǎn)換

YOLO系列算法采用的是coco數(shù)據(jù)集,coco數(shù)據(jù)集的標(biāo)注文件格式如下:

我們可以使用下面的代碼直接將Seaships數(shù)據(jù)集轉(zhuǎn)換成coco數(shù)據(jù)集文件夾架構(gòu)的文件:

import os
import cv2
import json
import shutil
import xml.etree.ElementTree as ET
from tqdm import tqdm# Seaships 數(shù)據(jù)集的類別
SEASHIPS_CLASSES = ('ship', 'ore carrier', 'bulk cargo carrier', 'general cargo ship', 'container ship', 'fishing boat'
)# 將類別名稱映射為 COCO 格式的 category_id
label_ids = {name: i + 1 for i, name in enumerate(SEASHIPS_CLASSES)}def parse_xml(xml_path):"""解析 XML 文件,提取標(biāo)注信息。"""tree = ET.parse(xml_path)root = tree.getroot()objects = []for obj in root.findall('object'):# 解析類別名稱name = obj.find('name').textif name not in label_ids:print(f"警告: 未知類別 '{name}',跳過(guò)該對(duì)象。")continue# 解析 difficult 標(biāo)簽difficult_tag = obj.find('difficult')difficult = int(difficult_tag.text) if difficult_tag is not None else 0# 解析邊界框bnd_box = obj.find('bndbox')if bnd_box is not None:bbox = [int(bnd_box.find('xmin').text),int(bnd_box.find('ymin').text),int(bnd_box.find('xmax').text),int(bnd_box.find('ymax').text)]else:print(f"警告: 在文件 {xml_path} 中未找到 <bndbox> 標(biāo)簽,跳過(guò)該對(duì)象。")continue# 添加到對(duì)象列表objects.append({'name': name,'label_id': label_ids[name],'difficult': difficult,'bbox': bbox})return objectsdef load_split_files(split_dir):"""加載劃分文件(train.txt, val.txt, test.txt)。"""split_files = {}for split_name in ['train', 'val', 'test']:split_path = os.path.join(split_dir, f'{split_name}.txt')if os.path.exists(split_path):with open(split_path, 'r') as f:split_files[split_name] = [line.strip() for line in f.readlines()]else:print(f"警告: 未找到 {split_name}.txt 文件,跳過(guò)該劃分。")split_files[split_name] = []return split_filesdef convert_to_coco(image_dir, xml_dir, split_dir, output_dir):"""將 Seaships 數(shù)據(jù)集轉(zhuǎn)換為 COCO 格式,并根據(jù)劃分文件劃分?jǐn)?shù)據(jù)集。"""# 創(chuàng)建輸出目錄os.makedirs(os.path.join(output_dir, 'annotations'), exist_ok=True)os.makedirs(os.path.join(output_dir, 'train'), exist_ok=True)os.makedirs(os.path.join(output_dir, 'val'), exist_ok=True)os.makedirs(os.path.join(output_dir, 'test'), exist_ok=True)# 加載劃分文件split_files = load_split_files(split_dir)# 定義 COCO 格式的基本結(jié)構(gòu)def create_coco_structure():return {"info": {"description": "Seaships Dataset","version": "1.0","year": 2023,"contributor": "Your Name","date_created": "2023-10-01"},"licenses": [],"images": [],"annotations": [],"categories": [{"id": i + 1, "name": name, "supercategory": "none"}for i, name in enumerate(SEASHIPS_CLASSES)]}# 處理每個(gè)數(shù)據(jù)集for split_name, file_names in split_files.items():coco_data = create_coco_structure()annotation_id = 1for file_name in tqdm(file_names, desc=f"處理 {split_name} 數(shù)據(jù)集"):xml_file = os.path.join(xml_dir, f'{file_name}.xml')image_name = f'{file_name}.jpg'image_path = os.path.join(image_dir, image_name)# 檢查圖像文件和 XML 文件是否存在if not os.path.exists(image_path):print(f"警告: 圖像文件 {image_name} 不存在,跳過(guò)該標(biāo)注文件。")continueif not os.path.exists(xml_file):print(f"警告: 標(biāo)注文件 {xml_file} 不存在,跳過(guò)該圖像文件。")continue# 讀取圖像尺寸image = cv2.imread(image_path)height, width, _ = image.shape# 添加圖像信息image_id = len(coco_data['images']) + 1coco_data['images'].append({"id": image_id,"file_name": image_name,"width": width,"height": height})# 解析 XML 文件objects = parse_xml(xml_file)for obj in objects:xmin, ymin, xmax, ymax = obj['bbox']bbox = [xmin, ymin, xmax - xmin, ymax - ymin]  # COCO 格式的 bbox 是 [x, y, width, height]area = (xmax - xmin) * (ymax - ymin)coco_data['annotations'].append({"id": annotation_id,"image_id": image_id,"category_id": obj['label_id'],"bbox": bbox,"area": area,"iscrowd": 0,"difficult": obj['difficult']})annotation_id += 1# 復(fù)制圖像文件到對(duì)應(yīng)的文件夾shutil.copy(image_path, os.path.join(output_dir, split_name, image_name))# 保存 COCO 格式的標(biāo)注文件with open(os.path.join(output_dir, 'annotations', f'instances_{split_name}.json'), 'w') as f:json.dump(coco_data, f, indent=4)print(f"轉(zhuǎn)換完成,結(jié)果已保存到 {output_dir}")# 設(shè)置路徑
image_dir = "your path to images"  # 圖像文件目錄
xml_dir = "your path to annotations"  # XML 標(biāo)注文件目錄
split_dir = "your path to txt directory"  # 劃分文件目錄(包含 train.txt, val.txt, test.txt)
output_dir = "your path to output directory"  # 輸出的 COCO 格式文件夾# 執(zhí)行轉(zhuǎn)換
convert_to_coco(image_dir, xml_dir, split_dir, output_dir)

將代碼保存為Seaships_to_coco.py文件。

運(yùn)行以下代碼進(jìn)行轉(zhuǎn)換:

python seaships_to_coco.py

運(yùn)行完成以后生成Seaships_coco文件夾,下面包含和coco數(shù)據(jù)集相同格式的文件:

這樣我們就得到了coco格式的Seaships數(shù)據(jù)集了。

三、修改配置文件

3.1 修改coco.py

將classes修改為Seaships數(shù)據(jù)集的類:

Seaships類如下六種:

'ship', 'ore carrier', 'bulk cargo carrier', 'general cargo ship', 'container ship', 'fishing boat'

3.2 修改class_names.py

同樣將coco_class修改為seaships的類別:

3.3 修改需要運(yùn)行的配置的文件

比如我跑的這個(gè)py文件,需要把里面所有的路徑都修改成自己coco格式的seaships數(shù)據(jù)集。

把所有coco的路徑都改成自己seaships數(shù)據(jù)集的路徑,包括測(cè)試集、訓(xùn)練集等。

完整代碼如下:

auto_scale_lr = dict(base_batch_size=64, enable=False)
backend_args = None
data_preprocessor = dict(bgr_to_rgb=True,mean=[0,0,0,],pad_size_divisor=32,std=[255.0,255.0,255.0,],type='DetDataPreprocessor')
data_root = 'data/SeaShips_coco/'
dataset_type = 'CocoDataset'
default_hooks = dict(checkpoint=dict(interval=7, type='CheckpointHook'),logger=dict(interval=50, type='LoggerHook'),param_scheduler=dict(type='ParamSchedulerHook'),sampler_seed=dict(type='DistSamplerSeedHook'),timer=dict(type='IterTimerHook'),visualization=dict(type='DetVisualizationHook'))
default_scope = 'mmdet'
env_cfg = dict(cudnn_benchmark=False,dist_cfg=dict(backend='nccl'),mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0))
input_size = (320,320,
)
launcher = 'none'
load_from = None
log_level = 'INFO'
log_processor = dict(by_epoch=True, type='LogProcessor', window_size=50)
model = dict(backbone=dict(depth=53,init_cfg=dict(checkpoint='open-mmlab://darknet53', type='Pretrained'),out_indices=(3,4,5,),type='Darknet'),bbox_head=dict(anchor_generator=dict(base_sizes=[[(116,90,),(156,198,),(373,326,),],[(30,61,),(62,45,),(59,119,),],[(10,13,),(16,30,),(33,23,),],],strides=[32,16,8,],type='YOLOAnchorGenerator'),bbox_coder=dict(type='YOLOBBoxCoder'),featmap_strides=[32,16,8,],in_channels=[512,256,128,],loss_cls=dict(loss_weight=1.0,reduction='sum',type='CrossEntropyLoss',use_sigmoid=True),loss_conf=dict(loss_weight=1.0,reduction='sum',type='CrossEntropyLoss',use_sigmoid=True),loss_wh=dict(loss_weight=2.0, reduction='sum', type='MSELoss'),loss_xy=dict(loss_weight=2.0,reduction='sum',type='CrossEntropyLoss',use_sigmoid=True),num_classes=80,out_channels=[1024,512,256,],type='YOLOV3Head'),data_preprocessor=dict(bgr_to_rgb=True,mean=[0,0,0,],pad_size_divisor=32,std=[255.0,255.0,255.0,],type='DetDataPreprocessor'),neck=dict(in_channels=[1024,512,256,],num_scales=3,out_channels=[512,256,128,],type='YOLOV3Neck'),test_cfg=dict(conf_thr=0.005,max_per_img=100,min_bbox_size=0,nms=dict(iou_threshold=0.45, type='nms'),nms_pre=1000,score_thr=0.05),train_cfg=dict(assigner=dict(min_pos_iou=0,neg_iou_thr=0.5,pos_iou_thr=0.5,type='GridAssigner')),type='YOLOV3')
optim_wrapper = dict(clip_grad=dict(max_norm=35, norm_type=2),optimizer=dict(lr=0.001, momentum=0.9, type='SGD', weight_decay=0.0005),type='OptimWrapper')
param_scheduler = [dict(begin=0, by_epoch=False, end=2000, start_factor=0.1, type='LinearLR'),dict(by_epoch=True, gamma=0.1, milestones=[218,246,], type='MultiStepLR'),
]
resume = False
test_cfg = dict(type='TestLoop')
test_dataloader = dict(batch_size=1,dataset=dict(ann_file='annotations/instances_test.json',backend_args=None,data_prefix=dict(img='test/'),data_root='data/SeaShips_coco/',pipeline=[dict(backend_args=None, type='LoadImageFromFile'),dict(keep_ratio=True, scale=(320,320,), type='Resize'),dict(type='LoadAnnotations', with_bbox=True),dict(meta_keys=('img_id','img_path','ori_shape','img_shape','scale_factor',),type='PackDetInputs'),],test_mode=True,type='CocoDataset'),drop_last=False,num_workers=2,persistent_workers=True,sampler=dict(shuffle=False, type='DefaultSampler'))
test_evaluator = dict(ann_file='data/SeaShips_coco/annotations/instances_test.json',backend_args=None,metric='bbox',type='CocoMetric')
test_pipeline = [dict(backend_args=None, type='LoadImageFromFile'),dict(keep_ratio=True, scale=(320,320,), type='Resize'),dict(type='LoadAnnotations', with_bbox=True),dict(meta_keys=('img_id','img_path','ori_shape','img_shape','scale_factor',),type='PackDetInputs'),
]
train_cfg = dict(max_epochs=273, type='EpochBasedTrainLoop', val_interval=7)
train_dataloader = dict(batch_sampler=dict(type='AspectRatioBatchSampler'),batch_size=8,dataset=dict(ann_file='annotations/instances_train.json',backend_args=None,data_prefix=dict(img='train/'),data_root='data/SeaShips_coco/',filter_cfg=dict(filter_empty_gt=True, min_size=32),pipeline=[dict(backend_args=None, type='LoadImageFromFile'),dict(type='LoadAnnotations', with_bbox=True),dict(mean=[0,0,0,],ratio_range=(1,2,),to_rgb=True,type='Expand'),dict(min_crop_size=0.3,min_ious=(0.4,0.5,0.6,0.7,0.8,0.9,),type='MinIoURandomCrop'),dict(keep_ratio=True, scale=(320,320,), type='Resize'),dict(prob=0.5, type='RandomFlip'),dict(type='PhotoMetricDistortion'),dict(type='PackDetInputs'),],type='CocoDataset'),num_workers=4,persistent_workers=True,sampler=dict(shuffle=True, type='DefaultSampler'))
train_pipeline = [dict(backend_args=None, type='LoadImageFromFile'),dict(type='LoadAnnotations', with_bbox=True),dict(mean=[0,0,0,], ratio_range=(1,2,), to_rgb=True, type='Expand'),dict(min_crop_size=0.3,min_ious=(0.4,0.5,0.6,0.7,0.8,0.9,),type='MinIoURandomCrop'),dict(keep_ratio=True, scale=(320,320,), type='Resize'),dict(prob=0.5, type='RandomFlip'),dict(type='PhotoMetricDistortion'),dict(type='PackDetInputs'),
]
val_cfg = dict(type='ValLoop')
val_dataloader = dict(batch_size=1,dataset=dict(ann_file='annotations/instances_val.json',backend_args=None,data_prefix=dict(img='val/'),data_root='data/SeaShips_coco/',pipeline=[dict(backend_args=None, type='LoadImageFromFile'),dict(keep_ratio=True, scale=(320,320,), type='Resize'),dict(type='LoadAnnotations', with_bbox=True),dict(meta_keys=('img_id','img_path','ori_shape','img_shape','scale_factor',),type='PackDetInputs'),],test_mode=True,type='CocoDataset'),drop_last=False,num_workers=2,persistent_workers=True,sampler=dict(shuffle=False, type='DefaultSampler'))
val_evaluator = dict(ann_file='data/SeaShips_coco/annotations/instances_val.json',backend_args=None,metric='bbox',type='CocoMetric')
vis_backends = [dict(type='LocalVisBackend'),
]
visualizer = dict(name='visualizer',type='DetLocalVisualizer',vis_backends=[dict(type='LocalVisBackend'),])
work_dir = '/home/21021110287/wxz/mmdetection/work_dirs/yolo_seaships'

路徑里面包含seaships的就是我自己修改過(guò)后的,大家在用的時(shí)候記得改成自己的路徑即可。將該文件保存為 yolov3_seaships.py。

運(yùn)行以下代碼開(kāi)始訓(xùn)練算法(驗(yàn)證集上跑):

python <the path to train.py> <the path to yolov3_seaships.py> --work-dir <the path to your output dirctory>

第一個(gè)路徑是train.py文件的路徑 第二個(gè)是剛剛保存的運(yùn)行配置文件的路徑,最后一個(gè)路徑是自定義的輸出日志保存結(jié)果的路徑,如果不設(shè)置則會(huì)自動(dòng)生成work_dir文件夾保存結(jié)果,命令如下:

python <the path to train.py> <the path to yolov3_seaships.py>

如果需要在測(cè)試集上跑的話還需要添加檢查點(diǎn)文件路徑:

python <the path to your test.py> <the path to yolov3_seaships.py> <the path to your pth file> --work-dir <the path to the output dirctory>

四、運(yùn)行結(jié)果

運(yùn)行上述命令后 我們的算法就開(kāi)始跑起來(lái)了:

最終運(yùn)行結(jié)果的日志文件如下:

五、Faster-RCNN

如果還想在faster-rcnn或者ssd上運(yùn)行,直接選擇configs文件夾下不同的配置文件修改運(yùn)行命令即可

faster-rcnn可能會(huì)出現(xiàn)service not available的錯(cuò)誤,則需要把運(yùn)行配置文件中加載與訓(xùn)練模型的代碼注釋掉,否則沒(méi)有預(yù)訓(xùn)練模型無(wú)法運(yùn)行:

如果不想注釋掉就可以按照下面的方法去下載預(yù)訓(xùn)練模型(即權(quán)重文件):

在python環(huán)境下輸入下面命令下載模型即可:

之后找到模型文件(.pth文件),復(fù)制路徑,添加到加載預(yù)訓(xùn)練模型的那行代碼中”checkpoint=“的后面即可重新運(yùn)行,這樣會(huì)發(fā)現(xiàn)運(yùn)行速度遠(yuǎn)超未加載權(quán)重的時(shí)候。

http://aloenet.com.cn/news/38741.html

相關(guān)文章:

  • 颶風(fēng)算法受影響的網(wǎng)站seo優(yōu)化主要做什么
  • 做網(wǎng)站必須注冊(cè)的商標(biāo)網(wǎng)頁(yè)生成
  • 做網(wǎng)站 創(chuàng)業(yè)seo查詢平臺(tái)
  • wordpress 彈出框企業(yè)網(wǎng)站優(yōu)化服務(wù)公司
  • 鄭州制作網(wǎng)站ihanshi河北優(yōu)化seo
  • 中原建設(shè)信息網(wǎng) 網(wǎng)站seo優(yōu)化方式包括
  • 漯河網(wǎng)站建設(shè)公司怎么建網(wǎng)站賣東西
  • 可以查企業(yè)備案的網(wǎng)站游戲推廣賺錢(qián)
  • 建設(shè)部國(guó)家標(biāo)準(zhǔn)網(wǎng)站線上銷售的方法和技巧
  • 怎么制作h5廣州seo推廣服務(wù)
  • 創(chuàng)辦一個(gè)網(wǎng)站需要多少錢(qián)百度灰色關(guān)鍵詞排名推廣
  • 南京醫(yī)院手機(jī)網(wǎng)站建設(shè)b站推廣鏈接
  • 網(wǎng)站專題頁(yè)面設(shè)計(jì)網(wǎng)絡(luò)推廣方案范文
  • 小程序appid格式東莞seo收費(fèi)
  • 過(guò)年做哪些網(wǎng)站能致富seo概念
  • 模板網(wǎng)站建設(shè)青島seo做的好的網(wǎng)站
  • 江門(mén)網(wǎng)站建設(shè)運(yùn)營(yíng)團(tuán)隊(duì)蘇州網(wǎng)站建設(shè)開(kāi)發(fā)公司
  • 上海網(wǎng)站免費(fèi)制作seo怎么讀
  • 薊縣網(wǎng)站建設(shè)品牌策劃公司排名
  • 哪個(gè)網(wǎng)站可以做行程表在線優(yōu)化網(wǎng)站
  • 做網(wǎng)站的職位家庭優(yōu)化大師下載
  • 吸金聚財(cái)?shù)墓久志W(wǎng)站seo整站優(yōu)化
  • 美麗鄉(xiāng)村網(wǎng)站建設(shè)模板百度搜索入口網(wǎng)址
  • 網(wǎng)站建設(shè)推廣文章百度廣告開(kāi)戶流程
  • 網(wǎng)站申請(qǐng)內(nèi)容嗎平臺(tái)推廣是什么意思
  • 攜程電子商務(wù)網(wǎng)站建設(shè)武漢大學(xué)人民醫(yī)院精神衛(wèi)生中心
  • 關(guān)于做無(wú)機(jī)化學(xué)實(shí)驗(yàn)的網(wǎng)站四川網(wǎng)絡(luò)推廣seo
  • b站直播能禁止id觀看嗎國(guó)外網(wǎng)站推廣公司
  • 有哪些做包裝設(shè)計(jì)網(wǎng)站好些網(wǎng)站開(kāi)發(fā)的步驟
  • 網(wǎng)站建設(shè)前期預(yù)算百度網(wǎng)頁(yè)版下載安裝