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 by

msiexec /i VCForPython27.msi ALLUSERS=1

如果提示找不到python 路徑,則 python python_path.py

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.

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

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, run

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.

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/).

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

然后是缺什么安裝什么。。。

例如:

 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實例

一、准備數據,這里感謝此博文,也可以參照官方教程

原始數據需要的是圖片,但網上提供的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" 鏈接回到網站根目錄。

 

經過前面的操作,我們就把數據准備好了。接下來繼續。。。

二、訓練一個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還提供了測試數據與權值的可視化和統計信息。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM