Caffe LeNet错误检查失败:shape [i]> = 0(-1对0)

时间:2016-05-28 02:54:32

标签: caffe lmdb

我为输入创建了一个lmdb数据库,为标签创建了另一个数据库。

输入的形状为(3,3,1226),标签为(1,1,1226),为(C,H,W)。

运行以下代码时:

import caffe

caffe.set_device(0)
caffe.set_mode_gpu()
solver = caffe.SGDSolver('my_lenet_solver.prototxt')

我收到了以下错误消息:

I0527 23:40:39.806207   551 layer_factory.hpp:77] Creating layer data
I0527 23:40:39.807922   551 net.cpp:106] Creating Layer data
I0527 23:40:39.807942   551 net.cpp:411] data -> data
I0527 23:40:39.808825   570 db_lmdb.cpp:38] Opened lmdb train_x
I0527 23:40:39.830607   551 data_layer.cpp:41] output data size: 35,3,3,1226
I0527 23:40:39.835955   551 base_data_layer.cpp:69] Initializing prefetch
I0527 23:40:39.836031   551 base_data_layer.cpp:72] Prefetch initialized.
I0527 23:40:39.836050   551 net.cpp:150] Setting up data
I0527 23:40:39.836071   551 net.cpp:157] Top shape: 35 3 3 1226 (386190)
I0527 23:40:39.836074   551 net.cpp:165] Memory required for data: 1544760
I0527 23:40:39.836097   551 layer_factory.hpp:77] Creating layer label
I0527 23:40:39.836238   551 net.cpp:106] Creating Layer label
I0527 23:40:39.836254   551 net.cpp:411] label -> label
I0527 23:40:39.837540   572 db_lmdb.cpp:38] Opened lmdb train_y
I0527 23:40:39.838732   551 data_layer.cpp:41] output data size: 35,1,1,1226
I0527 23:40:39.840147   551 base_data_layer.cpp:69] Initializing prefetch
I0527 23:40:39.840224   551 base_data_layer.cpp:72] Prefetch initialized.
I0527 23:40:39.840236   551 net.cpp:150] Setting up label
I0527 23:40:39.840263   551 net.cpp:157] Top shape: 35 1 1 1226 (42910)
I0527 23:40:39.840272   551 net.cpp:165] Memory required for data: 1716400
I0527 23:40:39.840286   551 layer_factory.hpp:77] Creating layer conv1
I0527 23:40:39.840348   551 net.cpp:106] Creating Layer conv1
I0527 23:40:39.840363   551 net.cpp:454] conv1 <- data
I0527 23:40:39.840409   551 net.cpp:411] conv1 -> conv1
I0527 23:40:39.841969   571 data_layer.cpp:102] Prefetch batch: 4 ms.
I0527 23:40:39.842005   571 data_layer.cpp:103]      Read time: 0.076 ms.
I0527 23:40:39.842010   571 data_layer.cpp:104] Transform time: 3.263 ms.
I0527 23:40:39.842770   576 data_layer.cpp:102] Prefetch batch: 0 ms.
I0527 23:40:39.842788   576 data_layer.cpp:103]      Read time: 0.06 ms.
I0527 23:40:39.842793   576 data_layer.cpp:104] Transform time: 0.472 ms.
I0527 23:40:39.845005   576 data_layer.cpp:102] Prefetch batch: 0 ms.
I0527 23:40:39.845021   576 data_layer.cpp:103]      Read time: 0.063 ms.
I0527 23:40:39.845031   576 data_layer.cpp:104] Transform time: 0.566 ms.
I0527 23:40:39.846081   576 data_layer.cpp:102] Prefetch batch: 0 ms.
I0527 23:40:39.846099   576 data_layer.cpp:103]      Read time: 0.058 ms.
I0527 23:40:39.846107   576 data_layer.cpp:104] Transform time: 0.593 ms.
I0527 23:40:39.846982   571 data_layer.cpp:102] Prefetch batch: 3 ms.
I0527 23:40:39.847000   571 data_layer.cpp:103]      Read time: 0.048 ms.
I0527 23:40:39.847005   571 data_layer.cpp:104] Transform time: 2.707 ms.
I0527 23:40:39.861234   571 data_layer.cpp:102] Prefetch batch: 7 ms.
I0527 23:40:39.861282   571 data_layer.cpp:103]      Read time: 0.083 ms.
I0527 23:40:39.861294   571 data_layer.cpp:104] Transform time: 4.307 ms.
F0527 23:40:40.031951   551 blob.cpp:32] Check failed: shape[i] >= 0 (-1 vs. 0) 
*** Check failure stack trace: ***

我的火车protobuf是:

layer {
  name: "data"
  type: "Data"
  top: "data"
  transform_param {
    scale: 0.00392156862745
  }
  data_param {
    source: "train_x"
    batch_size: 35
    backend: LMDB
  }
}
layer {
  name: "label"
  type: "Data"
  top: "label"
  transform_param {
    scale: 0.00392156862745
  }
  data_param {
    source: "train_y"
    batch_size: 35
    backend: LMDB
  }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  convolution_param {
    num_output: 20
    kernel_size: 5
    weight_filler {
      type: "xavier"
    }
  }
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  convolution_param {
    num_output: 50
    kernel_size: 5
    weight_filler {
      type: "xavier"
    }
  }
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "fc1"
  type: "InnerProduct"
  bottom: "pool2"
  top: "fc1"
  inner_product_param {
    num_output: 500
    weight_filler {
      type: "xavier"
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "fc1"
  top: "fc1"
}
layer {
  name: "score"
  type: "InnerProduct"
  bottom: "fc1"
  top: "score"
  inner_product_param {
    num_output: 1226
    weight_filler {
      type: "xavier"
    }
  }
}
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "score"
  bottom: "label"
  top: "loss"
}

我不知道出现此错误有什么问题。 我的输入有三行,标签只有一行吗?

谢谢!

1 个答案:

答案 0 :(得分:4)

我发现了问题:内核大小错误:
因为我有3行输入图像,而我的kernel_size大小为5,大于图像大小。