ProEns08
ProEns08

Reputation: 1914

Unknown pooling method when testing caffe with cuda but not cudnn

I built the caffe deep learning library in windows as shown in this link:

https://initialneil.wordpress.com/2015/07/15/caffe-vs2013-opencv-in-windows-tutorial-i/

I deactivated the cuDNN because my nvidia card didnot support this and changed the targert architecture to fermi architecture.

I built caffe as static library to use it in the test project shown below:

int main(int argc, char** argv)
{
// get a testing image and display
Mat img = imread(CAFFE_ROOT + "/examples/images/mnist_5.png");
cvtColor(img, img, CV_BGR2GRAY);
imshow("img", img);
waitKey(1);

// Set up Caffe
Caffe::set_mode(Caffe::GPU);
int device_id = 0;
Caffe::SetDevice(device_id);
LOG(INFO) << "Using GPU";

// Load net
Net<float> net(CAFFE_ROOT + "/examples/mnist/lenet_test-memory-1.prototxt");
string model_file = CAFFE_ROOT + "/examples/mnist/lenet_iter_10000.caffemodel";
net.CopyTrainedLayersFrom(model_file);

// set the patch for testing
vector<Mat> patches;
patches.push_back(img);

// push vector<Mat> to data layer
float loss = 0.0;
boost::shared_ptr<MemoryDataLayer<float> > memory_data_layer;
memory_data_layer = boost::static_pointer_cast<MemoryDataLayer<float>>(net.layer_by_name("data"));

vector<int> labels(patches.size());
memory_data_layer->AddMatVector(patches, labels);

// Net forward

 //ERROR IN THE LINE BELOW
const vector<Blob<float>*> & results = net.ForwardPrefilled(&loss);// HERE THE ERROR
float *output = results[1]->mutable_cpu_data();

// Display the output
for (int i = 0; i < 10; i++) {
    printf("Probability to be Number %d is %.3f\n", i, output[i]);
}
waitKey(0);
}

But I get an error when accessing the file: pooling_layer.cu in the function described below:

template <typename Dtype>
 void PoolingLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
  vector<Blob<Dtype>*>* top) {
  const Dtype* bottom_data = bottom[0]->gpu_data();
 Dtype* top_data = (*top)[0]->mutable_gpu_data();
int count = (*top)[0]->count();
 // We'll output the mask to top[1] if it's of size >1.
 const bool use_top_mask = top->size() > 1;
 int* mask = NULL;
 Dtype* top_mask = NULL;
 switch (this->layer_param_.pooling_param().pool()) {
case PoolingParameter_PoolMethod_MAX:
   if (use_top_mask) {
  top_mask = (*top)[1]->mutable_gpu_data();
  } else {
   mask = max_idx_.mutable_gpu_data();
  }
  // NOLINT_NEXT_LINE(whitespace/operators)
  MaxPoolForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>       (
    count, bottom_data, bottom[0]->num(), channels_,
    height_, width_, pooled_height_, pooled_width_, kernel_h_,
    kernel_w_, stride_h_, stride_w_, pad_h_, pad_w_, top_data,
    mask, top_mask);
break;
  case PoolingParameter_PoolMethod_AVE:
   // NOLINT_NEXT_LINE(whitespace/operators)
   AvePoolForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
      count, bottom_data, bottom[0]->num(), channels_,
    height_, width_, pooled_height_, pooled_width_, kernel_h_,
    kernel_w_, stride_h_, stride_w_, pad_h_, pad_w_, top_data);
  break;
   case PoolingParameter_PoolMethod_STOCHASTIC:
   if (Caffe::phase() == Caffe::TRAIN) {
   // We need to create the random index as well.
   caffe_gpu_rng_uniform(count, Dtype(0), Dtype(1),
                        rand_idx_.mutable_gpu_data());
    // NOLINT_NEXT_LINE(whitespace/operators)
    StoPoolForwardTrain<Dtype><<<CAFFE_GET_BLOCKS(count),
                               CAFFE_CUDA_NUM_THREADS>>>(
      count, bottom_data, bottom[0]->num(), channels_,
      height_, width_, pooled_height_, pooled_width_, kernel_h_,
      kernel_w_, stride_h_, stride_w_,
      rand_idx_.mutable_gpu_data(), top_data);
   } else {
    // NOLINT_NEXT_LINE(whitespace/operators)
     StoPoolForwardTest<Dtype><<<CAFFE_GET_BLOCKS(count),
                              CAFFE_CUDA_NUM_THREADS>>>(
      count, bottom_data, bottom[0]->num(), channels_,
      height_, width_, pooled_height_, pooled_width_, kernel_h_,
      kernel_w_, stride_h_, stride_w_, top_data);
  }
  break;
  default:
    LOG(FATAL) << "Unknown pooling method.";
   }
   CUDA_POST_KERNEL_CHECK;
}

And get the message "Unknown pooling method." as shown in the window below: Execution of the testing project to classify one given image

The normal execution of my project is described in the image below: enter image description here Could someone give me an idea about the possible solution?

Upvotes: 0

Views: 417

Answers (1)

Neil Z. Shao
Neil Z. Shao

Reputation: 752

The pooling layer which by default should be max pooling was translated into some other layers. You might add a breakpoint at pooling_layer.cu (line 163) or add cout << this->layer_param_.pooling_param().pool() << endl; before that line to see what pooling layer it was using. I guess it doesn't equal to PoolingParameter_PoolMethod_MAX here.

I'm not sure why it happened, maybe there some error in the prototxt file or the protobuf. A brutal trick would be overlapping line 206 with line 165-176 in order to force using max pooling.

Upvotes: 1

Related Questions