Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改写VerificationDemo.m为C语言版本后,distance为零 #59

Open
shandqc opened this issue Jul 6, 2017 · 7 comments
Open

改写VerificationDemo.m为C语言版本后,distance为零 #59

shandqc opened this issue Jul 6, 2017 · 7 comments

Comments

@shandqc
Copy link

shandqc commented Jul 6, 2017

博士,您好,非常感谢您的共享,还有点困惑麻烦您解疑。
我在matlab下,利用CASIA_demo.prototxt、CASIA_iter_666000.caffemodel以及mean.proto能够正常运行VerificationDemo.m,得出两幅人脸图像的距离值。但是我改写成C语言版本后,也是运用以上三个文件,为什么每次得出的距离值都是0?
改写的C版本关键代码如下,麻烦您指导下
LOG(INFO) << "reading model from " << FLAGS_model;
Net caffe_test_net(FLAGS_model, TEST);
LOG(INFO) << "reading weights from " << FLAGS_weights;
caffe_test_net.CopyTrainedLayersFrom(FLAGS_weights);

    人脸检测与对齐,以及去均值,人脸图像(100,100)

   std::vector<Mat> datum_vector;
datum_vector.push_back(face1);
datum_vector.push_back(face2);

std::vector<int> labels;
labels.push_back(1);
labels.push_back(2);

MemoryDataLayer* data_layer_ptr = (MemoryDataLayer*)&(caffe_test_net.layers()[0]);
data_layer_ptr->AddMatVector(datum_vector,labels);
const std::vector<Blob
>& result = caffe_test_net.ForwardPrefilled();
cout<<"distance:" << result[0]->cpu_data()[0]<<endl;

为什么每次 result[0]->cpu_data()[0]都是0,谢谢!

@happynear
Copy link
Owner

这个得debug一下,比如说把中间层输出出来看一下。

这个代码已经很老了,我建议你用caffe.binding.dll来调用caffe,那个接口比较清晰。

https://github.com/happynear/caffe-windows/tree/ms/windows/caffe.binding

@shandqc
Copy link
Author

shandqc commented Jul 7, 2017

谢谢您的回复。使用了caffe.binding,
CaffeBinding caffe_face_verification;
caffe_face_verification.AddNet(FLAGS_model, FLAGS_weights, 0);
……
caffe_face_verification.SetMemoryDataLayer("input", datum_vector, 0);
caffe_face_verification.Forward(0);
DataBlob & result = caffe_face_verification.GetBlobData("distance", 0);
cout << "distance:" << fixed << result.data[0] << endl;
得出的结果还是为0
是哪个地方还出现了错误吗?
打扰您宝贵时间了,谢谢!

@happynear
Copy link
Owner

你可以debug一下,依次用GetBlobData来获取中间层的输出来看看是不是0.

@shandqc
Copy link
Author

shandqc commented Jul 8, 2017

conv52层输出为0,之前中间层输出为非0数值

@happynear
Copy link
Owner

那就得再确认一下log里有没有把conv52层的weight读进来了。

@shandqc
Copy link
Author

shandqc commented Jul 9, 2017

好的,谢谢,我再试试。

@jieyongshi
Copy link

@shandqc 你好,我在matlab下,利用CASIA_demo.prototxt、CASIA_iter_666000.caffemodel以及mean.proto运行VerificationDemo.m的结果是matlab停止工作,提示appcrash,请问你是如何运行成功的呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants