【发布时间】:2017-03-25 18:20:11
【问题描述】:
我想做的是做一个简单的像素分类或回归任务。因此我有一个输入图像和一个ground_truth。我想做的是做一个简单的分割任务,我有一个圆形和一个矩形。我想训练,圆形或矩形在哪里。这意味着我有一个 ground_truth 图像,在圆圈所在的所有位置都有值“1”,在矩形所在的所有位置都有值“2”。然后我以 .png 图像的形式输入我的图像和 ground_truth 图像。
然后我想我可以根据我的损失层执行回归或分类任务:我一直在使用来自 fcn alexnet 的全卷积 AlexNet
分类:
layer {
name: "upscore"
type: "Deconvolution"
bottom: "score_fr"
top: "upscore"
param {
lr_mult: 0
}
convolution_param {
num_output: 3 ## <<---- 0 = backgrund 1 = circle 2 = rectangle
bias_term: false
kernel_size: 63
stride: 32
}
}
layer {
name: "score"
type: "Crop"
bottom: "upscore"
bottom: "data"
top: "score"
crop_param {
axis: 2
offset: 18
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss" ## <<----
bottom: "score"
bottom: "ground_truth"
top: "loss"
loss_param {
ignore_label: 0
}
}
回归:
layer {
name: "upscore"
type: "Deconvolution"
bottom: "score_fr"
top: "upscore"
param {
lr_mult: 0
}
convolution_param {
num_output: 1 ## <<---- 1 x height x width
bias_term: false
kernel_size: 63
stride: 32
}
}
layer {
name: "score"
type: "Crop"
bottom: "upscore"
bottom: "data"
top: "score"
crop_param {
axis: 2
offset: 18
}
}
layer {
name: "loss"
type: "EuclideanLoss" ## <<----
bottom: "score"
bottom: "ground_truth"
top: "loss"
}
但是,这甚至不会产生我想要的结果。我认为我对逐像素分类/回归的理解有问题。你能告诉我我的错误在哪里吗?
编辑 1
对于回归,输出的检索将如下所示:
output_blob = pred['result'].data
predicated_image_array = np.array(output_blob)
predicated_image_array = predicated_image_array.squeeze()
print predicated_image_array.shape
#print predicated_image_array.shape
#print mean_array
range_value = np.ptp(predicated_image_array)
min_value = predicated_image_array.min()
max_value = predicated_image_array.max()
# make positive
predicated_image_array[:] -= min_value
if not range_value == 0:
predicated_image_array /= range_value
predicated_image_array *= 255
predicated_image_array = predicated_image_array.astype(np.int64)
print predicated_image_array.shape
cv2.imwrite('predicted_output.jpg', predicated_image_array)
这很容易,因为输出是 1 x 高 x 宽,并且这些值是实际的输出值。但是如何检索分类/ SotMaxLayer的输出,因为输出是3(标签数量)x高度x宽度。但是我不知道这个形状的内容是什么意思。
【问题讨论】:
标签: deep-learning caffe