首页 文章

使用来自c的经过训练的caffe网的错误结果

提问于
浏览
1

我尝试使用我训练过的caffe net和我的C数据 . 我为部署实现了标准的caffe示例 classification.cpp . 在使用python脚本的训练/测试阶段,网络达到了准确度= 0.93,但现在当我去部署时,我得到了一些奇怪的结果 . 我有两节课:

  • 环境

  • 对象

我需要得到物体检测的概率 . 我相信如果网络在FC层有两个输出(prob1 prob2 == 1.0f),结果将以 Softmax 输出blob中的两个prob的形式呈现,但结果令人费解 . 在输出向量中,我为每个图像得到 two identical values . 这是输入和输出层:

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 . 该值通常在输出向量中找到 . 我究竟做错了什么?

1 回答

  • 1

    因此,问题超出了本主题的范围 . 这是关于STL和Qt向量之间的差异 . 原始代码

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

    代替

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

    解决了这个问题 .

相关问题