2016-01-20 63 views
0

我建立在Windows朱古力深度學習庫:未知池方法測試與CUDA朱古力時,但如在這個環節不cudnn

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

我停用cuDNN因爲我的nVidia顯卡因此未支持這一點,將目標架構改爲費米架構。

我建朱古力作爲靜態庫的測試項目中使用它如下圖所示:

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); 
} 

但訪問文件時,我得到一個錯誤:pooling_layer.cu的功能描述如下:

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; 
} 

並獲取消息"Unknown pooling method.",如下圖所示: Execution of the testing project to classify one given image

n我的項目的正式執行如下圖所示: enter image description here 有人可以給我一個關於可能的解決方案的想法嗎?

+0

@talonmies:我認爲這也是cuda相關的問題,爲什麼你的emove cuda標籤?崩潰是在cuda代碼中生成的,而不是普通的C++代碼。 – ProEns08

+1

如果你看看你的「崩潰」和你發佈的代碼部分,你可以清楚地看到它是一個運行時「功能未實現」的錯誤。這與CUDA編程無關。這是一個咖啡問題,就是這樣。我爲什麼要刪除CUDA標籤。 – talonmies

+0

@talonmies:好的,謝謝。 – ProEns08

回答

1

默認情況下應該是max pooling的池層被翻譯成其他層。您可以在pooling_layer.cu (line 163)處添加斷點或在該行之前添加cout << this->layer_param_.pooling_param().pool() << endl;以查看它正在使用的池層。我想這不等於PoolingParameter_PoolMethod_MAX

我不知道爲什麼會發生,也許有一些錯誤的prototxt文件或的protobuf。 A 野蠻欺騙將重疊line 206line 165-176爲了強制使用max pooling

+0

感謝您的信息,+1。我正在嘗試獲取池參數。 – ProEns08