框架學(xué)習(xí)源碼解析分析cpp_第1頁
框架學(xué)習(xí)源碼解析分析cpp_第2頁
框架學(xué)習(xí)源碼解析分析cpp_第3頁
免費(fèi)預(yù)覽已結(jié)束,剩余3頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、2015/8/29caffe源碼分析­­data_layer.cpp ­ linger(心懷夢想,活在當(dāng)下) ­ 博客頻道 ­ CSDN.NET登錄 |linger(心懷夢想,活在當(dāng)下) 學(xué)習(xí),深度學(xué)習(xí),數(shù)據(jù)挖掘,推薦系統(tǒng),分布式算法目錄視圖 摘要視圖 訂閱個人資料caffe源碼分析-data_layer.cpp分類: 深度學(xué)習(xí)(deep learning)2014­05­31 21:24 5375人閱讀 評論(5) 收藏神經(jīng)網(wǎng)絡(luò) caffe 深度學(xué)習(xí) deep learninglingerlanlandataLayer作為

2、整個網(wǎng)絡(luò)數(shù)據(jù)從leveldb中取。lev過圖片轉(zhuǎn)換過來的。網(wǎng)絡(luò)建立的時候,datalayer主要是負(fù)責(zé)設(shè)置一些參數(shù),比如batchsize,channels,height,width等。這次會通過讀leveldb一個數(shù)據(jù)塊來獲取這些信息。然后啟動一個線程來預(yù)先從leveldb拉取一批數(shù)據(jù),這些數(shù)據(jù)是圖像數(shù)據(jù)和圖像 。正向 的時候,: 156篇 : 0篇譯文: 2篇 評論: 260條datalayer就把預(yù)先拉取好數(shù)據(jù)拷貝到指定的cpu或者gpu的內(nèi)存。然后啟動新線程再預(yù)先拉取數(shù)據(jù),這些數(shù)據(jù)留到下一次正向文章搜索文章分類深度學(xué)習(xí)(deep learning) (28)學(xué)習(xí) (16)cuda(GP

3、U programming) (20)文本挖掘 (5)c/c+ (15)dota (5)hack programming (6)web2.0 (5)工具源碼 (7)語言學(xué)習(xí) (22)設(shè)計(jì)模式 (2)讀書筆記 (1)翻譯 (1)足球大數(shù)據(jù) (2)大雜燴 (18)Hadoop (12)Spark (2)sklearn (1)文章存檔2015年08月 (1)1/601.02.03.04.05.06.07.08.07.28.29.cpp/ Copyright 2013 Yangqing Jia#

4、include <stdint.h> #include <leveldb/db.h> #include <pthread.h>#include <string> #include <vector>#include "caffe/layer.hpp" #include "caffe/util/io.hpp" #include "caffe/vision_layers.hpp"using std:string;namespace caffe template <typena

5、me Dtype>void* DataLayerPrefetch(void* layer_pointer) CHECK(layer_pointer);DataLayer<Dtype>* layer = reinterpret_cast<DataLayer<Dtype>*>(layer_pointer); CHECK(layer);Datum datum; CHECK(layer>prefetch_data_);Dtype* top_data = layer>prefetch_data_>mutable_cpu_data();/數(shù)據(jù)Dt

6、ype* top_label = layer>prefetch_label_>mutable_cpu_data();/ const Dtype scale = layer>layer_param_.scale();const int batchsize = layer>layer_param_.batchsize(); const int cropsize = layer>layer_param_.cropsize();: 219485次: 3991等級:排名: 第3738名e2015/8/29caffe源碼分析­­data_layer.cpp

7、 ­ linger(心懷夢想,活在當(dāng)下) ­ 博客頻道 ­ CSDN.NET2015年07月 (3)2015年06月 (3)2015年05月 (3)2015年04月 (8)2.const bool mirror = layer>layer_param_.mirror();if (mirror && cropsize = 0) /當(dāng)前實(shí)現(xiàn)需要同時設(shè)置mirror和cropsize LOG(FATAL) << "Current implementati

8、on requires mirror and cropsize to be "<< "set at the same time."/ datum scalesconst int channels = layer>datum_channels_; const int height = layer>datum_height_; const int width = layer>datum_width_;const int size = layer>datum_size_;const Dtype* mean = layer>dat

9、a_mean_.cpu_data();for (int itemid = 0; itemid < batchsize; +itemid) /每一批數(shù)據(jù)的數(shù)量是batchsize,一個循環(huán)拉取一張?/ get a blob CHECK(layer>iter_); CHECK(layer>iter_>Valid();datum.ParseFromString(layer>iter_>value().ToString();/利用迭代器拉取下一批數(shù)據(jù)const string& data = datum.data(); if (cropsize) /如果需要裁

10、剪CHECK(data.size() << "Image cropping only support uint8 data" int h_off, w_off; 展開最新評論總結(jié)一下用caffe跑圖片數(shù)據(jù)的研l(wèi)iangzhituzi: zzq1989_:可能是那兩個文件路徑的問題,可以看看train_prototxt里面的路徑deep learning實(shí)踐經(jīng)驗(yàn)總結(jié)查志強(qiáng): 問下,怎樣 “錯誤”的?神經(jīng)網(wǎng)絡(luò):caffe特征可視化的代fqss0436: 博主,您好, 您代碼。在調(diào)試您的代碼時,程序中斷于175行caffe_test_net.For.我所寫的 框架 V

11、S caffe gzp95: 樓主碼的速度和caf差距。因?yàn)樽罱诘腸ud.總結(jié)一下用caffe跑圖片數(shù)依然_范佩西11: 訓(xùn)練完的模型如是調(diào)用呢,能說下能么測試單張圖像或者批量圖像的流程么Dota全圖那些事兒女圭丶女圭: 。單機(jī)理論效果,實(shí)際不好用啊。支持一下不錯的caffe源碼修改:抽取任意一張圖wwdzhtxnjwcnmd: 想請教一下博主,caffe網(wǎng)絡(luò)中batch_size和crop_size這兩個參數(shù)的含義是什么?哪一.caffe源碼分析­­data_layer.cpp 滄海1夢: 請問caffe中如何修改輸入和裁剪小是48的,想通過修改alexnet來訓(xùn)練,還

12、.caffe卷積神經(jīng)網(wǎng)絡(luò)框架安裝yang123jx: 我也遇到relu_layer.cu:29 check failed error = cudaSuc.caffe卷積神經(jīng)網(wǎng)絡(luò)框架安裝yang123jx: 我也遇到relu_layer.cu:29 check failed error = cudaSuc.9.50.596./if (mi/ Copy for (int c0; h < cropsize; +h) 3.8for

13、 (int w =) top_data(ite+ cropsiz (static_cast<Dtyp >(uint8_t)da+ c) * cropsize + h) * cropsize w =* height + h + h_off) * width w_off)h_off) * width + w + w_off) mean* sca el閱讀排行總結(jié)一下用caffe跑圖片數(shù) 92)word2vector學(xué)習(xí)筆記( 42)caffe神經(jīng)網(wǎng)絡(luò)框架的輔助 7)caffe源碼修改:抽取任意 ) caffe卷積神經(jīng)網(wǎng)絡(luò)框架安caffe源碼分析­­data_lay神

14、經(jīng)網(wǎng)絡(luò):caffe特征 視word2vec源碼caffe源碼分析­­Blob類代 (4386)deep learning實(shí)踐經(jīng)驗(yàn) (4225)0007. else /如果不需要裁剪/ we will prefer to use data() first, and then try float_data()/我們優(yōu)先考慮data(),然后float_data() if (data.size() for (int j = 0; j < size; +j) top_data

15、itemid * size + j =(static_cast<Dtype>(uint8_t)dataj) meanj) * scale; else for (int j = 0; j < size; +j) top_dataitemid * size + j =(datum.float_data(j) meanj) * scale;推薦文章2/62015/8/29caffe源碼分析­­data_layer.cpp ­ linger(心懷夢想,活在當(dāng)下) ­ 博客頻道 ­ CSDN.NET11.112

16、.19.120.top_labelitemid = datum.label();/ go to the next iter layer>iter_>Next();if (!layer>iter_>Valid() / We have reached the end. Restart from the first. DLOG(INFO) << "Restarting data prefetching from start." layer>iter_>SeekToFirst();re

17、turn reinterpret_cast<void*>(NULL);121. 122.123. template <typename Dtype>124. DataLayer<Dtype>:DataLayer<Dtype>() 125.126./ Finally, join the threadCHECK(!pthread_join(thread_, NULL) << "Pthread joining failed."127. 128.129. template <typename Dtype>130

18、. void DataLayer<Dtype>:SetUp(const vector<Blob<Dtype>*>& bottom,82.183.1

19、84.185.186.vector<Blob<Dtype>*>* top) CHECK_EQ(bottom.size(), 0) << "Data Layer takes no input blobs." CHECK_EQ(top>size(), 2) << "Data Layer takes two blobs as output."/ Initialize the leveldb leveldb:DB* db_temp; leveldb:Options options; options.creat

20、e_if_missing = false; options.max_open_files = 100;LOG(INFO) << "Opening leveldb " << this>layer_param_.source(); leveldb:Status status = leveldb:DB:Open(options, this>layer_param_.source(), &db_temp); CHECK(status.ok() << "Failed to open leveldb "<

21、< this>layer_param_.source() << std:endl << status.ToString(); db_.reset(db_temp);iter_.reset(db_>NewIterator(leveldb:ReadOptions();/通過迭代器來 leveldbiter_>SeekToFirst();/ Check if we would need to randomly skip a few data points/是否要隨機(jī)跳過一些數(shù)據(jù)if (this>layer_param_.rand_skip() /

22、 NOLINT_NEXT_LINE(runtime/threadsafe_fn)unsigned int skip = rand() % this>layer_param_.rand_skip(); LOG(INFO) << "Skipping first " << skip << " data points." while (skip > 0) /循環(huán)次數(shù)iter_>Next();if (!iter_>Valid() iter_>SeekToFirst();/ Read a data p

23、oint, and use it to initialize/可以觀察到下面iter_調(diào)用調(diào)用next。所以這次Datum datum;datum.ParseFromString(iter_>value().ToString();/利用迭代器/ image圖像數(shù)據(jù)int cropsize = this>layer_param_.cropsize();/裁剪大小if (cropsize > 0) /需要裁剪(*top)0>Reshape(this>layer_param_.batchsize(), datum.channels(), cropsize, cropsi

24、ze); prefetch_data_.reset(new Blob<Dtype>(this>layer_param_.batchsize(), datum.channels(), cropsize, cropsize); else /不需要裁剪(*top)0>Reshape(this>layer_param_.batchsize(), datum.channels(), datum.height(), datum.width();prefetch_data_.reset(new Blob<Dtype>(this>layer_param_.bat

25、chsize(), datum.channels(), datum.height(), datum.width();LOG(INFO) << "output data size: " << (*top)0>num() << ","<< (*top)0>channels() << "," << (*top)0>height() << ","<< (*top)0>width();/ label 數(shù)據(jù)(

26、*top)1>Reshape(this>layer_param_.batchsize(), 1, 1, 1); prefetch_label_.reset(new Blob<Dtype>(this>layer_param_.batchsize(), 1, 1, 1);3/62015/8/29caffe源碼分析­­data_layer.cpp ­ linger(心懷夢想,活在當(dāng)下) ­ 博客頻道 ­ CSDN.NET99

27、.00045./ datum sizedatum_channels_ = datum.channels(); datum_height_ = datum.height(); datum_width_ = datum.width();datum_

28、size_ = datum.channels() * datum.height() * datum.width(); CHECK_GT(datum_height_, cropsize);CHECK_GT(datum_width_, cropsize);/ check if we want to have mean是否要減去均值if (this>layer_param_.has_meanfile() BlobProto blob_proto;LOG(INFO) << "Loading mean file from" << this>laye

29、r_param_.meanfile(); ReadProtoFromBinaryFile(this>layer_param_.meanfile().c_str(), &blob_proto); data_mean_.FromProto(blob_proto);CHECK_EQ(data_mean_.num(), 1); CHECK_EQ(data_mean_.channels(), datum_channels_); CHECK_EQ(data_mean_.height(), datum_height_); CHECK_EQ(data_mean_.width(), datum_w

30、idth_); else / Simply initialize an allempty mean.data_mean_.Reshape(1, datum_channels_, datum_height_, datum_width_);/ Now, start the prefetch thread. Before calling prefetch, we make two/ cpu_data calls so that the prefetch thread does not accidentally make/ simultaneous cudaMalloc calls when the

31、main thread is running. In some/ GPUs this seems to cause failures if we do not so. prefetch_data_>mutable_cpu_data(); prefetch_label_>mutable_cpu_data(); data_mean_.cpu_data();DLOG(INFO) << "Initializing prefetch" CHECK(!pthread_create(&thread_, NULL, DataLayerPrefetch<

32、Dtype>,reinterpret_cast<void*>(this) << "Pthread execution failed." DLOG(INFO) << "Prefetch initialized."template <typename Dtype>void DataLayer<Dtype>:Forward_cpu(const vector<Blob<Dtype>*>& bottom, vector<Blob<Dtype>*>

33、;* top) / First, join the thread 等待線程結(jié)束CHECK(!pthread_join(thread_, NULL) << "Pthread joining failed."/ Copy the data拷貝數(shù)據(jù)到top,即該層的輸出memcpy(*top)0>mutable_cpu_data(), prefetch_data_>cpu_data(),sizeof(Dtype) * prefetch_data_>count(); memcpy(*top)1>mutable_cpu_data(), prefet

34、ch_label_>cpu_data(),sizeof(Dtype) * prefetch_label_>count();/ Start a new prefetch thread啟動新線程拉取下一批數(shù)據(jù)CHECK(!pthread_create(&thread_, NULL, DataLayerPrefetch<Dtype>,reinterpret_cast<void*>(this) << "Pthread execution failed."/ The backward operations are dummy t

35、hey do not carry any computation. template <typename Dtype>Dtype DataLayer<Dtype>:Backward_cpu(const vector<Blob<Dtype>*>& top, const bool propagate_down, vector<Blob<Dtype>*>* bottom) return Dtype(0.);INSTANTIATE_CLASS(DataLayer); / namespace caffe本文作者:linger本文 :本文為博主 文章, 博主 不得 。4/62015/8/29caffe源碼分析­­data_layer.cpp ­ linger(心懷夢想,活在當(dāng)下) ­ 博客頻道 ­ CSDN.NET上一篇 全局內(nèi)存性能測試下一篇 使用squid架設(shè)自己的主題推薦源碼 網(wǎng)絡(luò) 線程 圖片內(nèi)存猜你在找韋東山HTML 5移動開發(fā)從入門到精通C語言及程序設(shè)計(jì)初步Android入門實(shí)零基礎(chǔ)學(xué)HTML 5實(shí)戰(zhàn)開發(fā)(第一季)任意一張圖片的特征

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論