Problem with understanding input dimentions and SoftmaxWithLossLayer

60 views
Skip to first unread message

unit....@gmail.com

unread,
Jul 13, 2016, 2:04:34 PM7/13/16
to Caffe Users
Hello,

I'm trying to use my own trained network with my own data from C++. I trained and tested network on ".jpg"-data with "ImageData"-layers and then implemented basic caffe example "classification.cpp" to pass images through memory one-by-one. As the result I need to know the prob for 2 classes: 1 - object, 2 - environment.

My TEST input layer is:

layer {
    name
: "data"
    top
:  "data"
    top
:  "label"
    type
: "ImageData"
    include
{
        phase
: TEST
   
}
    image_data_param
{
        source
: "/home/esterlein/Orlanet/test_data.txt"
        batch_size
: 5
        new_height
: 256
        new_width
: 256
        shuffle
: true
   
}
    transform_param
{
        crop_size
: 227
        mirror
: true
   
}
}

Now my input layer for the regular purposes looks like:

layer {
    name
: "data"
    top
:  "data"
    top
:  "label"
    type
: "Input"
    input_param
{ shape: { dim: 1 dim: 3 dim: 256 dim: 256 }}
}

Output layers:

layer {
    name
: "fc6"
    top
:  "fc6"
    type
: "InnerProduct"
    bottom
: "drop5"
    inner_product_param
{
        num_output
: 2
        weight_filler
{
            type
: "xavier"
            std
: 0.1
       
}
   
}
}

layer
{
    name
: "prob"
    top
:  "prob"
    type
: "SoftmaxWithLoss"
    bottom
: "fc6"
    bottom
: "label"
}

layer
{
    name
: "accuracy"
    top
:  "accuracy"
    type
: "Accuracy"
    bottom
: "fc6"
    bottom
: "label"
    include
{
        phase
: TEST
   
}
}

In the testing phase, the net has achieved accuracy=0.93, but now in regular use with C++ I can't figure out some basic concept and get an error while parsing the model.

Check failure stack trace:

...

caffe::SoftmaxWithLossLayer<>::Reshape()

caffe::Net<>::Init() caffe::Net<>::Net()

...

Check failed: outer_num_ * inner_num_ == bottom[1]->count() (1 vs. 196608) Number of labels must match number of predictions; e.g., if softmax axis == 1 and prediction shape is (N, C, H, W), label count (number of labels) must be N*H*W, with integer values in {0, 1, ..., C-1}.


Ok, 1x3x256x256 = 196608, but why I need this label count?

I have a file "labels.txt" as in the example "classification.cpp":


environment
object


Why labels != classes?

What should I do with SoftmaxWithLoss and input dimentions?

unit....@gmail.com

unread,
Jul 14, 2016, 12:48:15 PM7/14/16
to Caffe Users
Reply all
Reply to author
Forward
0 new messages