【问题标题】:Segmentation error with caffecaffe 的分割错误
【发布时间】:2016-09-12 16:50:12
【问题描述】:

我在 Windows 上使用 caffe,并且遇到了我无法确定的分段错误。它发生在程序退出时,WinDbg 说scalar deleting destructor,不知道内存分配在哪里。我的完整代码(目前是一个试图缩小范围的虚拟代码,但它只是偶尔发生):

#include <string>
#include <vector>

#include "boost/algorithm/string.hpp"
#include "google/protobuf/text_format.h"
#include <stdio.h>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include "caffe/blob.hpp"
#include "caffe/common.hpp"
#include "caffe/net.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/util/db.hpp"
#include "caffe/util/format.hpp"
#include "caffe/util/io.hpp"

using caffe::Blob;
using caffe::Caffe;
using caffe::Datum;
using caffe::Net;
using std::string;
namespace db = caffe::db;

int main(int argc, char** argv) {
    // Initialize logging with program call. First thing that needs to be done
    ::google::InitGoogleLogging(argv[0]);

    cv::Mat mean_;

    // Set Caffe to run in CPU only mode
    Caffe::set_mode(caffe::Caffe::CPU);

    std::vector<std::string> labels_;

    /*std::shared_ptr<Net<float>> caffe_test_net;*/
    Net<float>* caffe_test_net;
    caffe_test_net = new Net<float>("D:\\Development\\caffe-windows\\models\\bvlc_reference_caffenet\\deploy.prototxt", caffe::Phase::TEST);
    caffe_test_net->CopyTrainedLayersFrom("D:\\Development\\caffe-windows\\models\\bvlc_reference_caffenet\\bvlc_reference_caffenet.caffemodel");

    delete caffe_test_net;
    return 1;
}

我已经在 unique 或 shared_ptr 中使用 caffe_net 进行了测试,但这根本没有区别。我不知道如何找到手头的问题。

【问题讨论】:

    标签: c++ segmentation-fault caffe


    【解决方案1】:

    “有时发生”是一种非常常见的未定义行为,这是您真正遇到的情况。分段错误是理论上计算机可能会做的无数事情之一 - 行为实际上是未定义的。换句话说,正如他们在 USENET 上所说:“编译器让恶魔飞出你的鼻子是合法的。”它可能会起作用,它可能会做一些奇怪的事情,或者它可能会引发一些重大错误,如段错误。

    有专门用于跟踪分段错误和其他内存错误的工具。在 Linux 上,这通常是 Valgrind,而在 Windows 上,你会使用 Dr. Memory。只要您使用包含的调试符号 (-g) 进行编译,当您通过 Dr. Memory 运行可执行文件时,它应该会为您提供分段错误的堆栈跟踪。

    一旦你得到堆栈跟踪,检查它的顶部,看看代码在抱怨哪个析构函数,或者至少,main.cpp 中的哪一行代码正在调用负责的函数未定义的行为。

    另外,根据您的编译器,您可能会遇到known bug in VC

    您可以在this answer 上找到有关分段错误、常见原因以及如何调试它们的更多一般信息。

    【讨论】:

    • 好的,我现在已经这样做了,我得到的主要是错误INVALID HEAP ARGUMENT: allocated with operator new, freed with free replace_free,但是一个,我认为棺材里的最后一个钉子是UNADDRESSABLE ACCESS beyond heap bounds: writing 4 byte(s),但是创建它的代码无法寻址的访问对我来说看起来不错。
    • 好的,修好了。感谢您的输入,这使修复发生了:)
    • 您能分享一下问题所在吗?我看到了同样的事情。谢谢
    猜你喜欢
    • 2017-02-28
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多