我想在caffe中定义一个353长度memorydata图层的标签,但是简单地添加它的名称不会,因为它的默认长度是1(batch_size * 1)。
layer {
name: "data"
type: "MemoryData"
top: "data"
top: "label"
include {
phase: TRAIN
}
memory_data_param {
batch_size: 60
channels: 3
height: 224
width: 224
}
}
如何解决此问题?
答案 0 :(得分: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)