2015-06-14 108 views
1

我年齡分類基礎上,開源在here 工作的Python代碼具有如何從訓練圖像創建caffemodel文件及其標籤?

age_net_pretrained='./age_net.caffemodel' 
age_net_model_file='./deploy_age.prototxt' 
age_net = caffe.Classifier(age_net_model_file, age_net_pretrained, 
     channel_swap=(2,1,0), 
     raw_scale=255, 
     image_dims=(256, 256)) 

在其.prototxt文件,如下圖所示。我仍然是一個文件,是".caffemodel"。作爲源代碼,他之前提供過。但是,我想基於我的臉部數據庫再次創建它。你可以有任何教程或一些方法來創建它?我假設我有包括100幅圖像和劃分的文件夾圖像所屬的每個年齡組(1對1)如

image1.png 1 
image2.png 1 
.. 
image10.png 1 
image11.png 2 
image12.png 2 
... 
image100.png 10 

這是prototxt文件。在此先感謝

name: "CaffeNet" 
input: "data" 
input_dim: 1 
input_dim: 3 
input_dim: 227 
input_dim: 227 
layers { 
    name: "conv1" 
    type: CONVOLUTION 
    bottom: "data" 
    top: "conv1" 
    convolution_param { 
    num_output: 96 
    kernel_size: 7 
    stride: 4 
    } 
} 
layers { 
    name: "relu1" 
    type: RELU 
    bottom: "conv1" 
    top: "conv1" 
} 
layers { 
    name: "pool1" 
    type: POOLING 
    bottom: "conv1" 
    top: "pool1" 
    pooling_param { 
    pool: MAX 
    kernel_size: 3 
    stride: 2 
    } 
} 
layers { 
    name: "norm1" 
    type: LRN 
    bottom: "pool1" 
    top: "norm1" 
    lrn_param { 
    local_size: 5 
    alpha: 0.0001 
    beta: 0.75 
    } 
} 
layers { 
    name: "conv2" 
    type: CONVOLUTION 
    bottom: "norm1" 
    top: "conv2" 
    convolution_param { 
    num_output: 256 
    pad: 2 
    kernel_size: 5 
    } 
} 
layers { 
    name: "relu2" 
    type: RELU 
    bottom: "conv2" 
    top: "conv2" 
} 
layers { 
    name: "pool2" 
    type: POOLING 
    bottom: "conv2" 
    top: "pool2" 
    pooling_param { 
    pool: MAX 
    kernel_size: 3 
    stride: 2 
    } 
} 
layers { 
    name: "norm2" 
    type: LRN 
    bottom: "pool2" 
    top: "norm2" 
    lrn_param { 
    local_size: 5 
    alpha: 0.0001 
    beta: 0.75 
    } 
} 
layers { 
    name: "conv3" 
    type: CONVOLUTION 
    bottom: "norm2" 
    top: "conv3" 
    convolution_param { 
    num_output: 384 
    pad: 1 
    kernel_size: 3 
    } 
} 
layers{ 
    name: "relu3" 
    type: RELU 
    bottom: "conv3" 
    top: "conv3" 
} 
layers { 
    name: "pool5" 
    type: POOLING 
    bottom: "conv3" 
    top: "pool5" 
    pooling_param { 
    pool: MAX 
    kernel_size: 3 
    stride: 2 
    } 
} 
layers { 
    name: "fc6" 
    type: INNER_PRODUCT 
    bottom: "pool5" 
    top: "fc6" 
    inner_product_param { 
    num_output: 512 
    } 
} 
layers { 
    name: "relu6" 
    type: RELU 
    bottom: "fc6" 
    top: "fc6" 
} 
layers { 
    name: "drop6" 
    type: DROPOUT 
    bottom: "fc6" 
    top: "fc6" 
    dropout_param { 
    dropout_ratio: 0.5 
    } 
} 
layers { 
    name: "fc7" 
    type: INNER_PRODUCT 
    bottom: "fc6" 
    top: "fc7" 
    inner_product_param { 
    num_output: 512 
    } 
} 
layers { 
    name: "relu7" 
    type: RELU 
    bottom: "fc7" 
    top: "fc7" 
} 
layers { 
    name: "drop7" 
    type: DROPOUT 
    bottom: "fc7" 
    top: "fc7" 
    dropout_param { 
    dropout_ratio: 0.5 
    } 
} 
layers { 
    name: "fc8" 
    type: INNER_PRODUCT 
    bottom: "fc7" 
    top: "fc8" 
    inner_product_param { 
    num_output: 8 
    } 
} 
layers { 
    name: "prob" 
    type: SOFTMAX 
    bottom: "fc8" 
    top: "prob" 
} 

回答

3

要獲得caffemodel您需要訓練網絡。該原型文件僅用於部署該模型,不能用於訓練它。

您需要添加一個指向數據庫的數據層。如您所述,要使用文件列表,圖層的來源應該是HDF5。你可能想要添加一個transform_param和平均值。爲了提高效率,圖像文件可以由LMDB或LevelDB數據庫替換。

在網絡結束時,您將不得不用「損失」層替換'概率'層。是這樣的:

層{ 名: 「損失」 類型:SoftmaxWithLoss 底部: 「FC8」 頂部: 「損失」 }

層目錄可以在這裏找到:

http://caffe.berkeleyvision.org/tutorial/layers.html

或者,因爲您的網絡是一個衆所周知的...請看這個教程:P。

http://caffe.berkeleyvision.org/gathered/examples/imagenet.html

培訓正確prototxt文件包含在朱古力( 'train_val.prototxt')。

+0

你說這個prototxt文件只是部署模型。那是因爲指定的第一個input_dim是1,並且訓練您需要指定合理的批量大小? – omatai

+0

嗨,我是這個領域的新手。我想創建自己的.caffemodel並將其轉換爲CoreML。我會怎麼做?請指導我。 – MacKa

相關問題