faster-rcnn系列學習之準備數據

? ? ? ? ? ? 如下列舉了 將數據集做成VOC2007格式用于Faster-RCNN訓練的相關鏈接。

  1. RCNN系列實驗的PASCAL VOC數據集格式設置?
  2. 制作VOC2007數據集用于Faster-RCNN訓練
  3. 將數據集做成VOC2007格式用于Faster-RCNN訓練
    這一篇比較詳細地介紹了如何制造voc2007的所有文件,內含相關軟件和代碼,值得一看。
  4. voc2007數據集的下載和解壓

下面的部分介紹了py-faster-rcnn源碼中關于產生imdb與roidb的方法。

  1. ? ??faster-rcnn 之訓練數據是如何準備的:imdb和roidb的產生
  2. faster rcnn源碼解讀(四)之數據類型imdb.py和pascal_voc.py(主要是imdb和roidb數據類型的解說)
  3. py-faster-rcnn源碼解讀系列(二)——pascal_voc.py

具體的訓練方法:
Faster-RCNN+ZF用自己的數據集訓練模型(Python版本)

這里簡單說一下Imdb與roidb。

imdb是作者封裝的一個圖片數據庫類,內含數據庫的名字,比如默認的是voc_2007_trainval ,部分定義如下:

class imdb(object):"""Image database."""def __init__(self, name):self._name = nameself._num_classes = 0self._classes = []self._image_index = []self._obj_proposer = 'selective_search'self._roidb = Noneself._roidb_handler = self.default_roidb #(handle本來是指針,這里就當做引用)# Use this dict for storing dataset specific config optionsself.config = {}@propertydef name(self):return self._name@propertydef num_classes(self):return len(self._classes)@propertydef classes(self):return self._classes@propertydef image_index(self):return self._image_index@propertydef roidb_handler(self):return self._roidb_handler@roidb_handler.setterdef roidb_handler(self, val):self._roidb_handler = val
##!!!!!!設置roidbdef set_proposal_method(self, method):method = eval('self.' + method + '_roidb') # python中eval是可以具體運行里面的字符串的,這里指運行:self.gt_roidb,函數在pascal_voc.py中。self.roidb_handler = method@propertydef roidb(self):# A roidb is a list of dictionaries, each with the following keys:#   boxes#   gt_overlaps#   gt_classes#   flippedif self._roidb is not None:return self._roidbself._roidb = self.roidb_handler()return self._roidb#cache_path: /data1/caiyong.wang/program/py-faster-rcnn.back_up/data/cache  緩沖路徑@propertydef cache_path(self):cache_path = osp.abspath(osp.join(cfg.DATA_DIR, 'cache'))if not os.path.exists(cache_path):os.makedirs(cache_path)return cache_path@propertydef num_images(self):return len(self.image_index)
其中包含了roidb,roidb翻譯過來就是roi database.其實就是目標檢測包圍盒,從上面也可以看出, roidb是字典的列表,每項都是一張圖片,如下的每一項都是一張圖片上多個盒子的信息,因此是二維數組

# A roidb is a list of dictionaries, each with the following keys:
?#??- ?boxes 一個二維數組 ? 每一行存儲 xmin ymin xmax ymax ,行指的多個box的序號
# - ?gt_classes存儲了每個box所對應的類索引(類數組在初始化函數中聲明)
# - ?overlap是一個二維數組,行指box的序號,列共有21列,存儲的是0.0或者1.0 ,當box對應的類別時,自然為1.0.這實際上是指對于ground truth box,由于這里的候選框就是ground truth box,所以自然重疊后為1,而與其他的自然重疊設為0.后來被轉成了稀疏矩陣.
# - ?seg _areas存儲著 box的面積
#- ?flipped 為false 代表該圖片還未被翻轉(后來在train.py里會將翻轉的圖片加進去,用該變量用于區分)


產生imdb與roidb的主要代碼是:

def get_roidb(imdb_name, rpn_file=None):imdb = get_imdb(imdb_name)#通過工廠類獲取數據庫信息print 'Loaded dataset `{:s}` for training'.format(imdb.name)imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD)print 'Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD)if rpn_file is not None:imdb.config['rpn_file'] = rpn_fileroidb = get_training_roidb(imdb)#獲得訓練數據return roidb, imdb

步驟是
1. 通過 lib/datasets/factory.py獲取pascal_voc對象。

2.?pascal_voc繼承自imdb,進一步定義了該數據庫下的一些函數。

如下是pascal_voc的一些成員舉例:

#下面是成員變量的初始化:
#{
#    year:’2007’
#    name:'voc_2007_trainval'
#    image _set:’trainval’
#    devkit _path:’data/VOCdevkit2007’
#    data _path:’data /VOCdevkit2007/VOC2007’
#    classes:(…)_如果想要訓練自己的數據,需要修改這里_
#    class _to _ind:{…} _一個將類名轉換成下標的字典 _
#    image _ext:’.jpg’
#    image _index: [‘000001’,’000003’,……]_根據trainval.txt獲取到的image索引_
#    roidb _handler: <Method gt_roidb >
#    salt:  <Object uuid >
#    comp _id:’comp4’
#    config:{…}
#} 


3.?通過 lib/datasets/imdb.py 中的set_proposal_method 獲取roidb.

    def set_proposal_method(self, method):method = eval('self.' + method + '_roidb') # python中eval是可以具體運行里面的字符串的,這里指運行:self.gt_roidb,函數在pascal_voc.py中。self.roidb_handler = method
這里默認是eval('self.gt_roidb'),self.gt_roidb,函數在pascal_voc.py中。定義了ground truth的box的一些信息。

4. 通過lib/fast rcnn/train.py中的如下函數獲取訓練數據。

def get_training_roidb(imdb):"""Returns a roidb (Region of Interest database) for use in training."""if cfg.TRAIN.USE_FLIPPED:print 'Appending horizontally-flipped training examples...'imdb.append_flipped_images()print 'done'print 'Preparing training data...'rdl_roidb.prepare_roidb(imdb)print 'done'return imdb.roidb

這里面進行了圖片的翻轉,其實是box的翻轉(見?lib/datasets/imdb.py/append_flipped_images)

以及lib/roi_data_layer/roidb/rdl_roidb對象的prepare_roidb ,這個函數豐富了roi的一些信息,新增了每一個圖片的roidb的圖片路徑,大小,以及每個box對應的最大重疊,和最大重疊對應的label等。

def prepare_roidb(imdb):"""Enrich the imdb's roidb by adding some derived quantities thatare useful for training. This function precomputes the maximumoverlap, taken over ground-truth boxes, between each ROI andeach ground-truth box. The class with maximum overlap is alsorecorded."""sizes = [PIL.Image.open(imdb.image_path_at(i)).sizefor i in xrange(imdb.num_images)]roidb = imdb.roidbfor i in xrange(len(imdb.image_index)): #此時如果在前面調用了imdb.append_flipped_images,則imdb.image_index已經翻倍。roidb[i]['image'] = imdb.image_path_at(i)roidb[i]['width'] = sizes[i][0]roidb[i]['height'] = sizes[i][1]# need gt_overlaps as a dense array for argmaxgt_overlaps = roidb[i]['gt_overlaps'].toarray()# max overlap with gt over classes (columns)max_overlaps = gt_overlaps.max(axis=1)# gt class that had the max overlapmax_classes = gt_overlaps.argmax(axis=1)roidb[i]['max_classes'] = max_classesroidb[i]['max_overlaps'] = max_overlaps# sanity checks# max overlap of 0 => class should be zero (background)zero_inds = np.where(max_overlaps == 0)[0]assert all(max_classes[zero_inds] == 0)# max overlap > 0 => class should not be zero (must be a fg class)nonzero_inds = np.where(max_overlaps > 0)[0]assert all(max_classes[nonzero_inds] != 0)








本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/258660.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/258660.shtml
英文地址,請注明出處:http://en.pswp.cn/news/258660.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C# 委托鏈、多路廣播委托

委托鏈、多路廣播委托&#xff1a;也就是把多個委托鏈接在一起,我們把鏈接了多個方法的委托稱為委托鏈或多路廣播委托 例&#xff1a; 1 class HelloWorld2 {3 //定義委托類型4 delegate void DelegationChain();5 static void Main(string[] args)6 …

openssl 生成證書_使用證書和私鑰導出P12格式個人證書!

【OpenSSL】使用證書和私鑰導出P12格式個人證書1, 產生CA證書1.1, 生成ca的私鑰openssl genrsa -out cakey.pem 20481.2, 生成ca的自簽名證書請求openssl req -new -key cakey.pem -subj "/CNExample Root CA" -out cacsr.pem1.3, 自簽名ca的證書openssl x509 -req -…

PHP (20140505)

數據庫表與表之間的連接是用id聯系。 join on&#xff1b;轉載于:https://www.cnblogs.com/sunshine-c/p/3710283.html

py-faster-rcnn代碼roidb.py的解讀

roidb是比較復雜的數據結構&#xff0c;存放了數據集的roi信息。原始的roidb來自數據集&#xff0c;在trian.py的get_training_roidb(imdb)函數進行了水平翻轉擴充數量&#xff0c;然后prepare_roidb(imdb)【定義在roidb.py】為roidb添加了一些說明性的屬性。 在這里暫時記錄下…

python 概率分布_python實現概率分布

伯努利分布from scipy import statsimport numpy as npimport matplotlib.pyplot as pltxnp.arange(0,2,1)xarray([0, 1])# 求對應分布的概率&#xff1a;概率質量函數 (PMF)p0.5# 硬幣朝上的概率dfstats.bernoulli.pmf(x,p)dfarray([0.5, 0.5])#繪圖vlines用于繪制豎直線(vert…

CodeForces 7D Palindrome Degree 字符串hash

題目鏈接&#xff1a;點擊打開鏈接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib…

程序清單8-9 回送所有命令行參數和所有環境字符串

1 /*2 3 Name : test.c4 Author : blank5 Version :6 Copyright : Your copyright notice7 Description : 程序清單8-9 回送所有命令行參數和所有環境字符串8 9 */ 10 11 #include "ourhdr.h" 12 13 int main(int argc, char *argv[]) 14…

SQL快速入門

關系化數據庫保存關系模式數據的容器關系模式是對業務對象實體&#xff0c;屬性以及關系的抽象&#xff0c;提煉需求的名詞是建立實體關系模型常用的方法。要了解E-R實體關系圖的繪制。常用關系數據庫Microsoft SQL Server&#xff1b;微軟公司產品&#xff0c;中等規模數據庫&…

Faster RCNN minibatch.py解讀

minibatch.py 的功能是&#xff1a; Compute minibatch blobs for training a Fast R-CNN network. 與roidb不同的是&#xff0c; minibatch中存儲的并不是完整的整張圖像圖像&#xff0c;而是從圖像經過轉換后得到的四維blob以及從圖像中截取的proposals&#xff0c;以及與之對…

oracle精簡版_使用Entity Framework Core訪問數據庫(Oracle篇)

前言哇。。看看時間 真的很久很久沒寫博客了 將近一年了。最近一直在忙各種家中事務和公司的新框架 終于抽出時間來更新一波了。本篇主要講一下關于Entity Framework Core訪問oracle數據庫的采坑。。強調一下&#xff0c;本篇文章發布之前 關于Entity Framework Core訪問oracl…

interrupt、interrupted 、isInterrupted 區別

interrupt&#xff1a;調用方法&#xff0c;是線程處于中斷狀態&#xff0c;但是這個方法只是讓線程設置為中斷狀態&#xff0c;并不會真正的停止線程。支持線程中斷的方法就是在堅持線程中斷狀態&#xff0c;一旦線程中斷狀態被設置為中斷&#xff0c;就會拋出異常。interrupt…

java String部分源碼解析

String類型的成員變量 /** String的屬性值 */ private final char value[];/** The offset is the first index of the storage that is used. *//**數組被使用的開始位置**/private final int offset;/** The count is the number of characters in the String. *//**String中…

python在材料模擬中的應用_基于Python的ABAQUS二次開發及在板料快速沖壓成形模擬中的應用...

2009doi:1013969/j1issn1100722012120091041013基于Python的ABAQUS二次開發及在板料快速沖壓成形模擬中的應用(北京航空航天大學飛行器制造工程系,北京100191)吳向東劉志剛萬敏王文平黃霖摘要:采用Python腳本語言對ABAQUS的前處理模塊進行二次開發,討論了Python腳本在ABAQUS二次…

Doxygen簡介

&#xff08;轉自&#xff1a;http://www.cnblogs.com/liuliunumberone/archive/2012/04/10/2441391.html&#xff09; 一&#xff0e;什么是Doxygen? Doxygen 是一個程序的文件產生工具&#xff0c;可將程序中的特定批注轉換成為說明文件。通常我們在寫程序時&#xff0c;或多…

javascript之閉包理解以及應用場景

1 function fn(){2 var a 0;3 return function (){4 return a;5 } 6 }如上所示&#xff0c;上面第一個return返回的就是一個閉包&#xff0c;那么本質上說閉包就是一個函數。那么返回這個函數有什么用呢&#xff1f;那是因為這個函數可以調用到它外部的a…

faster rcnn學習之rpn、fast rcnn數據準備說明

在上文《 faster-rcnn系列學習之準備數據》,我們已經介紹了imdb與roidb的一些情況&#xff0c;下面我們準備再繼續說一下rpn階段和fast rcnn階段的數據準備整個處理流程。 由于這兩個階段的數據準備有些重合&#xff0c;所以放在一起說明。 我們并行地從train_rpn與train_fas…

sql server規范

常見的字段類型選擇 1.字符類型建議采用varchar/nvarchar數據類型2.金額貨幣建議采用money數據類型3.科學計數建議采用numeric數據類型4.自增長標識建議采用bigint數據類型 (數據量一大&#xff0c;用int類型就裝不下&#xff0c;那以后改造就麻煩了)5.時間類型建議采用為dat…

關于標準庫中的ptr_fun/binary_function/bind1st/bind2nd

http://www.cnblogs.com/shootingstars/archive/2008/11/14/860042.html 以前使用bind1st以及bind2nd很少&#xff0c;后來發現這兩個函數還挺好玩的&#xff0c;于是關心上了。在C Primer對于bind函數的描述如下&#xff1a;“綁定器binder通過把二元函數對象的一個實參綁定到…

CSS偽類

一、首字母的顏色字體寫法 p:first-letter 二、文本的特殊樣式設置 first-line css偽類可與css類配合使用 偽元素只能用于塊級元素 轉載于:https://www.cnblogs.com/boyblog/p/4623374.html

php 結構體_【開發規范】PHP編碼開發規范下篇:PSR-2編碼風格規范

之前的一篇文章是對PSR-1的基本介紹接下來是PSR-2 編碼風格規范&#xff0c;它是 PSR-1 基本代碼規范的繼承與擴展。PSR-1 和PSR-2是PHP開發中基本的編碼規范&#xff0c;大家其實都可以參考學習下&#xff0c;雖然說每個開發者都有自己熟悉的一套開發規范&#xff0c;但是我覺…