2017-04-24 53 views
1

我想在caffe中定義一個353長度的memorydata圖層的標籤,但是簡單的添加它的名字不會,因爲它的默認長度是1(batch_size * 1 )。如何在caffe中的memorydata圖層中定義標籤尺寸

layer { 
    name: "data" 
    type: "MemoryData" 
    top: "data" 
    top: "label" 
    include { 
    phase: TRAIN 
    } 
    memory_data_param { 
    batch_size: 60 
    channels: 3 
    height: 224 
    width: 224 
    } 
} 

我該如何解決這個問題?

回答

1

默認情況下,如果將數據和標籤放在單個內存層中,caffe假定標籤是單個整數值(例如,用於單個標籤分類)。

如果您需要的標籤是一個數組,那麼你應該提供標籤作爲一個不同的數據層:

layer { 
    name: "data" 
    type: "MemoryData" 
    top: "data" 
    top: "useless1" 
    include { 
     phase: TRAIN 
    } 
    memory_data_param { 
     batch_size: 60 
     channels: 3 
     height: 224 
     width: 224 
    } 
} 

layer { 
    name: "label" 
    type: "MemoryData" 
    top: "label" 
    top: "useless2" 
    include { 
     phase: TRAIN 
    } 
    memory_data_param { 
     batch_size: 60 
     channels: 1 
     height: 1 
     width: 353 
    } 
} 

然後在python腳本填充每個訓練步驟之前,兩個載體:

numpy.copyto(net.blobs['data'].data, yourdata) #Put here your 60x3x224x224 data array 
numpy.copyto(net.blobs['label'].data, yourlabels) #Put here your 60x1x1x353 label array 
solver.step(1)