導航:首頁 > 程序命令 > caffe命令

caffe命令

發布時間:2023-07-14 23:40:33

Ⅰ Caffe訓練自己的imagenet,ubuntu提示killed

1、准備數據。
假設已經下載好數據集和驗證集,存儲路徑為:
/path/to/imagenet/train/n01440764/n01440764_10026.JPEG
/path/to/imagenet/val/ILSVRC2012_val_00000001.JPEG
首選需要創建一個txt文件,列舉出所有圖像以及對應的lable,caffe包「python/caffe/imagenet/ilsvrc_2012_train.txt」和「ilsvrc_2012_val.txt」兩個文件分別是標好的訓練集和驗證集的文件,共分為1000類。
還需要注意的是,所有的圖像都需要歸一到同樣的尺寸。

2、轉化生成訓練集。
運行下面的命令
GLOG_logtostderr=1 examples/convert_imageset.bin /path/to/imagenet/train/ python/caffe/imagenet/ilsvrc_2012_train.txt /path/to/imagenet-train-leveldb
生成文件存儲在「/path/to/imagenet-train_leveldb」路徑下。

3、計算圖像均值。
執行命令:
examples/demo_compute_image_mean.bin /path/to/imagenet-train-leveldb /path/to/mean.binaryproto
第一個參數是執行腳本代碼,第二個參數是上一步生成的數據集,第三個參數是存儲圖像均值的目錄路徑。

4、定義網路。
ImageNet的網路定義在「examples/imagenet.prototxt」文件中,使用時需要修改裡面source和meanfile變數的值,指向自己文件的路徑。
仔細觀察imagenet.prototxt和imagenet_val.prototxt文件可以發現,訓練和驗證的參數大部分都相同,不同之處在於初始層和最後一層。訓練時,使用softmax_loss層來計算損失函數和初始化後向傳播,驗證時,使用accuracy層來預測精確度。
在文件「examples/imagenet_solver.prototxt」中定義solver協議,同樣需要修改train_net和test_net的路徑。

5、訓練網路。
執行命令:
GLOG_logtostderr=1 examples/train_net.bin examples/imagenet_solver.prototxt

6、在python中使用已經訓練好的模型。
Caffe只提供封裝好的imagenet模型,給定一副圖像,直接計算出圖像的特徵和進行預測。首先需要下載模型文件。
Python代碼如下:

[python] view plain print?
from caffe import imagenet
from matplotlib import pyplot
# Set the right path to your model file, pretrained model
# and the image you would like to classify.
MODEL_FILE = 'examples/imagenet_deploy.prototxt'
PRETRAINED = '/home/jiayq/Downloads/caffe_reference_imagenet_model』
IMAGE_FILE = '/home/jiayq/lena.png'

net = imagenet.ImageNetClassifier(MODEL_FILE, PRETRAINED)
#預測
prediction = net.predict(IMAGE_FILE)
#繪制預測圖像
print 'prediction shape:', prediction.shape
pyplot.plot(prediction)
prediction shape: (1000,)
[<matplotlib.lines.Line2D at 0x8faf4d0>] #結果如圖所示

圖上的橫軸表示的label,縱軸表示在該類別上的概率,有圖我們看到,lena.jpg被分到了」sombrero」這組,結果還算準確。

閱讀全文

與caffe命令相關的資料

熱點內容
釣魚黑坑下什麼app 瀏覽:938
windows軟體編譯為linux程序 瀏覽:270
方舟編譯支持應用 瀏覽:422
華為雲伺服器可以遠程別的電腦嗎 瀏覽:7
單片機百度百科 瀏覽:230
安卓回聲效果發簡訊怎麼弄 瀏覽:166
windows7文件夾屬性沒有位置 瀏覽:949
單片機632什麼意思 瀏覽:119
奢侈品哪個app買最便宜 瀏覽:665
編譯原理意思 瀏覽:329
哪裡下載帶有加密版志願二維碼 瀏覽:393
python讀串口 瀏覽:171
Pdf修改文本 瀏覽:660
電力行業縱向加密技術原理 瀏覽:49
活塞壓縮機基礎 瀏覽:706
么解手機的壓縮包 瀏覽:767
如何開通加密貨幣 瀏覽:148
北京修理伺服器雲主機 瀏覽:204
python程序設計主要思路 瀏覽:897
jar包通過如何在伺服器運行 瀏覽:378