win7 x64 vs2015 c++ 使用 tensorflow - 2 使用 facenet 模型

    简单调用 facenet模型,并对比欧式距离.使用了opencv做人脸检测.其中一些参数暂时写死了.目前的效果一般般.因为 opencv对人脸的不同姿态检测并不是太准.(暂时依赖于Qt的QString 和 QImage )

 

1/ create:
    Scope m_root = Scope::NewRootScope();
    Status status = NewSession(SessionOptions(), &m_pSession);//创建新会话Session


    QString strModelPath = "E:/SmartCity2015/AI/testTensorFlow/x64/Debug/20170512-110547.pb";

    GraphDef graphdef; //Graph Definition for current model
    Status status_load = ReadBinaryProto(Env::Default(), strModelPath.toStdString(), &graphdef); //从pb文件中读取图模型;
    if (!status_load.ok()) {
        std::cout << "ERROR: Loading model failed..." << strModelPath.toStdString() << std::endl;
        std::cout << status_load.ToString() << "\n";
        return false;
    }
    Status status_create = m_pSession->Create(graphdef); //将模型导入会话Session中;
    if (!status_create.ok()) {
        std::cout << "ERROR: Creating graph in session failed..." << status_create.ToString() << std::endl;
        m_bIsSessionOk = false;
        return false;
    }
    cout << "Session successfully created." << endl;

    m_bIsSessionOk = true;

2 对比两个图片的距离.1.06 作为分界线. <1.06为同一个人脸.


int CTensorFlow::Run(const string& strPicture1, const string& strPicture2, float& fDistance, vector<RectInfo>& arrFaces1, vector<RectInfo>& arrFaces2)
{
    if (m_bIsSessionOk == false)
    {
        return -1;
    }

    m_strPicture1 = strPicture1;
    m_strPicture2 = strPicture2;

    int nHeight = 160;
    int nWidth = 160;

    m_nTotalRecognition++;
    Tensor tensorPic1;
    Tensor tensorPic2;

    bool bRet = GetPicTensor(strPicture1, nHeight, nWidth, tensorPic1, arrFaces1);
    if (bRet == false)
    {
        m_nRecognitionFail++;
        return 0;
    }
    bRet = GetPicTensor(strPicture2, nHeight, nWidth, tensorPic2, arrFaces2);
    if (bRet == false)
    {
        m_nRecognitionFail++;
        return 0;
    }
    vector<float> arrData1;
    GetValueFromTensor(tensorPic1, arrData1);
    vector<float> arrData2;
    GetValueFromTensor(tensorPic2, arrData2);

    fDistance = Euclidean(arrData1, arrData2);
    std::cout << "Euclidean fDistance: " << fDistance << std::endl;

    if (fDistance > m_fThreshold)
    {
        m_nMoreThenThreshold++;
    }

    return 1;
}

完整代码:

   https://download.csdn.net/download/zsyddl2/10563498

 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值