URGENT!! Caffe when embedded in C++ program code, convolution layers dont work

78 views
Skip to first unread message

soumali roychowdhury

unread,
Mar 15, 2017, 7:59:58 PM3/15/17
to Caffe Users
I have a C++ code and I am using the caffe library. My C++ code reads a model_file.prototxt to define the caffe network and everytime I feed inputs to the networ manually using the C++ code into the input_param.

The input_param is like this
input_param {

    shape: { 
      dim: 1
      dim: 3 
      dim: 32
      dim: 32
     } 

When I use, inner_product layers I can get correct output of forward and backward but the convolutional layers like this doesnot work
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  convolution_param {
    num_output: 64
    pad: 2
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}


Can some one please please help me

soumali roychowdhury

unread,
Mar 16, 2017, 7:19:30 AM3/16/17
to Caffe Users
Can someone like the authors of caffe give me some immediate solution...Please

Daniel Moodie

unread,
Mar 16, 2017, 1:58:12 PM3/16/17
to Caffe Users
I'm going to need a lot more clarity as to the problem.
What do you mean it doesn't work? What are the error message?  What works when it works with inner product?
How are you interfacing with the library?  Example C++ code?

soumali roychowdhury

unread,
Mar 16, 2017, 3:44:19 PM3/16/17
to Caffe Users
I have a C++ code that is aimed to solve the classification problem. I included libcaffe.a,libcaffe.so to the g++ linker. The C++ code includes caffe.hpp and it uses caffe to read the model of the network from a prototxt file, perform forward() and backward() and then returns the result from the last layer of the network to the C++ code. 

Everytime I give one coloured image to the network, take its output. So when I use innerproduct layers, it is able to classify data, for example I tried it on non image datasets like XOR dataset and IRIS dataset. But when I give it images as input and use convolutional layer in the model file, it gives me very strange results.

This is the network I want to use for the problem:
name: "ConvNet"
layer {
  name: "inputdata"
  type: "Input"
  top: "data"
  include {
    phase: TRAIN
  }
 input_param {

    shape: { 
      dim: 1
      dim: 3 
      dim: 32
      dim: 32
     } 
    }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  convolution_param {
    num_output: 64
    pad: 2
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
  relu_param{
     negative_slope: 0.00001 
  }
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  convolution_param {
    num_output: 32
    pad: 2
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
  relu_param{
     negative_slope: 0.001 
  }
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "pool2"
  top: "ip1"
  inner_product_param {
    num_output: 256
    weight_filler {
       type: "gaussian"
       std: 0.01
    }
  }
 }
layer {
  name: "relu3"
  type: "ReLU"
  bottom: "ip1"
  top: "ip1"
  relu_param{
     negative_slope: 0.001 
  }
 }
layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top:  "ip2"
  inner_product_param {
    num_output: 1
    weight_filler {
       type: "gaussian"
       std: 0.01
    }
  } 
 }
layer {
  name: "sig"
  type: "Sigmoid"
  bottom: "ip2"
  top: "ip2"
  loss_weight: 1
 }
Reply all
Reply to author
Forward
0 new messages