2016-07-22 2 views
1

C++의 데이터로 훈련 된 카페 넷을 사용하려고했습니다. 배포를 위해 표준 카페 예제 classification.cpp을 구현했습니다. 파이썬 스크립트를 사용하는 기차/테스트 단계에서는 정확도 = 0.93을 달성했지만 지금은 배포 할 때 이상한 결과가 나타납니다. 나는 두 개의 클래스가 있습니다C++에서 훈련 된 caffe net을 사용하여 잘못된 결과가 발생했습니다.

  • 환경
  • 객체

을 나는 물체 감지의 확률값을 얻을 필요가있다. 나는 그물이 FC 층 (prob1 + prob2 == 1.0f)에서 2 개의 출력을 가지고 있지만 결과가 수수께끼라면 Softmax 출력 얼룩에 두 가지 probs의 형태로 결과가 나타날 것이라고 믿었다. 출력 벡터에서 나는 모든 이미지에 대해 두 개의 동일한 값 을 얻습니다.

layer { 
    name: "data" 
    top: "data" 
    type: "Input" 
    input_param { shape: { dim: 1 dim: 3 dim: 227 dim: 227 }} 
} 
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: "Softmax" 
    bottom: "fc6" 
} 

내 C++ 통상 사용 코드 샘플 :

Blob<float>* input_layer = m_net->input_blobs()[0]; 
input_layer->Reshape(1, m_numChannels, m_inputGeometry.height, m_inputGeometry.width); 
m_net->Reshape(); 
std::vector<cv::Mat> input_channels; 
Blob<float>* input_layer = m_net->input_blobs()[0]; 
int width = input_layer->width(); 
int height = input_layer->height(); 
float* input_data = input_layer->mutable_cpu_data(); 

for(int i = 0; i < input_layer->channels(); ++i){ 
    cv::Mat channel(height, width, CV_32FC1, input_data); 
    input_channels->push_back(channel); 
    input_data += width * height; 
} 

cv::split(image_float, *input_channels); 
m_net->Forward(); 
Blob<float>* output_layer = m_net->output_blobs()[0]; 
const float* begin = output_layer->cpu_data(); 
const float* end = begin + output_layer->channels(); 
QVector<float> output = QVector<float>(end - begin, *begin); 

는 또한 결과가 랜덤 (각 클래스에 대한 중복)과 유사한, 작은 확률 여기서 입출력 층인 값은 마법 0.443142입니다. 이 값은 출력 벡터에서 종종 발견됩니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

+0

귀하의 입력 데이터가 바로 이미지입니까? 그런데 왜 완전히 연결된 레이어 만 사용하고 있습니까? 컨벌루션 레이어가 훨씬 잘 작동합니다. –

+0

@ Matias 여기에서는 입력 및 출력 레이어 만 설명합니다. 네트워크에는 컨벌루션 레이어도 포함됩니다. 내 문제는 정확성에 관한 것이 아니라고 생각합니다. – esterlein

답변

1

그래서이 문제는 주제의 범위를 벗어났습니다. 그것은 STL과 Qt 벡터의 차이점입니다. 원래 코드는

std::vector<float> output(begin, end); 

대신

QVector<float> output(end - begin, *begin); 

이 문제를 해결합니다.

관련 문제