【caffe-Windows】mnist例項編譯之model的使用-matlab
前言
針對上一個caffe文章留下的matlab手寫數字識別的問題,感謝caffe中文社群的 @ghgzh 的提示,原文請看:caffe中文社群
第一步
手寫圖片的製作方法我就不說了,直接把我自己畫的幾個數字放到雲盤先:
三通道影象以及轉換所需程式碼:連結:http://pan.baidu.com/s/1gfqeCAR 密碼:88kk
轉換後的灰度影象:連結:http://pan.baidu.com/s/1eSyohsY 密碼:zwum
【注意】如果你的手寫數字是黑字白底,最好反轉成白字黑底,畢竟mnist的資料集就是白字黑底
第二步
建立標籤,從零開始,synset_words.txt如下:
0 1 2 3 4 5 6 7 8 9
第三步
書寫呼叫classfication demo的test檔案:
【重點】上一篇文章所留問題就是在這裡解決的,在圖片輸入網路之前也就是net.forwarad之前,必須經過轉置,原理未知,目前是感覺跟matlab和opencv讀取圖片的方法有關,使用caffe.io.loadimage讀取是按照BGR讀取,並且進行了旋轉,所以使用matlab時候必須進行同等處理,詳細原因在後面分析程式碼再說~~~
clear clc close all im=imread('./binarybmp/5.bmp'); figure;imshow(im);%顯示圖片 [scores, maxlabel] = classification_demo(im', 0);%獲取得分第二個引數0為CPU,1為GPU scores maxlabel figure;plot(scores);%畫出得分情況 axis([0, 10, -0.1, 0.5]);%座標軸範圍 grid on %有網格 fid = fopen('synset_words.txt', 'r'); i=0; while ~feof(fid) i=i+1; lin = fgetl(fid); lin = strtrim(lin); if(i==maxlabel) fprintf('the maxlabel of %d in label txt is %s\n',i,lin) break end end
第四步
修改classification_demo如下:
說明一下修改的部分,function [scores, maxlabel] = classification_demo(im, use_gpu) if exist('../../+caffe', 'dir') addpath('../..'); else error('Please run this demo from caffe/matlab/demo'); end % Set caffe mode if exist('use_gpu', 'var') && use_gpu caffe.set_mode_gpu(); gpu_id = 0; % we will use the first gpu in this demo caffe.set_device(gpu_id); else caffe.set_mode_cpu(); end % Initialize the network using BVLC CaffeNet for image classification % Weights (parameter) file needs to be downloaded from Model Zoo. model_dir = '../../../examples/mnist/'; net_model = [model_dir 'lenet.prototxt']; net_weights = [model_dir 'lenet_iter_10000.caffemodel']; phase = 'test'; % run with phase test (so that dropout isn't applied) if ~exist(net_weights, 'file') error('Please download CaffeNet from Model Zoo before you run this demo'); end % Initialize a network net = caffe.Net(net_model, net_weights, phase); % prepare oversampled input % input_data is Height x Width x Channel x Num tic; mean_data = caffe.io.read_mean('../../../examples/mnist/mean.binaryproto'); scale=0.00390625; im=double(im); im=(im-mean_data)*scale; input_data = {im}; toc; % do forward pass to get scores % scores are now Channels x Num, where Channels == 1000 tic; % The net forward function. It takes in a cell array of N-D arrays % (where N == 4 here) containing data of input blob(s) and outputs a cell % array containing data from output blob(s) scores = net.forward(input_data); toc; scores = scores{1}; scores = mean(scores, 2); % take average scores over 10 crops [~, maxlabel] = max(scores); % call caffe.reset_all() to reset caffe caffe.reset_all();
①模型檔案:呼叫的模型依舊是要注意deploy.prototxt與train_test .prototxt的區別,在mnist例項中,deploy.prototxt就是lenet.prototxt,後者就是lenet_train_test.prototxt,它倆分別是前者在識別期間呼叫,一個是在訓練及測試階段呼叫。區別在於,deploy檔案前兩層並無指定輸入資料和測試資料的層,最後一層中deploy使用的softmax的“pro”,輸出的是可能標籤的概率,而train_test使用的是softmax的“loss”,用於指示每次訓練的損失。
②去掉了在cat 的那個classification_demo中的圖片預處理中需要進行crops_data處理對圖片進行分塊的部分。在手寫數字中的預處理,處理在第三步中比較重要的一步影象轉置外,在classification_demo中需要進行零均值以及縮放兩步驟。(注,按照上一篇的訓練檔案,我們已經更改了預處理步驟,添加了均值計算這一過程,在lenet_train_test1第一二層的 transform_param中可以看到)
這裡附帶一下我的deploy和train_test檔案
deploy.prototxt檔案:連結:http://pan.baidu.com/s/1pLPGf03 密碼:cqjy
train_test.prototxt檔案:連結:http://pan.baidu.com/s/1kVM03DP 密碼:l83w
第五步
差不多結束了,執行程式吧。我的測試結果如下:
相關推薦
【caffe-Windows】mnist例項編譯之model的使用-matlab
前言 針對上一個caffe文章留下的matlab手寫數字識別的問題,感謝caffe中文社群的 @ghgzh 的提示,原文請看:caffe中文社群 第一步 手寫圖片的製作方法我就不說了,直接把我自己畫的幾個數字放到雲盤先: 三通道影象以及轉換所需程式碼:連結:http://p
【caffe-Windows】mnist例項編譯之model的生成
其實這個和cifar的例項基本相同,只不過資料轉換的方法不一樣 【說明,此部落格按照我自己的路徑設定的相關操作,讀者如果自行選擇其他路徑,記得在bat和prototxt等檔案修改路徑】 第一步 為了避免部分人下載速度緩慢或者打不開網址,這個上傳了百度雲:連結:http:/
【caffe-Windows】cifar例項編譯之model的生成
參考:<span style="font-family: Arial, Helvetica, sans-serif;">http://blog.csdn.net/chengzhongxuyou/article/details/50715455</span
2.【caffe-Windows】cifar例項編譯之model的生成
準備工作 按照之前的教程,成功生成過caffe,並且編譯整個caffe.sln專案工程,在\caffe-master\Build\x64\Debug生成了一堆exe檔案,後面會使用到除了caffe.exe的另外一個exe 【PS】很多VS安裝過程中出現問題的,比如X
【caffe-Windows】微軟官方caffe之 Python介面配置及圖片生成例項
前言 發現許多程式碼還是用python寫的,所以還是配置一下介面吧,雖然博主不會Python,咳咳。在這裡使用的python安裝包是anaconda2,注意使用Python2.7版本的那個安裝包。 百度雲:連結:http://pan.baidu.com/s/1nvrrfQ
【caffe-Windows】微軟官方caffe之 matlab介面配置
前言按照微軟的官方地址配置可能會出現一個問題caffe_.mexw64找不到引用模組問題,或者在matlab裡面壓根找不到caffe_這個函式,下面會提到這兩個問題。還是按照步驟來吧【PS1】有GPU同樣按照下述步驟,進行即可【PS2】文章在matlab2013a、matla
【caffe-windows】 caffe-master 之 matlab介面配置
平臺環境: win10 64位 caffe-master vs2013 Matlab2016a 第一步: 開啟\caffe-master\windows下的CommonSettings.props檔案, 更改MatlabSupport,改成true(即支援Matlab介面
【caffe-windows】 caffe-master 之 卷積核可視化(利用matlab)
前期準備,需要兩個東西 1. 模型的描述檔案 deploy.prototxt 2. 模型本身lenet_iter_10000.caffemodel (此處用的examples中的mnist裡的) 第一步: 在建立D:\caffe-master\m
【caffe-Windows】關於LSTM的簡單小例子
前言 這裡主要是看到了一個簡單的LSTM例子,比上一個coco簡單很多,所以在這裡記錄一下,便於後續的分析,參考部落格在上一篇文章的末尾提到過:Recurrent neural nets with Caffe 需要說明的是這個例子也並非原原本本的使用caffe自帶的LSTM
【caffe-Windows】caffe+VS2013+Windows+GPU配置+cifar使用
前言 國際慣例,先來波地址: CUDA WIN7:連結:http://pan.baidu.com/s/1nvyA3Qp 密碼:h0f3 官方網址:https://developer.nvidia.com/cuda-toolkit CUDA WIN10:連結:http:/
【caffe-Windows】caffe+VS2013+Windows無GPU快速配置教程
前言首先來一波地址:happynear大神的第三方caffe:http://blog.csdn.net/happynear/article/details/45372231Neil Z大神的第三方caffe:https://initialneil.wordpress.com/
【轉】Android原始碼編譯之ADB編譯
How to build adb, the Android debugger adb is the Android debugger (officially the “Android debug bridge” I think). It is a tool for getti
【TensorFlow-windows】(七) CNN之VGG-net的測試
主要內容: 1.CNN之VGG-net的測試 2.該實現中的函式總結 平臺: 1.windows 10 64位 2.Anaconda3-4.2.0-Windows-x86_64.exe (當時TF還不支援python3.6,又懶得在高版本的an
【Ogre-windows】例項配置
前言 折騰了好久才搞定教程例項, 主要是因為上一篇部落格安裝的具體版本是Ogre1.10.9, 而官方的Ogre Wiki Tutorial Framework沒有指定具體版本, 如果單純下載Ogre Wiki Tutorial Framework 1.10
【caffe學習筆記——mnist】mnist手寫資料集訓練和測試
http://blog.csdn.NET/liumaolincycle/article/details/47336921 本文主要來自Caffe作者Yangqing Jia網站給出的examples。 @article{jia2014caffe, Author = {Jia, Yangqing an
【Prince2科普】P2七大主題之商業論證
每一個 基本 pri clas 主題 tro 決策 family ont 進入第一個主題,PRINCE2商業論證:PRINCE2指出,商業論證就是進行判斷是否值得對項目進行投資,值不值的問題。 PRINCE2的商業論證有四個在項目開始時,開發商業論證。在整個項目生命周期
【Prince2科普】P2七大主題之計劃
表示 展示 學習 其中 新的 設計 分析 當前 基於 今天我們學習第四個主題:計劃 目的是通過定義交付產品的方式、在哪裏、如何、由誰並估算多少時間、多少成本從而促進溝通與控制,說白了就是編制計劃。 PRINCE2建議用三個層次的計劃來反應項目階段和小組不同層次的管理需求
【Java基礎】RTTI與反射之Java
start auth try dword star sse from tac sed 1 ; Example assembly language program -- 2 ; Author: Karllen 3 ; Date: revised 05/2014
【OpenPose-Windows】運行OpenposeDemo.exe 如何保存圖像運行結果及關節點信息
out ubunt 操作 dash alt 特征 lac 來看 可執行文件 跑過很多次openposeDemo了,不管是video、Webcam還是Images,都是運行結果一閃而過,然而我們所要的肯定不是只看一下運行結果就完事的,很多情況下,我們都希望能夠把運行結果的圖像
【python-excel】Selenium+python自動化之讀取Excel數據(xlrd)
logs title .html selenium2 ref target targe pos 數據 Selenium2+python自動化之讀取Excel數據(xlrd) 轉載地址:http://www.cnblogs.com/lingzeng86/p/6793398.h