Win10 安裝 digits

安裝caffe配置python接口

接下來就按照官方教程來安裝了。。。

1. If the installation process complains compiler not found, you need to install Microsoft Visual C++ Compiler for Python 2.7, downloaded at (https://www.microsoft.com/en-us/download/details.aspx?id=44266). We recommend installing it byphp

msiexec /i VCForPython27.msi ALLUSERS=1

若是提示找不到python 路徑,則 python python_path.pyhtml

import sys


from _winreg import *

# tweak as necessary 
version = sys.version[:3] 
installpath = sys.prefix  
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)

def RegisterPy():
    print "begin RegisterPy "
    try:
        print "open key : %s"%regpath
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
    except EnvironmentError as e:    
        try:           
            reg = CreateKey(HKEY_CURRENT_USER, regpath) 
            SetValue(reg, installkey, REG_SZ, installpath) 
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg) 
        except: 
            print "*** EXCEPT: Unable to register!" 
            return             
        
        print "--- Python", version, "is now registered!" 
        return

   
    if (QueryValue(reg, installkey) == installpath and 
        QueryValue(reg, pythonkey) == pythonpath): 
            CloseKey(reg) 
            print "=== Python", version, "is already registered!" 
            return CloseKey(reg) 

    print "*** ERROR:Unable to register!" 
    print "*** REASON:You probably have another Python installation!"

def UnRegisterPy():
    #print "begin UnRegisterPy "
    try:
        print "open HKEY_CURRENT_USER key=%s"%(regpath)
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
        #reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
    except EnvironmentError:  
        print "*** Python not registered?!"
        return
    try:
       DeleteKey(reg, installkey)
       DeleteKey(reg, pythonkey)
       DeleteKey(HKEY_LOCAL_MACHINE, regpath)
    except:
       print "*** Unable to un-register!"
    else:
       print "--- Python", version, "is no longer registered!"            

if __name__ == "__main__":  
    RegisterPy()
View Code

2. 安裝Graphviz, Graphviz is available at (www.graphviz.org/Download.php). Please note this site is not always available online. The installation directory can not contain space, so don't install it under the regular 'c:\Program Files (x86)' directory. Try something like 'c:\graphviz' instead. When the installation directory contains space, pydot could not launch the dot.exe file, even it has no problem finding it. Add the c:\graphviz\bin directory to your PATH.python

3. Clone DIGITS from github.com (https://github.com/nvidia/digits). From the command prompt (run as administrator) and cd to DIGITS directory. Then typegit

python -m pip install -r requirements.txt

4. You may see error about Pillow, like ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting If this happens, download Pillow Windows Installer (Pillow-3.1.1.win-amd64-py2.7.exe) at https://pypi.python.org/pypi/Pillow/3.1.1 and run the exectuables. After installing Pillow in the above way, rungithub

python -m pip install -r requirements.txt

After the above command, check if all required Python dependencies are met by comparing requirements.txt and output of the following command.flask

python -m pip list

5. If gevent is not v1.0.2, install it from the whl file, downloaded previously from (http://www.lfd.uci.edu/~gohlke/pythonlibs/).windows

python -m pip install gevent-1.0.2-cp27-none-win_amd64.whl

6. It should uninstall the gevent you had, and install gevent 1.0.2.瀏覽器

Because readline is not available in Windows, you need to install one additional Python package.網絡

python -m pip install pyreadline

 

值得提出的是最後一步運行digits的命令發生了變化

python -m digits

而後是缺什麼安裝什麼。。。

例如:app

 No module named wtforms

pip install wtforms

 Invalid version: 'CAFFE_VERSION'

 windows/caffe/caffe.vcxproj

     <PostBuildEvent>
        <Command>"$(ScriptsDir)\FixGFlagsNaming.cmd" "$(OutDir)" $(Configuration)</Command>
      </PostBuildEvent>
 +    <ClCompile>
 +      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);CAFFE_VERSION=1.0.0-rc3</PreprocessorDefinitions>
 +    </ClCompile>
    </ItemDefinitionGroup>
    <ItemGroup>
      <ClCompile Include="..\..\tools\caffe.cpp" />

 windows/pycaffe/pycaffe.vcxproj

   <ItemDefinitionGroup>
      <ClCompile>
        <DisableSpecificWarnings>4003</DisableSpecificWarnings>
 +      <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NDEBUG;%(PreprocessorDefinitions);CAFFE_VERSION=1.0.0-rc3</PreprocessorDefinitions>
      </ClCompile>
      <PreBuildEvent>
        <Command>"$(ScriptsDir)\PythonPreBuild.cmd" "$(SolutionDir)" "$(ProtocDir)" "$(OutDir)"</Command>

No module named flask.ext.socketio

pip install flask-socketio
pip install -I Flask==0.10.1
pip install flask-wtf

No module named lmdb

pip install lmdb

 

最後 python -m digits 啓動

打開瀏覽器輸入: localhost:5000 就能夠看到

運行mnist實例

1、準備數據,這裏感謝此博文,也能夠參照官方教程

原始數據須要的是圖片,但網上提供的mnist數據並非圖片格式的數據,所以咱們須要將它轉換成圖片才能運行。

digits提供了一個腳本文件,用於下載mnist, cifar10 和cifar100 三類數據,並轉換成png格式圖片。文件路徑爲:

DIGITS-master/download_data/__main__.py

咱們先在當前用戶的根目錄下,新建一個mnist文件夾用來保存mnist圖片。

cd C:\DIGITS-master\digits\download_data

而後執行腳本

python  __main__.py   mnist  mnist

__main__.py 帶兩個參數,第一個爲數據集名稱(可設置爲mnist, cifar10或cifar100),第二個爲輸出路徑(mnist)

執行成功後,會在mnist文件夾下,生成兩個文件夾(train文件夾和test文件夾),每一個文件夾下面就是咱們須要的圖片(10類分別放在10個子文件夾內),同時還生成了對應在圖片列表文件train.txt和test.txt

接下來,在瀏覽器上運行digits, 點擊左邊Dataset模塊的"Image"按鈕選擇「classification", 建立一個dataset

數據集

手寫體MNIST數據集的原始數據格式爲:png,每幅圖像大小爲:28×28,包含70K個手寫體數字,共10類,其中60K爲訓練用樣本(train+val),10K的測試樣本(test)。本例中,從訓練樣本中隨機抽取25%的數據做爲驗證集(val),使用digits生成的數據信息以下:

數據集屬性
Image Type Grayscale
Image Encoding png
Image Dimensions 28×28
Number of Categories 10
Number of Training Images 45002
Number of Validation Images 14998(25% of 60000)
Number of test Images 10000

 

 

 

 

 

 

 

在這個頁面的左邊,能夠設置圖片是彩色圖片仍是灰度圖片,若是提供的原始圖片大小不一致,還可用Resize Transformation功能轉換成一致大小 。從頁面中間能夠看出,系統默認將訓練圖片中的25%取出來做爲驗證集(for validation)。

若是想把用來測試的圖片,也生成lmdb, 則把「 separate test image folder" 這個選項選上。

所有設置好後,點擊"create" 按鈕,開始生成lmdb數據。

注意左上角的Job Directory(工做目錄),生成的lmdb文件就放在這個目錄下面,你們最好打開這個目錄去看看,看一下生成了些什麼文件,瞭解一下運行原理。

在這個界面,咱們還能夠可視化查看訓練和測試的圖片,以下圖:

train.txt裏面存放的是全部訓練圖片的列表清單,柱狀圖清晰地顯示了10類樣本各自的數量。點擊" Explorer the db」 便可查看圖片。

最後,點擊最左上角「 DIGITS" 連接回到網站根目錄。

 

通過前面的操做,咱們就把數據準備好了。接下來繼續。。。

2、訓練一個model,這裏感謝此博文,也能夠參考官方教程

右擊右邊Models模塊的」 Images" 按鈕 ,選擇「classification"

在打開頁面右下角能夠看到,系統提供了一個caffe model,分別爲LeNet, AlexNet, GoogLeNet, 若是使用這三個模型,則全部參數都已經設置好了,就不用再設置了。

模型參數

模型選擇LeNet(Original Paper 1998

Solver Options 意義 示例值 solver.prototxt 計算
Training epochs 迭代代數:將訓練數據反覆送入網絡訓練的次數 30(單位次數) max_iter (Training epochs)×(numtrainsamples/batchsizetrain)),如30*(45002/64)=21120
Snapshot interval (in epochs) 快照間隔:是指訓練多少次後進行一次快照記錄 1(單位次數) snapshot (numtrainsamples/batchsizetrain)×(Snapshotinterval),如:(45002/64)*1=704
Validation interval (in epochs) 驗證間隔 1(單位次數) test_interval (numtrainsamples/batchsizetrain)(Validationinterval),如:(45002/64)*1=704
Random seed 權重隨機初始化種子 [none] - -
Batch size 批處理大小 [network defaults],網絡默認值,訓練:64,測試100 - -
Solver type 優化方法 Stochastic Gradient Descent (SGD) solver_type SGD
Base Learning Rate 學習率 0.01 base_lr 0.01
Policy 學習率策略 Step Size lr_policy 「step」
Step Size 步長 33% stepsize max_iter*Step Size,如:21120×33%=6970
Gamma Gamma參數 0.1(單位0.005) gamma 0.1

在下面,系統爲咱們列舉出了本機所帶的顯卡,咱們能夠選擇其中一塊進行運行。

在最下面,輸入一個model name, 就能夠點擊create 按鈕了。若是有些選項不對,會有錯誤提示,很人性化。

在訓練過程頁面,左上角顯示了生成的配置文件名稱 (放在job目錄文件下,默認路徑爲:C:/DIGITS-master/digits/jobs/),運行過程當中保存的caffemodel快照也保存在這個目錄下面。

頁面中顯示了訓練和測試的數據信息、訓練所用的時間和gpu使用狀況以及一些實時化圖表,能夠看到訓練階段的loss, 測試階段的loss和accuracy,至關方便,甚至還能夠看到學習率的變化狀況,吃驚吧!

         

模型訓練好後,直接就能夠在下面進行測試了。

測試新來的圖片

將頁面拖到最下面,選擇Upload imager按鈕,加載一幅測試圖片。在 C:/DIGITS-master/digits/download_data/mnist/test 下面有大量的測試圖片,隨便選一張就能夠了。

也能夠經過在Image URL方框裏,輸入一張網上的圖片地址來進行測試。

加載好測試圖片,在 Show visualizations and statistics 選擇模式框上點上勾。

點擊」Classify One" 按鈕就能夠開始測試了。

若是你不是對一張圖片進行測試,而是一個測試集,則是在" Upload Image List"這個地方,選擇測試圖片的列表清單文件(如 val.txt)

系統會彈出一個新的頁面,顯示top-5的分類狀況 ,同時digits還提供了測試數據與權值的可視化和統計信息。

相關文章
相關標籤/搜索