我在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;
}我在一个唯一的或shared_ptr中测试过caffe_net,但这并没有任何区别。我对如何找到手头的问题束手无策。
发布于 2016-09-13 01:15:47
“有时发生”是一件很常见的事情,有未定义的行为,这是你真正遇到的。从理论上讲,分割错误是计算机可能做的无限多的事情之一--行为实际上是未定义的。换句话说,就像他们在USENET上说的那样:“编译器让你鼻子里的魔鬼飞出来是合法的。”它可能会工作,它可能会做一些奇怪的事情,或者它可能会抛出一些重大错误,比如段错误。
有专门用于跟踪分段错误和其他内存错误的工具。在Linux上,这通常是Valgrind,而在Windows上,你可以使用Dr. Memory。只要您使用包含的调试符号(-g)进行编译,当您通过Dr.Memory运行可执行文件时,它将为您提供分段错误的堆栈跟踪。
一旦获得堆栈跟踪,就检查它的顶部,看看代码抱怨的是哪个析构函数,或者至少是main.cpp中的哪一行代码正在调用导致未定义行为的函数。
此外,根据您的编译器,您可能会遇到known bug in VC。
您可以找到有关分段故障、常见原因以及如何在this answer上调试它们的更多一般信息。
https://stackoverflow.com/questions/39455124
复制相似问题