【问题标题】:caffe pixel-wise classification / regressioncaffe 逐像素分类/回归
【发布时间】: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


    【解决方案1】:

    首先,你的问题不是regression,而是classification

    如果你想教网络识别圆形和矩形,你必须创建一个不同的数据集——图像和标签,例如:circle - 0 and rectangle - 1。您可以通过制作包含图像路径和图像标签的文本文件来做到这一点,例如:/path/circle1.png 0 /path/circle2.png 0 /path/rectangle1.png 1 /path/rectangle1.png 1。对于像您这样的问题,这是一个不错的tutorial。祝你好运。

    【讨论】:

    • 不不!我想做一个像素级的分类或回归任务。只是一个简单的。我知道您可以通过正常的分类任务来做到这一点,但我想进行逐像素分类。我的想法是进行细分/分类。你知道我的意思吗?
    • 你也可以想到:我在一张图片中有圆形和矩形,我要做分割!我只想能够做一个非常简单的逐像素预测任务,因为我知道如何进行标准分类,但我想稍后再进行逐像素预测并完成更困难的任务!
    • 所以你可以通过segmentation 来做。对于每个图像(圆形/矩形),您必须制作一个 GT 图像(0-255)。每个图像中的类数为 2(背景和几何形状),所以 num_output: 2。将背景设置为 0,形状设置为 1。祝你好运。
    • 好的,但我想我会为背景设置 0,为圆形设置 1,为矩形设置 2? GT 图像将只有值 0,1,2 而不是 0,1,...255 对吗?以及如何检索输出图像,因为您检索的是 3 x 高 x 宽的图像?
    • 如果你希望两个形状都在同一个图像中,你将拥有 3 个类 -> num_output: 2。这是一个 [tutorial][1] 用于像您这样的分割问题。 [1]:mi.eng.cam.ac.uk/projects/segnet
    猜你喜欢
    • 2016-02-20
    • 2017-04-16
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 2016-11-21
    • 2015-07-23
    • 2016-12-25
    相关资源
    最近更新 更多